graphics/LD_Objects.py
changeset 231 fc2d6cbb8b39
parent 213 4931959ea256
child 237 097e8ee006cb
equal deleted inserted replaced
230:45d70748e45a 231:fc2d6cbb8b39
   370         Graphic_Element.__init__(self, parent)
   370         Graphic_Element.__init__(self, parent)
   371         self.Type = type
   371         self.Type = type
   372         self.Name = name
   372         self.Name = name
   373         self.Id = id
   373         self.Id = id
   374         self.Size = wx.Size(LD_ELEMENT_SIZE[0], LD_ELEMENT_SIZE[1])
   374         self.Size = wx.Size(LD_ELEMENT_SIZE[0], LD_ELEMENT_SIZE[1])
       
   375         self.Errors = {}
   375         # Create an input and output connector
   376         # Create an input and output connector
   376         self.Input = Connector(self, "", "BOOL", wx.Point(0, self.Size[1] / 2 + 1), WEST)
   377         self.Input = Connector(self, "", "BOOL", wx.Point(0, self.Size[1] / 2 + 1), WEST)
   377         self.Output = Connector(self, "", "BOOL", wx.Point(self.Size[0], self.Size[1] / 2 + 1), EAST)
   378         self.Output = Connector(self, "", "BOOL", wx.Point(self.Size[0], self.Size[1] / 2 + 1), EAST)
   378         self.RefreshNameSize()
   379         self.RefreshNameSize()
   379         self.RefreshTypeSize()
   380         self.RefreshTypeSize()
   556         # Draw two rectangles for representing the contact
   557         # Draw two rectangles for representing the contact
   557         dc.DrawRectangle(self.Pos.x - 2, self.Pos.y - 2, 6, self.Size[1] + 5)
   558         dc.DrawRectangle(self.Pos.x - 2, self.Pos.y - 2, 6, self.Size[1] + 5)
   558         dc.DrawRectangle(self.Pos.x + self.Size[0] - 3, self.Pos.y - 2, 6, self.Size[1] + 5)
   559         dc.DrawRectangle(self.Pos.x + self.Size[0] - 3, self.Pos.y - 2, 6, self.Size[1] + 5)
   559         dc.SetLogicalFunction(wx.COPY)
   560         dc.SetLogicalFunction(wx.COPY)
   560     
   561     
       
   562     def AddError(self, infos, start, end):
       
   563         print infos
       
   564         self.Errors[infos[0]] = (start[1], end[1])
       
   565     
   561     # Draws contact
   566     # Draws contact
   562     def Draw(self, dc):
   567     def Draw(self, dc):
   563         Graphic_Element.Draw(self, dc)
   568         Graphic_Element.Draw(self, dc)
   564         dc.SetPen(wx.BLACK_PEN)
   569         dc.SetPen(wx.BLACK_PEN)
   565         dc.SetBrush(wx.BLACK_BRUSH)
   570         dc.SetBrush(wx.BLACK_BRUSH)
   584         
   589         
   585         # Draw two rectangles for representing the contact
   590         # Draw two rectangles for representing the contact
   586         dc.DrawRectangle(self.Pos.x, self.Pos.y, 2, self.Size[1] + 1)
   591         dc.DrawRectangle(self.Pos.x, self.Pos.y, 2, self.Size[1] + 1)
   587         dc.DrawRectangle(self.Pos.x + self.Size[0] - 1, self.Pos.y, 2, self.Size[1] + 1)
   592         dc.DrawRectangle(self.Pos.x + self.Size[0] - 1, self.Pos.y, 2, self.Size[1] + 1)
   588         # Draw contact name
   593         # Draw contact name
   589         dc.DrawText(self.Name, self.Pos.x + (self.Size[0] - name_size[0]) / 2,
   594         name_pos = (self.Pos.x + (self.Size[0] - name_size[0]) / 2,
   590                 self.Pos.y - (name_size[1] + 2))
   595                     self.Pos.y - (name_size[1] + 2))
       
   596         dc.DrawText(self.Name, name_pos[0], name_pos[1])
   591         # Draw the modifier symbol in the middle of contact
   597         # Draw the modifier symbol in the middle of contact
   592         if typetext != "":
   598         if typetext != "":
   593             dc.DrawText(typetext, self.Pos.x + (self.Size[0] - type_size[0]) / 2 + 1,
   599             type_pos = (self.Pos.x + (self.Size[0] - type_size[0]) / 2 + 1,
   594                     self.Pos.y + (self.Size[1] - type_size[1]) / 2)
   600                         self.Pos.y + (self.Size[1] - type_size[1]) / 2)
       
   601             dc.DrawText(typetext, type_pos[0], type_pos[1])
   595         # Draw input and output connectors
   602         # Draw input and output connectors
   596         self.Input.Draw(dc)
   603         self.Input.Draw(dc)
   597         self.Output.Draw(dc)
   604         self.Output.Draw(dc)
       
   605         if "reference" in self.Errors:
       
   606             HighlightErrorZone(dc, name_pos[0], name_pos[1], name_size[0], name_size[1])
       
   607         if typetext != "" and ("negated" in self.Errors or "rising" in self.Errors or "falling" in self.Errors):
       
   608             HighlightErrorZone(dc, type_pos[0], type_pos[1], type_size[0], type_size[1])
   598         
   609         
   599 
   610 
   600 #-------------------------------------------------------------------------------
   611 #-------------------------------------------------------------------------------
   601 #                         Ladder Diagram Coil
   612 #                         Ladder Diagram Coil
   602 #-------------------------------------------------------------------------------
   613 #-------------------------------------------------------------------------------
   612         Graphic_Element.__init__(self, parent)
   623         Graphic_Element.__init__(self, parent)
   613         self.Type = type
   624         self.Type = type
   614         self.Name = name
   625         self.Name = name
   615         self.Id = id
   626         self.Id = id
   616         self.Size = wx.Size(LD_ELEMENT_SIZE[0], LD_ELEMENT_SIZE[1])
   627         self.Size = wx.Size(LD_ELEMENT_SIZE[0], LD_ELEMENT_SIZE[1])
       
   628         self.Errors = {}
   617         # Create an input and output connector
   629         # Create an input and output connector
   618         self.Input = Connector(self, "", "BOOL", wx.Point(0, self.Size[1] / 2 + 1), WEST)
   630         self.Input = Connector(self, "", "BOOL", wx.Point(0, self.Size[1] / 2 + 1), WEST)
   619         self.Output = Connector(self, "", "BOOL", wx.Point(self.Size[0], self.Size[1] / 2 + 1), EAST)
   631         self.Output = Connector(self, "", "BOOL", wx.Point(self.Size[0], self.Size[1] / 2 + 1), EAST)
   620         self.RefreshNameSize()
   632         self.RefreshNameSize()
   621         self.RefreshTypeSize()
   633         self.RefreshTypeSize()
   798         # Draw a two circle arcs for representing the coil
   810         # Draw a two circle arcs for representing the coil
   799         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)
   811         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)
   800         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)
   812         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)
   801         dc.SetLogicalFunction(wx.COPY)
   813         dc.SetLogicalFunction(wx.COPY)
   802     
   814     
       
   815     def AddError(self, infos, start, end):
       
   816         self.Errors[infos[0]] = (start[1], end[1])
       
   817     
   803     # Draws coil
   818     # Draws coil
   804     def Draw(self, dc):
   819     def Draw(self, dc):
   805         Graphic_Element.Draw(self, dc)
   820         Graphic_Element.Draw(self, dc)
   806         dc.SetPen(wx.Pen(wx.BLACK, 2, wx.SOLID))
   821         dc.SetPen(wx.Pen(wx.BLACK, 2, wx.SOLID))
   807         dc.SetBrush(wx.TRANSPARENT_BRUSH)
   822         dc.SetBrush(wx.TRANSPARENT_BRUSH)
   837             name_size = self.NameSize
   852             name_size = self.NameSize
   838             if typetext != "":
   853             if typetext != "":
   839                 type_size = self.TypeSize
   854                 type_size = self.TypeSize
   840             
   855             
   841         # Draw coil name
   856         # Draw coil name
   842         dc.DrawText(self.Name, self.Pos.x + (self.Size[0] - name_size[0]) / 2,
   857         name_pos = (self.Pos.x + (self.Size[0] - name_size[0]) / 2,
   843                 self.Pos.y - (name_size[1] + 2))
   858                     self.Pos.y - (name_size[1] + 2))
       
   859         dc.DrawText(self.Name, name_pos[0], name_pos[1])
   844         # Draw the modifier symbol in the middle of coil
   860         # Draw the modifier symbol in the middle of coil
   845         if typetext != "":
   861         if typetext != "":
   846             dc.DrawText(typetext, self.Pos.x + (self.Size[0] - type_size[0]) / 2 + 1,
   862             type_pos = (self.Pos.x + (self.Size[0] - type_size[0]) / 2 + 1,
   847                     self.Pos.y + (self.Size[1] - type_size[1]) / 2)
   863                         self.Pos.y + (self.Size[1] - type_size[1]) / 2)
       
   864             dc.DrawText(typetext, type_pos[0], type_pos[1])
   848         # Draw input and output connectors
   865         # Draw input and output connectors
   849         self.Input.Draw(dc)
   866         self.Input.Draw(dc)
   850         self.Output.Draw(dc)
   867         self.Output.Draw(dc)
   851         
   868         if "reference" in self.Errors:
       
   869             HighlightErrorZone(dc, name_pos[0], name_pos[1], name_size[0], name_size[1])
       
   870         if typetext != "" and ("negated" in self.Errors or "rising" in self.Errors or "falling" in self.Errors):
       
   871             HighlightErrorZone(dc, type_pos[0], type_pos[1], type_size[0], type_size[1])
       
   872             
       
   873