Viewer.py
changeset 510 e7327ea490b4
parent 487 580b04db8c65
child 511 38fdcbc8ebd7
--- a/Viewer.py	Wed Mar 30 16:31:18 2011 +0200
+++ b/Viewer.py	Wed Mar 30 17:52:07 2011 +0200
@@ -281,26 +281,9 @@
                             var_type = values[2]
                         else:
                             var_type = LOCATIONDATATYPES.get(values[0][2], ["BOOL"])[0]
-                        id = self.ParentWindow.GetNewId()
-                        variable = FBD_Variable(self.ParentWindow, var_class, var_name, var_type, id)
-                        width, height = variable.GetMinSize()
-                        if scaling is not None:
-                            x = round(float(x) / float(scaling[0])) * scaling[0]
-                            y = round(float(y) / float(scaling[1])) * scaling[1]
-                            width = round(float(width) / float(scaling[0]) + 0.5) * scaling[0]
-                            height = round(float(height) / float(scaling[1]) + 0.5) * scaling[1]
-                        variable.SetPosition(x, y)
-                        variable.SetSize(width, height)
-                        self.ParentWindow.AddBlock(variable)
                         if not var_name.upper() in [name.upper() for name in self.ParentWindow.Controler.GetEditedElementVariables(tagname, self.ParentWindow.Debug)]:
                             self.ParentWindow.Controler.AddEditedElementPouVar(tagname, var_type, var_name, values[0], values[4])
-                        self.ParentWindow.Controler.AddEditedElementVariable(tagname, id, var_class)
-                        self.ParentWindow.RefreshVariableModel(variable)
-                        self.ParentWindow.RefreshBuffer()
-                        self.ParentWindow.RefreshScrollBars()
-                        self.ParentWindow.RefreshVisibleElements()
-                        self.ParentWindow.ParentWindow.RefreshVariablePanel(tagname)
-                        self.ParentWindow.Refresh(False)
+                        self.ParentWindow.AddVariableBlock(x, y, scaling, var_class, var_name, var_type)
             elif values[3] == tagname:
                 if values[1] == "Output":
                     var_class = OUTPUT
@@ -315,7 +298,7 @@
                         self.GenerateTreeMenu(x, y, scaling, menu, "", var_class, [(values[0], values[2], tree)])
                         self.ParentWindow.PopupMenuXY(menu)
                     else:
-                        self.AddParentVariableBlock(x, y, scaling, var_class, values[0], values[2])
+                        self.ParentWindow.AddVariableBlock(x, y, scaling, var_class, values[0], values[2])
                 else:
                     message = _("Unknown variable \"%s\" for this POU!") % values[0]
             else:
@@ -343,28 +326,9 @@
             
     def GetAddVariableBlockFunction(self, x, y, scaling, var_class, var_name, var_type):
         def AddVariableFunction(event):
-            self.AddParentVariableBlock(x, y, scaling, var_class, var_name, var_type)
+            self.ParentWindow.AddVariableBlock(x, y, scaling, var_class, var_name, var_type)
         return AddVariableFunction
     
-    def AddParentVariableBlock(self, x, y, scaling, var_class, var_name, var_type):
-        id = self.ParentWindow.GetNewId()
-        variable = FBD_Variable(self.ParentWindow, var_class, var_name, var_type, id)
-        width, height = variable.GetMinSize()
-        if scaling is not None:
-            x = round(float(x) / float(scaling[0])) * scaling[0]
-            y = round(float(y) / float(scaling[1])) * scaling[1]
-            width = round(float(width) / float(scaling[0]) + 0.5) * scaling[0]
-            height = round(float(height) / float(scaling[1]) + 0.5) * scaling[1]
-        variable.SetPosition(x, y)
-        variable.SetSize(width, height)
-        self.ParentWindow.AddBlock(variable)
-        self.ParentWindow.Controler.AddEditedElementVariable(self.ParentWindow.GetTagName(), id, var_class)
-        self.ParentWindow.RefreshVariableModel(variable)
-        self.ParentWindow.RefreshBuffer()
-        self.ParentWindow.RefreshScrollBars()
-        self.ParentWindow.RefreshVisibleElements()
-        self.ParentWindow.Refresh(False)
-    
     def ShowMessage(self, message):
         message = wx.MessageDialog(self.ParentWindow, message, _("Error"), wx.OK|wx.ICON_ERROR)
         message.ShowModal()
@@ -1761,6 +1725,29 @@
             event.Skip()
 
 #-------------------------------------------------------------------------------
+#                  Model adding functions from Drop Target
+#-------------------------------------------------------------------------------
+
+    def AddVariableBlock(self, x, y, scaling, var_class, var_name, var_type):
+        id = self.GetNewId()
+        variable = FBD_Variable(self, var_class, var_name, var_type, id)
+        width, height = variable.GetMinSize()
+        if scaling is not None:
+            x = round(float(x) / float(scaling[0])) * scaling[0]
+            y = round(float(y) / float(scaling[1])) * scaling[1]
+            width = round(float(width) / float(scaling[0]) + 0.5) * scaling[0]
+            height = round(float(height) / float(scaling[1]) + 0.5) * scaling[1]
+        variable.SetPosition(x, y)
+        variable.SetSize(width, height)
+        self.AddBlock(variable)
+        self.Controler.AddEditedElementVariable(self.GetTagName(), id, var_class)
+        self.RefreshVariableModel(variable)
+        self.RefreshBuffer()
+        self.RefreshScrollBars()
+        self.RefreshVisibleElements()
+        self.Refresh(False)
+
+#-------------------------------------------------------------------------------
 #                          Model adding functions
 #-------------------------------------------------------------------------------