65 powerrail.Connectors.append(connector.Clone(powerrail)) |
65 powerrail.Connectors.append(connector.Clone(powerrail)) |
66 else: |
66 else: |
67 powerrail.Connectors.append(None) |
67 powerrail.Connectors.append(None) |
68 return powerrail |
68 return powerrail |
69 |
69 |
|
70 # Returns the RedrawRect |
|
71 def GetRedrawRect(self, movex = 0, movey = 0): |
|
72 rect = Graphic_Element.GetRedrawRect(self, movex, movey) |
|
73 for connector in self.Connectors: |
|
74 if connector is not None: |
|
75 rect = rect.Union(connector.GetRedrawRect(movex, movey)) |
|
76 if movex != 0 or movey != 0: |
|
77 for connector in self.Connectors: |
|
78 if connector is not None and connector.IsConnected(): |
|
79 rect = rect.Union(connector.GetConnectedRedrawRect(movex, movey)) |
|
80 return rect |
|
81 |
70 # Forbids to change the power rail size |
82 # Forbids to change the power rail size |
71 def SetSize(self, width, height): |
83 def SetSize(self, width, height): |
72 if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
84 if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
73 Graphic_Element.SetSize(self, width, height) |
85 Graphic_Element.SetSize(self, width, height) |
74 self.RefreshConnectors() |
86 self.RefreshConnectors() |
96 connector.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
108 connector.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
97 |
109 |
98 # Refresh the power rail bounding box |
110 # Refresh the power rail bounding box |
99 def RefreshBoundingBox(self): |
111 def RefreshBoundingBox(self): |
100 dc = wx.ClientDC(self.Parent) |
112 dc = wx.ClientDC(self.Parent) |
101 self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y, self.Size[0], self.Size[1] + 1) |
113 self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
102 |
114 |
103 # Refresh the power rail size |
115 # Refresh the power rail size |
104 def RefreshSize(self): |
116 def RefreshSize(self): |
105 self.Size = wx.Size(2, LD_LINE_SIZE * len(self.Connectors)) |
117 self.Size = wx.Size(LD_POWERRAIL_WIDTH, LD_LINE_SIZE * len(self.Connectors)) |
106 self.RefreshBoundingBox() |
118 self.RefreshBoundingBox() |
107 |
119 |
108 # Returns the block minimum size |
120 # Returns the block minimum size |
109 def GetMinSize(self): |
121 def GetMinSize(self): |
110 if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
122 if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
111 return 2, self.Extensions[0] + self.Extensions[1] |
123 return LD_POWERRAIL_WIDTH, self.Extensions[0] + self.Extensions[1] |
112 else: |
124 else: |
113 return 2, LD_LINE_SIZE * len(self.Connectors) |
125 return LD_POWERRAIL_WIDTH, LD_LINE_SIZE * len(self.Connectors) |
114 |
126 |
115 # Add a connector or a blank to this power rail at the last place |
127 # Add a connector or a blank to this power rail at the last place |
116 def AddConnector(self, connector = True): |
128 def AddConnector(self, connector = True): |
117 self.InsertConnector(len(self.Connectors), connector) |
129 self.InsertConnector(len(self.Connectors), connector) |
118 |
130 |
311 if connector: |
323 if connector: |
312 connector.RefreshWires() |
324 connector.RefreshWires() |
313 |
325 |
314 # Draws power rail |
326 # Draws power rail |
315 def Draw(self, dc): |
327 def Draw(self, dc): |
|
328 Graphic_Element.Draw(self, dc) |
316 dc.SetPen(wx.BLACK_PEN) |
329 dc.SetPen(wx.BLACK_PEN) |
317 dc.SetBrush(wx.BLACK_BRUSH) |
330 dc.SetBrush(wx.BLACK_BRUSH) |
318 # Draw a rectangle with the power rail size |
331 # Draw a rectangle with the power rail size |
319 dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
332 dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
320 # Draw connectors |
333 # Draw connectors |
321 for connector in self.Connectors: |
334 for connector in self.Connectors: |
322 if connector: |
335 if connector: |
323 connector.Draw(dc) |
336 connector.Draw(dc) |
324 Graphic_Element.Draw(self, dc) |
|
325 |
337 |
326 |
338 |
327 #------------------------------------------------------------------------------- |
339 #------------------------------------------------------------------------------- |
328 # Ladder Diagram Contact |
340 # Ladder Diagram Contact |
329 #------------------------------------------------------------------------------- |
341 #------------------------------------------------------------------------------- |
359 if pos is not None: |
371 if pos is not None: |
360 contact.SetPosition(pos.x, pos.y) |
372 contact.SetPosition(pos.x, pos.y) |
361 contact.Input = self.Input.Clone(contact) |
373 contact.Input = self.Input.Clone(contact) |
362 contact.Output = self.Output.Clone(contact) |
374 contact.Output = self.Output.Clone(contact) |
363 return contact |
375 return contact |
|
376 |
|
377 # Returns the RedrawRect |
|
378 def GetRedrawRect(self, movex = 0, movey = 0): |
|
379 rect = Graphic_Element.GetRedrawRect(self, movex, movey) |
|
380 rect = rect.Union(self.Input.GetRedrawRect(movex, movey)) |
|
381 rect = rect.Union(self.Output.GetRedrawRect(movex, movey)) |
|
382 if movex != 0 or movey != 0: |
|
383 if self.Input.IsConnected(): |
|
384 rect = rect.Union(self.Input.GetConnectedRedrawRect(movex, movey)) |
|
385 if self.Output.IsConnected(): |
|
386 rect = rect.Union(self.Output.GetConnectedRedrawRect(movex, movey)) |
|
387 return rect |
364 |
388 |
365 # Forbids to change the contact size |
389 # Forbids to change the contact size |
366 def SetSize(self, width, height): |
390 def SetSize(self, width, height): |
367 if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
391 if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
368 Graphic_Element.SetSize(self, width, height) |
392 Graphic_Element.SetSize(self, width, height) |
501 if move: |
525 if move: |
502 self.Output.RefreshWires() |
526 self.Output.RefreshWires() |
503 |
527 |
504 # Draws the highlightment of this element if it is highlighted |
528 # Draws the highlightment of this element if it is highlighted |
505 def DrawHighlightment(self, dc): |
529 def DrawHighlightment(self, dc): |
506 if self.Highlighted: |
530 dc.SetPen(wx.Pen(HIGHLIGHTCOLOR)) |
507 dc.SetPen(wx.Pen(HIGHLIGHTCOLOR)) |
531 dc.SetBrush(wx.Brush(HIGHLIGHTCOLOR)) |
508 dc.SetBrush(wx.Brush(HIGHLIGHTCOLOR)) |
532 dc.SetLogicalFunction(wx.AND) |
509 # Draw two rectangles for representing the contact |
533 # Draw two rectangles for representing the contact |
510 dc.DrawRectangle(self.Pos.x - 2, self.Pos.y - 2, 6, self.Size[1] + 5) |
534 dc.DrawRectangle(self.Pos.x - 2, self.Pos.y - 2, 6, self.Size[1] + 5) |
511 dc.DrawRectangle(self.Pos.x + self.Size[0] - 3, self.Pos.y - 2, 6, self.Size[1] + 5) |
535 dc.DrawRectangle(self.Pos.x + self.Size[0] - 3, self.Pos.y - 2, 6, self.Size[1] + 5) |
|
536 dc.SetLogicalFunction(wx.COPY) |
512 |
537 |
513 # Draws contact |
538 # Draws contact |
514 def Draw(self, dc): |
539 def Draw(self, dc): |
|
540 Graphic_Element.Draw(self, dc) |
515 dc.SetPen(wx.BLACK_PEN) |
541 dc.SetPen(wx.BLACK_PEN) |
516 dc.SetBrush(wx.BLACK_BRUSH) |
542 dc.SetBrush(wx.BLACK_BRUSH) |
517 # Draw two rectangles for representing the contact |
543 # Draw two rectangles for representing the contact |
518 dc.DrawRectangle(self.Pos.x, self.Pos.y, 2, self.Size[1] + 1) |
544 dc.DrawRectangle(self.Pos.x, self.Pos.y, 2, self.Size[1] + 1) |
519 dc.DrawRectangle(self.Pos.x + self.Size[0] - 1, self.Pos.y, 2, self.Size[1] + 1) |
545 dc.DrawRectangle(self.Pos.x + self.Size[0] - 1, self.Pos.y, 2, self.Size[1] + 1) |
532 dc.DrawText(typetext, self.Pos.x + (self.Size[0] - self.TypeSize[0]) / 2 + 1, |
558 dc.DrawText(typetext, self.Pos.x + (self.Size[0] - self.TypeSize[0]) / 2 + 1, |
533 self.Pos.y + (self.Size[1] - self.TypeSize[1]) / 2) |
559 self.Pos.y + (self.Size[1] - self.TypeSize[1]) / 2) |
534 # Draw input and output connectors |
560 # Draw input and output connectors |
535 self.Input.Draw(dc) |
561 self.Input.Draw(dc) |
536 self.Output.Draw(dc) |
562 self.Output.Draw(dc) |
537 Graphic_Element.Draw(self, dc) |
|
538 |
563 |
539 |
564 |
540 #------------------------------------------------------------------------------- |
565 #------------------------------------------------------------------------------- |
541 # Ladder Diagram Coil |
566 # Ladder Diagram Coil |
542 #------------------------------------------------------------------------------- |
567 #------------------------------------------------------------------------------- |
572 if pos is not None: |
597 if pos is not None: |
573 coil.SetPosition(pos.x, pos.y) |
598 coil.SetPosition(pos.x, pos.y) |
574 coil.Input = self.Input.Clone(coil) |
599 coil.Input = self.Input.Clone(coil) |
575 coil.Output = self.Output.Clone(coil) |
600 coil.Output = self.Output.Clone(coil) |
576 return coil |
601 return coil |
|
602 |
|
603 # Returns the RedrawRect |
|
604 def GetRedrawRect(self, movex = 0, movey = 0): |
|
605 rect = Graphic_Element.GetRedrawRect(self, movex, movey) |
|
606 rect = rect.Union(self.Input.GetRedrawRect(movex, movey)) |
|
607 rect = rect.Union(self.Output.GetRedrawRect(movex, movey)) |
|
608 if movex != 0 or movey != 0: |
|
609 if self.Input.IsConnected(): |
|
610 rect = rect.Union(self.Input.GetConnectedRedrawRect(movex, movey)) |
|
611 if self.Output.IsConnected(): |
|
612 rect = rect.Union(self.Output.GetConnectedRedrawRect(movex, movey)) |
|
613 return rect |
577 |
614 |
578 # Forbids to change the contact size |
615 # Forbids to change the contact size |
579 def SetSize(self, width, height): |
616 def SetSize(self, width, height): |
580 if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
617 if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
581 Graphic_Element.SetSize(self, width, height) |
618 Graphic_Element.SetSize(self, width, height) |
714 if move: |
751 if move: |
715 self.Output.RefreshWires() |
752 self.Output.RefreshWires() |
716 |
753 |
717 # Draws the highlightment of this element if it is highlighted |
754 # Draws the highlightment of this element if it is highlighted |
718 def DrawHighlightment(self, dc): |
755 def DrawHighlightment(self, dc): |
719 if self.Highlighted: |
756 dc.SetPen(wx.Pen(HIGHLIGHTCOLOR, 6, wx.SOLID)) |
720 dc.SetPen(wx.Pen(HIGHLIGHTCOLOR, 6, wx.SOLID)) |
757 dc.SetBrush(wx.TRANSPARENT_BRUSH) |
721 dc.SetBrush(wx.TRANSPARENT_BRUSH) |
758 dc.SetLogicalFunction(wx.AND) |
722 # Draw a two circle arcs for representing the coil |
759 # Draw a two circle arcs for representing the coil |
723 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) |
760 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) |
724 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) |
761 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) |
|
762 dc.SetLogicalFunction(wx.COPY) |
725 |
763 |
726 # Draws coil |
764 # Draws coil |
727 def Draw(self, dc): |
765 def Draw(self, dc): |
|
766 Graphic_Element.Draw(self, dc) |
728 dc.SetPen(wx.Pen(wx.BLACK, 2, wx.SOLID)) |
767 dc.SetPen(wx.Pen(wx.BLACK, 2, wx.SOLID)) |
729 dc.SetBrush(wx.TRANSPARENT_BRUSH) |
768 dc.SetBrush(wx.TRANSPARENT_BRUSH) |
730 # Draw a two circle arcs for representing the coil |
769 # Draw a two circle arcs for representing the coil |
731 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) |
770 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) |
732 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) |
771 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) |