author | Edouard Tisserant <edouard.tisserant@gmail.com> |
Wed, 13 May 2020 18:47:09 +0200 | |
branch | svghmi |
changeset 2960 | 5ad82541b46e |
parent 2958 | 895d3f2b1786 |
child 2963 | 113e2f2e324d |
permissions | -rw-r--r-- |
2884
50b9832c51fc
SVGHMI: update Makefile to pick all changes to any dependency
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2883
diff
changeset
|
1 |
// widgets_common.ysl2 |
50b9832c51fc
SVGHMI: update Makefile to pick all changes to any dependency
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2883
diff
changeset
|
2 |
|
2808
dc78ffa5253d
SVGHMI: SVG viewport now defined so that HMI take scales and fit to the view. Implemented page switch through viewport change, no hiding of widget for now.
Edouard Tisserant
parents:
2807
diff
changeset
|
3 |
in xsl decl labels(*ptr, name="defs_by_labels") alias call-template { |
dc78ffa5253d
SVGHMI: SVG viewport now defined so that HMI take scales and fit to the view. Implemented page switch through viewport change, no hiding of widget for now.
Edouard Tisserant
parents:
2807
diff
changeset
|
4 |
with "hmi_element", "$hmi_element"; |
2810
63b9a37b73c7
SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents:
2808
diff
changeset
|
5 |
with "labels"{text *ptr}; |
2937
9226a830fbc3
SVGHMI: moving code wher it belongs, and reformulate some declarations for better readability.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2920
diff
changeset
|
6 |
content; |
2808
dc78ffa5253d
SVGHMI: SVG viewport now defined so that HMI take scales and fit to the view. Implemented page switch through viewport change, no hiding of widget for now.
Edouard Tisserant
parents:
2807
diff
changeset
|
7 |
}; |
dc78ffa5253d
SVGHMI: SVG viewport now defined so that HMI take scales and fit to the view. Implemented page switch through viewport change, no hiding of widget for now.
Edouard Tisserant
parents:
2807
diff
changeset
|
8 |
|
2937
9226a830fbc3
SVGHMI: moving code wher it belongs, and reformulate some declarations for better readability.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2920
diff
changeset
|
9 |
decl optional_labels(*ptr) alias - { |
9226a830fbc3
SVGHMI: moving code wher it belongs, and reformulate some declarations for better readability.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2920
diff
changeset
|
10 |
/* TODO add some per label xslt variable to check if exist */ |
9226a830fbc3
SVGHMI: moving code wher it belongs, and reformulate some declarations for better readability.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2920
diff
changeset
|
11 |
labels(*ptr){ |
9226a830fbc3
SVGHMI: moving code wher it belongs, and reformulate some declarations for better readability.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2920
diff
changeset
|
12 |
with "mandatory","'no'"; |
9226a830fbc3
SVGHMI: moving code wher it belongs, and reformulate some declarations for better readability.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2920
diff
changeset
|
13 |
content; |
9226a830fbc3
SVGHMI: moving code wher it belongs, and reformulate some declarations for better readability.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2920
diff
changeset
|
14 |
} |
2836
ce6cecdb7320
SVGHMI : still behave, even if important things are missing in SVG widget definitions (ex: needle missing for Meter widget)
Edouard Tisserant
parents:
2834
diff
changeset
|
15 |
}; |
ce6cecdb7320
SVGHMI : still behave, even if important things are missing in SVG widget definitions (ex: needle missing for Meter widget)
Edouard Tisserant
parents:
2834
diff
changeset
|
16 |
|
2937
9226a830fbc3
SVGHMI: moving code wher it belongs, and reformulate some declarations for better readability.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2920
diff
changeset
|
17 |
decl activable_labels(*ptr) alias - { |
9226a830fbc3
SVGHMI: moving code wher it belongs, and reformulate some declarations for better readability.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2920
diff
changeset
|
18 |
optional_labels(*ptr) { |
9226a830fbc3
SVGHMI: moving code wher it belongs, and reformulate some declarations for better readability.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2920
diff
changeset
|
19 |
with "subelements","'active inactive'"; |
9226a830fbc3
SVGHMI: moving code wher it belongs, and reformulate some declarations for better readability.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2920
diff
changeset
|
20 |
content; |
9226a830fbc3
SVGHMI: moving code wher it belongs, and reformulate some declarations for better readability.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2920
diff
changeset
|
21 |
} |
2920
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
22 |
}; |
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
23 |
|
2955
64e603b84aa3
SVGHMI: Exclude non-widget HMI:* labeled elements from hmi_widget. Namely : HMI:Page HMI:Lang and HMI:List have been excluded.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2954
diff
changeset
|
24 |
template "svg:*", mode="hmi_widgets" { |
2886
6c82fad8be65
SVGHMI: Simplification and optimization. func:parselabel becomes a template.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2884
diff
changeset
|
25 |
const "widget", "func:widget(@id)"; |
2881 | 26 |
const "eltid","@id"; |
2950
1e53d8b60ee9
SVGHMI: Parameters common to all widget constructors now passed as ordered parameters.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2949
diff
changeset
|
27 |
const "args" foreach "$widget/arg" > "«@value»"`if "position()!=last()" > ,` |
1e53d8b60ee9
SVGHMI: Parameters common to all widget constructors now passed as ordered parameters.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2949
diff
changeset
|
28 |
const "indexes" foreach "$widget/path" { |
2881 | 29 |
choose { |
30 |
when "not(@index)" { |
|
31 |
warning > Widget «$widget/@type» id="«$eltid»" : No match for path "«@value»" in HMI tree |
|
32 |
} |
|
33 |
otherwise { |
|
2950
1e53d8b60ee9
SVGHMI: Parameters common to all widget constructors now passed as ordered parameters.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2949
diff
changeset
|
34 |
> «@index»`if "position()!=last()" > ,` |
2792
0c0d3895b036
SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents:
2791
diff
changeset
|
35 |
} |
0c0d3895b036
SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents:
2791
diff
changeset
|
36 |
} |
0c0d3895b036
SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents:
2791
diff
changeset
|
37 |
} |
2950
1e53d8b60ee9
SVGHMI: Parameters common to all widget constructors now passed as ordered parameters.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2949
diff
changeset
|
38 |
|
1e53d8b60ee9
SVGHMI: Parameters common to all widget constructors now passed as ordered parameters.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2949
diff
changeset
|
39 |
| "«@id»": new «$widget/@type»Widget ("«@id»",[«$args»],[«$indexes»],{ |
2881 | 40 |
apply "$widget", mode="widget_defs" with "hmi_element","."; |
2949
e50908ddec60
SVGHMI: One class per widget type, widget objects are instances of these classes, and members are passed through constructor. This allows to keep compatible with previous widget_defs template used in most widgets.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2948
diff
changeset
|
41 |
| })`if "position()!=last()" > ,` |
e50908ddec60
SVGHMI: One class per widget type, widget objects are instances of these classes, and members are passed through constructor. This allows to keep compatible with previous widget_defs template used in most widgets.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2948
diff
changeset
|
42 |
} |
2948
faaf677ea99d
SVGHMI: Add an exslt function to collect used widget types, in order to only include necessary JS definitions in furure changes.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2941
diff
changeset
|
43 |
|
faaf677ea99d
SVGHMI: Add an exslt function to collect used widget types, in order to only include necessary JS definitions in furure changes.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2941
diff
changeset
|
44 |
def "func:unique_types" { |
faaf677ea99d
SVGHMI: Add an exslt function to collect used widget types, in order to only include necessary JS definitions in furure changes.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2941
diff
changeset
|
45 |
param "elts_with_type"; |
faaf677ea99d
SVGHMI: Add an exslt function to collect used widget types, in order to only include necessary JS definitions in furure changes.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2941
diff
changeset
|
46 |
choose { |
faaf677ea99d
SVGHMI: Add an exslt function to collect used widget types, in order to only include necessary JS definitions in furure changes.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2941
diff
changeset
|
47 |
when "count($elts_with_type) > 1" { |
faaf677ea99d
SVGHMI: Add an exslt function to collect used widget types, in order to only include necessary JS definitions in furure changes.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2941
diff
changeset
|
48 |
const "prior_results","func:unique_types($elts_with_type[position()!=last()])"; |
faaf677ea99d
SVGHMI: Add an exslt function to collect used widget types, in order to only include necessary JS definitions in furure changes.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2941
diff
changeset
|
49 |
choose { |
faaf677ea99d
SVGHMI: Add an exslt function to collect used widget types, in order to only include necessary JS definitions in furure changes.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2941
diff
changeset
|
50 |
when "$elts_with_type[last()][@type = $prior_results/@type]"{ |
faaf677ea99d
SVGHMI: Add an exslt function to collect used widget types, in order to only include necessary JS definitions in furure changes.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2941
diff
changeset
|
51 |
// type already in |
faaf677ea99d
SVGHMI: Add an exslt function to collect used widget types, in order to only include necessary JS definitions in furure changes.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2941
diff
changeset
|
52 |
result "$prior_results"; |
faaf677ea99d
SVGHMI: Add an exslt function to collect used widget types, in order to only include necessary JS definitions in furure changes.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2941
diff
changeset
|
53 |
} |
faaf677ea99d
SVGHMI: Add an exslt function to collect used widget types, in order to only include necessary JS definitions in furure changes.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2941
diff
changeset
|
54 |
otherwise { |
faaf677ea99d
SVGHMI: Add an exslt function to collect used widget types, in order to only include necessary JS definitions in furure changes.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2941
diff
changeset
|
55 |
result "$prior_results | $elts_with_type[last()]"; |
faaf677ea99d
SVGHMI: Add an exslt function to collect used widget types, in order to only include necessary JS definitions in furure changes.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2941
diff
changeset
|
56 |
} |
faaf677ea99d
SVGHMI: Add an exslt function to collect used widget types, in order to only include necessary JS definitions in furure changes.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2941
diff
changeset
|
57 |
} |
faaf677ea99d
SVGHMI: Add an exslt function to collect used widget types, in order to only include necessary JS definitions in furure changes.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2941
diff
changeset
|
58 |
} |
faaf677ea99d
SVGHMI: Add an exslt function to collect used widget types, in order to only include necessary JS definitions in furure changes.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2941
diff
changeset
|
59 |
otherwise { |
faaf677ea99d
SVGHMI: Add an exslt function to collect used widget types, in order to only include necessary JS definitions in furure changes.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2941
diff
changeset
|
60 |
result "$elts_with_type"; |
faaf677ea99d
SVGHMI: Add an exslt function to collect used widget types, in order to only include necessary JS definitions in furure changes.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2941
diff
changeset
|
61 |
} |
faaf677ea99d
SVGHMI: Add an exslt function to collect used widget types, in order to only include necessary JS definitions in furure changes.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2941
diff
changeset
|
62 |
} |
faaf677ea99d
SVGHMI: Add an exslt function to collect used widget types, in order to only include necessary JS definitions in furure changes.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2941
diff
changeset
|
63 |
} |
faaf677ea99d
SVGHMI: Add an exslt function to collect used widget types, in order to only include necessary JS definitions in furure changes.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2941
diff
changeset
|
64 |
|
2949
e50908ddec60
SVGHMI: One class per widget type, widget objects are instances of these classes, and members are passed through constructor. This allows to keep compatible with previous widget_defs template used in most widgets.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2948
diff
changeset
|
65 |
emit "preamble:widget-base-class" { |
e50908ddec60
SVGHMI: One class per widget type, widget objects are instances of these classes, and members are passed through constructor. This allows to keep compatible with previous widget_defs template used in most widgets.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2948
diff
changeset
|
66 |
|| |
e50908ddec60
SVGHMI: One class per widget type, widget objects are instances of these classes, and members are passed through constructor. This allows to keep compatible with previous widget_defs template used in most widgets.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2948
diff
changeset
|
67 |
class Widget { |
2950
1e53d8b60ee9
SVGHMI: Parameters common to all widget constructors now passed as ordered parameters.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2949
diff
changeset
|
68 |
constructor(elt_id,args,indexes,members){ |
2958
895d3f2b1786
SVGHMI: Back button updated to class style
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2955
diff
changeset
|
69 |
this.element_id = elt_id; |
2950
1e53d8b60ee9
SVGHMI: Parameters common to all widget constructors now passed as ordered parameters.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2949
diff
changeset
|
70 |
this.element = id(elt_id); |
1e53d8b60ee9
SVGHMI: Parameters common to all widget constructors now passed as ordered parameters.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2949
diff
changeset
|
71 |
this.args = args; |
1e53d8b60ee9
SVGHMI: Parameters common to all widget constructors now passed as ordered parameters.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2949
diff
changeset
|
72 |
this.indexes = indexes; |
1e53d8b60ee9
SVGHMI: Parameters common to all widget constructors now passed as ordered parameters.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2949
diff
changeset
|
73 |
this.offset = 0; |
2949
e50908ddec60
SVGHMI: One class per widget type, widget objects are instances of these classes, and members are passed through constructor. This allows to keep compatible with previous widget_defs template used in most widgets.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2948
diff
changeset
|
74 |
Object.keys(members).forEach(prop => this[prop]=members[prop]); |
e50908ddec60
SVGHMI: One class per widget type, widget objects are instances of these classes, and members are passed through constructor. This allows to keep compatible with previous widget_defs template used in most widgets.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2948
diff
changeset
|
75 |
} |
2958
895d3f2b1786
SVGHMI: Back button updated to class style
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2955
diff
changeset
|
76 |
|
2951
506fe9272660
SVGHMI: Widget's specific sub/unsub traits are now wxpressed in widget's class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2950
diff
changeset
|
77 |
unsub(){ |
506fe9272660
SVGHMI: Widget's specific sub/unsub traits are now wxpressed in widget's class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2950
diff
changeset
|
78 |
/* remove subsribers */ |
506fe9272660
SVGHMI: Widget's specific sub/unsub traits are now wxpressed in widget's class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2950
diff
changeset
|
79 |
for(let index of this.indexes){ |
506fe9272660
SVGHMI: Widget's specific sub/unsub traits are now wxpressed in widget's class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2950
diff
changeset
|
80 |
let idx = index + this.offset; |
506fe9272660
SVGHMI: Widget's specific sub/unsub traits are now wxpressed in widget's class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2950
diff
changeset
|
81 |
subscribers[idx].delete(this); |
506fe9272660
SVGHMI: Widget's specific sub/unsub traits are now wxpressed in widget's class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2950
diff
changeset
|
82 |
} |
506fe9272660
SVGHMI: Widget's specific sub/unsub traits are now wxpressed in widget's class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2950
diff
changeset
|
83 |
this.offset = 0; |
506fe9272660
SVGHMI: Widget's specific sub/unsub traits are now wxpressed in widget's class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2950
diff
changeset
|
84 |
} |
506fe9272660
SVGHMI: Widget's specific sub/unsub traits are now wxpressed in widget's class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2950
diff
changeset
|
85 |
|
506fe9272660
SVGHMI: Widget's specific sub/unsub traits are now wxpressed in widget's class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2950
diff
changeset
|
86 |
sub(new_offset=0){ |
506fe9272660
SVGHMI: Widget's specific sub/unsub traits are now wxpressed in widget's class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2950
diff
changeset
|
87 |
/* set the offset because relative */ |
506fe9272660
SVGHMI: Widget's specific sub/unsub traits are now wxpressed in widget's class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2950
diff
changeset
|
88 |
this.offset = new_offset; |
506fe9272660
SVGHMI: Widget's specific sub/unsub traits are now wxpressed in widget's class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2950
diff
changeset
|
89 |
/* add this's subsribers */ |
506fe9272660
SVGHMI: Widget's specific sub/unsub traits are now wxpressed in widget's class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2950
diff
changeset
|
90 |
for(let index of this.indexes){ |
506fe9272660
SVGHMI: Widget's specific sub/unsub traits are now wxpressed in widget's class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2950
diff
changeset
|
91 |
subscribers[index + new_offset].add(this); |
506fe9272660
SVGHMI: Widget's specific sub/unsub traits are now wxpressed in widget's class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2950
diff
changeset
|
92 |
} |
506fe9272660
SVGHMI: Widget's specific sub/unsub traits are now wxpressed in widget's class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2950
diff
changeset
|
93 |
need_cache_apply.push(this); |
506fe9272660
SVGHMI: Widget's specific sub/unsub traits are now wxpressed in widget's class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2950
diff
changeset
|
94 |
} |
506fe9272660
SVGHMI: Widget's specific sub/unsub traits are now wxpressed in widget's class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2950
diff
changeset
|
95 |
|
506fe9272660
SVGHMI: Widget's specific sub/unsub traits are now wxpressed in widget's class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2950
diff
changeset
|
96 |
apply_cache() { |
506fe9272660
SVGHMI: Widget's specific sub/unsub traits are now wxpressed in widget's class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2950
diff
changeset
|
97 |
for(let index of this.indexes){ |
506fe9272660
SVGHMI: Widget's specific sub/unsub traits are now wxpressed in widget's class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2950
diff
changeset
|
98 |
/* dispatch current cache in newly opened page widgets */ |
506fe9272660
SVGHMI: Widget's specific sub/unsub traits are now wxpressed in widget's class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2950
diff
changeset
|
99 |
let realindex = index+this.offset; |
506fe9272660
SVGHMI: Widget's specific sub/unsub traits are now wxpressed in widget's class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2950
diff
changeset
|
100 |
let cached_val = cache[realindex]; |
506fe9272660
SVGHMI: Widget's specific sub/unsub traits are now wxpressed in widget's class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2950
diff
changeset
|
101 |
if(cached_val != undefined) |
506fe9272660
SVGHMI: Widget's specific sub/unsub traits are now wxpressed in widget's class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2950
diff
changeset
|
102 |
dispatch_value_to_widget(this, realindex, cached_val, cached_val); |
506fe9272660
SVGHMI: Widget's specific sub/unsub traits are now wxpressed in widget's class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2950
diff
changeset
|
103 |
} |
506fe9272660
SVGHMI: Widget's specific sub/unsub traits are now wxpressed in widget's class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2950
diff
changeset
|
104 |
} |
506fe9272660
SVGHMI: Widget's specific sub/unsub traits are now wxpressed in widget's class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2950
diff
changeset
|
105 |
|
2949
e50908ddec60
SVGHMI: One class per widget type, widget objects are instances of these classes, and members are passed through constructor. This allows to keep compatible with previous widget_defs template used in most widgets.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2948
diff
changeset
|
106 |
} |
e50908ddec60
SVGHMI: One class per widget type, widget objects are instances of these classes, and members are passed through constructor. This allows to keep compatible with previous widget_defs template used in most widgets.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2948
diff
changeset
|
107 |
|| |
e50908ddec60
SVGHMI: One class per widget type, widget objects are instances of these classes, and members are passed through constructor. This allows to keep compatible with previous widget_defs template used in most widgets.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2948
diff
changeset
|
108 |
} |
e50908ddec60
SVGHMI: One class per widget type, widget objects are instances of these classes, and members are passed through constructor. This allows to keep compatible with previous widget_defs template used in most widgets.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2948
diff
changeset
|
109 |
|
2948
faaf677ea99d
SVGHMI: Add an exslt function to collect used widget types, in order to only include necessary JS definitions in furure changes.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2941
diff
changeset
|
110 |
emit "preamble:hmi-classes" { |
faaf677ea99d
SVGHMI: Add an exslt function to collect used widget types, in order to only include necessary JS definitions in furure changes.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2941
diff
changeset
|
111 |
const "used_widget_types", "func:unique_types($parsed_widgets/widget)"; |
faaf677ea99d
SVGHMI: Add an exslt function to collect used widget types, in order to only include necessary JS definitions in furure changes.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2941
diff
changeset
|
112 |
apply "$used_widget_types", mode="widget_class"; |
2881 | 113 |
} |
2810
63b9a37b73c7
SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents:
2808
diff
changeset
|
114 |
|
2949
e50908ddec60
SVGHMI: One class per widget type, widget objects are instances of these classes, and members are passed through constructor. This allows to keep compatible with previous widget_defs template used in most widgets.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2948
diff
changeset
|
115 |
template "widget", mode="widget_class" |
e50908ddec60
SVGHMI: One class per widget type, widget objects are instances of these classes, and members are passed through constructor. This allows to keep compatible with previous widget_defs template used in most widgets.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2948
diff
changeset
|
116 |
|| |
e50908ddec60
SVGHMI: One class per widget type, widget objects are instances of these classes, and members are passed through constructor. This allows to keep compatible with previous widget_defs template used in most widgets.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2948
diff
changeset
|
117 |
class «@type»Widget extends Widget{ |
e50908ddec60
SVGHMI: One class per widget type, widget objects are instances of these classes, and members are passed through constructor. This allows to keep compatible with previous widget_defs template used in most widgets.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2948
diff
changeset
|
118 |
/* empty class, as «@type» widget didn't provide any */ |
e50908ddec60
SVGHMI: One class per widget type, widget objects are instances of these classes, and members are passed through constructor. This allows to keep compatible with previous widget_defs template used in most widgets.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2948
diff
changeset
|
119 |
} |
e50908ddec60
SVGHMI: One class per widget type, widget objects are instances of these classes, and members are passed through constructor. This allows to keep compatible with previous widget_defs template used in most widgets.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2948
diff
changeset
|
120 |
|| |
e50908ddec60
SVGHMI: One class per widget type, widget objects are instances of these classes, and members are passed through constructor. This allows to keep compatible with previous widget_defs template used in most widgets.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2948
diff
changeset
|
121 |
|
2955
64e603b84aa3
SVGHMI: Exclude non-widget HMI:* labeled elements from hmi_widget. Namely : HMI:Page HMI:Lang and HMI:List have been excluded.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2954
diff
changeset
|
122 |
const "excluded_types", "str:split('Page Lang List')"; |
64e603b84aa3
SVGHMI: Exclude non-widget HMI:* labeled elements from hmi_widget. Namely : HMI:Page HMI:Lang and HMI:List have been excluded.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2954
diff
changeset
|
123 |
const "excluded_ids","$parsed_widgets/widget[not(@type = $excluded_types)]/@id"; |
64e603b84aa3
SVGHMI: Exclude non-widget HMI:* labeled elements from hmi_widget. Namely : HMI:Page HMI:Lang and HMI:List have been excluded.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2954
diff
changeset
|
124 |
|
2941
ef13a4007538
SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2937
diff
changeset
|
125 |
emit "preamble:hmi-elements" { |
ef13a4007538
SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2937
diff
changeset
|
126 |
| var hmi_widgets = { |
2955
64e603b84aa3
SVGHMI: Exclude non-widget HMI:* labeled elements from hmi_widget. Namely : HMI:Page HMI:Lang and HMI:List have been excluded.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2954
diff
changeset
|
127 |
apply "$hmi_elements[@id = $excluded_ids]", mode="hmi_widgets"; |
2941
ef13a4007538
SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2937
diff
changeset
|
128 |
| } |
ef13a4007538
SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2937
diff
changeset
|
129 |
} |
ef13a4007538
SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2937
diff
changeset
|
130 |
|
2881 | 131 |
function "defs_by_labels" { |
132 |
param "labels","''"; |
|
133 |
param "mandatory","'yes'"; |
|
2920
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
134 |
param "subelements","/.."; |
2881 | 135 |
param "hmi_element"; |
136 |
const "widget_type","@type"; |
|
137 |
foreach "str:split($labels)" { |
|
138 |
const "name","."; |
|
2920
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
139 |
const "elt","$result_svg_ns//*[@id = $hmi_element/@id]//*[@inkscape:label=$name][1]"; |
2881 | 140 |
choose { |
2920
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
141 |
when "not($elt/@id)" { |
2881 | 142 |
if "$mandatory='yes'" { |
2920
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
143 |
error > «$widget_type» widget must have a «$name» element |
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:
2833
diff
changeset
|
144 |
} |
2881 | 145 |
// otherwise produce nothing |
2797
c5ba1e77f054
SVGHMI: added a widgets description object, accessed by id. Added frequency to widgets, as separate template to allow future customization. Excluded non svg elements (i.e inkscape Sets) with HMI: labels from widgets.
Edouard Tisserant
parents:
2796
diff
changeset
|
146 |
} |
2881 | 147 |
otherwise { |
2920
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
148 |
| «$name»_elt: id("«$elt/@id»"), |
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
149 |
if "$subelements" { |
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
150 |
| «$name»_sub: { |
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
151 |
foreach "str:split($subelements)" { |
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
152 |
const "subname","."; |
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
153 |
const "subelt","$elt/*[@inkscape:label=$subname][1]"; |
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
154 |
choose { |
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
155 |
when "not($subelt/@id)" { |
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
156 |
if "$mandatory='yes'" { |
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
157 |
error > «$widget_type» widget must have a «$name»/«$subname» element |
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
158 |
} |
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
159 |
| /* missing «$name»/«$subname» element */ |
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
160 |
} |
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
161 |
otherwise { |
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
162 |
| "«$subname»": id("«$subelt/@id»")`if "position()!=last()" > ,` |
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
163 |
} |
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
164 |
} |
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
165 |
} |
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
166 |
| }, |
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
167 |
} |
2836
ce6cecdb7320
SVGHMI : still behave, even if important things are missing in SVG widget definitions (ex: needle missing for Meter widget)
Edouard Tisserant
parents:
2834
diff
changeset
|
168 |
} |
2808
dc78ffa5253d
SVGHMI: SVG viewport now defined so that HMI take scales and fit to the view. Implemented page switch through viewport change, no hiding of widget for now.
Edouard Tisserant
parents:
2807
diff
changeset
|
169 |
} |
dc78ffa5253d
SVGHMI: SVG viewport now defined so that HMI take scales and fit to the view. Implemented page switch through viewport change, no hiding of widget for now.
Edouard Tisserant
parents:
2807
diff
changeset
|
170 |
} |
2881 | 171 |
} |
2808
dc78ffa5253d
SVGHMI: SVG viewport now defined so that HMI take scales and fit to the view. Implemented page switch through viewport change, no hiding of widget for now.
Edouard Tisserant
parents:
2807
diff
changeset
|
172 |
|
2883
8e3d130399b0
SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2881
diff
changeset
|
173 |
def "func:escape_quotes" { |
8e3d130399b0
SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2881
diff
changeset
|
174 |
param "txt"; |
8e3d130399b0
SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2881
diff
changeset
|
175 |
// have to use a python string to enter escaped quote |
8e3d130399b0
SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2881
diff
changeset
|
176 |
const "frst", !"substring-before($txt,'\"')"!; |
8e3d130399b0
SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2881
diff
changeset
|
177 |
const "frstln", "string-length($frst)"; |
8e3d130399b0
SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2881
diff
changeset
|
178 |
choose { |
8e3d130399b0
SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2881
diff
changeset
|
179 |
when "$frstln > 0 and string-length($txt) > $frstln" { |
8e3d130399b0
SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2881
diff
changeset
|
180 |
result !"concat($frst,'\\\"',func:escape_quotes(substring-after($txt,'\"')))"!; |
8e3d130399b0
SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2881
diff
changeset
|
181 |
} |
8e3d130399b0
SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2881
diff
changeset
|
182 |
otherwise { |
8e3d130399b0
SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2881
diff
changeset
|
183 |
result "$txt"; |
8e3d130399b0
SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2881
diff
changeset
|
184 |
} |
8e3d130399b0
SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2881
diff
changeset
|
185 |
} |
8e3d130399b0
SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2881
diff
changeset
|
186 |
} |
8e3d130399b0
SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2881
diff
changeset
|
187 |