equal
deleted
inserted
replaced
13 import wx |
13 import wx |
14 |
14 |
15 import util.paths as paths |
15 import util.paths as paths |
16 from POULibrary import POULibrary |
16 from POULibrary import POULibrary |
17 from docutil import open_svg |
17 from docutil import open_svg |
|
18 from lxml import etree |
18 |
19 |
19 HMI_TYPES_DESC = { |
20 HMI_TYPES_DESC = { |
20 "HMI_CLASS":{}, |
21 "HMI_CLASS":{}, |
21 "HMI_LABEL":{}, |
22 "HMI_LABEL":{}, |
22 "HMI_STRING":{}, |
23 "HMI_STRING":{}, |
23 "HMI_INT":{}, |
24 "HMI_INT":{}, |
24 "HMI_REAL":{} |
25 "HMI_REAL":{} |
25 } |
26 } |
26 |
27 |
27 HMI_TYPES = HMI_TYPES_DESC.keys() |
28 HMI_TYPES = HMI_TYPES_DESC.keys() |
|
29 |
|
30 from XSLTransform import XSLTransform |
|
31 |
|
32 ScriptDirectory = paths.AbsDir(__file__) |
28 |
33 |
29 class SVGHMILibrary(POULibrary): |
34 class SVGHMILibrary(POULibrary): |
30 def GetLibraryPath(self): |
35 def GetLibraryPath(self): |
31 return paths.AbsNeighbourFile(__file__, "pous.xml") |
36 return paths.AbsNeighbourFile(__file__, "pous.xml") |
32 |
37 |
40 # TODO generate C code to observe/access HMI tree variables |
45 # TODO generate C code to observe/access HMI tree variables |
41 svghmi_c_filepath = paths.AbsNeighbourFile(__file__, "svghmi.c") |
46 svghmi_c_filepath = paths.AbsNeighbourFile(__file__, "svghmi.c") |
42 svghmi_c_file = open(svghmi_c_filepath, 'r') |
47 svghmi_c_file = open(svghmi_c_filepath, 'r') |
43 svghmi_c_code = svghmi_c_file.read() |
48 svghmi_c_code = svghmi_c_file.read() |
44 svghmi_c_file.close() |
49 svghmi_c_file.close() |
45 svghmi_c_code = svghmi_c_code % { "the code": "/* TODO */"} |
50 svghmi_c_code = svghmi_c_code % { "hmi_tree": "TODO !!!"} |
46 |
51 |
47 gen_svghmi_c_path = os.path.join(buildpath, "svghmi.c") |
52 gen_svghmi_c_path = os.path.join(buildpath, "svghmi.c") |
48 gen_svghmi_c = open(gen_svghmi_c_path, 'w') |
53 gen_svghmi_c = open(gen_svghmi_c_path, 'w') |
49 gen_svghmi_c.write(svghmi_c_code) |
54 gen_svghmi_c.write(svghmi_c_code) |
50 gen_svghmi_c.close() |
55 gen_svghmi_c.close() |
90 if from_project_path is not None: |
95 if from_project_path is not None: |
91 shutil.copyfile(self._getSVGpath(from_project_path), |
96 shutil.copyfile(self._getSVGpath(from_project_path), |
92 self._getSVGpath()) |
97 self._getSVGpath()) |
93 return True |
98 return True |
94 |
99 |
|
100 def GetSVGGeometry(self): |
|
101 # TODO : invoke inskscape -S, csv-parse output, produce elements |
|
102 return [etree.Element("bbox", id="blah0", x="1", y="2", w="3", h="4"), |
|
103 etree.Element("bbox", id="blah1", x="5", y="6", w="7", h="8")] |
|
104 |
95 def CTNGenerate_C(self, buildpath, locations): |
105 def CTNGenerate_C(self, buildpath, locations): |
96 """ |
106 """ |
97 Return C code generated by iec2c compiler |
107 Return C code generated by iec2c compiler |
98 when _generate_softPLC have been called |
108 when _generate_softPLC have been called |
99 @param locations: ignored |
109 @param locations: ignored |
102 |
112 |
103 # TODO fetch HMI tree from library |
113 # TODO fetch HMI tree from library |
104 |
114 |
105 svgfile = self._getSVGpath() |
115 svgfile = self._getSVGpath() |
106 if os.path.exists(svgfile): |
116 if os.path.exists(svgfile): |
107 # TODO : call xslt transform on Inkscape's SVG to generate |
117 |
|
118 # TODO : move to __init__ |
|
119 transform = XSLTransform(os.path.join(ScriptDirectory, "gen_index_xhtml.xslt"), |
|
120 [("GetSVGGeometry", lambda *_ignored:self.GetSVGGeometry())]) |
|
121 |
|
122 |
|
123 # load svg as a DOM with Etree |
|
124 svgdom = etree.parse(svgfile) |
|
125 |
|
126 # call xslt transform on Inkscape's SVG to generate XHTML |
|
127 result = transform.transform(svgdom) |
|
128 |
|
129 print(str(result)) |
|
130 print(transform.xslt.error_log) |
|
131 |
|
132 # TODO |
108 # - Errors on HMI semantics |
133 # - Errors on HMI semantics |
109 # - Target XHTML as a DOM |
|
110 # - ... maybe something to have a global view of what is declared in SVG. |
134 # - ... maybe something to have a global view of what is declared in SVG. |
111 pass |
135 |
112 else: |
136 else: |
113 # TODO : use default svg that expose the HMI tree as-is |
137 # TODO : use default svg that expose the HMI tree as-is |
114 pass |
138 pass |
115 |
139 |
116 |
140 |