PLCControler.py
changeset 712 c11b54730a7b
parent 707 e850bc674852
child 738 1ccd08cfae0c
equal deleted inserted replaced
711:5f6a743dcde5 712:c11b54730a7b
   767         if root.nodeName == "pou":
   767         if root.nodeName == "pou":
   768             new_pou = plcopen.pous_pou()
   768             new_pou = plcopen.pous_pou()
   769             new_pou.loadXMLTree(root)
   769             new_pou.loadXMLTree(root)
   770 
   770 
   771             name = new_pou.getname()
   771             name = new_pou.getname()
   772             orig_type = new_pou.getpouType()
       
   773 
       
   774             # prevent violations of POU content restrictions:
       
   775             # function blocks cannot be pasted as functions,
       
   776             # programs cannot be pasted as functions or function blocks
       
   777             if orig_type == 'functionBlock' and pou_type == 'function' or \
       
   778                orig_type == 'program' and pou_type in ['function', 'functionBlock']:
       
   779                 return _('''%s "%s" can't be pasted as a %s.''') % (orig_type, name, pou_type)
       
   780             
   772             
   781             idx = 0
   773             idx = 0
   782             new_name = name
   774             new_name = name
   783             while self.Project.getpou(new_name):
   775             while self.Project.getpou(new_name):
   784                 # a POU with that name already exists.
   776                 # a POU with that name already exists.
   787                 idx += 1
   779                 idx += 1
   788                 new_name = "%s%d" % (name, idx)
   780                 new_name = "%s%d" % (name, idx)
   789                 
   781                 
   790             # we've found a name that does not already exist, use it
   782             # we've found a name that does not already exist, use it
   791             new_pou.setname(new_name)
   783             new_pou.setname(new_name)
   792             new_pou.setpouType(pou_type)
   784             
       
   785             if pou_type is not None:
       
   786                 orig_type = new_pou.getpouType()
       
   787     
       
   788                 # prevent violations of POU content restrictions:
       
   789                 # function blocks cannot be pasted as functions,
       
   790                 # programs cannot be pasted as functions or function blocks
       
   791                 if orig_type == 'functionBlock' and pou_type == 'function' or \
       
   792                    orig_type == 'program' and pou_type in ['function', 'functionBlock']:
       
   793                     return _('''%s "%s" can't be pasted as a %s.''') % (orig_type, name, pou_type)
       
   794                 
       
   795                 new_pou.setpouType(pou_type)
   793 
   796 
   794             self.Project.insertpou(-1, new_pou)
   797             self.Project.insertpou(-1, new_pou)
   795             self.BufferProject()
   798             self.BufferProject()
       
   799             
       
   800             return self.ComputePouName(new_name),
   796         else:
   801         else:
   797             return _("Couldn't paste non-POU object.")
   802             return _("Couldn't paste non-POU object.")
   798 
   803 
   799     # Remove a Pou from project
   804     # Remove a Pou from project
   800     def ProjectRemovePou(self, pou_name):
   805     def ProjectRemovePou(self, pou_name):