PLCControler.py
changeset 712 c11b54730a7b
parent 707 e850bc674852
child 738 1ccd08cfae0c
--- a/PLCControler.py	Thu Jun 14 18:13:32 2012 +0200
+++ b/PLCControler.py	Fri Jun 15 18:02:09 2012 +0200
@@ -769,14 +769,6 @@
             new_pou.loadXMLTree(root)
 
             name = new_pou.getname()
-            orig_type = new_pou.getpouType()
-
-            # prevent violations of POU content restrictions:
-            # function blocks cannot be pasted as functions,
-            # programs cannot be pasted as functions or function blocks
-            if orig_type == 'functionBlock' and pou_type == 'function' or \
-               orig_type == 'program' and pou_type in ['function', 'functionBlock']:
-                return _('''%s "%s" can't be pasted as a %s.''') % (orig_type, name, pou_type)
             
             idx = 0
             new_name = name
@@ -789,10 +781,23 @@
                 
             # we've found a name that does not already exist, use it
             new_pou.setname(new_name)
-            new_pou.setpouType(pou_type)
+            
+            if pou_type is not None:
+                orig_type = new_pou.getpouType()
+    
+                # prevent violations of POU content restrictions:
+                # function blocks cannot be pasted as functions,
+                # programs cannot be pasted as functions or function blocks
+                if orig_type == 'functionBlock' and pou_type == 'function' or \
+                   orig_type == 'program' and pou_type in ['function', 'functionBlock']:
+                    return _('''%s "%s" can't be pasted as a %s.''') % (orig_type, name, pou_type)
+                
+                new_pou.setpouType(pou_type)
 
             self.Project.insertpou(-1, new_pou)
             self.BufferProject()
+            
+            return self.ComputePouName(new_name),
         else:
             return _("Couldn't paste non-POU object.")