graphics/SFC_Objects.py
changeset 2 93bc4c2cf376
parent 1 e9d01d824086
child 5 f8652b073e84
equal deleted inserted replaced
1:e9d01d824086 2:93bc4c2cf376
   444         if self.Condition != "":
   444         if self.Condition != "":
   445             text_width, text_height = dc.GetTextExtent(self.Condition)
   445             text_width, text_height = dc.GetTextExtent(self.Condition)
   446         else:
   446         else:
   447             text_width, text_height = dc.GetTextExtent("Transition")
   447             text_width, text_height = dc.GetTextExtent("Transition")
   448         # Calculate the bounding box size
   448         # Calculate the bounding box size
   449         bbx_width = self.Size[0] + CONNECTOR_SIZE + 2 + text_width
   449         bbx_width = self.Size[0] + 5 + text_width
   450         bbx_y = self.Pos.y - max(0, (text_height - self.Size[1]) / 2)
   450         bbx_y = self.Pos.y - max(0, (text_height - 5 - self.Size[1]) / 2)
   451         bbx_height = max(self.Size[1], text_height)
   451         bbx_height = max(self.Size[1], text_height)
   452         self.BoundingBox = wxRect(self.Pos.x, bbx_y, bbx_width + 1, bbx_height + 1)
   452         self.BoundingBox = wxRect(self.Pos.x, bbx_y, bbx_width + 1, bbx_height - 4)
   453         
   453         
   454     # Returns the connector connected to input
   454     # Returns the connector connected to input
   455     def GetPreviousConnector(self):
   455     def GetPreviousConnector(self):
   456         wires = self.Input.GetWires()
   456         wires = self.Input.GetWires()
   457         if len(wires) == 1:
   457         if len(wires) == 1:
   622             text_width, text_height = dc.GetTextExtent(self.Condition)
   622             text_width, text_height = dc.GetTextExtent(self.Condition)
   623             condition = self.Condition
   623             condition = self.Condition
   624         else:
   624         else:
   625             text_width, text_height = dc.GetTextExtent("Transition")
   625             text_width, text_height = dc.GetTextExtent("Transition")
   626             condition = "Transition"
   626             condition = "Transition"
   627         dc.DrawText(condition, self.Pos.x + self.Size[0] + CONNECTOR_SIZE + 2,
   627         dc.DrawText(condition, self.Pos.x + self.Size[0] + 5,
   628                     self.Pos.y + (self.Size[1] - text_height) / 2)
   628                     self.Pos.y + (self.Size[1] - text_height) / 2)
   629         # Draw input and output connectors
   629         # Draw input and output connectors
   630         self.Input.Draw(dc)
   630         self.Input.Draw(dc)
   631         self.Output.Draw(dc)
   631         self.Output.Draw(dc)
   632         Graphic_Element.Draw(self, dc)
   632         Graphic_Element.Draw(self, dc)
   732         return rect.InsideXY(pt.x, pt.y) or self.TestConnector(pt, False) != None
   732         return rect.InsideXY(pt.x, pt.y) or self.TestConnector(pt, False) != None
   733     
   733     
   734     # Refresh the divergence bounding box
   734     # Refresh the divergence bounding box
   735     def RefreshBoundingBox(self):
   735     def RefreshBoundingBox(self):
   736         if self.Type in [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE]:
   736         if self.Type in [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE]:
   737             self.BoundingBox = wxRect(self.Pos.x, self.Pos.y - CONNECTOR_SIZE, 
   737             self.BoundingBox = wxRect(self.Pos.x, self.Pos.y - 2, 
   738                 self.Size[0] + 1, self.Size[1] + CONNECTOR_SIZE * 2 + 1)
   738                 self.Size[0] + 1, self.Size[1] + 5)
   739         elif self.Type in [SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE]:
   739         elif self.Type in [SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE]:
   740             self.BoundingBox = wxRect(self.Pos.x - SFC_SIMULTANEOUS_SEQUENCE_EXTRA, self.Pos.y - CONNECTOR_SIZE, 
   740             self.BoundingBox = wxRect(self.Pos.x - SFC_SIMULTANEOUS_SEQUENCE_EXTRA, self.Pos.y - 2, 
   741                 self.Size[0] + 2 * SFC_SIMULTANEOUS_SEQUENCE_EXTRA + 1, self.Size[1] + CONNECTOR_SIZE * 2 + 1)
   741                 self.Size[0] + 2 * SFC_SIMULTANEOUS_SEQUENCE_EXTRA + 1, self.Size[1] + 5)
   742     
   742     
   743     # Refresh the position of wires connected to divergence
   743     # Refresh the position of wires connected to divergence
   744     def RefreshConnected(self, exclude = []):
   744     def RefreshConnected(self, exclude = []):
   745         for input in self.Inputs:
   745         for input in self.Inputs:
   746             input.MoveConnected(exclude)
   746             input.MoveConnected(exclude)
  1210         self.ColSize = [0, 0, 0]
  1210         self.ColSize = [0, 0, 0]
  1211         for action in self.Actions:
  1211         for action in self.Actions:
  1212             width, height = dc.GetTextExtent(action["qualifier"])
  1212             width, height = dc.GetTextExtent(action["qualifier"])
  1213             self.ColSize[0] = max(self.ColSize[0], width + 10)
  1213             self.ColSize[0] = max(self.ColSize[0], width + 10)
  1214             if "duration" in action:
  1214             if "duration" in action:
  1215                 width, height = dc.GetTextExtent("T#%s"%action["duration"])
  1215                 width, height = dc.GetTextExtent(action["duration"])
  1216                 self.ColSize[0] = max(self.ColSize[0], width + 10)
  1216                 self.ColSize[0] = max(self.ColSize[0], width + 10)
  1217             width, height = dc.GetTextExtent(action["value"])
  1217             width, height = dc.GetTextExtent(action["value"])
  1218             self.ColSize[1] = max(self.ColSize[1], width + 10)
  1218             self.ColSize[1] = max(self.ColSize[1], width + 10)
  1219             if "indicator" in action and action["indicator"] != "":
  1219             if "indicator" in action and action["indicator"] != "":
  1220                 width, height = dc.GetTextExtent(action["indicator"])
  1220                 width, height = dc.GetTextExtent(action["indicator"])
  1221                 self.ColSize[2] = max(self.ColSize[2], width + 10)
  1221                 self.ColSize[2] = max(self.ColSize[2], width + 10)
  1222         self.Size = wxSize(max(self.ColSize[0] + self.ColSize[1] + self.ColSize[2],
  1222         self.Size = wxSize(max(self.ColSize[0] + self.ColSize[1] + self.ColSize[2],
  1223             self.Size[0]), len(self.Actions) * SFC_ACTION_MIN_SIZE[1])
  1223             SFC_ACTION_MIN_SIZE[0]), len(self.Actions) * SFC_ACTION_MIN_SIZE[1])
  1224         self.RefreshBoundingBox()
  1224         self.RefreshBoundingBox()
  1225         if self.Input:
  1225         if self.Input:
  1226             wires = self.Input.GetWires()
  1226             wires = self.Input.GetWires()
  1227             if len(wires) == 1:
  1227             if len(wires) == 1:
  1228                 input_block = wires[0][0].EndConnected.GetParentBlock()
  1228                 input_block = wires[0][0].EndConnected.GetParentBlock()
  1233     def GetActions(self):
  1233     def GetActions(self):
  1234         return self.Actions
  1234         return self.Actions
  1235     
  1235     
  1236     # Returns the action block minimum size
  1236     # Returns the action block minimum size
  1237     def GetMinSize(self):
  1237     def GetMinSize(self):
  1238         return SFC_ACTION_MIN_SIZE[0], len(self.Actions) * SFC_ACTION_MIN_SIZE[1]
  1238         return max(self.ColSize[0] + self.ColSize[1] + self.ColSize[2],
       
  1239             SFC_ACTION_MIN_SIZE[0]), len(self.Actions) * SFC_ACTION_MIN_SIZE[1]
  1239     
  1240     
  1240     # Method called when a LeftDClick event have been generated
  1241     # Method called when a LeftDClick event have been generated
  1241     def OnLeftDClick(self, event, scaling):
  1242     def OnLeftDClick(self, event, scaling):
  1242         # Edit the action block properties
  1243         # Edit the action block properties
  1243         self.Parent.EditActionBlockContent(self)
  1244         self.Parent.EditActionBlockContent(self)