FBDViewer.py
changeset 2 93bc4c2cf376
parent 0 b622defdfd98
child 3 86ccc89d7b0b
equal deleted inserted replaced
1:e9d01d824086 2:93bc4c2cf376
   291         wires = []
   291         wires = []
   292         if self.SelectedElement.GetType() == INPUT:
   292         if self.SelectedElement.GetType() == INPUT:
   293             connector = variable.GetConnector()
   293             connector = variable.GetConnector()
   294             wires.extend([wire[0] for wire in connector.GetWires()])
   294             wires.extend([wire[0] for wire in connector.GetWires()])
   295         variable.Clean()
   295         variable.Clean()
   296         self.Blocks.remove(self.SelectedElement)
   296         self.Blocks.remove(variable)
   297         self.Elements.remove(self.SelectedElement)
   297         self.Elements.remove(variable)
   298         self.Controler.RemoveCurrentElementEditingInstance(variable.GetId())
   298         self.Controler.RemoveCurrentElementEditingInstance(variable.GetId())
   299         for wire in wires:
   299         for wire in wires:
   300             wire.RefreshModel()
   300             wire.RefreshModel()
   301         self.Parent.RefreshProjectTree()
   301         self.Parent.RefreshProjectTree()
   302 
   302 
   304         wires = []
   304         wires = []
   305         if self.SelectedElement.GetType() == CONTINUATION:
   305         if self.SelectedElement.GetType() == CONTINUATION:
   306             connector = connection.GetConnector()
   306             connector = connection.GetConnector()
   307             wires.extend([wire[0] for wire in connector.GetWires()])
   307             wires.extend([wire[0] for wire in connector.GetWires()])
   308         connection.Clean()
   308         connection.Clean()
   309         self.Blocks.remove(self.SelectedElement)
   309         self.Blocks.remove(connection)
   310         self.Elements.remove(self.SelectedElement)
   310         self.Elements.remove(connection)
   311         self.Controler.RemoveCurrentElementEditingInstance(connection.GetId())
   311         self.Controler.RemoveCurrentElementEditingInstance(connection.GetId())
   312         for wire in wires:
   312         for wire in wires:
   313             wire.RefreshModel()
   313             wire.RefreshModel()
   314         self.Parent.RefreshProjectTree()
   314         self.Parent.RefreshProjectTree()
   315 
   315 
   316     def DeleteComment(self, comment):
   316     def DeleteComment(self, comment):
   317         self.Elements.remove(self.SelectedElement)
   317         self.Elements.remove(comment)
   318         self.Controler.RemoveCurrentElementEditingInstance(comment.GetId())
   318         self.Controler.RemoveCurrentElementEditingInstance(comment.GetId())
   319 
   319 
   320     def DeleteWire(self, wire):
   320     def DeleteWire(self, wire):
   321         connected = wire.GetConnected()
   321         connected = wire.GetConnected()
   322         self.SelectedElement.Clean()
   322         self.SelectedElement.Clean()
   323         self.Wires.remove(self.SelectedElement)
   323         self.Wires.remove(wire)
   324         self.Elements.remove(self.SelectedElement)
   324         self.Elements.remove(wire)
   325         for connector in connected:
   325         for connector in connected:
   326             connector.RefreshParentBlock()
   326             connector.RefreshParentBlock()
       
   327 
       
   328 #-------------------------------------------------------------------------------
       
   329 #                          Edit element content functions
       
   330 #-------------------------------------------------------------------------------
       
   331 
       
   332     def EditBlockContent(self, block):
       
   333         dialog = BlockPropertiesDialog(self.Parent)
       
   334         dialog.SetBlockList(self.Controler.GetBlockTypes())
       
   335         dialog.SetMinBlockSize(block.GetSize())
       
   336         values = {"name" : block.GetName(), "type" : block.GetType()}
       
   337         values["extension"] = block.GetExtension()
       
   338         dialog.SetValues(values)
       
   339         if dialog.ShowModal() == wxID_OK:
       
   340             values = dialog.GetValues()
       
   341             if "name" in values:
       
   342                 block.SetName(values["name"])
       
   343             block.SetExtension(values["extension"])
       
   344             block.SetSize(values["width"], values["height"])
       
   345             block.SetType(values["type"])
       
   346             self.Refresh()
       
   347         dialog.Destroy()
   327 
   348 
   328 #-------------------------------------------------------------------------------
   349 #-------------------------------------------------------------------------------
   329 #                          Create New Block Dialog
   350 #                          Create New Block Dialog
   330 #-------------------------------------------------------------------------------
   351 #-------------------------------------------------------------------------------
   331 
   352 
   416         self.Block = None
   437         self.Block = None
   417         self.MinBlockSize = None
   438         self.MinBlockSize = None
   418         
   439         
   419         EVT_PAINT(self, self.OnPaint)
   440         EVT_PAINT(self, self.OnPaint)
   420         EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK)
   441         EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK)
       
   442     
       
   443     def FindTreeItem(self, root, name):
       
   444         if root.IsOk():
       
   445             if self.TypeTree.GetItemText(root) == name:
       
   446                 return root
       
   447             else:
       
   448                 item, root_cookie = self.TypeTree.GetFirstChild(root)
       
   449                 while item.IsOk():
       
   450                     result = self.FindTreeItem(item, name)
       
   451                     if result:
       
   452                         return result
       
   453                     item, root_cookie = self.TypeTree.GetNextChild(root, root_cookie)
       
   454         return None
   421     
   455     
   422     def OnOK(self, event):
   456     def OnOK(self, event):
   423         error = []
   457         error = []
   424         selected = self.TypeTree.GetSelection()
   458         selected = self.TypeTree.GetSelection()
   425         if not selected.IsOk() or self.TypeTree.GetItemParent(selected) == self.TypeTree.GetRootItem() or selected == self.TypeTree.GetRootItem():
   459         if not selected.IsOk() or self.TypeTree.GetItemParent(selected) == self.TypeTree.GetRootItem() or selected == self.TypeTree.GetRootItem():
   440             for blocktype in category["list"]:
   474             for blocktype in category["list"]:
   441                 blocktype_item = self.TypeTree.AppendItem(category_item, blocktype["name"])
   475                 blocktype_item = self.TypeTree.AppendItem(category_item, blocktype["name"])
   442 
   476 
   443     def SetMinBlockSize(self, size):
   477     def SetMinBlockSize(self, size):
   444         self.MinBlockSize = size
   478         self.MinBlockSize = size
       
   479 
       
   480     def SetValues(self, values):
       
   481         for name, value in values.items():
       
   482             if name == "type":
       
   483                 item = self.FindTreeItem(self.TypeTree.GetRootItem(), value)
       
   484                 if item:
       
   485                     self.TypeTree.SelectItem(item)
       
   486             elif name == "name":
       
   487                 self.Name.SetValue(value)
       
   488             elif name == "extension":
       
   489                 self.Inputs.SetValue(value)
       
   490         self.RefreshPreview()
   445 
   491 
   446     def GetValues(self):
   492     def GetValues(self):
   447         values = {}
   493         values = {}
   448         values["type"] = self.TypeTree.GetItemText(self.TypeTree.GetSelection())
   494         values["type"] = self.TypeTree.GetItemText(self.TypeTree.GetSelection())
   449         if self.Name.GetValue() != "":
   495         if self.Name.GetValue() != "":
   559               label='Name:', name='staticText2', parent=self.MainPanel,
   605               label='Name:', name='staticText2', parent=self.MainPanel,
   560               pos=wx.Point(204, 24), size=wx.Size(70, 17), style=0)
   606               pos=wx.Point(204, 24), size=wx.Size(70, 17), style=0)
   561 
   607 
   562         self.staticText3 = wx.StaticText(id=wxID_VARIABLEPROPERTIESDIALOGSTATICTEXT3,
   608         self.staticText3 = wx.StaticText(id=wxID_VARIABLEPROPERTIESDIALOGSTATICTEXT3,
   563               label='Preview:', name='staticText3', parent=self.MainPanel,
   609               label='Preview:', name='staticText3', parent=self.MainPanel,
   564               pos=wx.Point(24, 72), size=wx.Size(100, 17), style=0)
   610               pos=wx.Point(24, 78), size=wx.Size(100, 17), style=0)
   565 
   611 
   566         self.Class = wx.Choice(id=wxID_VARIABLEPROPERTIESDIALOGCLASS,
   612         self.Class = wx.Choice(id=wxID_VARIABLEPROPERTIESDIALOGCLASS,
   567               name='Class', parent=self.MainPanel, pos=wx.Point(24, 48),
   613               name='Class', parent=self.MainPanel, pos=wx.Point(24, 48),
   568               size=wx.Size(145, 24), style=0)
   614               size=wx.Size(145, 24), style=0)
   569         EVT_CHOICE(self, wxID_VARIABLEPROPERTIESDIALOGCLASS, self.OnClassChanged)
   615         EVT_CHOICE(self, wxID_VARIABLEPROPERTIESDIALOGCLASS, self.OnClassChanged)