@@ -59,6 +59,7 @@ def __init__ (self,name=""):
5959 self .has_pr = False
6060 self .meta = list ()
6161 self .obj = False #- Original JSON obj
62+ self .named_rects = dict ()
6263
6364
6465 def getPort (self ,name :str ):
@@ -70,8 +71,12 @@ def getPort(self,name:str):
7071
7172 # Find the first rectangle in this cell that uses layer
7273 def getRect (self ,layer ):
73- raise Exception ("Not implemented" )
74- pass
74+ for child in self .children :
75+ if (child is None ):
76+ continue
77+ if (child .layer == layer ):
78+ return child
79+ return None
7580
7681 # Add a rectangle to the cell, hooks updated() of the child to updateBoundingRect
7782 def add (self , child ):
@@ -90,6 +95,8 @@ def add(self, child):
9095 self .children .append (child )
9196 child .connect (self .updateBoundingRect )
9297
98+ self .updateBoundingRect ()
99+
93100
94101 # Move this cell, and all children by dx and dy
95102 def translate (self , dx , dy ):
@@ -104,7 +111,7 @@ def mirrorX(self,ax):
104111 super ().mirrorX (ax )
105112 for child in self .children :
106113 child .mirrorX (ax )
107- for port in self .ports :
114+ for _ , port in self .ports . items () :
108115 port .mirrorX (ax )
109116 self .updateBoundingRect ()
110117 self .emit_updated ()
@@ -115,8 +122,8 @@ def mirrorY(self,ay):
115122 super ().mirrorY (ay )
116123 for child in self .children :
117124 child .mirrorY (ay )
118- for port in self .ports :
119- port .mirrorY ()
125+ for _ , port in self .ports . items () :
126+ port .mirrorY (ay )
120127 self .updateBoundingRect ()
121128 self .emit_updated
122129
@@ -135,28 +142,29 @@ def moveTo(self,ax, ay):
135142 # Center this cell, and all children on ax and ay
136143 def moveCenter (self ,ax , ay ):
137144 self .updateBoundingRect ()
138-
139- xc1 = self .centerX
140- yc1 = self .centerY
141-
142- xpos = self .left - (xc1 - ax )
143- ypos = self .bottom - (yc1 - ay )
144-
145- self .moveTo (xpos ,ypos )
145+ xc1 = self .centerX ()
146+ yc1 = self .centerY ()
147+ dx = ax - xc1
148+ dy = ay - yc1
149+ self .translate (dx , dy )
146150
147151 # Shortcut for adding ports
148152 def addPort (name , rect ):
149- raise Exception ("Not implemented" )
150- pass
153+ if (rect is None ):
154+ return None
155+ p = Port (name )
156+ p .setRect (rect )
157+ self .add (p )
158+ return p
151159
152160 # Mirror this cell, and all children around horizontal center point (basically flip horizontal)
153161 def mirrorCenterX (self ):
154- self .mirrorX (self .centerY )
162+ self .mirrorX (self .centerY () )
155163 pass
156164
157165
158166 def mirrorCenterY (self ):
159- self .mirrorY (self .centerX )
167+ self .mirrorY (self .centerX () )
160168 pass
161169
162170 def updateBoundingRect (self ):
@@ -404,9 +412,34 @@ def updatePort(self,name:str,r:Rect):
404412
405413
406414 # //! Find all rectangles by regular expression
407- # virtual QList<Rect *> findRectanglesByRegex(QString regex,QString layer);
408- # virtual void findRectangles(QList<Rect*> &rects,QString name,QString layer);
409- # virtual QList<Rect *> findAllRectangles(QString regex, QString layer);
415+ def findRectanglesByRegex (self , regex :str , layer :str ):
416+ rects = list ()
417+ self .findRectangles (rects , regex , layer )
418+ return rects
419+
420+ def findRectangles (self , rects :list , name :str , layer :str ):
421+ for child in self .children :
422+ if child is None :
423+ continue
424+ if layer and child .layer != layer :
425+ continue
426+ if re .search (name , getattr (child ,'name' , '' )):
427+ rects .append (child )
428+ # Also include plain rects on layer when name matches empty or wildcard
429+ elif name == "" and (hasattr (child ,'isRect' ) and child .isRect ()):
430+ rects .append (child )
431+
432+ def findAllRectangles (self , regex :str , layer :str ):
433+ rects = list ()
434+ for child in self .children :
435+ if child is None :
436+ continue
437+ if layer and child .layer != layer :
438+ continue
439+ cname = getattr (child ,'name' ,'' )
440+ if re .search (regex , cname ) or (hasattr (child ,'isRect' ) and child .isRect () and re .search (regex , layer )):
441+ rects .append (child )
442+ return rects
410443
411444 # QJsonObject toJson();
412445 # void fromJson(QJsonObject o);
0 commit comments