13 |
13 |
14 from xmlclass import GenerateClassesFromXSDstring |
14 from xmlclass import GenerateClassesFromXSDstring |
15 from util.misc import GetClassImporter |
15 from util.misc import GetClassImporter |
16 |
16 |
17 from PLCControler import PLCControler, LOCATION_CONFNODE |
17 from PLCControler import PLCControler, LOCATION_CONFNODE |
18 from ConfTreeNodeEditor import ConfTreeNodeEditor |
18 from editors.ConfTreeNodeEditor import ConfTreeNodeEditor |
19 |
19 |
20 _BaseParamsClass = GenerateClassesFromXSDstring("""<?xml version="1.0" encoding="ISO-8859-1" ?> |
20 _BaseParamsClass = GenerateClassesFromXSDstring("""<?xml version="1.0" encoding="ISO-8859-1" ?> |
21 <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> |
21 <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> |
22 <xsd:element name="BaseParams"> |
22 <xsd:element name="BaseParams"> |
23 <xsd:complexType> |
23 <xsd:complexType> |
134 self.ChangesToSave = True |
134 self.ChangesToSave = True |
135 # Filter IEC_Channel and Name, that have specific behavior |
135 # Filter IEC_Channel and Name, that have specific behavior |
136 if path == "BaseParams.IEC_Channel": |
136 if path == "BaseParams.IEC_Channel": |
137 old_leading = ".".join(map(str, self.GetCurrentLocation())) |
137 old_leading = ".".join(map(str, self.GetCurrentLocation())) |
138 new_value = self.FindNewIEC_Channel(value) |
138 new_value = self.FindNewIEC_Channel(value) |
139 new_leading = ".".join(map(str, self.CTNParent.GetCurrentLocation() + (new_value,))) |
139 if new_value != value: |
140 self.GetCTRoot().UpdateProjectVariableLocation(old_leading, new_leading) |
140 new_leading = ".".join(map(str, self.CTNParent.GetCurrentLocation() + (new_value,))) |
|
141 self.GetCTRoot().UpdateProjectVariableLocation(old_leading, new_leading) |
141 return new_value, True |
142 return new_value, True |
142 elif path == "BaseParams.Name": |
143 elif path == "BaseParams.Name": |
143 res = self.FindNewName(value) |
144 res = self.FindNewName(value) |
144 self.CTNRequestSave() |
145 self.CTNRequestSave() |
145 return res, True |
146 return res, True |
192 |
193 |
193 def CTNImport(self, src_CTNPath): |
194 def CTNImport(self, src_CTNPath): |
194 shutil.copytree(src_CTNPath, self.CTNPath) |
195 shutil.copytree(src_CTNPath, self.CTNPath) |
195 return True |
196 return True |
196 |
197 |
|
198 def CTNGlobalInstances(self): |
|
199 """ |
|
200 @return: [(instance_name, instance_type),...] |
|
201 """ |
|
202 return [] |
|
203 |
|
204 def _GlobalInstances(self): |
|
205 instances = self.CTNGlobalInstances() |
|
206 for CTNChild in self.IECSortedChildren(): |
|
207 instances.extend(CTNChild._GlobalInstances()) |
|
208 return instances |
|
209 |
197 def CTNGenerate_C(self, buildpath, locations): |
210 def CTNGenerate_C(self, buildpath, locations): |
198 """ |
211 """ |
199 Generate C code |
212 Generate C code |
200 @param locations: List of complete variables locations \ |
213 @param locations: List of complete variables locations \ |
201 [{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...) |
214 [{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...) |
350 if CTNInstance != self: |
363 if CTNInstance != self: |
351 AllNames.append(CTNInstance.BaseParams.getName()) |
364 AllNames.append(CTNInstance.BaseParams.getName()) |
352 |
365 |
353 # Find a free name, eventually appending digit |
366 # Find a free name, eventually appending digit |
354 res = DesiredName |
367 res = DesiredName |
|
368 if DesiredName.endswith("_0"): |
|
369 BaseDesiredName = DesiredName[:-2] |
|
370 else: |
|
371 BaseDesiredName = DesiredName |
355 suffix = 1 |
372 suffix = 1 |
356 while res in AllNames: |
373 while res in AllNames: |
357 res = "%s-%d"%(DesiredName, suffix) |
374 res = "%s_%d"%(BaseDesiredName, suffix) |
358 suffix += 1 |
375 suffix += 1 |
359 |
376 |
360 # Get old path |
377 # Get old path |
361 oldname = self.CTNPath() |
378 oldname = self.CTNPath() |
362 # Check previous confnode existance |
379 # Check previous confnode existance |
402 else : # Want to go up ? |
419 else : # Want to go up ? |
403 res += 1 # Test for n-1 |
420 res += 1 # Test for n-1 |
404 # Finally set IEC Channel |
421 # Finally set IEC Channel |
405 self.BaseParams.setIEC_Channel(res) |
422 self.BaseParams.setIEC_Channel(res) |
406 return res |
423 return res |
|
424 |
|
425 def GetContextualMenuItems(self): |
|
426 return None |
407 |
427 |
408 def _OpenView(self, name=None, onlyopened=False): |
428 def _OpenView(self, name=None, onlyopened=False): |
409 if self.EditorType is not None: |
429 if self.EditorType is not None: |
410 app_frame = self.GetCTRoot().AppFrame |
430 app_frame = self.GetCTRoot().AppFrame |
411 if self._View is None and not onlyopened: |
431 if self._View is None and not onlyopened: |