svghmi/widget_input.ysl2
author Edouard Tisserant
Tue, 07 Apr 2020 10:01:23 +0200
branchsvghmi
changeset 2921 2670f5c53caf
parent 2917 c8d923dd707f
child 2929 9179cbc6fc49
permissions -rw-r--r--
SVGHMI: HMI is not speculating on PLC variable update anymore when sending new variable value.

HMI variable cache in JS was changed in advance for more responsive behaviour when updating a HMI tree variable. This was leading to display value different from hmi tree variable in case the expected update did not happen because PLC program did revert it.
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) {
1a1caf71b1cc SVGHMI: Widget input buttons should be clickable through svg:use (onclick attribute instead of addEventListener)
Edouard Tisserant
parents: 2883
diff changeset
    29
    |         let new_val = change_hmi_value(this.indexes[0], opstr);
2921
2670f5c53caf SVGHMI: HMI is not speculating on PLC variable update anymore when sending new variable value.
Edouard Tisserant
parents: 2917
diff changeset
    30
    //     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
    31
    // |         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
    32
    //           /* 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
    33
    //     }
2910
1a1caf71b1cc SVGHMI: Widget input buttons should be clickable through svg:use (onclick attribute instead of addEventListener)
Edouard Tisserant
parents: 2883
diff changeset
    34
    |     },
2911
211d6a185e31 SVGHMI: More infrastructure for editing values with a keypad.
Edouard Tisserant
parents: 2910
diff changeset
    35
    |     on_edit_click: function(opstr) {
2917
c8d923dd707f SVGHMI: Keypad working for HMI_STRING, still Shift/CapsLock not finished.
Edouard Tisserant
parents: 2911
diff changeset
    36
    |         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
    37
    |     },
211d6a185e31 SVGHMI: More infrastructure for editing values with a keypad.
Edouard Tisserant
parents: 2910
diff changeset
    38
211d6a185e31 SVGHMI: More infrastructure for editing values with a keypad.
Edouard Tisserant
parents: 2910
diff changeset
    39
    |     edit_callback: function(new_val) {
2917
c8d923dd707f SVGHMI: Keypad working for HMI_STRING, still Shift/CapsLock not finished.
Edouard Tisserant
parents: 2911
diff changeset
    40
    |         apply_hmi_value(this.indexes[0], 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
    41
    //     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
    42
    // |         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
    43
    //           /* 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
    44
    //     }
2911
211d6a185e31 SVGHMI: More infrastructure for editing values with a keypad.
Edouard Tisserant
parents: 2910
diff changeset
    45
    |     },
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
    46
}