251 setattr(cls, "getconfiguration", getconfiguration) |
251 setattr(cls, "getconfiguration", getconfiguration) |
252 |
252 |
253 def addconfiguration(self, name): |
253 def addconfiguration(self, name): |
254 for configuration in self.instances.configurations.getconfiguration(): |
254 for configuration in self.instances.configurations.getconfiguration(): |
255 if configuration.getname() == name: |
255 if configuration.getname() == name: |
256 raise ValueError, "\"%s\" configuration already exists !!!"%name |
256 raise ValueError, _("\"%s\" configuration already exists !!!")%name |
257 new_configuration = PLCOpenClasses["configurations_configuration"]() |
257 new_configuration = PLCOpenClasses["configurations_configuration"]() |
258 new_configuration.setname(name) |
258 new_configuration.setname(name) |
259 self.instances.configurations.appendconfiguration(new_configuration) |
259 self.instances.configurations.appendconfiguration(new_configuration) |
260 setattr(cls, "addconfiguration", addconfiguration) |
260 setattr(cls, "addconfiguration", addconfiguration) |
261 |
261 |
282 def addconfigurationResource(self, config_name, name): |
282 def addconfigurationResource(self, config_name, name): |
283 configuration = self.getconfiguration(config_name) |
283 configuration = self.getconfiguration(config_name) |
284 if configuration: |
284 if configuration: |
285 for resource in configuration.getresource(): |
285 for resource in configuration.getresource(): |
286 if resource.getname() == name: |
286 if resource.getname() == name: |
287 raise ValueError, "\"%s\" resource already exists in \"%s\" configuration !!!"%(name, config_name) |
287 raise ValueError, _("\"%s\" resource already exists in \"%s\" configuration !!!")%(name, config_name) |
288 new_resource = PLCOpenClasses["configuration_resource"]() |
288 new_resource = PLCOpenClasses["configuration_resource"]() |
289 new_resource.setname(name) |
289 new_resource.setname(name) |
290 configuration.appendresource(new_resource) |
290 configuration.appendresource(new_resource) |
291 setattr(cls, "addconfigurationResource", addconfigurationResource) |
291 setattr(cls, "addconfigurationResource", addconfigurationResource) |
292 |
292 |
795 setattr(cls, "getpouElement", getpouElement) |
795 setattr(cls, "getpouElement", getpouElement) |
796 |
796 |
797 def appendpouElement(self, name, pou_type, body_type): |
797 def appendpouElement(self, name, pou_type, body_type): |
798 for element in self.pous.getpou(): |
798 for element in self.pous.getpou(): |
799 if element.getname() == name: |
799 if element.getname() == name: |
800 raise ValueError, "\"%s\" POU already exists !!!"%name |
800 raise ValueError, _("\"%s\" POU already exists !!!")%name |
801 new_pou = PLCOpenClasses["pous_pou"]() |
801 new_pou = PLCOpenClasses["pous_pou"]() |
802 new_pou.setname(name) |
802 new_pou.setname(name) |
803 new_pou.setpouType(pou_type) |
803 new_pou.setpouType(pou_type) |
804 new_pou.appendbody(PLCOpenClasses["body"]()) |
804 new_pou.appendbody(PLCOpenClasses["body"]()) |
805 new_pou.setbodyType(body_type) |
805 new_pou.setbodyType(body_type) |
1213 if not isinstance(element["value"], (PLCOpenClasses.get("commonObjects_comment", None), |
1213 if not isinstance(element["value"], (PLCOpenClasses.get("commonObjects_comment", None), |
1214 PLCOpenClasses.get("commonObjects_connector", None), |
1214 PLCOpenClasses.get("commonObjects_connector", None), |
1215 PLCOpenClasses.get("commonObjects_continuation", None))): |
1215 PLCOpenClasses.get("commonObjects_continuation", None))): |
1216 element["value"].setexecutionOrderId(0) |
1216 element["value"].setexecutionOrderId(0) |
1217 else: |
1217 else: |
1218 raise TypeError, "Can only generate execution order on FBD networks!" |
1218 raise TypeError, _("Can only generate execution order on FBD networks!") |
1219 setattr(cls, "resetexecutionOrder", resetexecutionOrder) |
1219 setattr(cls, "resetexecutionOrder", resetexecutionOrder) |
1220 |
1220 |
1221 def compileexecutionOrder(self): |
1221 def compileexecutionOrder(self): |
1222 if self.content["name"] == "FBD": |
1222 if self.content["name"] == "FBD": |
1223 self.resetexecutionOrder() |
1223 self.resetexecutionOrder() |
1248 if isinstance(tmp_instance, PLCOpenClasses.get("commonObjects_connector", None)) and tmp_instance.getname() == name and tmp_instance.getexecutionOrderId() == 0: |
1248 if isinstance(tmp_instance, PLCOpenClasses.get("commonObjects_connector", None)) and tmp_instance.getname() == name and tmp_instance.getexecutionOrderId() == 0: |
1249 connections = tmp_instance.connectionPointIn.getconnections() |
1249 connections = tmp_instance.connectionPointIn.getconnections() |
1250 if connections and len(connections) == 1: |
1250 if connections and len(connections) == 1: |
1251 self.compileelementExecutionOrder(connections[0]) |
1251 self.compileelementExecutionOrder(connections[0]) |
1252 else: |
1252 else: |
1253 raise TypeError, "Can only generate execution order on FBD networks!" |
1253 raise TypeError, _("Can only generate execution order on FBD networks!") |
1254 setattr(cls, "compileelementExecutionOrder", compileelementExecutionOrder) |
1254 setattr(cls, "compileelementExecutionOrder", compileelementExecutionOrder) |
1255 |
1255 |
1256 def setelementExecutionOrder(self, instance, new_executionOrder): |
1256 def setelementExecutionOrder(self, instance, new_executionOrder): |
1257 if self.content["name"] == "FBD": |
1257 if self.content["name"] == "FBD": |
1258 old_executionOrder = instance.getexecutionOrderId() |
1258 old_executionOrder = instance.getexecutionOrderId() |
1264 element["value"].setexecutionOrderId(element_executionOrder - 1) |
1264 element["value"].setexecutionOrderId(element_executionOrder - 1) |
1265 if new_executionOrder <= element_executionOrder <= old_executionOrder: |
1265 if new_executionOrder <= element_executionOrder <= old_executionOrder: |
1266 element["value"].setexecutionOrderId(element_executionOrder + 1) |
1266 element["value"].setexecutionOrderId(element_executionOrder + 1) |
1267 instance.setexecutionOrderId(new_executionOrder) |
1267 instance.setexecutionOrderId(new_executionOrder) |
1268 else: |
1268 else: |
1269 raise TypeError, "Can only generate execution order on FBD networks!" |
1269 raise TypeError, _("Can only generate execution order on FBD networks!") |
1270 setattr(cls, "setelementExecutionOrder", setelementExecutionOrder) |
1270 setattr(cls, "setelementExecutionOrder", setelementExecutionOrder) |
1271 |
1271 |
1272 def appendcontentInstance(self, name, instance): |
1272 def appendcontentInstance(self, name, instance): |
1273 if self.content["name"] in ["LD","FBD","SFC"]: |
1273 if self.content["name"] in ["LD","FBD","SFC"]: |
1274 self.content["value"].appendcontent({"name" : name, "value" : instance}) |
1274 self.content["value"].appendcontent({"name" : name, "value" : instance}) |
1275 else: |
1275 else: |
1276 raise TypeError, "%s body don't have instances!"%self.content["name"] |
1276 raise TypeError, _("%s body don't have instances!")%self.content["name"] |
1277 setattr(cls, "appendcontentInstance", appendcontentInstance) |
1277 setattr(cls, "appendcontentInstance", appendcontentInstance) |
1278 |
1278 |
1279 def getcontentInstances(self): |
1279 def getcontentInstances(self): |
1280 if self.content["name"] in ["LD","FBD","SFC"]: |
1280 if self.content["name"] in ["LD","FBD","SFC"]: |
1281 instances = [] |
1281 instances = [] |
1282 for element in self.content["value"].getcontent(): |
1282 for element in self.content["value"].getcontent(): |
1283 instances.append(element["value"]) |
1283 instances.append(element["value"]) |
1284 return instances |
1284 return instances |
1285 else: |
1285 else: |
1286 raise TypeError, "%s body don't have instances!"%self.content["name"] |
1286 raise TypeError, _("%s body don't have instances!")%self.content["name"] |
1287 setattr(cls, "getcontentInstances", getcontentInstances) |
1287 setattr(cls, "getcontentInstances", getcontentInstances) |
1288 |
1288 |
1289 def getcontentInstance(self, id): |
1289 def getcontentInstance(self, id): |
1290 if self.content["name"] in ["LD","FBD","SFC"]: |
1290 if self.content["name"] in ["LD","FBD","SFC"]: |
1291 for element in self.content["value"].getcontent(): |
1291 for element in self.content["value"].getcontent(): |
1292 if element["value"].getlocalId() == id: |
1292 if element["value"].getlocalId() == id: |
1293 return element["value"] |
1293 return element["value"] |
1294 return None |
1294 return None |
1295 else: |
1295 else: |
1296 raise TypeError, "%s body don't have instances!"%self.content["name"] |
1296 raise TypeError, _("%s body don't have instances!")%self.content["name"] |
1297 setattr(cls, "getcontentInstance", getcontentInstance) |
1297 setattr(cls, "getcontentInstance", getcontentInstance) |
1298 |
1298 |
1299 def getcontentRandomInstance(self, exclude): |
1299 def getcontentRandomInstance(self, exclude): |
1300 if self.content["name"] in ["LD","FBD","SFC"]: |
1300 if self.content["name"] in ["LD","FBD","SFC"]: |
1301 for element in self.content["value"].getcontent(): |
1301 for element in self.content["value"].getcontent(): |
1302 if element["value"].getlocalId() not in exclude: |
1302 if element["value"].getlocalId() not in exclude: |
1303 return element["value"] |
1303 return element["value"] |
1304 return None |
1304 return None |
1305 else: |
1305 else: |
1306 raise TypeError, "%s body don't have instances!"%self.content["name"] |
1306 raise TypeError, _("%s body don't have instances!")%self.content["name"] |
1307 setattr(cls, "getcontentRandomInstance", getcontentRandomInstance) |
1307 setattr(cls, "getcontentRandomInstance", getcontentRandomInstance) |
1308 |
1308 |
1309 def getcontentInstanceByName(self, name): |
1309 def getcontentInstanceByName(self, name): |
1310 if self.content["name"] in ["LD","FBD","SFC"]: |
1310 if self.content["name"] in ["LD","FBD","SFC"]: |
1311 for element in self.content["value"].getcontent(): |
1311 for element in self.content["value"].getcontent(): |
1312 if isinstance(element["value"], PLCOpenClasses.get("fbdObjects_block", None)) and element["value"].getinstanceName() == name: |
1312 if isinstance(element["value"], PLCOpenClasses.get("fbdObjects_block", None)) and element["value"].getinstanceName() == name: |
1313 return element["value"] |
1313 return element["value"] |
1314 else: |
1314 else: |
1315 raise TypeError, "%s body don't have instances!"%self.content["name"] |
1315 raise TypeError, _("%s body don't have instances!")%self.content["name"] |
1316 setattr(cls, "getcontentInstanceByName", getcontentInstanceByName) |
1316 setattr(cls, "getcontentInstanceByName", getcontentInstanceByName) |
1317 |
1317 |
1318 def removecontentInstance(self, id): |
1318 def removecontentInstance(self, id): |
1319 if self.content["name"] in ["LD","FBD","SFC"]: |
1319 if self.content["name"] in ["LD","FBD","SFC"]: |
1320 i = 0 |
1320 i = 0 |
1324 if elements[i]["value"].getlocalId() == id: |
1324 if elements[i]["value"].getlocalId() == id: |
1325 self.content["value"].removecontent(i) |
1325 self.content["value"].removecontent(i) |
1326 removed = True |
1326 removed = True |
1327 i += 1 |
1327 i += 1 |
1328 if not removed: |
1328 if not removed: |
1329 raise ValueError, "Instance with id %d doesn't exists!"%id |
1329 raise ValueError, _("Instance with id %d doesn't exists!")%id |
1330 else: |
1330 else: |
1331 raise TypeError, "%s body don't have instances!"%self.content["name"] |
1331 raise TypeError, "%s body don't have instances!"%self.content["name"] |
1332 setattr(cls, "removecontentInstance", removecontentInstance) |
1332 setattr(cls, "removecontentInstance", removecontentInstance) |
1333 |
1333 |
1334 def settext(self, text): |
1334 def settext(self, text): |
1335 if self.content["name"] in ["IL","ST"]: |
1335 if self.content["name"] in ["IL","ST"]: |
1336 self.content["value"].settext(text) |
1336 self.content["value"].settext(text) |
1337 else: |
1337 else: |
1338 raise TypeError, "%s body don't have text!"%self.content["name"] |
1338 raise TypeError, _("%s body don't have text!")%self.content["name"] |
1339 setattr(cls, "settext", settext) |
1339 setattr(cls, "settext", settext) |
1340 |
1340 |
1341 def gettext(self): |
1341 def gettext(self): |
1342 if self.content["name"] in ["IL","ST"]: |
1342 if self.content["name"] in ["IL","ST"]: |
1343 return self.content["value"].gettext() |
1343 return self.content["value"].gettext() |
1344 else: |
1344 else: |
1345 raise TypeError, "%s body don't have text!"%self.content["name"] |
1345 raise TypeError, _("%s body don't have text!")%self.content["name"] |
1346 setattr(cls, "gettext", gettext) |
1346 setattr(cls, "gettext", gettext) |
1347 |
1347 |
1348 def updateElementName(self, old_name, new_name): |
1348 def updateElementName(self, old_name, new_name): |
1349 if self.content["name"] in ["IL", "ST"]: |
1349 if self.content["name"] in ["IL", "ST"]: |
1350 self.content["value"].updateElementName(old_name, new_name) |
1350 self.content["value"].updateElementName(old_name, new_name) |