63 self.Input = None |
63 self.Input = None |
64 self.Output = None |
64 self.Output = None |
65 self.Action = None |
65 self.Action = None |
66 |
66 |
67 # Make a clone of this SFC_Step |
67 # Make a clone of this SFC_Step |
68 def Clone(self, id = None, pos = None): |
68 def Clone(self, id = None, name = "Step", pos = None): |
69 step = SFC_Step(self.Parent, self.Type, self.Name, id) |
69 step = SFC_Step(self.Parent, name, self.Initial, id) |
70 step.SetSize(self.Size[0], self.Size[1]) |
70 step.SetSize(self.Size[0], self.Size[1]) |
71 if pos is not None: |
71 if pos is not None: |
72 step.SetPosition(pos.x, pos.y) |
72 step.SetPosition(pos.x, pos.y) |
73 step.Input = self.Input.Clone(step) |
73 if self.Input: |
74 step.Output = self.Output.Clone(step) |
74 step.Input = self.Input.Clone(step) |
75 step.Action = self.Action.Clone(step) |
75 if self.Output: |
|
76 step.Output = self.Output.Clone(step) |
|
77 if self.Action: |
|
78 step.Action = self.Action.Clone(step) |
76 return step |
79 return step |
|
80 |
|
81 # Returns the RedrawRect |
|
82 def GetRedrawRect(self, movex = 0, movey = 0): |
|
83 rect = Graphic_Element.GetRedrawRect(self, movex, movey) |
|
84 if self.Input: |
|
85 rect = rect.Union(self.Input.GetRedrawRect(movex, movey)) |
|
86 if self.Output: |
|
87 rect = rect.Union(self.Output.GetRedrawRect(movex, movey)) |
|
88 if self.Action: |
|
89 rect = rect.Union(self.Action.GetRedrawRect(movex, movey)) |
|
90 if movex != 0 or movey != 0: |
|
91 if self.Input and self.Input.IsConnected(): |
|
92 rect = rect.Union(self.Input.GetConnectedRedrawRect(movex, movey)) |
|
93 if self.Output and self.Output.IsConnected(): |
|
94 rect = rect.Union(self.Output.GetConnectedRedrawRect(movex, movey)) |
|
95 if self.Action and self.Action.IsConnected(): |
|
96 rect = rect.Union(self.Action.GetConnectedRedrawRect(movex, movey)) |
|
97 return rect |
77 |
98 |
78 # Delete this step by calling the appropriate method |
99 # Delete this step by calling the appropriate method |
79 def Delete(self): |
100 def Delete(self): |
80 self.Parent.DeleteStep(self) |
101 self.Parent.DeleteStep(self) |
81 |
102 |
426 elif self.Output: |
447 elif self.Output: |
427 self.Output.RefreshWires() |
448 self.Output.RefreshWires() |
428 |
449 |
429 # Draws step |
450 # Draws step |
430 def Draw(self, dc): |
451 def Draw(self, dc): |
|
452 Graphic_Element.Draw(self, dc) |
431 dc.SetPen(wx.BLACK_PEN) |
453 dc.SetPen(wx.BLACK_PEN) |
432 dc.SetBrush(wx.WHITE_BRUSH) |
454 dc.SetBrush(wx.WHITE_BRUSH) |
433 # Draw two rectangles for representing the step |
455 # Draw two rectangles for representing the step |
434 dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
456 dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
435 if self.Initial: |
457 if self.Initial: |
485 if pos is not None: |
506 if pos is not None: |
486 transition.SetPosition(pos.x, pos.y) |
507 transition.SetPosition(pos.x, pos.y) |
487 transition.Input = self.Input.Clone(transition) |
508 transition.Input = self.Input.Clone(transition) |
488 transition.Output = self.Output.Clone(transition) |
509 transition.Output = self.Output.Clone(transition) |
489 return transition |
510 return transition |
|
511 |
|
512 # Returns the RedrawRect |
|
513 def GetRedrawRect(self, movex = 0, movey = 0): |
|
514 rect = Graphic_Element.GetRedrawRect(self, movex, movey) |
|
515 rect = rect.Union(self.Input.GetRedrawRect(movex, movey)) |
|
516 rect = rect.Union(self.Output.GetRedrawRect(movex, movey)) |
|
517 if movex != 0 or movey != 0: |
|
518 if self.Input.IsConnected(): |
|
519 rect = rect.Union(self.Input.GetConnectedRedrawRect(movex, movey)) |
|
520 if self.Output.IsConnected(): |
|
521 rect = rect.Union(self.Output.GetConnectedRedrawRect(movex, movey)) |
|
522 return rect |
490 |
523 |
491 # Forbids to change the transition size |
524 # Forbids to change the transition size |
492 def SetSize(self, width, height): |
525 def SetSize(self, width, height): |
493 if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
526 if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
494 Graphic_Element.SetSize(self, width, height) |
527 Graphic_Element.SetSize(self, width, height) |
761 else: |
794 else: |
762 self.Output.RefreshWires() |
795 self.Output.RefreshWires() |
763 |
796 |
764 # Draws transition |
797 # Draws transition |
765 def Draw(self, dc): |
798 def Draw(self, dc): |
|
799 Graphic_Element.Draw(self, dc) |
766 dc.SetPen(wx.BLACK_PEN) |
800 dc.SetPen(wx.BLACK_PEN) |
767 dc.SetBrush(wx.BLACK_BRUSH) |
801 dc.SetBrush(wx.BLACK_BRUSH) |
768 # Draw plain rectangle for representing the transition |
802 # Draw plain rectangle for representing the transition |
769 dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
803 dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
770 # Draw transition condition |
804 # Draw transition condition |
783 # Draw input and output connectors |
817 # Draw input and output connectors |
784 self.Input.Draw(dc) |
818 self.Input.Draw(dc) |
785 self.Output.Draw(dc) |
819 self.Output.Draw(dc) |
786 if self.Type == "connection": |
820 if self.Type == "connection": |
787 self.Condition.Draw(dc) |
821 self.Condition.Draw(dc) |
788 Graphic_Element.Draw(self, dc) |
|
789 |
822 |
790 |
823 |
791 #------------------------------------------------------------------------------- |
824 #------------------------------------------------------------------------------- |
792 # Sequencial Function Chart Divergence and Convergence |
825 # Sequencial Function Chart Divergence and Convergence |
793 #------------------------------------------------------------------------------- |
826 #------------------------------------------------------------------------------- |
834 if pos is not None: |
867 if pos is not None: |
835 divergence.SetPosition(pos.x, pos.y) |
868 divergence.SetPosition(pos.x, pos.y) |
836 divergence.Inputs = [input.Clone(divergence) for input in self.Inputs] |
869 divergence.Inputs = [input.Clone(divergence) for input in self.Inputs] |
837 divergence.Outputs = [output.Clone(divergence) for output in self.Outputs] |
870 divergence.Outputs = [output.Clone(divergence) for output in self.Outputs] |
838 return divergence |
871 return divergence |
|
872 |
|
873 # Returns the RedrawRect |
|
874 def GetRedrawRect(self, movex = 0, movey = 0): |
|
875 rect = Graphic_Element.GetRedrawRect(self, movex, movey) |
|
876 if movex != 0 or movey != 0: |
|
877 for input in self.Inputs: |
|
878 if input.IsConnected(): |
|
879 rect = rect.Union(input.GetConnectedRedrawRect(movex, movey)) |
|
880 for output in self.Outputs: |
|
881 if output.IsConnected(): |
|
882 rect = rect.Union(output.GetConnectedRedrawRect(movex, movey)) |
|
883 return rect |
839 |
884 |
840 # Forbids to resize the divergence |
885 # Forbids to resize the divergence |
841 def Resize(self, x, y, width, height): |
886 def Resize(self, x, y, width, height): |
842 if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
887 if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
843 Graphic_Element.Resize(self, x, y, width, height) |
888 Graphic_Element.Resize(self, x, y, width, height) |
1170 for output in self.Outputs: |
1215 for output in self.Outputs: |
1171 output.RefreshWires() |
1216 output.RefreshWires() |
1172 |
1217 |
1173 # Draws the highlightment of this element if it is highlighted |
1218 # Draws the highlightment of this element if it is highlighted |
1174 def DrawHighlightment(self, dc): |
1219 def DrawHighlightment(self, dc): |
1175 if self.Highlighted: |
1220 dc.SetPen(wx.Pen(HIGHLIGHTCOLOR)) |
1176 dc.SetPen(wx.Pen(HIGHLIGHTCOLOR)) |
1221 dc.SetBrush(wx.Brush(HIGHLIGHTCOLOR)) |
1177 dc.SetBrush(wx.Brush(HIGHLIGHTCOLOR)) |
1222 dc.SetLogicalFunction(wx.AND) |
1178 # Draw two rectangles for representing the contact |
1223 # Draw two rectangles for representing the contact |
1179 posx = self.Pos.x - 2 |
1224 posx = self.Pos.x - 2 |
1180 width = self.Size[0] + 5 |
1225 width = self.Size[0] + 5 |
1181 if self.Type in [SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE]: |
1226 if self.Type in [SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE]: |
1182 posx -= SFC_SIMULTANEOUS_SEQUENCE_EXTRA |
1227 posx -= SFC_SIMULTANEOUS_SEQUENCE_EXTRA |
1183 width += SFC_SIMULTANEOUS_SEQUENCE_EXTRA * 2 |
1228 width += SFC_SIMULTANEOUS_SEQUENCE_EXTRA * 2 |
1184 dc.DrawRectangle(posx, self.Pos.y - 2, width, self.Size[1] + 5) |
1229 dc.DrawRectangle(posx, self.Pos.y - 2, width, self.Size[1] + 5) |
|
1230 dc.SetLogicalFunction(wx.COPY) |
1185 |
1231 |
1186 # Draws divergence |
1232 # Draws divergence |
1187 def Draw(self, dc): |
1233 def Draw(self, dc): |
|
1234 Graphic_Element.Draw(self, dc) |
1188 dc.SetPen(wx.BLACK_PEN) |
1235 dc.SetPen(wx.BLACK_PEN) |
1189 dc.SetBrush(wx.BLACK_BRUSH) |
1236 dc.SetBrush(wx.BLACK_BRUSH) |
1190 # Draw plain rectangle for representing the divergence |
1237 # Draw plain rectangle for representing the divergence |
1191 if self.Type in [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE]: |
1238 if self.Type in [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE]: |
1192 dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
1239 dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
1198 # Draw inputs and outputs connectors |
1245 # Draw inputs and outputs connectors |
1199 for input in self.Inputs: |
1246 for input in self.Inputs: |
1200 input.Draw(dc) |
1247 input.Draw(dc) |
1201 for output in self.Outputs: |
1248 for output in self.Outputs: |
1202 output.Draw(dc) |
1249 output.Draw(dc) |
1203 Graphic_Element.Draw(self, dc) |
|
1204 |
1250 |
1205 |
1251 |
1206 #------------------------------------------------------------------------------- |
1252 #------------------------------------------------------------------------------- |
1207 # Sequencial Function Chart Jump to Step |
1253 # Sequencial Function Chart Jump to Step |
1208 #------------------------------------------------------------------------------- |
1254 #------------------------------------------------------------------------------- |
1232 jump.SetSize(self.Size[0], self.Size[1]) |
1278 jump.SetSize(self.Size[0], self.Size[1]) |
1233 if pos is not None: |
1279 if pos is not None: |
1234 jump.SetPosition(pos.x, pos.y) |
1280 jump.SetPosition(pos.x, pos.y) |
1235 jump.Input = self.Input.Clone(jump) |
1281 jump.Input = self.Input.Clone(jump) |
1236 return jump |
1282 return jump |
|
1283 |
|
1284 # Returns the RedrawRect |
|
1285 def GetRedrawRect(self, movex = 0, movey = 0): |
|
1286 rect = Graphic_Element.GetRedrawRect(self, movex, movey) |
|
1287 rect = rect.Union(self.Input.GetRedrawRect(movex, movey)) |
|
1288 if movex != 0 or movey != 0: |
|
1289 if self.Input.IsConnected(): |
|
1290 rect = rect.Union(self.Input.GetConnectedRedrawRect(movex, movey)) |
|
1291 return rect |
1237 |
1292 |
1238 # Forbids to change the jump size |
1293 # Forbids to change the jump size |
1239 def SetSize(self, width, height): |
1294 def SetSize(self, width, height): |
1240 if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
1295 if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
1241 Graphic_Element.SetSize(self, width, height) |
1296 Graphic_Element.SetSize(self, width, height) |
1365 if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: |
1420 if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: |
1366 self.RefreshInputModel() |
1421 self.RefreshInputModel() |
1367 |
1422 |
1368 # Draws the highlightment of this element if it is highlighted |
1423 # Draws the highlightment of this element if it is highlighted |
1369 def DrawHighlightment(self, dc): |
1424 def DrawHighlightment(self, dc): |
1370 if self.Highlighted: |
1425 dc.SetPen(wx.Pen(HIGHLIGHTCOLOR)) |
1371 dc.SetPen(wx.Pen(HIGHLIGHTCOLOR)) |
1426 dc.SetBrush(wx.Brush(HIGHLIGHTCOLOR)) |
1372 dc.SetBrush(wx.Brush(HIGHLIGHTCOLOR)) |
1427 dc.SetLogicalFunction(wx.AND) |
1373 points = [wx.Point(self.Pos.x - 3, self.Pos.y - 2), |
1428 points = [wx.Point(self.Pos.x - 3, self.Pos.y - 2), |
1374 wx.Point(self.Pos.x + self.Size[0] + 4, self.Pos.y - 2), |
1429 wx.Point(self.Pos.x + self.Size[0] + 4, self.Pos.y - 2), |
1375 wx.Point(self.Pos.x + self.Size[0] / 2, self.Pos.y + self.Size[1] + 4)] |
1430 wx.Point(self.Pos.x + self.Size[0] / 2, self.Pos.y + self.Size[1] + 4)] |
1376 dc.DrawPolygon(points) |
1431 dc.DrawPolygon(points) |
|
1432 dc.SetLogicalFunction(wx.COPY) |
1377 |
1433 |
1378 # Draws divergence |
1434 # Draws divergence |
1379 def Draw(self, dc): |
1435 def Draw(self, dc): |
|
1436 Graphic_Element.Draw(self, dc) |
1380 dc.SetPen(wx.BLACK_PEN) |
1437 dc.SetPen(wx.BLACK_PEN) |
1381 dc.SetBrush(wx.BLACK_BRUSH) |
1438 dc.SetBrush(wx.BLACK_BRUSH) |
1382 # Draw plain rectangle for representing the divergence |
1439 # Draw plain rectangle for representing the divergence |
1383 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]) |
1440 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]) |
1384 points = [wx.Point(self.Pos.x, self.Pos.y), |
1441 points = [wx.Point(self.Pos.x, self.Pos.y), |
1390 dc.DrawText(self.Target, self.Pos.x + self.Size[0] + 2, |
1447 dc.DrawText(self.Target, self.Pos.x + self.Size[0] + 2, |
1391 self.Pos.y + (self.Size[1] - text_height) / 2) |
1448 self.Pos.y + (self.Size[1] - text_height) / 2) |
1392 # Draw input connector |
1449 # Draw input connector |
1393 if self.Input: |
1450 if self.Input: |
1394 self.Input.Draw(dc) |
1451 self.Input.Draw(dc) |
1395 Graphic_Element.Draw(self, dc) |
|
1396 |
1452 |
1397 |
1453 |
1398 #------------------------------------------------------------------------------- |
1454 #------------------------------------------------------------------------------- |
1399 # Sequencial Function Chart Action Block |
1455 # Sequencial Function Chart Action Block |
1400 #------------------------------------------------------------------------------- |
1456 #------------------------------------------------------------------------------- |
1425 action_block = SFC_ActionBlock(self.Parent, actions, id) |
1481 action_block = SFC_ActionBlock(self.Parent, actions, id) |
1426 action_block.SetSize(self.Size[0], self.Size[1]) |
1482 action_block.SetSize(self.Size[0], self.Size[1]) |
1427 if pos is not None: |
1483 if pos is not None: |
1428 action_block.SetPosition(pos.x, pos.y) |
1484 action_block.SetPosition(pos.x, pos.y) |
1429 action_block.Input = self.Input.Clone(action_block) |
1485 action_block.Input = self.Input.Clone(action_block) |
1430 return jump |
1486 return action_block |
|
1487 |
|
1488 # Returns the RedrawRect |
|
1489 def GetRedrawRect(self, movex = 0, movey = 0): |
|
1490 rect = Graphic_Element.GetRedrawRect(self, movex, movey) |
|
1491 rect = rect.Union(self.Input.GetRedrawRect(movex, movey)) |
|
1492 if movex != 0 or movey != 0: |
|
1493 if self.Input.IsConnected(): |
|
1494 rect = rect.Union(self.Input.GetConnectedRedrawRect(movex, movey)) |
|
1495 return rect |
1431 |
1496 |
1432 # Returns the number of action lines |
1497 # Returns the number of action lines |
1433 def GetLineNumber(self): |
1498 def GetLineNumber(self): |
1434 return len(self.Actions) |
1499 return len(self.Actions) |
1435 |
1500 |
1455 def Clean(self): |
1520 def Clean(self): |
1456 self.Input.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
1521 self.Input.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
1457 |
1522 |
1458 # Refresh the action block bounding box |
1523 # Refresh the action block bounding box |
1459 def RefreshBoundingBox(self): |
1524 def RefreshBoundingBox(self): |
1460 self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y, self.Size[0], self.Size[1]) |
1525 self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
1461 |
1526 |
1462 # Refresh the position of wires connected to action block |
1527 # Refresh the position of wires connected to action block |
1463 def RefreshConnected(self, exclude = []): |
1528 def RefreshConnected(self, exclude = []): |
1464 self.Input.MoveConnected(exclude) |
1529 self.Input.MoveConnected(exclude) |
1465 |
1530 |
1555 def RefreshModel(self, move=True): |
1620 def RefreshModel(self, move=True): |
1556 self.Parent.RefreshActionBlockModel(self) |
1621 self.Parent.RefreshActionBlockModel(self) |
1557 |
1622 |
1558 # Draws divergence |
1623 # Draws divergence |
1559 def Draw(self, dc): |
1624 def Draw(self, dc): |
|
1625 Graphic_Element.Draw(self, dc) |
1560 dc.SetPen(wx.BLACK_PEN) |
1626 dc.SetPen(wx.BLACK_PEN) |
1561 dc.SetBrush(wx.WHITE_BRUSH) |
1627 dc.SetBrush(wx.WHITE_BRUSH) |
1562 colsize = [self.ColSize[0], self.Size[0] - self.ColSize[0] - self.ColSize[2], self.ColSize[2]] |
1628 colsize = [self.ColSize[0], self.Size[0] - self.ColSize[0] - self.ColSize[2], self.ColSize[2]] |
1563 # Draw plain rectangle for representing the action block |
1629 # Draw plain rectangle for representing the action block |
1564 dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
1630 dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
1588 text_width, text_height = dc.GetTextExtent(action["indicator"]) |
1654 text_width, text_height = dc.GetTextExtent(action["indicator"]) |
1589 dc.DrawText(action["indicator"], self.Pos.x + colsize[0] + colsize[1] + (colsize[2] - text_width) / 2, |
1655 dc.DrawText(action["indicator"], self.Pos.x + colsize[0] + colsize[1] + (colsize[2] - text_width) / 2, |
1590 self.Pos.y + i * line_size + (line_size - text_height) / 2) |
1656 self.Pos.y + i * line_size + (line_size - text_height) / 2) |
1591 # Draw input connector |
1657 # Draw input connector |
1592 self.Input.Draw(dc) |
1658 self.Input.Draw(dc) |
1593 Graphic_Element.Draw(self, dc) |
|
1594 |
1659 |