diff -r 82bfc75bcd9d -r 105c20fdeb19 graphics/SFC_Objects.py --- a/graphics/SFC_Objects.py Fri Oct 05 13:48:54 2018 +0300 +++ b/graphics/SFC_Objects.py Fri Oct 05 14:22:01 2018 +0300 @@ -24,6 +24,7 @@ from __future__ import absolute_import +from __future__ import division import wx from six.moves import xrange @@ -59,7 +60,7 @@ self.Size = wx.Size(SFC_STEP_DEFAULT_SIZE[0], SFC_STEP_DEFAULT_SIZE[1]) # Create an input and output connector if not self.Initial: - self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH) + self.Input = Connector(self, "", None, wx.Point(self.Size[0] // 2, 0), NORTH) else: self.Input = None self.Output = None @@ -171,7 +172,7 @@ # Add output connector to step def AddInput(self): if not self.Input: - self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH) + self.Input = Connector(self, "", None, wx.Point(self.Size[0] // 2, 0), NORTH) self.RefreshBoundingBox() # Remove output connector from step @@ -184,7 +185,7 @@ # Add output connector to step def AddOutput(self): if not self.Output: - self.Output = Connector(self, "", None, wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH, onlyone=True) + self.Output = Connector(self, "", None, wx.Point(self.Size[0] // 2, self.Size[1]), SOUTH, onlyone=True) self.RefreshBoundingBox() # Remove output connector from step @@ -197,7 +198,7 @@ # Add action connector to step def AddAction(self): if not self.Action: - self.Action = Connector(self, "", None, wx.Point(self.Size[0], self.Size[1] / 2), EAST, onlyone=True) + self.Action = Connector(self, "", None, wx.Point(self.Size[0], self.Size[1] // 2), EAST, onlyone=True) self.RefreshBoundingBox() # Remove action connector from step @@ -232,11 +233,11 @@ # Refresh the positions of the step connectors def RefreshConnectors(self): scaling = self.Parent.GetScaling() - horizontal_pos = self.Size[0] / 2 - vertical_pos = self.Size[1] / 2 + horizontal_pos = self.Size[0] // 2 + vertical_pos = self.Size[1] // 2 if scaling is not None: - horizontal_pos = round(float(self.Pos.x + horizontal_pos) / float(scaling[0])) * scaling[0] - self.Pos.x - vertical_pos = round(float(self.Pos.y + vertical_pos) / float(scaling[1])) * scaling[1] - self.Pos.y + horizontal_pos = round((self.Pos.x + horizontal_pos) / scaling[0]) * scaling[0] - self.Pos.x + vertical_pos = round((self.Pos.y + vertical_pos) / scaling[1]) * scaling[1] - self.Pos.y # Update input position if it exists if self.Input: self.Input.SetPosition(wx.Point(horizontal_pos, 0)) @@ -363,7 +364,7 @@ # Updates the step size def UpdateSize(self, width, height): - diffx = self.Size.GetWidth() / 2 - width / 2 + diffx = self.Size.GetWidth() // 2 - width // 2 diffy = height - self.Size.GetHeight() self.Move(diffx, 0) Graphic_Element.SetSize(self, width, height) @@ -463,8 +464,8 @@ movex = max(-self.BoundingBox.x, movex) movey = max(-self.BoundingBox.y, movey) if scaling is not None: - movex = round(float(self.Pos.x + movex) / float(scaling[0])) * scaling[0] - self.Pos.x - movey = round(float(self.Pos.y + movey) / float(scaling[1])) * scaling[1] - self.Pos.y + movex = round((self.Pos.x + movex) / scaling[0]) * scaling[0] - self.Pos.x + movey = round((self.Pos.y + movey) / scaling[1]) * scaling[1] - self.Pos.y if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: self.Move(movex, movey) self.RefreshConnected() @@ -557,8 +558,8 @@ if self.Initial: dc.DrawRectangle(self.Pos.x + 2, self.Pos.y + 2, self.Size[0] - 3, self.Size[1] - 3) # Draw step name - name_pos = (self.Pos.x + (self.Size[0] - name_size[0]) / 2, - self.Pos.y + (self.Size[1] - name_size[1]) / 2) + name_pos = (self.Pos.x + (self.Size[0] - name_size[0]) // 2, + self.Pos.y + (self.Size[1] - name_size[1]) // 2) dc.DrawText(self.Name, name_pos[0], name_pos[1]) # Draw input and output connectors if self.Input: @@ -591,8 +592,8 @@ self.Priority = 0 self.Size = wx.Size(SFC_TRANSITION_SIZE[0], SFC_TRANSITION_SIZE[1]) # Create an input and output connector - self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH, onlyone=True) - self.Output = Connector(self, "", None, wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH, onlyone=True) + self.Input = Connector(self, "", None, wx.Point(self.Size[0] // 2, 0), NORTH, onlyone=True) + self.Output = Connector(self, "", None, wx.Point(self.Size[0] // 2, self.Size[1]), SOUTH, onlyone=True) self.SetType(type, condition) self.SetPriority(priority) self.Highlights = {} @@ -713,7 +714,7 @@ # Calculate the bounding box of the condition outside the transition text_width, text_height = self.ConditionSize text_bbx = wx.Rect(self.Pos.x + self.Size[0] + 5, - self.Pos.y + (self.Size[1] - text_height) / 2, + self.Pos.y + (self.Size[1] - text_height) // 2, text_width, text_height) test_text = text_bbx.InsideXY(pt.x, pt.y) @@ -735,8 +736,8 @@ text_width, text_height = self.ConditionSize # Calculate the bounding box size bbx_width = max(bbx_width, self.Size[0] + 5 + text_width) - bbx_y = min(bbx_y, self.Pos.y - max(0, (text_height - self.Size[1]) / 2)) - bbx_height = max(bbx_height, self.Pos.y - bbx_y + (self.Size[1] + text_height) / 2) + bbx_y = min(bbx_y, self.Pos.y - max(0, (text_height - self.Size[1]) // 2)) + bbx_height = max(bbx_height, self.Pos.y - bbx_y + (self.Size[1] + text_height) // 2) self.BoundingBox = wx.Rect(bbx_x, bbx_y, bbx_width + 1, bbx_height + 1) # Returns the connector connected to input @@ -756,11 +757,11 @@ # Refresh the positions of the transition connectors def RefreshConnectors(self): scaling = self.Parent.GetScaling() - horizontal_pos = self.Size[0] / 2 - vertical_pos = self.Size[1] / 2 + horizontal_pos = self.Size[0] // 2 + vertical_pos = self.Size[1] // 2 if scaling is not None: - horizontal_pos = round(float(self.Pos.x + horizontal_pos) / float(scaling[0])) * scaling[0] - self.Pos.x - vertical_pos = round(float(self.Pos.y + vertical_pos) / float(scaling[1])) * scaling[1] - self.Pos.y + horizontal_pos = round((self.Pos.x + horizontal_pos) / scaling[0]) * scaling[0] - self.Pos.x + vertical_pos = round((self.Pos.y + vertical_pos) / scaling[1]) * scaling[1] - self.Pos.y # Update input position self.Input.SetPosition(wx.Point(horizontal_pos, 0)) # Update output position @@ -822,7 +823,7 @@ self.Condition.UnConnect(delete=self.Parent.GetDrawingMode() == FREEDRAWING_MODE) self.Type = type if type == "connection": - self.Condition = Connector(self, "", "BOOL", wx.Point(0, self.Size[1] / 2), WEST) + self.Condition = Connector(self, "", "BOOL", wx.Point(0, self.Size[1] // 2), WEST) else: if condition is None: condition = "" @@ -917,7 +918,7 @@ if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: movex = max(-self.BoundingBox.x, movex) if scaling is not None: - movex = round(float(self.Pos.x + movex) / float(scaling[0])) * scaling[0] - self.Pos.x + movex = round((self.Pos.x + movex) / scaling[0]) * scaling[0] - self.Pos.x self.Move(movex, 0) self.RefreshInputPosition() self.RefreshOutputPosition() @@ -1009,7 +1010,7 @@ # Draw plain rectangle for representing the transition dc.DrawRectangle(self.Pos.x, - self.Pos.y + (self.Size[1] - SFC_TRANSITION_SIZE[1])/2, + self.Pos.y + (self.Size[1] - SFC_TRANSITION_SIZE[1]) // 2, self.Size[0] + 1, SFC_TRANSITION_SIZE[1] + 1) vertical_line_x = self.Input.GetPosition()[0] @@ -1021,7 +1022,7 @@ else: condition = "Transition" condition_pos = (self.Pos.x + self.Size[0] + 5, - self.Pos.y + (self.Size[1] - condition_size[1]) / 2) + self.Pos.y + (self.Size[1] - condition_size[1]) // 2) dc.DrawText(condition, condition_pos[0], condition_pos[1]) # Draw priority number if self.Priority != 0: @@ -1062,7 +1063,7 @@ self.Size = wx.Size((number - 1) * SFC_DEFAULT_SEQUENCE_INTERVAL, self.GetMinSize()[1]) # Create an input and output connector if self.Type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]: - self.Inputs = [Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH, onlyone=True)] + self.Inputs = [Connector(self, "", None, wx.Point(self.Size[0] // 2, 0), NORTH, onlyone=True)] self.Outputs = [] for i in xrange(number): self.Outputs.append(Connector(self, "", None, wx.Point(i * SFC_DEFAULT_SEQUENCE_INTERVAL, self.Size[1]), SOUTH, onlyone=True)) @@ -1070,7 +1071,7 @@ self.Inputs = [] for i in xrange(number): self.Inputs.append(Connector(self, "", None, wx.Point(i * SFC_DEFAULT_SEQUENCE_INTERVAL, 0), NORTH, onlyone=True)) - self.Outputs = [Connector(self, "", None, wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH, onlyone=True)] + self.Outputs = [Connector(self, "", None, wx.Point(self.Size[0] // 2, self.Size[1]), SOUTH, onlyone=True)] self.Value = None self.PreviousValue = None @@ -1285,14 +1286,14 @@ if self.RealConnectors: input.SetPosition(wx.Point(int(round(self.RealConnectors["Inputs"][i] * width)), 0)) else: - input.SetPosition(wx.Point(int(round(float(position.x)*float(width)/float(self.Size[0]))), 0)) + input.SetPosition(wx.Point(int(round(position.x*width / self.Size[0])), 0)) input.MoveConnected() for i, output in enumerate(self.Outputs): position = output.GetRelPosition() if self.RealConnectors: output.SetPosition(wx.Point(int(round(self.RealConnectors["Outputs"][i] * width)), height)) else: - output.SetPosition(wx.Point(int(round(float(position.x)*float(width)/float(self.Size[0]))), height)) + output.SetPosition(wx.Point(int(round(position.x*width / self.Size[0])), height)) output.MoveConnected() self.Size = wx.Size(width, height) self.RefreshBoundingBox() @@ -1368,10 +1369,10 @@ self.RealConnectors = {"Inputs": [], "Outputs": []} for input in self.Inputs: position = input.GetRelPosition() - self.RealConnectors["Inputs"].append(float(position.x)/float(self.Size[0])) + self.RealConnectors["Inputs"].append(position.x / self.Size[0]) for output in self.Outputs: position = output.GetRelPosition() - self.RealConnectors["Outputs"].append(float(position.x)/float(self.Size[0])) + self.RealConnectors["Outputs"].append(position.x / self.Size[0]) Graphic_Element.OnLeftDown(self, event, dc, scaling) # Method called when a LeftUp event have been generated @@ -1425,7 +1426,7 @@ if handle_type == HANDLE_CONNECTOR: movex = max(-self.BoundingBox.x, movex) if scaling is not None: - movex = round(float(self.Pos.x + movex) / float(scaling[0])) * scaling[0] - self.Pos.x + movex = round((self.Pos.x + movex) / scaling[0]) * scaling[0] - self.Pos.x self.MoveConnector(handle, movex) if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: self.RefreshConnectedPosition(handle) @@ -1519,7 +1520,7 @@ self.Size = wx.Size(SFC_JUMP_SIZE[0], SFC_JUMP_SIZE[1]) self.Highlights = [] # Create an input and output connector - self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH, onlyone=True) + self.Input = Connector(self, "", None, wx.Point(self.Size[0] // 2, 0), NORTH, onlyone=True) self.Value = None self.PreviousValue = None @@ -1586,7 +1587,7 @@ # Calculate the bounding box of the condition outside the transition text_width, text_height = self.TargetSize text_bbx = wx.Rect(self.Pos.x + self.Size[0] + 2, - self.Pos.y + (self.Size[1] - text_height) / 2, + self.Pos.y + (self.Size[1] - text_height) // 2, text_width, text_height) return text_bbx.InsideXY(pt.x, pt.y) or Graphic_Element.HitTest(self, pt, connectors) @@ -1609,9 +1610,9 @@ # Refresh the element connectors position def RefreshConnectors(self): scaling = self.Parent.GetScaling() - horizontal_pos = self.Size[0] / 2 + horizontal_pos = self.Size[0] // 2 if scaling is not None: - horizontal_pos = round(float(self.Pos.x + horizontal_pos) / float(scaling[0])) * scaling[0] - self.Pos.x + horizontal_pos = round((self.Pos.x + horizontal_pos) / scaling[0]) * scaling[0] - self.Pos.x self.Input.SetPosition(wx.Point(horizontal_pos, 0)) self.RefreshConnected() @@ -1685,7 +1686,7 @@ if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: movex = max(-self.BoundingBox.x, movex) if scaling is not None: - movex = round(float(self.Pos.x + movex) / float(scaling[0])) * scaling[0] - self.Pos.x + movex = round((self.Pos.x + movex) / scaling[0]) * scaling[0] - self.Pos.x self.Move(movex, 0) self.RefreshInputPosition() return movex, 0 @@ -1760,14 +1761,14 @@ target_size = self.TargetSize # Draw plain rectangle for representing the divergence - dc.DrawLine(self.Pos.x + self.Size[0] / 2, self.Pos.y, self.Pos.x + self.Size[0] / 2, self.Pos.y + self.Size[1]) + dc.DrawLine(self.Pos.x + self.Size[0] // 2, self.Pos.y, self.Pos.x + self.Size[0] // 2, self.Pos.y + self.Size[1]) points = [wx.Point(self.Pos.x, self.Pos.y), - wx.Point(self.Pos.x + self.Size[0] / 2, self.Pos.y + self.Size[1] / 3), + wx.Point(self.Pos.x + self.Size[0] // 2, self.Pos.y + self.Size[1] // 3), wx.Point(self.Pos.x + self.Size[0], self.Pos.y), - wx.Point(self.Pos.x + self.Size[0] / 2, self.Pos.y + self.Size[1])] + wx.Point(self.Pos.x + self.Size[0] // 2, self.Pos.y + self.Size[1])] dc.DrawPolygon(points) target_pos = (self.Pos.x + self.Size[0] + 2, - self.Pos.y + (self.Size[1] - target_size[1]) / 2) + self.Pos.y + (self.Size[1] - target_size[1]) // 2) dc.DrawText(self.Target, target_pos[0], target_pos[1]) # Draw input connector if self.Input: @@ -1795,7 +1796,7 @@ self.MinSize = wx.Size(SFC_ACTION_MIN_SIZE[0], SFC_ACTION_MIN_SIZE[1]) self.Highlights = {} # Create an input and output connector - self.Input = Connector(self, "", None, wx.Point(0, SFC_ACTION_MIN_SIZE[1] / 2), WEST, onlyone=True) + self.Input = Connector(self, "", None, wx.Point(0, SFC_ACTION_MIN_SIZE[1] // 2), WEST, onlyone=True) self.SetActions(actions) self.Value = None self.PreviousValue = None @@ -1843,7 +1844,7 @@ def GetLineSize(self): if len(self.Actions) > 0: - return self.Size[1] / len(self.Actions) + return self.Size[1] // len(self.Actions) else: return SFC_ACTION_MIN_SIZE[1] @@ -1889,9 +1890,9 @@ # Refresh the element connectors position def RefreshConnectors(self): scaling = self.Parent.GetScaling() - vertical_pos = SFC_ACTION_MIN_SIZE[1] / 2 + vertical_pos = SFC_ACTION_MIN_SIZE[1] // 2 if scaling is not None: - vertical_pos = round(float(self.Pos.y + vertical_pos) / float(scaling[1])) * scaling[1] - self.Pos.y + vertical_pos = round((self.Pos.y + vertical_pos) / scaling[1]) * scaling[1] - self.Pos.y self.Input.SetPosition(wx.Point(0, vertical_pos)) self.RefreshConnected() @@ -1962,7 +1963,7 @@ if handle_type == HANDLE_MOVE: movex = max(-self.BoundingBox.x, movex) if scaling is not None: - movex = round(float(self.Pos.x + movex) / float(scaling[0])) * scaling[0] - self.Pos.x + movex = round((self.Pos.x + movex) / scaling[0]) * scaling[0] - self.Pos.x wires = self.Input.GetWires() if len(wires) == 1: input_pos = wires[0][0].GetOtherConnected(self.Input).GetPosition(False) @@ -2033,24 +2034,24 @@ self.Pos.x + self.Size[0], self.Pos.y + i * line_size) qualifier_size = dc.GetTextExtent(action.qualifier) if action.duration != "": - qualifier_pos = (self.Pos.x + (colsize[0] - qualifier_size[0]) / 2, - self.Pos.y + i * line_size + line_size / 2 - qualifier_size[1]) + qualifier_pos = (self.Pos.x + (colsize[0] - qualifier_size[0]) // 2, + self.Pos.y + i * line_size + line_size // 2 - qualifier_size[1]) duration_size = dc.GetTextExtent(action.duration) - duration_pos = (self.Pos.x + (colsize[0] - duration_size[0]) / 2, - self.Pos.y + i * line_size + line_size / 2) + duration_pos = (self.Pos.x + (colsize[0] - duration_size[0]) // 2, + self.Pos.y + i * line_size + line_size // 2) dc.DrawText(action.duration, duration_pos[0], duration_pos[1]) else: - qualifier_pos = (self.Pos.x + (colsize[0] - qualifier_size[0]) / 2, - self.Pos.y + i * line_size + (line_size - qualifier_size[1]) / 2) + qualifier_pos = (self.Pos.x + (colsize[0] - qualifier_size[0]) // 2, + self.Pos.y + i * line_size + (line_size - qualifier_size[1]) // 2) dc.DrawText(action.qualifier, qualifier_pos[0], qualifier_pos[1]) content_size = dc.GetTextExtent(action.value) - content_pos = (self.Pos.x + colsize[0] + (colsize[1] - content_size[0]) / 2, - self.Pos.y + i * line_size + (line_size - content_size[1]) / 2) + content_pos = (self.Pos.x + colsize[0] + (colsize[1] - content_size[0]) // 2, + self.Pos.y + i * line_size + (line_size - content_size[1]) // 2) dc.DrawText(action.value, content_pos[0], content_pos[1]) if action.indicator != "": indicator_size = dc.GetTextExtent(action.indicator) - indicator_pos = (self.Pos.x + colsize[0] + colsize[1] + (colsize[2] - indicator_size[0]) / 2, - self.Pos.y + i * line_size + (line_size - indicator_size[1]) / 2) + indicator_pos = (self.Pos.x + colsize[0] + colsize[1] + (colsize[2] - indicator_size[0]) // 2, + self.Pos.y + i * line_size + (line_size - indicator_size[1]) // 2) dc.DrawText(action.indicator, indicator_pos[0], indicator_pos[1]) if not getattr(dc, "printing", False):