graphics/LD_Objects.py
changeset 566 6014ef82a98a
parent 563 3f92a5e18804
child 633 3536f4469cde
equal deleted inserted replaced
565:94c11207aa6f 566:6014ef82a98a
   352         DebugDataConsumer.__init__(self)
   352         DebugDataConsumer.__init__(self)
   353         self.Type = type
   353         self.Type = type
   354         self.Name = name
   354         self.Name = name
   355         self.Id = id
   355         self.Id = id
   356         self.Size = wx.Size(LD_ELEMENT_SIZE[0], LD_ELEMENT_SIZE[1])
   356         self.Size = wx.Size(LD_ELEMENT_SIZE[0], LD_ELEMENT_SIZE[1])
   357         self.Errors = {}
   357         self.Highlights = {}
   358         # Create an input and output connector
   358         # Create an input and output connector
   359         self.Input = Connector(self, "", "BOOL", wx.Point(0, self.Size[1] / 2 + 1), WEST)
   359         self.Input = Connector(self, "", "BOOL", wx.Point(0, self.Size[1] / 2 + 1), WEST)
   360         self.Output = Connector(self, "", "BOOL", wx.Point(self.Size[0], self.Size[1] / 2 + 1), EAST)
   360         self.Output = Connector(self, "", "BOOL", wx.Point(self.Size[0], self.Size[1] / 2 + 1), EAST)
   361         self.PreviousValue = False
   361         self.PreviousValue = False
   362         self.PreviousSpreading = False
   362         self.PreviousSpreading = False
   593         dc.DrawRectangle(left_left, top, width, height)
   593         dc.DrawRectangle(left_left, top, width, height)
   594         dc.DrawRectangle(right_left, top, width, height)
   594         dc.DrawRectangle(right_left, top, width, height)
   595         dc.SetLogicalFunction(wx.COPY)
   595         dc.SetLogicalFunction(wx.COPY)
   596         dc.SetUserScale(scalex, scaley)
   596         dc.SetUserScale(scalex, scaley)
   597     
   597     
   598     def AddError(self, infos, start, end):
   598     # Adds an highlight to the connection
   599         self.Errors[infos[0]] = (start[1], end[1])
   599     def AddHighlight(self, infos, start, end, highlight_type):
       
   600         highlights = self.Highlights.setdefault(infos[0], [])
       
   601         if infos[0] == "reference":
       
   602             if start[0] == 0 and end[0] == 0:
       
   603                 AddHighlight(highlights, (start, end, highlight_type))
       
   604         else:
       
   605             AddHighlight(highlights, ((0, 0), (0, 1), highlight_type))
       
   606     
       
   607     # Removes an highlight from the connection
       
   608     def RemoveHighlight(self, infos, start, end, highlight_type):
       
   609         highlights = self.Highlights.get(infos[0], [])
       
   610         if RemoveHighlight(highlights, (start, end, highlight_type)) and len(highlights) == 0:
       
   611             self.Highlights.pop(infos[0])
       
   612     
       
   613     # Removes all the highlights of one particular type from the connection
       
   614     def ClearHighlight(self, highlight_type=None):
       
   615         if highlight_type is None:
       
   616             self.Highlights = {}
       
   617         else:
       
   618             highlight_items = self.Highlights.items()
       
   619             for name, highlights in highlight_items:
       
   620                 highlights = ClearHighlights(highlight, highlight_type)
       
   621                 if len(highlights) == 0:
       
   622                     self.Highlights.pop(name)
   600     
   623     
   601     # Draws contact
   624     # Draws contact
   602     def Draw(self, dc):
   625     def Draw(self, dc):
   603         Graphic_Element.Draw(self, dc)
   626         Graphic_Element.Draw(self, dc)
   604         if self.Value is not None:            
   627         if self.Value is not None:            
   649                         self.Pos.y + (self.Size[1] - type_size[1]) / 2)
   672                         self.Pos.y + (self.Size[1] - type_size[1]) / 2)
   650             dc.DrawText(typetext, type_pos[0], type_pos[1])
   673             dc.DrawText(typetext, type_pos[0], type_pos[1])
   651         # Draw input and output connectors
   674         # Draw input and output connectors
   652         self.Input.Draw(dc)
   675         self.Input.Draw(dc)
   653         self.Output.Draw(dc)
   676         self.Output.Draw(dc)
   654         if self.Errors.has_key("reference"):
   677         
   655             HighlightErrorZone(dc, name_pos[0], name_pos[1], name_size[0], name_size[1])
   678         if not getattr(dc, "printing", False):
   656         if typetext != "" and (self.Errors.has_key("negated") or self.Errors.has_key("rising") or self.Errors.has_key("falling")):
   679             for name, highlights in self.Highlights.iteritems():
   657             HighlightErrorZone(dc, type_pos[0], type_pos[1], type_size[0], type_size[1])
   680                 if name == "reference":
   658         
   681                     DrawHighlightedText(dc, self.Name, highlights, name_pos[0], name_pos[1])
       
   682                 elif typetext != "":
       
   683                     DrawHighlightedText(dc, typetext, highlights, type_pos[0], type_pos[1])
   659 
   684 
   660 #-------------------------------------------------------------------------------
   685 #-------------------------------------------------------------------------------
   661 #                         Ladder Diagram Coil
   686 #                         Ladder Diagram Coil
   662 #-------------------------------------------------------------------------------
   687 #-------------------------------------------------------------------------------
   663 
   688 
   672         Graphic_Element.__init__(self, parent)
   697         Graphic_Element.__init__(self, parent)
   673         self.Type = type
   698         self.Type = type
   674         self.Name = name
   699         self.Name = name
   675         self.Id = id
   700         self.Id = id
   676         self.Size = wx.Size(LD_ELEMENT_SIZE[0], LD_ELEMENT_SIZE[1])
   701         self.Size = wx.Size(LD_ELEMENT_SIZE[0], LD_ELEMENT_SIZE[1])
   677         self.Errors = {}
   702         self.Highlights = {}
   678         # Create an input and output connector
   703         # Create an input and output connector
   679         self.Input = Connector(self, "", "BOOL", wx.Point(0, self.Size[1] / 2 + 1), WEST)
   704         self.Input = Connector(self, "", "BOOL", wx.Point(0, self.Size[1] / 2 + 1), WEST)
   680         self.Output = Connector(self, "", "BOOL", wx.Point(self.Size[0], self.Size[1] / 2 + 1), EAST)
   705         self.Output = Connector(self, "", "BOOL", wx.Point(self.Size[0], self.Size[1] / 2 + 1), EAST)
   681         self.Value = None
   706         self.Value = None
   682         self.PreviousValue = False
   707         self.PreviousValue = False
   889                            round((int(self.Size[1] * sqrt(2)) - 1) * scaley),
   914                            round((int(self.Size[1] * sqrt(2)) - 1) * scaley),
   890                            -45, 45)
   915                            -45, 45)
   891         dc.SetLogicalFunction(wx.COPY)
   916         dc.SetLogicalFunction(wx.COPY)
   892         dc.SetUserScale(scalex, scaley)
   917         dc.SetUserScale(scalex, scaley)
   893     
   918     
   894     def AddError(self, infos, start, end):
   919     # Adds an highlight to the connection
   895         self.Errors[infos[0]] = (start[1], end[1])
   920     def AddHighlight(self, infos, start, end, highlight_type):
       
   921         highlights = self.Highlights.setdefault(infos[0], [])
       
   922         if infos[0] == "reference":
       
   923             if start[0] == 0 and end[0] == 0:
       
   924                 AddHighlight(highlights, (start, end, highlight_type))
       
   925         else:
       
   926             AddHighlight(highlights, ((0, 0), (0, 1), highlight_type))
       
   927     
       
   928     # Removes an highlight from the connection
       
   929     def RemoveHighlight(self, infos, start, end, highlight_type):
       
   930         highlights = self.Highlights.get(infos[0], [])
       
   931         if RemoveHighlight(highlights, (start, end, highlight_type)) and len(highlights) == 0:
       
   932             self.Highlights.pop(infos[0])
       
   933     
       
   934     # Removes all the highlights of one particular type from the connection
       
   935     def ClearHighlight(self, highlight_type=None):
       
   936         if highlight_type is None:
       
   937             self.Highlights = {}
       
   938         else:
       
   939             highlight_items = self.Highlights.items()
       
   940             for name, highlights in highlight_items:
       
   941                 highlights = ClearHighlights(highlight, highlight_type)
       
   942                 if len(highlights) == 0:
       
   943                     self.Highlights.pop(name)
   896     
   944     
   897     # Draws coil
   945     # Draws coil
   898     def Draw(self, dc):
   946     def Draw(self, dc):
   899         Graphic_Element.Draw(self, dc)
   947         Graphic_Element.Draw(self, dc)
   900         if self.Value is not None and self.Value:
   948         if self.Value is not None and self.Value:
   952                         self.Pos.y + (self.Size[1] - type_size[1]) / 2)
  1000                         self.Pos.y + (self.Size[1] - type_size[1]) / 2)
   953             dc.DrawText(typetext, type_pos[0], type_pos[1])
  1001             dc.DrawText(typetext, type_pos[0], type_pos[1])
   954         # Draw input and output connectors
  1002         # Draw input and output connectors
   955         self.Input.Draw(dc)
  1003         self.Input.Draw(dc)
   956         self.Output.Draw(dc)
  1004         self.Output.Draw(dc)
   957         if self.Errors.has_key("reference"):
  1005 
   958             HighlightErrorZone(dc, name_pos[0], name_pos[1], name_size[0], name_size[1])
  1006         if not getattr(dc, "printing", False):
   959         if typetext != "" and (self.Errors.has_key("negated") or self.Errors.has_key("rising") or self.Errors.has_key("falling")):
  1007             for name, highlights in self.Highlights.iteritems():
   960             HighlightErrorZone(dc, type_pos[0], type_pos[1], type_size[0], type_size[1])
  1008                 if name == "reference":
       
  1009                     DrawHighlightedText(dc, self.Name, highlights, name_pos[0], name_pos[1])
       
  1010                 elif typetext != "":
       
  1011                     DrawHighlightedText(dc, typetext, highlights, type_pos[0], type_pos[1])
   961             
  1012             
   962         
  1013