595 pou = self.Project.getpou(name) |
595 pou = self.Project.getpou(name) |
596 if pou is not None: |
596 if pou is not None: |
597 pou.setpouType(pou_type) |
597 pou.setpouType(pou_type) |
598 self.BufferProject() |
598 self.BufferProject() |
599 |
599 |
600 def ProjectCreatePouFrom(self, name, from_name): |
600 def GetPouXml(self, pou_name): |
601 if self.Project is not None: |
601 if self.Project is not None: |
602 pou = self.Project.getpou(from_name) |
602 pou = self.Project.getpou(pou_name) |
603 if pou is not None: |
603 if pou is not None: |
604 new_pou = self.Copy(pou) |
604 return pou.generateXMLText('pou', 0) |
605 new_pou.setname(name) |
605 return None |
606 self.Project.insertpou(-1, new_pou) |
|
607 self.BufferProject() |
|
608 |
606 |
609 def PastePou(self, pou_type, pou_xml): |
607 def PastePou(self, pou_type, pou_xml): |
610 ''' |
608 ''' |
611 Adds the POU defined by 'pou_xml' to the current project with type 'pou_type' |
609 Adds the POU defined by 'pou_xml' to the current project with type 'pou_type' |
612 ''' |
610 ''' |
625 |
623 |
626 # prevent violations of POU content restrictions: |
624 # prevent violations of POU content restrictions: |
627 # function blocks cannot be pasted as functions, |
625 # function blocks cannot be pasted as functions, |
628 # programs cannot be pasted as functions or function blocks |
626 # programs cannot be pasted as functions or function blocks |
629 if orig_type == 'functionBlock' and pou_type == 'function' or \ |
627 if orig_type == 'functionBlock' and pou_type == 'function' or \ |
630 orig_type == 'program' and pou_type in ['function', 'functionBlock']: |
628 orig_type == 'program' and pou_type in ['function', 'functionBlock']: |
631 return _('''%s "%s" can't be pasted as a %s.''') % (orig_type, name, pou_type) |
629 return _('''%s "%s" can't be pasted as a %s.''') % (orig_type, name, pou_type) |
632 |
630 |
633 while self.Project.getpou(name): |
631 idx = 0 |
|
632 new_name = name |
|
633 while self.Project.getpou(new_name): |
634 # a POU with that name already exists. |
634 # a POU with that name already exists. |
635 # make a new name and test if a POU with that name exists. |
635 # make a new name and test if a POU with that name exists. |
636 |
636 # append an incrementing numeric suffix to the POU name. |
637 # append an incrementing numeric suffix to the POU name. it |
637 idx += 1 |
638 # doesn't count up perfectly, but as long as it's unique who cares? |
638 new_name = "%s%d" % (name, idx) |
639 if name[-1] >= '0' and name[-1] <= '9': |
639 |
640 last_digit = int(name[-1]) |
|
641 name = name[0:-1] + str(last_digit+1) |
|
642 else: |
|
643 name = name + '1' |
|
644 |
|
645 # we've found a name that does not already exist, use it |
640 # we've found a name that does not already exist, use it |
646 new_pou.setname(name) |
641 new_pou.setname(new_name) |
647 new_pou.setpouType(pou_type) |
642 new_pou.setpouType(pou_type) |
648 |
643 |
649 self.Project.insertpou(-1, new_pou) |
644 self.Project.insertpou(-1, new_pou) |
650 self.BufferProject() |
645 self.BufferProject() |
651 else: |
646 else: |