184 index = text.find(block_type.upper(), index + len(block_type)) |
184 index = text.find(block_type.upper(), index + len(block_type)) |
185 return False |
185 return False |
186 setattr(cls, "hasblock", hasblock) |
186 setattr(cls, "hasblock", hasblock) |
187 |
187 |
188 def Search(self, criteria, parent_infos): |
188 def Search(self, criteria, parent_infos): |
189 return [(tuple(parent_infos),) + result for result in TestTextElement(self.gettext(), criteria)] |
189 return [(tuple(parent_infos),) + result for result in TestTextElement(self.getanyText(), criteria)] |
190 setattr(cls, "Search", Search) |
190 setattr(cls, "Search", Search) |
191 |
191 |
192 cls = PLCOpenParser.GetElementClass("project") |
192 cls = PLCOpenParser.GetElementClass("project") |
193 if cls: |
193 if cls: |
194 cls.EnumeratedDataTypeValues = {} |
194 cls.EnumeratedDataTypeValues = {} |
471 pou_name = pou.getname() |
471 pou_name = pou.getname() |
472 pou_type = pou.getpouType() |
472 pou_type = pou.getpouType() |
473 block_infos = {"name" : pou_name, "type" : pou_type, "extensible" : False, |
473 block_infos = {"name" : pou_name, "type" : pou_type, "extensible" : False, |
474 "inputs" : [], "outputs" : [], "comment" : pou.getdescription(), |
474 "inputs" : [], "outputs" : [], "comment" : pou.getdescription(), |
475 "generate" : generate_block, "initialise" : initialise_block} |
475 "generate" : generate_block, "initialise" : initialise_block} |
476 if pou.getinterface(): |
476 if pou.interface is not None: |
477 return_type = pou.interface.getreturnType() |
477 return_type = pou.interface.getreturnType() |
478 if return_type: |
478 if return_type is not None: |
479 var_type = return_type.getcontent() |
479 var_type = return_type.getcontent() |
480 var_type_name = var_type.getLocalTag() |
480 var_type_name = var_type.getLocalTag() |
481 if var_type_name == "derived": |
481 if var_type_name == "derived": |
482 block_infos["outputs"].append(("OUT", var_type.getname(), "none")) |
482 block_infos["outputs"].append(("OUT", var_type.getname(), "none")) |
483 elif var_type_name in ["string", "wstring"]: |
483 elif var_type_name in ["string", "wstring"]: |
551 self.AddElementUsingTreeInstance(name, type_content) |
551 self.AddElementUsingTreeInstance(name, type_content) |
552 |
552 |
553 # Analyze each pou |
553 # Analyze each pou |
554 for pou in self.getpous(): |
554 for pou in self.getpous(): |
555 name = pou.getname() |
555 name = pou.getname() |
556 if pou.interface: |
556 if pou.interface is not None: |
557 # Extract variables from every varLists |
557 # Extract variables from every varLists |
558 for varlist_type, varlist in pou.getvars(): |
558 for varlist_type, varlist in pou.getvars(): |
559 for var in varlist.getvariable(): |
559 for var in varlist.getvariable(): |
560 vartype_content = var.gettype().getcontent() |
560 vartype_content = var.gettype().getcontent() |
561 if vartype_content.getLocalTag() == "derived": |
561 if vartype_content.getLocalTag() == "derived": |
867 globalvars.append(PLCOpenParser.CreateElement("varList")) |
867 globalvars.append(PLCOpenParser.CreateElement("varList")) |
868 var = PLCOpenParser.CreateElement("variable", "varListPlain") |
868 var = PLCOpenParser.CreateElement("variable", "varListPlain") |
869 var.setname(name) |
869 var.setname(name) |
870 var_type_obj = PLCOpenParser.CreateElement("dataType") |
870 var_type_obj = PLCOpenParser.CreateElement("dataType") |
871 if var_type in [x for x,y in TypeHierarchy_list if not x.startswith("ANY")]: |
871 if var_type in [x for x,y in TypeHierarchy_list if not x.startswith("ANY")]: |
872 if var_type == "STRING": |
872 var_type_obj.setcontent(PLCOpenParser.CreateElement( |
873 var_type_obj.setcontent(PLCOpenParser.CreateElement("string", "elementaryTypes")) |
873 var_type.lower() if var_type in ["STRING", "WSTRING"] |
874 elif var_type == "WSTRING": |
874 else vartype, "dataType")) |
875 var_type_obj.setcontent(PLCOpenParser.CreateElement("wstring", "elementaryTypes")) |
|
876 else: |
|
877 var_type_obj.setcontent(PLCOpenParser.CreateElement(var_type)) |
|
878 else: |
875 else: |
879 derived_type = PLCOpenParser.CreateElement("derived", "derivedTypes") |
876 derived_type = PLCOpenParser.CreateElement("derived", "dataType") |
880 derived_type.setname(var_type) |
877 derived_type.setname(var_type) |
881 var_type_obj.setcontent(derived_type) |
878 var_type_obj.setcontent(derived_type) |
882 var.settype(var_type_obj) |
879 var.settype(var_type_obj) |
883 if location != "": |
880 if location != "": |
884 var.setaddress(location) |
881 var.setaddress(location) |
885 if description != "": |
882 if description != "": |
886 ft = PLCOpenParser.CreateElementClass("formattedText") |
883 ft = PLCOpenParser.CreateElementClass("formattedText") |
887 ft.settext(description) |
884 ft.setanyText(description) |
888 var.setdocumentation(ft) |
885 var.setdocumentation(ft) |
889 globalvars[-1].appendvariable(var) |
886 globalvars[-1].appendvariable(var) |
890 setattr(cls, "addglobalVar", addglobalVar) |
887 setattr(cls, "addglobalVar", addglobalVar) |
891 |
888 |
892 def updateElementName(self, old_name, new_name): |
889 def updateElementName(self, old_name, new_name): |
1195 content_name = content_name.upper() |
1192 content_name = content_name.upper() |
1196 search_result.extend(_Search([("base", content_name)], criteria, parent_infos)) |
1193 search_result.extend(_Search([("base", content_name)], criteria, parent_infos)) |
1197 return search_result |
1194 return search_result |
1198 setattr(cls, "Search", Search) |
1195 setattr(cls, "Search", Search) |
1199 |
1196 |
1200 cls = PLCOpenParser.GetElementClass("array", "derivedTypes") |
1197 cls = PLCOpenParser.GetElementClass("array", "dataType") |
1201 if cls: |
1198 if cls: |
1202 setattr(cls, "updateElementName", _updateBaseTypeElementName) |
1199 setattr(cls, "updateElementName", _updateBaseTypeElementName) |
1203 |
1200 |
1204 def Search(self, criteria, parent_infos=[]): |
1201 def Search(self, criteria, parent_infos=[]): |
1205 search_result = self.baseType.Search(criteria, parent_infos) |
1202 search_result = self.baseType.Search(criteria, parent_infos) |
1215 search_result.extend(_Search([("lower", self.range.getlower()), |
1212 search_result.extend(_Search([("lower", self.range.getlower()), |
1216 ("upper", self.range.getupper())], |
1213 ("upper", self.range.getupper())], |
1217 criteria, parent_infos)) |
1214 criteria, parent_infos)) |
1218 return search_result |
1215 return search_result |
1219 |
1216 |
1220 cls = PLCOpenParser.GetElementClass("subrangeSigned", "derivedTypes") |
1217 cls = PLCOpenParser.GetElementClass("subrangeSigned", "dataType") |
1221 if cls: |
1218 if cls: |
1222 setattr(cls, "updateElementName", _updateBaseTypeElementName) |
1219 setattr(cls, "updateElementName", _updateBaseTypeElementName) |
1223 setattr(cls, "Search", _SearchInSubrange) |
1220 setattr(cls, "Search", _SearchInSubrange) |
1224 |
1221 |
1225 cls = PLCOpenParser.GetElementClass("subrangeUnsigned", "derivedTypes") |
1222 cls = PLCOpenParser.GetElementClass("subrangeUnsigned", "dataType") |
1226 if cls: |
1223 if cls: |
1227 setattr(cls, "updateElementName", _updateBaseTypeElementName) |
1224 setattr(cls, "updateElementName", _updateBaseTypeElementName) |
1228 setattr(cls, "Search", _SearchInSubrange) |
1225 setattr(cls, "Search", _SearchInSubrange) |
1229 |
1226 |
1230 cls = PLCOpenParser.GetElementClass("enum", "derivedTypes") |
1227 cls = PLCOpenParser.GetElementClass("enum", "dataType") |
1231 if cls: |
1228 if cls: |
1232 |
1229 |
1233 def updateElementName(self, old_name, new_name): |
1230 def updateElementName(self, old_name, new_name): |
1234 pass |
1231 pass |
1235 setattr(cls, "updateElementName", updateElementName) |
1232 setattr(cls, "updateElementName", updateElementName) |
1248 def setdescription(self, description): |
1245 def setdescription(self, description): |
1249 doc = self.getdocumentation() |
1246 doc = self.getdocumentation() |
1250 if doc is None: |
1247 if doc is None: |
1251 doc = PLCOpenParser.CreateElement("formattedText") |
1248 doc = PLCOpenParser.CreateElement("formattedText") |
1252 self.setdocumentation(doc) |
1249 self.setdocumentation(doc) |
1253 doc.settext(description) |
1250 doc.setanyText(description) |
1254 setattr(cls, "setdescription", setdescription) |
1251 setattr(cls, "setdescription", setdescription) |
1255 |
1252 |
1256 def getdescription(self): |
1253 def getdescription(self): |
1257 doc = self.getdocumentation() |
1254 doc = self.getdocumentation() |
1258 if doc is not None: |
1255 if doc is not None: |
1259 return doc.gettext() |
1256 return doc.getanyText() |
1260 return "" |
1257 return "" |
1261 setattr(cls, "getdescription", getdescription) |
1258 setattr(cls, "getdescription", getdescription) |
1262 |
1259 |
1263 def setbodyType(self, body_type): |
1260 def setbodyType(self, body_type): |
1264 if len(self.body) > 0: |
1261 if len(self.body) > 0: |
1346 |
1343 |
1347 def setvars(self, vars): |
1344 def setvars(self, vars): |
1348 if self.interface is None: |
1345 if self.interface is None: |
1349 self.interface = PLCOpenParser.CreateElement("interface", "pou") |
1346 self.interface = PLCOpenParser.CreateElement("interface", "pou") |
1350 self.interface.setcontent(vars) |
1347 self.interface.setcontent(vars) |
|
1348 print self.interface.tostring() |
1351 setattr(cls, "setvars", setvars) |
1349 setattr(cls, "setvars", setvars) |
1352 |
1350 |
1353 def addpouLocalVar(self, var_type, name, location="", description=""): |
1351 def addpouLocalVar(self, var_type, name, location="", description=""): |
1354 self.addpouVar(var_type, name, location=location, description=description) |
1352 self.addpouVar(var_type, name, location=location, description=description) |
1355 setattr(cls, "addpouLocalVar", addpouLocalVar) |
1353 setattr(cls, "addpouLocalVar", addpouLocalVar) |
1371 self.appendcontent(PLCOpenParser.CreateElementClass(var_class, "interface")) |
1369 self.appendcontent(PLCOpenParser.CreateElementClass(var_class, "interface")) |
1372 var = PLCOpenParser.CreateElementClass("variable", "varListPlain") |
1370 var = PLCOpenParser.CreateElementClass("variable", "varListPlain") |
1373 var.setname(name) |
1371 var.setname(name) |
1374 var_type_obj = PLCOpenParser.CreateElement("dataType") |
1372 var_type_obj = PLCOpenParser.CreateElement("dataType") |
1375 if var_type in [x for x,y in TypeHierarchy_list if not x.startswith("ANY")]: |
1373 if var_type in [x for x,y in TypeHierarchy_list if not x.startswith("ANY")]: |
1376 if var_type == "STRING": |
1374 var_type_obj.setcontent(PLCOpenParser.CreateElement( |
1377 var_type_obj.setcontent(PLCOpenParser.CreateElement("string", "elementaryTypes")) |
1375 var_type.lower() if var_type in ["STRING", "WSTRING"] |
1378 elif var_type == "WSTRING": |
1376 else var_type, "dataType")) |
1379 var_type_obj.setcontent(PLCOpenParser.CreateElement("wstring", "elementaryTypes")) |
|
1380 else: |
|
1381 var_type_obj.setcontent(PLCOpenParser.CreateElement(var_type)) |
|
1382 else: |
1377 else: |
1383 derived_type = PLCOpenParser.CreateElement("derived", "derivedTypes") |
1378 derived_type = PLCOpenParser.CreateElement("derived", "dataType") |
1384 derived_type.setname(var_type) |
1379 derived_type.setname(var_type) |
1385 var_type_obj.setcontent(derived_type) |
1380 var_type_obj.setcontent(derived_type) |
1386 var.settype(var_type_obj) |
1381 var.settype(var_type_obj) |
1387 if location != "": |
1382 if location != "": |
1388 var.setaddress(location) |
1383 var.setaddress(location) |
1389 if description != "": |
1384 if description != "": |
1390 ft = PLCOpenParser.GetElementClass("formattedText")() |
1385 ft = PLCOpenParser.GetElementClass("formattedText")() |
1391 ft.settext(description) |
1386 ft.setanyText(description) |
1392 var.setdocumentation(ft) |
1387 var.setdocumentation(ft) |
1393 |
1388 |
1394 content[-1]["value"].appendvariable(var) |
1389 content[-1]["value"].appendvariable(var) |
1395 setattr(cls, "addpouVar", addpouVar) |
1390 setattr(cls, "addpouVar", addpouVar) |
1396 |
1391 |
1451 self.transitions.settransition([]) |
1446 self.transitions.settransition([]) |
1452 transition = PLCOpenParser.CreateElement("transition", "transitions") |
1447 transition = PLCOpenParser.CreateElement("transition", "transitions") |
1453 transition.setname(name) |
1448 transition.setname(name) |
1454 transition.setbodyType(body_type) |
1449 transition.setbodyType(body_type) |
1455 if body_type == "ST": |
1450 if body_type == "ST": |
1456 transition.settext(":= ;") |
1451 transition.setanyText(":= ;") |
1457 elif body_type == "IL": |
1452 elif body_type == "IL": |
1458 transition.settext("\tST\t%s"%name) |
1453 transition.setanyText("\tST\t%s"%name) |
1459 self.transitions.appendtransition(transition) |
1454 self.transitions.appendtransition(transition) |
1460 setattr(cls, "addtransition", addtransition) |
1455 setattr(cls, "addtransition", addtransition) |
1461 |
1456 |
1462 def gettransition(self, name): |
1457 def gettransition(self, name): |
1463 if self.transitions: |
1458 if self.transitions: |
1830 raise TypeError, _("%s body don't have instances!")%self.content["name"] |
1825 raise TypeError, _("%s body don't have instances!")%self.content["name"] |
1831 setattr(cls, "getcontentInstance", getcontentInstance) |
1826 setattr(cls, "getcontentInstance", getcontentInstance) |
1832 |
1827 |
1833 def getcontentRandomInstance(self, exclude): |
1828 def getcontentRandomInstance(self, exclude): |
1834 if self.content.getLocalTag() in ["LD","FBD","SFC"]: |
1829 if self.content.getLocalTag() in ["LD","FBD","SFC"]: |
1835 instance = self.content.xpath("*[regexp:test(@localId,'(%s)')]" % "|".join(map(str, exclude))) |
1830 instance = self.content.xpath("*%s[position()=1]" % |
|
1831 ("[not(%s)]" % " or ".join( |
|
1832 map(lambda x: "@localId=%d" % x, exclude)) |
|
1833 if len(exclude) > 0 else "")) |
1836 if len(instance) > 0: |
1834 if len(instance) > 0: |
1837 return instance[0] |
1835 return instance[0] |
1838 return None |
1836 return None |
1839 else: |
1837 else: |
1840 raise TypeError, _("%s body don't have instances!")%self.content["name"] |
1838 raise TypeError, _("%s body don't have instances!")%self.content["name"] |
1861 raise TypeError, "%s body don't have instances!"%self.content["name"] |
1859 raise TypeError, "%s body don't have instances!"%self.content["name"] |
1862 setattr(cls, "removecontentInstance", removecontentInstance) |
1860 setattr(cls, "removecontentInstance", removecontentInstance) |
1863 |
1861 |
1864 def settext(self, text): |
1862 def settext(self, text): |
1865 if self.content.getLocalTag() in ["IL","ST"]: |
1863 if self.content.getLocalTag() in ["IL","ST"]: |
1866 self.content.settext(text) |
1864 self.content.setanyText(text) |
1867 else: |
1865 else: |
1868 raise TypeError, _("%s body don't have text!")%self.content["name"] |
1866 raise TypeError, _("%s body don't have text!")%self.content["name"] |
1869 setattr(cls, "settext", settext) |
1867 setattr(cls, "settext", settext) |
1870 |
1868 |
1871 def gettext(self): |
1869 def gettext(self): |
1872 if self.content.getLocalTag() in ["IL","ST"]: |
1870 if self.content.getLocalTag() in ["IL","ST"]: |
1873 return self.content.gettext() |
1871 return self.content.getanyText() |
1874 else: |
1872 else: |
1875 raise TypeError, _("%s body don't have text!")%self.content["name"] |
1873 raise TypeError, _("%s body don't have text!")%self.content["name"] |
1876 setattr(cls, "gettext", gettext) |
1874 setattr(cls, "gettext", gettext) |
1877 |
1875 |
1878 def hasblock(self, block_type): |
1876 def hasblock(self, block_type): |
2101 def _getvariableinfosFunction(type, input, output): |
2099 def _getvariableinfosFunction(type, input, output): |
2102 def getvariableinfos(self): |
2100 def getvariableinfos(self): |
2103 infos = _getelementinfos(self) |
2101 infos = _getelementinfos(self) |
2104 infos["type"] = type |
2102 infos["type"] = type |
2105 specific_values = infos["specific_values"] |
2103 specific_values = infos["specific_values"] |
2106 specific_values["name"] = self.getexpression() |
2104 specific_values["name"] = self.getexpression().text |
2107 _getexecutionOrder(self, specific_values) |
2105 _getexecutionOrder(self, specific_values) |
2108 if input and output: |
2106 if input and output: |
2109 infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True, "input")) |
2107 infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True, "input")) |
2110 infos["outputs"].append(_getconnectioninfos(self, self.connectionPointOut, False, "output")) |
2108 infos["outputs"].append(_getconnectioninfos(self, self.connectionPointOut, False, "output")) |
2111 elif input: |
2109 elif input: |
2114 infos["outputs"].append(_getconnectioninfos(self, self.connectionPointOut, False, "default")) |
2112 infos["outputs"].append(_getconnectioninfos(self, self.connectionPointOut, False, "default")) |
2115 return infos |
2113 return infos |
2116 return getvariableinfos |
2114 return getvariableinfos |
2117 |
2115 |
2118 def _getconnectorinfosFunction(type): |
2116 def _getconnectorinfosFunction(type): |
2119 def getvariableinfos(self): |
2117 def getconnectorinfos(self): |
2120 infos = _getelementinfos(self) |
2118 infos = _getelementinfos(self) |
2121 infos["type"] = type |
2119 infos["type"] = type |
2122 infos["specific_values"]["name"] = self.getname() |
2120 infos["specific_values"]["name"] = self.getname() |
2123 if type == "connector": |
2121 if type == "connector": |
2124 infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True)) |
2122 infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True)) |
2125 elif type == "continuation": |
2123 elif type == "continuation": |
2126 infos["outputs"].append(_getconnectioninfos(self, self.connectionPointOut)) |
2124 infos["outputs"].append(_getconnectioninfos(self, self.connectionPointOut)) |
2127 return infos |
2125 return infos |
2128 return getvariableinfos |
2126 return getconnectorinfos |
2129 |
2127 |
2130 def _getpowerrailinfosFunction(type): |
2128 def _getpowerrailinfosFunction(type): |
2131 def getpowerrailinfos(self): |
2129 def getpowerrailinfos(self): |
2132 infos = _getelementinfos(self) |
2130 infos = _getelementinfos(self) |
2133 infos["type"] = type |
2131 infos["type"] = type |
2188 infos["specific_values"]["content"] = self.getcontentText() |
2186 infos["specific_values"]["content"] = self.getcontentText() |
2189 return infos |
2187 return infos |
2190 setattr(cls, "getinfos", getinfos) |
2188 setattr(cls, "getinfos", getinfos) |
2191 |
2189 |
2192 def setcontentText(self, text): |
2190 def setcontentText(self, text): |
2193 self.content.settext(text) |
2191 self.content.setanyText(text) |
2194 setattr(cls, "setcontentText", setcontentText) |
2192 setattr(cls, "setcontentText", setcontentText) |
2195 |
2193 |
2196 def getcontentText(self): |
2194 def getcontentText(self): |
2197 return self.content.gettext() |
2195 return self.content.getanyText() |
2198 setattr(cls, "getcontentText", getcontentText) |
2196 setattr(cls, "getcontentText", getcontentText) |
2199 |
2197 |
2200 def updateElementName(self, old_name, new_name): |
2198 def updateElementName(self, old_name, new_name): |
2201 self.content.updateElementName(old_name, new_name) |
2199 self.content.updateElementName(old_name, new_name) |
2202 setattr(cls, "updateElementName", updateElementName) |
2200 setattr(cls, "updateElementName", updateElementName) |
2376 condition = PLCOpenParser.CreateElement("reference", "condition") |
2374 condition = PLCOpenParser.CreateElement("reference", "condition") |
2377 condition.setname(value) |
2375 condition.setname(value) |
2378 elif condition_type == "inline": |
2376 elif condition_type == "inline": |
2379 condition = PLCOpenParser.CreateElement("inline", "condition") |
2377 condition = PLCOpenParser.CreateElement("inline", "condition") |
2380 condition.setcontent(PLCOpenParser.GetElementClass("ST", "inline")) |
2378 condition.setcontent(PLCOpenParser.GetElementClass("ST", "inline")) |
2381 condition.settext(value) |
2379 condition.setanyText(value) |
2382 elif condition_type == "connection": |
2380 elif condition_type == "connection": |
2383 condition = PLCOpenParser.CreateElementClass("connectionPointIn") |
2381 condition = PLCOpenParser.CreateElementClass("connectionPointIn") |
2384 self.condition.setcontent(condition) |
2382 self.condition.setcontent(condition) |
2385 setattr(cls, "setconditionContent", setconditionContent) |
2383 setattr(cls, "setconditionContent", setconditionContent) |
2386 |
2384 |
2389 content = self.condition.getcontent() |
2387 content = self.condition.getcontent() |
2390 values = {"type" : content.getLocalTag()} |
2388 values = {"type" : content.getLocalTag()} |
2391 if values["type"] == "reference": |
2389 if values["type"] == "reference": |
2392 values["value"] = content.getname() |
2390 values["value"] = content.getname() |
2393 elif values["type"] == "inline": |
2391 elif values["type"] == "inline": |
2394 values["value"] = content.gettext() |
2392 values["value"] = content.getanyText() |
2395 elif values["type"] == "connectionPointIn": |
2393 elif values["type"] == "connectionPointIn": |
2396 values["type"] = "connection" |
2394 values["type"] = "connection" |
2397 values["value"] = content |
2395 values["value"] = content |
2398 return values |
2396 return values |
2399 return "" |
2397 return "" |
2477 elif content_name == "inline": |
2475 elif content_name == "inline": |
2478 search_result.extend(content.Search(criteria, parent_infos + ["inline"])) |
2476 search_result.extend(content.Search(criteria, parent_infos + ["inline"])) |
2479 return search_result |
2477 return search_result |
2480 setattr(cls, "Search", Search) |
2478 setattr(cls, "Search", Search) |
2481 |
2479 |
2482 cls = _initElementClass("selectionDivergence", "sfcObjects_selectionDivergence", "single") |
2480 cls = _initElementClass("selectionDivergence", "sfcObjects", "single") |
2483 if cls: |
2481 if cls: |
2484 setattr(cls, "getinfos", _getdivergenceinfosFunction(True, False)) |
2482 setattr(cls, "getinfos", _getdivergenceinfosFunction(True, False)) |
2485 |
2483 |
2486 cls = _initElementClass("selectionConvergence", "sfcObjects_selectionConvergence", "multiple") |
2484 cls = _initElementClass("selectionConvergence", "sfcObjects", "multiple") |
2487 if cls: |
2485 if cls: |
2488 setattr(cls, "getinfos", _getdivergenceinfosFunction(False, False)) |
2486 setattr(cls, "getinfos", _getdivergenceinfosFunction(False, False)) |
2489 |
2487 |
2490 cls = _initElementClass("simultaneousDivergence", "sfcObjects_simultaneousDivergence", "single") |
2488 cls = _initElementClass("simultaneousDivergence", "sfcObjects", "single") |
2491 if cls: |
2489 if cls: |
2492 setattr(cls, "getinfos", _getdivergenceinfosFunction(True, True)) |
2490 setattr(cls, "getinfos", _getdivergenceinfosFunction(True, True)) |
2493 |
2491 |
2494 cls = _initElementClass("simultaneousConvergence", "sfcObjects_simultaneousConvergence", "multiple") |
2492 cls = _initElementClass("simultaneousConvergence", "sfcObjects", "multiple") |
2495 if cls: |
2493 if cls: |
2496 setattr(cls, "getinfos", _getdivergenceinfosFunction(False, True)) |
2494 setattr(cls, "getinfos", _getdivergenceinfosFunction(False, True)) |
2497 |
2495 |
2498 cls = _initElementClass("jumpStep", "sfcObjects_jumpStep", "single") |
2496 cls = _initElementClass("jumpStep", "sfcObjects", "single") |
2499 if cls: |
2497 if cls: |
2500 def getinfos(self): |
2498 def getinfos(self): |
2501 infos = _getelementinfos(self) |
2499 infos = _getelementinfos(self) |
2502 infos["type"] = "jump" |
2500 infos["type"] = "jump" |
2503 infos["specific_values"]["target"] = self.gettargetName() |
2501 infos["specific_values"]["target"] = self.gettargetName() |
2534 setattr(cls, "getreferenceName", getreferenceName) |
2532 setattr(cls, "getreferenceName", getreferenceName) |
2535 |
2533 |
2536 def setinlineContent(self, content): |
2534 def setinlineContent(self, content): |
2537 if self.inline: |
2535 if self.inline: |
2538 self.inline.setcontent(PLCOpenParser.CreateElementClass("ST", "action")) |
2536 self.inline.setcontent(PLCOpenParser.CreateElementClass("ST", "action")) |
2539 self.inline.settext(content) |
2537 self.inline.setanyText(content) |
2540 setattr(cls, "setinlineContent", setinlineContent) |
2538 setattr(cls, "setinlineContent", setinlineContent) |
2541 |
2539 |
2542 def getinlineContent(self): |
2540 def getinlineContent(self): |
2543 if self.inline: |
2541 if self.inline: |
2544 return self.inline.gettext() |
2542 return self.inline.getanyText() |
2545 return None |
2543 return None |
2546 setattr(cls, "getinlineContent", getinlineContent) |
2544 setattr(cls, "getinlineContent", getinlineContent) |
2547 |
2545 |
2548 def updateElementName(self, old_name, new_name): |
2546 def updateElementName(self, old_name, new_name): |
2549 if self.reference and self.reference.getname() == old_name: |
2547 if self.reference and self.reference.getname() == old_name: |
2569 ("duration", self.getduration()), |
2567 ("duration", self.getduration()), |
2570 ("indicator", self.getindicator())], |
2568 ("indicator", self.getindicator())], |
2571 criteria, parent_infos) |
2569 criteria, parent_infos) |
2572 setattr(cls, "Search", Search) |
2570 setattr(cls, "Search", Search) |
2573 |
2571 |
2574 cls = _initElementClass("actionBlock", "commonObjects_actionBlock", "single") |
2572 cls = _initElementClass("actionBlock", "commonObjects", "single") |
2575 if cls: |
2573 if cls: |
2576 def compatibility(self, tree): |
2574 def compatibility(self, tree): |
2577 for child in tree.childNodes[:]: |
2575 for child in tree.childNodes[:]: |
2578 if child.nodeName == "connectionPointOut": |
2576 if child.nodeName == "connectionPointOut": |
2579 tree.childNodes.remove(child) |
2577 tree.childNodes.remove(child) |
2647 setattr(cls, "Search", Search) |
2645 setattr(cls, "Search", Search) |
2648 |
2646 |
2649 def _SearchInIOVariable(self, criteria, parent_infos=[]): |
2647 def _SearchInIOVariable(self, criteria, parent_infos=[]): |
2650 return _Search([("expression", self.getexpression())], criteria, parent_infos + ["io_variable", self.getlocalId()]) |
2648 return _Search([("expression", self.getexpression())], criteria, parent_infos + ["io_variable", self.getlocalId()]) |
2651 |
2649 |
2652 cls = _initElementClass("inVariable", "fbdObjects_inVariable") |
2650 cls = _initElementClass("inVariable", "fbdObjects") |
2653 if cls: |
2651 if cls: |
2654 setattr(cls, "getinfos", _getvariableinfosFunction("input", False, True)) |
2652 setattr(cls, "getinfos", _getvariableinfosFunction("input", False, True)) |
2655 |
2653 |
2656 def updateElementName(self, old_name, new_name): |
2654 def updateElementName(self, old_name, new_name): |
2657 if self.expression == old_name: |
2655 if self.expression == old_name: |
2662 self.expression = update_address(self.expression, address_model, new_leading) |
2660 self.expression = update_address(self.expression, address_model, new_leading) |
2663 setattr(cls, "updateElementAddress", updateElementAddress) |
2661 setattr(cls, "updateElementAddress", updateElementAddress) |
2664 |
2662 |
2665 setattr(cls, "Search", _SearchInIOVariable) |
2663 setattr(cls, "Search", _SearchInIOVariable) |
2666 |
2664 |
2667 cls = _initElementClass("outVariable", "fbdObjects_outVariable", "single") |
2665 cls = _initElementClass("outVariable", "fbdObjects", "single") |
2668 if cls: |
2666 if cls: |
2669 setattr(cls, "getinfos", _getvariableinfosFunction("output", True, False)) |
2667 setattr(cls, "getinfos", _getvariableinfosFunction("output", True, False)) |
2670 |
2668 |
2671 def updateElementName(self, old_name, new_name): |
2669 def updateElementName(self, old_name, new_name): |
2672 if self.expression == old_name: |
2670 if self.expression == old_name: |
2677 self.expression = update_address(self.expression, address_model, new_leading) |
2675 self.expression = update_address(self.expression, address_model, new_leading) |
2678 setattr(cls, "updateElementAddress", updateElementAddress) |
2676 setattr(cls, "updateElementAddress", updateElementAddress) |
2679 |
2677 |
2680 setattr(cls, "Search", _SearchInIOVariable) |
2678 setattr(cls, "Search", _SearchInIOVariable) |
2681 |
2679 |
2682 cls = _initElementClass("inOutVariable", "fbdObjects_inOutVariable", "single") |
2680 cls = _initElementClass("inOutVariable", "fbdObjects", "single") |
2683 if cls: |
2681 if cls: |
2684 setattr(cls, "getinfos", _getvariableinfosFunction("inout", True, True)) |
2682 setattr(cls, "getinfos", _getvariableinfosFunction("inout", True, True)) |
2685 |
2683 |
2686 def updateElementName(self, old_name, new_name): |
2684 def updateElementName(self, old_name, new_name): |
2687 if self.expression == old_name: |
2685 if self.expression == old_name: |
2696 |
2694 |
2697 |
2695 |
2698 def _SearchInConnector(self, criteria, parent_infos=[]): |
2696 def _SearchInConnector(self, criteria, parent_infos=[]): |
2699 return _Search([("name", self.getname())], criteria, parent_infos + ["connector", self.getlocalId()]) |
2697 return _Search([("name", self.getname())], criteria, parent_infos + ["connector", self.getlocalId()]) |
2700 |
2698 |
2701 cls = _initElementClass("continuation", "commonObjects_continuation") |
2699 cls = _initElementClass("continuation", "commonObjects") |
2702 if cls: |
2700 if cls: |
2703 setattr(cls, "getinfos", _getconnectorinfosFunction("continuation")) |
2701 setattr(cls, "getinfos", _getconnectorinfosFunction("continuation")) |
2704 setattr(cls, "Search", _SearchInConnector) |
2702 setattr(cls, "Search", _SearchInConnector) |
2705 |
2703 |
2706 def updateElementName(self, old_name, new_name): |
2704 def updateElementName(self, old_name, new_name): |
2707 if self.name == old_name: |
2705 if self.name == old_name: |
2708 self.name = new_name |
2706 self.name = new_name |
2709 setattr(cls, "updateElementName", updateElementName) |
2707 setattr(cls, "updateElementName", updateElementName) |
2710 |
2708 |
2711 cls = _initElementClass("connector", "commonObjects_connector", "single") |
2709 cls = _initElementClass("connector", "commonObjects", "single") |
2712 if cls: |
2710 if cls: |
2713 setattr(cls, "getinfos", _getconnectorinfosFunction("connector")) |
2711 setattr(cls, "getinfos", _getconnectorinfosFunction("connector")) |
2714 setattr(cls, "Search", _SearchInConnector) |
2712 setattr(cls, "Search", _SearchInConnector) |
2715 |
2713 |
2716 def updateElementName(self, old_name, new_name): |
2714 def updateElementName(self, old_name, new_name): |
2744 self.relPosition.setx(x) |
2742 self.relPosition.setx(x) |
2745 self.relPosition.sety(y) |
2743 self.relPosition.sety(y) |
2746 setattr(cls, "setrelPositionXY", setrelPositionXY) |
2744 setattr(cls, "setrelPositionXY", setrelPositionXY) |
2747 |
2745 |
2748 def getrelPositionXY(self): |
2746 def getrelPositionXY(self): |
2749 if self.relPosition: |
2747 if self.relPosition is not None: |
2750 return self.relPosition.getx(), self.relPosition.gety() |
2748 return self.relPosition.getx(), self.relPosition.gety() |
2751 else: |
2749 return self.relPosition |
2752 return self.relPosition |
|
2753 setattr(cls, "getrelPositionXY", getrelPositionXY) |
2750 setattr(cls, "getrelPositionXY", getrelPositionXY) |
2754 |
2751 |
2755 def addconnection(self): |
2752 def addconnection(self): |
2756 self.appendcontent(PLCOpenParser.CreateElement("connection")) |
2753 self.appendcontent(PLCOpenParser.CreateElement("connection")) |
2757 setattr(cls, "addconnection", addconnection) |
2754 setattr(cls, "addconnection", addconnection) |
2764 def removeconnections(self): |
2761 def removeconnections(self): |
2765 self.content = None |
2762 self.content = None |
2766 setattr(cls, "removeconnections", removeconnections) |
2763 setattr(cls, "removeconnections", removeconnections) |
2767 |
2764 |
2768 def getconnections(self): |
2765 def getconnections(self): |
2769 return self.content |
2766 return self.xpath("ppx:connection", namespaces=PLCOpenParser.NSMAP) |
2770 setattr(cls, "getconnections", getconnections) |
2767 setattr(cls, "getconnections", getconnections) |
2771 |
2768 |
2772 def setconnectionId(self, idx, local_id): |
2769 def setconnectionId(self, idx, local_id): |
2773 if len(self.content) > idx: |
2770 if len(self.content) > idx: |
2774 self.content[idx].setrefLocalId(local_id) |
2771 self.content[idx].setrefLocalId(local_id) |
2809 self.relPosition.setx(x) |
2806 self.relPosition.setx(x) |
2810 self.relPosition.sety(y) |
2807 self.relPosition.sety(y) |
2811 setattr(cls, "setrelPositionXY", setrelPositionXY) |
2808 setattr(cls, "setrelPositionXY", setrelPositionXY) |
2812 |
2809 |
2813 def getrelPositionXY(self): |
2810 def getrelPositionXY(self): |
2814 if self.relPosition: |
2811 if self.relPosition is not None: |
2815 return self.relPosition.getx(), self.relPosition.gety() |
2812 return self.relPosition.getx(), self.relPosition.gety() |
2816 return self.relPosition |
2813 return self.relPosition |
2817 setattr(cls, "getrelPositionXY", getrelPositionXY) |
2814 setattr(cls, "getrelPositionXY", getrelPositionXY) |
2818 |
2815 |
2819 cls = PLCOpenParser.GetElementClass("value") |
2816 cls = PLCOpenParser.GetElementClass("value") |
2820 if cls: |
2817 if cls: |
2821 def setvalue(self, value): |
2818 def setvalue(self, value): |
2822 value = value.strip() |
2819 value = value.strip() |
2823 if value.startswith("[") and value.endswith("]"): |
2820 if value.startswith("[") and value.endswith("]"): |
2824 self.content = PLCOpenParser.CreateElement("arrayValue", "value") |
2821 content = PLCOpenParser.CreateElement("arrayValue", "value") |
2825 elif value.startswith("(") and value.endswith(")"): |
2822 elif value.startswith("(") and value.endswith(")"): |
2826 self.content = PLCOpenParser.CreateElement("structValue", "value") |
2823 content = PLCOpenParser.CreateElement("structValue", "value") |
2827 else: |
2824 else: |
2828 self.content = PLCOpenParser.CreateElement("simpleValue", "value") |
2825 content = PLCOpenParser.CreateElement("simpleValue", "value") |
2829 self.content.setvalue(value) |
2826 content.setvalue(value) |
|
2827 self.setcontent(content) |
2830 setattr(cls, "setvalue", setvalue) |
2828 setattr(cls, "setvalue", setvalue) |
2831 |
2829 |
2832 def getvalue(self): |
2830 def getvalue(self): |
2833 return self.content.getvalue() |
2831 return self.content.getvalue() |
2834 setattr(cls, "getvalue", getvalue) |
2832 setattr(cls, "getvalue", getvalue) |