author | lbessard |
Tue, 04 Sep 2007 17:16:42 +0200 | |
changeset 19 | 73257cea38bd |
parent 18 | 0fac6d621a24 |
child 20 | d3cb5020997b |
permissions | -rw-r--r-- |
12 | 1 |
import os |
11 | 2 |
from nodelist import NodeList |
3 |
from nodemanager import NodeManager |
|
4 |
import config_utils, gen_cfile |
|
12 | 5 |
from networkedit import networkedit |
11 | 6 |
|
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
7 |
class _NetworkEdit(networkedit): |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
8 |
" Overload some of CanFestival Network Editor methods " |
12 | 9 |
def OnCloseFrame(self, event): |
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
10 |
" Do reset _NodeListPlug.View when closed" |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
11 |
self._onclose() |
12 | 12 |
event.Skip() |
13 |
||
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
14 |
class _NodeListPlug(NodeList): |
12 | 15 |
XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?> |
16 |
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> |
|
17 |
<xsd:element name="CanFestivalNode"> |
|
18 |
<xsd:complexType> |
|
19 |
<xsd:attribute name="CAN_Device" type="xsd:string" use="required" /> |
|
20 |
</xsd:complexType> |
|
21 |
</xsd:element> |
|
22 |
</xsd:schema> |
|
23 |
""" |
|
24 |
||
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
15
diff
changeset
|
25 |
def __init__(self): |
11 | 26 |
manager = NodeManager() |
27 |
NodeList.__init__(self, manager) |
|
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
15
diff
changeset
|
28 |
self.LoadProject(self.PlugPath()) |
11 | 29 |
|
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
30 |
_View = None |
18 | 31 |
def _OpenView(self, logger): |
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
32 |
if not self._View: |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
33 |
def _onclose(): |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
34 |
self.View = None |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
35 |
self._View = _NetworkEdit() |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
36 |
self._View._onclose = _onclose |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
37 |
return self.View |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
38 |
PluginMethods = [("NetworkEdit",_OpenView)] |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
39 |
|
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
40 |
def OnPlugClose(self): |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
41 |
if self._View: |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
42 |
self._View.Close() |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
43 |
|
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
44 |
def PlugTestModified(self): |
12 | 45 |
return self.HasChanged() |
46 |
||
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
15
diff
changeset
|
47 |
def OnPlugSave(self): |
11 | 48 |
self.SaveProject() |
12 | 49 |
return True |
50 |
||
18 | 51 |
def PlugGenerate_C(self, buildpath, current_location, locations, logger): |
12 | 52 |
""" |
15
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
53 |
Generate C code |
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
54 |
@param current_location: Tupple containing plugin IEC location : %I0.0.4.5 => (0,0,4,5) |
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
55 |
@param locations: List of complete variables locations \ |
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
56 |
[(IEC_loc, IEC_Direction IEC_Type, Name)]\ |
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
57 |
ex: [((0,0,4,5),'I','X','__IX_0_0_4_5'),...] |
12 | 58 |
""" |
15
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
59 |
prefix = "_".join(map(lambda x:str(x), current_location)) |
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
60 |
Gen_OD_path = os.path.join(buildpath, prefix + "_OD.c" ) |
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
61 |
master = config_utils.GenerateConciseDCF(locations, current_location, self) |
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
62 |
res = gen_cfile.GenerateFile(Gen_OD_path, master) |
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
63 |
if res : |
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
64 |
raise Exception, res |
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
65 |
|
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
66 |
return [(Gen_OD_path,CanFestival_OD_CFLAGS)],"" |
12 | 67 |
|
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
68 |
class RootClass: |
12 | 69 |
XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?> |
70 |
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> |
|
71 |
<xsd:element name="CanFestivalInstance"> |
|
72 |
<xsd:complexType> |
|
73 |
<xsd:attribute name="CAN_Driver" type="xsd:string" use="required" /> |
|
74 |
</xsd:complexType> |
|
75 |
</xsd:element> |
|
76 |
</xsd:schema> |
|
77 |
""" |
|
11 | 78 |
|
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
79 |
PlugChildsTypes = [("CanOpenNode",_NodeListPlug)] |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
15
diff
changeset
|
80 |
|
15
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
81 |
def PlugGenerate_C(self, buildpath, current_location, locations): |
11 | 82 |
""" |
15
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
83 |
Generate C code |
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
84 |
@param current_location: Tupple containing plugin IEC location : %I0.0.4.5 => (0,0,4,5) |
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
85 |
@param locations: List of complete variables locations \ |
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
86 |
[(IEC_loc, IEC_Direction IEC_Type, Name)]\ |
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
87 |
ex: [((0,0,4,5),'I','X','__IX_0_0_4_5'),...] |
11 | 88 |
""" |
15
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
89 |
prefix = "_".join(map(lambda x:str(x), current_location)) |
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
90 |
Gen_OD_path = os.path.join(buildpath, prefix + "_OD.c" ) |
11 | 91 |
master = config_utils.GenerateConciseDCF(locations, self) |
15
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
92 |
res = gen_cfile.GenerateFile(Gen_OD_path, master) |
11 | 93 |
if not res: |
12 | 94 |
s = str(self.BaseParams.BusId)+"_IN(){}\n" |
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
95 |
s += "CanOpen(str(\""+self.CanFestivalNode.CAN_Device+"\")" |
11 | 96 |
f = file(filepath, 'a') |
97 |
f.write(s) |
|
98 |
else: |
|
99 |
pass # error |
|
15
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
100 |
|
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
101 |
return [],"" |
11 | 102 |
|
15
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
103 |