author | lbessard |
Mon, 17 Sep 2007 10:12:35 +0200 | |
changeset 41 | 1608a434fb8c |
parent 32 | 4bdc888e634b |
child 47 | fd45c291fed0 |
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" /> |
|
26 | 23 |
<xsd:attribute name="Sync_TPDOs" type="xsd:boolean" use="required" default="true"/> |
12 | 24 |
</xsd:complexType> |
25 |
</xsd:element> |
|
26 |
</xsd:schema> |
|
27 |
""" |
|
28 |
||
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
15
diff
changeset
|
29 |
def __init__(self): |
11 | 30 |
manager = NodeManager() |
23 | 31 |
# TODO change netname when name change |
32 |
NodeList.__init__(self, manager, self.BaseParams.getName()) |
|
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
15
diff
changeset
|
33 |
self.LoadProject(self.PlugPath()) |
11 | 34 |
|
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
35 |
_View = None |
18 | 36 |
def _OpenView(self, logger): |
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
37 |
if not self._View: |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
38 |
def _onclose(): |
30 | 39 |
self._View = None |
25
fa7503684c28
Adding support for using Networkedit et PLCOpenEditor in Beremiz
lbessard
parents:
24
diff
changeset
|
40 |
def _onsave(): |
fa7503684c28
Adding support for using Networkedit et PLCOpenEditor in Beremiz
lbessard
parents:
24
diff
changeset
|
41 |
self.GetPlugRoot().SaveProject() |
23 | 42 |
self._View = _NetworkEdit(self.GetPlugRoot().AppFrame, self) |
43 |
# TODO redefine BusId when IEC channel change |
|
44 |
self._View.SetBusId(self.GetCurrentLocation()) |
|
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
45 |
self._View._onclose = _onclose |
25
fa7503684c28
Adding support for using Networkedit et PLCOpenEditor in Beremiz
lbessard
parents:
24
diff
changeset
|
46 |
self._View._onsave = _onsave |
23 | 47 |
self._View.Show() |
48 |
||
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
49 |
PluginMethods = [("NetworkEdit",_OpenView)] |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
50 |
|
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
51 |
def OnPlugClose(self): |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
52 |
if self._View: |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
53 |
self._View.Close() |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
54 |
|
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
55 |
def PlugTestModified(self): |
12 | 56 |
return self.HasChanged() |
57 |
||
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
15
diff
changeset
|
58 |
def OnPlugSave(self): |
32 | 59 |
self.SetRoot(self.PlugPath()) |
11 | 60 |
self.SaveProject() |
12 | 61 |
return True |
62 |
||
24 | 63 |
def PlugGenerate_C(self, buildpath, locations, logger): |
12 | 64 |
""" |
15
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
65 |
Generate C code |
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
66 |
@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
|
67 |
@param locations: List of complete variables locations \ |
22 | 68 |
[{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...) |
69 |
"NAME" : name of the variable (generally "__IW0_1_2" style) |
|
70 |
"DIR" : direction "Q","I" or "M" |
|
71 |
"SIZE" : size "X", "B", "W", "D", "L" |
|
72 |
"LOC" : tuple of interger for IEC location (0,1,2,...) |
|
73 |
}, ...] |
|
74 |
@return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND |
|
12 | 75 |
""" |
24 | 76 |
current_location = self.GetCurrentLocation() |
22 | 77 |
# define a unique name for the generated C file |
15
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
78 |
prefix = "_".join(map(lambda x:str(x), current_location)) |
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
79 |
Gen_OD_path = os.path.join(buildpath, prefix + "_OD.c" ) |
22 | 80 |
# Create a new copy of the model with DCF loaded with PDO mappings for desired location |
26 | 81 |
master = config_utils.GenerateConciseDCF(locations, current_location, self, self.CanFestivalNode.getSync_TPDOs()) |
15
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
82 |
res = gen_cfile.GenerateFile(Gen_OD_path, master) |
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
83 |
if res : |
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
84 |
raise Exception, res |
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
85 |
|
24 | 86 |
return [(Gen_OD_path,"")],"" |
12 | 87 |
|
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
88 |
class RootClass: |
12 | 89 |
XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?> |
90 |
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> |
|
91 |
<xsd:element name="CanFestivalInstance"> |
|
92 |
<xsd:complexType> |
|
93 |
<xsd:attribute name="CAN_Driver" type="xsd:string" use="required" /> |
|
94 |
</xsd:complexType> |
|
95 |
</xsd:element> |
|
96 |
</xsd:schema> |
|
97 |
""" |
|
11 | 98 |
|
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
99 |
PlugChildsTypes = [("CanOpenNode",_NodeListPlug)] |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
15
diff
changeset
|
100 |
|
24 | 101 |
def PlugGenerate_C(self, buildpath, locations, logger): |
15
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
102 |
return [],"" |
11 | 103 |
|
15
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
104 |