editors/Viewer.py
changeset 857 9695969796d0
parent 856 b64e436f000e
child 872 6aadbde5f41e
equal deleted inserted replaced
856:b64e436f000e 857:9695969796d0
  1376     def GetReleaseVariableMenuFunction(self, iec_path):
  1376     def GetReleaseVariableMenuFunction(self, iec_path):
  1377         def ReleaseVariableFunction(event):
  1377         def ReleaseVariableFunction(event):
  1378             self.ReleaseDataValue(iec_path)
  1378             self.ReleaseDataValue(iec_path)
  1379         return ReleaseVariableFunction
  1379         return ReleaseVariableFunction
  1380 
  1380 
       
  1381     def GetChangeVariableTypeMenuFunction(self, type):
       
  1382         def ChangeVariableTypeMenu(event):
       
  1383             self.ChangeVariableType(self.SelectedElement, type)
       
  1384         return ChangeVariableTypeMenu
       
  1385 
       
  1386     def GetChangeConnectionTypeMenuFunction(self, type):
       
  1387         def ChangeConnectionTypeMenu(event):
       
  1388             self.ChangeConnectionType(self.SelectedElement, type)
       
  1389         return ChangeConnectionTypeMenu
       
  1390 
  1381     def PopupForceMenu(self):
  1391     def PopupForceMenu(self):
  1382         iec_path = self.GetElementIECPath(self.SelectedElement)
  1392         iec_path = self.GetElementIECPath(self.SelectedElement)
  1383         if iec_path is not None:
  1393         if iec_path is not None:
  1384             menu = wx.Menu(title='')
  1394             menu = wx.Menu(title='')
  1385             new_id = wx.NewId()
  1395             new_id = wx.NewId()
  1400         if connector is not None and connector.IsCompatible("BOOL"):
  1410         if connector is not None and connector.IsCompatible("BOOL"):
  1401             self.AddBlockPinMenuItems(menu, connector)
  1411             self.AddBlockPinMenuItems(menu, connector)
  1402         else:
  1412         else:
  1403             edit = self.SelectedElement.GetType() in self.Controler.GetProjectPouNames(self.Debug)
  1413             edit = self.SelectedElement.GetType() in self.Controler.GetProjectPouNames(self.Debug)
  1404             self.AddDefaultMenuItems(menu, block=True, edit=edit)
  1414             self.AddDefaultMenuItems(menu, block=True, edit=edit)
       
  1415         self.Editor.PopupMenu(menu)
       
  1416         menu.Destroy()
       
  1417     
       
  1418     def PopupVariableMenu(self):
       
  1419         menu = wx.Menu(title='')
       
  1420         variable_type = self.SelectedElement.GetType()
       
  1421         for type_label, type in [(_("Input"), INPUT),
       
  1422                                  (_("Output"), OUTPUT),
       
  1423                                  (_("InOut"), INOUT)]:
       
  1424             new_id = wx.NewId()
       
  1425             AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_RADIO, text=type_label)
       
  1426             self.Bind(wx.EVT_MENU, self.GetChangeVariableTypeMenuFunction(type), id=new_id)
       
  1427             if type == variable_type:
       
  1428                 menu.Check(new_id, True)
       
  1429         menu.AppendSeparator()
       
  1430         self.AddDefaultMenuItems(menu, block=True)
       
  1431         self.Editor.PopupMenu(menu)
       
  1432         menu.Destroy()
       
  1433     
       
  1434     def PopupConnectionMenu(self):
       
  1435         menu = wx.Menu(title='')
       
  1436         connection_type = self.SelectedElement.GetType()
       
  1437         for type_label, type in [(_("Connector"), CONNECTOR),
       
  1438                                  (_("Continuation"), CONTINUATION)]:
       
  1439             new_id = wx.NewId()
       
  1440             AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_RADIO, text=type_label)
       
  1441             self.Bind(wx.EVT_MENU, self.GetChangeConnectionTypeMenuFunction(type), id=new_id)
       
  1442             if type == connection_type:
       
  1443                 menu.Check(new_id, True)
       
  1444         menu.AppendSeparator()
       
  1445         self.AddDefaultMenuItems(menu, block=True)
  1405         self.Editor.PopupMenu(menu)
  1446         self.Editor.PopupMenu(menu)
  1406         menu.Destroy()
  1447         menu.Destroy()
  1407     
  1448     
  1408     def PopupWireMenu(self, delete=True):
  1449     def PopupWireMenu(self, delete=True):
  1409         menu = wx.Menu(title='')
  1450         menu = wx.Menu(title='')
  1844                                    self.Controler.IsOfType(var_type, "ANY_BIT", self.Debug):
  1885                                    self.Controler.IsOfType(var_type, "ANY_BIT", self.Debug):
  1845                                     self.ParentWindow.OpenGraphicViewer(iec_path)
  1886                                     self.ParentWindow.OpenGraphicViewer(iec_path)
  1846                         else:
  1887                         else:
  1847                             self.ParentWindow.OpenGraphicViewer(iec_path)
  1888                             self.ParentWindow.OpenGraphicViewer(iec_path)
  1848             elif event.ControlDown() and not event.ShiftDown():
  1889             elif event.ControlDown() and not event.ShiftDown():
  1849                 if not isinstance(self.SelectedElement, Group_Element):
  1890                 if not isinstance(self.SelectedElement, Graphic_Group):
  1850                     instance_type = self.SelectedElement.GetType()
  1891                     instance_type = self.SelectedElement.GetType()
  1851                     if self.IsBlock(self.SelectedElement) and instance_type in self.Controler.GetProjectPouNames(self.Debug):
  1892                     if self.IsBlock(self.SelectedElement) and instance_type in self.Controler.GetProjectPouNames(self.Debug):
  1852                         self.ParentWindow.EditProjectElement(ITEM_POU, 
  1893                         self.ParentWindow.EditProjectElement(ITEM_POU, 
  1853                             self.Controler.ComputePouName(instance_type))
  1894                             self.Controler.ComputePouName(instance_type))
  1854                     else:
  1895                     else:
  1855                         self.SelectedElement.OnLeftDClick(event, self.GetLogicalDC(), self.Scaling)
  1896                         self.SelectedElement.OnLeftDClick(event, self.GetLogicalDC(), self.Scaling)
  1856             elif event.ControlDown() and event.ShiftDown():
  1897             elif event.ControlDown() and event.ShiftDown():
  1857                 movex, movey = self.SelectedElement.SetBestSize(self.Scaling)
  1898                 movex, movey = self.SelectedElement.SetBestSize(self.Scaling)
  1858                 self.SelectedElement.RefreshModel()
       
  1859                 self.RefreshBuffer()
       
  1860                 if movex != 0 or movey != 0:
  1899                 if movex != 0 or movey != 0:
       
  1900                     self.SelectedElement.RefreshModel()
       
  1901                     self.RefreshBuffer()
  1861                     self.RefreshRect(self.GetScrolledRect(self.SelectedElement.GetRedrawRect(movex, movey)), False)
  1902                     self.RefreshRect(self.GetScrolledRect(self.SelectedElement.GetRedrawRect(movex, movey)), False)
  1862             else:
  1903             else:
  1863                 self.SelectedElement.OnLeftDClick(event, self.GetLogicalDC(), self.Scaling)
  1904                 self.SelectedElement.OnLeftDClick(event, self.GetLogicalDC(), self.Scaling)
  1864         event.Skip()
  1905         event.Skip()
  1865     
  1906     
  2702         infos["x"], infos["y"] = block.GetPosition()
  2743         infos["x"], infos["y"] = block.GetPosition()
  2703         infos["width"], infos["height"] = block.GetSize()
  2744         infos["width"], infos["height"] = block.GetSize()
  2704         infos["connectors"] = block.GetConnectors()
  2745         infos["connectors"] = block.GetConnectors()
  2705         self.Controler.SetEditedElementBlockInfos(self.TagName, blockid, infos)
  2746         self.Controler.SetEditedElementBlockInfos(self.TagName, blockid, infos)
  2706     
  2747     
       
  2748     def ChangeVariableType(self, variable, new_type):
       
  2749         old_type = variable.GetType()
       
  2750         rect = variable.GetRedrawRect(1, 1)
       
  2751         if old_type != new_type:
       
  2752             variable.SetType(new_type, variable.GetValueType())
       
  2753             id = variable.GetId()
       
  2754             self.Controler.RemoveEditedElementInstance(self.TagName, id)
       
  2755             self.Controler.AddEditedElementVariable(self.TagName, id, new_type)
       
  2756             self.RefreshVariableModel(variable)
       
  2757             self.RefreshBuffer()
       
  2758             self.RefreshVisibleElements()
       
  2759             self.RefreshScrollBars()
       
  2760             variable.Refresh(rect.Union(variable.GetRedrawRect()))
       
  2761     
  2707     def RefreshVariableModel(self, variable):
  2762     def RefreshVariableModel(self, variable):
  2708         variableid = variable.GetId()
  2763         variableid = variable.GetId()
  2709         infos = {}
  2764         infos = {}
  2710         infos["name"] = variable.GetName()
  2765         infos["name"] = variable.GetName()
  2711         if self.CurrentLanguage == "FBD":
  2766         if self.CurrentLanguage == "FBD":
  2712             infos["executionOrder"] = variable.GetExecutionOrder()
  2767             infos["executionOrder"] = variable.GetExecutionOrder()
  2713         infos["x"], infos["y"] = variable.GetPosition()
  2768         infos["x"], infos["y"] = variable.GetPosition()
  2714         infos["width"], infos["height"] = variable.GetSize()
  2769         infos["width"], infos["height"] = variable.GetSize()
  2715         infos["connectors"] = variable.GetConnectors()
  2770         infos["connectors"] = variable.GetConnectors()
  2716         self.Controler.SetEditedElementVariableInfos(self.TagName, variableid, infos)
  2771         self.Controler.SetEditedElementVariableInfos(self.TagName, variableid, infos)
       
  2772 
       
  2773     def ChangeConnectionType(self, connection, new_type):
       
  2774         old_type = connection.GetType()
       
  2775         rect = connection.GetRedrawRect(1, 1)
       
  2776         if old_type != new_type:
       
  2777             connection.SetType(new_type)
       
  2778             id = connection.GetId()
       
  2779             self.Controler.RemoveEditedElementInstance(self.TagName, id)
       
  2780             self.Controler.AddEditedElementConnection(self.TagName, id, new_type)
       
  2781             self.RefreshConnectionModel(connection)
       
  2782             self.RefreshBuffer()
       
  2783             self.RefreshScrollBars()
       
  2784             self.RefreshVisibleElements()
       
  2785             connection.Refresh(rect.Union(connection.GetRedrawRect()))
  2717 
  2786 
  2718     def RefreshConnectionModel(self, connection):
  2787     def RefreshConnectionModel(self, connection):
  2719         connectionid = connection.GetId()
  2788         connectionid = connection.GetId()
  2720         infos = {}
  2789         infos = {}
  2721         infos["name"] = connection.GetName()
  2790         infos["name"] = connection.GetName()