594 new_pou = self.Copy(pou) |
594 new_pou = self.Copy(pou) |
595 new_pou.setname(name) |
595 new_pou.setname(name) |
596 self.Project.insertpou(-1, new_pou) |
596 self.Project.insertpou(-1, new_pou) |
597 self.BufferProject() |
597 self.BufferProject() |
598 |
598 |
|
599 def PastePou(self, pou_type, pou_xml): |
|
600 ''' |
|
601 Adds the POU defined by 'pou_xml' to the current project with type 'pou_type' |
|
602 ''' |
|
603 try: |
|
604 tree = minidom.parseString(pou_xml) |
|
605 root = tree.childNodes[0] |
|
606 except: |
|
607 return _("Couldn't paste non-POU object.") |
|
608 |
|
609 if root.nodeName == "pou": |
|
610 new_pou = plcopen.pous_pou() |
|
611 new_pou.loadXMLTree(root) |
|
612 |
|
613 name = new_pou.getname() |
|
614 orig_type = new_pou.getpouType() |
|
615 |
|
616 # prevent violations of POU content restrictions: |
|
617 # function blocks cannot be pasted as functions, |
|
618 # programs cannot be pasted as functions or function blocks |
|
619 if orig_type == 'functionBlock' and pou_type == 'function' or \ |
|
620 orig_type == 'program' and pou_type in ['function', 'functionBlock']: |
|
621 return _('''%s "%s" can't be pasted as a %s.''') % (orig_type, name, pou_type) |
|
622 |
|
623 while self.Project.getpou(name): |
|
624 # a POU with that name already exists. |
|
625 # make a new name and test if a POU with that name exists. |
|
626 |
|
627 # append an incrementing numeric suffix to the POU name. it |
|
628 # doesn't count up perfectly, but as long as it's unique who cares? |
|
629 if name[-1] >= '0' and name[-1] <= '9': |
|
630 last_digit = int(name[-1]) |
|
631 name = name[0:-1] + str(last_digit+1) |
|
632 else: |
|
633 name = name + '1' |
|
634 |
|
635 # we've found a name that does not already exist, use it |
|
636 new_pou.setname(name) |
|
637 new_pou.setpouType(pou_type) |
|
638 |
|
639 self.Project.insertpou(-1, new_pou) |
|
640 self.BufferProject() |
|
641 else: |
|
642 return _("Couldn't paste non-POU object.") |
|
643 |
599 # Remove a Pou from project |
644 # Remove a Pou from project |
600 def ProjectRemovePou(self, pou_name): |
645 def ProjectRemovePou(self, pou_name): |
601 if self.Project is not None: |
646 if self.Project is not None: |
602 self.Project.removepou(pou_name) |
647 self.Project.removepou(pou_name) |
603 self.BufferProject() |
648 self.BufferProject() |
1645 exclude = {} |
1690 exclude = {} |
1646 for root in tree.childNodes: |
1691 for root in tree.childNodes: |
1647 if root.nodeType == tree.ELEMENT_NODE and root.nodeName == "paste": |
1692 if root.nodeType == tree.ELEMENT_NODE and root.nodeName == "paste": |
1648 for child in root.childNodes: |
1693 for child in root.childNodes: |
1649 if child.nodeType == tree.ELEMENT_NODE: |
1694 if child.nodeType == tree.ELEMENT_NODE: |
|
1695 if not child.nodeName in plcopen.ElementNameToClass: |
|
1696 return _("\"%s\" element can't be pasted here!!!")%child.nodeName |
|
1697 |
1650 classname = plcopen.ElementNameToClass[child.nodeName] |
1698 classname = plcopen.ElementNameToClass[child.nodeName] |
1651 if not self.CheckPasteCompatibility[bodytype](classname): |
1699 if not self.CheckPasteCompatibility[bodytype](classname): |
1652 return _("\"%s\" element can't be pasted here!!!")%child.nodeName |
1700 return _("\"%s\" element can't be pasted here!!!")%child.nodeName |
1653 |
1701 |
1654 classobj = getattr(plcopen, classname, None) |
1702 classobj = getattr(plcopen, classname, None) |