47 self.Extensions = [LD_LINE_SIZE / 2, LD_LINE_SIZE / 2] |
47 self.Extensions = [LD_LINE_SIZE / 2, LD_LINE_SIZE / 2] |
48 if len(connectors) < 1: |
48 if len(connectors) < 1: |
49 connectors = [True] |
49 connectors = [True] |
50 self.SetType(type, connectors) |
50 self.SetType(type, connectors) |
51 |
51 |
52 # Destructor |
52 def Flush(self): |
53 def __del__(self): |
53 for connector in self.Connectors: |
|
54 if connector is not None: |
|
55 connector.Flush() |
54 self.Connectors = [] |
56 self.Connectors = [] |
55 |
57 |
56 # Make a clone of this LD_PowerRail |
58 # Make a clone of this LD_PowerRail |
57 def Clone(self, parent, id = None, pos = None): |
59 def Clone(self, parent, id = None, pos = None): |
58 powerrail = LD_PowerRail(parent, self.Type, id) |
60 powerrail = LD_PowerRail(parent, self.Type, id) |
374 self.Size = wx.Size(LD_ELEMENT_SIZE[0], LD_ELEMENT_SIZE[1]) |
376 self.Size = wx.Size(LD_ELEMENT_SIZE[0], LD_ELEMENT_SIZE[1]) |
375 self.Errors = {} |
377 self.Errors = {} |
376 # Create an input and output connector |
378 # Create an input and output connector |
377 self.Input = Connector(self, "", "BOOL", wx.Point(0, self.Size[1] / 2 + 1), WEST) |
379 self.Input = Connector(self, "", "BOOL", wx.Point(0, self.Size[1] / 2 + 1), WEST) |
378 self.Output = Connector(self, "", "BOOL", wx.Point(self.Size[0], self.Size[1] / 2 + 1), EAST) |
380 self.Output = Connector(self, "", "BOOL", wx.Point(self.Size[0], self.Size[1] / 2 + 1), EAST) |
|
381 self.Value = None |
|
382 self.PreviousValue = False |
|
383 self.PreviousSpreading = False |
379 self.RefreshNameSize() |
384 self.RefreshNameSize() |
380 self.RefreshTypeSize() |
385 self.RefreshTypeSize() |
381 |
386 |
382 # Destructor |
387 def Flush(self): |
383 def __del__(self): |
388 if self.Input is not None: |
384 self.Input = None |
389 self.Input.Flush() |
385 self.Output = None |
390 self.Input = None |
|
391 if self.Output is not None: |
|
392 self.Output.Flush() |
|
393 self.Output = None |
|
394 |
|
395 def SetValue(self, value): |
|
396 self.PreviousValue = self.Value |
|
397 self.Value = value |
|
398 if self.Value != self.PreviousValue: |
|
399 self.Refresh() |
|
400 self.SpreadCurrent() |
|
401 |
|
402 def SpreadCurrent(self): |
|
403 spreading = self.Input.ReceivingCurrent() |
|
404 if self.Value is not None: |
|
405 if self.Type == CONTACT_NORMAL: |
|
406 spreading &= self.Value |
|
407 elif self.Type == CONTACT_REVERSE: |
|
408 spreading &= not self.Value |
|
409 elif self.Type == CONTACT_RISING: |
|
410 spreading &= self.Value and not self.PreviousValue |
|
411 elif self.Type == CONTACT_FALLING: |
|
412 spreading &= self.Value and not self.PreviousValue |
|
413 else: |
|
414 spreading = False |
|
415 if spreading and not self.PreviousSpreading: |
|
416 self.Output.SpreadCurrent(True) |
|
417 elif not spreading and self.PreviousSpreading: |
|
418 self.Output.SpreadCurrent(False) |
|
419 self.PreviousSpreading = spreading |
386 |
420 |
387 # Make a clone of this LD_Contact |
421 # Make a clone of this LD_Contact |
388 def Clone(self, parent, id = None, pos = None): |
422 def Clone(self, parent, id = None, pos = None): |
389 contact = LD_Contact(parent, self.Type, self.Name, id) |
423 contact = LD_Contact(parent, self.Type, self.Name, id) |
390 contact.SetSize(self.Size[0], self.Size[1]) |
424 contact.SetSize(self.Size[0], self.Size[1]) |
563 self.Errors[infos[0]] = (start[1], end[1]) |
597 self.Errors[infos[0]] = (start[1], end[1]) |
564 |
598 |
565 # Draws contact |
599 # Draws contact |
566 def Draw(self, dc): |
600 def Draw(self, dc): |
567 Graphic_Element.Draw(self, dc) |
601 Graphic_Element.Draw(self, dc) |
568 dc.SetPen(wx.BLACK_PEN) |
602 if self.Value is not None: |
|
603 if self.Type == CONTACT_NORMAL and self.Value: |
|
604 dc.SetPen(wx.GREEN_PEN) |
|
605 elif self.Type == CONTACT_REVERSE and not self.Value: |
|
606 dc.SetPen(wx.GREEN_PEN) |
|
607 elif self.Type == CONTACT_RISING and self.Value and not self.PreviousValue: |
|
608 dc.SetPen(wx.GREEN_PEN) |
|
609 elif self.Type == CONTACT_FALLING and self.Value and not self.PreviousValue: |
|
610 dc.SetPen(wx.GREEN_PEN) |
|
611 else: |
|
612 dc.SetPen(wx.BLACK_PEN) |
|
613 else: |
|
614 dc.SetPen(wx.BLACK_PEN) |
569 dc.SetBrush(wx.BLACK_BRUSH) |
615 dc.SetBrush(wx.BLACK_BRUSH) |
570 |
616 |
571 # Compiling contact type modifier symbol |
617 # Compiling contact type modifier symbol |
572 typetext = "" |
618 typetext = "" |
573 if self.Type == CONTACT_REVERSE: |
619 if self.Type == CONTACT_REVERSE: |
626 self.Size = wx.Size(LD_ELEMENT_SIZE[0], LD_ELEMENT_SIZE[1]) |
672 self.Size = wx.Size(LD_ELEMENT_SIZE[0], LD_ELEMENT_SIZE[1]) |
627 self.Errors = {} |
673 self.Errors = {} |
628 # Create an input and output connector |
674 # Create an input and output connector |
629 self.Input = Connector(self, "", "BOOL", wx.Point(0, self.Size[1] / 2 + 1), WEST) |
675 self.Input = Connector(self, "", "BOOL", wx.Point(0, self.Size[1] / 2 + 1), WEST) |
630 self.Output = Connector(self, "", "BOOL", wx.Point(self.Size[0], self.Size[1] / 2 + 1), EAST) |
676 self.Output = Connector(self, "", "BOOL", wx.Point(self.Size[0], self.Size[1] / 2 + 1), EAST) |
|
677 self.Value = None |
|
678 self.PreviousValue = False |
631 self.RefreshNameSize() |
679 self.RefreshNameSize() |
632 self.RefreshTypeSize() |
680 self.RefreshTypeSize() |
633 |
681 |
634 # Destructor |
682 def Flush(self): |
635 def __del__(self): |
683 if self.Input is not None: |
636 self.Input = None |
684 self.Input.Flush() |
637 self.Output = None |
685 self.Input = None |
|
686 if self.Output is not None: |
|
687 self.Output.Flush() |
|
688 self.Output = None |
|
689 |
|
690 def SetValue(self, value): |
|
691 if self.Value != value: |
|
692 self.Value = value |
|
693 self.Refresh() |
|
694 |
|
695 def SpreadCurrent(self): |
|
696 self.PreviousValue = self.Value |
|
697 self.Value = self.Input.ReceivingCurrent() |
|
698 if self.Value and not self.PreviousValue: |
|
699 self.Output.SpreadCurrent(True) |
|
700 elif not self.Value and self.PreviousValue: |
|
701 self.Output.SpreadCurrent(False) |
|
702 if self.Value != self.PreviousValue: |
|
703 self.Refresh() |
638 |
704 |
639 # Make a clone of this LD_Coil |
705 # Make a clone of this LD_Coil |
640 def Clone(self, parent, id = None, pos = None): |
706 def Clone(self, parent, id = None, pos = None): |
641 coil = LD_Coil(parent, self.Type, self.Name, id) |
707 coil = LD_Coil(parent, self.Type, self.Name, id) |
642 coil.SetSize(self.Size[0], self.Size[1]) |
708 coil.SetSize(self.Size[0], self.Size[1]) |
815 self.Errors[infos[0]] = (start[1], end[1]) |
881 self.Errors[infos[0]] = (start[1], end[1]) |
816 |
882 |
817 # Draws coil |
883 # Draws coil |
818 def Draw(self, dc): |
884 def Draw(self, dc): |
819 Graphic_Element.Draw(self, dc) |
885 Graphic_Element.Draw(self, dc) |
820 dc.SetPen(wx.Pen(wx.BLACK, 2, wx.SOLID)) |
886 if self.Value is not None and self.Value: |
|
887 dc.SetPen(wx.Pen(wx.GREEN, 2, wx.SOLID)) |
|
888 else: |
|
889 dc.SetPen(wx.Pen(wx.BLACK, 2, wx.SOLID)) |
821 dc.SetBrush(wx.TRANSPARENT_BRUSH) |
890 dc.SetBrush(wx.TRANSPARENT_BRUSH) |
822 |
891 |
823 # Compiling coil type modifier symbol |
892 # Compiling coil type modifier symbol |
824 typetext = "" |
893 typetext = "" |
825 if self.Type == COIL_REVERSE: |
894 if self.Type == COIL_REVERSE: |
844 # Draw a two ellipse arcs for representing the coil |
913 # Draw a two ellipse arcs for representing the coil |
845 dc.DrawEllipticArc(self.Pos.x, self.Pos.y - int(self.Size[1] * (sqrt(2) - 1.) / 2.) + 1, self.Size[0], int(self.Size[1] * sqrt(2)) - 1, 135, 225) |
914 dc.DrawEllipticArc(self.Pos.x, self.Pos.y - int(self.Size[1] * (sqrt(2) - 1.) / 2.) + 1, self.Size[0], int(self.Size[1] * sqrt(2)) - 1, 135, 225) |
846 dc.DrawEllipticArc(self.Pos.x, self.Pos.y - int(self.Size[1] * (sqrt(2) - 1.) / 2.) + 1, self.Size[0], int(self.Size[1] * sqrt(2)) - 1, -45, 45) |
915 dc.DrawEllipticArc(self.Pos.x, self.Pos.y - int(self.Size[1] * (sqrt(2) - 1.) / 2.) + 1, self.Size[0], int(self.Size[1] * sqrt(2)) - 1, -45, 45) |
847 # Draw a point to avoid hole in left arc |
916 # Draw a point to avoid hole in left arc |
848 if not getattr(dc, "printing", False): |
917 if not getattr(dc, "printing", False): |
849 dc.SetPen(wx.BLACK_PEN) |
918 if self.Value is not None and self.Value: |
|
919 dc.SetPen(wx.GREEN_PEN) |
|
920 else: |
|
921 dc.SetPen(wx.BLACK_PEN) |
850 dc.DrawPoint(self.Pos.x + 1, self.Pos.y + self.Size[1] / 2 + 1) |
922 dc.DrawPoint(self.Pos.x + 1, self.Pos.y + self.Size[1] / 2 + 1) |
851 name_size = self.NameSize |
923 name_size = self.NameSize |
852 if typetext != "": |
924 if typetext != "": |
853 type_size = self.TypeSize |
925 type_size = self.TypeSize |
854 |
926 |