184 self.RefreshConnectors() |
184 self.RefreshConnectors() |
185 self.RefreshSize() |
185 self.RefreshSize() |
186 |
186 |
187 # Refresh the positions of the power rail connectors |
187 # Refresh the positions of the power rail connectors |
188 def RefreshConnectors(self): |
188 def RefreshConnectors(self): |
|
189 scaling = self.Parent.GetScaling() |
189 if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
190 if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
190 height = self.Size[1] - self.Extensions[0] - self.Extensions[1] |
191 height = self.Size[1] - self.Extensions[0] - self.Extensions[1] |
191 interval = float(height) / float(max(len(self.Connectors) - 1, 1)) |
192 interval = float(height) / float(max(len(self.Connectors) - 1, 1)) |
192 for i, connector in enumerate(self.Connectors): |
193 for i, connector in enumerate(self.Connectors): |
193 position = connector.GetRelPosition() |
194 if self.RealConnectors: |
|
195 position = self.Extensions[0] + int(round(self.RealConnectors[i] * height)) |
|
196 else: |
|
197 position = self.Extensions[0] + int(round(i * interval)) |
|
198 if scaling is not None: |
|
199 position = round(float(self.Pos.y + position) / float(scaling[1])) * scaling[1] - self.Pos.y |
194 if self.Type == LEFTRAIL: |
200 if self.Type == LEFTRAIL: |
195 if self.RealConnectors: |
201 connector.SetPosition(wx.Point(self.Size[0], position)) |
196 connector.SetPosition(wx.Point(self.Size[0], self.Extensions[0] + int(round(self.RealConnectors[i] * height)))) |
|
197 else: |
|
198 connector.SetPosition(wx.Point(self.Size[0], self.Extensions[0] + int(round(i * interval)))) |
|
199 elif self.Type == RIGHTRAIL: |
202 elif self.Type == RIGHTRAIL: |
200 if self.RealConnectors: |
203 connector.SetPosition(wx.Point(0, position)) |
201 connector.SetPosition(wx.Point(0, self.Extensions[0] + int(round(self.RealConnectors[i] * height)))) |
|
202 else: |
|
203 connector.SetPosition(wx.Point(0, self.Extensions[0] + int(round(i * interval)))) |
|
204 else: |
204 else: |
205 position = self.Extensions[0] |
205 position = self.Extensions[0] |
206 for connector in self.Connectors: |
206 for connector in self.Connectors: |
207 if connector: |
207 if connector: |
|
208 if scaling is not None: |
|
209 ypos = round(float(self.Pos.y + position) / float(scaling[1])) * scaling[1] - self.Pos.y |
|
210 else: |
|
211 ypos = position |
208 if self.Type == LEFTRAIL: |
212 if self.Type == LEFTRAIL: |
209 connector.SetPosition(wx.Point(self.Size[0], position)) |
213 connector.SetPosition(wx.Point(self.Size[0], ypos)) |
210 elif self.Type == RIGHTRAIL: |
214 elif self.Type == RIGHTRAIL: |
211 connector.SetPosition(wx.Point(0, position)) |
215 connector.SetPosition(wx.Point(0, ypos)) |
212 position += LD_LINE_SIZE |
216 position += LD_LINE_SIZE |
213 self.RefreshConnected() |
217 self.RefreshConnected() |
214 |
218 |
215 # Refresh the position of wires connected to power rail |
219 # Refresh the position of wires connected to power rail |
216 def RefreshConnected(self, exclude = []): |
220 def RefreshConnected(self, exclude = []): |
260 def GetType(self): |
264 def GetType(self): |
261 return self.Type |
265 return self.Type |
262 |
266 |
263 # Method called when a LeftDown event have been generated |
267 # Method called when a LeftDown event have been generated |
264 def OnLeftDown(self, event, dc, scaling): |
268 def OnLeftDown(self, event, dc, scaling): |
|
269 self.RealConnectors = [] |
|
270 height = self.Size[1] - self.Extensions[0] - self.Extensions[1] |
|
271 for connector in self.Connectors: |
|
272 position = connector.GetRelPosition() |
|
273 self.RealConnectors.append(float(position.y - self.Extensions[0])/float(max(1, height))) |
|
274 Graphic_Element.OnLeftDown(self, event, dc, scaling) |
|
275 |
|
276 # Method called when a LeftUp event have been generated |
|
277 def OnLeftUp(self, event, dc, scaling): |
|
278 Graphic_Element.OnLeftUp(self, event, dc, scaling) |
|
279 self.RealConnectors = None |
|
280 |
|
281 # Method called when a LeftDown event have been generated |
|
282 def OnRightDown(self, event, dc, scaling): |
265 pos = GetScaledEventPosition(event, dc, scaling) |
283 pos = GetScaledEventPosition(event, dc, scaling) |
266 # Test if a connector have been handled |
284 # Test if a connector have been handled |
267 connector = self.TestConnector(pos, False) |
285 connector = self.TestConnector(pos, False) |
268 if connector: |
286 if connector: |
269 self.Handle = (HANDLE_CONNECTOR, connector) |
287 self.Handle = (HANDLE_CONNECTOR, connector) |
270 self.Parent.SetCursor(wx.StockCursor(wx.CURSOR_HAND)) |
288 self.Parent.SetCursor(wx.StockCursor(wx.CURSOR_HAND)) |
271 self.Selected = False |
289 self.Selected = False |
272 # Initializes the last position |
290 # Initializes the last position |
273 self.oldPos = GetScaledEventPosition(event, dc, scaling) |
291 self.oldPos = GetScaledEventPosition(event, dc, scaling) |
274 else: |
292 else: |
275 self.RealConnectors = [] |
293 Graphic_Element.OnRightDown(self, event, dc, scaling) |
276 height = self.Size[1] - self.Extensions[0] - self.Extensions[1] |
294 |
277 for connector in self.Connectors: |
295 # Method called when a LeftDClick event have been generated |
278 position = connector.GetRelPosition() |
296 def OnLeftDClick(self, event, dc, scaling): |
279 self.RealConnectors.append(float(position.y - self.Extensions[0])/float(max(1, height))) |
297 # Edit the powerrail properties |
280 Graphic_Element.OnLeftDown(self, event, dc, scaling) |
298 self.Parent.EditPowerRailContent(self) |
281 |
299 |
282 # Method called when a LeftUp event have been generated |
300 # Method called when a RightUp event have been generated |
283 def OnLeftUp(self, event, dc, scaling): |
301 def OnRightUp(self, event, dc, scaling): |
284 handle_type, handle = self.Handle |
302 handle_type, handle = self.Handle |
285 if handle_type == HANDLE_CONNECTOR: |
303 if handle_type == HANDLE_CONNECTOR: |
286 wires = handle.GetWires() |
304 wires = handle.GetWires() |
287 if len(wires) == 1: |
305 if len(wires) == 1: |
288 if handle == wires[0][0].StartConnected: |
306 if handle == wires[0][0].StartConnected: |
289 block = wires[0][0].EndConnected.GetParentBlock() |
307 block = wires[0][0].EndConnected.GetParentBlock() |
290 else: |
308 else: |
291 block = wires[0][0].StartConnected.GetParentBlock() |
309 block = wires[0][0].StartConnected.GetParentBlock() |
292 block.RefreshModel(False) |
310 block.RefreshModel(False) |
293 Graphic_Element.OnLeftUp(self, event, dc, scaling) |
311 Graphic_Element.OnRightUp(self, event, dc, scaling) |
294 self.RealConnectors = None |
312 else: |
295 |
313 self.Parent.PopupDefaultMenu() |
296 # Method called when a LeftDClick event have been generated |
|
297 def OnLeftDClick(self, event, dc, scaling): |
|
298 # Edit the powerrail properties |
|
299 self.Parent.EditPowerRailContent(self) |
|
300 |
|
301 # Method called when a RightUp event have been generated |
|
302 def OnRightUp(self, event, dc, scaling): |
|
303 self.Parent.PopupDefaultMenu() |
|
304 |
314 |
305 # Refreshes the powerrail state according to move defined and handle selected |
315 # Refreshes the powerrail state according to move defined and handle selected |
306 def ProcessDragging(self, movex, movey): |
316 def ProcessDragging(self, movex, movey, scaling): |
307 handle_type, handle = self.Handle |
317 handle_type, handle = self.Handle |
308 # A connector has been handled |
318 # A connector has been handled |
309 if handle_type == HANDLE_CONNECTOR: |
319 if handle_type == HANDLE_CONNECTOR: |
310 movey = max(-self.BoundingBox.y, movey) |
320 movey = max(-self.BoundingBox.y, movey) |
|
321 if scaling is not None: |
|
322 position = handle.GetRelPosition() |
|
323 movey = round(float(self.Pos.y + position.y + movey) / float(scaling[1])) * scaling[1] - self.Pos.y - position.y |
311 self.MoveConnector(handle, movey) |
324 self.MoveConnector(handle, movey) |
312 return 0, movey |
325 return 0, movey |
313 else: |
326 else: |
314 return Graphic_Element.ProcessDragging(self, movex, movey) |
327 return Graphic_Element.ProcessDragging(self, movex, movey, scaling) |
315 |
328 |
316 # Refreshes the power rail model |
329 # Refreshes the power rail model |
317 def RefreshModel(self, move=True): |
330 def RefreshModel(self, move=True): |
318 self.Parent.RefreshPowerRailModel(self) |
331 self.Parent.RefreshPowerRailModel(self) |
319 # If power rail has moved and power rail is of type LEFT, refresh the model |
332 # If power rail has moved and power rail is of type LEFT, refresh the model |