1167 self.RestartTimer() |
1178 self.RestartTimer() |
1168 |
1179 |
1169 def AddBus(self, iec_channel, name, icon=None): |
1180 def AddBus(self, iec_channel, name, icon=None): |
1170 for child in self.PluginRoot.IterChilds(): |
1181 for child in self.PluginRoot.IterChilds(): |
1171 if child.BaseParams.getName() == name: |
1182 if child.BaseParams.getName() == name: |
1172 return "Error: A bus named %s already exists" % name |
1183 return "Error: A bus named %s already exists\n" % name |
1173 elif child.BaseParams.getIEC_Channel() == iec_channel: |
1184 elif child.BaseParams.getIEC_Channel() == iec_channel: |
1174 return "Error: A bus with IEC_channel %d already exists" % iec_channel |
1185 return "Error: A bus with IEC_channel %d already exists\n" % iec_channel |
1175 bus = self.PluginRoot.PlugAddChild(name, "LPCBus", iec_channel) |
1186 bus = self.PluginRoot.PlugAddChild(name, "LPCBus", iec_channel) |
1176 if bus is None: |
1187 if bus is None: |
1177 return "Error: Unable to create bus" |
1188 return "Error: Unable to create bus\n" |
1178 bus.SetIcon(icon) |
1189 bus.SetIcon(icon) |
1179 self.RestartTimer() |
1190 self.RestartTimer() |
1180 |
1191 |
1181 def RenameBus(self, iec_channel, name): |
1192 def RenameBus(self, iec_channel, name): |
1182 bus = self.PluginRoot.GetChildByIECLocation((iec_channel,)) |
1193 bus = self.PluginRoot.GetChildByIECLocation((iec_channel,)) |
1183 if bus is None: |
1194 if bus is None: |
1184 return "Error: No bus found" |
1195 return "Error: No bus found\n" |
1185 for child in self.PluginRoot.IterChilds(): |
1196 for child in self.PluginRoot.IterChilds(): |
1186 if child != bus and child.BaseParams.getName() == name: |
1197 if child != bus and child.BaseParams.getName() == name: |
1187 return "Error: A bus named %s already exists" % name |
1198 return "Error: A bus named %s already exists\n" % name |
1188 bus.BaseParams.setName(name) |
1199 bus.BaseParams.setName(name) |
1189 self.RestartTimer() |
1200 self.RestartTimer() |
1190 |
1201 |
1191 def ChangeBusIECChannel(self, old_iec_channel, new_iec_channel): |
1202 def ChangeBusIECChannel(self, old_iec_channel, new_iec_channel): |
1192 bus = self.PluginRoot.GetChildByIECLocation((old_iec_channel,)) |
1203 bus = self.PluginRoot.GetChildByIECLocation((old_iec_channel,)) |
1193 if bus is None: |
1204 if bus is None: |
1194 return "Error: No bus found" |
1205 return "Error: No bus found\n" |
1195 for child in self.PluginRoot.IterChilds(): |
1206 for child in self.PluginRoot.IterChilds(): |
1196 if child != bus and child.BaseParams.getIEC_Channel() == new_iec_channel: |
1207 if child != bus and child.BaseParams.getIEC_Channel() == new_iec_channel: |
1197 return "Error: A bus with IEC_channel %d already exists" % new_iec_channel |
1208 return "Error: A bus with IEC_channel %d already exists\n" % new_iec_channel |
1198 if wx.GetApp() is None: |
1209 if wx.GetApp() is None: |
1199 self.PluginRoot.UpdateProjectVariableLocation(str(old_iec_channel), |
1210 self.PluginRoot.UpdateProjectVariableLocation(str(old_iec_channel), |
1200 str(new_iec_channel)) |
1211 str(new_iec_channel)) |
1201 else: |
1212 else: |
1202 self.PluginRoot.UpdateProjectVariableLocation( |
1213 self.PluginRoot.UpdateProjectVariableLocation( |
1206 self.RestartTimer() |
1217 self.RestartTimer() |
1207 |
1218 |
1208 def RemoveBus(self, iec_channel): |
1219 def RemoveBus(self, iec_channel): |
1209 bus = self.PluginRoot.GetChildByIECLocation((iec_channel,)) |
1220 bus = self.PluginRoot.GetChildByIECLocation((iec_channel,)) |
1210 if bus is None: |
1221 if bus is None: |
1211 return "Error: No bus found" |
1222 return "Error: No bus found\n" |
1212 self.PluginRoot.RemoveProjectVariableByFilter(str(iec_channel)) |
1223 self.PluginRoot.RemoveProjectVariableByFilter(str(iec_channel)) |
1213 self.PluginRoot.PluggedChilds["LPCBus"].remove(bus) |
1224 self.PluginRoot.PluggedChilds["LPCBus"].remove(bus) |
1214 self.RestartTimer() |
1225 self.RestartTimer() |
1215 |
1226 |
1216 def AddModule(self, parent, iec_channel, name, icon=None): |
1227 def AddModule(self, parent, iec_channel, name, icon=None): |
1217 module = self.PluginRoot.GetChildByIECLocation(parent) |
1228 module = self.PluginRoot.GetChildByIECLocation(parent) |
1218 if module is None: |
1229 if module is None: |
1219 return "Error: No parent found" |
1230 return "Error: No parent found\n" |
1220 for child in _GetModuleChildren(module): |
1231 for child in _GetModuleChildren(module): |
1221 if child["name"] == name: |
1232 if child["name"] == name: |
1222 return "Error: A module named %s already exists" % name |
1233 return "Error: A module named %s already exists\n" % name |
1223 elif child["IEC_Channel"] == iec_channel: |
1234 elif child["IEC_Channel"] == iec_channel: |
1224 return "Error: A module with IEC_channel %d already exists" % iec_channel |
1235 return "Error: A module with IEC_channel %d already exists\n" % iec_channel |
1225 _GetLastModuleGroup(module).append({"name": name, |
1236 _GetLastModuleGroup(module).append({"name": name, |
1226 "type": LOCATION_MODULE, |
1237 "type": LOCATION_MODULE, |
1227 "IEC_Channel": iec_channel, |
1238 "IEC_Channel": iec_channel, |
1228 "icon": icon, |
1239 "icon": icon, |
1229 "children": []}) |
1240 "children": []}) |
1230 self.RestartTimer() |
1241 self.RestartTimer() |
1231 |
1242 |
1232 def RenameModule(self, iec_location, name): |
1243 def RenameModule(self, iec_location, name): |
1233 module = self.PluginRoot.GetChildByIECLocation(iec_location) |
1244 module = self.PluginRoot.GetChildByIECLocation(iec_location) |
1234 if module is None: |
1245 if module is None: |
1235 return "Error: No module found" |
1246 return "Error: No module found\n" |
1236 parent = self.PluginRoot.GetChildByIECLocation(iec_location[:-1]) |
1247 parent = self.PluginRoot.GetChildByIECLocation(iec_location[:-1]) |
1237 if parent is self.PluginRoot: |
1248 if parent is self.PluginRoot: |
1238 return "Error: No module found" |
1249 return "Error: No module found\n" |
1239 if module["name"] != name: |
1250 if module["name"] != name: |
1240 for child in _GetModuleChildren(parent): |
1251 for child in _GetModuleChildren(parent): |
1241 if child["name"] == name: |
1252 if child["name"] == name: |
1242 return "Error: A module named %s already exists" % name |
1253 return "Error: A module named %s already exists\n" % name |
1243 module["name"] = name |
1254 module["name"] = name |
1244 self.RestartTimer() |
1255 self.RestartTimer() |
1245 |
1256 |
1246 def ChangeModuleIECChannel(self, old_iec_location, new_iec_channel): |
1257 def ChangeModuleIECChannel(self, old_iec_location, new_iec_channel): |
1247 module = self.PluginRoot.GetChildByIECLocation(old_iec_location) |
1258 module = self.PluginRoot.GetChildByIECLocation(old_iec_location) |
1248 if module is None: |
1259 if module is None: |
1249 return "Error: No module found" |
1260 return "Error: No module found\n" |
1250 parent = self.PluginRoot.GetChildByIECLocation(old_iec_location[:-1]) |
1261 parent = self.PluginRoot.GetChildByIECLocation(old_iec_location[:-1]) |
1251 if parent is self.PluginRoot: |
1262 if parent is self.PluginRoot: |
1252 return "Error: No module found" |
1263 return "Error: No module found\n" |
1253 if module["IEC_Channel"] != new_iec_channel: |
1264 if module["IEC_Channel"] != new_iec_channel: |
1254 for child in _GetModuleChildren(parent): |
1265 for child in _GetModuleChildren(parent): |
1255 if child["IEC_Channel"] == new_iec_channel: |
1266 if child["IEC_Channel"] == new_iec_channel: |
1256 return "Error: A module with IEC_channel %d already exists" % new_iec_channel |
1267 return "Error: A module with IEC_channel %d already exists\n" % new_iec_channel |
1257 self.PluginRoot.UpdateProjectVariableLocation(".".join(map(str, old_iec_location)), ".".join(map(str, old_iec_location[:1] + (new_iec_channel,)))) |
1268 self.PluginRoot.UpdateProjectVariableLocation(".".join(map(str, old_iec_location)), ".".join(map(str, old_iec_location[:1] + (new_iec_channel,)))) |
1258 module["IEC_Channel"] = new_iec_channel |
1269 module["IEC_Channel"] = new_iec_channel |
1259 self.RestartTimer() |
1270 self.RestartTimer() |
1260 |
1271 |
1261 def RemoveModule(self, parent, iec_channel): |
1272 def RemoveModule(self, parent, iec_channel): |
1262 module = self.PluginRoot.GetChildByIECLocation(parent) |
1273 module = self.PluginRoot.GetChildByIECLocation(parent) |
1263 if module is None: |
1274 if module is None: |
1264 return "Error: No parent found" |
1275 return "Error: No parent found\n" |
1265 child = _GetModuleBySomething(module, "IEC_Channel", (iec_channel,)) |
1276 child = _GetModuleBySomething(module, "IEC_Channel", (iec_channel,)) |
1266 if child is None: |
1277 if child is None: |
1267 return "Error: No module found" |
1278 return "Error: No module found\n" |
1268 self.PluginRoot.RemoveProjectVariableByFilter(".".join(map(str, parent + (iec_channel,)))) |
1279 self.PluginRoot.RemoveProjectVariableByFilter(".".join(map(str, parent + (iec_channel,)))) |
1269 _RemoveModuleChild(module, child) |
1280 _RemoveModuleChild(module, child) |
1270 self.RestartTimer() |
1281 self.RestartTimer() |
1271 |
1282 |
1272 def StartGroup(self, parent, name, icon=None): |
1283 def StartGroup(self, parent, name, icon=None): |
1273 module = self.PluginRoot.GetChildByIECLocation(parent) |
1284 module = self.PluginRoot.GetChildByIECLocation(parent) |
1274 if module is None: |
1285 if module is None: |
1275 return "Error: No parent found" |
1286 return "Error: No parent found\n" |
1276 for child in module["children"]: |
1287 for child in module["children"]: |
1277 if child["type"] == LOCATION_GROUP and child["name"] == name: |
1288 if child["type"] == LOCATION_GROUP and child["name"] == name: |
1278 return "Error: A group named %s already exists" % name |
1289 return "Error: A group named %s already exists\n" % name |
1279 module["children"].append({"name": name, |
1290 module["children"].append({"name": name, |
1280 "type": LOCATION_GROUP, |
1291 "type": LOCATION_GROUP, |
1281 "icon": icon, |
1292 "icon": icon, |
1282 "children": []}) |
1293 "children": []}) |
1283 self.RestartTimer() |
1294 self.RestartTimer() |
1284 |
1295 |
1285 def AddVariable(self, parent, location, name, direction, type, dcode, rcode, pcode, description=""): |
1296 def AddVariable(self, parent, location, name, direction, type, dcode, rcode, pcode, description=""): |
1286 module = self.PluginRoot.GetChildByIECLocation(parent) |
1297 module = self.PluginRoot.GetChildByIECLocation(parent) |
1287 if module is None: |
1298 if module is None: |
1288 return "Error: No parent found" |
1299 return "Error: No parent found\n" |
1289 for child in _GetModuleChildren(module): |
1300 for child in _GetModuleChildren(module): |
1290 if child["name"] == name: |
1301 if child["name"] == name: |
1291 return "Error: A variable named %s already exists" % name |
1302 return "Error: A variable named %s already exists\n" % name |
1292 if child["location"] == location and child["type"] == LOCATION_TYPES[direction]: |
1303 if child["location"] == location and child["type"] == LOCATION_TYPES[direction]: |
1293 return "Error: A variable with location %s already exists" % ".".join(map(str, location)) |
1304 return "Error: A variable with location %s already exists\n" % ".".join(map(str, location)) |
1294 _GetLastModuleGroup(module).append({"name": name, |
1305 _GetLastModuleGroup(module).append({"name": name, |
1295 "location": location, |
1306 "location": location, |
1296 "type": LOCATION_TYPES[direction], |
1307 "type": LOCATION_TYPES[direction], |
1297 "IEC_type": type, |
1308 "IEC_type": type, |
1298 "description": description, |
1309 "description": description, |
1302 self.RestartTimer() |
1313 self.RestartTimer() |
1303 |
1314 |
1304 def ChangeVariableParams(self, parent, location, new_name, new_direction, new_type, new_dcode, new_rcode, new_pcode, new_description=None): |
1315 def ChangeVariableParams(self, parent, location, new_name, new_direction, new_type, new_dcode, new_rcode, new_pcode, new_description=None): |
1305 module = self.PluginRoot.GetChildByIECLocation(parent) |
1316 module = self.PluginRoot.GetChildByIECLocation(parent) |
1306 if module is None: |
1317 if module is None: |
1307 return "Error: No parent found" |
1318 return "Error: No parent found\n" |
1308 variable = None |
1319 variable = None |
1309 for child in _GetModuleChildren(module): |
1320 for child in _GetModuleChildren(module): |
1310 if child["location"] == location and child["type"] == LOCATION_TYPES[new_direction]: |
1321 if child["location"] == location and child["type"] == LOCATION_TYPES[new_direction]: |
1311 variable = child |
1322 variable = child |
1312 elif child["name"] == new_name: |
1323 elif child["name"] == new_name: |
1313 return "Error: A variable named %s already exists" % new_name |
1324 return "Error: A variable named %s already exists\n" % new_name |
1314 if variable is None: |
1325 if variable is None: |
1315 return "Error: No variable found" |
1326 return "Error: No variable found\n" |
1316 if variable["name"] != new_name: |
1327 if variable["name"] != new_name: |
1317 self.PluginRoot.UpdateProjectVariableName(variable["name"], new_name) |
1328 self.PluginRoot.UpdateProjectVariableName(variable["name"], new_name) |
1318 variable["name"] = new_name |
1329 variable["name"] = new_name |
1319 variable["type"] = LOCATION_TYPES[new_direction] |
1330 variable["type"] = LOCATION_TYPES[new_direction] |
1320 variable["IEC_type"] = new_type |
1331 variable["IEC_type"] = new_type |