842 def PastePou(self, pou_type, pou_xml): |
842 def PastePou(self, pou_type, pou_xml): |
843 ''' |
843 ''' |
844 Adds the POU defined by 'pou_xml' to the current project with type 'pou_type' |
844 Adds the POU defined by 'pou_xml' to the current project with type 'pou_type' |
845 ''' |
845 ''' |
846 try: |
846 try: |
847 new_pou = LoadPou(pou_xml) |
847 new_pou, error = LoadPou(pou_xml) |
848 except: |
848 except: |
|
849 error = "" |
|
850 if error is not None: |
849 return _("Couldn't paste non-POU object.") |
851 return _("Couldn't paste non-POU object.") |
850 |
852 |
851 name = new_pou.getname() |
853 name = new_pou.getname() |
852 |
854 |
853 idx = 0 |
855 idx = 0 |
2205 # Get ids already by all the instances in edited element |
2207 # Get ids already by all the instances in edited element |
2206 used_id = dict([(instance.getlocalId(), True) for instance in element.getinstances()]) |
2208 used_id = dict([(instance.getlocalId(), True) for instance in element.getinstances()]) |
2207 new_id = {} |
2209 new_id = {} |
2208 |
2210 |
2209 try: |
2211 try: |
2210 instances = LoadPouInstances(text.encode("utf-8"), bodytype) |
2212 instances, error = LoadPouInstances(text.encode("utf-8"), bodytype) |
2211 if len(instances) == 0: |
|
2212 raise ValueError |
|
2213 except: |
2213 except: |
|
2214 instances, error = [], "" |
|
2215 if error is not None or len(instances) == 0: |
2214 return _("Invalid plcopen element(s)!!!") |
2216 return _("Invalid plcopen element(s)!!!") |
2215 |
2217 |
2216 exclude = {} |
2218 exclude = {} |
2217 for instance in instances: |
2219 for instance in instances: |
2218 element.addinstance(instance) |
2220 element.addinstance(instance) |
2283 if getattr(instance, "setexecutionOrderId", None) is not None: |
2285 if getattr(instance, "setexecutionOrderId", None) is not None: |
2284 instance.setexecutionOrderId(0) |
2286 instance.setexecutionOrderId(0) |
2285 instance.translate(*diff) |
2287 instance.translate(*diff) |
2286 |
2288 |
2287 return new_id, connections |
2289 return new_id, connections |
2288 |
2290 |
|
2291 # Return the current pou editing instances idx |
|
2292 def GetEditedElementInstancesIds(self, tagname, debug = False): |
|
2293 element = self.GetEditedElement(tagname, debug) |
|
2294 if element is not None: |
|
2295 return element.getinstancesIds() |
|
2296 return [] |
|
2297 |
2289 # Return the current pou editing informations |
2298 # Return the current pou editing informations |
2290 def GetEditedElementInstanceInfos(self, tagname, id = None, exclude = [], debug = False): |
2299 def GetEditedElementInstanceInfos(self, tagname, id, debug = False): |
2291 infos = {} |
|
2292 instance = None |
|
2293 element = self.GetEditedElement(tagname, debug) |
2300 element = self.GetEditedElement(tagname, debug) |
2294 if element is not None: |
2301 if element is not None: |
2295 # if id is defined |
2302 instance = element.getinstance(id) |
2296 if id is not None: |
2303 if instance is not None: |
2297 instance = element.getinstance(id) |
2304 infos = instance.getinfos() |
2298 else: |
2305 if infos["type"] in ["input", "output", "inout"]: |
2299 instance = element.getrandomInstance(exclude) |
2306 var_type = self.GetEditedElementVarValueType(tagname, infos["specific_values"]["name"], debug) |
2300 if instance is not None: |
2307 infos["specific_values"]["value_type"] = var_type |
2301 infos = instance.getinfos() |
2308 return infos |
2302 if infos["type"] in ["input", "output", "inout"]: |
|
2303 var_type = self.GetEditedElementVarValueType(tagname, infos["specific_values"]["name"], debug) |
|
2304 infos["specific_values"]["value_type"] = var_type |
|
2305 return infos |
|
2306 return None |
2309 return None |
2307 |
2310 |
2308 def ClearEditedElementExecutionOrder(self, tagname): |
2311 def ClearEditedElementExecutionOrder(self, tagname): |
2309 element = self.GetEditedElement(tagname) |
2312 element = self.GetEditedElement(tagname) |
2310 if element is not None: |
2313 if element is not None: |
3061 new_instance["Task"] = "" |
3064 new_instance["Task"] = "" |
3062 instances_data.append(new_instance) |
3065 instances_data.append(new_instance) |
3063 return tasks_data, instances_data |
3066 return tasks_data, instances_data |
3064 |
3067 |
3065 def OpenXMLFile(self, filepath): |
3068 def OpenXMLFile(self, filepath): |
3066 #try: |
3069 self.Project, error = LoadProject(filepath) |
3067 self.Project = LoadProject(filepath) |
3070 if self.Project is None: |
3068 #except Exception, e: |
3071 return _("Project file syntax error:\n\n") + error |
3069 # return _("Project file syntax error:\n\n") + str(e) |
|
3070 self.SetFilePath(filepath) |
3072 self.SetFilePath(filepath) |
3071 self.CreateProjectBuffer(True) |
3073 self.CreateProjectBuffer(True) |
3072 self.ProgramChunks = [] |
3074 self.ProgramChunks = [] |
3073 self.ProgramOffset = 0 |
3075 self.ProgramOffset = 0 |
3074 self.NextCompiledProject = self.Copy(self.Project) |
3076 self.NextCompiledProject = self.Copy(self.Project) |
3075 self.CurrentCompiledProject = None |
3077 self.CurrentCompiledProject = None |
3076 self.Buffering = False |
3078 self.Buffering = False |
3077 self.CurrentElementEditing = None |
3079 self.CurrentElementEditing = None |
3078 return None |
3080 return error |
3079 |
3081 |
3080 def SaveXMLFile(self, filepath = None): |
3082 def SaveXMLFile(self, filepath = None): |
3081 if not filepath and self.FilePath == "": |
3083 if not filepath and self.FilePath == "": |
3082 return False |
3084 return False |
3083 else: |
3085 else: |