40 # Create a new power rail |
40 # Create a new power rail |
41 def __init__(self, parent, type, id = None, connectors = [True]): |
41 def __init__(self, parent, type, id = None, connectors = [True]): |
42 Graphic_Element.__init__(self, parent) |
42 Graphic_Element.__init__(self, parent) |
43 self.Type = None |
43 self.Type = None |
44 self.Connectors = [] |
44 self.Connectors = [] |
|
45 self.RealConnectors = None |
45 self.Id = id |
46 self.Id = id |
46 self.Extensions = [LD_LINE_SIZE / 2, LD_LINE_SIZE / 2] |
47 self.Extensions = [LD_LINE_SIZE / 2, LD_LINE_SIZE / 2] |
47 if len(connectors) < 1: |
48 if len(connectors) < 1: |
48 connectors = [True] |
49 connectors = [True] |
49 self.SetType(type, connectors) |
50 self.SetType(type, connectors) |
149 self.RefreshConnectors() |
150 self.RefreshConnectors() |
150 self.RefreshSize() |
151 self.RefreshSize() |
151 |
152 |
152 # Refresh the positions of the power rail connectors |
153 # Refresh the positions of the power rail connectors |
153 def RefreshConnectors(self): |
154 def RefreshConnectors(self): |
154 position = self.Extensions[0] |
155 if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
155 for connector in self.Connectors: |
156 height = self.Size[1] - self.Extensions[0] - self.Extensions[1] |
156 if connector: |
157 for i, connector in enumerate(self.Connectors): |
157 if self.Type == LEFTRAIL: |
158 position = connector.GetRelPosition() |
158 connector.SetPosition(wx.Point(self.Size[0], position)) |
159 if self.RealConnectors: |
159 elif self.Type == RIGHTRAIL: |
160 if self.Type == LEFTRAIL: |
160 connector.SetPosition(wx.Point(0, position)) |
161 connector.SetPosition(wx.Point(self.Size[0], self.Extensions[0] + int(round(self.RealConnectors[i] * height)))) |
161 position += LD_LINE_SIZE |
162 elif self.Type == RIGHTRAIL: |
|
163 connector.SetPosition(wx.Point(0, self.Extensions[0] + int(round(self.RealConnectors[i] * height)))) |
|
164 else: |
|
165 position = self.Extensions[0] |
|
166 for connector in self.Connectors: |
|
167 if connector: |
|
168 if self.Type == LEFTRAIL: |
|
169 connector.SetPosition(wx.Point(self.Size[0], position)) |
|
170 elif self.Type == RIGHTRAIL: |
|
171 connector.SetPosition(wx.Point(0, position)) |
|
172 position += LD_LINE_SIZE |
162 self.RefreshConnected() |
173 self.RefreshConnected() |
163 |
174 |
164 # Refresh the position of wires connected to power rail |
175 # Refresh the position of wires connected to power rail |
165 def RefreshConnected(self, exclude = []): |
176 def RefreshConnected(self, exclude = []): |
166 for connector in self.Connectors: |
177 for connector in self.Connectors: |
219 self.Parent.SetCursor(wx.StockCursor(wx.CURSOR_HAND)) |
230 self.Parent.SetCursor(wx.StockCursor(wx.CURSOR_HAND)) |
220 self.Selected = False |
231 self.Selected = False |
221 # Initializes the last position |
232 # Initializes the last position |
222 self.oldPos = GetScaledEventPosition(event, dc, scaling) |
233 self.oldPos = GetScaledEventPosition(event, dc, scaling) |
223 else: |
234 else: |
224 ## self.RealConnectors = {"Inputs":[],"Outputs":[]} |
235 self.RealConnectors = [] |
225 ## for input in self.Inputs: |
236 height = self.Size[1] - self.Extensions[0] - self.Extensions[1] |
226 ## position = input.GetRelPosition() |
237 for connector in self.Connectors: |
227 ## self.RealConnectors["Inputs"].append(float(position.x)/float(self.Size[0])) |
238 position = connector.GetRelPosition() |
228 ## for output in self.Outputs: |
239 self.RealConnectors.append(float(position.y - self.Extensions[0])/float(max(1, height))) |
229 ## position = output.GetRelPosition() |
240 print self.RealConnectors |
230 ## self.RealConnectors["Outputs"].append(float(position.x)/float(self.Size[0])) |
|
231 Graphic_Element.OnLeftDown(self, event, dc, scaling) |
241 Graphic_Element.OnLeftDown(self, event, dc, scaling) |
232 |
242 |
233 # Method called when a LeftUp event have been generated |
243 # Method called when a LeftUp event have been generated |
234 def OnLeftUp(self, event, dc, scaling): |
244 def OnLeftUp(self, event, dc, scaling): |
235 self.RealConnectors = None |
245 self.RealConnectors = None |