diff -r 82bfc75bcd9d -r 105c20fdeb19 graphics/GraphicCommons.py --- a/graphics/GraphicCommons.py Fri Oct 05 13:48:54 2018 +0300 +++ b/graphics/GraphicCommons.py Fri Oct 05 14:22:01 2018 +0300 @@ -24,6 +24,7 @@ from __future__ import absolute_import +from __future__ import division from math import * from types import * from six.moves import xrange @@ -116,7 +117,7 @@ def round_scaling(x, n, constraint=0): - fraction = float(x) / float(n) + fraction = x / n if constraint == -1: xround = int(fraction) else: @@ -186,8 +187,8 @@ """ pos = event.GetLogicalPosition(dc) if scaling: - pos.x = round(float(pos.x) / float(scaling[0])) * scaling[0] - pos.y = round(float(pos.y) / float(scaling[1])) * scaling[1] + pos.x = round(pos.x / scaling[0]) * scaling[0] + pos.y = round(pos.y / scaling[1]) * scaling[1] return pos @@ -435,11 +436,11 @@ pt = wx.Point(*self.Parent.CalcUnscrolledPosition(pos.x, pos.y)) left = (self.BoundingBox.x - 2) * scalex - HANDLE_SIZE - center = (self.BoundingBox.x + self.BoundingBox.width / 2) * scalex - HANDLE_SIZE / 2 + center = (self.BoundingBox.x + self.BoundingBox.width // 2) * scalex - HANDLE_SIZE // 2 right = (self.BoundingBox.x + self.BoundingBox.width + 2) * scalex top = (self.BoundingBox.y - 2) * scaley - HANDLE_SIZE - middle = (self.BoundingBox.y + self.BoundingBox.height / 2) * scaley - HANDLE_SIZE / 2 + middle = (self.BoundingBox.y + self.BoundingBox.height / 2) * scaley - HANDLE_SIZE // 2 bottom = (self.BoundingBox.y + self.BoundingBox.height + 2) * scaley extern_rect = wx.Rect(left, top, right + HANDLE_SIZE - left, bottom + HANDLE_SIZE - top) @@ -683,11 +684,11 @@ dc.SetBrush(wx.BLACK_BRUSH) left = (self.BoundingBox.x - 2) * scalex - HANDLE_SIZE - center = (self.BoundingBox.x + self.BoundingBox.width / 2) * scalex - HANDLE_SIZE / 2 + center = (self.BoundingBox.x + self.BoundingBox.width // 2) * scalex - HANDLE_SIZE // 2 right = (self.BoundingBox.x + self.BoundingBox.width + 2) * scalex top = (self.BoundingBox.y - 2) * scaley - HANDLE_SIZE - middle = (self.BoundingBox.y + self.BoundingBox.height / 2) * scaley - HANDLE_SIZE / 2 + middle = (self.BoundingBox.y + self.BoundingBox.height // 2) * scaley - HANDLE_SIZE // 2 bottom = (self.BoundingBox.y + self.BoundingBox.height + 2) * scaley for x, y in [(left, top), (center, top), (right, top), @@ -859,13 +860,13 @@ if horizontally == ALIGN_LEFT: movex = minx - posx elif horizontally == ALIGN_CENTER: - movex = (maxx + minx - width) / 2 - posx + movex = (maxx + minx - width) // 2 - posx elif horizontally == ALIGN_RIGHT: movex = maxx - width - posx if vertically == ALIGN_TOP: movey = miny - posy elif vertically == ALIGN_MIDDLE: - movey = (maxy + miny - height) / 2 - posy + movey = (maxy + miny - height) // 2 - posy elif vertically == ALIGN_BOTTOM: movey = maxy - height - posy if movex != 0 or movey != 0: @@ -1087,7 +1088,7 @@ rect = rect.Union( wx.Rect( parent_pos[0] + self.Pos.x + CONNECTOR_SIZE * self.Direction[0] + - width * (self.Direction[0] - 1) / 2, + width * (self.Direction[0] - 1) // 2, parent_pos[1] + self.Pos.y + CONNECTOR_SIZE * self.Direction[1] + height * (self.Direction[1] - 1), width, height)) @@ -1492,9 +1493,9 @@ if self.Negated: # If connector is negated, draw a circle - xcenter = parent_pos[0] + self.Pos.x + (CONNECTOR_SIZE * self.Direction[0]) / 2 - ycenter = parent_pos[1] + self.Pos.y + (CONNECTOR_SIZE * self.Direction[1]) / 2 - dc.DrawCircle(xcenter, ycenter, CONNECTOR_SIZE / 2) + xcenter = parent_pos[0] + self.Pos.x + (CONNECTOR_SIZE * self.Direction[0]) // 2 + ycenter = parent_pos[1] + self.Pos.y + (CONNECTOR_SIZE * self.Direction[1]) // 2 + dc.DrawCircle(xcenter, ycenter, CONNECTOR_SIZE // 2) else: xstart = parent_pos[0] + self.Pos.x ystart = parent_pos[1] + self.Pos.y @@ -1519,13 +1520,13 @@ yend = ystart + CONNECTOR_SIZE * self.Direction[1] dc.DrawLine(xstart + self.Direction[0], ystart + self.Direction[1], xend, yend) if self.Direction[0] != 0: - ytext = parent_pos[1] + self.Pos.y - name_size[1] / 2 + ytext = parent_pos[1] + self.Pos.y - name_size[1] // 2 if self.Direction[0] < 0: xtext = parent_pos[0] + self.Pos.x + 5 else: xtext = parent_pos[0] + self.Pos.x - (name_size[0] + 5) if self.Direction[1] != 0: - xtext = parent_pos[0] + self.Pos.x - name_size[0] / 2 + xtext = parent_pos[0] + self.Pos.x - name_size[0] // 2 if self.Direction[1] < 0: ytext = parent_pos[1] + self.Pos.y + 5 else: @@ -1544,7 +1545,7 @@ width, height = self.ValueSize dc.DrawText(self.ComputedValue, parent_pos[0] + self.Pos.x + CONNECTOR_SIZE * self.Direction[0] + - width * (self.Direction[0] - 1) / 2, + width * (self.Direction[0] - 1) // 2, parent_pos[1] + self.Pos.y + CONNECTOR_SIZE * self.Direction[1] + height * (self.Direction[1] - 1)) dc.SetFont(self.ParentBlock.Parent.GetFont()) @@ -1611,17 +1612,17 @@ if self.ValueSize is not None: width, height = self.ValueSize if self.BoundingBox[2] > width * 4 or self.BoundingBox[3] > height * 4: - x = self.Points[0].x + width * self.StartPoint[1][0] / 2 + x = self.Points[0].x + width * self.StartPoint[1][0] // 2 y = self.Points[0].y + height * (self.StartPoint[1][1] - 1) rect = rect.Union(wx.Rect(x, y, width, height)) - x = self.Points[-1].x + width * self.EndPoint[1][0] / 2 + x = self.Points[-1].x + width * self.EndPoint[1][0] // 2 y = self.Points[-1].y + height * (self.EndPoint[1][1] - 1) rect = rect.Union(wx.Rect(x, y, width, height)) else: - middle = len(self.Segments) / 2 + len(self.Segments) % 2 - 1 - x = (self.Points[middle].x + self.Points[middle + 1].x - width) / 2 + middle = len(self.Segments) // 2 + len(self.Segments) % 2 - 1 + x = (self.Points[middle].x + self.Points[middle + 1].x - width) // 2 if self.BoundingBox[3] > height and self.Segments[middle] in [NORTH, SOUTH]: - y = (self.Points[middle].y + self.Points[middle + 1].y - height) / 2 + y = (self.Points[middle].y + self.Points[middle + 1].y - height) // 2 else: y = self.Points[middle].y - height rect = rect.Union(wx.Rect(x, y, width, height)) @@ -2092,9 +2093,9 @@ # Current point is positioned in the middle of start point # and end point on the current direction and a point is added if self.Segments[0][0] != 0: - self.Points[1].x = (end.x + start.x) / 2 + self.Points[1].x = (end.x + start.x) // 2 if self.Segments[0][1] != 0: - self.Points[1].y = (end.y + start.y) / 2 + self.Points[1].y = (end.y + start.y) // 2 self.Points.insert(2, wx.Point(self.Points[1].x, self.Points[1].y)) self.Segments.insert(2, DirectionChoice( (self.Segments[1][1], @@ -2136,9 +2137,9 @@ # Current point is positioned in the middle of previous point # and end point on the current direction and a point is added if self.Segments[1][0] != 0: - self.Points[2].x = (self.Points[1].x + end.x) / 2 + self.Points[2].x = (self.Points[1].x + end.x) // 2 if self.Segments[1][1] != 0: - self.Points[2].y = (self.Points[1].y + end.y) / 2 + self.Points[2].y = (self.Points[1].y + end.y) // 2 self.Points.insert(3, wx.Point(self.Points[2].x, self.Points[2].y)) self.Segments.insert( 3, @@ -2160,9 +2161,9 @@ # Current point is positioned in the middle of previous point # and end point on the current direction if self.Segments[i - 1][0] != 0: - self.Points[i].x = (end.x + self.Points[i - 1].x) / 2 + self.Points[i].x = (end.x + self.Points[i - 1].x) // 2 if self.Segments[i - 1][1] != 0: - self.Points[i].y = (end.y + self.Points[i - 1].y) / 2 + self.Points[i].y = (end.y + self.Points[i - 1].y) // 2 # A point is added self.Points.insert(i + 1, wx.Point(self.Points[i].x, self.Points[i].y)) self.Segments.insert( @@ -2242,9 +2243,9 @@ dir = self.EndPoint[1] else: dir = (0, 0) - pointx = max(-dir[0] * MIN_SEGMENT_SIZE, min(int(round(point[0] * width / float(max(lastwidth, 1)))), + pointx = max(-dir[0] * MIN_SEGMENT_SIZE, min(int(round(point[0] * width / max(lastwidth, 1))), width - dir[0] * MIN_SEGMENT_SIZE)) - pointy = max(-dir[1] * MIN_SEGMENT_SIZE, min(int(round(point[1] * height / float(max(lastheight, 1)))), + pointy = max(-dir[1] * MIN_SEGMENT_SIZE, min(int(round(point[1] * height / max(lastheight, 1))), height - dir[1] * MIN_SEGMENT_SIZE)) self.Points[i] = wx.Point(minx + x + pointx, miny + y + pointy) self.StartPoint[0] = self.Points[0] @@ -2266,8 +2267,8 @@ # during a resize dragging for i, point in enumerate(self.RealPoints): if not (i == 0 and self.StartConnected) and not (i == len(self.Points) - 1 and self.EndConnected): - point[0] = point[0] * width / float(max(lastwidth, 1)) - point[1] = point[1] * height / float(max(lastheight, 1)) + point[0] = point[0] * width / max(lastwidth, 1) + point[1] = point[1] * height / max(lastheight, 1) # Calculate the correct position of the points from real points for i, point in enumerate(self.RealPoints): if not (i == 0 and self.StartConnected) and not (i == len(self.Points) - 1 and self.EndConnected): @@ -2399,9 +2400,9 @@ pointx = self.Points[segment].x pointy = self.Points[segment].y if dir[0] != 0: - pointx = (self.Points[segment].x + self.Points[segment + 1].x) / 2 + pointx = (self.Points[segment].x + self.Points[segment + 1].x) // 2 if dir[1] != 0: - pointy = (self.Points[segment].y + self.Points[segment + 1].y) / 2 + pointy = (self.Points[segment].y + self.Points[segment + 1].y) // 2 self.Points.insert(segment + 1, wx.Point(pointx, pointy)) self.Segments.insert(segment + 1, (dir[1], dir[0])) self.Points.insert(segment + 2, wx.Point(pointx, pointy)) @@ -2410,11 +2411,11 @@ p1x = p2x = self.Points[segment].x p1y = p2y = self.Points[segment].y if dir[0] != 0: - p1x = (2 * self.Points[segment].x + self.Points[segment + 1].x) / 3 - p2x = (self.Points[segment].x + 2 * self.Points[segment + 1].x) / 3 + p1x = (2 * self.Points[segment].x + self.Points[segment + 1].x) // 3 + p2x = (self.Points[segment].x + 2 * self.Points[segment + 1].x) // 3 if dir[1] != 0: - p1y = (2 * self.Points[segment].y + self.Points[segment + 1].y) / 3 - p2y = (self.Points[segment].y + 2 * self.Points[segment + 1].y) / 3 + p1y = (2 * self.Points[segment].y + self.Points[segment + 1].y) // 3 + p2y = (self.Points[segment].y + 2 * self.Points[segment + 1].y) // 3 self.Points.insert(segment + 1, wx.Point(p1x, p1y)) self.Segments.insert(segment + 1, (dir[1], dir[0])) self.Points.insert(segment + 2, wx.Point(p1x, p1y)) @@ -2477,9 +2478,9 @@ if event.ControlDown(): direction = (self.StartPoint[1], self.EndPoint[1]) if direction in [(EAST, WEST), (WEST, EAST)]: - avgy = (self.StartPoint[0].y + self.EndPoint[0].y) / 2 + avgy = (self.StartPoint[0].y + self.EndPoint[0].y) // 2 if scaling is not None: - avgy = round(float(avgy) / scaling[1]) * scaling[1] + avgy = round(avgy / scaling[1]) * scaling[1] if self.StartConnected is not None: movey = avgy - self.StartPoint[0].y startblock = self.StartConnected.GetParentBlock() @@ -2498,9 +2499,9 @@ self.MoveEndPoint(wx.Point(self.EndPoint[0].x, avgy)) self.Parent.RefreshBuffer() elif direction in [(NORTH, SOUTH), (SOUTH, NORTH)]: - avgx = (self.StartPoint[0].x + self.EndPoint[0].x) / 2 + avgx = (self.StartPoint[0].x + self.EndPoint[0].x) // 2 if scaling is not None: - avgx = round(float(avgx) / scaling[0]) * scaling[0] + avgx = round(avgx / scaling[0]) * scaling[0] if self.StartConnected is not None: movex = avgx - self.StartPoint[0].x startblock = self.StartConnected.GetParentBlock() @@ -2726,17 +2727,17 @@ if self.ValueSize is not None: width, height = self.ValueSize if self.BoundingBox[2] > width * 4 or self.BoundingBox[3] > height * 4: - x = self.Points[0].x + width * (self.StartPoint[1][0] - 1) / 2 + x = self.Points[0].x + width * (self.StartPoint[1][0] - 1) // 2 y = self.Points[0].y + height * (self.StartPoint[1][1] - 1) dc.DrawText(self.ComputedValue, x, y) - x = self.Points[-1].x + width * (self.EndPoint[1][0] - 1) / 2 + x = self.Points[-1].x + width * (self.EndPoint[1][0] - 1) // 2 y = self.Points[-1].y + height * (self.EndPoint[1][1] - 1) dc.DrawText(self.ComputedValue, x, y) else: - middle = len(self.Segments) / 2 + len(self.Segments) % 2 - 1 - x = (self.Points[middle].x + self.Points[middle + 1].x - width) / 2 + middle = len(self.Segments) // 2 + len(self.Segments) % 2 - 1 + x = (self.Points[middle].x + self.Points[middle + 1].x - width) // 2 if self.BoundingBox[3] > height and self.Segments[middle] in [NORTH, SOUTH]: - y = (self.Points[middle].y + self.Points[middle + 1].y - height) / 2 + y = (self.Points[middle].y + self.Points[middle + 1].y - height) // 2 else: y = self.Points[middle].y - height dc.DrawText(self.ComputedValue, x, y)