author | Laurent Bessard |
Wed, 08 May 2013 23:31:12 +0200 | |
changeset 1101 | 5a0b439cf576 |
parent 1063 | 9b5995303db1 |
child 1179 | 3e7bd88fcff7 |
permissions | -rw-r--r-- |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
1 |
""" |
725 | 2 |
Config Tree Node base class. |
3 |
||
4 |
- A Beremiz project is organized in a tree each node derivate from ConfigTreeNode |
|
5 |
- Project tree organization match filesystem organization of project directory. |
|
6 |
- Each node of the tree have its own xml configuration, whose grammar is defined for each node type, as XSD |
|
7 |
- ... TODO : document |
|
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
8 |
""" |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
9 |
|
725 | 10 |
import os,traceback,types |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
11 |
import shutil |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
12 |
from xml.dom import minidom |
126 | 13 |
|
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
14 |
from xmlclass import GenerateClassesFromXSDstring |
742
41a4a560406c
Fixed runtime problems with python 2.6 without wx installed
Edouard Tisserant
parents:
741
diff
changeset
|
15 |
from util.misc import GetClassImporter |
725 | 16 |
|
17 |
from PLCControler import PLCControler, LOCATION_CONFNODE |
|
814 | 18 |
from editors.ConfTreeNodeEditor import ConfTreeNodeEditor |
274
8628f3dd0979
Adding support for defining plugin library as a plcopen xml file in plugin folder
greg
parents:
273
diff
changeset
|
19 |
|
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
20 |
_BaseParamsClass = GenerateClassesFromXSDstring("""<?xml version="1.0" encoding="ISO-8859-1" ?> |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
21 |
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
22 |
<xsd:element name="BaseParams"> |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
23 |
<xsd:complexType> |
86 | 24 |
<xsd:attribute name="Name" type="xsd:string" use="optional" default="__unnamed__"/> |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
16
diff
changeset
|
25 |
<xsd:attribute name="IEC_Channel" type="xsd:integer" use="required"/> |
86 | 26 |
<xsd:attribute name="Enabled" type="xsd:boolean" use="optional" default="true"/> |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
27 |
</xsd:complexType> |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
28 |
</xsd:element> |
86 | 29 |
</xsd:schema>""")["BaseParams"] |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
30 |
|
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
31 |
NameTypeSeparator = '@' |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
32 |
|
717 | 33 |
class ConfigTreeNode: |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
34 |
""" |
717 | 35 |
This class is the one that define confnodes. |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
36 |
""" |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
37 |
|
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
38 |
XSD = None |
718 | 39 |
CTNChildrenTypes = [] |
40 |
CTNMaxCount = None |
|
717 | 41 |
ConfNodeMethods = [] |
274
8628f3dd0979
Adding support for defining plugin library as a plcopen xml file in plugin folder
greg
parents:
273
diff
changeset
|
42 |
LibraryControler = None |
743 | 43 |
EditorType = ConfTreeNodeEditor |
738 | 44 |
IconPath = None |
45 |
||
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
46 |
def _AddParamsMembers(self): |
718 | 47 |
self.CTNParams = None |
29
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
48 |
if self.XSD: |
411
8261c8f1e365
Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents:
403
diff
changeset
|
49 |
self.Classes = GenerateClassesFromXSDstring(self.XSD) |
8261c8f1e365
Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents:
403
diff
changeset
|
50 |
Classes = [(name, XSDclass) for name, XSDclass in self.Classes.items() if XSDclass.IsBaseClass] |
29
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
51 |
if len(Classes) == 1: |
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
52 |
name, XSDclass = Classes[0] |
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
53 |
obj = XSDclass() |
718 | 54 |
self.CTNParams = (name, obj) |
29
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
55 |
setattr(self, name, obj) |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
16
diff
changeset
|
56 |
|
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
16
diff
changeset
|
57 |
def __init__(self): |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
58 |
# Create BaseParam |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
59 |
self.BaseParams = _BaseParamsClass() |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
16
diff
changeset
|
60 |
self.MandatoryParams = ("BaseParams", self.BaseParams) |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
61 |
self._AddParamsMembers() |
718 | 62 |
self.Children = {} |
656
c1792dfc8c7e
Fixing bug integrated plugin editors not closed when removing corresponding plugin
laurent
parents:
655
diff
changeset
|
63 |
self._View = None |
717 | 64 |
# copy ConfNodeMethods so that it can be later customized |
65 |
self.ConfNodeMethods = [dic.copy() for dic in self.ConfNodeMethods] |
|
325
f2604900bf25
Bug preventing loading STLibrary when adding a plugin fixed
lbessard
parents:
321
diff
changeset
|
66 |
|
718 | 67 |
def ConfNodeBaseXmlFilePath(self, CTNName=None): |
68 |
return os.path.join(self.CTNPath(CTNName), "baseconfnode.xml") |
|
69 |
||
70 |
def ConfNodeXmlFilePath(self, CTNName=None): |
|
71 |
return os.path.join(self.CTNPath(CTNName), "confnode.xml") |
|
717 | 72 |
|
73 |
def ConfNodePath(self): |
|
718 | 74 |
return os.path.join(self.CTNParent.ConfNodePath(), self.CTNType) |
75 |
||
1061 | 76 |
def CTNPath(self,CTNName=None,project_path=None): |
718 | 77 |
if not CTNName: |
78 |
CTNName = self.CTNName() |
|
1061 | 79 |
if not project_path: |
80 |
project_path = self.CTNParent.CTNPath() |
|
81 |
return os.path.join(project_path, |
|
718 | 82 |
CTNName + NameTypeSeparator + self.CTNType) |
83 |
||
84 |
def CTNName(self): |
|
675
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
674
diff
changeset
|
85 |
return self.BaseParams.getName() |
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
674
diff
changeset
|
86 |
|
718 | 87 |
def CTNEnabled(self): |
675
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
674
diff
changeset
|
88 |
return self.BaseParams.getEnabled() |
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
674
diff
changeset
|
89 |
|
718 | 90 |
def CTNFullName(self): |
91 |
parent = self.CTNParent.CTNFullName() |
|
656
c1792dfc8c7e
Fixing bug integrated plugin editors not closed when removing corresponding plugin
laurent
parents:
655
diff
changeset
|
92 |
if parent != "": |
718 | 93 |
return parent + "." + self.CTNName() |
656
c1792dfc8c7e
Fixing bug integrated plugin editors not closed when removing corresponding plugin
laurent
parents:
655
diff
changeset
|
94 |
return self.BaseParams.getName() |
c1792dfc8c7e
Fixing bug integrated plugin editors not closed when removing corresponding plugin
laurent
parents:
655
diff
changeset
|
95 |
|
781
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
780
diff
changeset
|
96 |
def GetIconName(self): |
734 | 97 |
return None |
652
eb2d9f2b3567
Adding support for loading specific POUs library in LPCBeremiz
laurent
parents:
639
diff
changeset
|
98 |
|
718 | 99 |
def CTNTestModified(self): |
118 | 100 |
return self.ChangesToSave |
101 |
||
102 |
def ProjectTestModified(self): |
|
103 |
""" |
|
104 |
recursively check modified status |
|
105 |
""" |
|
718 | 106 |
if self.CTNTestModified(): |
118 | 107 |
return True |
108 |
||
718 | 109 |
for CTNChild in self.IterChildren(): |
110 |
if CTNChild.ProjectTestModified(): |
|
118 | 111 |
return True |
112 |
||
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
113 |
return False |
699
6ff64cadb1ff
Adding support for executing python scripts on remote runtime
laurent
parents:
696
diff
changeset
|
114 |
|
6ff64cadb1ff
Adding support for executing python scripts on remote runtime
laurent
parents:
696
diff
changeset
|
115 |
def RemoteExec(self, script, **kwargs): |
718 | 116 |
return self.CTNParent.RemoteExec(script, **kwargs) |
117 |
||
1061 | 118 |
def OnCTNSave(self, from_project_path=None): |
20 | 119 |
#Default, do nothing and return success |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
120 |
return True |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
121 |
|
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
122 |
def GetParamsAttributes(self, path = None): |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
123 |
if path: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
124 |
parts = path.split(".", 1) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
125 |
if self.MandatoryParams and parts[0] == self.MandatoryParams[0]: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
126 |
return self.MandatoryParams[1].getElementInfos(parts[0], parts[1]) |
718 | 127 |
elif self.CTNParams and parts[0] == self.CTNParams[0]: |
128 |
return self.CTNParams[1].getElementInfos(parts[0], parts[1]) |
|
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
16
diff
changeset
|
129 |
else: |
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
130 |
params = [] |
718 | 131 |
if self.CTNParams: |
132 |
params.append(self.CTNParams[1].getElementInfos(self.CTNParams[0])) |
|
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
133 |
return params |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
134 |
|
203 | 135 |
def SetParamsAttribute(self, path, value): |
118 | 136 |
self.ChangesToSave = True |
29
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
137 |
# Filter IEC_Channel and Name, that have specific behavior |
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
138 |
if path == "BaseParams.IEC_Channel": |
443
34c9788bd933
Adding support for updating located variables when changing plugin IEC_Channel
laurent
parents:
440
diff
changeset
|
139 |
old_leading = ".".join(map(str, self.GetCurrentLocation())) |
34c9788bd933
Adding support for updating located variables when changing plugin IEC_Channel
laurent
parents:
440
diff
changeset
|
140 |
new_value = self.FindNewIEC_Channel(value) |
842 | 141 |
if new_value != value: |
142 |
new_leading = ".".join(map(str, self.CTNParent.GetCurrentLocation() + (new_value,))) |
|
143 |
self.GetCTRoot().UpdateProjectVariableLocation(old_leading, new_leading) |
|
443
34c9788bd933
Adding support for updating located variables when changing plugin IEC_Channel
laurent
parents:
440
diff
changeset
|
144 |
return new_value, True |
29
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
145 |
elif path == "BaseParams.Name": |
203 | 146 |
res = self.FindNewName(value) |
718 | 147 |
self.CTNRequestSave() |
118 | 148 |
return res, True |
29
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
149 |
|
19
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
150 |
parts = path.split(".", 1) |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
151 |
if self.MandatoryParams and parts[0] == self.MandatoryParams[0]: |
73257cea38bd
Adding Plugin params visualization with basic controls
lbessard
parents:
18
diff
changeset
|
152 |
self.MandatoryParams[1].setElementValue(parts[1], value) |
718 | 153 |
elif self.CTNParams and parts[0] == self.CTNParams[0]: |
154 |
self.CTNParams[1].setElementValue(parts[1], value) |
|
29
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
155 |
return value, False |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
16
diff
changeset
|
156 |
|
718 | 157 |
def CTNMakeDir(self): |
158 |
os.mkdir(self.CTNPath()) |
|
159 |
||
1061 | 160 |
def CTNRequestSave(self, from_project_path=None): |
718 | 161 |
if self.GetCTRoot().CheckProjectPathPerm(False): |
717 | 162 |
# If confnode do not have corresponding directory |
718 | 163 |
ctnpath = self.CTNPath() |
164 |
if not os.path.isdir(ctnpath): |
|
427 | 165 |
# Create it |
718 | 166 |
os.mkdir(ctnpath) |
427 | 167 |
|
717 | 168 |
# generate XML for base XML parameters controller of the confnode |
427 | 169 |
if self.MandatoryParams: |
717 | 170 |
BaseXMLFile = open(self.ConfNodeBaseXmlFilePath(),'w') |
427 | 171 |
BaseXMLFile.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n") |
430 | 172 |
BaseXMLFile.write(self.MandatoryParams[1].generateXMLText(self.MandatoryParams[0], 0).encode("utf-8")) |
427 | 173 |
BaseXMLFile.close() |
174 |
||
717 | 175 |
# generate XML for XML parameters controller of the confnode |
718 | 176 |
if self.CTNParams: |
717 | 177 |
XMLFile = open(self.ConfNodeXmlFilePath(),'w') |
427 | 178 |
XMLFile.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n") |
718 | 179 |
XMLFile.write(self.CTNParams[1].generateXMLText(self.CTNParams[0], 0).encode("utf-8")) |
427 | 180 |
XMLFile.close() |
181 |
||
718 | 182 |
# Call the confnode specific OnCTNSave method |
1061 | 183 |
result = self.OnCTNSave(from_project_path) |
427 | 184 |
if not result: |
718 | 185 |
return _("Error while saving \"%s\"\n")%self.CTNPath() |
427 | 186 |
|
717 | 187 |
# mark confnode as saved |
427 | 188 |
self.ChangesToSave = False |
718 | 189 |
# go through all children and do the same |
190 |
for CTNChild in self.IterChildren(): |
|
1063 | 191 |
CTNChildPath = None |
192 |
if from_project_path is not None: |
|
193 |
CTNChildPath = CTNChild.CTNPath(project_path=from_project_path) |
|
194 |
result = CTNChild.CTNRequestSave(CTNChildPath) |
|
427 | 195 |
if result: |
196 |
return result |
|
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
16
diff
changeset
|
197 |
return None |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
198 |
|
718 | 199 |
def CTNImport(self, src_CTNPath): |
200 |
shutil.copytree(src_CTNPath, self.CTNPath) |
|
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
201 |
return True |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
202 |
|
883
235a9ec83b95
Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents:
842
diff
changeset
|
203 |
def CTNGlobalInstances(self): |
235a9ec83b95
Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents:
842
diff
changeset
|
204 |
""" |
235a9ec83b95
Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents:
842
diff
changeset
|
205 |
@return: [(instance_name, instance_type),...] |
235a9ec83b95
Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents:
842
diff
changeset
|
206 |
""" |
235a9ec83b95
Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents:
842
diff
changeset
|
207 |
return [] |
235a9ec83b95
Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents:
842
diff
changeset
|
208 |
|
235a9ec83b95
Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents:
842
diff
changeset
|
209 |
def _GlobalInstances(self): |
235a9ec83b95
Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents:
842
diff
changeset
|
210 |
instances = self.CTNGlobalInstances() |
235a9ec83b95
Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents:
842
diff
changeset
|
211 |
for CTNChild in self.IECSortedChildren(): |
235a9ec83b95
Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents:
842
diff
changeset
|
212 |
instances.extend(CTNChild._GlobalInstances()) |
235a9ec83b95
Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents:
842
diff
changeset
|
213 |
return instances |
235a9ec83b95
Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents:
842
diff
changeset
|
214 |
|
718 | 215 |
def CTNGenerate_C(self, buildpath, locations): |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
216 |
""" |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
217 |
Generate C code |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
218 |
@param locations: List of complete variables locations \ |
22 | 219 |
[{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...) |
220 |
"NAME" : name of the variable (generally "__IW0_1_2" style) |
|
221 |
"DIR" : direction "Q","I" or "M" |
|
222 |
"SIZE" : size "X", "B", "W", "D", "L" |
|
223 |
"LOC" : tuple of interger for IEC location (0,1,2,...) |
|
224 |
}, ...] |
|
18 | 225 |
@return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND |
226 |
""" |
|
718 | 227 |
self.GetCTRoot().logger.write_warning(".".join(map(lambda x:str(x), self.GetCurrentLocation())) + " -> Nothing to do\n") |
51
c31c55601556
Added project linking, and plugin init,cleanup,retrive and publish method calls in main
etisserant
parents:
49
diff
changeset
|
228 |
return [],"",False |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
229 |
|
203 | 230 |
def _Generate_C(self, buildpath, locations): |
717 | 231 |
# Generate confnodes [(Cfiles, CFLAGS)], LDFLAGS, DoCalls, extra_files |
203 | 232 |
# extra_files = [(fname,fobject), ...] |
718 | 233 |
gen_result = self.CTNGenerate_C(buildpath, locations) |
234 |
CTNCFilesAndCFLAGS, CTNLDFLAGS, DoCalls = gen_result[:3] |
|
203 | 235 |
extra_files = gen_result[3:] |
361 | 236 |
# if some files have been generated put them in the list with their location |
718 | 237 |
if CTNCFilesAndCFLAGS: |
238 |
LocationCFilesAndCFLAGS = [(self.GetCurrentLocation(), CTNCFilesAndCFLAGS, DoCalls)] |
|
47
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
239 |
else: |
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
240 |
LocationCFilesAndCFLAGS = [] |
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
241 |
|
717 | 242 |
# confnode asks for some LDFLAGS |
718 | 243 |
if CTNLDFLAGS: |
47
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
244 |
# LDFLAGS can be either string |
718 | 245 |
if type(CTNLDFLAGS)==type(str()): |
246 |
LDFLAGS=[CTNLDFLAGS] |
|
47
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
247 |
#or list of strings |
718 | 248 |
elif type(CTNLDFLAGS)==type(list()): |
249 |
LDFLAGS=CTNLDFLAGS[:] |
|
47
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
250 |
else: |
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
251 |
LDFLAGS=[] |
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
252 |
|
718 | 253 |
# recurse through all children, and stack their results |
254 |
for CTNChild in self.IECSortedChildren(): |
|
255 |
new_location = CTNChild.GetCurrentLocation() |
|
24 | 256 |
# How deep are we in the tree ? |
257 |
depth=len(new_location) |
|
203 | 258 |
_LocationCFilesAndCFLAGS, _LDFLAGS, _extra_files = \ |
718 | 259 |
CTNChild._Generate_C( |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
260 |
#keep the same path |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
261 |
buildpath, |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
262 |
# filter locations that start with current IEC location |
203 | 263 |
[loc for loc in locations if loc["LOC"][0:depth] == new_location ]) |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
264 |
# stack the result |
47
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
265 |
LocationCFilesAndCFLAGS += _LocationCFilesAndCFLAGS |
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
266 |
LDFLAGS += _LDFLAGS |
203 | 267 |
extra_files += _extra_files |
268 |
||
269 |
return LocationCFilesAndCFLAGS, LDFLAGS, extra_files |
|
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
270 |
|
718 | 271 |
def IterChildren(self): |
272 |
for CTNType, Children in self.Children.items(): |
|
273 |
for CTNInstance in Children: |
|
274 |
yield CTNInstance |
|
275 |
||
276 |
def IECSortedChildren(self): |
|
277 |
# reorder children by IEC_channels |
|
278 |
ordered = [(chld.BaseParams.getIEC_Channel(),chld) for chld in self.IterChildren()] |
|
47
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
279 |
if ordered: |
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
280 |
ordered.sort() |
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
281 |
return zip(*ordered)[1] |
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
282 |
else: |
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
283 |
return [] |
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
284 |
|
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
285 |
def _GetChildBySomething(self, something, toks): |
718 | 286 |
for CTNInstance in self.IterChildren(): |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
287 |
# if match component of the name |
718 | 288 |
if getattr(CTNInstance.BaseParams, something) == toks[0]: |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
289 |
# if Name have other components |
47
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
290 |
if len(toks) >= 2: |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
291 |
# Recurse in order to find the latest object |
718 | 292 |
return CTNInstance._GetChildBySomething( something, toks[1:]) |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
293 |
# No sub name -> found |
718 | 294 |
return CTNInstance |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
295 |
# Not found |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
296 |
return None |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
297 |
|
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
298 |
def GetChildByName(self, Name): |
47
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
299 |
if Name: |
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
300 |
toks = Name.split('.') |
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
301 |
return self._GetChildBySomething("Name", toks) |
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
302 |
else: |
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
303 |
return self |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
304 |
|
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
305 |
def GetChildByIECLocation(self, Location): |
47
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
306 |
if Location: |
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
307 |
return self._GetChildBySomething("IEC_Channel", Location) |
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
308 |
else: |
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
309 |
return self |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
310 |
|
23 | 311 |
def GetCurrentLocation(self): |
24 | 312 |
""" |
717 | 313 |
@return: Tupple containing confnode IEC location of current confnode : %I0.0.4.5 => (0,0,4,5) |
24 | 314 |
""" |
718 | 315 |
return self.CTNParent.GetCurrentLocation() + (self.BaseParams.getIEC_Channel(),) |
23 | 316 |
|
47
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
317 |
def GetCurrentName(self): |
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
318 |
""" |
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
319 |
@return: String "ParentParentName.ParentName.Name" |
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
320 |
""" |
718 | 321 |
return self.CTNParent._GetCurrentName() + self.BaseParams.getName() |
47
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
322 |
|
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
323 |
def _GetCurrentName(self): |
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
324 |
""" |
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
325 |
@return: String "ParentParentName.ParentName.Name." |
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
326 |
""" |
718 | 327 |
return self.CTNParent._GetCurrentName() + self.BaseParams.getName() + "." |
328 |
||
329 |
def GetCTRoot(self): |
|
330 |
return self.CTNParent.GetCTRoot() |
|
23 | 331 |
|
97 | 332 |
def GetFullIEC_Channel(self): |
333 |
return ".".join([str(i) for i in self.GetCurrentLocation()]) + ".x" |
|
334 |
||
335 |
def GetLocations(self): |
|
336 |
location = self.GetCurrentLocation() |
|
718 | 337 |
return [loc for loc in self.CTNParent.GetLocations() if loc["LOC"][0:len(location)] == location] |
97 | 338 |
|
401
8106a853a7c7
Adding support for displaying plugins available variable into Beremiz plugin tree
laurent
parents:
396
diff
changeset
|
339 |
def GetVariableLocationTree(self): |
8106a853a7c7
Adding support for displaying plugins available variable into Beremiz plugin tree
laurent
parents:
396
diff
changeset
|
340 |
''' |
717 | 341 |
This function is meant to be overridden by confnodes. |
401
8106a853a7c7
Adding support for displaying plugins available variable into Beremiz plugin tree
laurent
parents:
396
diff
changeset
|
342 |
|
8106a853a7c7
Adding support for displaying plugins available variable into Beremiz plugin tree
laurent
parents:
396
diff
changeset
|
343 |
It should returns an list of dictionaries |
8106a853a7c7
Adding support for displaying plugins available variable into Beremiz plugin tree
laurent
parents:
396
diff
changeset
|
344 |
|
8106a853a7c7
Adding support for displaying plugins available variable into Beremiz plugin tree
laurent
parents:
396
diff
changeset
|
345 |
- IEC_type is an IEC type like BOOL/BYTE/SINT/... |
8106a853a7c7
Adding support for displaying plugins available variable into Beremiz plugin tree
laurent
parents:
396
diff
changeset
|
346 |
- location is a string of this variable's location, like "%IX0.0.0" |
8106a853a7c7
Adding support for displaying plugins available variable into Beremiz plugin tree
laurent
parents:
396
diff
changeset
|
347 |
''' |
8106a853a7c7
Adding support for displaying plugins available variable into Beremiz plugin tree
laurent
parents:
396
diff
changeset
|
348 |
children = [] |
718 | 349 |
for child in self.IECSortedChildren(): |
402
984e238e63d0
Bugs on displaying plugin available variables in PluginTree fixed
laurent
parents:
401
diff
changeset
|
350 |
children.append(child.GetVariableLocationTree()) |
984e238e63d0
Bugs on displaying plugin available variables in PluginTree fixed
laurent
parents:
401
diff
changeset
|
351 |
return {"name": self.BaseParams.getName(), |
717 | 352 |
"type": LOCATION_CONFNODE, |
402
984e238e63d0
Bugs on displaying plugin available variables in PluginTree fixed
laurent
parents:
401
diff
changeset
|
353 |
"location": self.GetFullIEC_Channel(), |
984e238e63d0
Bugs on displaying plugin available variables in PluginTree fixed
laurent
parents:
401
diff
changeset
|
354 |
"children": children} |
401
8106a853a7c7
Adding support for displaying plugins available variable into Beremiz plugin tree
laurent
parents:
396
diff
changeset
|
355 |
|
203 | 356 |
def FindNewName(self, DesiredName): |
29
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
357 |
""" |
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
358 |
Changes Name to DesiredName if available, Name-N if not. |
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
359 |
@param DesiredName: The desired Name (string) |
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
360 |
""" |
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
361 |
# Get Current Name |
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
362 |
CurrentName = self.BaseParams.getName() |
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
363 |
# Do nothing if no change |
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
364 |
#if CurrentName == DesiredName: return CurrentName |
718 | 365 |
# Build a list of used Name out of parent's Children |
29
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
366 |
AllNames=[] |
718 | 367 |
for CTNInstance in self.CTNParent.IterChildren(): |
368 |
if CTNInstance != self: |
|
369 |
AllNames.append(CTNInstance.BaseParams.getName()) |
|
29
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
370 |
|
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
371 |
# Find a free name, eventually appending digit |
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
372 |
res = DesiredName |
833
3f997fb22928
Fix confnode new name format that generates an error with frame class name in wxGlade extension
laurent
parents:
814
diff
changeset
|
373 |
if DesiredName.endswith("_0"): |
841
8e19df12b596
Fix unexpected warning message when adding extension to project
Laurent Bessard
parents:
833
diff
changeset
|
374 |
BaseDesiredName = DesiredName[:-2] |
8e19df12b596
Fix unexpected warning message when adding extension to project
Laurent Bessard
parents:
833
diff
changeset
|
375 |
else: |
8e19df12b596
Fix unexpected warning message when adding extension to project
Laurent Bessard
parents:
833
diff
changeset
|
376 |
BaseDesiredName = DesiredName |
29
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
377 |
suffix = 1 |
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
378 |
while res in AllNames: |
841
8e19df12b596
Fix unexpected warning message when adding extension to project
Laurent Bessard
parents:
833
diff
changeset
|
379 |
res = "%s_%d"%(BaseDesiredName, suffix) |
29
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
380 |
suffix += 1 |
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
381 |
|
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
382 |
# Get old path |
718 | 383 |
oldname = self.CTNPath() |
717 | 384 |
# Check previous confnode existance |
29
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
385 |
dontexist = self.BaseParams.getName() == "__unnamed__" |
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
386 |
# Set the new name |
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
387 |
self.BaseParams.setName(res) |
717 | 388 |
# Rename confnode dir if exist |
29
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
389 |
if not dontexist: |
718 | 390 |
shutil.move(oldname, self.CTNPath()) |
29
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
391 |
# warn user he has two left hands |
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
392 |
if DesiredName != res: |
801
435e49e80832
Update list of messages to be translated for internationalization and french translations
laurent
parents:
786
diff
changeset
|
393 |
self.GetCTRoot().logger.write_warning(_("A child named \"%s\" already exist -> \"%s\"\n")%(DesiredName,res)) |
29
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
394 |
return res |
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
395 |
|
683
57aa9da845d5
Fix wrong panel size making strange background in topology plugin element
laurent
parents:
677
diff
changeset
|
396 |
def GetAllChannels(self): |
57aa9da845d5
Fix wrong panel size making strange background in topology plugin element
laurent
parents:
677
diff
changeset
|
397 |
AllChannels=[] |
718 | 398 |
for CTNInstance in self.CTNParent.IterChildren(): |
399 |
if CTNInstance != self: |
|
400 |
AllChannels.append(CTNInstance.BaseParams.getIEC_Channel()) |
|
683
57aa9da845d5
Fix wrong panel size making strange background in topology plugin element
laurent
parents:
677
diff
changeset
|
401 |
AllChannels.sort() |
57aa9da845d5
Fix wrong panel size making strange background in topology plugin element
laurent
parents:
677
diff
changeset
|
402 |
return AllChannels |
57aa9da845d5
Fix wrong panel size making strange background in topology plugin element
laurent
parents:
677
diff
changeset
|
403 |
|
203 | 404 |
def FindNewIEC_Channel(self, DesiredChannel): |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
405 |
""" |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
406 |
Changes IEC Channel number to DesiredChannel if available, nearest available if not. |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
407 |
@param DesiredChannel: The desired IEC channel (int) |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
408 |
""" |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
409 |
# Get Current IEC channel |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
410 |
CurrentChannel = self.BaseParams.getIEC_Channel() |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
411 |
# Do nothing if no change |
29
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
412 |
#if CurrentChannel == DesiredChannel: return CurrentChannel |
718 | 413 |
# Build a list of used Channels out of parent's Children |
683
57aa9da845d5
Fix wrong panel size making strange background in topology plugin element
laurent
parents:
677
diff
changeset
|
414 |
AllChannels = self.GetAllChannels() |
57aa9da845d5
Fix wrong panel size making strange background in topology plugin element
laurent
parents:
677
diff
changeset
|
415 |
|
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
416 |
# Now, try to guess the nearest available channel |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
417 |
res = DesiredChannel |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
418 |
while res in AllChannels: # While channel not free |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
419 |
if res < CurrentChannel: # Want to go down ? |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
420 |
res -= 1 # Test for n-1 |
33
59b84ab7bf8b
Enhanced bahavior of plugin tree representation when changing IEC channel
etisserant
parents:
29
diff
changeset
|
421 |
if res < 0 : |
718 | 422 |
self.GetCTRoot().logger.write_warning(_("Cannot find lower free IEC channel than %d\n")%CurrentChannel) |
33
59b84ab7bf8b
Enhanced bahavior of plugin tree representation when changing IEC channel
etisserant
parents:
29
diff
changeset
|
423 |
return CurrentChannel # Can't go bellow 0, do nothing |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
424 |
else : # Want to go up ? |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
425 |
res += 1 # Test for n-1 |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
426 |
# Finally set IEC Channel |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
427 |
self.BaseParams.setIEC_Channel(res) |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
428 |
return res |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
429 |
|
967
8a339cd61cb4
Added support for extension custom contextual add menu
Laurent Bessard
parents:
883
diff
changeset
|
430 |
def GetContextualMenuItems(self): |
8a339cd61cb4
Added support for extension custom contextual add menu
Laurent Bessard
parents:
883
diff
changeset
|
431 |
return None |
8a339cd61cb4
Added support for extension custom contextual add menu
Laurent Bessard
parents:
883
diff
changeset
|
432 |
|
782 | 433 |
def _OpenView(self, name=None, onlyopened=False): |
774
78b5fa92dd1c
Fix bug when opening and closing confnode extra viewers
laurent
parents:
744
diff
changeset
|
434 |
if self.EditorType is not None: |
782 | 435 |
app_frame = self.GetCTRoot().AppFrame |
784
a1d970365e41
Adding support for beremiz extensions to define custom file editors for project files
laurent
parents:
782
diff
changeset
|
436 |
if self._View is None and not onlyopened: |
774
78b5fa92dd1c
Fix bug when opening and closing confnode extra viewers
laurent
parents:
744
diff
changeset
|
437 |
|
78b5fa92dd1c
Fix bug when opening and closing confnode extra viewers
laurent
parents:
744
diff
changeset
|
438 |
self._View = self.EditorType(app_frame.TabsOpened, self, app_frame) |
784
a1d970365e41
Adding support for beremiz extensions to define custom file editors for project files
laurent
parents:
782
diff
changeset
|
439 |
|
a1d970365e41
Adding support for beremiz extensions to define custom file editors for project files
laurent
parents:
782
diff
changeset
|
440 |
if self._View is not None: |
786 | 441 |
if name is None: |
442 |
name = self.CTNFullName() |
|
443 |
app_frame.EditProjectElement(self._View, name) |
|
782 | 444 |
|
715
135566ab0807
Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents:
707
diff
changeset
|
445 |
return self._View |
135566ab0807
Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents:
707
diff
changeset
|
446 |
return None |
675
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
674
diff
changeset
|
447 |
|
774
78b5fa92dd1c
Fix bug when opening and closing confnode extra viewers
laurent
parents:
744
diff
changeset
|
448 |
def _CloseView(self, view): |
78b5fa92dd1c
Fix bug when opening and closing confnode extra viewers
laurent
parents:
744
diff
changeset
|
449 |
app_frame = self.GetCTRoot().AppFrame |
78b5fa92dd1c
Fix bug when opening and closing confnode extra viewers
laurent
parents:
744
diff
changeset
|
450 |
if app_frame is not None: |
78b5fa92dd1c
Fix bug when opening and closing confnode extra viewers
laurent
parents:
744
diff
changeset
|
451 |
app_frame.DeletePage(view) |
78b5fa92dd1c
Fix bug when opening and closing confnode extra viewers
laurent
parents:
744
diff
changeset
|
452 |
|
675
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
674
diff
changeset
|
453 |
def OnCloseEditor(self, view): |
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
674
diff
changeset
|
454 |
if self._View == view: |
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
674
diff
changeset
|
455 |
self._View = None |
656
c1792dfc8c7e
Fixing bug integrated plugin editors not closed when removing corresponding plugin
laurent
parents:
655
diff
changeset
|
456 |
|
718 | 457 |
def OnCTNClose(self): |
656
c1792dfc8c7e
Fixing bug integrated plugin editors not closed when removing corresponding plugin
laurent
parents:
655
diff
changeset
|
458 |
if self._View is not None: |
780
70632f4612a1
Fix bug when deleting conf tree node and conf tree node editor opened for this same node
laurent
parents:
774
diff
changeset
|
459 |
self._CloseView(self._View) |
774
78b5fa92dd1c
Fix bug when opening and closing confnode extra viewers
laurent
parents:
744
diff
changeset
|
460 |
self._View = None |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
461 |
return True |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
462 |
|
718 | 463 |
def _doRemoveChild(self, CTNInstance): |
464 |
# Remove all children of child |
|
465 |
for SubCTNInstance in CTNInstance.IterChildren(): |
|
466 |
CTNInstance._doRemoveChild(SubCTNInstance) |
|
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
467 |
# Call the OnCloseMethod |
718 | 468 |
CTNInstance.OnCTNClose() |
717 | 469 |
# Delete confnode dir |
718 | 470 |
shutil.rmtree(CTNInstance.CTNPath()) |
471 |
# Remove child of Children |
|
472 |
self.Children[CTNInstance.CTNType].remove(CTNInstance) |
|
1033
1eec9b855e47
Clean Config Tree Node children list by type after removing one child
Laurent Bessard
parents:
967
diff
changeset
|
473 |
if len(self.Children[CTNInstance.CTNType]) == 0: |
1eec9b855e47
Clean Config Tree Node children list by type after removing one child
Laurent Bessard
parents:
967
diff
changeset
|
474 |
self.Children.pop(CTNInstance.CTNType) |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
475 |
# Forget it... (View have to refresh) |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
476 |
|
718 | 477 |
def CTNRemove(self): |
717 | 478 |
# Fetch the confnode |
718 | 479 |
#CTNInstance = self.GetChildByName(CTNName) |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
480 |
# Ask to his parent to remove it |
718 | 481 |
self.CTNParent._doRemoveChild(self) |
482 |
||
483 |
def CTNAddChild(self, CTNName, CTNType, IEC_Channel=0): |
|
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
484 |
""" |
717 | 485 |
Create the confnodes that may be added as child to this node self |
718 | 486 |
@param CTNType: string desining the confnode class name (get name from CTNChildrenTypes) |
487 |
@param CTNName: string for the name of the confnode instance |
|
488 |
""" |
|
720 | 489 |
# reorganize self.CTNChildrenTypes tuples from (name, CTNClass, Help) |
718 | 490 |
# to ( name, (CTNClass, Help)), an make a dict |
491 |
transpose = zip(*self.CTNChildrenTypes) |
|
492 |
CTNChildrenTypes = dict(zip(transpose[0],zip(transpose[1],transpose[2]))) |
|
717 | 493 |
# Check that adding this confnode is allowed |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
494 |
try: |
718 | 495 |
CTNClass, CTNHelp = CTNChildrenTypes[CTNType] |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
496 |
except KeyError: |
718 | 497 |
raise Exception, _("Cannot create child %s of type %s ")%(CTNName, CTNType) |
498 |
||
499 |
# if CTNClass is a class factory, call it. (prevent unneeded imports) |
|
500 |
if type(CTNClass) == types.FunctionType: |
|
501 |
CTNClass = CTNClass() |
|
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
502 |
|
717 | 503 |
# Eventualy Initialize child instance list for this class of confnode |
718 | 504 |
ChildrenWithSameClass = self.Children.setdefault(CTNType, list()) |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
505 |
# Check count |
718 | 506 |
if getattr(CTNClass, "CTNMaxCount", None) and len(ChildrenWithSameClass) >= CTNClass.CTNMaxCount: |
507 |
raise Exception, _("Max count (%d) reached for this confnode of type %s ")%(CTNClass.CTNMaxCount, CTNType) |
|
717 | 508 |
|
509 |
# create the final class, derived of provided confnode and template |
|
718 | 510 |
class FinalCTNClass(CTNClass, ConfigTreeNode): |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
511 |
""" |
718 | 512 |
ConfNode class is derivated into FinalCTNClass before being instanciated |
717 | 513 |
This way __init__ is overloaded to ensure ConfigTreeNode.__init__ is called |
718 | 514 |
before CTNClass.__init__, and to do the file related stuff. |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
515 |
""" |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
516 |
def __init__(_self): |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
517 |
# self is the parent |
718 | 518 |
_self.CTNParent = self |
717 | 519 |
# Keep track of the confnode type name |
718 | 520 |
_self.CTNType = CTNType |
106
9810689febb0
Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents:
105
diff
changeset
|
521 |
# remind the help string, for more fancy display |
718 | 522 |
_self.CTNHelp = CTNHelp |
717 | 523 |
# Call the base confnode template init - change XSD into class members |
524 |
ConfigTreeNode.__init__(_self) |
|
29
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
525 |
# check name is unique |
718 | 526 |
NewCTNName = _self.FindNewName(CTNName) |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
527 |
# If dir have already be made, and file exist |
718 | 528 |
if os.path.isdir(_self.CTNPath(NewCTNName)): #and os.path.isfile(_self.ConfNodeXmlFilePath(CTNName)): |
717 | 529 |
#Load the confnode.xml file into parameters members |
718 | 530 |
_self.LoadXMLParams(NewCTNName) |
20 | 531 |
# Basic check. Better to fail immediately. |
718 | 532 |
if (_self.BaseParams.getName() != NewCTNName): |
533 |
raise Exception, _("Project tree layout do not match confnode.xml %s!=%s ")%(NewCTNName, _self.BaseParams.getName()) |
|
534 |
||
535 |
# Now, self.CTNPath() should be OK |
|
20 | 536 |
|
15
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
14
diff
changeset
|
537 |
# Check that IEC_Channel is not already in use. |
203 | 538 |
_self.FindNewIEC_Channel(_self.BaseParams.getIEC_Channel()) |
717 | 539 |
# Call the confnode real __init__ |
718 | 540 |
if getattr(CTNClass, "__init__", None): |
541 |
CTNClass.__init__(_self) |
|
542 |
#Load and init all the children |
|
543 |
_self.LoadChildren() |
|
118 | 544 |
#just loaded, nothing to saved |
545 |
_self.ChangesToSave = False |
|
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
546 |
else: |
717 | 547 |
# If confnode do not have corresponding file/dirs - they will be created on Save |
718 | 548 |
_self.CTNMakeDir() |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
549 |
# Find an IEC number |
417
a895ae50b737
Adding support for declaring PluginRoot outside of Beremiz
laurent
parents:
415
diff
changeset
|
550 |
_self.FindNewIEC_Channel(IEC_Channel) |
717 | 551 |
# Call the confnode real __init__ |
718 | 552 |
if getattr(CTNClass, "__init__", None): |
553 |
CTNClass.__init__(_self) |
|
554 |
_self.CTNRequestSave() |
|
118 | 555 |
#just created, must be saved |
556 |
_self.ChangesToSave = True |
|
403 | 557 |
|
77
7de69369373e
Adding file with generated master in build folder and a button for editing it with objdictedit
lbessard
parents:
75
diff
changeset
|
558 |
def _getBuildPath(_self): |
7de69369373e
Adding file with generated master in build folder and a button for editing it with objdictedit
lbessard
parents:
75
diff
changeset
|
559 |
return self._getBuildPath() |
7de69369373e
Adding file with generated master in build folder and a button for editing it with objdictedit
lbessard
parents:
75
diff
changeset
|
560 |
|
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
561 |
# Create the object out of the resulting class |
718 | 562 |
newConfNodeOpj = FinalCTNClass() |
563 |
# Store it in CTNgedChils |
|
564 |
ChildrenWithSameClass.append(newConfNodeOpj) |
|
717 | 565 |
|
566 |
return newConfNodeOpj |
|
403 | 567 |
|
718 | 568 |
def ClearChildren(self): |
569 |
for child in self.IterChildren(): |
|
570 |
child.ClearChildren() |
|
571 |
self.Children = {} |
|
403 | 572 |
|
718 | 573 |
def LoadXMLParams(self, CTNName = None): |
574 |
methode_name = os.path.join(self.CTNPath(CTNName), "methods.py") |
|
105
434aed8dc58d
Added ability to override plugin methods with arbitrary python code (methods.py) when loading plugins
etisserant
parents:
97
diff
changeset
|
575 |
if os.path.isfile(methode_name): |
434aed8dc58d
Added ability to override plugin methods with arbitrary python code (methods.py) when loading plugins
etisserant
parents:
97
diff
changeset
|
576 |
execfile(methode_name) |
274
8628f3dd0979
Adding support for defining plugin library as a plcopen xml file in plugin folder
greg
parents:
273
diff
changeset
|
577 |
|
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
16
diff
changeset
|
578 |
# Get the base xml tree |
20 | 579 |
if self.MandatoryParams: |
203 | 580 |
try: |
718 | 581 |
basexmlfile = open(self.ConfNodeBaseXmlFilePath(CTNName), 'r') |
106
9810689febb0
Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents:
105
diff
changeset
|
582 |
basetree = minidom.parse(basexmlfile) |
9810689febb0
Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents:
105
diff
changeset
|
583 |
self.MandatoryParams[1].loadXMLTree(basetree.childNodes[0]) |
9810689febb0
Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents:
105
diff
changeset
|
584 |
basexmlfile.close() |
203 | 585 |
except Exception, exc: |
741
382b2c848dac
fixed uncaught exception dialog while displaying cought exception in log
Edouard Tisserant
parents:
738
diff
changeset
|
586 |
self.GetCTRoot().logger.write_error(_("Couldn't load confnode base parameters %s :\n %s") % (CTNName, unicode(exc))) |
718 | 587 |
self.GetCTRoot().logger.write_error(traceback.format_exc()) |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
16
diff
changeset
|
588 |
|
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
589 |
# Get the xml tree |
718 | 590 |
if self.CTNParams: |
203 | 591 |
try: |
718 | 592 |
xmlfile = open(self.ConfNodeXmlFilePath(CTNName), 'r') |
106
9810689febb0
Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents:
105
diff
changeset
|
593 |
tree = minidom.parse(xmlfile) |
718 | 594 |
self.CTNParams[1].loadXMLTree(tree.childNodes[0]) |
106
9810689febb0
Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents:
105
diff
changeset
|
595 |
xmlfile.close() |
203 | 596 |
except Exception, exc: |
741
382b2c848dac
fixed uncaught exception dialog while displaying cought exception in log
Edouard Tisserant
parents:
738
diff
changeset
|
597 |
self.GetCTRoot().logger.write_error(_("Couldn't load confnode parameters %s :\n %s") % (CTNName, unicode(exc))) |
718 | 598 |
self.GetCTRoot().logger.write_error(traceback.format_exc()) |
599 |
||
600 |
def LoadChildren(self): |
|
601 |
# Iterate over all CTNName@CTNType in confnode directory, and try to open them |
|
602 |
for CTNDir in os.listdir(self.CTNPath()): |
|
603 |
if os.path.isdir(os.path.join(self.CTNPath(), CTNDir)) and \ |
|
604 |
CTNDir.count(NameTypeSeparator) == 1: |
|
605 |
pname, ptype = CTNDir.split(NameTypeSeparator) |
|
203 | 606 |
try: |
718 | 607 |
self.CTNAddChild(pname, ptype) |
203 | 608 |
except Exception, exc: |
741
382b2c848dac
fixed uncaught exception dialog while displaying cought exception in log
Edouard Tisserant
parents:
738
diff
changeset
|
609 |
self.GetCTRoot().logger.write_error(_("Could not add child \"%s\", type %s :\n%s\n")%(pname, ptype, unicode(exc))) |
718 | 610 |
self.GetCTRoot().logger.write_error(traceback.format_exc()) |
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
diff
changeset
|
611 |