FBDViewer.py
changeset 2 93bc4c2cf376
parent 0 b622defdfd98
child 3 86ccc89d7b0b
--- a/FBDViewer.py	Thu Feb 01 18:09:34 2007 +0100
+++ b/FBDViewer.py	Wed Feb 07 18:43:32 2007 +0100
@@ -293,8 +293,8 @@
             connector = variable.GetConnector()
             wires.extend([wire[0] for wire in connector.GetWires()])
         variable.Clean()
-        self.Blocks.remove(self.SelectedElement)
-        self.Elements.remove(self.SelectedElement)
+        self.Blocks.remove(variable)
+        self.Elements.remove(variable)
         self.Controler.RemoveCurrentElementEditingInstance(variable.GetId())
         for wire in wires:
             wire.RefreshModel()
@@ -306,26 +306,47 @@
             connector = connection.GetConnector()
             wires.extend([wire[0] for wire in connector.GetWires()])
         connection.Clean()
-        self.Blocks.remove(self.SelectedElement)
-        self.Elements.remove(self.SelectedElement)
+        self.Blocks.remove(connection)
+        self.Elements.remove(connection)
         self.Controler.RemoveCurrentElementEditingInstance(connection.GetId())
         for wire in wires:
             wire.RefreshModel()
         self.Parent.RefreshProjectTree()
 
     def DeleteComment(self, comment):
-        self.Elements.remove(self.SelectedElement)
+        self.Elements.remove(comment)
         self.Controler.RemoveCurrentElementEditingInstance(comment.GetId())
 
     def DeleteWire(self, wire):
         connected = wire.GetConnected()
         self.SelectedElement.Clean()
-        self.Wires.remove(self.SelectedElement)
-        self.Elements.remove(self.SelectedElement)
+        self.Wires.remove(wire)
+        self.Elements.remove(wire)
         for connector in connected:
             connector.RefreshParentBlock()
 
 #-------------------------------------------------------------------------------
+#                          Edit element content functions
+#-------------------------------------------------------------------------------
+
+    def EditBlockContent(self, block):
+        dialog = BlockPropertiesDialog(self.Parent)
+        dialog.SetBlockList(self.Controler.GetBlockTypes())
+        dialog.SetMinBlockSize(block.GetSize())
+        values = {"name" : block.GetName(), "type" : block.GetType()}
+        values["extension"] = block.GetExtension()
+        dialog.SetValues(values)
+        if dialog.ShowModal() == wxID_OK:
+            values = dialog.GetValues()
+            if "name" in values:
+                block.SetName(values["name"])
+            block.SetExtension(values["extension"])
+            block.SetSize(values["width"], values["height"])
+            block.SetType(values["type"])
+            self.Refresh()
+        dialog.Destroy()
+
+#-------------------------------------------------------------------------------
 #                          Create New Block Dialog
 #-------------------------------------------------------------------------------
 
@@ -419,6 +440,19 @@
         EVT_PAINT(self, self.OnPaint)
         EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK)
     
+    def FindTreeItem(self, root, name):
+        if root.IsOk():
+            if self.TypeTree.GetItemText(root) == name:
+                return root
+            else:
+                item, root_cookie = self.TypeTree.GetFirstChild(root)
+                while item.IsOk():
+                    result = self.FindTreeItem(item, name)
+                    if result:
+                        return result
+                    item, root_cookie = self.TypeTree.GetNextChild(root, root_cookie)
+        return None
+    
     def OnOK(self, event):
         error = []
         selected = self.TypeTree.GetSelection()
@@ -443,6 +477,18 @@
     def SetMinBlockSize(self, size):
         self.MinBlockSize = size
 
+    def SetValues(self, values):
+        for name, value in values.items():
+            if name == "type":
+                item = self.FindTreeItem(self.TypeTree.GetRootItem(), value)
+                if item:
+                    self.TypeTree.SelectItem(item)
+            elif name == "name":
+                self.Name.SetValue(value)
+            elif name == "extension":
+                self.Inputs.SetValue(value)
+        self.RefreshPreview()
+
     def GetValues(self):
         values = {}
         values["type"] = self.TypeTree.GetItemText(self.TypeTree.GetSelection())
@@ -561,7 +607,7 @@
 
         self.staticText3 = wx.StaticText(id=wxID_VARIABLEPROPERTIESDIALOGSTATICTEXT3,
               label='Preview:', name='staticText3', parent=self.MainPanel,
-              pos=wx.Point(24, 72), size=wx.Size(100, 17), style=0)
+              pos=wx.Point(24, 78), size=wx.Size(100, 17), style=0)
 
         self.Class = wx.Choice(id=wxID_VARIABLEPROPERTIESDIALOGCLASS,
               name='Class', parent=self.MainPanel, pos=wx.Point(24, 48),