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 from __future__ import absolute_import |
|
27 from __future__ import division |
27 from math import * |
28 from math import * |
28 from types import * |
29 from types import * |
29 from six.moves import xrange |
30 from six.moves import xrange |
30 |
31 |
31 import wx |
32 import wx |
184 """ |
185 """ |
185 Function that calculates the nearest point of the grid defined by scaling for the given point |
186 Function that calculates the nearest point of the grid defined by scaling for the given point |
186 """ |
187 """ |
187 pos = event.GetLogicalPosition(dc) |
188 pos = event.GetLogicalPosition(dc) |
188 if scaling: |
189 if scaling: |
189 pos.x = round(float(pos.x) / float(scaling[0])) * scaling[0] |
190 pos.x = round(pos.x / scaling[0]) * scaling[0] |
190 pos.y = round(float(pos.y) / float(scaling[1])) * scaling[1] |
191 pos.y = round(pos.y / scaling[1]) * scaling[1] |
191 return pos |
192 return pos |
192 |
193 |
193 |
194 |
194 def DirectionChoice(v_base, v_target, dir_target): |
195 def DirectionChoice(v_base, v_target, dir_target): |
195 """ |
196 """ |
433 scalex, scaley = dc.GetUserScale() |
434 scalex, scaley = dc.GetUserScale() |
434 pos = event.GetPosition() |
435 pos = event.GetPosition() |
435 pt = wx.Point(*self.Parent.CalcUnscrolledPosition(pos.x, pos.y)) |
436 pt = wx.Point(*self.Parent.CalcUnscrolledPosition(pos.x, pos.y)) |
436 |
437 |
437 left = (self.BoundingBox.x - 2) * scalex - HANDLE_SIZE |
438 left = (self.BoundingBox.x - 2) * scalex - HANDLE_SIZE |
438 center = (self.BoundingBox.x + self.BoundingBox.width / 2) * scalex - HANDLE_SIZE / 2 |
439 center = (self.BoundingBox.x + self.BoundingBox.width // 2) * scalex - HANDLE_SIZE // 2 |
439 right = (self.BoundingBox.x + self.BoundingBox.width + 2) * scalex |
440 right = (self.BoundingBox.x + self.BoundingBox.width + 2) * scalex |
440 |
441 |
441 top = (self.BoundingBox.y - 2) * scaley - HANDLE_SIZE |
442 top = (self.BoundingBox.y - 2) * scaley - HANDLE_SIZE |
442 middle = (self.BoundingBox.y + self.BoundingBox.height / 2) * scaley - HANDLE_SIZE / 2 |
443 middle = (self.BoundingBox.y + self.BoundingBox.height / 2) * scaley - HANDLE_SIZE // 2 |
443 bottom = (self.BoundingBox.y + self.BoundingBox.height + 2) * scaley |
444 bottom = (self.BoundingBox.y + self.BoundingBox.height + 2) * scaley |
444 |
445 |
445 extern_rect = wx.Rect(left, top, right + HANDLE_SIZE - left, bottom + HANDLE_SIZE - top) |
446 extern_rect = wx.Rect(left, top, right + HANDLE_SIZE - left, bottom + HANDLE_SIZE - top) |
446 intern_rect = wx.Rect(left + HANDLE_SIZE, top + HANDLE_SIZE, right - left - HANDLE_SIZE, bottom - top - HANDLE_SIZE) |
447 intern_rect = wx.Rect(left + HANDLE_SIZE, top + HANDLE_SIZE, right - left - HANDLE_SIZE, bottom - top - HANDLE_SIZE) |
447 |
448 |
681 dc.SetUserScale(1, 1) |
682 dc.SetUserScale(1, 1) |
682 dc.SetPen(MiterPen(wx.BLACK)) |
683 dc.SetPen(MiterPen(wx.BLACK)) |
683 dc.SetBrush(wx.BLACK_BRUSH) |
684 dc.SetBrush(wx.BLACK_BRUSH) |
684 |
685 |
685 left = (self.BoundingBox.x - 2) * scalex - HANDLE_SIZE |
686 left = (self.BoundingBox.x - 2) * scalex - HANDLE_SIZE |
686 center = (self.BoundingBox.x + self.BoundingBox.width / 2) * scalex - HANDLE_SIZE / 2 |
687 center = (self.BoundingBox.x + self.BoundingBox.width // 2) * scalex - HANDLE_SIZE // 2 |
687 right = (self.BoundingBox.x + self.BoundingBox.width + 2) * scalex |
688 right = (self.BoundingBox.x + self.BoundingBox.width + 2) * scalex |
688 |
689 |
689 top = (self.BoundingBox.y - 2) * scaley - HANDLE_SIZE |
690 top = (self.BoundingBox.y - 2) * scaley - HANDLE_SIZE |
690 middle = (self.BoundingBox.y + self.BoundingBox.height / 2) * scaley - HANDLE_SIZE / 2 |
691 middle = (self.BoundingBox.y + self.BoundingBox.height // 2) * scaley - HANDLE_SIZE // 2 |
691 bottom = (self.BoundingBox.y + self.BoundingBox.height + 2) * scaley |
692 bottom = (self.BoundingBox.y + self.BoundingBox.height + 2) * scaley |
692 |
693 |
693 for x, y in [(left, top), (center, top), (right, top), |
694 for x, y in [(left, top), (center, top), (right, top), |
694 (left, middle), (right, middle), |
695 (left, middle), (right, middle), |
695 (left, bottom), (center, bottom), (right, bottom)]: |
696 (left, bottom), (center, bottom), (right, bottom)]: |
857 width, height = element.GetSize() |
858 width, height = element.GetSize() |
858 movex = movey = 0 |
859 movex = movey = 0 |
859 if horizontally == ALIGN_LEFT: |
860 if horizontally == ALIGN_LEFT: |
860 movex = minx - posx |
861 movex = minx - posx |
861 elif horizontally == ALIGN_CENTER: |
862 elif horizontally == ALIGN_CENTER: |
862 movex = (maxx + minx - width) / 2 - posx |
863 movex = (maxx + minx - width) // 2 - posx |
863 elif horizontally == ALIGN_RIGHT: |
864 elif horizontally == ALIGN_RIGHT: |
864 movex = maxx - width - posx |
865 movex = maxx - width - posx |
865 if vertically == ALIGN_TOP: |
866 if vertically == ALIGN_TOP: |
866 movey = miny - posy |
867 movey = miny - posy |
867 elif vertically == ALIGN_MIDDLE: |
868 elif vertically == ALIGN_MIDDLE: |
868 movey = (maxy + miny - height) / 2 - posy |
869 movey = (maxy + miny - height) // 2 - posy |
869 elif vertically == ALIGN_BOTTOM: |
870 elif vertically == ALIGN_BOTTOM: |
870 movey = maxy - height - posy |
871 movey = maxy - height - posy |
871 if movex != 0 or movey != 0: |
872 if movex != 0 or movey != 0: |
872 element.Move(movex, movey) |
873 element.Move(movex, movey) |
873 element.RefreshModel() |
874 element.RefreshModel() |
1085 if self.ValueSize is not None: |
1086 if self.ValueSize is not None: |
1086 width, height = self.ValueSize |
1087 width, height = self.ValueSize |
1087 rect = rect.Union( |
1088 rect = rect.Union( |
1088 wx.Rect( |
1089 wx.Rect( |
1089 parent_pos[0] + self.Pos.x + CONNECTOR_SIZE * self.Direction[0] + |
1090 parent_pos[0] + self.Pos.x + CONNECTOR_SIZE * self.Direction[0] + |
1090 width * (self.Direction[0] - 1) / 2, |
1091 width * (self.Direction[0] - 1) // 2, |
1091 parent_pos[1] + self.Pos.y + CONNECTOR_SIZE * self.Direction[1] + |
1092 parent_pos[1] + self.Pos.y + CONNECTOR_SIZE * self.Direction[1] + |
1092 height * (self.Direction[1] - 1), |
1093 height * (self.Direction[1] - 1), |
1093 width, height)) |
1094 width, height)) |
1094 return rect |
1095 return rect |
1095 |
1096 |
1490 else: |
1491 else: |
1491 name_size = self.NameSize |
1492 name_size = self.NameSize |
1492 |
1493 |
1493 if self.Negated: |
1494 if self.Negated: |
1494 # If connector is negated, draw a circle |
1495 # If connector is negated, draw a circle |
1495 xcenter = parent_pos[0] + self.Pos.x + (CONNECTOR_SIZE * self.Direction[0]) / 2 |
1496 xcenter = parent_pos[0] + self.Pos.x + (CONNECTOR_SIZE * self.Direction[0]) // 2 |
1496 ycenter = parent_pos[1] + self.Pos.y + (CONNECTOR_SIZE * self.Direction[1]) / 2 |
1497 ycenter = parent_pos[1] + self.Pos.y + (CONNECTOR_SIZE * self.Direction[1]) // 2 |
1497 dc.DrawCircle(xcenter, ycenter, CONNECTOR_SIZE / 2) |
1498 dc.DrawCircle(xcenter, ycenter, CONNECTOR_SIZE // 2) |
1498 else: |
1499 else: |
1499 xstart = parent_pos[0] + self.Pos.x |
1500 xstart = parent_pos[0] + self.Pos.x |
1500 ystart = parent_pos[1] + self.Pos.y |
1501 ystart = parent_pos[1] + self.Pos.y |
1501 if self.Edge == "rising": |
1502 if self.Edge == "rising": |
1502 # If connector has a rising edge, draw a right arrow |
1503 # If connector has a rising edge, draw a right arrow |
1517 else: |
1518 else: |
1518 xend = xstart + CONNECTOR_SIZE * self.Direction[0] |
1519 xend = xstart + CONNECTOR_SIZE * self.Direction[0] |
1519 yend = ystart + CONNECTOR_SIZE * self.Direction[1] |
1520 yend = ystart + CONNECTOR_SIZE * self.Direction[1] |
1520 dc.DrawLine(xstart + self.Direction[0], ystart + self.Direction[1], xend, yend) |
1521 dc.DrawLine(xstart + self.Direction[0], ystart + self.Direction[1], xend, yend) |
1521 if self.Direction[0] != 0: |
1522 if self.Direction[0] != 0: |
1522 ytext = parent_pos[1] + self.Pos.y - name_size[1] / 2 |
1523 ytext = parent_pos[1] + self.Pos.y - name_size[1] // 2 |
1523 if self.Direction[0] < 0: |
1524 if self.Direction[0] < 0: |
1524 xtext = parent_pos[0] + self.Pos.x + 5 |
1525 xtext = parent_pos[0] + self.Pos.x + 5 |
1525 else: |
1526 else: |
1526 xtext = parent_pos[0] + self.Pos.x - (name_size[0] + 5) |
1527 xtext = parent_pos[0] + self.Pos.x - (name_size[0] + 5) |
1527 if self.Direction[1] != 0: |
1528 if self.Direction[1] != 0: |
1528 xtext = parent_pos[0] + self.Pos.x - name_size[0] / 2 |
1529 xtext = parent_pos[0] + self.Pos.x - name_size[0] // 2 |
1529 if self.Direction[1] < 0: |
1530 if self.Direction[1] < 0: |
1530 ytext = parent_pos[1] + self.Pos.y + 5 |
1531 ytext = parent_pos[1] + self.Pos.y + 5 |
1531 else: |
1532 else: |
1532 ytext = parent_pos[1] + self.Pos.y - (name_size[1] + 5) |
1533 ytext = parent_pos[1] + self.Pos.y - (name_size[1] + 5) |
1533 # Draw the text |
1534 # Draw the text |
1542 self.ValueSize = self.ParentBlock.Parent.GetMiniTextExtent(self.ComputedValue) |
1543 self.ValueSize = self.ParentBlock.Parent.GetMiniTextExtent(self.ComputedValue) |
1543 if self.ValueSize is not None: |
1544 if self.ValueSize is not None: |
1544 width, height = self.ValueSize |
1545 width, height = self.ValueSize |
1545 dc.DrawText(self.ComputedValue, |
1546 dc.DrawText(self.ComputedValue, |
1546 parent_pos[0] + self.Pos.x + CONNECTOR_SIZE * self.Direction[0] + |
1547 parent_pos[0] + self.Pos.x + CONNECTOR_SIZE * self.Direction[0] + |
1547 width * (self.Direction[0] - 1) / 2, |
1548 width * (self.Direction[0] - 1) // 2, |
1548 parent_pos[1] + self.Pos.y + CONNECTOR_SIZE * self.Direction[1] + |
1549 parent_pos[1] + self.Pos.y + CONNECTOR_SIZE * self.Direction[1] + |
1549 height * (self.Direction[1] - 1)) |
1550 height * (self.Direction[1] - 1)) |
1550 dc.SetFont(self.ParentBlock.Parent.GetFont()) |
1551 dc.SetFont(self.ParentBlock.Parent.GetFont()) |
1551 dc.SetTextForeground(wx.BLACK) |
1552 dc.SetTextForeground(wx.BLACK) |
1552 |
1553 |
1609 if self.ValueSize is None and isinstance(self.ComputedValue, (StringType, UnicodeType)): |
1610 if self.ValueSize is None and isinstance(self.ComputedValue, (StringType, UnicodeType)): |
1610 self.ValueSize = self.Parent.GetMiniTextExtent(self.ComputedValue) |
1611 self.ValueSize = self.Parent.GetMiniTextExtent(self.ComputedValue) |
1611 if self.ValueSize is not None: |
1612 if self.ValueSize is not None: |
1612 width, height = self.ValueSize |
1613 width, height = self.ValueSize |
1613 if self.BoundingBox[2] > width * 4 or self.BoundingBox[3] > height * 4: |
1614 if self.BoundingBox[2] > width * 4 or self.BoundingBox[3] > height * 4: |
1614 x = self.Points[0].x + width * self.StartPoint[1][0] / 2 |
1615 x = self.Points[0].x + width * self.StartPoint[1][0] // 2 |
1615 y = self.Points[0].y + height * (self.StartPoint[1][1] - 1) |
1616 y = self.Points[0].y + height * (self.StartPoint[1][1] - 1) |
1616 rect = rect.Union(wx.Rect(x, y, width, height)) |
1617 rect = rect.Union(wx.Rect(x, y, width, height)) |
1617 x = self.Points[-1].x + width * self.EndPoint[1][0] / 2 |
1618 x = self.Points[-1].x + width * self.EndPoint[1][0] // 2 |
1618 y = self.Points[-1].y + height * (self.EndPoint[1][1] - 1) |
1619 y = self.Points[-1].y + height * (self.EndPoint[1][1] - 1) |
1619 rect = rect.Union(wx.Rect(x, y, width, height)) |
1620 rect = rect.Union(wx.Rect(x, y, width, height)) |
1620 else: |
1621 else: |
1621 middle = len(self.Segments) / 2 + len(self.Segments) % 2 - 1 |
1622 middle = len(self.Segments) // 2 + len(self.Segments) % 2 - 1 |
1622 x = (self.Points[middle].x + self.Points[middle + 1].x - width) / 2 |
1623 x = (self.Points[middle].x + self.Points[middle + 1].x - width) // 2 |
1623 if self.BoundingBox[3] > height and self.Segments[middle] in [NORTH, SOUTH]: |
1624 if self.BoundingBox[3] > height and self.Segments[middle] in [NORTH, SOUTH]: |
1624 y = (self.Points[middle].y + self.Points[middle + 1].y - height) / 2 |
1625 y = (self.Points[middle].y + self.Points[middle + 1].y - height) // 2 |
1625 else: |
1626 else: |
1626 y = self.Points[middle].y - height |
1627 y = self.Points[middle].y - height |
1627 rect = rect.Union(wx.Rect(x, y, width, height)) |
1628 rect = rect.Union(wx.Rect(x, y, width, height)) |
1628 return rect |
1629 return rect |
1629 |
1630 |
2090 self.Segments[1][0]), v_end, self.EndPoint[1])) |
2091 self.Segments[1][0]), v_end, self.EndPoint[1])) |
2091 else: |
2092 else: |
2092 # Current point is positioned in the middle of start point |
2093 # Current point is positioned in the middle of start point |
2093 # and end point on the current direction and a point is added |
2094 # and end point on the current direction and a point is added |
2094 if self.Segments[0][0] != 0: |
2095 if self.Segments[0][0] != 0: |
2095 self.Points[1].x = (end.x + start.x) / 2 |
2096 self.Points[1].x = (end.x + start.x) // 2 |
2096 if self.Segments[0][1] != 0: |
2097 if self.Segments[0][1] != 0: |
2097 self.Points[1].y = (end.y + start.y) / 2 |
2098 self.Points[1].y = (end.y + start.y) // 2 |
2098 self.Points.insert(2, wx.Point(self.Points[1].x, self.Points[1].y)) |
2099 self.Points.insert(2, wx.Point(self.Points[1].x, self.Points[1].y)) |
2099 self.Segments.insert(2, DirectionChoice( |
2100 self.Segments.insert(2, DirectionChoice( |
2100 (self.Segments[1][1], |
2101 (self.Segments[1][1], |
2101 self.Segments[1][0]), v_end, self.EndPoint[1])) |
2102 self.Segments[1][0]), v_end, self.EndPoint[1])) |
2102 else: |
2103 else: |
2134 self.Segments[i] = (-self.EndPoint[1][0], -self.EndPoint[1][1]) |
2135 self.Segments[i] = (-self.EndPoint[1][0], -self.EndPoint[1][1]) |
2135 else: |
2136 else: |
2136 # Current point is positioned in the middle of previous point |
2137 # Current point is positioned in the middle of previous point |
2137 # and end point on the current direction and a point is added |
2138 # and end point on the current direction and a point is added |
2138 if self.Segments[1][0] != 0: |
2139 if self.Segments[1][0] != 0: |
2139 self.Points[2].x = (self.Points[1].x + end.x) / 2 |
2140 self.Points[2].x = (self.Points[1].x + end.x) // 2 |
2140 if self.Segments[1][1] != 0: |
2141 if self.Segments[1][1] != 0: |
2141 self.Points[2].y = (self.Points[1].y + end.y) / 2 |
2142 self.Points[2].y = (self.Points[1].y + end.y) // 2 |
2142 self.Points.insert(3, wx.Point(self.Points[2].x, self.Points[2].y)) |
2143 self.Points.insert(3, wx.Point(self.Points[2].x, self.Points[2].y)) |
2143 self.Segments.insert( |
2144 self.Segments.insert( |
2144 3, |
2145 3, |
2145 DirectionChoice((self.Segments[2][1], |
2146 DirectionChoice((self.Segments[2][1], |
2146 self.Segments[2][0]), |
2147 self.Segments[2][0]), |
2158 # If previous direction and end direction are opposed |
2159 # If previous direction and end direction are opposed |
2159 if product(self.Segments[i - 1], self.EndPoint[1]) < 0: |
2160 if product(self.Segments[i - 1], self.EndPoint[1]) < 0: |
2160 # Current point is positioned in the middle of previous point |
2161 # Current point is positioned in the middle of previous point |
2161 # and end point on the current direction |
2162 # and end point on the current direction |
2162 if self.Segments[i - 1][0] != 0: |
2163 if self.Segments[i - 1][0] != 0: |
2163 self.Points[i].x = (end.x + self.Points[i - 1].x) / 2 |
2164 self.Points[i].x = (end.x + self.Points[i - 1].x) // 2 |
2164 if self.Segments[i - 1][1] != 0: |
2165 if self.Segments[i - 1][1] != 0: |
2165 self.Points[i].y = (end.y + self.Points[i - 1].y) / 2 |
2166 self.Points[i].y = (end.y + self.Points[i - 1].y) // 2 |
2166 # A point is added |
2167 # A point is added |
2167 self.Points.insert(i + 1, wx.Point(self.Points[i].x, self.Points[i].y)) |
2168 self.Points.insert(i + 1, wx.Point(self.Points[i].x, self.Points[i].y)) |
2168 self.Segments.insert( |
2169 self.Segments.insert( |
2169 i + 1, |
2170 i + 1, |
2170 DirectionChoice((self.Segments[i][1], |
2171 DirectionChoice((self.Segments[i][1], |
2240 dir = self.StartPoint[1] |
2241 dir = self.StartPoint[1] |
2241 elif i == len(self.Points) - 1: |
2242 elif i == len(self.Points) - 1: |
2242 dir = self.EndPoint[1] |
2243 dir = self.EndPoint[1] |
2243 else: |
2244 else: |
2244 dir = (0, 0) |
2245 dir = (0, 0) |
2245 pointx = max(-dir[0] * MIN_SEGMENT_SIZE, min(int(round(point[0] * width / float(max(lastwidth, 1)))), |
2246 pointx = max(-dir[0] * MIN_SEGMENT_SIZE, min(int(round(point[0] * width / max(lastwidth, 1))), |
2246 width - dir[0] * MIN_SEGMENT_SIZE)) |
2247 width - dir[0] * MIN_SEGMENT_SIZE)) |
2247 pointy = max(-dir[1] * MIN_SEGMENT_SIZE, min(int(round(point[1] * height / float(max(lastheight, 1)))), |
2248 pointy = max(-dir[1] * MIN_SEGMENT_SIZE, min(int(round(point[1] * height / max(lastheight, 1))), |
2248 height - dir[1] * MIN_SEGMENT_SIZE)) |
2249 height - dir[1] * MIN_SEGMENT_SIZE)) |
2249 self.Points[i] = wx.Point(minx + x + pointx, miny + y + pointy) |
2250 self.Points[i] = wx.Point(minx + x + pointx, miny + y + pointy) |
2250 self.StartPoint[0] = self.Points[0] |
2251 self.StartPoint[0] = self.Points[0] |
2251 self.EndPoint[0] = self.Points[-1] |
2252 self.EndPoint[0] = self.Points[-1] |
2252 self.GeneratePoints(False) |
2253 self.GeneratePoints(False) |
2264 # Calculate the real points from the new size, it's important for |
2265 # Calculate the real points from the new size, it's important for |
2265 # keeping a proportionality in the points position with the size |
2266 # keeping a proportionality in the points position with the size |
2266 # during a resize dragging |
2267 # during a resize dragging |
2267 for i, point in enumerate(self.RealPoints): |
2268 for i, point in enumerate(self.RealPoints): |
2268 if not (i == 0 and self.StartConnected) and not (i == len(self.Points) - 1 and self.EndConnected): |
2269 if not (i == 0 and self.StartConnected) and not (i == len(self.Points) - 1 and self.EndConnected): |
2269 point[0] = point[0] * width / float(max(lastwidth, 1)) |
2270 point[0] = point[0] * width / max(lastwidth, 1) |
2270 point[1] = point[1] * height / float(max(lastheight, 1)) |
2271 point[1] = point[1] * height / max(lastheight, 1) |
2271 # Calculate the correct position of the points from real points |
2272 # Calculate the correct position of the points from real points |
2272 for i, point in enumerate(self.RealPoints): |
2273 for i, point in enumerate(self.RealPoints): |
2273 if not (i == 0 and self.StartConnected) and not (i == len(self.Points) - 1 and self.EndConnected): |
2274 if not (i == 0 and self.StartConnected) and not (i == len(self.Points) - 1 and self.EndConnected): |
2274 if i == 0: |
2275 if i == 0: |
2275 dir = self.StartPoint[1] |
2276 dir = self.StartPoint[1] |
2397 segment, dir = handle |
2398 segment, dir = handle |
2398 if len(self.Segments) > 1: |
2399 if len(self.Segments) > 1: |
2399 pointx = self.Points[segment].x |
2400 pointx = self.Points[segment].x |
2400 pointy = self.Points[segment].y |
2401 pointy = self.Points[segment].y |
2401 if dir[0] != 0: |
2402 if dir[0] != 0: |
2402 pointx = (self.Points[segment].x + self.Points[segment + 1].x) / 2 |
2403 pointx = (self.Points[segment].x + self.Points[segment + 1].x) // 2 |
2403 if dir[1] != 0: |
2404 if dir[1] != 0: |
2404 pointy = (self.Points[segment].y + self.Points[segment + 1].y) / 2 |
2405 pointy = (self.Points[segment].y + self.Points[segment + 1].y) // 2 |
2405 self.Points.insert(segment + 1, wx.Point(pointx, pointy)) |
2406 self.Points.insert(segment + 1, wx.Point(pointx, pointy)) |
2406 self.Segments.insert(segment + 1, (dir[1], dir[0])) |
2407 self.Segments.insert(segment + 1, (dir[1], dir[0])) |
2407 self.Points.insert(segment + 2, wx.Point(pointx, pointy)) |
2408 self.Points.insert(segment + 2, wx.Point(pointx, pointy)) |
2408 self.Segments.insert(segment + 2, dir) |
2409 self.Segments.insert(segment + 2, dir) |
2409 else: |
2410 else: |
2410 p1x = p2x = self.Points[segment].x |
2411 p1x = p2x = self.Points[segment].x |
2411 p1y = p2y = self.Points[segment].y |
2412 p1y = p2y = self.Points[segment].y |
2412 if dir[0] != 0: |
2413 if dir[0] != 0: |
2413 p1x = (2 * self.Points[segment].x + self.Points[segment + 1].x) / 3 |
2414 p1x = (2 * self.Points[segment].x + self.Points[segment + 1].x) // 3 |
2414 p2x = (self.Points[segment].x + 2 * self.Points[segment + 1].x) / 3 |
2415 p2x = (self.Points[segment].x + 2 * self.Points[segment + 1].x) // 3 |
2415 if dir[1] != 0: |
2416 if dir[1] != 0: |
2416 p1y = (2 * self.Points[segment].y + self.Points[segment + 1].y) / 3 |
2417 p1y = (2 * self.Points[segment].y + self.Points[segment + 1].y) // 3 |
2417 p2y = (self.Points[segment].y + 2 * self.Points[segment + 1].y) / 3 |
2418 p2y = (self.Points[segment].y + 2 * self.Points[segment + 1].y) // 3 |
2418 self.Points.insert(segment + 1, wx.Point(p1x, p1y)) |
2419 self.Points.insert(segment + 1, wx.Point(p1x, p1y)) |
2419 self.Segments.insert(segment + 1, (dir[1], dir[0])) |
2420 self.Segments.insert(segment + 1, (dir[1], dir[0])) |
2420 self.Points.insert(segment + 2, wx.Point(p1x, p1y)) |
2421 self.Points.insert(segment + 2, wx.Point(p1x, p1y)) |
2421 self.Segments.insert(segment + 2, dir) |
2422 self.Segments.insert(segment + 2, dir) |
2422 self.Points.insert(segment + 3, wx.Point(p2x, p2y)) |
2423 self.Points.insert(segment + 3, wx.Point(p2x, p2y)) |
2475 def OnLeftDClick(self, event, dc, scaling): |
2476 def OnLeftDClick(self, event, dc, scaling): |
2476 rect = self.GetRedrawRect() |
2477 rect = self.GetRedrawRect() |
2477 if event.ControlDown(): |
2478 if event.ControlDown(): |
2478 direction = (self.StartPoint[1], self.EndPoint[1]) |
2479 direction = (self.StartPoint[1], self.EndPoint[1]) |
2479 if direction in [(EAST, WEST), (WEST, EAST)]: |
2480 if direction in [(EAST, WEST), (WEST, EAST)]: |
2480 avgy = (self.StartPoint[0].y + self.EndPoint[0].y) / 2 |
2481 avgy = (self.StartPoint[0].y + self.EndPoint[0].y) // 2 |
2481 if scaling is not None: |
2482 if scaling is not None: |
2482 avgy = round(float(avgy) / scaling[1]) * scaling[1] |
2483 avgy = round(avgy / scaling[1]) * scaling[1] |
2483 if self.StartConnected is not None: |
2484 if self.StartConnected is not None: |
2484 movey = avgy - self.StartPoint[0].y |
2485 movey = avgy - self.StartPoint[0].y |
2485 startblock = self.StartConnected.GetParentBlock() |
2486 startblock = self.StartConnected.GetParentBlock() |
2486 startblock.Move(0, movey) |
2487 startblock.Move(0, movey) |
2487 startblock.RefreshModel() |
2488 startblock.RefreshModel() |
2496 rect.Union(endblock.GetRedrawRect(0, movey)) |
2497 rect.Union(endblock.GetRedrawRect(0, movey)) |
2497 else: |
2498 else: |
2498 self.MoveEndPoint(wx.Point(self.EndPoint[0].x, avgy)) |
2499 self.MoveEndPoint(wx.Point(self.EndPoint[0].x, avgy)) |
2499 self.Parent.RefreshBuffer() |
2500 self.Parent.RefreshBuffer() |
2500 elif direction in [(NORTH, SOUTH), (SOUTH, NORTH)]: |
2501 elif direction in [(NORTH, SOUTH), (SOUTH, NORTH)]: |
2501 avgx = (self.StartPoint[0].x + self.EndPoint[0].x) / 2 |
2502 avgx = (self.StartPoint[0].x + self.EndPoint[0].x) // 2 |
2502 if scaling is not None: |
2503 if scaling is not None: |
2503 avgx = round(float(avgx) / scaling[0]) * scaling[0] |
2504 avgx = round(avgx / scaling[0]) * scaling[0] |
2504 if self.StartConnected is not None: |
2505 if self.StartConnected is not None: |
2505 movex = avgx - self.StartPoint[0].x |
2506 movex = avgx - self.StartPoint[0].x |
2506 startblock = self.StartConnected.GetParentBlock() |
2507 startblock = self.StartConnected.GetParentBlock() |
2507 startblock.Move(movex, 0) |
2508 startblock.Move(movex, 0) |
2508 startblock.RefreshModel() |
2509 startblock.RefreshModel() |
2724 if self.ValueSize is None and isinstance(self.ComputedValue, (StringType, UnicodeType)): |
2725 if self.ValueSize is None and isinstance(self.ComputedValue, (StringType, UnicodeType)): |
2725 self.ValueSize = self.Parent.GetMiniTextExtent(self.ComputedValue) |
2726 self.ValueSize = self.Parent.GetMiniTextExtent(self.ComputedValue) |
2726 if self.ValueSize is not None: |
2727 if self.ValueSize is not None: |
2727 width, height = self.ValueSize |
2728 width, height = self.ValueSize |
2728 if self.BoundingBox[2] > width * 4 or self.BoundingBox[3] > height * 4: |
2729 if self.BoundingBox[2] > width * 4 or self.BoundingBox[3] > height * 4: |
2729 x = self.Points[0].x + width * (self.StartPoint[1][0] - 1) / 2 |
2730 x = self.Points[0].x + width * (self.StartPoint[1][0] - 1) // 2 |
2730 y = self.Points[0].y + height * (self.StartPoint[1][1] - 1) |
2731 y = self.Points[0].y + height * (self.StartPoint[1][1] - 1) |
2731 dc.DrawText(self.ComputedValue, x, y) |
2732 dc.DrawText(self.ComputedValue, x, y) |
2732 x = self.Points[-1].x + width * (self.EndPoint[1][0] - 1) / 2 |
2733 x = self.Points[-1].x + width * (self.EndPoint[1][0] - 1) // 2 |
2733 y = self.Points[-1].y + height * (self.EndPoint[1][1] - 1) |
2734 y = self.Points[-1].y + height * (self.EndPoint[1][1] - 1) |
2734 dc.DrawText(self.ComputedValue, x, y) |
2735 dc.DrawText(self.ComputedValue, x, y) |
2735 else: |
2736 else: |
2736 middle = len(self.Segments) / 2 + len(self.Segments) % 2 - 1 |
2737 middle = len(self.Segments) // 2 + len(self.Segments) % 2 - 1 |
2737 x = (self.Points[middle].x + self.Points[middle + 1].x - width) / 2 |
2738 x = (self.Points[middle].x + self.Points[middle + 1].x - width) // 2 |
2738 if self.BoundingBox[3] > height and self.Segments[middle] in [NORTH, SOUTH]: |
2739 if self.BoundingBox[3] > height and self.Segments[middle] in [NORTH, SOUTH]: |
2739 y = (self.Points[middle].y + self.Points[middle + 1].y - height) / 2 |
2740 y = (self.Points[middle].y + self.Points[middle + 1].y - height) // 2 |
2740 else: |
2741 else: |
2741 y = self.Points[middle].y - height |
2742 y = self.Points[middle].y - height |
2742 dc.DrawText(self.ComputedValue, x, y) |
2743 dc.DrawText(self.ComputedValue, x, y) |
2743 dc.SetFont(self.Parent.GetFont()) |
2744 dc.SetFont(self.Parent.GetFont()) |
2744 dc.SetTextForeground(wx.BLACK) |
2745 dc.SetTextForeground(wx.BLACK) |