44 class SFC_Step(Graphic_Element): |
44 class SFC_Step(Graphic_Element): |
45 |
45 |
46 # Create a new step |
46 # Create a new step |
47 def __init__(self, parent, name, initial = False, id = None): |
47 def __init__(self, parent, name, initial = False, id = None): |
48 Graphic_Element.__init__(self, parent) |
48 Graphic_Element.__init__(self, parent) |
49 self.Name = name |
49 self.SetName(name) |
50 self.Initial = initial |
50 self.Initial = initial |
51 self.Id = id |
51 self.Id = id |
52 self.Size = wx.Size(SFC_STEP_DEFAULT_SIZE[0], SFC_STEP_DEFAULT_SIZE[1]) |
52 self.Size = wx.Size(SFC_STEP_DEFAULT_SIZE[0], SFC_STEP_DEFAULT_SIZE[1]) |
53 # Create an input and output connector |
53 # Create an input and output connector |
54 if not self.Initial: |
54 if not self.Initial: |
106 self.Input.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
106 self.Input.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
107 if self.Output: |
107 if self.Output: |
108 self.Output.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
108 self.Output.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
109 if self.Action: |
109 if self.Action: |
110 self.Action.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
110 self.Action.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
|
111 |
|
112 # Refresh the size of text for name |
|
113 def RefreshNameSize(self): |
|
114 self.NameSize = self.Parent.GetTextExtent(self.Name) |
111 |
115 |
112 # Add output connector to step |
116 # Add output connector to step |
113 def AddInput(self): |
117 def AddInput(self): |
114 if not self.Input: |
118 if not self.Input: |
115 self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH) |
119 self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH) |
457 # Draws step |
462 # Draws step |
458 def Draw(self, dc): |
463 def Draw(self, dc): |
459 Graphic_Element.Draw(self, dc) |
464 Graphic_Element.Draw(self, dc) |
460 dc.SetPen(wx.BLACK_PEN) |
465 dc.SetPen(wx.BLACK_PEN) |
461 dc.SetBrush(wx.WHITE_BRUSH) |
466 dc.SetBrush(wx.WHITE_BRUSH) |
|
467 |
|
468 if getattr(dc, "printing", False): |
|
469 name_size = dc.GetTextExtent(self.Name) |
|
470 else: |
|
471 name_size = self.NameSize |
|
472 |
462 # Draw two rectangles for representing the step |
473 # Draw two rectangles for representing the step |
463 dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
474 dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
464 if self.Initial: |
475 if self.Initial: |
465 dc.DrawRectangle(self.Pos.x + 2, self.Pos.y + 2, self.Size[0] - 3, self.Size[1] - 3) |
476 dc.DrawRectangle(self.Pos.x + 2, self.Pos.y + 2, self.Size[0] - 3, self.Size[1] - 3) |
466 # Draw step name |
477 # Draw step name |
467 namewidth, nameheight = dc.GetTextExtent(self.Name) |
478 dc.DrawText(self.Name, self.Pos.x + (self.Size[0] - name_size[0]) / 2, |
468 dc.DrawText(self.Name, self.Pos.x + (self.Size[0] - namewidth) / 2, |
479 self.Pos.y + (self.Size[1] - name_size[1]) / 2) |
469 self.Pos.y + (self.Size[1] - nameheight) / 2) |
|
470 # Draw input and output connectors |
480 # Draw input and output connectors |
471 if self.Input: |
481 if self.Input: |
472 self.Input.Draw(dc) |
482 self.Input.Draw(dc) |
473 if self.Output: |
483 if self.Output: |
474 self.Output.Draw(dc) |
484 self.Output.Draw(dc) |
813 # Draws transition |
823 # Draws transition |
814 def Draw(self, dc): |
824 def Draw(self, dc): |
815 Graphic_Element.Draw(self, dc) |
825 Graphic_Element.Draw(self, dc) |
816 dc.SetPen(wx.BLACK_PEN) |
826 dc.SetPen(wx.BLACK_PEN) |
817 dc.SetBrush(wx.BLACK_BRUSH) |
827 dc.SetBrush(wx.BLACK_BRUSH) |
|
828 |
|
829 if getattr(dc, "printing", False): |
|
830 if self.Type != "connection": |
|
831 condition_size = dc.GetTextExtent(self.Condition) |
|
832 if self.Priority != 0: |
|
833 priority_size = dc.GetTextExtent(str(self.Priority)) |
|
834 else: |
|
835 if self.Type != "connection": |
|
836 condition_size = self.ConditionSize |
|
837 if self.Priority != 0: |
|
838 priority_size = self.PrioritySize |
|
839 |
818 # Draw plain rectangle for representing the transition |
840 # Draw plain rectangle for representing the transition |
819 dc.DrawRectangle(self.Pos.x, |
841 dc.DrawRectangle(self.Pos.x, |
820 self.Pos.y + (self.Size[1] - SFC_TRANSITION_SIZE[1])/2, |
842 self.Pos.y + (self.Size[1] - SFC_TRANSITION_SIZE[1])/2, |
821 self.Size[0] + 1, |
843 self.Size[0] + 1, |
822 SFC_TRANSITION_SIZE[1] + 1) |
844 SFC_TRANSITION_SIZE[1] + 1) |
823 vertical_line_x = self.Input.GetPosition()[0] |
845 vertical_line_x = self.Input.GetPosition()[0] |
824 dc.DrawLine(vertical_line_x, self.Pos.y, vertical_line_x, self.Pos.y + self.Size[1] + 1) |
846 dc.DrawLine(vertical_line_x, self.Pos.y, vertical_line_x, self.Pos.y + self.Size[1] + 1) |
825 # Draw transition condition |
847 # Draw transition condition |
826 if self.Type != "connection": |
848 if self.Type != "connection": |
827 text_width, text_height = self.ConditionSize |
|
828 if self.Condition != "": |
849 if self.Condition != "": |
829 condition = self.Condition |
850 condition = self.Condition |
830 else: |
851 else: |
831 condition = "Transition" |
852 condition = "Transition" |
832 dc.DrawText(condition, self.Pos.x + self.Size[0] + 5, |
853 dc.DrawText(condition, self.Pos.x + self.Size[0] + 5, |
833 self.Pos.y + (self.Size[1] - text_height) / 2) |
854 self.Pos.y + (self.Size[1] - condition_size[1]) / 2) |
834 # Draw priority number |
855 # Draw priority number |
835 if self.Priority != 0: |
856 if self.Priority != 0: |
836 priority_width, priority_height = self.PrioritySize |
857 dc.DrawText(str(self.Priority), self.Pos.x, self.Pos.y - priority_size[1] - 2) |
837 dc.DrawText(str(self.Priority), self.Pos.x, self.Pos.y - self.PrioritySize[1] - 2) |
|
838 # Draw input and output connectors |
858 # Draw input and output connectors |
839 self.Input.Draw(dc) |
859 self.Input.Draw(dc) |
840 self.Output.Draw(dc) |
860 self.Output.Draw(dc) |
841 if self.Type == "connection": |
861 if self.Type == "connection": |
842 self.Condition.Draw(dc) |
862 self.Condition.Draw(dc) |
1281 class SFC_Jump(Graphic_Element): |
1301 class SFC_Jump(Graphic_Element): |
1282 |
1302 |
1283 # Create a new jump |
1303 # Create a new jump |
1284 def __init__(self, parent, target, id = None): |
1304 def __init__(self, parent, target, id = None): |
1285 Graphic_Element.__init__(self, parent) |
1305 Graphic_Element.__init__(self, parent) |
1286 self.Target = target |
1306 self.SetTarget(target) |
1287 self.Id = id |
1307 self.Id = id |
1288 self.Size = wx.Size(SFC_JUMP_SIZE[0], SFC_JUMP_SIZE[1]) |
1308 self.Size = wx.Size(SFC_JUMP_SIZE[0], SFC_JUMP_SIZE[1]) |
1289 # Create an input and output connector |
1309 # Create an input and output connector |
1290 self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH, onlyone = True) |
1310 self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH, onlyone = True) |
1291 |
1311 |
1327 |
1347 |
1328 # Unconnect input |
1348 # Unconnect input |
1329 def Clean(self): |
1349 def Clean(self): |
1330 self.Input.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
1350 self.Input.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
1331 |
1351 |
|
1352 # Refresh the size of text for target |
|
1353 def RefreshTargetSize(self): |
|
1354 self.TargetSize = self.Parent.GetTextExtent(self.Target) |
|
1355 |
1332 # Refresh the jump bounding box |
1356 # Refresh the jump bounding box |
1333 def RefreshBoundingBox(self): |
1357 def RefreshBoundingBox(self): |
1334 text_width, text_height = self.Parent.GetTextExtent(self.Target) |
1358 text_width, text_height = self.Parent.GetTextExtent(self.Target) |
1335 # Calculate the bounding box size |
1359 # Calculate the bounding box size |
1336 bbx_width = self.Size[0] + 2 + text_width |
1360 bbx_width = self.Size[0] + 2 + text_width |
1460 # Draws divergence |
1485 # Draws divergence |
1461 def Draw(self, dc): |
1486 def Draw(self, dc): |
1462 Graphic_Element.Draw(self, dc) |
1487 Graphic_Element.Draw(self, dc) |
1463 dc.SetPen(wx.BLACK_PEN) |
1488 dc.SetPen(wx.BLACK_PEN) |
1464 dc.SetBrush(wx.BLACK_BRUSH) |
1489 dc.SetBrush(wx.BLACK_BRUSH) |
|
1490 |
|
1491 if getattr(dc, "printing", False): |
|
1492 target_size = dc.GetTextExtent(self.Target) |
|
1493 else: |
|
1494 target_size = self.TargetSize |
|
1495 |
1465 # Draw plain rectangle for representing the divergence |
1496 # Draw plain rectangle for representing the divergence |
1466 dc.DrawLine(self.Pos.x + self.Size[0] / 2, self.Pos.y, self.Pos.x + self.Size[0] / 2, self.Pos.y + self.Size[1]) |
1497 dc.DrawLine(self.Pos.x + self.Size[0] / 2, self.Pos.y, self.Pos.x + self.Size[0] / 2, self.Pos.y + self.Size[1]) |
1467 points = [wx.Point(self.Pos.x, self.Pos.y), |
1498 points = [wx.Point(self.Pos.x, self.Pos.y), |
1468 wx.Point(self.Pos.x + self.Size[0] / 2, self.Pos.y + self.Size[1] / 3), |
1499 wx.Point(self.Pos.x + self.Size[0] / 2, self.Pos.y + self.Size[1] / 3), |
1469 wx.Point(self.Pos.x + self.Size[0], self.Pos.y), |
1500 wx.Point(self.Pos.x + self.Size[0], self.Pos.y), |
1470 wx.Point(self.Pos.x + self.Size[0] / 2, self.Pos.y + self.Size[1])] |
1501 wx.Point(self.Pos.x + self.Size[0] / 2, self.Pos.y + self.Size[1])] |
1471 dc.DrawPolygon(points) |
1502 dc.DrawPolygon(points) |
1472 text_width, text_height = dc.GetTextExtent(self.Target) |
|
1473 dc.DrawText(self.Target, self.Pos.x + self.Size[0] + 2, |
1503 dc.DrawText(self.Target, self.Pos.x + self.Size[0] + 2, |
1474 self.Pos.y + (self.Size[1] - text_height) / 2) |
1504 self.Pos.y + (self.Size[1] - target_size[1]) / 2) |
1475 # Draw input connector |
1505 # Draw input connector |
1476 if self.Input: |
1506 if self.Input: |
1477 self.Input.Draw(dc) |
1507 self.Input.Draw(dc) |
1478 |
1508 |
1479 |
1509 |