author | Edouard Tisserant |
Tue, 19 Feb 2019 11:27:29 +0100 | |
changeset 2490 | 2d72d8a8d7e5 |
parent 2450 | 5024c19ca8f0 |
child 3750 | f62625418bff |
permissions | -rw-r--r-- |
814 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1567
diff
changeset
|
4 |
# This file is part of Beremiz, a Integrated Development Environment for |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1567
diff
changeset
|
5 |
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
814 | 6 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1567
diff
changeset
|
7 |
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
814 | 8 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1567
diff
changeset
|
9 |
# See COPYING file for copyrights details. |
814 | 10 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1567
diff
changeset
|
11 |
# This program is free software; you can redistribute it and/or |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1567
diff
changeset
|
12 |
# modify it under the terms of the GNU General Public License |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1567
diff
changeset
|
13 |
# as published by the Free Software Foundation; either version 2 |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1567
diff
changeset
|
14 |
# of the License, or (at your option) any later version. |
814 | 15 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1567
diff
changeset
|
16 |
# This program is distributed in the hope that it will be useful, |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1567
diff
changeset
|
17 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1567
diff
changeset
|
18 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1567
diff
changeset
|
19 |
# GNU General Public License for more details. |
814 | 20 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1567
diff
changeset
|
21 |
# You should have received a copy of the GNU General Public License |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1567
diff
changeset
|
22 |
# along with this program; if not, write to the Free Software |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1567
diff
changeset
|
23 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
814 | 24 |
|
1853
47a3f39bead0
fix pylint warning "(relative-import) Relative import 'Y', should be 'X.Y'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1847
diff
changeset
|
25 |
|
47a3f39bead0
fix pylint warning "(relative-import) Relative import 'Y', should be 'X.Y'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1847
diff
changeset
|
26 |
from __future__ import absolute_import |
2437
105c20fdeb19
python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2414
diff
changeset
|
27 |
from __future__ import division |
814 | 28 |
|
29 |
import wx |
|
30 |
||
1853
47a3f39bead0
fix pylint warning "(relative-import) Relative import 'Y', should be 'X.Y'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1847
diff
changeset
|
31 |
from editors.Viewer import * |
1567
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
32 |
from graphics.SFC_Objects import * |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
33 |
from graphics.GraphicCommons import SELECTION_DIVERGENCE, \ |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
34 |
SELECTION_CONVERGENCE, SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE, EAST, NORTH, WEST, SOUTH |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
35 |
|
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
36 |
SFC_Objects = (SFC_Step, SFC_ActionBlock, SFC_Transition, SFC_Divergence, SFC_Jump) |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
37 |
|
814 | 38 |
|
39 |
class SFC_Viewer(Viewer): |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1584
diff
changeset
|
40 |
|
1584
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
41 |
SFC_StandardRules = { |
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
42 |
# The key of this dict is a block that user try to connect, |
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
43 |
# and the value is a list of blocks, that can be connected with the current block |
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
44 |
# and with directions of connection |
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
45 |
"SFC_Step": [("SFC_ActionBlock", EAST), |
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
46 |
("SFC_Transition", SOUTH), |
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
47 |
(SELECTION_DIVERGENCE, SOUTH), |
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
48 |
(SIMULTANEOUS_CONVERGENCE, SOUTH)], |
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
49 |
|
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
50 |
"SFC_ActionBlock": [("SFC_Step", EAST)], |
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
51 |
|
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
52 |
"SFC_Transition": [("SFC_Step", SOUTH), |
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
53 |
(SELECTION_CONVERGENCE, SOUTH), |
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
54 |
(SIMULTANEOUS_DIVERGENCE, SOUTH), |
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
55 |
("SFC_Jump", SOUTH), |
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
56 |
("FBD_Block", EAST), |
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
57 |
("FBD_Variable", EAST), |
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
58 |
("FBD_Connector", EAST), |
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
59 |
("LD_Contact", EAST), |
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
60 |
("LD_PowerRail", EAST), |
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
61 |
("LD_Coil", EAST)], |
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
62 |
|
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
63 |
SELECTION_DIVERGENCE: [("SFC_Transition", SOUTH)], |
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
64 |
|
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
65 |
SELECTION_CONVERGENCE: [("SFC_Step", SOUTH), |
1767
c74815729afd
clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1764
diff
changeset
|
66 |
("SFC_Jump", SOUTH)], |
1584
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
67 |
|
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
68 |
SIMULTANEOUS_DIVERGENCE: [("SFC_Step", SOUTH)], |
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
69 |
|
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
70 |
SIMULTANEOUS_CONVERGENCE: [("SFC_Transition", SOUTH)], |
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
71 |
|
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
72 |
"SFC_Jump": [], |
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
73 |
|
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
74 |
"FBD_Block": [("SFC_Transition", WEST)], |
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
75 |
|
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
76 |
"FBD_Variable": [("SFC_Transition", WEST)], |
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
77 |
|
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
78 |
"FBD_Connector": [("SFC_Transition", WEST)], |
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
79 |
|
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
80 |
"LD_Contact": [("SFC_Transition", WEST)], |
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
81 |
|
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
82 |
"LD_PowerRail": [("SFC_Transition", WEST)], |
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
83 |
|
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
84 |
"LD_Coil": [("SFC_Transition", WEST)] |
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
85 |
} |
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
86 |
|
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1743
diff
changeset
|
87 |
def __init__(self, parent, tagname, window, controler, debug=False, instancepath=""): |
814 | 88 |
Viewer.__init__(self, parent, tagname, window, controler, debug, instancepath) |
89 |
self.CurrentLanguage = "SFC" |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1584
diff
changeset
|
90 |
|
814 | 91 |
def ConnectConnectors(self, start, end): |
92 |
startpoint = [start.GetPosition(False), start.GetDirection()] |
|
93 |
endpoint = [end.GetPosition(False), end.GetDirection()] |
|
94 |
wire = Wire(self, startpoint, endpoint) |
|
95 |
self.AddWire(wire) |
|
96 |
start.Connect((wire, 0), False) |
|
97 |
end.Connect((wire, -1), False) |
|
98 |
wire.ConnectStartPoint(None, start) |
|
99 |
wire.ConnectEndPoint(None, end) |
|
100 |
return wire |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1584
diff
changeset
|
101 |
|
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1743
diff
changeset
|
102 |
def CreateTransition(self, connector, next=None): |
814 | 103 |
previous = connector.GetParentBlock() |
104 |
id = self.GetNewId() |
|
105 |
transition = SFC_Transition(self, "reference", "", 0, id) |
|
106 |
pos = connector.GetPosition(False) |
|
107 |
transition.SetPosition(pos.x, pos.y + SFC_WIRE_MIN_SIZE) |
|
108 |
transition_connectors = transition.GetConnectors() |
|
109 |
wire = self.ConnectConnectors(transition_connectors["input"], connector) |
|
110 |
if isinstance(previous, SFC_Divergence): |
|
111 |
previous.RefreshConnectedPosition(connector) |
|
112 |
else: |
|
113 |
previous.RefreshOutputPosition() |
|
114 |
wire.SetPoints([wx.Point(pos.x, pos.y + GetWireSize(previous)), wx.Point(pos.x, pos.y)]) |
|
115 |
self.AddBlock(transition) |
|
116 |
self.Controler.AddEditedElementTransition(self.TagName, id) |
|
117 |
self.RefreshTransitionModel(transition) |
|
118 |
if next: |
|
119 |
wire = self.ConnectConnectors(next, transition_connectors["output"]) |
|
120 |
pos = transition_connectors["output"].GetPosition(False) |
|
121 |
next_block = next.GetParentBlock() |
|
122 |
next_pos = next.GetPosition(False) |
|
123 |
transition.RefreshOutputPosition((0, pos.y + SFC_WIRE_MIN_SIZE - next_pos.y)) |
|
124 |
wire.SetPoints([wx.Point(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wx.Point(pos.x, pos.y)]) |
|
125 |
if isinstance(next_block, SFC_Divergence): |
|
126 |
next_block.RefreshPosition() |
|
127 |
transition.RefreshOutputModel(True) |
|
128 |
return transition |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1584
diff
changeset
|
129 |
|
814 | 130 |
def RemoveTransition(self, transition): |
131 |
connectors = transition.GetConnectors() |
|
132 |
input_wires = connectors["input"].GetWires() |
|
133 |
if len(input_wires) != 1: |
|
134 |
return |
|
135 |
input_wire = input_wires[0][0] |
|
136 |
previous = input_wire.EndConnected |
|
137 |
input_wire.Clean() |
|
138 |
self.RemoveWire(input_wire) |
|
139 |
output_wires = connectors["output"].GetWires() |
|
140 |
if len(output_wires) != 1: |
|
141 |
return |
|
142 |
output_wire = output_wires[0][0] |
|
143 |
next = output_wire.StartConnected |
|
144 |
output_wire.Clean() |
|
145 |
self.RemoveWire(output_wire) |
|
146 |
transition.Clean() |
|
147 |
self.RemoveBlock(transition) |
|
148 |
self.Controler.RemoveEditedElementInstance(self.TagName, transition.GetId()) |
|
149 |
wire = self.ConnectConnectors(next, previous) |
|
150 |
return wire |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1584
diff
changeset
|
151 |
|
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1743
diff
changeset
|
152 |
def CreateStep(self, name, connector, next=None): |
814 | 153 |
previous = connector.GetParentBlock() |
154 |
id = self.GetNewId() |
|
155 |
step = SFC_Step(self, name, False, id) |
|
156 |
if next: |
|
157 |
step.AddOutput() |
|
158 |
min_width, min_height = step.GetMinSize() |
|
159 |
pos = connector.GetPosition(False) |
|
160 |
step.SetPosition(pos.x, pos.y + SFC_WIRE_MIN_SIZE) |
|
161 |
step.SetSize(min_width, min_height) |
|
162 |
step_connectors = step.GetConnectors() |
|
163 |
wire = self.ConnectConnectors(step_connectors["input"], connector) |
|
164 |
if isinstance(previous, SFC_Divergence): |
|
165 |
previous.RefreshConnectedPosition(connector) |
|
166 |
else: |
|
167 |
previous.RefreshOutputPosition() |
|
168 |
wire.SetPoints([wx.Point(pos.x, pos.y + GetWireSize(previous)), wx.Point(pos.x, pos.y)]) |
|
169 |
self.AddBlock(step) |
|
170 |
self.Controler.AddEditedElementStep(self.TagName, id) |
|
171 |
self.RefreshStepModel(step) |
|
172 |
if next: |
|
173 |
wire = self.ConnectConnectors(next, step_connectors["output"]) |
|
174 |
pos = step_connectors["output"].GetPosition(False) |
|
175 |
next_block = next.GetParentBlock() |
|
176 |
next_pos = next.GetPosition(False) |
|
177 |
step.RefreshOutputPosition((0, pos.y + SFC_WIRE_MIN_SIZE - next_pos.y)) |
|
178 |
wire.SetPoints([wx.Point(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wx.Point(pos.x, pos.y)]) |
|
179 |
if isinstance(next_block, SFC_Divergence): |
|
180 |
next_block.RefreshPosition() |
|
181 |
step.RefreshOutputModel(True) |
|
182 |
return step |
|
183 |
||
184 |
def RemoveStep(self, step): |
|
185 |
connectors = step.GetConnectors() |
|
186 |
if connectors["input"]: |
|
187 |
input_wires = connectors["input"].GetWires() |
|
188 |
if len(input_wires) != 1: |
|
189 |
return |
|
190 |
input_wire = input_wires[0][0] |
|
191 |
previous = input_wire.EndConnected |
|
192 |
input_wire.Clean() |
|
193 |
self.RemoveWire(input_wire) |
|
194 |
else: |
|
195 |
previous = None |
|
196 |
if connectors["output"]: |
|
197 |
output_wires = connectors["output"].GetWires() |
|
198 |
if len(output_wires) != 1: |
|
199 |
return |
|
200 |
output_wire = output_wires[0][0] |
|
201 |
next = output_wire.StartConnected |
|
202 |
output_wire.Clean() |
|
203 |
self.RemoveWire(output_wire) |
|
204 |
else: |
|
205 |
next = None |
|
206 |
action = step.GetActionConnected() |
|
207 |
if action: |
|
208 |
self.DeleteActionBlock(action.GetParentBlock()) |
|
209 |
step.Clean() |
|
210 |
self.RemoveBlock(step) |
|
211 |
self.Controler.RemoveEditedElementInstance(self.TagName, step.GetId()) |
|
212 |
if next and previous: |
|
213 |
wire = self.ConnectConnectors(next, previous) |
|
214 |
return wire |
|
215 |
else: |
|
216 |
return None |
|
217 |
||
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
218 |
# ------------------------------------------------------------------------------- |
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
219 |
# Mouse event functions |
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
220 |
# ------------------------------------------------------------------------------- |
814 | 221 |
|
222 |
def OnViewerLeftDown(self, event): |
|
223 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
224 |
Viewer.OnViewerLeftDown(self, event) |
|
225 |
elif self.Mode == MODE_SELECTION: |
|
226 |
if event.ShiftDown() and not event.ControlDown() and self.SelectedElement is not None: |
|
227 |
element = self.FindElement(event, True) |
|
228 |
if element and not self.IsWire(element): |
|
229 |
if isinstance(self.SelectedElement, Graphic_Group): |
|
230 |
self.SelectedElement.SelectElement(element) |
|
231 |
else: |
|
232 |
group = Graphic_Group(self) |
|
233 |
self.SelectedElement.SetSelected(False) |
|
234 |
group.SelectElement(self.SelectedElement) |
|
235 |
group.SelectElement(element) |
|
236 |
self.SelectedElement = group |
|
237 |
elements = self.SelectedElement.GetElements() |
|
238 |
if len(elements) == 0: |
|
239 |
self.SelectedElement = element |
|
240 |
elif len(elements) == 1: |
|
241 |
self.SelectedElement = elements[0] |
|
242 |
self.SelectedElement.SetSelected(True) |
|
243 |
else: |
|
244 |
element = self.FindElement(event) |
|
245 |
if self.SelectedElement and self.SelectedElement != element: |
|
246 |
if self.IsWire(self.SelectedElement): |
|
247 |
self.SelectedElement.SetSelectedSegment(None) |
|
248 |
else: |
|
249 |
self.SelectedElement.SetSelected(False) |
|
250 |
self.SelectedElement = None |
|
251 |
if element: |
|
252 |
self.SelectedElement = element |
|
253 |
self.SelectedElement.OnLeftDown(event, self.GetLogicalDC(), self.Scaling) |
|
254 |
self.SelectedElement.Refresh() |
|
255 |
else: |
|
256 |
self.rubberBand.Reset() |
|
257 |
self.rubberBand.OnLeftDown(event, self.GetLogicalDC(), self.Scaling) |
|
258 |
elif self.Mode == MODE_COMMENT: |
|
259 |
self.rubberBand.Reset() |
|
260 |
self.rubberBand.OnLeftDown(event, self.GetLogicalDC(), self.Scaling) |
|
261 |
event.Skip() |
|
262 |
||
263 |
def OnViewerLeftUp(self, event): |
|
264 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
265 |
Viewer.OnViewerLeftUp(self, event) |
|
266 |
elif self.rubberBand.IsShown(): |
|
267 |
if self.Mode == MODE_SELECTION: |
|
268 |
elements = self.SearchElements(self.rubberBand.GetCurrentExtent()) |
|
269 |
self.rubberBand.OnLeftUp(event, self.GetLogicalDC(), self.Scaling) |
|
270 |
if len(elements) > 0: |
|
271 |
self.SelectedElement = Graphic_Group(self) |
|
272 |
self.SelectedElement.SetElements(elements) |
|
273 |
self.SelectedElement.SetSelected(True) |
|
274 |
elif self.Mode == MODE_COMMENT: |
|
275 |
bbox = self.rubberBand.GetCurrentExtent() |
|
276 |
self.rubberBand.OnLeftUp(event, self.GetLogicalDC(), self.Scaling) |
|
277 |
wx.CallAfter(self.AddComment, bbox) |
|
278 |
elif self.Mode == MODE_INITIALSTEP: |
|
279 |
wx.CallAfter(self.AddInitialStep, GetScaledEventPosition(event, self.GetLogicalDC(), self.Scaling)) |
|
280 |
elif self.Mode == MODE_SELECTION and self.SelectedElement: |
|
281 |
if self.IsWire(self.SelectedElement): |
|
282 |
self.SelectedElement.SetSelectedSegment(0) |
|
283 |
else: |
|
284 |
self.SelectedElement.OnLeftUp(event, self.GetLogicalDC(), self.Scaling) |
|
285 |
self.SelectedElement.Refresh() |
|
286 |
wx.CallAfter(self.SetCurrentCursor, 0) |
|
1872
866fb3ab8778
fix pylint error "(undefined-variable) Undefined variable 'X'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1865
diff
changeset
|
287 |
# |
866fb3ab8778
fix pylint error "(undefined-variable) Undefined variable 'X'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1865
diff
changeset
|
288 |
# FIXME: |
866fb3ab8778
fix pylint error "(undefined-variable) Undefined variable 'X'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1865
diff
changeset
|
289 |
# This code was forgotten by commit |
866fb3ab8778
fix pylint error "(undefined-variable) Undefined variable 'X'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1865
diff
changeset
|
290 |
# 9c74d00ce93e from plcopeneditor_history repository |
866fb3ab8778
fix pylint error "(undefined-variable) Undefined variable 'X'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1865
diff
changeset
|
291 |
# 'Last bugs on block and wire moving, resizing with cursor fixed' |
866fb3ab8778
fix pylint error "(undefined-variable) Undefined variable 'X'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1865
diff
changeset
|
292 |
# |
866fb3ab8778
fix pylint error "(undefined-variable) Undefined variable 'X'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1865
diff
changeset
|
293 |
# elif self.Mode == MODE_WIRE and self.SelectedElement: |
866fb3ab8778
fix pylint error "(undefined-variable) Undefined variable 'X'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1865
diff
changeset
|
294 |
# self.SelectedElement.ResetPoints() |
866fb3ab8778
fix pylint error "(undefined-variable) Undefined variable 'X'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1865
diff
changeset
|
295 |
# self.SelectedElement.OnMotion(event, self.GetLogicalDC(), self.Scaling) |
866fb3ab8778
fix pylint error "(undefined-variable) Undefined variable 'X'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1865
diff
changeset
|
296 |
# self.SelectedElement.GeneratePoints() |
866fb3ab8778
fix pylint error "(undefined-variable) Undefined variable 'X'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1865
diff
changeset
|
297 |
# self.SelectedElement.RefreshModel() |
866fb3ab8778
fix pylint error "(undefined-variable) Undefined variable 'X'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1865
diff
changeset
|
298 |
# self.SelectedElement.SetSelected(True) |
814 | 299 |
event.Skip() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1584
diff
changeset
|
300 |
|
814 | 301 |
def OnViewerRightUp(self, event): |
302 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
303 |
Viewer.OnViewerRightUp(self, event) |
|
304 |
else: |
|
305 |
element = self.FindElement(event) |
|
306 |
if element: |
|
307 |
if self.SelectedElement and self.SelectedElement != element: |
|
308 |
self.SelectedElement.SetSelected(False) |
|
309 |
self.SelectedElement = element |
|
310 |
if self.IsWire(self.SelectedElement): |
|
311 |
self.SelectedElement.SetSelectedSegment(0) |
|
312 |
else: |
|
313 |
self.SelectedElement.SetSelected(True) |
|
314 |
self.SelectedElement.OnRightUp(event, self.GetLogicalDC(), self.Scaling) |
|
315 |
self.SelectedElement.Refresh() |
|
316 |
wx.CallAfter(self.SetCurrentCursor, 0) |
|
317 |
event.Skip() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1584
diff
changeset
|
318 |
|
814 | 319 |
def OnViewerLeftDClick(self, event): |
320 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
321 |
Viewer.OnViewerLeftDClick(self, event) |
|
322 |
elif self.Mode == MODE_SELECTION and self.SelectedElement: |
|
323 |
self.SelectedElement.OnLeftDClick(event, self.GetLogicalDC(), self.Scaling) |
|
324 |
self.Refresh(False) |
|
325 |
event.Skip() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1584
diff
changeset
|
326 |
|
814 | 327 |
def OnViewerMotion(self, event): |
328 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
329 |
Viewer.OnViewerMotion(self, event) |
|
330 |
else: |
|
331 |
if self.rubberBand.IsShown(): |
|
332 |
self.rubberBand.OnMotion(event, self.GetLogicalDC(), self.Scaling) |
|
333 |
elif self.Mode == MODE_SELECTION and self.SelectedElement: |
|
334 |
if not self.IsWire(self.SelectedElement) and not isinstance(self.SelectedElement, Graphic_Group): |
|
335 |
self.SelectedElement.OnMotion(event, self.GetLogicalDC(), self.Scaling) |
|
336 |
self.SelectedElement.Refresh() |
|
1872
866fb3ab8778
fix pylint error "(undefined-variable) Undefined variable 'X'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1865
diff
changeset
|
337 |
# |
866fb3ab8778
fix pylint error "(undefined-variable) Undefined variable 'X'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1865
diff
changeset
|
338 |
# FIXME: |
866fb3ab8778
fix pylint error "(undefined-variable) Undefined variable 'X'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1865
diff
changeset
|
339 |
# This code was forgotten by commit |
866fb3ab8778
fix pylint error "(undefined-variable) Undefined variable 'X'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1865
diff
changeset
|
340 |
# 9c74d00ce93e from plcopeneditor_history repository |
866fb3ab8778
fix pylint error "(undefined-variable) Undefined variable 'X'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1865
diff
changeset
|
341 |
# 'Last bugs on block and wire moving, resizing with cursor fixed' |
866fb3ab8778
fix pylint error "(undefined-variable) Undefined variable 'X'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1865
diff
changeset
|
342 |
# |
866fb3ab8778
fix pylint error "(undefined-variable) Undefined variable 'X'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1865
diff
changeset
|
343 |
# elif self.Mode == MODE_WIRE and self.SelectedElement: |
866fb3ab8778
fix pylint error "(undefined-variable) Undefined variable 'X'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1865
diff
changeset
|
344 |
# self.SelectedElement.ResetPoints() |
866fb3ab8778
fix pylint error "(undefined-variable) Undefined variable 'X'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1865
diff
changeset
|
345 |
# self.SelectedElement.OnMotion(event, self.GetLogicalDC(), self.Scaling) |
866fb3ab8778
fix pylint error "(undefined-variable) Undefined variable 'X'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1865
diff
changeset
|
346 |
# self.SelectedElement.GeneratePoints() |
866fb3ab8778
fix pylint error "(undefined-variable) Undefined variable 'X'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1865
diff
changeset
|
347 |
# self.SelectedElement.Refresh() |
814 | 348 |
self.UpdateScrollPos(event) |
349 |
event.Skip() |
|
350 |
||
1567
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
351 |
def GetBlockName(self, block): |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
352 |
blockName = block.__class__.__name__ |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
353 |
if blockName == "SFC_Divergence": |
1584
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
354 |
blockName = block.Type |
1567
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
355 |
return blockName |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
356 |
|
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
357 |
# This method check the IEC 61131-3 compatibility between two SFC blocks |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1743
diff
changeset
|
358 |
def BlockCompatibility(self, startblock=None, endblock=None, direction=None): |
1764
d5df428640ff
clean-up: fix PEP8 E502 the backslash is redundant between brackets
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1745
diff
changeset
|
359 |
if startblock is not None and endblock is not None and \ |
d5df428640ff
clean-up: fix PEP8 E502 the backslash is redundant between brackets
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1745
diff
changeset
|
360 |
(isinstance(startblock, SFC_Objects) or isinstance(endblock, SFC_Objects)): |
1584
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
361 |
# Full "SFC_StandardRules" table would be symmetrical and |
1567
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
362 |
# to avoid duplicate records and minimize the table only upper part is defined. |
1828
396da88d7b5c
fix unnecessary parens after keyword
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1782
diff
changeset
|
363 |
if direction == SOUTH or direction == EAST: |
1567
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
364 |
startblock, endblock = endblock, startblock |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
365 |
start = self.GetBlockName(startblock) |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
366 |
end = self.GetBlockName(endblock) |
1584
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
367 |
for val in self.SFC_StandardRules[start]: |
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
368 |
if end in val: |
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
369 |
return True |
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
370 |
return False |
1567
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
371 |
return True |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
372 |
|
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
373 |
# ------------------------------------------------------------------------------- |
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
374 |
# Keyboard event functions |
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
375 |
# ------------------------------------------------------------------------------- |
814 | 376 |
|
377 |
def OnChar(self, event): |
|
378 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
379 |
Viewer.OnChar(self, event) |
|
380 |
else: |
|
381 |
xpos, ypos = self.GetScrollPos(wx.HORIZONTAL), self.GetScrollPos(wx.VERTICAL) |
|
382 |
xmax = self.GetScrollRange(wx.HORIZONTAL) - self.GetScrollThumb(wx.HORIZONTAL) |
|
383 |
ymax = self.GetScrollRange(wx.VERTICAL) - self.GetScrollThumb(wx.VERTICAL) |
|
384 |
keycode = event.GetKeyCode() |
|
385 |
if self.Scaling: |
|
386 |
scaling = self.Scaling |
|
387 |
else: |
|
388 |
scaling = (8, 8) |
|
389 |
if keycode == wx.WXK_DELETE and self.SelectedElement: |
|
390 |
self.SelectedElement.Delete() |
|
391 |
self.SelectedElement = None |
|
392 |
self.RefreshBuffer() |
|
393 |
self.RefreshScrollBars() |
|
394 |
self.Refresh(False) |
|
395 |
elif keycode == wx.WXK_LEFT: |
|
396 |
if event.ControlDown() and event.ShiftDown(): |
|
397 |
self.Scroll(0, ypos) |
|
398 |
elif event.ControlDown(): |
|
399 |
event.Skip() |
|
400 |
elif self.SelectedElement: |
|
401 |
self.SelectedElement.Move(-scaling[0], 0) |
|
402 |
self.SelectedElement.RefreshModel() |
|
403 |
self.RefreshBuffer() |
|
404 |
self.RefreshScrollBars() |
|
405 |
self.RefreshRect(self.GetScrolledRect(self.SelectedElement.GetRedrawRect(-scaling[0], 0)), False) |
|
406 |
elif keycode == wx.WXK_RIGHT: |
|
407 |
if event.ControlDown() and event.ShiftDown(): |
|
408 |
self.Scroll(xmax, ypos) |
|
409 |
elif event.ControlDown(): |
|
410 |
event.Skip() |
|
411 |
elif self.SelectedElement: |
|
412 |
self.SelectedElement.Move(scaling[0], 0) |
|
413 |
self.SelectedElement.RefreshModel() |
|
414 |
self.RefreshBuffer() |
|
415 |
self.RefreshScrollBars() |
|
416 |
self.RefreshRect(self.GetScrolledRect(self.SelectedElement.GetRedrawRect(scaling[0], 0)), False) |
|
417 |
elif keycode == wx.WXK_UP: |
|
418 |
if event.ControlDown() and event.ShiftDown(): |
|
419 |
self.Scroll(xpos, 0) |
|
420 |
elif event.ControlDown(): |
|
421 |
event.Skip() |
|
422 |
elif self.SelectedElement: |
|
423 |
self.SelectedElement.Move(0, -scaling[1]) |
|
424 |
self.SelectedElement.RefreshModel() |
|
425 |
self.RefreshBuffer() |
|
426 |
self.RefreshScrollBars() |
|
427 |
self.RefreshRect(self.GetScrolledRect(self.SelectedElement.GetRedrawRect(0, -scaling[1])), False) |
|
428 |
elif keycode == wx.WXK_DOWN: |
|
429 |
if event.ControlDown() and event.ShiftDown(): |
|
430 |
self.Scroll(xpos, ymax) |
|
431 |
elif event.ControlDown(): |
|
432 |
event.Skip() |
|
433 |
elif self.SelectedElement: |
|
434 |
self.SelectedElement.Move(0, scaling[1]) |
|
435 |
self.SelectedElement.RefreshModel() |
|
436 |
self.RefreshBuffer() |
|
437 |
self.RefreshScrollBars() |
|
438 |
self.RefreshRect(self.GetScrolledRect(self.SelectedElement.GetRedrawRect(0, scaling[1])), False) |
|
439 |
else: |
|
440 |
event.Skip() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1584
diff
changeset
|
441 |
|
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
442 |
# ------------------------------------------------------------------------------- |
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
443 |
# Adding element functions |
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
444 |
# ------------------------------------------------------------------------------- |
814 | 445 |
|
446 |
def AddInitialStep(self, pos): |
|
1745
f9d32913bad4
clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
447 |
dialog = SFCStepNameDialog(self.ParentWindow, _("Please enter step name"), _("Add a new initial step"), "", wx.OK | wx.CANCEL) |
814 | 448 |
dialog.SetPouNames(self.Controler.GetProjectPouNames(self.Debug)) |
1347
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
814
diff
changeset
|
449 |
dialog.SetVariables(self.Controler.GetEditedElementInterfaceVars(self.TagName, debug=self.Debug)) |
814 | 450 |
dialog.SetStepNames([block.GetName() for block in self.Blocks if isinstance(block, SFC_Step)]) |
451 |
if dialog.ShowModal() == wx.ID_OK: |
|
452 |
id = self.GetNewId() |
|
453 |
name = dialog.GetValue() |
|
454 |
step = SFC_Step(self, name, True, id) |
|
455 |
min_width, min_height = step.GetMinSize() |
|
456 |
step.SetPosition(pos.x, pos.y) |
|
457 |
width, height = step.GetSize() |
|
458 |
step.SetSize(max(min_width, width), max(min_height, height)) |
|
459 |
self.AddBlock(step) |
|
460 |
self.Controler.AddEditedElementStep(self.TagName, id) |
|
461 |
self.RefreshStepModel(step) |
|
462 |
self.RefreshBuffer() |
|
463 |
self.RefreshScrollBars() |
|
464 |
self.Refresh(False) |
|
465 |
dialog.Destroy() |
|
466 |
||
467 |
def AddStep(self): |
|
468 |
if self.SelectedElement in self.Wires or isinstance(self.SelectedElement, SFC_Step): |
|
1745
f9d32913bad4
clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
469 |
dialog = SFCStepNameDialog(self.ParentWindow, _("Add a new step"), _("Please enter step name"), "", wx.OK | wx.CANCEL) |
814 | 470 |
dialog.SetPouNames(self.Controler.GetProjectPouNames(self.Debug)) |
1347
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
814
diff
changeset
|
471 |
dialog.SetVariables(self.Controler.GetEditedElementInterfaceVars(self.TagName, debug=self.Debug)) |
814 | 472 |
dialog.SetStepNames([block.GetName() for block in self.Blocks if isinstance(block, SFC_Step)]) |
473 |
if dialog.ShowModal() == wx.ID_OK: |
|
474 |
name = dialog.GetValue() |
|
475 |
if self.IsWire(self.SelectedElement): |
|
476 |
self.SelectedElement.SetSelectedSegment(None) |
|
477 |
previous = self.SelectedElement.EndConnected |
|
478 |
next = self.SelectedElement.StartConnected |
|
479 |
self.SelectedElement.Clean() |
|
480 |
self.RemoveWire(self.SelectedElement) |
|
481 |
else: |
|
482 |
connectors = self.SelectedElement.GetConnectors() |
|
483 |
if connectors["output"]: |
|
484 |
previous = connectors["output"] |
|
485 |
wires = previous.GetWires() |
|
486 |
if len(wires) != 1: |
|
487 |
return |
|
488 |
wire = wires[0][0] |
|
489 |
next = wire.StartConnected |
|
490 |
wire.Clean() |
|
491 |
self.RemoveWire(wire) |
|
492 |
else: |
|
493 |
self.SelectedElement.AddOutput() |
|
494 |
connectors = self.SelectedElement.GetConnectors() |
|
495 |
self.RefreshStepModel(self.SelectedElement) |
|
496 |
previous = connectors["output"] |
|
497 |
next = None |
|
498 |
previous_block = previous.GetParentBlock() |
|
499 |
if isinstance(previous_block, SFC_Step) or isinstance(previous_block, SFC_Divergence) and previous_block.GetType() in [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE]: |
|
500 |
transition = self.CreateTransition(previous) |
|
501 |
transition_connectors = transition.GetConnectors() |
|
502 |
step = self.CreateStep(name, transition_connectors["output"], next) |
|
503 |
else: |
|
504 |
step = self.CreateStep(name, previous) |
|
505 |
step.AddOutput() |
|
506 |
step.RefreshModel() |
|
507 |
step_connectors = step.GetConnectors() |
|
508 |
transition = self.CreateTransition(step_connectors["output"], next) |
|
509 |
if self.IsWire(self.SelectedElement): |
|
510 |
self.SelectedElement = wire |
|
511 |
self.SelectedElement.SetSelectedSegment(0) |
|
512 |
else: |
|
513 |
self.SelectedElement.SetSelected(False) |
|
514 |
self.SelectedElement = step |
|
515 |
self.SelectedElement.SetSelected(True) |
|
516 |
self.RefreshBuffer() |
|
517 |
self.RefreshScrollBars() |
|
518 |
self.Refresh(False) |
|
519 |
dialog.Destroy() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1584
diff
changeset
|
520 |
|
814 | 521 |
def AddStepAction(self): |
522 |
if isinstance(self.SelectedElement, SFC_Step): |
|
523 |
connectors = self.SelectedElement.GetConnectors() |
|
524 |
if not connectors["action"]: |
|
525 |
dialog = ActionBlockDialog(self.ParentWindow) |
|
526 |
dialog.SetQualifierList(self.Controler.GetQualifierTypes()) |
|
527 |
dialog.SetActionList(self.Controler.GetEditedElementActions(self.TagName, self.Debug)) |
|
1347
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
814
diff
changeset
|
528 |
dialog.SetVariableList(self.Controler.GetEditedElementInterfaceVars(self.TagName, debug=self.Debug)) |
814 | 529 |
if dialog.ShowModal() == wx.ID_OK: |
530 |
actions = dialog.GetValues() |
|
531 |
self.SelectedElement.AddAction() |
|
532 |
self.RefreshStepModel(self.SelectedElement) |
|
533 |
connectors = self.SelectedElement.GetConnectors() |
|
534 |
pos = connectors["action"].GetPosition(False) |
|
535 |
id = self.GetNewId() |
|
536 |
actionblock = SFC_ActionBlock(self, [], id) |
|
2437
105c20fdeb19
python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2414
diff
changeset
|
537 |
actionblock.SetPosition(pos.x + SFC_WIRE_MIN_SIZE, pos.y - SFC_STEP_DEFAULT_SIZE[1] // 2) |
814 | 538 |
actionblock_connector = actionblock.GetConnector() |
539 |
wire = self.ConnectConnectors(actionblock_connector, connectors["action"]) |
|
540 |
wire.SetPoints([wx.Point(pos.x + SFC_WIRE_MIN_SIZE, pos.y), wx.Point(pos.x, pos.y)]) |
|
541 |
actionblock.SetActions(actions) |
|
542 |
self.AddBlock(actionblock) |
|
543 |
self.Controler.AddEditedElementActionBlock(self.TagName, id) |
|
544 |
self.RefreshActionBlockModel(actionblock) |
|
545 |
self.RefreshBuffer() |
|
546 |
self.RefreshScrollBars() |
|
547 |
self.Refresh(False) |
|
548 |
dialog.Destroy() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1584
diff
changeset
|
549 |
|
814 | 550 |
def AddDivergence(self): |
2414
7fad75e5e63d
cleanup: pylint, R1701 # (consider-merging-isinstance) Consider merging these isinstance calls to isinstance(CTNLDFLAGS, (str, unicode))
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1872
diff
changeset
|
551 |
if self.SelectedElement in self.Wires or isinstance(self.SelectedElement, (Graphic_Group, SFC_Step)): |
1865
0bd5b3099144
fix pylint warning "(no-value-for-parameter) No value for argument 'X' in function call"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1853
diff
changeset
|
552 |
dialog = SFCDivergenceDialog(self.ParentWindow, self.Controler, self.TagName) |
814 | 553 |
dialog.SetPreviewFont(self.GetFont()) |
554 |
if dialog.ShowModal() == wx.ID_OK: |
|
555 |
value = dialog.GetValues() |
|
556 |
if value["type"] == SELECTION_DIVERGENCE: |
|
557 |
if self.SelectedElement in self.Wires and isinstance(self.SelectedElement.EndConnected.GetParentBlock(), SFC_Step): |
|
558 |
self.SelectedElement.SetSelectedSegment(None) |
|
559 |
previous = self.SelectedElement.EndConnected |
|
560 |
next = self.SelectedElement.StartConnected |
|
561 |
self.SelectedElement.Clean() |
|
562 |
self.RemoveWire(self.SelectedElement) |
|
563 |
self.SelectedElement = None |
|
564 |
elif isinstance(self.SelectedElement, SFC_Step): |
|
565 |
connectors = self.SelectedElement.GetConnectors() |
|
566 |
if connectors["output"]: |
|
567 |
previous = connectors["output"] |
|
568 |
wires = previous.GetWires() |
|
569 |
if len(wires) != 1: |
|
570 |
return |
|
571 |
wire = wires[0][0] |
|
572 |
next = wire.StartConnected |
|
573 |
wire.Clean() |
|
574 |
self.RemoveWire(wire) |
|
575 |
else: |
|
576 |
self.SelectedElement.AddOutput() |
|
577 |
connectors = self.SelectedElement.GetConnectors() |
|
578 |
self.RefreshStepModel(self.SelectedElement) |
|
579 |
previous = connectors["output"] |
|
580 |
next = None |
|
581 |
else: |
|
582 |
return |
|
583 |
id = self.GetNewId() |
|
584 |
divergence = SFC_Divergence(self, SELECTION_DIVERGENCE, value["number"], id) |
|
585 |
pos = previous.GetPosition(False) |
|
586 |
previous_block = previous.GetParentBlock() |
|
587 |
wire_size = GetWireSize(previous_block) |
|
588 |
divergence.SetPosition(pos.x, pos.y + wire_size) |
|
589 |
divergence_connectors = divergence.GetConnectors() |
|
590 |
wire = self.ConnectConnectors(divergence_connectors["inputs"][0], previous) |
|
591 |
previous_block.RefreshOutputPosition() |
|
592 |
wire.SetPoints([wx.Point(pos.x, pos.y + wire_size), wx.Point(pos.x, pos.y)]) |
|
593 |
self.AddBlock(divergence) |
|
594 |
self.Controler.AddEditedElementDivergence(self.TagName, id, value["type"]) |
|
595 |
self.RefreshDivergenceModel(divergence) |
|
1847
6198190bc121
explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1828
diff
changeset
|
596 |
for _index, connector in enumerate(divergence_connectors["outputs"]): |
814 | 597 |
if next: |
598 |
wire = self.ConnectConnectors(next, connector) |
|
599 |
pos = connector.GetPosition(False) |
|
600 |
next_pos = next.GetPosition(False) |
|
601 |
next_block = next.GetParentBlock() |
|
602 |
divergence.RefreshOutputPosition((0, pos.y + SFC_WIRE_MIN_SIZE - next_pos.y)) |
|
603 |
divergence.RefreshConnectedPosition(connector) |
|
604 |
wire.SetPoints([wx.Point(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wx.Point(pos.x, pos.y)]) |
|
605 |
next_block.RefreshModel() |
|
606 |
next = None |
|
607 |
else: |
|
608 |
transition = self.CreateTransition(connector) |
|
609 |
transition_connectors = transition.GetConnectors() |
|
1847
6198190bc121
explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1828
diff
changeset
|
610 |
_step = self.CreateStep("Step", transition_connectors["output"]) |
814 | 611 |
elif value["type"] == SIMULTANEOUS_DIVERGENCE: |
612 |
if self.SelectedElement in self.Wires and isinstance(self.SelectedElement.EndConnected.GetParentBlock(), SFC_Transition): |
|
613 |
self.SelectedElement.SetSelectedSegment(None) |
|
614 |
previous = self.SelectedElement.EndConnected |
|
615 |
next = self.SelectedElement.StartConnected |
|
616 |
self.SelectedElement.Clean() |
|
617 |
self.RemoveWire(self.SelectedElement) |
|
618 |
self.SelectedElement = None |
|
619 |
elif isinstance(self.SelectedElement, SFC_Step): |
|
620 |
connectors = self.SelectedElement.GetConnectors() |
|
621 |
if connectors["output"]: |
|
622 |
previous = connectors["output"] |
|
623 |
wires = previous.GetWires() |
|
624 |
if len(wires) != 1: |
|
625 |
return |
|
626 |
wire = wires[0][0] |
|
627 |
next = wire.StartConnected |
|
628 |
wire.Clean() |
|
629 |
self.RemoveWire(wire) |
|
630 |
else: |
|
631 |
self.SelectedElement.AddOutput() |
|
632 |
connectors = self.SelectedElement.GetConnectors() |
|
633 |
self.RefreshStepModel(self.SelectedElement) |
|
634 |
previous = connectors["output"] |
|
635 |
next = None |
|
636 |
transition = self.CreateTransition(previous) |
|
637 |
transition_connectors = transition.GetConnectors() |
|
638 |
previous = transition_connectors["output"] |
|
639 |
else: |
|
640 |
return |
|
641 |
id = self.GetNewId() |
|
642 |
divergence = SFC_Divergence(self, SIMULTANEOUS_DIVERGENCE, value["number"], id) |
|
643 |
pos = previous.GetPosition(False) |
|
644 |
previous_block = previous.GetParentBlock() |
|
645 |
wire_size = GetWireSize(previous_block) |
|
646 |
divergence.SetPosition(pos.x, pos.y + wire_size) |
|
647 |
divergence_connectors = divergence.GetConnectors() |
|
648 |
wire = self.ConnectConnectors(divergence_connectors["inputs"][0], previous) |
|
649 |
previous_block.RefreshOutputPosition() |
|
650 |
wire.SetPoints([wx.Point(pos.x, pos.y + wire_size), wx.Point(pos.x, pos.y)]) |
|
651 |
self.AddBlock(divergence) |
|
652 |
self.Controler.AddEditedElementDivergence(self.TagName, id, value["type"]) |
|
653 |
self.RefreshDivergenceModel(divergence) |
|
1847
6198190bc121
explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1828
diff
changeset
|
654 |
for _index, connector in enumerate(divergence_connectors["outputs"]): |
814 | 655 |
if next: |
656 |
wire = self.ConnectConnectors(next, connector) |
|
657 |
pos = connector.GetPosition(False) |
|
658 |
next_pos = next.GetPosition(False) |
|
659 |
next_block = next.GetParentBlock() |
|
660 |
divergence.RefreshOutputPosition((0, pos.y + SFC_WIRE_MIN_SIZE - next_pos.y)) |
|
661 |
divergence.RefreshConnectedPosition(connector) |
|
662 |
wire.SetPoints([wx.Point(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wx.Point(pos.x, pos.y)]) |
|
663 |
next_block.RefreshModel() |
|
664 |
next = None |
|
665 |
else: |
|
1847
6198190bc121
explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1828
diff
changeset
|
666 |
_step = self.CreateStep("Step", connector) |
814 | 667 |
elif isinstance(self.SelectedElement, Graphic_Group) and len(self.SelectedElement.GetElements()) > 1: |
668 |
next = None |
|
669 |
for element in self.SelectedElement.GetElements(): |
|
670 |
connectors = element.GetConnectors() |
|
671 |
if not isinstance(element, SFC_Step) or connectors["output"] and next: |
|
672 |
return |
|
673 |
elif connectors["output"] and not next: |
|
674 |
wires = connectors["output"].GetWires() |
|
675 |
if len(wires) != 1: |
|
676 |
return |
|
677 |
if value["type"] == SELECTION_CONVERGENCE: |
|
678 |
transition = wires[0][0].StartConnected.GetParentBlock() |
|
679 |
transition_connectors = transition.GetConnectors() |
|
680 |
wires = transition_connectors["output"].GetWires() |
|
681 |
if len(wires) != 1: |
|
682 |
return |
|
683 |
wire = wires[0][0] |
|
684 |
next = wire.StartConnected |
|
685 |
wire.Clean() |
|
686 |
self.RemoveWire(wire) |
|
687 |
inputs = [] |
|
688 |
for input in self.SelectedElement.GetElements(): |
|
689 |
input_connectors = input.GetConnectors() |
|
690 |
if not input_connectors["output"]: |
|
691 |
input.AddOutput() |
|
692 |
input.RefreshModel() |
|
693 |
input_connectors = input.GetConnectors() |
|
694 |
if value["type"] == SELECTION_CONVERGENCE: |
|
695 |
transition = self.CreateTransition(input_connectors["output"]) |
|
696 |
transition_connectors = transition.GetConnectors() |
|
697 |
inputs.append(transition_connectors["output"]) |
|
698 |
else: |
|
699 |
inputs.append(input_connectors["output"]) |
|
700 |
elif value["type"] == SELECTION_CONVERGENCE: |
|
701 |
wires = input_connectors["output"].GetWires() |
|
702 |
transition = wires[0][0].StartConnected.GetParentBlock() |
|
703 |
transition_connectors = transition.GetConnectors() |
|
704 |
inputs.append(transition_connectors["output"]) |
|
705 |
else: |
|
706 |
inputs.append(input_connectors["output"]) |
|
707 |
id = self.GetNewId() |
|
708 |
divergence = SFC_Divergence(self, value["type"], len(inputs), id) |
|
709 |
pos = inputs[0].GetPosition(False) |
|
710 |
divergence.SetPosition(pos.x, pos.y + SFC_WIRE_MIN_SIZE) |
|
711 |
divergence_connectors = divergence.GetConnectors() |
|
712 |
for i, input in enumerate(inputs): |
|
713 |
pos = input.GetPosition(False) |
|
714 |
wire = self.ConnectConnectors(divergence_connectors["inputs"][i], input) |
|
715 |
wire_size = GetWireSize(input) |
|
716 |
wire.SetPoints([wx.Point(pos.x, pos.y + wire_size), wx.Point(pos.x, pos.y)]) |
|
717 |
input_block = input.GetParentBlock() |
|
718 |
input_block.RefreshOutputPosition() |
|
719 |
divergence.RefreshPosition() |
|
720 |
pos = divergence_connectors["outputs"][0].GetRelPosition() |
|
721 |
divergence.MoveConnector(divergence_connectors["outputs"][0], - pos.x) |
|
722 |
self.AddBlock(divergence) |
|
723 |
self.Controler.AddEditedElementDivergence(self.TagName, id, value["type"]) |
|
724 |
self.RefreshDivergenceModel(divergence) |
|
725 |
if next: |
|
726 |
wire = self.ConnectConnectors(next, divergence_connectors["outputs"][0]) |
|
727 |
pos = divergence_connectors["outputs"][0].GetPosition(False) |
|
728 |
next_pos = next.GetPosition(False) |
|
729 |
next_block = next.GetParentBlock() |
|
730 |
divergence.RefreshOutputPosition((0, pos.y + SFC_WIRE_MIN_SIZE - next_pos.y)) |
|
731 |
divergence.RefreshConnectedPosition(divergence_connectors["outputs"][0]) |
|
732 |
wire.SetPoints([wx.Point(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wx.Point(pos.x, pos.y)]) |
|
733 |
next_block.RefreshModel() |
|
734 |
else: |
|
735 |
if value["type"] == SELECTION_CONVERGENCE: |
|
736 |
previous = divergence_connectors["outputs"][0] |
|
737 |
else: |
|
738 |
transition = self.CreateTransition(divergence_connectors["outputs"][0]) |
|
739 |
transition_connectors = transition.GetConnectors() |
|
740 |
previous = transition_connectors["output"] |
|
741 |
self.CreateStep("Step", previous) |
|
742 |
self.RefreshBuffer() |
|
743 |
self.RefreshScrollBars() |
|
744 |
self.Refresh(False) |
|
745 |
dialog.Destroy() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1584
diff
changeset
|
746 |
|
814 | 747 |
def AddDivergenceBranch(self, divergence): |
748 |
if isinstance(divergence, SFC_Divergence): |
|
749 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
750 |
divergence.AddBranch() |
|
751 |
self.RefreshDivergenceModel(divergence) |
|
752 |
else: |
|
753 |
type = divergence.GetType() |
|
754 |
if type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]: |
|
755 |
divergence.AddBranch() |
|
756 |
divergence_connectors = divergence.GetConnectors() |
|
757 |
if type == SELECTION_DIVERGENCE: |
|
758 |
transition = self.CreateTransition(divergence_connectors["outputs"][-1]) |
|
759 |
transition_connectors = transition.GetConnectors() |
|
760 |
previous = transition_connectors["output"] |
|
761 |
else: |
|
762 |
previous = divergence_connectors["outputs"][-1] |
|
1847
6198190bc121
explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1828
diff
changeset
|
763 |
_step = self.CreateStep("Step", previous) |
814 | 764 |
self.RefreshBuffer() |
765 |
self.RefreshScrollBars() |
|
766 |
self.Refresh(False) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1584
diff
changeset
|
767 |
|
814 | 768 |
def RemoveDivergenceBranch(self, divergence): |
769 |
if isinstance(divergence, SFC_Divergence): |
|
770 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
771 |
divergence.RemoveHandledBranch() |
|
772 |
self.RefreshDivergenceModel(divergence) |
|
773 |
self.RefreshBuffer() |
|
774 |
self.RefreshScrollBars() |
|
775 |
self.Refresh(False) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1584
diff
changeset
|
776 |
|
814 | 777 |
def AddJump(self): |
778 |
if isinstance(self.SelectedElement, SFC_Step) and not self.SelectedElement.Output: |
|
779 |
choices = [] |
|
780 |
for block in self.Blocks: |
|
781 |
if isinstance(block, SFC_Step): |
|
782 |
choices.append(block.GetName()) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1584
diff
changeset
|
783 |
dialog = wx.SingleChoiceDialog(self.ParentWindow, |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1767
diff
changeset
|
784 |
_("Add a new jump"), |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1767
diff
changeset
|
785 |
_("Please choose a target"), |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1767
diff
changeset
|
786 |
choices, |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1767
diff
changeset
|
787 |
wx.DEFAULT_DIALOG_STYLE | wx.OK | wx.CANCEL) |
814 | 788 |
if dialog.ShowModal() == wx.ID_OK: |
789 |
value = dialog.GetStringSelection() |
|
790 |
self.SelectedElement.AddOutput() |
|
791 |
self.RefreshStepModel(self.SelectedElement) |
|
792 |
step_connectors = self.SelectedElement.GetConnectors() |
|
793 |
transition = self.CreateTransition(step_connectors["output"]) |
|
794 |
transition_connectors = transition.GetConnectors() |
|
795 |
id = self.GetNewId() |
|
796 |
jump = SFC_Jump(self, value, id) |
|
797 |
pos = transition_connectors["output"].GetPosition(False) |
|
798 |
jump.SetPosition(pos.x, pos.y + SFC_WIRE_MIN_SIZE) |
|
799 |
self.AddBlock(jump) |
|
800 |
self.Controler.AddEditedElementJump(self.TagName, id) |
|
801 |
jump_connector = jump.GetConnector() |
|
802 |
wire = self.ConnectConnectors(jump_connector, transition_connectors["output"]) |
|
803 |
transition.RefreshOutputPosition() |
|
804 |
wire.SetPoints([wx.Point(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wx.Point(pos.x, pos.y)]) |
|
805 |
self.RefreshJumpModel(jump) |
|
806 |
self.RefreshBuffer() |
|
807 |
self.RefreshScrollBars() |
|
808 |
self.Refresh(False) |
|
809 |
dialog.Destroy() |
|
810 |
||
811 |
def EditStepContent(self, step): |
|
812 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
813 |
Viewer.EditStepContent(self, step) |
|
814 |
else: |
|
1745
f9d32913bad4
clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
815 |
dialog = SFCStepNameDialog(self.ParentWindow, _("Edit step name"), _("Please enter step name"), step.GetName(), wx.OK | wx.CANCEL) |
814 | 816 |
dialog.SetPouNames(self.Controler.GetProjectPouNames(self.Debug)) |
1347
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
814
diff
changeset
|
817 |
dialog.SetVariables(self.Controler.GetEditedElementInterfaceVars(self.TagName, debug=self.Debug)) |
814 | 818 |
dialog.SetStepNames([block.GetName() for block in self.Blocks if isinstance(block, SFC_Step) and block.GetName() != step.GetName()]) |
819 |
if dialog.ShowModal() == wx.ID_OK: |
|
820 |
value = dialog.GetValue() |
|
821 |
step.SetName(value) |
|
822 |
min_size = step.GetMinSize() |
|
823 |
size = step.GetSize() |
|
824 |
step.UpdateSize(max(min_size[0], size[0]), max(min_size[1], size[1])) |
|
825 |
step.RefreshModel() |
|
826 |
self.RefreshBuffer() |
|
827 |
self.RefreshScrollBars() |
|
828 |
self.Refresh(False) |
|
829 |
dialog.Destroy() |
|
830 |
||
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
831 |
# ------------------------------------------------------------------------------- |
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
832 |
# Delete element functions |
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
833 |
# ------------------------------------------------------------------------------- |
814 | 834 |
|
835 |
def DeleteStep(self, step): |
|
836 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
837 |
Viewer.DeleteStep(self, step) |
|
838 |
else: |
|
839 |
step_connectors = step.GetConnectors() |
|
840 |
if not step.GetInitial() or not step_connectors["output"]: |
|
841 |
previous = step.GetPreviousConnector() |
|
842 |
if previous: |
|
843 |
previous_block = previous.GetParentBlock() |
|
844 |
else: |
|
845 |
previous_block = None |
|
846 |
next = step.GetNextConnector() |
|
847 |
if next: |
|
848 |
next_block = next.GetParentBlock() |
|
849 |
else: |
|
850 |
next_block = None |
|
851 |
if isinstance(next_block, SFC_Transition): |
|
852 |
self.RemoveTransition(next_block) |
|
853 |
next = step.GetNextConnector() |
|
854 |
if next: |
|
855 |
next_block = next.GetParentBlock() |
|
856 |
else: |
|
857 |
next_block = None |
|
858 |
elif isinstance(previous_block, SFC_Transition): |
|
859 |
self.RemoveTransition(previous_block) |
|
860 |
previous = step.GetPreviousConnector() |
|
861 |
if previous: |
|
862 |
previous_block = previous.GetParentBlock() |
|
863 |
else: |
|
864 |
previous_block = None |
|
865 |
wire = self.RemoveStep(step) |
|
866 |
self.SelectedElement = None |
|
867 |
if next_block: |
|
868 |
if isinstance(next_block, SFC_Divergence) and next_block.GetType() == SIMULTANEOUS_CONVERGENCE and isinstance(previous_block, SFC_Divergence) and previous_block.GetType() == SIMULTANEOUS_DIVERGENCE: |
|
869 |
wire.Clean() |
|
870 |
self.RemoveWire(wire) |
|
871 |
next_block.RemoveBranch(next) |
|
872 |
if next_block.GetBranchNumber() < 2: |
|
873 |
self.DeleteDivergence(next_block) |
|
874 |
else: |
|
875 |
next_block.RefreshModel() |
|
876 |
previous_block.RemoveBranch(previous) |
|
877 |
if previous_block.GetBranchNumber() < 2: |
|
878 |
self.DeleteDivergence(previous_block) |
|
879 |
else: |
|
880 |
previous_block.RefreshModel() |
|
881 |
else: |
|
882 |
pos = previous.GetPosition(False) |
|
883 |
next_pos = next.GetPosition(False) |
|
884 |
wire_size = GetWireSize(previous_block) |
|
885 |
previous_block.RefreshOutputPosition((0, pos.y + wire_size - next_pos.y)) |
|
886 |
wire.SetPoints([wx.Point(pos.x, pos.y + wire_size), wx.Point(pos.x, pos.y)]) |
|
887 |
if isinstance(next_block, SFC_Divergence): |
|
888 |
next_block.RefreshPosition() |
|
889 |
previous_block.RefreshOutputModel(True) |
|
890 |
else: |
|
891 |
if isinstance(previous_block, SFC_Step): |
|
892 |
previous_block.RemoveOutput() |
|
893 |
self.RefreshStepModel(previous_block) |
|
894 |
elif isinstance(previous_block, SFC_Divergence): |
|
895 |
if previous_block.GetType() in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]: |
|
896 |
self.DeleteDivergence(previous_block) |
|
897 |
else: |
|
898 |
previous_block.RemoveBranch(previous) |
|
899 |
if previous_block.GetBranchNumber() < 2: |
|
900 |
self.DeleteDivergence(previous_block) |
|
901 |
else: |
|
902 |
self.RefreshDivergenceModel(previous_block) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1584
diff
changeset
|
903 |
|
814 | 904 |
def DeleteTransition(self, transition): |
905 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
906 |
Viewer.DeleteTransition(self, transition) |
|
907 |
else: |
|
908 |
previous = transition.GetPreviousConnector() |
|
909 |
previous_block = previous.GetParentBlock() |
|
910 |
next = transition.GetNextConnector() |
|
911 |
next_block = next.GetParentBlock() |
|
912 |
if isinstance(previous_block, SFC_Divergence) and previous_block.GetType() == SELECTION_DIVERGENCE and isinstance(next_block, SFC_Divergence) and next_block.GetType() == SELECTION_CONVERGENCE: |
|
913 |
wires = previous.GetWires() |
|
914 |
if len(wires) != 1: |
|
915 |
return |
|
916 |
wire = wires[0][0] |
|
917 |
wire.Clean() |
|
918 |
self.RemoveWire(wire) |
|
919 |
wires = next.GetWires() |
|
920 |
if len(wires) != 1: |
|
921 |
return |
|
922 |
wire = wires[0][0] |
|
923 |
wire.Clean() |
|
924 |
self.RemoveWire(wire) |
|
925 |
transition.Clean() |
|
926 |
self.RemoveBlock(transition) |
|
927 |
self.Controler.RemoveEditedElementInstance(self.TagName, transition.GetId()) |
|
928 |
previous_block.RemoveBranch(previous) |
|
929 |
if previous_block.GetBranchNumber() < 2: |
|
930 |
self.DeleteDivergence(previous_block) |
|
931 |
else: |
|
932 |
self.RefreshDivergenceModel(previous_block) |
|
933 |
next_block.RemoveBranch(next) |
|
934 |
if next_block.GetBranchNumber() < 2: |
|
935 |
self.DeleteDivergence(next_block) |
|
936 |
else: |
|
937 |
self.RefreshDivergenceModel(next_block) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1584
diff
changeset
|
938 |
|
814 | 939 |
def DeleteDivergence(self, divergence): |
940 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
941 |
Viewer.DeleteDivergence(self, divergence) |
|
942 |
else: |
|
943 |
connectors = divergence.GetConnectors() |
|
944 |
type = divergence.GetType() |
|
945 |
if type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]: |
|
946 |
wires = connectors["outputs"][0].GetWires() |
|
947 |
if len(wires) > 1: |
|
948 |
return |
|
949 |
elif len(wires) == 1: |
|
950 |
next = wires[0][0].StartConnected |
|
951 |
next_block = next.GetParentBlock() |
|
952 |
wire = wires[0][0] |
|
953 |
wire.Clean() |
|
954 |
self.RemoveWire(wire) |
|
955 |
else: |
|
956 |
next = None |
|
957 |
next_block = None |
|
958 |
for index, connector in enumerate(connectors["inputs"]): |
|
959 |
if next and index == 0: |
|
960 |
wires = connector.GetWires() |
|
961 |
wire = wires[0][0] |
|
962 |
previous = wires[0][0].EndConnected |
|
963 |
wire.Clean() |
|
964 |
self.RemoveWire(wire) |
|
965 |
else: |
|
966 |
if type == SELECTION_CONVERGENCE: |
|
967 |
wires = connector.GetWires() |
|
968 |
previous_block = wires[0][0].EndConnected.GetParentBlock() |
|
969 |
self.RemoveTransition(previous_block) |
|
970 |
wires = connector.GetWires() |
|
971 |
wire = wires[0][0] |
|
972 |
previous_connector = wire.EndConnected |
|
973 |
previous_block = previous_connector.GetParentBlock() |
|
974 |
wire.Clean() |
|
975 |
self.RemoveWire(wire) |
|
976 |
if isinstance(previous_block, SFC_Step): |
|
977 |
previous_block.RemoveOutput() |
|
978 |
self.RefreshStepModel(previous_block) |
|
979 |
elif isinstance(previous_block, SFC_Divergence): |
|
980 |
if previous_block.GetType() in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]: |
|
981 |
previous_block.RemoveBranch(previous_connector) |
|
982 |
if previous_block.GetBranchNumber() < 2: |
|
983 |
self.DeleteDivergence(previous_block) |
|
984 |
else: |
|
985 |
self.RefreshDivergenceModel(previous_block) |
|
986 |
else: |
|
987 |
self.DeleteDivergence(previous_block) |
|
988 |
divergence.Clean() |
|
989 |
self.RemoveBlock(divergence) |
|
990 |
self.Controler.RemoveEditedElementInstance(self.TagName, divergence.GetId()) |
|
991 |
if next: |
|
992 |
wire = self.ConnectConnectors(next, previous) |
|
993 |
previous_block = previous.GetParentBlock() |
|
994 |
previous_pos = previous.GetPosition(False) |
|
995 |
next_pos = next.GetPosition(False) |
|
996 |
wire_size = GetWireSize(previous_block) |
|
997 |
previous_block.RefreshOutputPosition((0, previous_pos.y + wire_size - next_pos.y)) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1584
diff
changeset
|
998 |
wire.SetPoints([wx.Point(previous_pos.x, previous_pos.y + wire_size), |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1767
diff
changeset
|
999 |
wx.Point(previous_pos.x, previous_pos.y)]) |
814 | 1000 |
if isinstance(next_block, SFC_Divergence): |
1001 |
next_block.RefreshPosition() |
|
1002 |
previous_block.RefreshOutputModel(True) |
|
1003 |
elif divergence.GetBranchNumber() == 1: |
|
1004 |
wires = connectors["inputs"][0].GetWires() |
|
1005 |
if len(wires) != 1: |
|
1006 |
return |
|
1007 |
wire = wires[0][0] |
|
1008 |
previous = wire.EndConnected |
|
1009 |
previous_block = previous.GetParentBlock() |
|
1010 |
wire.Clean() |
|
1011 |
self.RemoveWire(wire) |
|
1012 |
wires = connectors["outputs"][0].GetWires() |
|
1013 |
if len(wires) != 1: |
|
1014 |
return |
|
1015 |
wire = wires[0][0] |
|
1016 |
next = wire.StartConnected |
|
1017 |
next_block = next.GetParentBlock() |
|
1018 |
wire.Clean() |
|
1019 |
self.RemoveWire(wire) |
|
1020 |
divergence.Clean() |
|
1021 |
self.RemoveBlock(divergence) |
|
1022 |
self.Controler.RemoveEditedElementInstance(self.TagName, divergence.GetId()) |
|
1023 |
wire = self.ConnectConnectors(next, previous) |
|
1024 |
previous_pos = previous.GetPosition(False) |
|
1025 |
next_pos = next.GetPosition(False) |
|
1026 |
wire_size = GetWireSize(previous_block) |
|
1027 |
previous_block.RefreshOutputPosition((previous_pos.x - next_pos.x, previous_pos.y + wire_size - next_pos.y)) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1584
diff
changeset
|
1028 |
wire.SetPoints([wx.Point(previous_pos.x, previous_pos.y + wire_size), |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1767
diff
changeset
|
1029 |
wx.Point(previous_pos.x, previous_pos.y)]) |
814 | 1030 |
if isinstance(next_block, SFC_Divergence): |
1031 |
next_block.RefreshPosition() |
|
1032 |
previous_block.RefreshOutputModel(True) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1584
diff
changeset
|
1033 |
|
814 | 1034 |
def DeleteJump(self, jump): |
1035 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
1036 |
Viewer.DeleteJump(self, jump) |
|
1037 |
else: |
|
1038 |
previous = jump.GetPreviousConnector() |
|
1039 |
previous_block = previous.GetParentBlock() |
|
1040 |
if isinstance(previous_block, SFC_Transition): |
|
1041 |
self.RemoveTransition(previous_block) |
|
1042 |
previous = jump.GetPreviousConnector() |
|
1043 |
if previous: |
|
1044 |
previous_block = previous.GetParentBlock() |
|
1045 |
else: |
|
1046 |
previous_block = None |
|
1047 |
wires = previous.GetWires() |
|
1048 |
if len(wires) != 1: |
|
1049 |
return |
|
1050 |
wire = wires[0][0] |
|
1051 |
wire.Clean() |
|
1052 |
self.RemoveWire(wire) |
|
1053 |
jump.Clean() |
|
1054 |
self.RemoveBlock(jump) |
|
1055 |
self.Controler.RemoveEditedElementInstance(self.TagName, jump.GetId()) |
|
1056 |
if isinstance(previous_block, SFC_Step): |
|
1057 |
previous_block.RemoveOutput() |
|
1058 |
self.RefreshStepModel(previous_block) |
|
1059 |
elif isinstance(previous_block, SFC_Divergence): |
|
1060 |
if previous_block.GetType() in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]: |
|
1061 |
self.DeleteDivergence(previous_block) |
|
1062 |
else: |
|
1063 |
previous_block.RemoveBranch(previous) |
|
1064 |
if previous_block.GetBranchNumber() < 2: |
|
1065 |
self.DeleteDivergence(previous_block) |
|
1066 |
else: |
|
1067 |
previous_block.RefreshModel() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1584
diff
changeset
|
1068 |
|
814 | 1069 |
def DeleteActionBlock(self, actionblock): |
1070 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
1071 |
Viewer.DeleteActionBlock(self, actionblock) |
|
1072 |
else: |
|
1073 |
connector = actionblock.GetConnector() |
|
1074 |
wires = connector.GetWires() |
|
1075 |
if len(wires) != 1: |
|
1076 |
return |
|
1077 |
wire = wires[0][0] |
|
1078 |
step = wire.EndConnected.GetParentBlock() |
|
1079 |
wire.Clean() |
|
1080 |
self.RemoveWire(wire) |
|
1081 |
actionblock.Clean() |
|
1082 |
self.RemoveBlock(actionblock) |
|
1083 |
self.Controler.RemoveEditedElementInstance(self.TagName, actionblock.GetId()) |
|
1084 |
step.RemoveAction() |
|
1085 |
self.RefreshStepModel(step) |
|
1086 |
step.RefreshOutputPosition() |
|
1087 |
step.RefreshOutputModel(True) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1584
diff
changeset
|
1088 |
|
814 | 1089 |
def DeleteWire(self, wire): |
1090 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
1091 |
Viewer.DeleteWire(self, wire) |
|
1092 |
||
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
1093 |
# ------------------------------------------------------------------------------- |
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
1094 |
# Model update functions |
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
1095 |
# ------------------------------------------------------------------------------- |
814 | 1096 |
|
1097 |
def RefreshBlockModel(self, block): |
|
1098 |
blockid = block.GetId() |
|
1099 |
infos = {} |
|
1100 |
infos["type"] = block.GetType() |
|
1101 |
infos["name"] = block.GetName() |
|
1102 |
infos["x"], infos["y"] = block.GetPosition() |
|
1103 |
infos["width"], infos["height"] = block.GetSize() |
|
1104 |
infos["connectors"] = block.GetConnectors() |
|
1105 |
self.Controler.SetEditedElementBlockInfos(self.TagName, blockid, infos) |