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