svghmi/widget_page.ysl2
author Edouard Tisserant <edouard.tisserant@gmail.com>
Fri, 05 Apr 2024 14:55:58 +0200
changeset 3929 1a0bed0b4f1c
parent 3685 570a738239f4
child 3921 9bb17341aebb
permissions -rw-r--r--
Doc: start converting Standard Library documentation from old MC8 manual.
3685
570a738239f4 SVGHMI: Add arbitrary variable assignment when entering Pages
Edouard Tisserant
parents: 3627
diff changeset
     1
// widget_page.ysl2
3627
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
     2
3685
570a738239f4 SVGHMI: Add arbitrary variable assignment when entering Pages
Edouard Tisserant
parents: 3627
diff changeset
     3
widget_desc("Page") {
3627
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
     4
    longdesc
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
     5
    ||
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
     6
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
     7
    Arguments are either:
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
     8
3685
570a738239f4 SVGHMI: Add arbitrary variable assignment when entering Pages
Edouard Tisserant
parents: 3627
diff changeset
     9
    - XXX reference path TODO
570a738239f4 SVGHMI: Add arbitrary variable assignment when entering Pages
Edouard Tisserant
parents: 3627
diff changeset
    10
3627
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
    11
    - name=value: setting variable with literal value.
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
    12
    - name=other_name: copy variable content into another
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
    13
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
    14
    "active"+"inactive" labeled elements can be provided to show feedback when pressed
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
    15
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
    16
    Exemples:
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
    17
3685
570a738239f4 SVGHMI: Add arbitrary variable assignment when entering Pages
Edouard Tisserant
parents: 3627
diff changeset
    18
    HMI:Page:notify=1@notify=/PLCVAR
570a738239f4 SVGHMI: Add arbitrary variable assignment when entering Pages
Edouard Tisserant
parents: 3627
diff changeset
    19
    HMI:Page:ack=2:notify=1@ack=.local_var@notify=/PLCVAR
3627
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
    20
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
    21
    ||
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
    22
3685
570a738239f4 SVGHMI: Add arbitrary variable assignment when entering Pages
Edouard Tisserant
parents: 3627
diff changeset
    23
    shortdesc > Page 
3627
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
    24
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
    25
}
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
    26
3685
570a738239f4 SVGHMI: Add arbitrary variable assignment when entering Pages
Edouard Tisserant
parents: 3627
diff changeset
    27
widget_defs("Page") {
3627
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
    28
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
    29
    |     assignments: {},
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
    30
    |     dispatch: function(value, oldval, varnum) {
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
    31
    const "widget", ".";
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
    32
    foreach "path" {
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
    33
        const "varid","generate-id()";
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
    34
        const "varnum","position()-1";
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
    35
        if "@assign" foreach "$widget/path[@assign]" if "$varid = generate-id()" {
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
    36
    |         if(varnum == «$varnum») this.assignments["«@assign»"] = value;
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
    37
        }
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
    38
    }
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
    39
    |     },
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
    40
    |     assign: function() {
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
    41
    const "paths","path";
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
    42
    foreach "arg[contains(@value,'=')]"{
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
    43
        const "name","substring-before(@value,'=')";
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
    44
        const "value","substring-after(@value,'=')";
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
    45
        const "index" foreach "$paths" if "@assign = $name" value "position()-1";
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
    46
        const "isVarName", "regexp:test($value,'^[a-zA-Z_][a-zA-Z0-9_]+$')";
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
    47
        choose {
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
    48
            when "$isVarName"{
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
    49
    |         const «$value» = this.assignments["«$value»"];
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
    50
    |         if(«$value» != undefined)
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
    51
    |             this.apply_hmi_value(«$index», «$value»);
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
    52
            }
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
    53
            otherwise {
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
    54
    |         this.apply_hmi_value(«$index», «$value»);
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
    55
            }
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
    56
        }
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
    57
    }
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
    58
    |     },
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
    59
}
1b627c2c743c SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff changeset
    60