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