branch | python3 |
changeset 3750 | f62625418bff |
parent 3344 | 4a08728a2ea4 |
child 3752 | 9f6f46dbe3ae |
3749:fda6c1a37662 | 3750:f62625418bff |
---|---|
21 # You should have received a copy of the GNU General Public License |
21 # You should have received a copy of the GNU General Public License |
22 # along with this program; if not, write to the Free Software |
22 # along with this program; if not, write to the Free Software |
23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
24 |
24 |
25 |
25 |
26 from __future__ import absolute_import |
26 |
27 from __future__ import division |
27 |
28 from math import * |
28 from math import * |
29 from future.builtins import round |
29 from future.builtins import round |
30 from six import string_types |
30 from six import string_types |
31 from six.moves import xrange |
31 from six.moves import xrange |
32 |
32 |
66 SFC_JUMP_SIZE = (12, 13) # Size of a SFC jump to step |
66 SFC_JUMP_SIZE = (12, 13) # Size of a SFC jump to step |
67 SFC_WIRE_MIN_SIZE = 25 # Size of a wire between two elements |
67 SFC_WIRE_MIN_SIZE = 25 # Size of a wire between two elements |
68 SFC_ACTION_MIN_SIZE = (100, 30) # Minimum size of an action block line |
68 SFC_ACTION_MIN_SIZE = (100, 30) # Minimum size of an action block line |
69 |
69 |
70 # Type definition constants for graphic elements |
70 # Type definition constants for graphic elements |
71 [INPUT, OUTPUT, INOUT] = range(3) |
71 [INPUT, OUTPUT, INOUT] = list(range(3)) |
72 [CONNECTOR, CONTINUATION] = range(2) |
72 [CONNECTOR, CONTINUATION] = list(range(2)) |
73 [LEFTRAIL, RIGHTRAIL] = range(2) |
73 [LEFTRAIL, RIGHTRAIL] = list(range(2)) |
74 [CONTACT_NORMAL, CONTACT_REVERSE, CONTACT_RISING, CONTACT_FALLING] = range(4) |
74 [CONTACT_NORMAL, CONTACT_REVERSE, CONTACT_RISING, CONTACT_FALLING] = list(range(4)) |
75 [COIL_NORMAL, COIL_REVERSE, COIL_SET, COIL_RESET, COIL_RISING, COIL_FALLING] = range(6) |
75 [COIL_NORMAL, COIL_REVERSE, COIL_SET, COIL_RESET, COIL_RISING, COIL_FALLING] = list(range(6)) |
76 [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE, SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE] = range(4) |
76 [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE, SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE] = list(range(4)) |
77 |
77 |
78 # Constants for defining the type of dragging that has been selected |
78 # Constants for defining the type of dragging that has been selected |
79 [HANDLE_MOVE, HANDLE_RESIZE, HANDLE_POINT, HANDLE_SEGMENT, HANDLE_CONNECTOR] = range(5) |
79 [HANDLE_MOVE, HANDLE_RESIZE, HANDLE_POINT, HANDLE_SEGMENT, HANDLE_CONNECTOR] = list(range(5)) |
80 |
80 |
81 # List of value for resize handle that are valid |
81 # List of value for resize handle that are valid |
82 VALID_HANDLES = [(1, 1), (1, 2), (1, 3), (2, 3), (3, 3), (3, 2), (3, 1), (2, 1)] |
82 VALID_HANDLES = [(1, 1), (1, 2), (1, 3), (2, 3), (3, 3), (3, 2), (3, 1), (2, 1)] |
83 |
83 |
84 # Contants for defining the direction of a connector |
84 # Contants for defining the direction of a connector |
85 [EAST, NORTH, WEST, SOUTH] = [(1, 0), (0, -1), (-1, 0), (0, 1)] |
85 [EAST, NORTH, WEST, SOUTH] = [(1, 0), (0, -1), (-1, 0), (0, 1)] |
86 |
86 |
87 # Contants for defining which mode is selected for each view |
87 # Contants for defining which mode is selected for each view |
88 [MODE_SELECTION, MODE_BLOCK, MODE_VARIABLE, MODE_CONNECTION, MODE_COMMENT, |
88 [MODE_SELECTION, MODE_BLOCK, MODE_VARIABLE, MODE_CONNECTION, MODE_COMMENT, |
89 MODE_COIL, MODE_CONTACT, MODE_POWERRAIL, MODE_INITIALSTEP, MODE_STEP, |
89 MODE_COIL, MODE_CONTACT, MODE_POWERRAIL, MODE_INITIALSTEP, MODE_STEP, |
90 MODE_TRANSITION, MODE_DIVERGENCE, MODE_JUMP, MODE_ACTION, MODE_MOTION] = range(15) |
90 MODE_TRANSITION, MODE_DIVERGENCE, MODE_JUMP, MODE_ACTION, MODE_MOTION] = list(range(15)) |
91 |
91 |
92 # Contants for defining alignment types for graphic group |
92 # Contants for defining alignment types for graphic group |
93 [ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT, ALIGN_TOP, ALIGN_MIDDLE, ALIGN_BOTTOM] = range(6) |
93 [ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT, ALIGN_TOP, ALIGN_MIDDLE, ALIGN_BOTTOM] = list(range(6)) |
94 |
94 |
95 # Contants for defining which drawing mode is selected for app |
95 # Contants for defining which drawing mode is selected for app |
96 [FREEDRAWING_MODE, DRIVENDRAWING_MODE] = [1, 2] |
96 [FREEDRAWING_MODE, DRIVENDRAWING_MODE] = [1, 2] |
97 |
97 |
98 # Color for Highlighting |
98 # Color for Highlighting |
1916 return width + 1, height + 1 |
1916 return width + 1, height + 1 |
1917 |
1917 |
1918 # Returns if the point given is on one of the wire segments |
1918 # Returns if the point given is on one of the wire segments |
1919 def HitTest(self, pt, connectors=True): |
1919 def HitTest(self, pt, connectors=True): |
1920 test = False |
1920 test = False |
1921 for i in xrange(len(self.Points) - 1): |
1921 for i in range(len(self.Points) - 1): |
1922 rect = wx.Rect(0, 0, 0, 0) |
1922 rect = wx.Rect(0, 0, 0, 0) |
1923 if i == 0 and self.StartConnected is not None: |
1923 if i == 0 and self.StartConnected is not None: |
1924 x1 = self.Points[i].x - self.Segments[0][0] * CONNECTOR_SIZE |
1924 x1 = self.Points[i].x - self.Segments[0][0] * CONNECTOR_SIZE |
1925 y1 = self.Points[i].y - self.Segments[0][1] * CONNECTOR_SIZE |
1925 y1 = self.Points[i].y - self.Segments[0][1] * CONNECTOR_SIZE |
1926 else: |
1926 else: |
1951 return -1 |
1951 return -1 |
1952 return None |
1952 return None |
1953 |
1953 |
1954 # Returns the wire segment if the point given is on it |
1954 # Returns the wire segment if the point given is on it |
1955 def TestSegment(self, pt, all=False): |
1955 def TestSegment(self, pt, all=False): |
1956 for i in xrange(len(self.Segments)): |
1956 for i in range(len(self.Segments)): |
1957 # If wire is not in a Ladder Diagram, first and last segments are excluded |
1957 # If wire is not in a Ladder Diagram, first and last segments are excluded |
1958 if all or 0 < i < len(self.Segments) - 1: |
1958 if all or 0 < i < len(self.Segments) - 1: |
1959 x1, y1 = self.Points[i].x, self.Points[i].y |
1959 x1, y1 = self.Points[i].x, self.Points[i].y |
1960 x2, y2 = self.Points[i + 1].x, self.Points[i + 1].y |
1960 x2, y2 = self.Points[i + 1].x, self.Points[i + 1].y |
1961 # Calculate a rectangle around the segment |
1961 # Calculate a rectangle around the segment |
2231 points = [point for point in self.Points] |
2231 points = [point for point in self.Points] |
2232 segments = [segment for segment in self.Segments] |
2232 segments = [segment for segment in self.Segments] |
2233 i = 1 |
2233 i = 1 |
2234 while i < len(points) - 1: |
2234 while i < len(points) - 1: |
2235 if points[i] == points[i + 1] and segments[i - 1] == segments[i + 1]: |
2235 if points[i] == points[i + 1] and segments[i - 1] == segments[i + 1]: |
2236 for dummy in xrange(2): |
2236 for dummy in range(2): |
2237 points.pop(i) |
2237 points.pop(i) |
2238 segments.pop(i) |
2238 segments.pop(i) |
2239 else: |
2239 else: |
2240 i += 1 |
2240 i += 1 |
2241 # If the wire isn't in a Ladder Diagram, save the new point list |
2241 # If the wire isn't in a Ladder Diagram, save the new point list |
2457 # Delete the handled segment by removing the two segment points |
2457 # Delete the handled segment by removing the two segment points |
2458 def DeleteSegment(self): |
2458 def DeleteSegment(self): |
2459 handle_type, handle = self.Handle |
2459 handle_type, handle = self.Handle |
2460 if handle_type == HANDLE_SEGMENT: |
2460 if handle_type == HANDLE_SEGMENT: |
2461 segment, _dir = handle |
2461 segment, _dir = handle |
2462 for dummy in xrange(2): |
2462 for dummy in range(2): |
2463 self.Points.pop(segment) |
2463 self.Points.pop(segment) |
2464 self.Segments.pop(segment) |
2464 self.Segments.pop(segment) |
2465 self.GeneratePoints() |
2465 self.GeneratePoints() |
2466 self.RefreshModel() |
2466 self.RefreshModel() |
2467 |
2467 |