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 import math |
28 import math |
28 from time import time as gettime |
29 from time import time as gettime |
29 from types import TupleType |
30 from types import TupleType |
30 from threading import Lock |
31 from threading import Lock |
31 |
32 |
306 else: |
307 else: |
307 id = self.ParentWindow.GetNewId() |
308 id = self.ParentWindow.GetNewId() |
308 block = FBD_Block(self.ParentWindow, values[0], blockname, id, inputs=blockinputs) |
309 block = FBD_Block(self.ParentWindow, values[0], blockname, id, inputs=blockinputs) |
309 width, height = block.GetMinSize() |
310 width, height = block.GetMinSize() |
310 if scaling is not None: |
311 if scaling is not None: |
311 x = round(float(x) / float(scaling[0])) * scaling[0] |
312 x = round(x / scaling[0]) * scaling[0] |
312 y = round(float(y) / float(scaling[1])) * scaling[1] |
313 y = round(y / scaling[1]) * scaling[1] |
313 width = round(float(width) / float(scaling[0]) + 0.5) * scaling[0] |
314 width = round(width / scaling[0] + 0.5) * scaling[0] |
314 height = round(float(height) / float(scaling[1]) + 0.5) * scaling[1] |
315 height = round(height / scaling[1] + 0.5) * scaling[1] |
315 block.SetPosition(x, y) |
316 block.SetPosition(x, y) |
316 block.SetSize(width, height) |
317 block.SetSize(width, height) |
317 self.ParentWindow.AddBlock(block) |
318 self.ParentWindow.AddBlock(block) |
318 self.ParentWindow.Controler.AddEditedElementBlock(tagname, id, values[0], blockname) |
319 self.ParentWindow.Controler.AddEditedElementBlock(tagname, id, values[0], blockname) |
319 self.ParentWindow.RefreshBlockModel(block) |
320 self.ParentWindow.RefreshBlockModel(block) |
858 self.ViewScale = (ZOOM_FACTORS[self.CurrentScale], ZOOM_FACTORS[self.CurrentScale]) |
859 self.ViewScale = (ZOOM_FACTORS[self.CurrentScale], ZOOM_FACTORS[self.CurrentScale]) |
859 if refresh: |
860 if refresh: |
860 self.Editor.Freeze() |
861 self.Editor.Freeze() |
861 if mouse_event is None: |
862 if mouse_event is None: |
862 client_size = self.Editor.GetClientSize() |
863 client_size = self.Editor.GetClientSize() |
863 mouse_pos = wx.Point(client_size[0] / 2, client_size[1] / 2) |
864 mouse_pos = wx.Point(client_size[0] // 2, client_size[1] // 2) |
864 mouse_event = wx.MouseEvent(wx.EVT_MOUSEWHEEL.typeId) |
865 mouse_event = wx.MouseEvent(wx.EVT_MOUSEWHEEL.typeId) |
865 mouse_event.x = mouse_pos.x |
866 mouse_event.x = mouse_pos.x |
866 mouse_event.y = mouse_pos.y |
867 mouse_event.y = mouse_pos.y |
867 else: |
868 else: |
868 mouse_pos = mouse_event.GetPosition() |
869 mouse_pos = mouse_event.GetPosition() |
1337 maxy = max(maxy, extent.y + extent.height) |
1338 maxy = max(maxy, extent.y + extent.height) |
1338 maxx = int(maxx * self.ViewScale[0]) |
1339 maxx = int(maxx * self.ViewScale[0]) |
1339 maxy = int(maxy * self.ViewScale[1]) |
1340 maxy = int(maxy * self.ViewScale[1]) |
1340 self.Editor.SetScrollbars( |
1341 self.Editor.SetScrollbars( |
1341 SCROLLBAR_UNIT, SCROLLBAR_UNIT, |
1342 SCROLLBAR_UNIT, SCROLLBAR_UNIT, |
1342 round(maxx / SCROLLBAR_UNIT) + width_incr, round(maxy / SCROLLBAR_UNIT) + height_incr, |
1343 round(maxx / SCROLLBAR_UNIT) + width_incr, |
|
1344 round(maxy / SCROLLBAR_UNIT) + height_incr, |
1343 xstart, ystart, True) |
1345 xstart, ystart, True) |
1344 |
1346 |
1345 def EnsureVisible(self, block): |
1347 def EnsureVisible(self, block): |
1346 xstart, ystart = self.GetViewStart() |
1348 xstart, ystart = self.GetViewStart() |
1347 window_size = self.Editor.GetClientSize() |
1349 window_size = self.Editor.GetClientSize() |
1354 block_maxx = int(round((block_bbx.x + block_bbx.width) * self.ViewScale[0])) |
1356 block_maxx = int(round((block_bbx.x + block_bbx.width) * self.ViewScale[0])) |
1355 block_maxy = int(round((block_bbx.y + block_bbx.height) * self.ViewScale[1])) |
1357 block_maxy = int(round((block_bbx.y + block_bbx.height) * self.ViewScale[1])) |
1356 |
1358 |
1357 xpos, ypos = xstart, ystart |
1359 xpos, ypos = xstart, ystart |
1358 if block_minx < screen_minx and block_maxx < screen_maxx: |
1360 if block_minx < screen_minx and block_maxx < screen_maxx: |
1359 xpos -= (screen_minx - block_minx) / SCROLLBAR_UNIT + 1 |
1361 xpos -= (screen_minx - block_minx) // SCROLLBAR_UNIT + 1 |
1360 elif block_maxx > screen_maxx and block_minx > screen_minx: |
1362 elif block_maxx > screen_maxx and block_minx > screen_minx: |
1361 xpos += (block_maxx - screen_maxx) / SCROLLBAR_UNIT + 1 |
1363 xpos += (block_maxx - screen_maxx) // SCROLLBAR_UNIT + 1 |
1362 if block_miny < screen_miny and block_maxy < screen_maxy: |
1364 if block_miny < screen_miny and block_maxy < screen_maxy: |
1363 ypos -= (screen_miny - block_miny) / SCROLLBAR_UNIT + 1 |
1365 ypos -= (screen_miny - block_miny) // SCROLLBAR_UNIT + 1 |
1364 elif block_maxy > screen_maxy and block_miny > screen_miny: |
1366 elif block_maxy > screen_maxy and block_miny > screen_miny: |
1365 ypos += (block_maxy - screen_maxy) / SCROLLBAR_UNIT + 1 |
1367 ypos += (block_maxy - screen_maxy) // SCROLLBAR_UNIT + 1 |
1366 self.Scroll(xpos, ypos) |
1368 self.Scroll(xpos, ypos) |
1367 |
1369 |
1368 def SelectInGroup(self, element): |
1370 def SelectInGroup(self, element): |
1369 element.SetSelected(True) |
1371 element.SetSelected(True) |
1370 if self.SelectedElement is None: |
1372 if self.SelectedElement is None: |
2315 if event.MiddleIsDown() or self.Mode == MODE_MOTION: |
2317 if event.MiddleIsDown() or self.Mode == MODE_MOTION: |
2316 if self.StartMousePos is not None and self.StartScreenPos is not None: |
2318 if self.StartMousePos is not None and self.StartScreenPos is not None: |
2317 new_pos = event.GetPosition() |
2319 new_pos = event.GetPosition() |
2318 xmax = self.GetScrollRange(wx.HORIZONTAL) - self.GetScrollThumb(wx.HORIZONTAL) |
2320 xmax = self.GetScrollRange(wx.HORIZONTAL) - self.GetScrollThumb(wx.HORIZONTAL) |
2319 ymax = self.GetScrollRange(wx.VERTICAL) - self.GetScrollThumb(wx.VERTICAL) |
2321 ymax = self.GetScrollRange(wx.VERTICAL) - self.GetScrollThumb(wx.VERTICAL) |
2320 scrollx = max(0, self.StartScreenPos[0] - (new_pos[0] - self.StartMousePos[0]) / SCROLLBAR_UNIT) |
2322 scrollx = max(0, self.StartScreenPos[0] - (new_pos[0] - self.StartMousePos[0]) // SCROLLBAR_UNIT) |
2321 scrolly = max(0, self.StartScreenPos[1] - (new_pos[1] - self.StartMousePos[1]) / SCROLLBAR_UNIT) |
2323 scrolly = max(0, self.StartScreenPos[1] - (new_pos[1] - self.StartMousePos[1]) // SCROLLBAR_UNIT) |
2322 if scrollx > xmax or scrolly > ymax: |
2324 if scrollx > xmax or scrolly > ymax: |
2323 self.RefreshScrollBars(max(0, scrollx - xmax), max(0, scrolly - ymax)) |
2325 self.RefreshScrollBars(max(0, scrollx - xmax), max(0, scrolly - ymax)) |
2324 self.Scroll(scrollx, scrolly) |
2326 self.Scroll(scrollx, scrolly) |
2325 else: |
2327 else: |
2326 self.Scroll(scrollx, scrolly) |
2328 self.Scroll(scrollx, scrolly) |
2544 def AddVariableBlock(self, x, y, scaling, var_class, var_name, var_type): |
2546 def AddVariableBlock(self, x, y, scaling, var_class, var_name, var_type): |
2545 id = self.GetNewId() |
2547 id = self.GetNewId() |
2546 variable = FBD_Variable(self, var_class, var_name, var_type, id) |
2548 variable = FBD_Variable(self, var_class, var_name, var_type, id) |
2547 width, height = variable.GetMinSize() |
2549 width, height = variable.GetMinSize() |
2548 if scaling is not None: |
2550 if scaling is not None: |
2549 x = round(float(x) / float(scaling[0])) * scaling[0] |
2551 x = round(x / scaling[0]) * scaling[0] |
2550 y = round(float(y) / float(scaling[1])) * scaling[1] |
2552 y = round(y / scaling[1]) * scaling[1] |
2551 width = round(float(width) / float(scaling[0]) + 0.5) * scaling[0] |
2553 width = round(width / scaling[0] + 0.5) * scaling[0] |
2552 height = round(float(height) / float(scaling[1]) + 0.5) * scaling[1] |
2554 height = round(height / scaling[1] + 0.5) * scaling[1] |
2553 variable.SetPosition(x, y) |
2555 variable.SetPosition(x, y) |
2554 variable.SetSize(width, height) |
2556 variable.SetSize(width, height) |
2555 self.AddBlock(variable) |
2557 self.AddBlock(variable) |
2556 self.Controler.AddEditedElementVariable(self.GetTagName(), id, var_class) |
2558 self.Controler.AddEditedElementVariable(self.GetTagName(), id, var_class) |
2557 self.RefreshVariableModel(variable) |
2559 self.RefreshVariableModel(variable) |
2564 # Model adding functions |
2566 # Model adding functions |
2565 # ------------------------------------------------------------------------------- |
2567 # ------------------------------------------------------------------------------- |
2566 |
2568 |
2567 def GetScaledSize(self, width, height): |
2569 def GetScaledSize(self, width, height): |
2568 if self.Scaling is not None: |
2570 if self.Scaling is not None: |
2569 width = round(float(width) / float(self.Scaling[0]) + 0.4) * self.Scaling[0] |
2571 width = round(width / self.Scaling[0] + 0.4) * self.Scaling[0] |
2570 height = round(float(height) / float(self.Scaling[1]) + 0.4) * self.Scaling[1] |
2572 height = round(height / self.Scaling[1] + 0.4) * self.Scaling[1] |
2571 return width, height |
2573 return width, height |
2572 |
2574 |
2573 def AddNewElement(self, element, bbox, wire=None, connector=None): |
2575 def AddNewElement(self, element, bbox, wire=None, connector=None): |
2574 min_width, min_height = (element.GetMinSize(True) |
2576 min_width, min_height = (element.GetMinSize(True) |
2575 if isinstance(element, (LD_PowerRail, |
2577 if isinstance(element, (LD_PowerRail, |