graphics/GraphicCommons.py
changeset 222 8ce5c2635976
parent 213 4931959ea256
child 231 fc2d6cbb8b39
equal deleted inserted replaced
221:25f2b4924347 222:8ce5c2635976
  1184             self.GeneratePoints()
  1184             self.GeneratePoints()
  1185         else:
  1185         else:
  1186             self.Points = []
  1186             self.Points = []
  1187             self.Segments = []
  1187             self.Segments = []
  1188         self.SelectedSegment = None
  1188         self.SelectedSegment = None
       
  1189         self.Valid = True
  1189         self.Value = None
  1190         self.Value = None
  1190         self.OverStart = False
  1191         self.OverStart = False
  1191         self.OverEnd = False
  1192         self.OverEnd = False
  1192         self.ComputingType = False
  1193         self.ComputingType = False
  1193     
  1194     
  1284             if self.EndConnected:
  1285             if self.EndConnected:
  1285                 self.EndConnected.SetPen(wx.BLACK_PEN)
  1286                 self.EndConnected.SetPen(wx.BLACK_PEN)
  1286         # The segment selected is the first
  1287         # The segment selected is the first
  1287         elif segment == 0:
  1288         elif segment == 0:
  1288             if self.StartConnected:
  1289             if self.StartConnected:
  1289                 self.StartConnected.SetPen(wx.RED_PEN)
  1290                 self.StartConnected.SetPen(wx.BLUE_PEN)
  1290             if self.EndConnected:
  1291             if self.EndConnected:
  1291                 # There is only one segment
  1292                 # There is only one segment
  1292                 if len(self.Segments) == 1:
  1293                 if len(self.Segments) == 1:
  1293                     self.EndConnected.SetPen(wx.RED_PEN)
  1294                     self.EndConnected.SetPen(wx.BLUE_PEN)
  1294                 else:
  1295                 else:
  1295                     self.EndConnected.SetPen(wx.BLACK_PEN)
  1296                     self.EndConnected.SetPen(wx.BLACK_PEN)
  1296         # The segment selected is the last
  1297         # The segment selected is the last
  1297         elif segment == len(self.Segments) - 1:
  1298         elif segment == len(self.Segments) - 1:
  1298             if self.StartConnected:
  1299             if self.StartConnected:
  1299                 self.StartConnected.SetPen(wx.BLACK_PEN)
  1300                 self.StartConnected.SetPen(wx.BLACK_PEN)
  1300             if self.EndConnected:
  1301             if self.EndConnected:
  1301                 self.EndConnected.SetPen(wx.RED_PEN)
  1302                 self.EndConnected.SetPen(wx.BLUE_PEN)
  1302         self.SelectedSegment = segment
  1303         self.SelectedSegment = segment
  1303         self.Refresh()
  1304         self.Refresh()
       
  1305     
       
  1306     # Select a segment and not the whole wire. It's useful for Ladder Diagram
       
  1307     def MarkAsInvalid(self):
       
  1308         self.Valid = False
       
  1309         if self.StartConnected:
       
  1310             self.StartConnected.SetPen(wx.RED_PEN)
       
  1311         if self.EndConnected:
       
  1312             self.EndConnected.SetPen(wx.RED_PEN)
  1304     
  1313     
  1305     # Reinitialize the wire points
  1314     # Reinitialize the wire points
  1306     def ResetPoints(self):
  1315     def ResetPoints(self):
  1307         if self.StartPoint and self.EndPoint:
  1316         if self.StartPoint and self.EndPoint:
  1308             self.Points = [self.StartPoint[0], self.EndPoint[0]]
  1317             self.Points = [self.StartPoint[0], self.EndPoint[0]]
  2027             self.EndConnected.Draw(dc)
  2036             self.EndConnected.Draw(dc)
  2028         
  2037         
  2029     # Draws the wire lines and points
  2038     # Draws the wire lines and points
  2030     def Draw(self, dc):
  2039     def Draw(self, dc):
  2031         Graphic_Element.Draw(self, dc)
  2040         Graphic_Element.Draw(self, dc)
  2032         dc.SetPen(wx.BLACK_PEN)
  2041         if self.Valid:
       
  2042             dc.SetPen(wx.BLACK_PEN)
       
  2043         else:
       
  2044             dc.SetPen(wx.RED_PEN)
  2033         dc.SetBrush(wx.BLACK_BRUSH)
  2045         dc.SetBrush(wx.BLACK_BRUSH)
  2034         # Draw the start and end points if they are not connected or the mouse is over them
  2046         # Draw the start and end points if they are not connected or the mouse is over them
  2035         if len(self.Points) > 0 and (not self.StartConnected or self.OverStart):
  2047         if len(self.Points) > 0 and (not self.StartConnected or self.OverStart):
  2036             dc.DrawCircle(self.Points[0].x, self.Points[0].y, POINT_RADIUS)
  2048             dc.DrawCircle(self.Points[0].x, self.Points[0].y, POINT_RADIUS)
  2037         if len(self.Points) > 1 and (not self.EndConnected or self.OverEnd):
  2049         if len(self.Points) > 1 and (not self.EndConnected or self.OverEnd):