107 if connector: |
107 if connector: |
108 connector.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
108 connector.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
109 |
109 |
110 # Refresh the power rail bounding box |
110 # Refresh the power rail bounding box |
111 def RefreshBoundingBox(self): |
111 def RefreshBoundingBox(self): |
112 dc = wx.ClientDC(self.Parent) |
|
113 self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
112 self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
114 |
113 |
115 # Refresh the power rail size |
114 # Refresh the power rail size |
116 def RefreshSize(self): |
115 def RefreshSize(self): |
117 self.Size = wx.Size(LD_POWERRAIL_WIDTH, LD_LINE_SIZE * len(self.Connectors)) |
116 self.Size = wx.Size(LD_POWERRAIL_WIDTH, LD_LINE_SIZE * len(self.Connectors)) |
311 Graphic_Element.OnRightUp(self, event, dc, scaling) |
310 Graphic_Element.OnRightUp(self, event, dc, scaling) |
312 else: |
311 else: |
313 self.Parent.PopupDefaultMenu() |
312 self.Parent.PopupDefaultMenu() |
314 |
313 |
315 # Refreshes the powerrail state according to move defined and handle selected |
314 # Refreshes the powerrail state according to move defined and handle selected |
316 def ProcessDragging(self, movex, movey, scaling): |
315 def ProcessDragging(self, movex, movey, centered, scaling): |
317 handle_type, handle = self.Handle |
316 handle_type, handle = self.Handle |
318 # A connector has been handled |
317 # A connector has been handled |
319 if handle_type == HANDLE_CONNECTOR: |
318 if handle_type == HANDLE_CONNECTOR: |
320 movey = max(-self.BoundingBox.y, movey) |
319 movey = max(-self.BoundingBox.y, movey) |
321 if scaling is not None: |
320 if scaling is not None: |
322 position = handle.GetRelPosition() |
321 position = handle.GetRelPosition() |
323 movey = round(float(self.Pos.y + position.y + movey) / float(scaling[1])) * scaling[1] - self.Pos.y - position.y |
322 movey = round(float(self.Pos.y + position.y + movey) / float(scaling[1])) * scaling[1] - self.Pos.y - position.y |
324 self.MoveConnector(handle, movey) |
323 self.MoveConnector(handle, movey) |
325 return 0, movey |
324 return 0, movey |
326 else: |
325 else: |
327 return Graphic_Element.ProcessDragging(self, movex, movey, scaling) |
326 return Graphic_Element.ProcessDragging(self, movex, movey, centered, scaling) |
328 |
327 |
329 # Refreshes the power rail model |
328 # Refreshes the power rail model |
330 def RefreshModel(self, move=True): |
329 def RefreshModel(self, move=True): |
331 self.Parent.RefreshPowerRailModel(self) |
330 self.Parent.RefreshPowerRailModel(self) |
332 # If power rail has moved and power rail is of type LEFT, refresh the model |
331 # If power rail has moved and power rail is of type LEFT, refresh the model |
414 self.Input.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
413 self.Input.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
415 self.Output.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
414 self.Output.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
416 |
415 |
417 # Refresh the size of text for name |
416 # Refresh the size of text for name |
418 def RefreshNameSize(self): |
417 def RefreshNameSize(self): |
419 dc = wx.ClientDC(self.Parent) |
|
420 if self.Name != "": |
418 if self.Name != "": |
421 self.NameSize = dc.GetTextExtent(self.Name) |
419 self.NameSize = self.Parent.GetTextExtent(self.Name) |
422 else: |
420 else: |
423 self.NameSize = 0, 0 |
421 self.NameSize = 0, 0 |
424 |
422 |
425 # Refresh the size of text for type |
423 # Refresh the size of text for type |
426 def RefreshTypeSize(self): |
424 def RefreshTypeSize(self): |
427 dc = wx.ClientDC(self.Parent) |
|
428 typetext = "" |
425 typetext = "" |
429 if self.Type == CONTACT_REVERSE: |
426 if self.Type == CONTACT_REVERSE: |
430 typetext = "/" |
427 typetext = "/" |
431 elif self.Type == CONTACT_RISING: |
428 elif self.Type == CONTACT_RISING: |
432 typetext = "P" |
429 typetext = "P" |
433 elif self.Type == CONTACT_FALLING: |
430 elif self.Type == CONTACT_FALLING: |
434 typetext = "N" |
431 typetext = "N" |
435 if typetext != "": |
432 if typetext != "": |
436 self.TypeSize = dc.GetTextExtent(typetext) |
433 self.TypeSize = self.Parent.GetTextExtent(typetext) |
437 else: |
434 else: |
438 self.TypeSize = 0, 0 |
435 self.TypeSize = 0, 0 |
439 |
436 |
440 # Refresh the contact bounding box |
437 # Refresh the contact bounding box |
441 def RefreshBoundingBox(self): |
438 def RefreshBoundingBox(self): |
442 dc = wx.ClientDC(self.Parent) |
|
443 # Calculate the size of the name outside the contact |
439 # Calculate the size of the name outside the contact |
444 text_width, text_height = dc.GetTextExtent(self.Name) |
440 text_width, text_height = self.Parent.GetTextExtent(self.Name) |
445 # Calculate the bounding box size |
441 # Calculate the bounding box size |
446 if self.Name != "": |
442 if self.Name != "": |
447 bbx_x = self.Pos.x - max(0, (text_width - self.Size[0]) / 2) |
443 bbx_x = self.Pos.x - max(0, (text_width - self.Size[0]) / 2) |
448 bbx_width = max(self.Size[0], text_width) |
444 bbx_width = max(self.Size[0], text_width) |
449 bbx_y = self.Pos.y - (text_height + 2) |
445 bbx_y = self.Pos.y - (text_height + 2) |
644 self.Input.UnConnect() |
640 self.Input.UnConnect() |
645 self.Output.UnConnect() |
641 self.Output.UnConnect() |
646 |
642 |
647 # Refresh the size of text for name |
643 # Refresh the size of text for name |
648 def RefreshNameSize(self): |
644 def RefreshNameSize(self): |
649 dc = wx.ClientDC(self.Parent) |
|
650 if self.Name != "": |
645 if self.Name != "": |
651 self.NameSize = dc.GetTextExtent(self.Name) |
646 self.NameSize = self.Parent.GetTextExtent(self.Name) |
652 else: |
647 else: |
653 self.NameSize = 0, 0 |
648 self.NameSize = 0, 0 |
654 |
649 |
655 # Refresh the size of text for type |
650 # Refresh the size of text for type |
656 def RefreshTypeSize(self): |
651 def RefreshTypeSize(self): |
657 dc = wx.ClientDC(self.Parent) |
|
658 typetext = "" |
652 typetext = "" |
659 if self.Type == COIL_REVERSE: |
653 if self.Type == COIL_REVERSE: |
660 typetext = "/" |
654 typetext = "/" |
661 elif self.Type == COIL_SET: |
655 elif self.Type == COIL_SET: |
662 typetext = "S" |
656 typetext = "S" |
663 elif self.Type == COIL_RESET: |
657 elif self.Type == COIL_RESET: |
664 typetext = "R" |
658 typetext = "R" |
665 if typetext != "": |
659 if typetext != "": |
666 self.TypeSize = dc.GetTextExtent(typetext) |
660 self.TypeSize = self.Parent.GetTextExtent(typetext) |
667 else: |
661 else: |
668 self.TypeSize = 0, 0 |
662 self.TypeSize = 0, 0 |
669 |
663 |
670 # Refresh the coil bounding box |
664 # Refresh the coil bounding box |
671 def RefreshBoundingBox(self): |
665 def RefreshBoundingBox(self): |
672 dc = wx.ClientDC(self.Parent) |
|
673 # Calculate the size of the name outside the coil |
666 # Calculate the size of the name outside the coil |
674 text_width, text_height = dc.GetTextExtent(self.Name) |
667 text_width, text_height = self.Parent.GetTextExtent(self.Name) |
675 # Calculate the bounding box size |
668 # Calculate the bounding box size |
676 if self.Name != "": |
669 if self.Name != "": |
677 bbx_x = self.Pos.x - max(0, (text_width - self.Size[0]) / 2) |
670 bbx_x = self.Pos.x - max(0, (text_width - self.Size[0]) / 2) |
678 bbx_width = max(self.Size[0], text_width) |
671 bbx_width = max(self.Size[0], text_width) |
679 bbx_y = self.Pos.y - (text_height + 2) |
672 bbx_y = self.Pos.y - (text_height + 2) |