author | Edouard Tisserant |
Wed, 09 May 2012 00:00:50 +0200 | |
changeset 725 | 31dade089db5 |
parent 722 | ConfigTree.py@a94f361fc42e |
child 728 | e0424e96e3fd |
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 |
725 | 15 |
from util import opjimg, GetClassImporter |
16 |
||
17 |
from PLCControler import PLCControler, LOCATION_CONFNODE |
|
274
8628f3dd0979
Adding support for defining plugin library as a plcopen xml file in plugin folder
greg
parents:
273
diff
changeset
|
18 |
|
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
19 |
_BaseParamsClass = GenerateClassesFromXSDstring("""<?xml version="1.0" encoding="ISO-8859-1" ?> |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
20 |
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
21 |
<xsd:element name="BaseParams"> |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
22 |
<xsd:complexType> |
86 | 23 |
<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
|
24 |
<xsd:attribute name="IEC_Channel" type="xsd:integer" use="required"/> |
86 | 25 |
<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
|
26 |
</xsd:complexType> |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
27 |
</xsd:element> |
86 | 28 |
</xsd:schema>""")["BaseParams"] |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
29 |
|
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
30 |
NameTypeSeparator = '@' |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
31 |
|
717 | 32 |
class ConfigTreeNode: |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
33 |
""" |
717 | 34 |
This class is the one that define confnodes. |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
35 |
""" |
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 |
XSD = None |
718 | 38 |
CTNChildrenTypes = [] |
39 |
CTNMaxCount = None |
|
717 | 40 |
ConfNodeMethods = [] |
274
8628f3dd0979
Adding support for defining plugin library as a plcopen xml file in plugin folder
greg
parents:
273
diff
changeset
|
41 |
LibraryControler = None |
656
c1792dfc8c7e
Fixing bug integrated plugin editors not closed when removing corresponding plugin
laurent
parents:
655
diff
changeset
|
42 |
EditorType = None |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
43 |
|
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
44 |
def _AddParamsMembers(self): |
718 | 45 |
self.CTNParams = None |
29
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
46 |
if self.XSD: |
411
8261c8f1e365
Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents:
403
diff
changeset
|
47 |
self.Classes = GenerateClassesFromXSDstring(self.XSD) |
8261c8f1e365
Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents:
403
diff
changeset
|
48 |
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
|
49 |
if len(Classes) == 1: |
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
50 |
name, XSDclass = Classes[0] |
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
51 |
obj = XSDclass() |
718 | 52 |
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
|
53 |
setattr(self, name, obj) |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
16
diff
changeset
|
54 |
|
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
16
diff
changeset
|
55 |
def __init__(self): |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
56 |
# Create BaseParam |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
57 |
self.BaseParams = _BaseParamsClass() |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
16
diff
changeset
|
58 |
self.MandatoryParams = ("BaseParams", self.BaseParams) |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
59 |
self._AddParamsMembers() |
718 | 60 |
self.Children = {} |
656
c1792dfc8c7e
Fixing bug integrated plugin editors not closed when removing corresponding plugin
laurent
parents:
655
diff
changeset
|
61 |
self._View = None |
717 | 62 |
# copy ConfNodeMethods so that it can be later customized |
63 |
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
|
64 |
self.LoadSTLibrary() |
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 ConfNodeLibraryFilePath(self): |
|
73 |
return os.path.join(self.ConfNodePath(), "pous.xml") |
|
74 |
||
75 |
def ConfNodePath(self): |
|
718 | 76 |
return os.path.join(self.CTNParent.ConfNodePath(), self.CTNType) |
77 |
||
78 |
def CTNPath(self,CTNName=None): |
|
79 |
if not CTNName: |
|
80 |
CTNName = self.CTNName() |
|
81 |
return os.path.join(self.CTNParent.CTNPath(), |
|
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 |
|
652
eb2d9f2b3567
Adding support for loading specific POUs library in LPCBeremiz
laurent
parents:
639
diff
changeset
|
96 |
def GetIconPath(self, name): |
eb2d9f2b3567
Adding support for loading specific POUs library in LPCBeremiz
laurent
parents:
639
diff
changeset
|
97 |
return opjimg(name) |
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 |
||
118 |
def OnCTNSave(self): |
|
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) |
718 | 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) |
718 | 152 |
elif self.CTNParams and parts[0] == self.CTNParams[0]: |
153 |
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
|
154 |
return value, False |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
16
diff
changeset
|
155 |
|
718 | 156 |
def CTNMakeDir(self): |
157 |
os.mkdir(self.CTNPath()) |
|
158 |
||
159 |
def CTNRequestSave(self): |
|
160 |
if self.GetCTRoot().CheckProjectPathPerm(False): |
|
717 | 161 |
# If confnode do not have corresponding directory |
718 | 162 |
ctnpath = self.CTNPath() |
163 |
if not os.path.isdir(ctnpath): |
|
427 | 164 |
# Create it |
718 | 165 |
os.mkdir(ctnpath) |
427 | 166 |
|
717 | 167 |
# generate XML for base XML parameters controller of the confnode |
427 | 168 |
if self.MandatoryParams: |
717 | 169 |
BaseXMLFile = open(self.ConfNodeBaseXmlFilePath(),'w') |
427 | 170 |
BaseXMLFile.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n") |
430 | 171 |
BaseXMLFile.write(self.MandatoryParams[1].generateXMLText(self.MandatoryParams[0], 0).encode("utf-8")) |
427 | 172 |
BaseXMLFile.close() |
173 |
||
717 | 174 |
# generate XML for XML parameters controller of the confnode |
718 | 175 |
if self.CTNParams: |
717 | 176 |
XMLFile = open(self.ConfNodeXmlFilePath(),'w') |
427 | 177 |
XMLFile.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n") |
718 | 178 |
XMLFile.write(self.CTNParams[1].generateXMLText(self.CTNParams[0], 0).encode("utf-8")) |
427 | 179 |
XMLFile.close() |
180 |
||
718 | 181 |
# Call the confnode specific OnCTNSave method |
182 |
result = self.OnCTNSave() |
|
427 | 183 |
if not result: |
718 | 184 |
return _("Error while saving \"%s\"\n")%self.CTNPath() |
427 | 185 |
|
717 | 186 |
# mark confnode as saved |
427 | 187 |
self.ChangesToSave = False |
718 | 188 |
# go through all children and do the same |
189 |
for CTNChild in self.IterChildren(): |
|
190 |
result = CTNChild.CTNRequestSave() |
|
427 | 191 |
if result: |
192 |
return result |
|
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
16
diff
changeset
|
193 |
return None |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
194 |
|
718 | 195 |
def CTNImport(self, src_CTNPath): |
196 |
shutil.copytree(src_CTNPath, self.CTNPath) |
|
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
197 |
return True |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
198 |
|
718 | 199 |
def CTNGenerate_C(self, buildpath, locations): |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
200 |
""" |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
201 |
Generate C code |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
202 |
@param locations: List of complete variables locations \ |
22 | 203 |
[{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...) |
204 |
"NAME" : name of the variable (generally "__IW0_1_2" style) |
|
205 |
"DIR" : direction "Q","I" or "M" |
|
206 |
"SIZE" : size "X", "B", "W", "D", "L" |
|
207 |
"LOC" : tuple of interger for IEC location (0,1,2,...) |
|
208 |
}, ...] |
|
18 | 209 |
@return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND |
210 |
""" |
|
718 | 211 |
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
|
212 |
return [],"",False |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
213 |
|
203 | 214 |
def _Generate_C(self, buildpath, locations): |
717 | 215 |
# Generate confnodes [(Cfiles, CFLAGS)], LDFLAGS, DoCalls, extra_files |
203 | 216 |
# extra_files = [(fname,fobject), ...] |
718 | 217 |
gen_result = self.CTNGenerate_C(buildpath, locations) |
218 |
CTNCFilesAndCFLAGS, CTNLDFLAGS, DoCalls = gen_result[:3] |
|
203 | 219 |
extra_files = gen_result[3:] |
361 | 220 |
# if some files have been generated put them in the list with their location |
718 | 221 |
if CTNCFilesAndCFLAGS: |
222 |
LocationCFilesAndCFLAGS = [(self.GetCurrentLocation(), CTNCFilesAndCFLAGS, DoCalls)] |
|
47
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
223 |
else: |
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
224 |
LocationCFilesAndCFLAGS = [] |
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
225 |
|
717 | 226 |
# confnode asks for some LDFLAGS |
718 | 227 |
if CTNLDFLAGS: |
47
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
228 |
# LDFLAGS can be either string |
718 | 229 |
if type(CTNLDFLAGS)==type(str()): |
230 |
LDFLAGS=[CTNLDFLAGS] |
|
47
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
231 |
#or list of strings |
718 | 232 |
elif type(CTNLDFLAGS)==type(list()): |
233 |
LDFLAGS=CTNLDFLAGS[:] |
|
47
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
234 |
else: |
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
235 |
LDFLAGS=[] |
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
236 |
|
718 | 237 |
# recurse through all children, and stack their results |
238 |
for CTNChild in self.IECSortedChildren(): |
|
239 |
new_location = CTNChild.GetCurrentLocation() |
|
24 | 240 |
# How deep are we in the tree ? |
241 |
depth=len(new_location) |
|
203 | 242 |
_LocationCFilesAndCFLAGS, _LDFLAGS, _extra_files = \ |
718 | 243 |
CTNChild._Generate_C( |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
244 |
#keep the same path |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
245 |
buildpath, |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
246 |
# filter locations that start with current IEC location |
203 | 247 |
[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
|
248 |
# stack the result |
47
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
249 |
LocationCFilesAndCFLAGS += _LocationCFilesAndCFLAGS |
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
250 |
LDFLAGS += _LDFLAGS |
203 | 251 |
extra_files += _extra_files |
252 |
||
253 |
return LocationCFilesAndCFLAGS, LDFLAGS, extra_files |
|
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
254 |
|
717 | 255 |
def ConfNodeTypesFactory(self): |
274
8628f3dd0979
Adding support for defining plugin library as a plcopen xml file in plugin folder
greg
parents:
273
diff
changeset
|
256 |
if self.LibraryControler is not None: |
718 | 257 |
return [{"name" : self.CTNType, "types": self.LibraryControler.Project}] |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
258 |
return [] |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
259 |
|
669
472469f4d5ad
Adding support for loading datatypes defined in plugins to allow to use them in PLC program
laurent
parents:
661
diff
changeset
|
260 |
def ParentsTypesFactory(self): |
718 | 261 |
return self.CTNParent.ParentsTypesFactory() + self.ConfNodeTypesFactory() |
717 | 262 |
|
263 |
def ConfNodesTypesFactory(self): |
|
264 |
list = self.ConfNodeTypesFactory() |
|
718 | 265 |
for CTNChild in self.IterChildren(): |
266 |
list += CTNChild.ConfNodesTypesFactory() |
|
363
e0c4d3549369
Adding support for recursively generate STLibrary and BlockLibrary according to plugin tree
laurent
parents:
361
diff
changeset
|
267 |
return list |
e0c4d3549369
Adding support for recursively generate STLibrary and BlockLibrary according to plugin tree
laurent
parents:
361
diff
changeset
|
268 |
|
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
269 |
def STLibraryFactory(self): |
274
8628f3dd0979
Adding support for defining plugin library as a plcopen xml file in plugin folder
greg
parents:
273
diff
changeset
|
270 |
if self.LibraryControler is not None: |
309
6eb074f0dae9
Adding support for cancelling code generation of function with no input connected
lbessard
parents:
304
diff
changeset
|
271 |
program, errors, warnings = self.LibraryControler.GenerateProgram() |
363
e0c4d3549369
Adding support for recursively generate STLibrary and BlockLibrary according to plugin tree
laurent
parents:
361
diff
changeset
|
272 |
return program + "\n" |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
273 |
return "" |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
274 |
|
717 | 275 |
def ConfNodesSTLibraryFactory(self): |
363
e0c4d3549369
Adding support for recursively generate STLibrary and BlockLibrary according to plugin tree
laurent
parents:
361
diff
changeset
|
276 |
program = self.STLibraryFactory() |
718 | 277 |
for CTNChild in self.IECSortedChildren(): |
278 |
program += CTNChild.ConfNodesSTLibraryFactory() |
|
363
e0c4d3549369
Adding support for recursively generate STLibrary and BlockLibrary according to plugin tree
laurent
parents:
361
diff
changeset
|
279 |
return program |
e0c4d3549369
Adding support for recursively generate STLibrary and BlockLibrary according to plugin tree
laurent
parents:
361
diff
changeset
|
280 |
|
718 | 281 |
def IterChildren(self): |
282 |
for CTNType, Children in self.Children.items(): |
|
283 |
for CTNInstance in Children: |
|
284 |
yield CTNInstance |
|
285 |
||
286 |
def IECSortedChildren(self): |
|
287 |
# reorder children by IEC_channels |
|
288 |
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
|
289 |
if ordered: |
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
290 |
ordered.sort() |
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
291 |
return zip(*ordered)[1] |
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
292 |
else: |
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
293 |
return [] |
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
294 |
|
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
295 |
def _GetChildBySomething(self, something, toks): |
718 | 296 |
for CTNInstance in self.IterChildren(): |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
297 |
# if match component of the name |
718 | 298 |
if getattr(CTNInstance.BaseParams, something) == toks[0]: |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
299 |
# if Name have other components |
47
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
300 |
if len(toks) >= 2: |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
301 |
# Recurse in order to find the latest object |
718 | 302 |
return CTNInstance._GetChildBySomething( something, toks[1:]) |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
303 |
# No sub name -> found |
718 | 304 |
return CTNInstance |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
305 |
# Not found |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
306 |
return None |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
307 |
|
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
308 |
def GetChildByName(self, Name): |
47
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
309 |
if Name: |
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
310 |
toks = Name.split('.') |
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
311 |
return self._GetChildBySomething("Name", toks) |
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
312 |
else: |
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
313 |
return self |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
314 |
|
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
315 |
def GetChildByIECLocation(self, Location): |
47
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
316 |
if Location: |
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
317 |
return self._GetChildBySomething("IEC_Channel", Location) |
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
318 |
else: |
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
319 |
return self |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
320 |
|
23 | 321 |
def GetCurrentLocation(self): |
24 | 322 |
""" |
717 | 323 |
@return: Tupple containing confnode IEC location of current confnode : %I0.0.4.5 => (0,0,4,5) |
24 | 324 |
""" |
718 | 325 |
return self.CTNParent.GetCurrentLocation() + (self.BaseParams.getIEC_Channel(),) |
23 | 326 |
|
47
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
327 |
def GetCurrentName(self): |
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
328 |
""" |
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
329 |
@return: String "ParentParentName.ParentName.Name" |
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
330 |
""" |
718 | 331 |
return self.CTNParent._GetCurrentName() + self.BaseParams.getName() |
47
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
332 |
|
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
333 |
def _GetCurrentName(self): |
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
334 |
""" |
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
335 |
@return: String "ParentParentName.ParentName.Name." |
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
41
diff
changeset
|
336 |
""" |
718 | 337 |
return self.CTNParent._GetCurrentName() + self.BaseParams.getName() + "." |
338 |
||
339 |
def GetCTRoot(self): |
|
340 |
return self.CTNParent.GetCTRoot() |
|
23 | 341 |
|
97 | 342 |
def GetFullIEC_Channel(self): |
343 |
return ".".join([str(i) for i in self.GetCurrentLocation()]) + ".x" |
|
344 |
||
345 |
def GetLocations(self): |
|
346 |
location = self.GetCurrentLocation() |
|
718 | 347 |
return [loc for loc in self.CTNParent.GetLocations() if loc["LOC"][0:len(location)] == location] |
97 | 348 |
|
401
8106a853a7c7
Adding support for displaying plugins available variable into Beremiz plugin tree
laurent
parents:
396
diff
changeset
|
349 |
def GetVariableLocationTree(self): |
8106a853a7c7
Adding support for displaying plugins available variable into Beremiz plugin tree
laurent
parents:
396
diff
changeset
|
350 |
''' |
717 | 351 |
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
|
352 |
|
8106a853a7c7
Adding support for displaying plugins available variable into Beremiz plugin tree
laurent
parents:
396
diff
changeset
|
353 |
It should returns an list of dictionaries |
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 |
- 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
|
356 |
- 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
|
357 |
''' |
8106a853a7c7
Adding support for displaying plugins available variable into Beremiz plugin tree
laurent
parents:
396
diff
changeset
|
358 |
children = [] |
718 | 359 |
for child in self.IECSortedChildren(): |
402
984e238e63d0
Bugs on displaying plugin available variables in PluginTree fixed
laurent
parents:
401
diff
changeset
|
360 |
children.append(child.GetVariableLocationTree()) |
984e238e63d0
Bugs on displaying plugin available variables in PluginTree fixed
laurent
parents:
401
diff
changeset
|
361 |
return {"name": self.BaseParams.getName(), |
717 | 362 |
"type": LOCATION_CONFNODE, |
402
984e238e63d0
Bugs on displaying plugin available variables in PluginTree fixed
laurent
parents:
401
diff
changeset
|
363 |
"location": self.GetFullIEC_Channel(), |
984e238e63d0
Bugs on displaying plugin available variables in PluginTree fixed
laurent
parents:
401
diff
changeset
|
364 |
"children": children} |
401
8106a853a7c7
Adding support for displaying plugins available variable into Beremiz plugin tree
laurent
parents:
396
diff
changeset
|
365 |
|
203 | 366 |
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
|
367 |
""" |
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
368 |
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
|
369 |
@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
|
370 |
""" |
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
371 |
# Get Current Name |
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
372 |
CurrentName = self.BaseParams.getName() |
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
373 |
# 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
|
374 |
#if CurrentName == DesiredName: return CurrentName |
718 | 375 |
# 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
|
376 |
AllNames=[] |
718 | 377 |
for CTNInstance in self.CTNParent.IterChildren(): |
378 |
if CTNInstance != self: |
|
379 |
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
|
380 |
|
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
381 |
# 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
|
382 |
res = DesiredName |
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
383 |
suffix = 1 |
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
384 |
while res in AllNames: |
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
385 |
res = "%s-%d"%(DesiredName, suffix) |
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
386 |
suffix += 1 |
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
387 |
|
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
388 |
# Get old path |
718 | 389 |
oldname = self.CTNPath() |
717 | 390 |
# 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
|
391 |
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
|
392 |
# Set the new name |
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
393 |
self.BaseParams.setName(res) |
717 | 394 |
# 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
|
395 |
if not dontexist: |
718 | 396 |
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
|
397 |
# 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
|
398 |
if DesiredName != res: |
718 | 399 |
self.GetCTRoot().logger.write_warning(_("A child names \"%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
|
400 |
return res |
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
401 |
|
683
57aa9da845d5
Fix wrong panel size making strange background in topology plugin element
laurent
parents:
677
diff
changeset
|
402 |
def GetAllChannels(self): |
57aa9da845d5
Fix wrong panel size making strange background in topology plugin element
laurent
parents:
677
diff
changeset
|
403 |
AllChannels=[] |
718 | 404 |
for CTNInstance in self.CTNParent.IterChildren(): |
405 |
if CTNInstance != self: |
|
406 |
AllChannels.append(CTNInstance.BaseParams.getIEC_Channel()) |
|
683
57aa9da845d5
Fix wrong panel size making strange background in topology plugin element
laurent
parents:
677
diff
changeset
|
407 |
AllChannels.sort() |
57aa9da845d5
Fix wrong panel size making strange background in topology plugin element
laurent
parents:
677
diff
changeset
|
408 |
return AllChannels |
57aa9da845d5
Fix wrong panel size making strange background in topology plugin element
laurent
parents:
677
diff
changeset
|
409 |
|
203 | 410 |
def FindNewIEC_Channel(self, DesiredChannel): |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
411 |
""" |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
412 |
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
|
413 |
@param DesiredChannel: The desired IEC channel (int) |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
414 |
""" |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
415 |
# Get Current IEC channel |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
416 |
CurrentChannel = self.BaseParams.getIEC_Channel() |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
417 |
# 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
|
418 |
#if CurrentChannel == DesiredChannel: return CurrentChannel |
718 | 419 |
# 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
|
420 |
AllChannels = self.GetAllChannels() |
57aa9da845d5
Fix wrong panel size making strange background in topology plugin element
laurent
parents:
677
diff
changeset
|
421 |
|
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
422 |
# Now, try to guess the nearest available channel |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
423 |
res = DesiredChannel |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
424 |
while res in AllChannels: # While channel not free |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
425 |
if res < CurrentChannel: # Want to go down ? |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
426 |
res -= 1 # Test for n-1 |
33
59b84ab7bf8b
Enhanced bahavior of plugin tree representation when changing IEC channel
etisserant
parents:
29
diff
changeset
|
427 |
if res < 0 : |
718 | 428 |
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
|
429 |
return CurrentChannel # Can't go bellow 0, do nothing |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
430 |
else : # Want to go up ? |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
431 |
res += 1 # Test for n-1 |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
432 |
# Finally set IEC Channel |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
433 |
self.BaseParams.setIEC_Channel(res) |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
434 |
return res |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
435 |
|
716
180e4a7d945c
Adding search field for finding function or function block in library tree
laurent
parents:
715
diff
changeset
|
436 |
def _OpenView(self, name=None): |
656
c1792dfc8c7e
Fixing bug integrated plugin editors not closed when removing corresponding plugin
laurent
parents:
655
diff
changeset
|
437 |
if self.EditorType is not None and self._View is None: |
718 | 438 |
app_frame = self.GetCTRoot().AppFrame |
656
c1792dfc8c7e
Fixing bug integrated plugin editors not closed when removing corresponding plugin
laurent
parents:
655
diff
changeset
|
439 |
|
c1792dfc8c7e
Fixing bug integrated plugin editors not closed when removing corresponding plugin
laurent
parents:
655
diff
changeset
|
440 |
self._View = self.EditorType(app_frame.TabsOpened, self, app_frame) |
c1792dfc8c7e
Fixing bug integrated plugin editors not closed when removing corresponding plugin
laurent
parents:
655
diff
changeset
|
441 |
|
718 | 442 |
app_frame.EditProjectElement(self._View, self.CTNName()) |
715
135566ab0807
Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents:
707
diff
changeset
|
443 |
|
135566ab0807
Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents:
707
diff
changeset
|
444 |
return self._View |
135566ab0807
Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents:
707
diff
changeset
|
445 |
return None |
675
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
674
diff
changeset
|
446 |
|
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
674
diff
changeset
|
447 |
def OnCloseEditor(self, view): |
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
674
diff
changeset
|
448 |
if self._View == view: |
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
674
diff
changeset
|
449 |
self._View = None |
656
c1792dfc8c7e
Fixing bug integrated plugin editors not closed when removing corresponding plugin
laurent
parents:
655
diff
changeset
|
450 |
|
718 | 451 |
def OnCTNClose(self): |
656
c1792dfc8c7e
Fixing bug integrated plugin editors not closed when removing corresponding plugin
laurent
parents:
655
diff
changeset
|
452 |
if self._View is not None: |
718 | 453 |
app_frame = self.GetCTRoot().AppFrame |
656
c1792dfc8c7e
Fixing bug integrated plugin editors not closed when removing corresponding plugin
laurent
parents:
655
diff
changeset
|
454 |
if app_frame is not None: |
c1792dfc8c7e
Fixing bug integrated plugin editors not closed when removing corresponding plugin
laurent
parents:
655
diff
changeset
|
455 |
app_frame.DeletePage(self._View) |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
456 |
return True |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
457 |
|
718 | 458 |
def _doRemoveChild(self, CTNInstance): |
459 |
# Remove all children of child |
|
460 |
for SubCTNInstance in CTNInstance.IterChildren(): |
|
461 |
CTNInstance._doRemoveChild(SubCTNInstance) |
|
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
462 |
# Call the OnCloseMethod |
718 | 463 |
CTNInstance.OnCTNClose() |
717 | 464 |
# Delete confnode dir |
718 | 465 |
shutil.rmtree(CTNInstance.CTNPath()) |
466 |
# Remove child of Children |
|
467 |
self.Children[CTNInstance.CTNType].remove(CTNInstance) |
|
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
468 |
# Forget it... (View have to refresh) |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
469 |
|
718 | 470 |
def CTNRemove(self): |
717 | 471 |
# Fetch the confnode |
718 | 472 |
#CTNInstance = self.GetChildByName(CTNName) |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
473 |
# Ask to his parent to remove it |
718 | 474 |
self.CTNParent._doRemoveChild(self) |
475 |
||
476 |
def CTNAddChild(self, CTNName, CTNType, IEC_Channel=0): |
|
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
477 |
""" |
717 | 478 |
Create the confnodes that may be added as child to this node self |
718 | 479 |
@param CTNType: string desining the confnode class name (get name from CTNChildrenTypes) |
480 |
@param CTNName: string for the name of the confnode instance |
|
481 |
""" |
|
720 | 482 |
# reorganize self.CTNChildrenTypes tuples from (name, CTNClass, Help) |
718 | 483 |
# to ( name, (CTNClass, Help)), an make a dict |
484 |
transpose = zip(*self.CTNChildrenTypes) |
|
485 |
CTNChildrenTypes = dict(zip(transpose[0],zip(transpose[1],transpose[2]))) |
|
717 | 486 |
# Check that adding this confnode is allowed |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
487 |
try: |
718 | 488 |
CTNClass, CTNHelp = CTNChildrenTypes[CTNType] |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
489 |
except KeyError: |
718 | 490 |
raise Exception, _("Cannot create child %s of type %s ")%(CTNName, CTNType) |
491 |
||
492 |
# if CTNClass is a class factory, call it. (prevent unneeded imports) |
|
493 |
if type(CTNClass) == types.FunctionType: |
|
494 |
CTNClass = CTNClass() |
|
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
495 |
|
717 | 496 |
# Eventualy Initialize child instance list for this class of confnode |
718 | 497 |
ChildrenWithSameClass = self.Children.setdefault(CTNType, list()) |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
498 |
# Check count |
718 | 499 |
if getattr(CTNClass, "CTNMaxCount", None) and len(ChildrenWithSameClass) >= CTNClass.CTNMaxCount: |
500 |
raise Exception, _("Max count (%d) reached for this confnode of type %s ")%(CTNClass.CTNMaxCount, CTNType) |
|
717 | 501 |
|
502 |
# create the final class, derived of provided confnode and template |
|
718 | 503 |
class FinalCTNClass(CTNClass, ConfigTreeNode): |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
504 |
""" |
718 | 505 |
ConfNode class is derivated into FinalCTNClass before being instanciated |
717 | 506 |
This way __init__ is overloaded to ensure ConfigTreeNode.__init__ is called |
718 | 507 |
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
|
508 |
""" |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
509 |
def __init__(_self): |
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
510 |
# self is the parent |
718 | 511 |
_self.CTNParent = self |
717 | 512 |
# Keep track of the confnode type name |
718 | 513 |
_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
|
514 |
# remind the help string, for more fancy display |
718 | 515 |
_self.CTNHelp = CTNHelp |
717 | 516 |
# Call the base confnode template init - change XSD into class members |
517 |
ConfigTreeNode.__init__(_self) |
|
29
282380dea497
Major improvements, plugin renaming and secured name/IEC channel attribution, various fixes on PlugTemplate
etisserant
parents:
25
diff
changeset
|
518 |
# check name is unique |
718 | 519 |
NewCTNName = _self.FindNewName(CTNName) |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
520 |
# If dir have already be made, and file exist |
718 | 521 |
if os.path.isdir(_self.CTNPath(NewCTNName)): #and os.path.isfile(_self.ConfNodeXmlFilePath(CTNName)): |
717 | 522 |
#Load the confnode.xml file into parameters members |
718 | 523 |
_self.LoadXMLParams(NewCTNName) |
20 | 524 |
# Basic check. Better to fail immediately. |
718 | 525 |
if (_self.BaseParams.getName() != NewCTNName): |
526 |
raise Exception, _("Project tree layout do not match confnode.xml %s!=%s ")%(NewCTNName, _self.BaseParams.getName()) |
|
527 |
||
528 |
# Now, self.CTNPath() should be OK |
|
20 | 529 |
|
15
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
14
diff
changeset
|
530 |
# Check that IEC_Channel is not already in use. |
203 | 531 |
_self.FindNewIEC_Channel(_self.BaseParams.getIEC_Channel()) |
717 | 532 |
# Call the confnode real __init__ |
718 | 533 |
if getattr(CTNClass, "__init__", None): |
534 |
CTNClass.__init__(_self) |
|
535 |
#Load and init all the children |
|
536 |
_self.LoadChildren() |
|
118 | 537 |
#just loaded, nothing to saved |
538 |
_self.ChangesToSave = False |
|
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
539 |
else: |
717 | 540 |
# If confnode do not have corresponding file/dirs - they will be created on Save |
718 | 541 |
_self.CTNMakeDir() |
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
542 |
# Find an IEC number |
417
a895ae50b737
Adding support for declaring PluginRoot outside of Beremiz
laurent
parents:
415
diff
changeset
|
543 |
_self.FindNewIEC_Channel(IEC_Channel) |
717 | 544 |
# Call the confnode real __init__ |
718 | 545 |
if getattr(CTNClass, "__init__", None): |
546 |
CTNClass.__init__(_self) |
|
547 |
_self.CTNRequestSave() |
|
118 | 548 |
#just created, must be saved |
549 |
_self.ChangesToSave = True |
|
403 | 550 |
|
77
7de69369373e
Adding file with generated master in build folder and a button for editing it with objdictedit
lbessard
parents:
75
diff
changeset
|
551 |
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
|
552 |
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
|
553 |
|
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
554 |
# Create the object out of the resulting class |
718 | 555 |
newConfNodeOpj = FinalCTNClass() |
556 |
# Store it in CTNgedChils |
|
557 |
ChildrenWithSameClass.append(newConfNodeOpj) |
|
717 | 558 |
|
559 |
return newConfNodeOpj |
|
403 | 560 |
|
718 | 561 |
def ClearChildren(self): |
562 |
for child in self.IterChildren(): |
|
563 |
child.ClearChildren() |
|
564 |
self.Children = {} |
|
403 | 565 |
|
325
f2604900bf25
Bug preventing loading STLibrary when adding a plugin fixed
lbessard
parents:
321
diff
changeset
|
566 |
def LoadSTLibrary(self): |
f2604900bf25
Bug preventing loading STLibrary when adding a plugin fixed
lbessard
parents:
321
diff
changeset
|
567 |
# Get library blocks if plcopen library exist |
717 | 568 |
library_path = self.ConfNodeLibraryFilePath() |
325
f2604900bf25
Bug preventing loading STLibrary when adding a plugin fixed
lbessard
parents:
321
diff
changeset
|
569 |
if os.path.isfile(library_path): |
f2604900bf25
Bug preventing loading STLibrary when adding a plugin fixed
lbessard
parents:
321
diff
changeset
|
570 |
self.LibraryControler = PLCControler() |
f2604900bf25
Bug preventing loading STLibrary when adding a plugin fixed
lbessard
parents:
321
diff
changeset
|
571 |
self.LibraryControler.OpenXMLFile(library_path) |
717 | 572 |
self.LibraryControler.ClearConfNodeTypes() |
573 |
self.LibraryControler.AddConfNodeTypesList(self.ParentsTypesFactory()) |
|
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
574 |
|
718 | 575 |
def LoadXMLParams(self, CTNName = None): |
576 |
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
|
577 |
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
|
578 |
execfile(methode_name) |
274
8628f3dd0979
Adding support for defining plugin library as a plcopen xml file in plugin folder
greg
parents:
273
diff
changeset
|
579 |
|
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
16
diff
changeset
|
580 |
# Get the base xml tree |
20 | 581 |
if self.MandatoryParams: |
203 | 582 |
try: |
718 | 583 |
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
|
584 |
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
|
585 |
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
|
586 |
basexmlfile.close() |
203 | 587 |
except Exception, exc: |
718 | 588 |
self.GetCTRoot().logger.write_error(_("Couldn't load confnode base parameters %s :\n %s") % (CTNName, str(exc))) |
589 |
self.GetCTRoot().logger.write_error(traceback.format_exc()) |
|
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
16
diff
changeset
|
590 |
|
14
eb9fdd316a40
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
591 |
# Get the xml tree |
718 | 592 |
if self.CTNParams: |
203 | 593 |
try: |
718 | 594 |
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
|
595 |
tree = minidom.parse(xmlfile) |
718 | 596 |
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
|
597 |
xmlfile.close() |
203 | 598 |
except Exception, exc: |
718 | 599 |
self.GetCTRoot().logger.write_error(_("Couldn't load confnode parameters %s :\n %s") % (CTNName, str(exc))) |
600 |
self.GetCTRoot().logger.write_error(traceback.format_exc()) |
|
601 |
||
602 |
def LoadChildren(self): |
|
603 |
# Iterate over all CTNName@CTNType in confnode directory, and try to open them |
|
604 |
for CTNDir in os.listdir(self.CTNPath()): |
|
605 |
if os.path.isdir(os.path.join(self.CTNPath(), CTNDir)) and \ |
|
606 |
CTNDir.count(NameTypeSeparator) == 1: |
|
607 |
pname, ptype = CTNDir.split(NameTypeSeparator) |
|
203 | 608 |
try: |
718 | 609 |
self.CTNAddChild(pname, ptype) |
203 | 610 |
except Exception, exc: |
718 | 611 |
self.GetCTRoot().logger.write_error(_("Could not add child \"%s\", type %s :\n%s\n")%(pname, ptype, str(exc))) |
612 |
self.GetCTRoot().logger.write_error(traceback.format_exc()) |
|
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
diff
changeset
|
613 |
|
109
f27ca37b6e7a
Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents:
108
diff
changeset
|
614 |
def EnableMethod(self, method, value): |
717 | 615 |
for d in self.ConfNodeMethods: |
109
f27ca37b6e7a
Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents:
108
diff
changeset
|
616 |
if d["method"]==method: |
f27ca37b6e7a
Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents:
108
diff
changeset
|
617 |
d["enabled"]=value |
f27ca37b6e7a
Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents:
108
diff
changeset
|
618 |
return True |
f27ca37b6e7a
Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents:
108
diff
changeset
|
619 |
return False |
f27ca37b6e7a
Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents:
108
diff
changeset
|
620 |
|
203 | 621 |
def ShowMethod(self, method, value): |
717 | 622 |
for d in self.ConfNodeMethods: |
203 | 623 |
if d["method"]==method: |
624 |
d["shown"]=value |
|
625 |
return True |
|
626 |
return False |
|
627 |
||
623
8cdb533c3c7a
A few new keyboard shortcuts : F4=stop, F5=run, F5=transfer, F7=connect
Edouard Tisserant
parents:
619
diff
changeset
|
628 |
def CallMethod(self, method): |
717 | 629 |
for d in self.ConfNodeMethods: |
623
8cdb533c3c7a
A few new keyboard shortcuts : F4=stop, F5=run, F5=transfer, F7=connect
Edouard Tisserant
parents:
619
diff
changeset
|
630 |
if d["method"]==method and d.get("enabled", True) and d.get("shown", True): |
8cdb533c3c7a
A few new keyboard shortcuts : F4=stop, F5=run, F5=transfer, F7=connect
Edouard Tisserant
parents:
619
diff
changeset
|
631 |
getattr(self, method)() |
8cdb533c3c7a
A few new keyboard shortcuts : F4=stop, F5=run, F5=transfer, F7=connect
Edouard Tisserant
parents:
619
diff
changeset
|
632 |