@@ -1337,7 +1337,7 @@ def get_padstack_instances_id_intersecting_polygon(self, points, nets=None, pads
13371337
13381338 Parameters
13391339 ----------
1340- bounding_box : tuple or list.
1340+ points : tuple or list.
13411341 bounding box, [x1, y1, x2, y2]
13421342 nets : str or list, optional
13431343 net name of list of nets name applying filtering on padstack instances selection. If ``None`` is provided
@@ -1347,39 +1347,43 @@ def get_padstack_instances_id_intersecting_polygon(self, points, nets=None, pads
13471347
13481348 Returns
13491349 -------
1350- List of padstack instances ID intersecting the bounding box.
1350+ List[int]
1351+ List of padstack instances ID intersecting the bounding box.
13511352 """
13521353 if not points :
13531354 raise Exception ("No points defining polygon was provided" )
13541355 if not padstack_instances_index :
13551356 padstack_instances_index = {}
13561357 for inst in self .instances :
1357- padstack_instances_index [inst .edb_uid ] = inst .position
1358+ padstack_instances_index [inst .id ] = inst .position
13581359 _x = [pt [0 ] for pt in points ]
13591360 _y = [pt [1 ] for pt in points ]
13601361 points = [_x , _y ]
13611362 return [
13621363 ind for ind , pt in padstack_instances_index .items () if GeometryOperators .is_point_in_polygon (pt , points )
13631364 ]
13641365
1365- def get_padstack_instances_intersecting_bounding_box (self , bounding_box , nets = None ):
1366+ def get_padstack_instances_intersecting_bounding_box (self , bounding_box , nets = None , padstack_instances_index = None ):
13661367 """Returns the list of padstack instances ID intersecting a given bounding box and nets.
1367-
13681368 Parameters
13691369 ----------
13701370 bounding_box : tuple or list.
13711371 bounding box, [x1, y1, x2, y2]
13721372 nets : str or list, optional
13731373 net name of list of nets name applying filtering on padstack instances selection. If ``None`` is provided
13741374 all instances are included in the index. Default value is ``None``.
1375-
1375+ padstack_instances_index : optional, Rtree object.
1376+ Can be provided optionally to prevent computing padstack instances Rtree index again.
13761377 Returns
13771378 -------
13781379 List of padstack instances ID intersecting the bounding box.
13791380 """
13801381 if not bounding_box :
13811382 raise Exception ("No bounding box was provided" )
1382- index = self .get_padstack_instances_rtree_index (nets = nets )
1383+ if not padstack_instances_index :
1384+ index = self .get_padstack_instances_rtree_index (nets = nets )
1385+ else :
1386+ index = padstack_instances_index
13831387 if not len (bounding_box ) == 4 :
13841388 raise Exception ("The bounding box length must be equal to 4" )
13851389 if isinstance (bounding_box , list ):
@@ -1569,71 +1573,31 @@ def merge_via(self, contour_boxes, net_filter=None, start_layer=None, stop_layer
15691573 instances = self .get_padstack_instances_id_intersecting_polygon (
15701574 points = contour_box , padstack_instances_index = instances_index
15711575 )
1572- if not instances :
1573- raise Exception (f"No padstack instances found inside { contour_box } " )
1574- else :
1575- if net_filter :
1576- instances = [id for id in instances if not self .instances [id ].net_name in net_filter ]
1577- if start_layer :
1578- if start_layer not in self ._pedb .stackup .layers .keys ():
1579- raise Exception (f"{ start_layer } not exist" )
1580- else :
1581- instances = [id for id in instances if all_instances [id ].start_layer == start_layer ]
1582- if stop_layer :
1583- if stop_layer not in self ._pedb .stackup .layers .keys ():
1584- raise Exception (f"{ stop_layer } not exist" )
1585- else :
1586- instances = [id for id in instances if all_instances [id ].stop_layer == stop_layer ]
1587- if not instances :
1588- raise Exception (
1589- f"No padstack instances found inside { contour_box } between { start_layer } and { stop_layer } "
1590- )
1591-
1592- if not start_layer :
1593- start_layer = list (self ._pedb .stackup .layers .values ())[0 ].name
1594- if not stop_layer :
1595- stop_layer = list (self ._pedb .stackup .layers .values ())[- 1 ].name
1596-
1597- net = self .instances [instances [0 ]].net_name
1598- x_values = []
1599- y_values = []
1600- for inst in instances :
1601- pos = instances_index [inst ]
1602- x_values .append (pos [0 ])
1603- y_values .append (pos [1 ])
1604- x_values = list (set (x_values ))
1605- y_values = list (set (y_values ))
1606- if len (x_values ) == 1 or len (y_values ) == 1 :
1607- create_instances = self .merge_via_along_lines (
1608- net_name = net , padstack_instances_id = instances , minimum_via_number = 2
1609- )
1610- merged_via_ids .extend (create_instances )
1611- else :
1612- instances_pts = np .array ([instances_index [id ] for id in instances ])
1613- convex_hull_contour = ConvexHull (instances_pts )
1614- contour_points = list (instances_pts [convex_hull_contour .vertices ])
1615- layer = list (self ._pedb .stackup .layers .values ())[0 ].name
1616- polygon = self ._pedb .modeler .create_polygon (points = contour_points , layer_name = layer )
1617- polygon_data = polygon .polygon_data
1618- polygon .delete ()
1619- new_padstack_def = generate_unique_name (self .instances [instances [0 ]].definition .name )
1620- if not self .create (
1621- padstackname = new_padstack_def ,
1622- pad_shape = "Polygon" ,
1623- antipad_shape = "Polygon" ,
1624- pad_polygon = polygon_data ,
1625- antipad_polygon = polygon_data ,
1626- polygon_hole = polygon_data ,
1627- start_layer = start_layer ,
1628- stop_layer = stop_layer ,
1629- ):
1630- raise Exception (f"Failed to create padstack definition { new_padstack_def } " )
1631- merged_instance = self .place (position = [0 , 0 ], definition_name = new_padstack_def , net_name = net )
1632- merged_instance .start_layer = start_layer
1633- merged_instance .stop_layer = stop_layer
1634-
1635- merged_via_ids .append (merged_instance .edb_uid )
1636- _ = [all_instances [id ].delete () for id in instances ]
1576+ if net_filter :
1577+ instances = [self .instances [id ] for id in instances if not self .instances [id ].net .name in net_filter ]
1578+ net = self .instances [instances [0 ]].net .name
1579+ instances_pts = np .array ([self .instances [id ].position for id in instances ])
1580+ convex_hull_contour = ConvexHull (instances_pts )
1581+ contour_points = list (instances_pts [convex_hull_contour .vertices ])
1582+ layer = list (self ._pedb .stackup .layers .values ())[0 ].name
1583+ polygon = self ._pedb .modeler .create_polygon (points = contour_points , layer_name = layer )
1584+ polygon_data = polygon .polygon_data
1585+ polygon .delete ()
1586+ new_padstack_def = generate_unique_name ("test" )
1587+ if not self .create (
1588+ padstackname = new_padstack_def ,
1589+ pad_shape = "Polygon" ,
1590+ antipad_shape = "Polygon" ,
1591+ pad_polygon = polygon_data ,
1592+ antipad_polygon = polygon_data ,
1593+ polygon_hole = polygon_data ,
1594+ start_layer = start_layer ,
1595+ stop_layer = stop_layer ,
1596+ ):
1597+ self ._logger .error (f"Failed to create padstack definition { new_padstack_def } " )
1598+ merged_instance = self .place (position = [0 , 0 ], definition_name = new_padstack_def , net_name = net )
1599+ merged_via_ids .append (merged_instance .id )
1600+ [self .instances [id ].delete () for id in instances ]
16371601 return merged_via_ids
16381602
16391603 def reduce_via_in_bounding_box (self , bounding_box , x_samples , y_samples , nets = None ):
0 commit comments