author | Edouard Tisserant <edouard.tisserant@gmail.com> |
Wed, 13 May 2020 18:47:09 +0200 | |
branch | svghmi |
changeset 2960 | 5ad82541b46e |
parent 2929 | 9179cbc6fc49 |
child 3001 | 003fd80ff0b8 |
permissions | -rw-r--r-- |
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:
2882
diff
changeset
|
1 |
// widget_input.ysl2 |
2779
75c6a31caca6
SVGHMI: Work In Progress : fixed pointer types in ctypes interface, cleaned up server startup and cleanup code, changed document type to XHTML, cleaner JS script : encapsulated in a function and in CDATA.
Edouard Tisserant
parents:
2763
diff
changeset
|
2 |
|
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:
2882
diff
changeset
|
3 |
template "widget[@type='Input']", mode="widget_defs" { |
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:
2882
diff
changeset
|
4 |
param "hmi_element"; |
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:
2882
diff
changeset
|
5 |
const "value_elt" { |
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:
2882
diff
changeset
|
6 |
optional_labels("value"); |
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:
2882
diff
changeset
|
7 |
} |
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:
2882
diff
changeset
|
8 |
const "have_value","string-length($value_elt)>0"; |
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:
2882
diff
changeset
|
9 |
value "$value_elt"; |
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:
2882
diff
changeset
|
10 |
if "$have_value" |
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:
2882
diff
changeset
|
11 |
| frequency: 5, |
2911
211d6a185e31
SVGHMI: More infrastructure for editing values with a keypad.
Edouard Tisserant
parents:
2910
diff
changeset
|
12 |
| last_val: undefined, |
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:
2882
diff
changeset
|
13 |
| dispatch: function(value) { |
2911
211d6a185e31
SVGHMI: More infrastructure for editing values with a keypad.
Edouard Tisserant
parents:
2910
diff
changeset
|
14 |
| this.last_val = value; |
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:
2882
diff
changeset
|
15 |
if "$have_value" |
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:
2882
diff
changeset
|
16 |
| this.value_elt.textContent = String(value); |
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
|
17 |
|
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:
2882
diff
changeset
|
18 |
| }, |
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:
2882
diff
changeset
|
19 |
const "edit_elt_id","$hmi_element/*[@inkscape:label='edit'][1]/@id"; |
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:
2882
diff
changeset
|
20 |
| init: function() { |
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:
2882
diff
changeset
|
21 |
if "$edit_elt_id" { |
2911
211d6a185e31
SVGHMI: More infrastructure for editing values with a keypad.
Edouard Tisserant
parents:
2910
diff
changeset
|
22 |
| id("«$edit_elt_id»").setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_edit_click()"); |
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:
2882
diff
changeset
|
23 |
} |
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:
2882
diff
changeset
|
24 |
foreach "$hmi_element/*[regexp:test(@inkscape:label,'^[=+\-].+')]" { |
2910
1a1caf71b1cc
SVGHMI: Widget input buttons should be clickable through svg:use (onclick attribute instead of addEventListener)
Edouard Tisserant
parents:
2883
diff
changeset
|
25 |
| id("«@id»").setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_op_click('«func:escape_quotes(@inkscape:label)»')"); |
2792
0c0d3895b036
SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents:
2791
diff
changeset
|
26 |
} |
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:
2882
diff
changeset
|
27 |
| }, |
2910
1a1caf71b1cc
SVGHMI: Widget input buttons should be clickable through svg:use (onclick attribute instead of addEventListener)
Edouard Tisserant
parents:
2883
diff
changeset
|
28 |
| on_op_click: function(opstr) { |
2929
9179cbc6fc49
SVGHMI: fix probable problem in HMI:Input, where value could be applied to wrong index if used in relative page.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2921
diff
changeset
|
29 |
| let orig = this.indexes[0]; |
9179cbc6fc49
SVGHMI: fix probable problem in HMI:Input, where value could be applied to wrong index if used in relative page.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2921
diff
changeset
|
30 |
| let idx = this.offset ? orig - this.offset : orig; |
9179cbc6fc49
SVGHMI: fix probable problem in HMI:Input, where value could be applied to wrong index if used in relative page.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2921
diff
changeset
|
31 |
| let new_val = change_hmi_value(idx, opstr); |
2921
2670f5c53caf
SVGHMI: HMI is not speculating on PLC variable update anymore when sending new variable value.
Edouard Tisserant
parents:
2917
diff
changeset
|
32 |
// if "$have_value"{ |
2670f5c53caf
SVGHMI: HMI is not speculating on PLC variable update anymore when sending new variable value.
Edouard Tisserant
parents:
2917
diff
changeset
|
33 |
// | this.value_elt.textContent = String(new_val); |
2670f5c53caf
SVGHMI: HMI is not speculating on PLC variable update anymore when sending new variable value.
Edouard Tisserant
parents:
2917
diff
changeset
|
34 |
// /* TODO gray out value until refreshed */ |
2670f5c53caf
SVGHMI: HMI is not speculating on PLC variable update anymore when sending new variable value.
Edouard Tisserant
parents:
2917
diff
changeset
|
35 |
// } |
2910
1a1caf71b1cc
SVGHMI: Widget input buttons should be clickable through svg:use (onclick attribute instead of addEventListener)
Edouard Tisserant
parents:
2883
diff
changeset
|
36 |
| }, |
2911
211d6a185e31
SVGHMI: More infrastructure for editing values with a keypad.
Edouard Tisserant
parents:
2910
diff
changeset
|
37 |
| on_edit_click: function(opstr) { |
2917
c8d923dd707f
SVGHMI: Keypad working for HMI_STRING, still Shift/CapsLock not finished.
Edouard Tisserant
parents:
2911
diff
changeset
|
38 |
| edit_value("«path/@value»", "«path/@type»", this, this.last_val); |
2911
211d6a185e31
SVGHMI: More infrastructure for editing values with a keypad.
Edouard Tisserant
parents:
2910
diff
changeset
|
39 |
| }, |
211d6a185e31
SVGHMI: More infrastructure for editing values with a keypad.
Edouard Tisserant
parents:
2910
diff
changeset
|
40 |
|
211d6a185e31
SVGHMI: More infrastructure for editing values with a keypad.
Edouard Tisserant
parents:
2910
diff
changeset
|
41 |
| edit_callback: function(new_val) { |
2929
9179cbc6fc49
SVGHMI: fix probable problem in HMI:Input, where value could be applied to wrong index if used in relative page.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2921
diff
changeset
|
42 |
| let orig = this.indexes[0]; |
9179cbc6fc49
SVGHMI: fix probable problem in HMI:Input, where value could be applied to wrong index if used in relative page.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2921
diff
changeset
|
43 |
| let idx = this.offset ? orig - this.offset : orig; |
9179cbc6fc49
SVGHMI: fix probable problem in HMI:Input, where value could be applied to wrong index if used in relative page.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2921
diff
changeset
|
44 |
| apply_hmi_value(idx, new_val); |
2921
2670f5c53caf
SVGHMI: HMI is not speculating on PLC variable update anymore when sending new variable value.
Edouard Tisserant
parents:
2917
diff
changeset
|
45 |
// if "$have_value"{ |
2670f5c53caf
SVGHMI: HMI is not speculating on PLC variable update anymore when sending new variable value.
Edouard Tisserant
parents:
2917
diff
changeset
|
46 |
// | this.value_elt.textContent = String(new_val); |
2670f5c53caf
SVGHMI: HMI is not speculating on PLC variable update anymore when sending new variable value.
Edouard Tisserant
parents:
2917
diff
changeset
|
47 |
// /* TODO gray out value until refreshed */ |
2670f5c53caf
SVGHMI: HMI is not speculating on PLC variable update anymore when sending new variable value.
Edouard Tisserant
parents:
2917
diff
changeset
|
48 |
// } |
2911
211d6a185e31
SVGHMI: More infrastructure for editing values with a keypad.
Edouard Tisserant
parents:
2910
diff
changeset
|
49 |
| }, |
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:
diff
changeset
|
50 |
} |