101 |
101 |
102 # Add a connector or a blank to this power rail at the place given |
102 # Add a connector or a blank to this power rail at the place given |
103 def InsertConnector(self, idx, connector = True): |
103 def InsertConnector(self, idx, connector = True): |
104 if connector: |
104 if connector: |
105 if self.Type == LEFTRAIL: |
105 if self.Type == LEFTRAIL: |
106 connector = Connector(self, "", "BOOL", wx.Point(2, 0), EAST) |
106 connector = Connector(self, "", "BOOL", wx.Point(self.Size[0], 0), EAST) |
107 elif self.Type == RIGHTRAIL: |
107 elif self.Type == RIGHTRAIL: |
108 connector = Connector(self, "", "BOOL", wx.Point(0, 0), WEST) |
108 connector = Connector(self, "", "BOOL", wx.Point(0, 0), WEST) |
109 self.Connectors.insert(idx, connector) |
109 self.Connectors.insert(idx, connector) |
110 else: |
110 else: |
111 self.Connectors.insert(idx, None) |
111 self.Connectors.insert(idx, None) |
118 connector.SetPosition(wx.Point(position.x, position.y + movey)) |
118 connector.SetPosition(wx.Point(position.x, position.y + movey)) |
119 miny = self.Size[1] |
119 miny = self.Size[1] |
120 maxy = 0 |
120 maxy = 0 |
121 for connect in self.Connectors: |
121 for connect in self.Connectors: |
122 connect_pos = connect.GetRelPosition() |
122 connect_pos = connect.GetRelPosition() |
123 miny = min(miny, connect_pos.y) |
123 miny = min(miny, connect_pos.y - self.Extensions[0]) |
124 maxy = max(maxy, connect_pos.y) |
124 maxy = max(maxy, connect_pos.y - self.Extensions[0]) |
125 min_pos = self.Pos.y + miny - self.Extensions[0] |
125 min_pos = self.Pos.y + miny |
126 self.Pos.y = min(min_pos, self.Pos.y) |
126 self.Pos.y = min(min_pos, self.Pos.y) |
127 if min_pos == self.Pos.y: |
127 if min_pos == self.Pos.y: |
128 for connect in self.Connectors: |
128 for connect in self.Connectors: |
129 connect_pos = connect.GetRelPosition() |
129 connect_pos = connect.GetRelPosition() |
130 connect.SetPosition(wx.Point(connect_pos.x, connect_pos.y - miny + self.Extensions[0])) |
130 connect.SetPosition(wx.Point(connect_pos.x, connect_pos.y - miny)) |
131 self.Size[1] = max(maxy - miny + self.Extensions[0] + self.Extensions[1], self.Size[1]) |
131 maxy = 0 |
|
132 for connect in self.Connectors: |
|
133 connect_pos = connect.GetRelPosition() |
|
134 maxy = max(maxy, connect_pos.y) |
|
135 self.Size[1] = max(maxy + self.Extensions[1], self.Size[1]) |
132 connector.MoveConnected() |
136 connector.MoveConnected() |
133 self.RefreshBoundingBox() |
137 self.RefreshBoundingBox() |
134 |
138 |
135 # Returns the index in connectors list for the connector given |
139 # Returns the index in connectors list for the connector given |
136 def GetConnectorIndex(self, connector): |
140 def GetConnectorIndex(self, connector): |
152 |
156 |
153 # Refresh the positions of the power rail connectors |
157 # Refresh the positions of the power rail connectors |
154 def RefreshConnectors(self): |
158 def RefreshConnectors(self): |
155 if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
159 if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
156 height = self.Size[1] - self.Extensions[0] - self.Extensions[1] |
160 height = self.Size[1] - self.Extensions[0] - self.Extensions[1] |
|
161 interval = float(height) / float(max(len(self.Connectors) - 1, 1)) |
157 for i, connector in enumerate(self.Connectors): |
162 for i, connector in enumerate(self.Connectors): |
158 position = connector.GetRelPosition() |
163 position = connector.GetRelPosition() |
159 if self.RealConnectors: |
164 if self.Type == LEFTRAIL: |
160 if self.Type == LEFTRAIL: |
165 if self.RealConnectors: |
161 connector.SetPosition(wx.Point(self.Size[0], self.Extensions[0] + int(round(self.RealConnectors[i] * height)))) |
166 connector.SetPosition(wx.Point(self.Size[0], self.Extensions[0] + int(round(self.RealConnectors[i] * height)))) |
162 elif self.Type == RIGHTRAIL: |
167 else: |
|
168 connector.SetPosition(wx.Point(self.Size[0], self.Extensions[0] + int(round(i * height)))) |
|
169 elif self.Type == RIGHTRAIL: |
|
170 if self.RealConnectors: |
163 connector.SetPosition(wx.Point(0, self.Extensions[0] + int(round(self.RealConnectors[i] * height)))) |
171 connector.SetPosition(wx.Point(0, self.Extensions[0] + int(round(self.RealConnectors[i] * height)))) |
|
172 else: |
|
173 connector.SetPosition(wx.Point(0, self.Extensions[0] + int(round(i * height)))) |
164 else: |
174 else: |
165 position = self.Extensions[0] |
175 position = self.Extensions[0] |
166 for connector in self.Connectors: |
176 for connector in self.Connectors: |
167 if connector: |
177 if connector: |
168 if self.Type == LEFTRAIL: |
178 if self.Type == LEFTRAIL: |
235 self.RealConnectors = [] |
245 self.RealConnectors = [] |
236 height = self.Size[1] - self.Extensions[0] - self.Extensions[1] |
246 height = self.Size[1] - self.Extensions[0] - self.Extensions[1] |
237 for connector in self.Connectors: |
247 for connector in self.Connectors: |
238 position = connector.GetRelPosition() |
248 position = connector.GetRelPosition() |
239 self.RealConnectors.append(float(position.y - self.Extensions[0])/float(max(1, height))) |
249 self.RealConnectors.append(float(position.y - self.Extensions[0])/float(max(1, height))) |
240 print self.RealConnectors |
|
241 Graphic_Element.OnLeftDown(self, event, dc, scaling) |
250 Graphic_Element.OnLeftDown(self, event, dc, scaling) |
242 |
251 |
243 # Method called when a LeftUp event have been generated |
252 # Method called when a LeftUp event have been generated |
244 def OnLeftUp(self, event, dc, scaling): |
253 def OnLeftUp(self, event, dc, scaling): |
245 self.RealConnectors = None |
254 self.RealConnectors = None |
246 handle_type, handle = self.Handle |
255 handle_type, handle = self.Handle |
247 if handle_type == HANDLE_CONNECTOR: |
256 if handle_type == HANDLE_CONNECTOR: |
248 wires = handle.GetWires() |
257 wires = handle.GetWires() |
249 if len(wires) != 1: |
258 if len(wires) == 1: |
250 return |
259 if handle == wires[0][0].StartConnected: |
251 if handle == wires[0][0].StartConnected: |
260 block = wires[0][0].EndConnected.GetParentBlock() |
252 block = wires[0][0].EndConnected.GetParentBlock() |
261 else: |
253 else: |
262 block = wires[0][0].StartConnected.GetParentBlock() |
254 block = wires[0][0].StartConnected.GetParentBlock() |
263 block.RefreshModel(False) |
255 block.RefreshModel(False) |
|
256 Graphic_Element.OnLeftUp(self, event, dc, scaling) |
264 Graphic_Element.OnLeftUp(self, event, dc, scaling) |
257 |
265 |
258 # Method called when a LeftDClick event have been generated |
266 # Method called when a LeftDClick event have been generated |
259 def OnLeftDClick(self, event, dc, scaling): |
267 def OnLeftDClick(self, event, dc, scaling): |
260 # Edit the powerrail properties |
268 # Edit the powerrail properties |