author | Edouard Tisserant <edouard.tisserant@gmail.com> |
Sun, 10 May 2020 17:01:09 +0200 | |
branch | svghmi |
changeset 2954 | b5dccd0d99ac |
parent 2945 | 69f395c01c09 |
child 2965 | 8f928cee01e5 |
permissions | -rw-r--r-- |
2745 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
4 |
# This file is part of Beremiz |
|
5 |
# Copyright (C) 2019: Edouard TISSERANT |
|
6 |
# |
|
7 |
# See COPYING file for copyrights details. |
|
8 |
||
9 |
from __future__ import absolute_import |
|
10 |
import os |
|
11 |
import shutil |
|
2763
ce04d79b8e57
Pass HMITree to SVG transform. It seems it could really help to reduce JS tree binding logic in the end.
Edouard Tisserant
parents:
2762
diff
changeset
|
12 |
from itertools import izip, imap |
2822
9101a72a1da0
SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents:
2818
diff
changeset
|
13 |
from pprint import pformat |
2789 | 14 |
import hashlib |
2816 | 15 |
import weakref |
2823
d631f8671c75
SVGHMI : add on Start, Stop and Watchdog command fields to configuration
Edouard Tisserant
parents:
2822
diff
changeset
|
16 |
import shlex |
2745 | 17 |
|
18 |
import wx |
|
2816 | 19 |
import wx.dataview as dv |
20 |
||
21 |
from lxml import etree |
|
22 |
from lxml.etree import XSLTApplyError |
|
2745 | 23 |
|
24 |
import util.paths as paths |
|
25 |
from POULibrary import POULibrary |
|
2756
f94bc35a023e
SVGHMI: added extraction of SVG bounding boxes, obtained from "inkscape -S", and passed to XSLT transform as variable.
Edouard Tisserant
parents:
2753
diff
changeset
|
26 |
from docutil import open_svg, get_inkscape_path |
2745 | 27 |
|
2756
f94bc35a023e
SVGHMI: added extraction of SVG bounding boxes, obtained from "inkscape -S", and passed to XSLT transform as variable.
Edouard Tisserant
parents:
2753
diff
changeset
|
28 |
from util.ProcessLogger import ProcessLogger |
2764
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
29 |
from runtime.typemapping import DebugTypesSize |
2767
302347f48193
svghmi.c : deduplicated variable access code borrowed from plc_debug.c. Added targets/var_access.c.
Edouard Tisserant
parents:
2765
diff
changeset
|
30 |
import targets |
2816 | 31 |
from editors.ConfTreeNodeEditor import ConfTreeNodeEditor |
32 |
from XSLTransform import XSLTransform |
|
2756
f94bc35a023e
SVGHMI: added extraction of SVG bounding boxes, obtained from "inkscape -S", and passed to XSLT transform as variable.
Edouard Tisserant
parents:
2753
diff
changeset
|
33 |
|
2749
2769b3aed34d
Use a POU Library's Generate_C to collect all variables in SVGHMI.
Edouard Tisserant
parents:
2747
diff
changeset
|
34 |
HMI_TYPES_DESC = { |
2814
2cabc4773885
SVGHMI: HMI_LABEL and HMI_CLASS become HMI_NODE.
Edouard Tisserant
parents:
2812
diff
changeset
|
35 |
"HMI_NODE":{}, |
2749
2769b3aed34d
Use a POU Library's Generate_C to collect all variables in SVGHMI.
Edouard Tisserant
parents:
2747
diff
changeset
|
36 |
"HMI_STRING":{}, |
2769b3aed34d
Use a POU Library's Generate_C to collect all variables in SVGHMI.
Edouard Tisserant
parents:
2747
diff
changeset
|
37 |
"HMI_INT":{}, |
2826
1e5abecc3cde
SVGHMI : support for HMI_STRING and HMI_BOOL
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2824
diff
changeset
|
38 |
"HMI_BOOL":{} |
2749
2769b3aed34d
Use a POU Library's Generate_C to collect all variables in SVGHMI.
Edouard Tisserant
parents:
2747
diff
changeset
|
39 |
} |
2769b3aed34d
Use a POU Library's Generate_C to collect all variables in SVGHMI.
Edouard Tisserant
parents:
2747
diff
changeset
|
40 |
|
2769b3aed34d
Use a POU Library's Generate_C to collect all variables in SVGHMI.
Edouard Tisserant
parents:
2747
diff
changeset
|
41 |
HMI_TYPES = HMI_TYPES_DESC.keys() |
2745 | 42 |
|
2753
9a7e12e96399
SVGHMI: Added XSLT transformation, Makefile to get XSLT from ysl2 (copy of plcopen/Makefile) and a minimal stylesheet to start with.
Edouard Tisserant
parents:
2750
diff
changeset
|
43 |
|
9a7e12e96399
SVGHMI: Added XSLT transformation, Makefile to get XSLT from ysl2 (copy of plcopen/Makefile) and a minimal stylesheet to start with.
Edouard Tisserant
parents:
2750
diff
changeset
|
44 |
ScriptDirectory = paths.AbsDir(__file__) |
9a7e12e96399
SVGHMI: Added XSLT transformation, Makefile to get XSLT from ysl2 (copy of plcopen/Makefile) and a minimal stylesheet to start with.
Edouard Tisserant
parents:
2750
diff
changeset
|
45 |
|
2757
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
46 |
class HMITreeNode(object): |
2822
9101a72a1da0
SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents:
2818
diff
changeset
|
47 |
def __init__(self, path, name, nodetype, iectype = None, vartype = None, cpath = None, hmiclass = None): |
2757
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
48 |
self.path = path |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
49 |
self.name = name |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
50 |
self.nodetype = nodetype |
2814
2cabc4773885
SVGHMI: HMI_LABEL and HMI_CLASS become HMI_NODE.
Edouard Tisserant
parents:
2812
diff
changeset
|
51 |
self.hmiclass = hmiclass |
2764
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
52 |
|
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
53 |
if iectype is not None: |
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
54 |
self.iectype = iectype |
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
55 |
self.vartype = vartype |
2822
9101a72a1da0
SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents:
2818
diff
changeset
|
56 |
self.cpath = cpath |
9101a72a1da0
SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents:
2818
diff
changeset
|
57 |
|
2890
ae8063127e95
SVGHMI: make root HMI tree node a HMI_NODE, droped HMI_ROOT node type
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2866
diff
changeset
|
58 |
if nodetype in ["HMI_NODE"]: |
2757
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
59 |
self.children = [] |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
60 |
|
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
61 |
def pprint(self, indent = 0): |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
62 |
res = ">"*indent + pformat(self.__dict__, indent = indent, depth = 1) + "\n" |
2817
45bbfb2e120f
Non significant changes, whitespaces, etc.
Edouard Tisserant
parents:
2816
diff
changeset
|
63 |
if hasattr(self, "children"): |
2757
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
64 |
res += "\n".join([child.pprint(indent = indent + 1) |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
65 |
for child in self.children]) |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
66 |
res += "\n" |
2817
45bbfb2e120f
Non significant changes, whitespaces, etc.
Edouard Tisserant
parents:
2816
diff
changeset
|
67 |
|
2757
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
68 |
return res |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
69 |
|
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
70 |
def place_node(self, node): |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
71 |
best_child = None |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
72 |
known_best_match = 0 |
2817
45bbfb2e120f
Non significant changes, whitespaces, etc.
Edouard Tisserant
parents:
2816
diff
changeset
|
73 |
for child in self.children: |
2762
282500e03dbc
Add special nodes at HMI Tree root, fix code to handle special node (no path).
Edouard Tisserant
parents:
2758
diff
changeset
|
74 |
if child.path is not None: |
282500e03dbc
Add special nodes at HMI Tree root, fix code to handle special node (no path).
Edouard Tisserant
parents:
2758
diff
changeset
|
75 |
in_common = 0 |
282500e03dbc
Add special nodes at HMI Tree root, fix code to handle special node (no path).
Edouard Tisserant
parents:
2758
diff
changeset
|
76 |
for child_path_item, node_path_item in izip(child.path, node.path): |
282500e03dbc
Add special nodes at HMI Tree root, fix code to handle special node (no path).
Edouard Tisserant
parents:
2758
diff
changeset
|
77 |
if child_path_item == node_path_item: |
282500e03dbc
Add special nodes at HMI Tree root, fix code to handle special node (no path).
Edouard Tisserant
parents:
2758
diff
changeset
|
78 |
in_common +=1 |
282500e03dbc
Add special nodes at HMI Tree root, fix code to handle special node (no path).
Edouard Tisserant
parents:
2758
diff
changeset
|
79 |
else: |
282500e03dbc
Add special nodes at HMI Tree root, fix code to handle special node (no path).
Edouard Tisserant
parents:
2758
diff
changeset
|
80 |
break |
2945
69f395c01c09
SVGHMI: Fix flawed logic to place nodes in the HMI tree, leading to wrecked tree in some cases.
Edouard Tisserant
parents:
2890
diff
changeset
|
81 |
# Match can only be HMI_NODE, and the whole path of node |
69f395c01c09
SVGHMI: Fix flawed logic to place nodes in the HMI tree, leading to wrecked tree in some cases.
Edouard Tisserant
parents:
2890
diff
changeset
|
82 |
# must match candidate node (except for name part) |
69f395c01c09
SVGHMI: Fix flawed logic to place nodes in the HMI tree, leading to wrecked tree in some cases.
Edouard Tisserant
parents:
2890
diff
changeset
|
83 |
# since candidate would become child of that node |
69f395c01c09
SVGHMI: Fix flawed logic to place nodes in the HMI tree, leading to wrecked tree in some cases.
Edouard Tisserant
parents:
2890
diff
changeset
|
84 |
if in_common > known_best_match and \ |
69f395c01c09
SVGHMI: Fix flawed logic to place nodes in the HMI tree, leading to wrecked tree in some cases.
Edouard Tisserant
parents:
2890
diff
changeset
|
85 |
child.nodetype == "HMI_NODE" and \ |
69f395c01c09
SVGHMI: Fix flawed logic to place nodes in the HMI tree, leading to wrecked tree in some cases.
Edouard Tisserant
parents:
2890
diff
changeset
|
86 |
in_common == len(child.path) - 1: |
2762
282500e03dbc
Add special nodes at HMI Tree root, fix code to handle special node (no path).
Edouard Tisserant
parents:
2758
diff
changeset
|
87 |
known_best_match = in_common |
282500e03dbc
Add special nodes at HMI Tree root, fix code to handle special node (no path).
Edouard Tisserant
parents:
2758
diff
changeset
|
88 |
best_child = child |
2945
69f395c01c09
SVGHMI: Fix flawed logic to place nodes in the HMI tree, leading to wrecked tree in some cases.
Edouard Tisserant
parents:
2890
diff
changeset
|
89 |
if best_child is not None: |
2757
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
90 |
best_child.place_node(node) |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
91 |
else: |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
92 |
self.children.append(node) |
2817
45bbfb2e120f
Non significant changes, whitespaces, etc.
Edouard Tisserant
parents:
2816
diff
changeset
|
93 |
|
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2781
diff
changeset
|
94 |
def etree(self, add_hash=False): |
2763
ce04d79b8e57
Pass HMITree to SVG transform. It seems it could really help to reduce JS tree binding logic in the end.
Edouard Tisserant
parents:
2762
diff
changeset
|
95 |
|
ce04d79b8e57
Pass HMITree to SVG transform. It seems it could really help to reduce JS tree binding logic in the end.
Edouard Tisserant
parents:
2762
diff
changeset
|
96 |
attribs = dict(name=self.name) |
ce04d79b8e57
Pass HMITree to SVG transform. It seems it could really help to reduce JS tree binding logic in the end.
Edouard Tisserant
parents:
2762
diff
changeset
|
97 |
if self.path is not None: |
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2781
diff
changeset
|
98 |
attribs["path"] = ".".join(self.path) |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2781
diff
changeset
|
99 |
|
2815
77b2a3757e66
SVGHMI: add a class attribute to HMI Tree nodes, set when using HMI_NODE
Edouard Tisserant
parents:
2814
diff
changeset
|
100 |
if self.hmiclass is not None: |
77b2a3757e66
SVGHMI: add a class attribute to HMI Tree nodes, set when using HMI_NODE
Edouard Tisserant
parents:
2814
diff
changeset
|
101 |
attribs["class"] = self.hmiclass |
77b2a3757e66
SVGHMI: add a class attribute to HMI Tree nodes, set when using HMI_NODE
Edouard Tisserant
parents:
2814
diff
changeset
|
102 |
|
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2781
diff
changeset
|
103 |
if add_hash: |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2781
diff
changeset
|
104 |
attribs["hash"] = ",".join(map(str,self.hash())) |
2763
ce04d79b8e57
Pass HMITree to SVG transform. It seems it could really help to reduce JS tree binding logic in the end.
Edouard Tisserant
parents:
2762
diff
changeset
|
105 |
|
ce04d79b8e57
Pass HMITree to SVG transform. It seems it could really help to reduce JS tree binding logic in the end.
Edouard Tisserant
parents:
2762
diff
changeset
|
106 |
res = etree.Element(self.nodetype, **attribs) |
ce04d79b8e57
Pass HMITree to SVG transform. It seems it could really help to reduce JS tree binding logic in the end.
Edouard Tisserant
parents:
2762
diff
changeset
|
107 |
|
2817
45bbfb2e120f
Non significant changes, whitespaces, etc.
Edouard Tisserant
parents:
2816
diff
changeset
|
108 |
if hasattr(self, "children"): |
2763
ce04d79b8e57
Pass HMITree to SVG transform. It seems it could really help to reduce JS tree binding logic in the end.
Edouard Tisserant
parents:
2762
diff
changeset
|
109 |
for child_etree in imap(lambda c:c.etree(), self.children): |
ce04d79b8e57
Pass HMITree to SVG transform. It seems it could really help to reduce JS tree binding logic in the end.
Edouard Tisserant
parents:
2762
diff
changeset
|
110 |
res.append(child_etree) |
ce04d79b8e57
Pass HMITree to SVG transform. It seems it could really help to reduce JS tree binding logic in the end.
Edouard Tisserant
parents:
2762
diff
changeset
|
111 |
|
ce04d79b8e57
Pass HMITree to SVG transform. It seems it could really help to reduce JS tree binding logic in the end.
Edouard Tisserant
parents:
2762
diff
changeset
|
112 |
return res |
ce04d79b8e57
Pass HMITree to SVG transform. It seems it could really help to reduce JS tree binding logic in the end.
Edouard Tisserant
parents:
2762
diff
changeset
|
113 |
|
2764
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
114 |
def traverse(self): |
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
115 |
yield self |
2817
45bbfb2e120f
Non significant changes, whitespaces, etc.
Edouard Tisserant
parents:
2816
diff
changeset
|
116 |
if hasattr(self, "children"): |
2764
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
117 |
for c in self.children: |
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
118 |
for yoodl in c.traverse(): |
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
119 |
yield yoodl |
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
120 |
|
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2781
diff
changeset
|
121 |
|
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2781
diff
changeset
|
122 |
def hash(self): |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2781
diff
changeset
|
123 |
""" Produce a hash, any change in HMI tree structure change that hash """ |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2781
diff
changeset
|
124 |
s = hashlib.new('md5') |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2781
diff
changeset
|
125 |
self._hash(s) |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2781
diff
changeset
|
126 |
# limit size to HMI_HASH_SIZE as in svghmi.c |
2817
45bbfb2e120f
Non significant changes, whitespaces, etc.
Edouard Tisserant
parents:
2816
diff
changeset
|
127 |
return map(ord,s.digest())[:8] |
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2781
diff
changeset
|
128 |
|
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2781
diff
changeset
|
129 |
def _hash(self, s): |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2781
diff
changeset
|
130 |
s.update(str((self.name,self.nodetype))) |
2817
45bbfb2e120f
Non significant changes, whitespaces, etc.
Edouard Tisserant
parents:
2816
diff
changeset
|
131 |
if hasattr(self, "children"): |
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2781
diff
changeset
|
132 |
for c in self.children: |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2781
diff
changeset
|
133 |
c._hash(s) |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2781
diff
changeset
|
134 |
|
2763
ce04d79b8e57
Pass HMITree to SVG transform. It seems it could really help to reduce JS tree binding logic in the end.
Edouard Tisserant
parents:
2762
diff
changeset
|
135 |
# module scope for HMITree root |
ce04d79b8e57
Pass HMITree to SVG transform. It seems it could really help to reduce JS tree binding logic in the end.
Edouard Tisserant
parents:
2762
diff
changeset
|
136 |
# so that CTN can use HMITree deduced in Library |
2817
45bbfb2e120f
Non significant changes, whitespaces, etc.
Edouard Tisserant
parents:
2816
diff
changeset
|
137 |
# note: this only works because library's Generate_C is |
2763
ce04d79b8e57
Pass HMITree to SVG transform. It seems it could really help to reduce JS tree binding logic in the end.
Edouard Tisserant
parents:
2762
diff
changeset
|
138 |
# systematicaly invoked before CTN's CTNGenerate_C |
ce04d79b8e57
Pass HMITree to SVG transform. It seems it could really help to reduce JS tree binding logic in the end.
Edouard Tisserant
parents:
2762
diff
changeset
|
139 |
|
ce04d79b8e57
Pass HMITree to SVG transform. It seems it could really help to reduce JS tree binding logic in the end.
Edouard Tisserant
parents:
2762
diff
changeset
|
140 |
hmi_tree_root = None |
2757
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
141 |
|
2817
45bbfb2e120f
Non significant changes, whitespaces, etc.
Edouard Tisserant
parents:
2816
diff
changeset
|
142 |
on_hmitree_update = None |
2816 | 143 |
|
2890
ae8063127e95
SVGHMI: make root HMI tree node a HMI_NODE, droped HMI_ROOT node type
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2866
diff
changeset
|
144 |
SPECIAL_NODES = [("HMI_ROOT", "HMI_NODE"), |
ae8063127e95
SVGHMI: make root HMI tree node a HMI_NODE, droped HMI_ROOT node type
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2866
diff
changeset
|
145 |
("heartbeat", "HMI_INT")] |
2822
9101a72a1da0
SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents:
2818
diff
changeset
|
146 |
# ("current_page", "HMI_STRING")]) |
9101a72a1da0
SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents:
2818
diff
changeset
|
147 |
|
2745 | 148 |
class SVGHMILibrary(POULibrary): |
149 |
def GetLibraryPath(self): |
|
2750 | 150 |
return paths.AbsNeighbourFile(__file__, "pous.xml") |
2745 | 151 |
|
2749
2769b3aed34d
Use a POU Library's Generate_C to collect all variables in SVGHMI.
Edouard Tisserant
parents:
2747
diff
changeset
|
152 |
def Generate_C(self, buildpath, varlist, IECCFLAGS): |
2822
9101a72a1da0
SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents:
2818
diff
changeset
|
153 |
global hmi_tree_root, on_hmitree_update |
2749
2769b3aed34d
Use a POU Library's Generate_C to collect all variables in SVGHMI.
Edouard Tisserant
parents:
2747
diff
changeset
|
154 |
|
2757
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
155 |
""" |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
156 |
PLC Instance Tree: |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
157 |
prog0 |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
158 |
+->v1 HMI_INT |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
159 |
+->v2 HMI_INT |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
160 |
+->fb0 (type mhoo) |
2814
2cabc4773885
SVGHMI: HMI_LABEL and HMI_CLASS become HMI_NODE.
Edouard Tisserant
parents:
2812
diff
changeset
|
161 |
| +->va HMI_NODE |
2757
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
162 |
| +->v3 HMI_INT |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
163 |
| +->v4 HMI_INT |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
164 |
| |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
165 |
+->fb1 (type mhoo) |
2814
2cabc4773885
SVGHMI: HMI_LABEL and HMI_CLASS become HMI_NODE.
Edouard Tisserant
parents:
2812
diff
changeset
|
166 |
| +->va HMI_NODE |
2757
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
167 |
| +->v3 HMI_INT |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
168 |
| +->v4 HMI_INT |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
169 |
| |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
170 |
+->fb2 |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
171 |
+->v5 HMI_IN |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
172 |
|
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
173 |
HMI tree: |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
174 |
hmi0 |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
175 |
+->v1 |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
176 |
+->v2 |
2814
2cabc4773885
SVGHMI: HMI_LABEL and HMI_CLASS become HMI_NODE.
Edouard Tisserant
parents:
2812
diff
changeset
|
177 |
+->fb0 class:va |
2757
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
178 |
| +-> v3 |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
179 |
| +-> v4 |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
180 |
| |
2814
2cabc4773885
SVGHMI: HMI_LABEL and HMI_CLASS become HMI_NODE.
Edouard Tisserant
parents:
2812
diff
changeset
|
181 |
+->fb1 class:va |
2757
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
182 |
| +-> v3 |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
183 |
| +-> v4 |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
184 |
| |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
185 |
+->v5 |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
186 |
|
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
187 |
""" |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
188 |
|
2749
2769b3aed34d
Use a POU Library's Generate_C to collect all variables in SVGHMI.
Edouard Tisserant
parents:
2747
diff
changeset
|
189 |
# Filter known HMI types |
2769b3aed34d
Use a POU Library's Generate_C to collect all variables in SVGHMI.
Edouard Tisserant
parents:
2747
diff
changeset
|
190 |
hmi_types_instances = [v for v in varlist if v["derived"] in HMI_TYPES] |
2758
5f79b194fa63
SVGHMI: filter out temporary variables created while generating ST code out of FBD.
Edouard Tisserant
parents:
2757
diff
changeset
|
191 |
|
2890
ae8063127e95
SVGHMI: make root HMI tree node a HMI_NODE, droped HMI_ROOT node type
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2866
diff
changeset
|
192 |
hmi_tree_root = None |
ae8063127e95
SVGHMI: make root HMI tree node a HMI_NODE, droped HMI_ROOT node type
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2866
diff
changeset
|
193 |
|
ae8063127e95
SVGHMI: make root HMI tree node a HMI_NODE, droped HMI_ROOT node type
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2866
diff
changeset
|
194 |
# take first HMI_NODE (placed as special node), make it root |
ae8063127e95
SVGHMI: make root HMI tree node a HMI_NODE, droped HMI_ROOT node type
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2866
diff
changeset
|
195 |
for i,v in enumerate(hmi_types_instances): |
ae8063127e95
SVGHMI: make root HMI tree node a HMI_NODE, droped HMI_ROOT node type
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2866
diff
changeset
|
196 |
path = v["IEC_path"].split(".") |
ae8063127e95
SVGHMI: make root HMI tree node a HMI_NODE, droped HMI_ROOT node type
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2866
diff
changeset
|
197 |
derived = v["derived"] |
ae8063127e95
SVGHMI: make root HMI tree node a HMI_NODE, droped HMI_ROOT node type
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2866
diff
changeset
|
198 |
if derived == "HMI_NODE" and ['CONFIG', 'HEARTBEAT'] : |
ae8063127e95
SVGHMI: make root HMI tree node a HMI_NODE, droped HMI_ROOT node type
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2866
diff
changeset
|
199 |
hmi_tree_root = HMITreeNode(path, "", derived, v["type"], v["vartype"], v["C_path"]) |
ae8063127e95
SVGHMI: make root HMI tree node a HMI_NODE, droped HMI_ROOT node type
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2866
diff
changeset
|
200 |
hmi_types_instances.pop(i) |
ae8063127e95
SVGHMI: make root HMI tree node a HMI_NODE, droped HMI_ROOT node type
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2866
diff
changeset
|
201 |
break |
ae8063127e95
SVGHMI: make root HMI tree node a HMI_NODE, droped HMI_ROOT node type
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2866
diff
changeset
|
202 |
|
ae8063127e95
SVGHMI: make root HMI tree node a HMI_NODE, droped HMI_ROOT node type
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2866
diff
changeset
|
203 |
assert(hmi_tree_root is not None) |
2757
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
204 |
|
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
205 |
# deduce HMI tree from PLC HMI_* instances |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
206 |
for v in hmi_types_instances: |
2822
9101a72a1da0
SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents:
2818
diff
changeset
|
207 |
path = v["IEC_path"].split(".") |
2758
5f79b194fa63
SVGHMI: filter out temporary variables created while generating ST code out of FBD.
Edouard Tisserant
parents:
2757
diff
changeset
|
208 |
# ignores variables starting with _TMP_ |
5f79b194fa63
SVGHMI: filter out temporary variables created while generating ST code out of FBD.
Edouard Tisserant
parents:
2757
diff
changeset
|
209 |
if path[-1].startswith("_TMP_"): |
5f79b194fa63
SVGHMI: filter out temporary variables created while generating ST code out of FBD.
Edouard Tisserant
parents:
2757
diff
changeset
|
210 |
continue |
2814
2cabc4773885
SVGHMI: HMI_LABEL and HMI_CLASS become HMI_NODE.
Edouard Tisserant
parents:
2812
diff
changeset
|
211 |
derived = v["derived"] |
2cabc4773885
SVGHMI: HMI_LABEL and HMI_CLASS become HMI_NODE.
Edouard Tisserant
parents:
2812
diff
changeset
|
212 |
kwargs={} |
2cabc4773885
SVGHMI: HMI_LABEL and HMI_CLASS become HMI_NODE.
Edouard Tisserant
parents:
2812
diff
changeset
|
213 |
if derived == "HMI_NODE": |
2822
9101a72a1da0
SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents:
2818
diff
changeset
|
214 |
# TODO : make problem if HMI_NODE used in CONFIG or RESOURCE |
2814
2cabc4773885
SVGHMI: HMI_LABEL and HMI_CLASS become HMI_NODE.
Edouard Tisserant
parents:
2812
diff
changeset
|
215 |
name = path[-2] |
2cabc4773885
SVGHMI: HMI_LABEL and HMI_CLASS become HMI_NODE.
Edouard Tisserant
parents:
2812
diff
changeset
|
216 |
kwargs['hmiclass'] = path[-1] |
2cabc4773885
SVGHMI: HMI_LABEL and HMI_CLASS become HMI_NODE.
Edouard Tisserant
parents:
2812
diff
changeset
|
217 |
else: |
2cabc4773885
SVGHMI: HMI_LABEL and HMI_CLASS become HMI_NODE.
Edouard Tisserant
parents:
2812
diff
changeset
|
218 |
name = path[-1] |
2822
9101a72a1da0
SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents:
2818
diff
changeset
|
219 |
new_node = HMITreeNode(path, name, derived, v["type"], v["vartype"], v["C_path"], **kwargs) |
2757
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
220 |
hmi_tree_root.place_node(new_node) |
c901baa36bb3
SVGHMI: added deduction of HMI tree from list of HMI_* instances.
Edouard Tisserant
parents:
2756
diff
changeset
|
221 |
|
2817
45bbfb2e120f
Non significant changes, whitespaces, etc.
Edouard Tisserant
parents:
2816
diff
changeset
|
222 |
if on_hmitree_update is not None: |
45bbfb2e120f
Non significant changes, whitespaces, etc.
Edouard Tisserant
parents:
2816
diff
changeset
|
223 |
on_hmitree_update() |
2816 | 224 |
|
2764
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
225 |
variable_decl_array = [] |
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
226 |
extern_variables_declarations = [] |
2765
887aba5ef178
SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents:
2764
diff
changeset
|
227 |
buf_index = 0 |
2775
3b93409ba22c
SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents:
2772
diff
changeset
|
228 |
item_count = 0 |
2822
9101a72a1da0
SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents:
2818
diff
changeset
|
229 |
found_heartbeat = False |
9101a72a1da0
SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents:
2818
diff
changeset
|
230 |
|
9101a72a1da0
SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents:
2818
diff
changeset
|
231 |
hearbeat_IEC_path = ['CONFIG', 'HEARTBEAT'] |
2828 | 232 |
|
2764
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
233 |
for node in hmi_tree_root.traverse(): |
2828 | 234 |
if not found_heartbeat and node.path == hearbeat_IEC_path: |
2822
9101a72a1da0
SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents:
2818
diff
changeset
|
235 |
hmi_tree_hearbeat_index = item_count |
9101a72a1da0
SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents:
2818
diff
changeset
|
236 |
found_heartbeat = True |
9101a72a1da0
SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents:
2818
diff
changeset
|
237 |
extern_variables_declarations += [ |
9101a72a1da0
SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents:
2818
diff
changeset
|
238 |
"#define heartbeat_index "+str(hmi_tree_hearbeat_index) |
9101a72a1da0
SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents:
2818
diff
changeset
|
239 |
] |
2866
59a855c17aa6
SVGHMI: Stop ignoring HMI_NODE in HMI tree, and count it as a BOOL. Soon we use those nodes as reference for relative page jump, and as an "enable" bit for features associated to an HMI tree fragment.
Edouard Tisserant
parents:
2834
diff
changeset
|
240 |
if hasattr(node, "iectype"): |
2764
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
241 |
sz = DebugTypesSize.get(node.iectype, 0) |
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
242 |
variable_decl_array += [ |
2822
9101a72a1da0
SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents:
2818
diff
changeset
|
243 |
"{&(" + node.cpath + "), " + node.iectype + { |
2764
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
244 |
"EXT": "_P_ENUM", |
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
245 |
"IN": "_P_ENUM", |
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
246 |
"MEM": "_O_ENUM", |
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
247 |
"OUT": "_O_ENUM", |
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
248 |
"VAR": "_ENUM" |
2765
887aba5ef178
SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents:
2764
diff
changeset
|
249 |
}[node.vartype] + ", " + |
2768
31785529a657
SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents:
2767
diff
changeset
|
250 |
str(buf_index) + ", 0, }"] |
2765
887aba5ef178
SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents:
2764
diff
changeset
|
251 |
buf_index += sz |
2775
3b93409ba22c
SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents:
2772
diff
changeset
|
252 |
item_count += 1 |
2764
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
253 |
if len(node.path) == 1: |
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
254 |
extern_variables_declarations += [ |
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
255 |
"extern __IEC_" + node.iectype + "_" + |
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
256 |
"t" if node.vartype is "VAR" else "p" |
2822
9101a72a1da0
SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents:
2818
diff
changeset
|
257 |
+ node.cpath + ";"] |
2828 | 258 |
|
2822
9101a72a1da0
SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents:
2818
diff
changeset
|
259 |
assert(found_heartbeat) |
2764
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
260 |
|
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
261 |
# TODO : filter only requiered external declarations |
2828 | 262 |
for v in varlist: |
263 |
if v["C_path"].find('.') < 0: |
|
2764
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
264 |
extern_variables_declarations += [ |
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
265 |
"extern %(type)s %(C_path)s;" % v] |
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
266 |
|
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
267 |
# TODO check if programs need to be declared separately |
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
268 |
# "programs_declarations": "\n".join(["extern %(type)s %(C_path)s;" % |
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
269 |
# p for p in self._ProgramList]), |
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
270 |
|
2771
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
271 |
# C code to observe/access HMI tree variables |
2749
2769b3aed34d
Use a POU Library's Generate_C to collect all variables in SVGHMI.
Edouard Tisserant
parents:
2747
diff
changeset
|
272 |
svghmi_c_filepath = paths.AbsNeighbourFile(__file__, "svghmi.c") |
2769b3aed34d
Use a POU Library's Generate_C to collect all variables in SVGHMI.
Edouard Tisserant
parents:
2747
diff
changeset
|
273 |
svghmi_c_file = open(svghmi_c_filepath, 'r') |
2769b3aed34d
Use a POU Library's Generate_C to collect all variables in SVGHMI.
Edouard Tisserant
parents:
2747
diff
changeset
|
274 |
svghmi_c_code = svghmi_c_file.read() |
2769b3aed34d
Use a POU Library's Generate_C to collect all variables in SVGHMI.
Edouard Tisserant
parents:
2747
diff
changeset
|
275 |
svghmi_c_file.close() |
2817
45bbfb2e120f
Non significant changes, whitespaces, etc.
Edouard Tisserant
parents:
2816
diff
changeset
|
276 |
svghmi_c_code = svghmi_c_code % { |
2764
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
277 |
"variable_decl_array": ",\n".join(variable_decl_array), |
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
278 |
"extern_variables_declarations": "\n".join(extern_variables_declarations), |
2767
302347f48193
svghmi.c : deduplicated variable access code borrowed from plc_debug.c. Added targets/var_access.c.
Edouard Tisserant
parents:
2765
diff
changeset
|
279 |
"buffer_size": buf_index, |
2775
3b93409ba22c
SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents:
2772
diff
changeset
|
280 |
"item_count": item_count, |
2768
31785529a657
SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents:
2767
diff
changeset
|
281 |
"var_access_code": targets.GetCode("var_access.c"), |
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2781
diff
changeset
|
282 |
"PLC_ticktime": self.GetCTR().GetTicktime(), |
2789 | 283 |
"hmi_hash_ints": ",".join(map(str,hmi_tree_root.hash())) |
2764
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
284 |
} |
2749
2769b3aed34d
Use a POU Library's Generate_C to collect all variables in SVGHMI.
Edouard Tisserant
parents:
2747
diff
changeset
|
285 |
|
2769b3aed34d
Use a POU Library's Generate_C to collect all variables in SVGHMI.
Edouard Tisserant
parents:
2747
diff
changeset
|
286 |
gen_svghmi_c_path = os.path.join(buildpath, "svghmi.c") |
2769b3aed34d
Use a POU Library's Generate_C to collect all variables in SVGHMI.
Edouard Tisserant
parents:
2747
diff
changeset
|
287 |
gen_svghmi_c = open(gen_svghmi_c_path, 'w') |
2769b3aed34d
Use a POU Library's Generate_C to collect all variables in SVGHMI.
Edouard Tisserant
parents:
2747
diff
changeset
|
288 |
gen_svghmi_c.write(svghmi_c_code) |
2769b3aed34d
Use a POU Library's Generate_C to collect all variables in SVGHMI.
Edouard Tisserant
parents:
2747
diff
changeset
|
289 |
gen_svghmi_c.close() |
2769b3aed34d
Use a POU Library's Generate_C to collect all variables in SVGHMI.
Edouard Tisserant
parents:
2747
diff
changeset
|
290 |
|
2771
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
291 |
# Python based WebSocket HMITree Server |
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
292 |
svghmiserverfile = open(paths.AbsNeighbourFile(__file__, "svghmi_server.py"), 'r') |
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
293 |
svghmiservercode = svghmiserverfile.read() |
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
294 |
svghmiserverfile.close() |
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
295 |
|
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
296 |
runtimefile_path = os.path.join(buildpath, "runtime_svghmi.py") |
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
297 |
runtimefile = open(runtimefile_path, 'w') |
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
298 |
runtimefile.write(svghmiservercode) |
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
299 |
runtimefile.close() |
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
300 |
|
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
301 |
return ((["svghmi"], [(gen_svghmi_c_path, IECCFLAGS)], True), "", |
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
302 |
("runtime_svghmi0.py", open(runtimefile_path, "rb"))) |
2745 | 303 |
|
2816 | 304 |
|
2818
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
305 |
class HMITreeSelector(wx.TreeCtrl): |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
306 |
def __init__(self, parent): |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
307 |
global on_hmitree_update |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
308 |
wx.TreeCtrl.__init__(self,parent,style=wx.TR_MULTIPLE)# | wx.TR_HIDE_ROOT) |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
309 |
|
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
310 |
isz = (16,16) |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
311 |
self.il = il = wx.ImageList(*isz) |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
312 |
self.fldridx = il.AddIcon(wx.ArtProvider.GetIcon(wx.ART_FOLDER, wx.ART_OTHER, isz)) |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
313 |
self.fldropenidx = il.AddIcon(wx.ArtProvider.GetIcon(wx.ART_FOLDER_OPEN, wx.ART_OTHER, isz)) |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
314 |
self.fileidx = il.AddIcon(wx.ArtProvider.GetIcon(wx.ART_NORMAL_FILE, wx.ART_OTHER, isz)) |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
315 |
self.SetImageList(il) |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
316 |
|
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
317 |
on_hmitree_update = self.SVGHMIEditorUpdater() |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
318 |
self.MakeTree() |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
319 |
|
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
320 |
def _recurseTree(self, current_hmitree_root, current_tc_root): |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
321 |
for c in current_hmitree_root.children: |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
322 |
if hasattr(c, "children"): |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
323 |
display_name = ('{} (class={})'.format(c.name, c.hmiclass)) \ |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
324 |
if c.hmiclass is not None else c.name |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
325 |
tc_child = self.AppendItem(current_tc_root, display_name) |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
326 |
self.SetPyData(tc_child, None) |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
327 |
self.SetItemImage(tc_child, self.fldridx, wx.TreeItemIcon_Normal) |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
328 |
self.SetItemImage(tc_child, self.fldropenidx, wx.TreeItemIcon_Expanded) |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
329 |
|
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
330 |
self._recurseTree(c,tc_child) |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
331 |
else: |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
332 |
display_name = '{} {}'.format(c.nodetype[4:], c.name) |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
333 |
tc_child = self.AppendItem(current_tc_root, display_name) |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
334 |
self.SetPyData(tc_child, None) |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
335 |
self.SetItemImage(tc_child, self.fileidx, wx.TreeItemIcon_Normal) |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
336 |
self.SetItemImage(tc_child, self.fileidx, wx.TreeItemIcon_Expanded) |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
337 |
|
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
338 |
def MakeTree(self): |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
339 |
global hmi_tree_root |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
340 |
|
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
341 |
self.Freeze() |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
342 |
|
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
343 |
self.root = None |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
344 |
self.DeleteAllItems() |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
345 |
|
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
346 |
root_display_name = _("Please build to see HMI Tree") if hmi_tree_root is None else "HMI" |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
347 |
self.root = self.AddRoot(root_display_name) |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
348 |
self.SetPyData(self.root, None) |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
349 |
self.SetItemImage(self.root, self.fldridx, wx.TreeItemIcon_Normal) |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
350 |
self.SetItemImage(self.root, self.fldropenidx, wx.TreeItemIcon_Expanded) |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
351 |
|
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
352 |
if hmi_tree_root is not None: |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
353 |
self._recurseTree(hmi_tree_root, self.root) |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
354 |
|
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
355 |
self.Thaw() |
2816 | 356 |
|
357 |
def SVGHMIEditorUpdater(self): |
|
358 |
selfref = weakref.ref(self) |
|
359 |
def SVGHMIEditorUpdate(): |
|
360 |
o = selfref() |
|
361 |
if o is not None: |
|
362 |
wx.CallAfter(o.MakeTree) |
|
363 |
return SVGHMIEditorUpdate |
|
364 |
||
2818
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
365 |
class HMITreeView(wx.SplitterWindow): |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
366 |
|
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
367 |
def __init__(self, parent): |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
368 |
wx.SplitterWindow.__init__(self, parent, |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
369 |
style=wx.SUNKEN_BORDER | wx.SP_3D) |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
370 |
|
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
371 |
self.SelectionTree = HMITreeSelector(self) |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
372 |
#self.Staging = wx.Panel(self) |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
373 |
#self.SplitHorizontally(self.SelectionTree, self.Staging, 200) |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
374 |
self.Initialize(self.SelectionTree) |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
375 |
|
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
376 |
|
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
377 |
class SVGHMIEditor(ConfTreeNodeEditor): |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
378 |
CONFNODEEDITOR_TABS = [ |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
379 |
(_("HMI Tree"), "CreateHMITreeView")] |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
380 |
|
2816 | 381 |
def CreateHMITreeView(self, parent): |
2818
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
382 |
#self.HMITreeView = HMITreeView(self) |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
383 |
return HMITreeSelector(parent) |
65f32c94d7ec
SVGHMI: re-implemented tree view with classic wxTreeCtl
Edouard Tisserant
parents:
2817
diff
changeset
|
384 |
|
2816 | 385 |
|
2745 | 386 |
class SVGHMI(object): |
2771
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
387 |
XSD = """<?xml version="1.0" encoding="utf-8" ?> |
2745 | 388 |
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> |
389 |
<xsd:element name="SVGHMI"> |
|
390 |
<xsd:complexType> |
|
2823
d631f8671c75
SVGHMI : add on Start, Stop and Watchdog command fields to configuration
Edouard Tisserant
parents:
2822
diff
changeset
|
391 |
<xsd:attribute name="OnStart" type="xsd:string" use="optional"/> |
d631f8671c75
SVGHMI : add on Start, Stop and Watchdog command fields to configuration
Edouard Tisserant
parents:
2822
diff
changeset
|
392 |
<xsd:attribute name="OnStop" type="xsd:string" use="optional"/> |
d631f8671c75
SVGHMI : add on Start, Stop and Watchdog command fields to configuration
Edouard Tisserant
parents:
2822
diff
changeset
|
393 |
<xsd:attribute name="OnWatchdog" type="xsd:string" use="optional"/> |
2831
6c9cfdbe94dc
SVGHMI : watchdog is now taking an initial and interval duration as CTN fields.
Edouard Tisserant
parents:
2830
diff
changeset
|
394 |
<xsd:attribute name="WatchdogInitial" type="xsd:integer" use="optional"/> |
6c9cfdbe94dc
SVGHMI : watchdog is now taking an initial and interval duration as CTN fields.
Edouard Tisserant
parents:
2830
diff
changeset
|
395 |
<xsd:attribute name="WatchdogInterval" type="xsd:integer" use="optional"/> |
2745 | 396 |
</xsd:complexType> |
397 |
</xsd:element> |
|
398 |
</xsd:schema> |
|
399 |
""" |
|
2816 | 400 |
|
401 |
EditorType = SVGHMIEditor |
|
2745 | 402 |
|
403 |
ConfNodeMethods = [ |
|
404 |
{ |
|
405 |
"bitmap": "ImportSVG", |
|
406 |
"name": _("Import SVG"), |
|
407 |
"tooltip": _("Import SVG"), |
|
408 |
"method": "_ImportSVG" |
|
409 |
}, |
|
410 |
{ |
|
411 |
"bitmap": "ImportSVG", # should be something different |
|
412 |
"name": _("Inkscape"), |
|
413 |
"tooltip": _("Edit HMI"), |
|
414 |
"method": "_StartInkscape" |
|
415 |
}, |
|
2771
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
416 |
|
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2781
diff
changeset
|
417 |
# TODO : Launch POEdit button |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2781
diff
changeset
|
418 |
# PO -> SVG layers button |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2781
diff
changeset
|
419 |
# SVG layers -> PO |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2781
diff
changeset
|
420 |
|
2771
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
421 |
# TODO : HMITree button |
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
422 |
# - can drag'n'drop variabes to Inkscape |
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
423 |
|
2745 | 424 |
] |
425 |
||
426 |
def _getSVGpath(self, project_path=None): |
|
427 |
if project_path is None: |
|
428 |
project_path = self.CTNPath() |
|
2781 | 429 |
return os.path.join(project_path, "svghmi.svg") |
2745 | 430 |
|
431 |
||
432 |
def OnCTNSave(self, from_project_path=None): |
|
433 |
if from_project_path is not None: |
|
434 |
shutil.copyfile(self._getSVGpath(from_project_path), |
|
435 |
self._getSVGpath()) |
|
2750 | 436 |
return True |
2745 | 437 |
|
2753
9a7e12e96399
SVGHMI: Added XSLT transformation, Makefile to get XSLT from ysl2 (copy of plcopen/Makefile) and a minimal stylesheet to start with.
Edouard Tisserant
parents:
2750
diff
changeset
|
438 |
def GetSVGGeometry(self): |
2756
f94bc35a023e
SVGHMI: added extraction of SVG bounding boxes, obtained from "inkscape -S", and passed to XSLT transform as variable.
Edouard Tisserant
parents:
2753
diff
changeset
|
439 |
# invoke inskscape -S, csv-parse output, produce elements |
f94bc35a023e
SVGHMI: added extraction of SVG bounding boxes, obtained from "inkscape -S", and passed to XSLT transform as variable.
Edouard Tisserant
parents:
2753
diff
changeset
|
440 |
InkscapeGeomColumns = ["Id", "x", "y", "w", "h"] |
f94bc35a023e
SVGHMI: added extraction of SVG bounding boxes, obtained from "inkscape -S", and passed to XSLT transform as variable.
Edouard Tisserant
parents:
2753
diff
changeset
|
441 |
|
f94bc35a023e
SVGHMI: added extraction of SVG bounding boxes, obtained from "inkscape -S", and passed to XSLT transform as variable.
Edouard Tisserant
parents:
2753
diff
changeset
|
442 |
inkpath = get_inkscape_path() |
f94bc35a023e
SVGHMI: added extraction of SVG bounding boxes, obtained from "inkscape -S", and passed to XSLT transform as variable.
Edouard Tisserant
parents:
2753
diff
changeset
|
443 |
svgpath = self._getSVGpath() |
f94bc35a023e
SVGHMI: added extraction of SVG bounding boxes, obtained from "inkscape -S", and passed to XSLT transform as variable.
Edouard Tisserant
parents:
2753
diff
changeset
|
444 |
_status, result, _err_result = ProcessLogger(None, |
f94bc35a023e
SVGHMI: added extraction of SVG bounding boxes, obtained from "inkscape -S", and passed to XSLT transform as variable.
Edouard Tisserant
parents:
2753
diff
changeset
|
445 |
inkpath + " -S " + svgpath, |
f94bc35a023e
SVGHMI: added extraction of SVG bounding boxes, obtained from "inkscape -S", and passed to XSLT transform as variable.
Edouard Tisserant
parents:
2753
diff
changeset
|
446 |
no_stdout=True, |
f94bc35a023e
SVGHMI: added extraction of SVG bounding boxes, obtained from "inkscape -S", and passed to XSLT transform as variable.
Edouard Tisserant
parents:
2753
diff
changeset
|
447 |
no_stderr=True).spin() |
f94bc35a023e
SVGHMI: added extraction of SVG bounding boxes, obtained from "inkscape -S", and passed to XSLT transform as variable.
Edouard Tisserant
parents:
2753
diff
changeset
|
448 |
res = [] |
f94bc35a023e
SVGHMI: added extraction of SVG bounding boxes, obtained from "inkscape -S", and passed to XSLT transform as variable.
Edouard Tisserant
parents:
2753
diff
changeset
|
449 |
for line in result.split(): |
f94bc35a023e
SVGHMI: added extraction of SVG bounding boxes, obtained from "inkscape -S", and passed to XSLT transform as variable.
Edouard Tisserant
parents:
2753
diff
changeset
|
450 |
strippedline = line.strip() |
f94bc35a023e
SVGHMI: added extraction of SVG bounding boxes, obtained from "inkscape -S", and passed to XSLT transform as variable.
Edouard Tisserant
parents:
2753
diff
changeset
|
451 |
attrs = dict( |
f94bc35a023e
SVGHMI: added extraction of SVG bounding boxes, obtained from "inkscape -S", and passed to XSLT transform as variable.
Edouard Tisserant
parents:
2753
diff
changeset
|
452 |
zip(InkscapeGeomColumns, line.strip().split(','))) |
f94bc35a023e
SVGHMI: added extraction of SVG bounding boxes, obtained from "inkscape -S", and passed to XSLT transform as variable.
Edouard Tisserant
parents:
2753
diff
changeset
|
453 |
|
f94bc35a023e
SVGHMI: added extraction of SVG bounding boxes, obtained from "inkscape -S", and passed to XSLT transform as variable.
Edouard Tisserant
parents:
2753
diff
changeset
|
454 |
res.append(etree.Element("bbox", **attrs)) |
f94bc35a023e
SVGHMI: added extraction of SVG bounding boxes, obtained from "inkscape -S", and passed to XSLT transform as variable.
Edouard Tisserant
parents:
2753
diff
changeset
|
455 |
|
f94bc35a023e
SVGHMI: added extraction of SVG bounding boxes, obtained from "inkscape -S", and passed to XSLT transform as variable.
Edouard Tisserant
parents:
2753
diff
changeset
|
456 |
return res |
2753
9a7e12e96399
SVGHMI: Added XSLT transformation, Makefile to get XSLT from ysl2 (copy of plcopen/Makefile) and a minimal stylesheet to start with.
Edouard Tisserant
parents:
2750
diff
changeset
|
457 |
|
2763
ce04d79b8e57
Pass HMITree to SVG transform. It seems it could really help to reduce JS tree binding logic in the end.
Edouard Tisserant
parents:
2762
diff
changeset
|
458 |
def GetHMITree(self): |
ce04d79b8e57
Pass HMITree to SVG transform. It seems it could really help to reduce JS tree binding logic in the end.
Edouard Tisserant
parents:
2762
diff
changeset
|
459 |
global hmi_tree_root |
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2781
diff
changeset
|
460 |
res = [hmi_tree_root.etree(add_hash=True)] |
2763
ce04d79b8e57
Pass HMITree to SVG transform. It seems it could really help to reduce JS tree binding logic in the end.
Edouard Tisserant
parents:
2762
diff
changeset
|
461 |
return res |
ce04d79b8e57
Pass HMITree to SVG transform. It seems it could really help to reduce JS tree binding logic in the end.
Edouard Tisserant
parents:
2762
diff
changeset
|
462 |
|
2745 | 463 |
def CTNGenerate_C(self, buildpath, locations): |
464 |
||
2771
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
465 |
location_str = "_".join(map(str, self.GetCurrentLocation())) |
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
466 |
view_name = self.BaseParams.getName() |
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
467 |
|
2745 | 468 |
svgfile = self._getSVGpath() |
2771
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
469 |
|
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
470 |
res = ([], "", False) |
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
471 |
|
2812
68ac5bf43525
SVGHMI: various fixes to make SVGHMI behave on more versions of twisted and GCC.
Edouard Tisserant
parents:
2789
diff
changeset
|
472 |
target_fname = "svghmi_"+location_str+".xhtml" |
2771
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
473 |
|
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
474 |
target_path = os.path.join(self._getBuildPath(), target_fname) |
2812
68ac5bf43525
SVGHMI: various fixes to make SVGHMI behave on more versions of twisted and GCC.
Edouard Tisserant
parents:
2789
diff
changeset
|
475 |
target_file = open(target_path, 'wb') |
2771
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
476 |
|
2745 | 477 |
if os.path.exists(svgfile): |
2753
9a7e12e96399
SVGHMI: Added XSLT transformation, Makefile to get XSLT from ysl2 (copy of plcopen/Makefile) and a minimal stylesheet to start with.
Edouard Tisserant
parents:
2750
diff
changeset
|
478 |
|
9a7e12e96399
SVGHMI: Added XSLT transformation, Makefile to get XSLT from ysl2 (copy of plcopen/Makefile) and a minimal stylesheet to start with.
Edouard Tisserant
parents:
2750
diff
changeset
|
479 |
# TODO : move to __init__ |
9a7e12e96399
SVGHMI: Added XSLT transformation, Makefile to get XSLT from ysl2 (copy of plcopen/Makefile) and a minimal stylesheet to start with.
Edouard Tisserant
parents:
2750
diff
changeset
|
480 |
transform = XSLTransform(os.path.join(ScriptDirectory, "gen_index_xhtml.xslt"), |
2763
ce04d79b8e57
Pass HMITree to SVG transform. It seems it could really help to reduce JS tree binding logic in the end.
Edouard Tisserant
parents:
2762
diff
changeset
|
481 |
[("GetSVGGeometry", lambda *_ignored:self.GetSVGGeometry()), |
ce04d79b8e57
Pass HMITree to SVG transform. It seems it could really help to reduce JS tree binding logic in the end.
Edouard Tisserant
parents:
2762
diff
changeset
|
482 |
("GetHMITree", lambda *_ignored:self.GetHMITree())]) |
2753
9a7e12e96399
SVGHMI: Added XSLT transformation, Makefile to get XSLT from ysl2 (copy of plcopen/Makefile) and a minimal stylesheet to start with.
Edouard Tisserant
parents:
2750
diff
changeset
|
483 |
|
9a7e12e96399
SVGHMI: Added XSLT transformation, Makefile to get XSLT from ysl2 (copy of plcopen/Makefile) and a minimal stylesheet to start with.
Edouard Tisserant
parents:
2750
diff
changeset
|
484 |
|
9a7e12e96399
SVGHMI: Added XSLT transformation, Makefile to get XSLT from ysl2 (copy of plcopen/Makefile) and a minimal stylesheet to start with.
Edouard Tisserant
parents:
2750
diff
changeset
|
485 |
# load svg as a DOM with Etree |
9a7e12e96399
SVGHMI: Added XSLT transformation, Makefile to get XSLT from ysl2 (copy of plcopen/Makefile) and a minimal stylesheet to start with.
Edouard Tisserant
parents:
2750
diff
changeset
|
486 |
svgdom = etree.parse(svgfile) |
9a7e12e96399
SVGHMI: Added XSLT transformation, Makefile to get XSLT from ysl2 (copy of plcopen/Makefile) and a minimal stylesheet to start with.
Edouard Tisserant
parents:
2750
diff
changeset
|
487 |
|
9a7e12e96399
SVGHMI: Added XSLT transformation, Makefile to get XSLT from ysl2 (copy of plcopen/Makefile) and a minimal stylesheet to start with.
Edouard Tisserant
parents:
2750
diff
changeset
|
488 |
# call xslt transform on Inkscape's SVG to generate XHTML |
2834
6ac6a9dff594
SVGHMI: be a bit more tolerant with missing HMI paths or missing elements in widgets : continue build (with warning) and fail silently at runtime.
Edouard Tisserant
parents:
2831
diff
changeset
|
489 |
try: |
2814
2cabc4773885
SVGHMI: HMI_LABEL and HMI_CLASS become HMI_NODE.
Edouard Tisserant
parents:
2812
diff
changeset
|
490 |
result = transform.transform(svgdom) |
2cabc4773885
SVGHMI: HMI_LABEL and HMI_CLASS become HMI_NODE.
Edouard Tisserant
parents:
2812
diff
changeset
|
491 |
except XSLTApplyError as e: |
2cabc4773885
SVGHMI: HMI_LABEL and HMI_CLASS become HMI_NODE.
Edouard Tisserant
parents:
2812
diff
changeset
|
492 |
self.FatalError("SVGHMI " + view_name + ": " + e.message) |
2834
6ac6a9dff594
SVGHMI: be a bit more tolerant with missing HMI paths or missing elements in widgets : continue build (with warning) and fail silently at runtime.
Edouard Tisserant
parents:
2831
diff
changeset
|
493 |
finally: |
6ac6a9dff594
SVGHMI: be a bit more tolerant with missing HMI paths or missing elements in widgets : continue build (with warning) and fail silently at runtime.
Edouard Tisserant
parents:
2831
diff
changeset
|
494 |
for entry in transform.get_error_log(): |
6ac6a9dff594
SVGHMI: be a bit more tolerant with missing HMI paths or missing elements in widgets : continue build (with warning) and fail silently at runtime.
Edouard Tisserant
parents:
2831
diff
changeset
|
495 |
message = "SVGHMI: "+ entry.message + "\n" |
6ac6a9dff594
SVGHMI: be a bit more tolerant with missing HMI paths or missing elements in widgets : continue build (with warning) and fail silently at runtime.
Edouard Tisserant
parents:
2831
diff
changeset
|
496 |
self.GetCTRoot().logger.write_warning(message) |
2817
45bbfb2e120f
Non significant changes, whitespaces, etc.
Edouard Tisserant
parents:
2816
diff
changeset
|
497 |
|
2771
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
498 |
result.write(target_file, encoding="utf-8") |
2764
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
499 |
# print(str(result)) |
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2763
diff
changeset
|
500 |
# print(transform.xslt.error_log) |
2753
9a7e12e96399
SVGHMI: Added XSLT transformation, Makefile to get XSLT from ysl2 (copy of plcopen/Makefile) and a minimal stylesheet to start with.
Edouard Tisserant
parents:
2750
diff
changeset
|
501 |
|
9a7e12e96399
SVGHMI: Added XSLT transformation, Makefile to get XSLT from ysl2 (copy of plcopen/Makefile) and a minimal stylesheet to start with.
Edouard Tisserant
parents:
2750
diff
changeset
|
502 |
# TODO |
2745 | 503 |
# - Errors on HMI semantics |
504 |
# - ... maybe something to have a global view of what is declared in SVG. |
|
2753
9a7e12e96399
SVGHMI: Added XSLT transformation, Makefile to get XSLT from ysl2 (copy of plcopen/Makefile) and a minimal stylesheet to start with.
Edouard Tisserant
parents:
2750
diff
changeset
|
505 |
|
2745 | 506 |
else: |
2817
45bbfb2e120f
Non significant changes, whitespaces, etc.
Edouard Tisserant
parents:
2816
diff
changeset
|
507 |
# TODO : use default svg that expose the HMI tree as-is |
2771
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
508 |
target_file.write("""<!DOCTYPE html> |
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
509 |
<html> |
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
510 |
<body> |
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
511 |
<h1> No SVG file provided </h1> |
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
512 |
</body> |
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
513 |
</html> |
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
514 |
""") |
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
515 |
|
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
516 |
target_file.close() |
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
517 |
|
2772 | 518 |
res += ((target_fname, open(target_path, "rb")),) |
2828 | 519 |
|
2823
d631f8671c75
SVGHMI : add on Start, Stop and Watchdog command fields to configuration
Edouard Tisserant
parents:
2822
diff
changeset
|
520 |
svghmi_cmds = {} |
d631f8671c75
SVGHMI : add on Start, Stop and Watchdog command fields to configuration
Edouard Tisserant
parents:
2822
diff
changeset
|
521 |
for thing in ["Start", "Stop", "Watchdog"]: |
d631f8671c75
SVGHMI : add on Start, Stop and Watchdog command fields to configuration
Edouard Tisserant
parents:
2822
diff
changeset
|
522 |
given_command = self.GetParamsAttributes("SVGHMI.On"+thing)["value"] |
2824
074f43e6e114
SVGHMI : Added python fomating {port} and {name} to commands so that command can build target URL
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2823
diff
changeset
|
523 |
svghmi_cmds[thing] = ( |
074f43e6e114
SVGHMI : Added python fomating {port} and {name} to commands so that command can build target URL
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2823
diff
changeset
|
524 |
"Popen(" + |
2828 | 525 |
repr(shlex.split(given_command.format(port="8008", name=view_name))) + |
2834
6ac6a9dff594
SVGHMI: be a bit more tolerant with missing HMI paths or missing elements in widgets : continue build (with warning) and fail silently at runtime.
Edouard Tisserant
parents:
2831
diff
changeset
|
526 |
")") if given_command else "pass # no command given" |
2772 | 527 |
|
2771
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
528 |
runtimefile_path = os.path.join(buildpath, "runtime_svghmi1_%s.py" % location_str) |
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
529 |
runtimefile = open(runtimefile_path, 'w') |
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
530 |
runtimefile.write(""" |
2831
6c9cfdbe94dc
SVGHMI : watchdog is now taking an initial and interval duration as CTN fields.
Edouard Tisserant
parents:
2830
diff
changeset
|
531 |
# TODO : multiple watchdog (one for each svghmi instance) |
6c9cfdbe94dc
SVGHMI : watchdog is now taking an initial and interval duration as CTN fields.
Edouard Tisserant
parents:
2830
diff
changeset
|
532 |
def svghmi_watchdog_trigger(): |
2828 | 533 |
{svghmi_cmds[Watchdog]} |
2824
074f43e6e114
SVGHMI : Added python fomating {port} and {name} to commands so that command can build target URL
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2823
diff
changeset
|
534 |
|
2831
6c9cfdbe94dc
SVGHMI : watchdog is now taking an initial and interval duration as CTN fields.
Edouard Tisserant
parents:
2830
diff
changeset
|
535 |
svghmi_watchdog = None |
6c9cfdbe94dc
SVGHMI : watchdog is now taking an initial and interval duration as CTN fields.
Edouard Tisserant
parents:
2830
diff
changeset
|
536 |
|
2824
074f43e6e114
SVGHMI : Added python fomating {port} and {name} to commands so that command can build target URL
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2823
diff
changeset
|
537 |
def _runtime_svghmi1_{location}_start(): |
2831
6c9cfdbe94dc
SVGHMI : watchdog is now taking an initial and interval duration as CTN fields.
Edouard Tisserant
parents:
2830
diff
changeset
|
538 |
global svghmi_watchdog |
6c9cfdbe94dc
SVGHMI : watchdog is now taking an initial and interval duration as CTN fields.
Edouard Tisserant
parents:
2830
diff
changeset
|
539 |
svghmi_root.putChild( |
6c9cfdbe94dc
SVGHMI : watchdog is now taking an initial and interval duration as CTN fields.
Edouard Tisserant
parents:
2830
diff
changeset
|
540 |
'{view_name}', |
6c9cfdbe94dc
SVGHMI : watchdog is now taking an initial and interval duration as CTN fields.
Edouard Tisserant
parents:
2830
diff
changeset
|
541 |
NoCacheFile('{xhtml}', |
6c9cfdbe94dc
SVGHMI : watchdog is now taking an initial and interval duration as CTN fields.
Edouard Tisserant
parents:
2830
diff
changeset
|
542 |
defaultType='application/xhtml+xml')) |
6c9cfdbe94dc
SVGHMI : watchdog is now taking an initial and interval duration as CTN fields.
Edouard Tisserant
parents:
2830
diff
changeset
|
543 |
|
2828 | 544 |
{svghmi_cmds[Start]} |
2824
074f43e6e114
SVGHMI : Added python fomating {port} and {name} to commands so that command can build target URL
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2823
diff
changeset
|
545 |
|
2831
6c9cfdbe94dc
SVGHMI : watchdog is now taking an initial and interval duration as CTN fields.
Edouard Tisserant
parents:
2830
diff
changeset
|
546 |
svghmi_watchdog = Watchdog( |
6c9cfdbe94dc
SVGHMI : watchdog is now taking an initial and interval duration as CTN fields.
Edouard Tisserant
parents:
2830
diff
changeset
|
547 |
{watchdog_initial}, |
6c9cfdbe94dc
SVGHMI : watchdog is now taking an initial and interval duration as CTN fields.
Edouard Tisserant
parents:
2830
diff
changeset
|
548 |
{watchdog_interval}, |
6c9cfdbe94dc
SVGHMI : watchdog is now taking an initial and interval duration as CTN fields.
Edouard Tisserant
parents:
2830
diff
changeset
|
549 |
svghmi_watchdog_trigger) |
6c9cfdbe94dc
SVGHMI : watchdog is now taking an initial and interval duration as CTN fields.
Edouard Tisserant
parents:
2830
diff
changeset
|
550 |
|
2824
074f43e6e114
SVGHMI : Added python fomating {port} and {name} to commands so that command can build target URL
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2823
diff
changeset
|
551 |
def _runtime_svghmi1_{location}_stop(): |
2831
6c9cfdbe94dc
SVGHMI : watchdog is now taking an initial and interval duration as CTN fields.
Edouard Tisserant
parents:
2830
diff
changeset
|
552 |
global svghmi_watchdog |
6c9cfdbe94dc
SVGHMI : watchdog is now taking an initial and interval duration as CTN fields.
Edouard Tisserant
parents:
2830
diff
changeset
|
553 |
if svghmi_watchdog is not None: |
6c9cfdbe94dc
SVGHMI : watchdog is now taking an initial and interval duration as CTN fields.
Edouard Tisserant
parents:
2830
diff
changeset
|
554 |
svghmi_watchdog.cancel() |
6c9cfdbe94dc
SVGHMI : watchdog is now taking an initial and interval duration as CTN fields.
Edouard Tisserant
parents:
2830
diff
changeset
|
555 |
svghmi_watchdog = None |
6c9cfdbe94dc
SVGHMI : watchdog is now taking an initial and interval duration as CTN fields.
Edouard Tisserant
parents:
2830
diff
changeset
|
556 |
|
2824
074f43e6e114
SVGHMI : Added python fomating {port} and {name} to commands so that command can build target URL
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2823
diff
changeset
|
557 |
svghmi_root.delEntity('{view_name}') |
2828 | 558 |
{svghmi_cmds[Stop]} |
2824
074f43e6e114
SVGHMI : Added python fomating {port} and {name} to commands so that command can build target URL
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2823
diff
changeset
|
559 |
|
074f43e6e114
SVGHMI : Added python fomating {port} and {name} to commands so that command can build target URL
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2823
diff
changeset
|
560 |
""".format(location=location_str, |
074f43e6e114
SVGHMI : Added python fomating {port} and {name} to commands so that command can build target URL
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2823
diff
changeset
|
561 |
xhtml=target_fname, |
074f43e6e114
SVGHMI : Added python fomating {port} and {name} to commands so that command can build target URL
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2823
diff
changeset
|
562 |
view_name=view_name, |
2831
6c9cfdbe94dc
SVGHMI : watchdog is now taking an initial and interval duration as CTN fields.
Edouard Tisserant
parents:
2830
diff
changeset
|
563 |
svghmi_cmds=svghmi_cmds, |
6c9cfdbe94dc
SVGHMI : watchdog is now taking an initial and interval duration as CTN fields.
Edouard Tisserant
parents:
2830
diff
changeset
|
564 |
watchdog_initial = self.GetParamsAttributes("SVGHMI.WatchdogInitial")["value"], |
6c9cfdbe94dc
SVGHMI : watchdog is now taking an initial and interval duration as CTN fields.
Edouard Tisserant
parents:
2830
diff
changeset
|
565 |
watchdog_interval = self.GetParamsAttributes("SVGHMI.WatchdogInterval")["value"], |
6c9cfdbe94dc
SVGHMI : watchdog is now taking an initial and interval duration as CTN fields.
Edouard Tisserant
parents:
2830
diff
changeset
|
566 |
)) |
2771
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
567 |
|
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
568 |
runtimefile.close() |
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
569 |
|
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
570 |
res += (("runtime_svghmi1_%s.py" % location_str, open(runtimefile_path, "rb")),) |
2745 | 571 |
|
572 |
return res |
|
573 |
||
574 |
def _ImportSVG(self): |
|
575 |
dialog = wx.FileDialog(self.GetCTRoot().AppFrame, _("Choose a SVG file"), os.getcwd(), "", _("SVG files (*.svg)|*.svg|All files|*.*"), wx.OPEN) |
|
576 |
if dialog.ShowModal() == wx.ID_OK: |
|
577 |
svgpath = dialog.GetPath() |
|
578 |
if os.path.isfile(svgpath): |
|
579 |
shutil.copy(svgpath, self._getSVGpath()) |
|
580 |
else: |
|
581 |
self.GetCTRoot().logger.write_error(_("No such SVG file: %s\n") % svgpath) |
|
582 |
dialog.Destroy() |
|
583 |
||
584 |
def _StartInkscape(self): |
|
585 |
svgfile = self._getSVGpath() |
|
586 |
open_inkscape = True |
|
587 |
if not self.GetCTRoot().CheckProjectPathPerm(): |
|
588 |
dialog = wx.MessageDialog(self.GetCTRoot().AppFrame, |
|
589 |
_("You don't have write permissions.\nOpen Inkscape anyway ?"), |
|
590 |
_("Open Inkscape"), |
|
591 |
wx.YES_NO | wx.ICON_QUESTION) |
|
592 |
open_inkscape = dialog.ShowModal() == wx.ID_YES |
|
593 |
dialog.Destroy() |
|
594 |
if open_inkscape: |
|
595 |
if not os.path.isfile(svgfile): |
|
596 |
svgfile = None |
|
597 |
open_svg(svgfile) |
|
2822
9101a72a1da0
SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents:
2818
diff
changeset
|
598 |
|
9101a72a1da0
SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents:
2818
diff
changeset
|
599 |
def CTNGlobalInstances(self): |
9101a72a1da0
SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents:
2818
diff
changeset
|
600 |
# view_name = self.BaseParams.getName() |
9101a72a1da0
SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents:
2818
diff
changeset
|
601 |
# return [ (view_name + "_" + name, iec_type, "") for name, iec_type in SPECIAL_NODES] |
9101a72a1da0
SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents:
2818
diff
changeset
|
602 |
# TODO : move to library level for multiple hmi |
9101a72a1da0
SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents:
2818
diff
changeset
|
603 |
return [(name, iec_type, "") for name, iec_type in SPECIAL_NODES] |
9101a72a1da0
SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents:
2818
diff
changeset
|
604 |