25 import wx |
25 import wx |
26 from types import * |
26 from types import * |
27 |
27 |
28 from Viewer import * |
28 from Viewer import * |
29 |
29 |
|
30 if wx.VERSION >= (2, 8, 0): |
|
31 import wx.aui |
|
32 |
|
33 class SFC_MDIViewer(wx.aui.AuiMDIChildFrame): |
|
34 def __init__(self, parent, tagname, window, controler): |
|
35 wx.aui.AuiMDIChildFrame.__init__(self, parent, -1, title = "") |
|
36 |
|
37 sizer = wx.BoxSizer(wx.HORIZONTAL) |
|
38 |
|
39 self.Viewer = SFC_Viewer(self, tagname, window, controler) |
|
40 |
|
41 sizer.AddWindow(self.Viewer, 1, border=0, flag=wx.GROW) |
|
42 |
|
43 self.SetSizer(sizer) |
|
44 |
|
45 def GetViewer(self): |
|
46 return self.Viewer |
|
47 |
30 class SFC_Viewer(Viewer): |
48 class SFC_Viewer(Viewer): |
31 |
49 |
32 def __init__(self, parent, window, controler): |
50 def __init__(self, parent, tagname, window, controler): |
33 Viewer.__init__(self, parent, window, controler) |
51 Viewer.__init__(self, parent, tagname, window, controler) |
34 self.CurrentLanguage = "SFC" |
52 self.CurrentLanguage = "SFC" |
35 |
53 |
36 def ConnectConnectors(self, start, end): |
54 def ConnectConnectors(self, start, end): |
37 startpoint = [start.GetPosition(False), start.GetDirection()] |
55 startpoint = [start.GetPosition(False), start.GetDirection()] |
38 endpoint = [end.GetPosition(False), end.GetDirection()] |
56 endpoint = [end.GetPosition(False), end.GetDirection()] |
56 previous.RefreshConnectedPosition(connector) |
74 previous.RefreshConnectedPosition(connector) |
57 else: |
75 else: |
58 previous.RefreshOutputPosition() |
76 previous.RefreshOutputPosition() |
59 wire.SetPoints([wx.Point(pos.x, pos.y + GetWireSize(previous)), wx.Point(pos.x, pos.y)]) |
77 wire.SetPoints([wx.Point(pos.x, pos.y + GetWireSize(previous)), wx.Point(pos.x, pos.y)]) |
60 self.AddBlock(transition) |
78 self.AddBlock(transition) |
61 self.Controler.AddCurrentElementEditingTransition(id) |
79 self.Controler.AddEditedElementTransition(self.TagName, id) |
62 self.RefreshTransitionModel(transition) |
80 self.RefreshTransitionModel(transition) |
63 if next: |
81 if next: |
64 wire = self.ConnectConnectors(next, transition_connectors["output"]) |
82 wire = self.ConnectConnectors(next, transition_connectors["output"]) |
65 pos = transition_connectors["output"].GetPosition(False) |
83 pos = transition_connectors["output"].GetPosition(False) |
66 next_block = next.GetParentBlock() |
84 next_block = next.GetParentBlock() |
88 next = output_wire.StartConnected |
106 next = output_wire.StartConnected |
89 output_wire.Clean() |
107 output_wire.Clean() |
90 self.RemoveWire(output_wire) |
108 self.RemoveWire(output_wire) |
91 transition.Clean() |
109 transition.Clean() |
92 self.RemoveBlock(transition) |
110 self.RemoveBlock(transition) |
93 self.Controler.RemoveCurrentElementEditingInstance(transition.GetId()) |
111 self.Controler.RemoveEditedElementInstance(self.TagName, transition.GetId()) |
94 wire = self.ConnectConnectors(next, previous) |
112 wire = self.ConnectConnectors(next, previous) |
95 return wire |
113 return wire |
96 |
114 |
97 def CreateStep(self, name, connector, next = None): |
115 def CreateStep(self, name, connector, next = None): |
98 previous = connector.GetParentBlock() |
116 previous = connector.GetParentBlock() |
110 previous.RefreshConnectedPosition(connector) |
128 previous.RefreshConnectedPosition(connector) |
111 else: |
129 else: |
112 previous.RefreshOutputPosition() |
130 previous.RefreshOutputPosition() |
113 wire.SetPoints([wx.Point(pos.x, pos.y + GetWireSize(previous)), wx.Point(pos.x, pos.y)]) |
131 wire.SetPoints([wx.Point(pos.x, pos.y + GetWireSize(previous)), wx.Point(pos.x, pos.y)]) |
114 self.AddBlock(step) |
132 self.AddBlock(step) |
115 self.Controler.AddCurrentElementEditingStep(id) |
133 self.Controler.AddEditedElementStep(self.TagName, id) |
116 self.RefreshStepModel(step) |
134 self.RefreshStepModel(step) |
117 if next: |
135 if next: |
118 wire = self.ConnectConnectors(next, step_connectors["output"]) |
136 wire = self.ConnectConnectors(next, step_connectors["output"]) |
119 pos = step_connectors["output"].GetPosition(False) |
137 pos = step_connectors["output"].GetPosition(False) |
120 next_block = next.GetParentBlock() |
138 next_block = next.GetParentBlock() |
372 #------------------------------------------------------------------------------- |
390 #------------------------------------------------------------------------------- |
373 |
391 |
374 def AddInitialStep(self, pos): |
392 def AddInitialStep(self, pos): |
375 dialog = StepNameDialog(self.ParentWindow, "Add a new initial step", "Please enter step name", "", wx.OK|wx.CANCEL) |
393 dialog = StepNameDialog(self.ParentWindow, "Add a new initial step", "Please enter step name", "", wx.OK|wx.CANCEL) |
376 dialog.SetPouNames(self.Controler.GetProjectPouNames()) |
394 dialog.SetPouNames(self.Controler.GetProjectPouNames()) |
377 dialog.SetVariables(self.Controler.GetCurrentElementEditingInterfaceVars()) |
395 dialog.SetVariables(self.Controler.GetEditedElementInterfaceVars(self.TagName)) |
378 dialog.SetStepNames([block.GetName() for block in self.Blocks if isinstance(block, SFC_Step)]) |
396 dialog.SetStepNames([block.GetName() for block in self.Blocks if isinstance(block, SFC_Step)]) |
379 if dialog.ShowModal() == wx.ID_OK: |
397 if dialog.ShowModal() == wx.ID_OK: |
380 id = self.GetNewId() |
398 id = self.GetNewId() |
381 name = dialog.GetValue() |
399 name = dialog.GetValue() |
382 step = SFC_Step(self, name, True, id) |
400 step = SFC_Step(self, name, True, id) |
383 min_width, min_height = step.GetMinSize() |
401 min_width, min_height = step.GetMinSize() |
384 step.SetPosition(pos.x, pos.y) |
402 step.SetPosition(pos.x, pos.y) |
385 width, height = step.GetSize() |
403 width, height = step.GetSize() |
386 step.SetSize(max(min_width, width), max(min_height, height)) |
404 step.SetSize(max(min_width, width), max(min_height, height)) |
387 self.AddBlock(step) |
405 self.AddBlock(step) |
388 self.Controler.AddCurrentElementEditingStep(id) |
406 self.Controler.AddEditedElementStep(self.TagName, id) |
389 self.RefreshStepModel(step) |
407 self.RefreshStepModel(step) |
390 self.RefreshBuffer() |
408 self.RefreshBuffer() |
391 self.RefreshScrollBars() |
409 self.RefreshScrollBars() |
392 self.Refresh() |
410 self.Refresh() |
393 dialog.Destroy() |
411 dialog.Destroy() |
394 |
412 |
395 def AddStep(self): |
413 def AddStep(self): |
396 if self.SelectedElement in self.Wires or isinstance(self.SelectedElement, SFC_Step): |
414 if self.SelectedElement in self.Wires or isinstance(self.SelectedElement, SFC_Step): |
397 dialog = StepNameDialog(self.ParentWindow, "Add a new step", "Please enter step name", "", wx.OK|wx.CANCEL) |
415 dialog = StepNameDialog(self.ParentWindow, "Add a new step", "Please enter step name", "", wx.OK|wx.CANCEL) |
398 dialog.SetPouNames(self.Controler.GetProjectPouNames()) |
416 dialog.SetPouNames(self.Controler.GetProjectPouNames()) |
399 dialog.SetVariables(self.Controler.GetCurrentElementEditingInterfaceVars()) |
417 dialog.SetVariables(self.Controler.GetEditedElementInterfaceVars(self.TagName)) |
400 dialog.SetStepNames([block.GetName() for block in self.Blocks if isinstance(block, SFC_Step)]) |
418 dialog.SetStepNames([block.GetName() for block in self.Blocks if isinstance(block, SFC_Step)]) |
401 if dialog.ShowModal() == wx.ID_OK: |
419 if dialog.ShowModal() == wx.ID_OK: |
402 name = dialog.GetValue() |
420 name = dialog.GetValue() |
403 if self.IsWire(self.SelectedElement): |
421 if self.IsWire(self.SelectedElement): |
404 self.SelectedElement.SetSelectedSegment(None) |
422 self.SelectedElement.SetSelectedSegment(None) |
450 if isinstance(self.SelectedElement, SFC_Step): |
468 if isinstance(self.SelectedElement, SFC_Step): |
451 connectors = self.SelectedElement.GetConnectors() |
469 connectors = self.SelectedElement.GetConnectors() |
452 if not connectors["action"]: |
470 if not connectors["action"]: |
453 dialog = ActionBlockDialog(self.ParentWindow) |
471 dialog = ActionBlockDialog(self.ParentWindow) |
454 dialog.SetQualifierList(self.Controler.GetQualifierTypes()) |
472 dialog.SetQualifierList(self.Controler.GetQualifierTypes()) |
455 dialog.SetActionList(self.Controler.GetCurrentElementEditingActions()) |
473 dialog.SetActionList(self.Controler.GetEditedElementActions(self.TagName)) |
456 dialog.SetVariableList(self.Controler.GetCurrentElementEditingInterfaceVars()) |
474 dialog.SetVariableList(self.Controler.GetEditedElementInterfaceVars(self.TagName)) |
457 if dialog.ShowModal() == wx.ID_OK: |
475 if dialog.ShowModal() == wx.ID_OK: |
458 actions = dialog.GetValues() |
476 actions = dialog.GetValues() |
459 self.SelectedElement.AddAction() |
477 self.SelectedElement.AddAction() |
460 self.RefreshStepModel(self.SelectedElement) |
478 self.RefreshStepModel(self.SelectedElement) |
461 connectors = self.SelectedElement.GetConnectors() |
479 connectors = self.SelectedElement.GetConnectors() |
466 actionblock_connector = actionblock.GetConnector() |
484 actionblock_connector = actionblock.GetConnector() |
467 wire = self.ConnectConnectors(actionblock_connector, connectors["action"]) |
485 wire = self.ConnectConnectors(actionblock_connector, connectors["action"]) |
468 wire.SetPoints([wx.Point(pos.x + SFC_WIRE_MIN_SIZE, pos.y), wx.Point(pos.x, pos.y)]) |
486 wire.SetPoints([wx.Point(pos.x + SFC_WIRE_MIN_SIZE, pos.y), wx.Point(pos.x, pos.y)]) |
469 actionblock.SetActions(actions) |
487 actionblock.SetActions(actions) |
470 self.AddBlock(actionblock) |
488 self.AddBlock(actionblock) |
471 self.Controler.AddCurrentElementEditingActionBlock(id) |
489 self.Controler.AddEditedElementActionBlock(self.TagName, id) |
472 self.RefreshActionBlockModel(actionblock) |
490 self.RefreshActionBlockModel(actionblock) |
473 self.RefreshBuffer() |
491 self.RefreshBuffer() |
474 self.RefreshScrollBars() |
492 self.RefreshScrollBars() |
475 self.Refresh() |
493 self.Refresh() |
476 dialog.Destroy() |
494 dialog.Destroy() |
516 divergence_connectors = divergence.GetConnectors() |
534 divergence_connectors = divergence.GetConnectors() |
517 wire = self.ConnectConnectors(divergence_connectors["inputs"][0], previous) |
535 wire = self.ConnectConnectors(divergence_connectors["inputs"][0], previous) |
518 previous_block.RefreshOutputPosition() |
536 previous_block.RefreshOutputPosition() |
519 wire.SetPoints([wx.Point(pos.x, pos.y + wire_size), wx.Point(pos.x, pos.y)]) |
537 wire.SetPoints([wx.Point(pos.x, pos.y + wire_size), wx.Point(pos.x, pos.y)]) |
520 self.AddBlock(divergence) |
538 self.AddBlock(divergence) |
521 self.Controler.AddCurrentElementEditingDivergence(id, value["type"]) |
539 self.Controler.AddEditedElementDivergence(self.TagName, id, value["type"]) |
522 self.RefreshDivergenceModel(divergence) |
540 self.RefreshDivergenceModel(divergence) |
523 for index, connector in enumerate(divergence_connectors["outputs"]): |
541 for index, connector in enumerate(divergence_connectors["outputs"]): |
524 if next: |
542 if next: |
525 wire = self.ConnectConnectors(next, connector) |
543 wire = self.ConnectConnectors(next, connector) |
526 pos = connector.GetPosition(False) |
544 pos = connector.GetPosition(False) |
574 divergence_connectors = divergence.GetConnectors() |
592 divergence_connectors = divergence.GetConnectors() |
575 wire = self.ConnectConnectors(divergence_connectors["inputs"][0], previous) |
593 wire = self.ConnectConnectors(divergence_connectors["inputs"][0], previous) |
576 previous_block.RefreshOutputPosition() |
594 previous_block.RefreshOutputPosition() |
577 wire.SetPoints([wx.Point(pos.x, pos.y + wire_size), wx.Point(pos.x, pos.y)]) |
595 wire.SetPoints([wx.Point(pos.x, pos.y + wire_size), wx.Point(pos.x, pos.y)]) |
578 self.AddBlock(divergence) |
596 self.AddBlock(divergence) |
579 self.Controler.AddCurrentElementEditingDivergence(id, value["type"]) |
597 self.Controler.AddEditedElementDivergence(self.TagName, id, value["type"]) |
580 self.RefreshDivergenceModel(divergence) |
598 self.RefreshDivergenceModel(divergence) |
581 for index, connector in enumerate(divergence_connectors["outputs"]): |
599 for index, connector in enumerate(divergence_connectors["outputs"]): |
582 if next: |
600 if next: |
583 wire = self.ConnectConnectors(next, connector) |
601 wire = self.ConnectConnectors(next, connector) |
584 pos = connector.GetPosition(False) |
602 pos = connector.GetPosition(False) |
645 input_block.RefreshOutputPosition() |
663 input_block.RefreshOutputPosition() |
646 divergence.RefreshPosition() |
664 divergence.RefreshPosition() |
647 pos = divergence_connectors["outputs"][0].GetRelPosition() |
665 pos = divergence_connectors["outputs"][0].GetRelPosition() |
648 divergence.MoveConnector(divergence_connectors["outputs"][0], - pos.x) |
666 divergence.MoveConnector(divergence_connectors["outputs"][0], - pos.x) |
649 self.AddBlock(divergence) |
667 self.AddBlock(divergence) |
650 self.Controler.AddCurrentElementEditingDivergence(id, value["type"]) |
668 self.Controler.AddEditedElementDivergence(self.TagName, id, value["type"]) |
651 self.RefreshDivergenceModel(divergence) |
669 self.RefreshDivergenceModel(divergence) |
652 if next: |
670 if next: |
653 wire = self.ConnectConnectors(next, divergence_connectors["outputs"][0]) |
671 wire = self.ConnectConnectors(next, divergence_connectors["outputs"][0]) |
654 pos = divergence_connectors["outputs"][0].GetPosition(False) |
672 pos = divergence_connectors["outputs"][0].GetPosition(False) |
655 next_pos = next.GetPosition(False) |
673 next_pos = next.GetPosition(False) |
716 id = self.GetNewId() |
734 id = self.GetNewId() |
717 jump = SFC_Jump(self, value, id) |
735 jump = SFC_Jump(self, value, id) |
718 pos = transition_connectors["output"].GetPosition(False) |
736 pos = transition_connectors["output"].GetPosition(False) |
719 jump.SetPosition(pos.x, pos.y + SFC_WIRE_MIN_SIZE) |
737 jump.SetPosition(pos.x, pos.y + SFC_WIRE_MIN_SIZE) |
720 self.AddBlock(jump) |
738 self.AddBlock(jump) |
721 self.Controler.AddCurrentElementEditingJump(id) |
739 self.Controler.AddEditedElementJump(self.TagName, id) |
722 jump_connector = jump.GetConnector() |
740 jump_connector = jump.GetConnector() |
723 wire = self.ConnectConnectors(jump_connector, transition_connectors["output"]) |
741 wire = self.ConnectConnectors(jump_connector, transition_connectors["output"]) |
724 transition.RefreshOutputPosition() |
742 transition.RefreshOutputPosition() |
725 wire.SetPoints([wx.Point(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wx.Point(pos.x, pos.y)]) |
743 wire.SetPoints([wx.Point(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wx.Point(pos.x, pos.y)]) |
726 self.RefreshJumpModel(jump) |
744 self.RefreshJumpModel(jump) |
733 if self.GetDrawingMode() == FREEDRAWING_MODE: |
751 if self.GetDrawingMode() == FREEDRAWING_MODE: |
734 Viewer.EditStepContent(self, step) |
752 Viewer.EditStepContent(self, step) |
735 else: |
753 else: |
736 dialog = StepNameDialog(self.ParentWindow, "Edit step name", "Please enter step name", step.GetName(), wx.OK|wx.CANCEL) |
754 dialog = StepNameDialog(self.ParentWindow, "Edit step name", "Please enter step name", step.GetName(), wx.OK|wx.CANCEL) |
737 dialog.SetPouNames(self.Controler.GetProjectPouNames()) |
755 dialog.SetPouNames(self.Controler.GetProjectPouNames()) |
738 dialog.SetVariables(self.Controler.GetCurrentElementEditingInterfaceVars()) |
756 dialog.SetVariables(self.Controler.GetEditedElementInterfaceVars(self.TagName)) |
739 dialog.SetStepNames([block.GetName() for block in self.Blocks if isinstance(block, SFC_Step) and block.GetName() != step.GetName()]) |
757 dialog.SetStepNames([block.GetName() for block in self.Blocks if isinstance(block, SFC_Step) and block.GetName() != step.GetName()]) |
740 if dialog.ShowModal() == wx.ID_OK: |
758 if dialog.ShowModal() == wx.ID_OK: |
741 value = dialog.GetValue() |
759 value = dialog.GetValue() |
742 step.SetName(value) |
760 step.SetName(value) |
743 min_size = step.GetMinSize() |
761 min_size = step.GetMinSize() |
906 self.RefreshDivergenceModel(previous_block) |
924 self.RefreshDivergenceModel(previous_block) |
907 else: |
925 else: |
908 self.DeleteDivergence(previous_block) |
926 self.DeleteDivergence(previous_block) |
909 divergence.Clean() |
927 divergence.Clean() |
910 self.RemoveBlock(divergence) |
928 self.RemoveBlock(divergence) |
911 self.Controler.RemoveCurrentElementEditingInstance(divergence.GetId()) |
929 self.Controler.RemoveEditedElementInstance(self.TagName, divergence.GetId()) |
912 if next: |
930 if next: |
913 wire = self.ConnectConnectors(next, previous) |
931 wire = self.ConnectConnectors(next, previous) |
914 previous_block = previous.GetParentBlock() |
932 previous_block = previous.GetParentBlock() |
915 previous_pos = previous.GetPosition(False) |
933 previous_pos = previous.GetPosition(False) |
916 next_pos = next.GetPosition(False) |
934 next_pos = next.GetPosition(False) |
938 next_block = next.GetParentBlock() |
956 next_block = next.GetParentBlock() |
939 wire.Clean() |
957 wire.Clean() |
940 self.RemoveWire(wire) |
958 self.RemoveWire(wire) |
941 divergence.Clean() |
959 divergence.Clean() |
942 self.RemoveBlock(divergence) |
960 self.RemoveBlock(divergence) |
943 self.Controler.RemoveCurrentElementEditingInstance(divergence.GetId()) |
961 self.Controler.RemoveEditedElementInstance(self.TagName, divergence.GetId()) |
944 wire = self.ConnectConnectors(next, previous) |
962 wire = self.ConnectConnectors(next, previous) |
945 previous_pos = previous.GetPosition(False) |
963 previous_pos = previous.GetPosition(False) |
946 next_pos = next.GetPosition(False) |
964 next_pos = next.GetPosition(False) |
947 wire_size = GetWireSize(previous_block) |
965 wire_size = GetWireSize(previous_block) |
948 previous_block.RefreshOutputPosition((previous_pos.x - next_pos.x, previous_pos.y + wire_size - next_pos.y)) |
966 previous_block.RefreshOutputPosition((previous_pos.x - next_pos.x, previous_pos.y + wire_size - next_pos.y)) |
971 wire = wires[0][0] |
989 wire = wires[0][0] |
972 wire.Clean() |
990 wire.Clean() |
973 self.RemoveWire(wire) |
991 self.RemoveWire(wire) |
974 jump.Clean() |
992 jump.Clean() |
975 self.RemoveBlock(jump) |
993 self.RemoveBlock(jump) |
976 self.Controler.RemoveCurrentElementEditingInstance(jump.GetId()) |
994 self.Controler.RemoveEditedElementInstance(self.TagName, jump.GetId()) |
977 if isinstance(previous_block, SFC_Step): |
995 if isinstance(previous_block, SFC_Step): |
978 previous_block.RemoveOutput() |
996 previous_block.RemoveOutput() |
979 self.RefreshStepModel(previous_block) |
997 self.RefreshStepModel(previous_block) |
980 elif isinstance(previous_block, SFC_Divergence): |
998 elif isinstance(previous_block, SFC_Divergence): |
981 if previous_block.GetType() in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]: |
999 if previous_block.GetType() in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]: |