svghmi/widgets_common.ysl2
branchsvghmi
changeset 2920 3ee337c8c769
parent 2897 bf8a39cc65e4
child 2937 9226a830fbc3
equal deleted inserted replaced
2919:c6e6051898f5 2920:3ee337c8c769
     7 
     7 
     8 in xsl decl optional_labels(*ptr, name="defs_by_labels") alias call-template {
     8 in xsl decl optional_labels(*ptr, name="defs_by_labels") alias call-template {
     9     with "hmi_element", "$hmi_element";
     9     with "hmi_element", "$hmi_element";
    10     with "labels"{text *ptr};
    10     with "labels"{text *ptr};
    11     with "mandatory","'no'";
    11     with "mandatory","'no'";
       
    12 };
       
    13 
       
    14 in xsl decl activable_labels(*ptr, name="defs_by_labels") alias call-template {
       
    15     with "hmi_element", "$hmi_element";
       
    16     with "labels"{text *ptr};
       
    17     with "mandatory","'no'";
       
    18     with "subelements","'active inactive'";
    12 };
    19 };
    13 
    20 
    14 template "svg:*", mode="hmi_elements" {
    21 template "svg:*", mode="hmi_elements" {
    15     const "widget", "func:widget(@id)";
    22     const "widget", "func:widget(@id)";
    16     const "eltid","@id";
    23     const "eltid","@id";
    49 template "widget[@type='Page']", mode="widget_subscribe";
    56 template "widget[@type='Page']", mode="widget_subscribe";
    50 
    57 
    51 function "defs_by_labels" {
    58 function "defs_by_labels" {
    52     param "labels","''";
    59     param "labels","''";
    53     param "mandatory","'yes'";
    60     param "mandatory","'yes'";
       
    61     param "subelements","/..";
    54     param "hmi_element";
    62     param "hmi_element";
    55     const "widget_type","@type";
    63     const "widget_type","@type";
    56     foreach "str:split($labels)" {
    64     foreach "str:split($labels)" {
    57         const "name",".";
    65         const "name",".";
    58         const "elt_id","$result_svg_ns//*[@id = $hmi_element/@id]//*[@inkscape:label=$name][1]/@id";
    66         const "elt","$result_svg_ns//*[@id = $hmi_element/@id]//*[@inkscape:label=$name][1]";
    59         choose {
    67         choose {
    60             when "not($elt_id)" {
    68             when "not($elt/@id)" {
    61                 if "$mandatory='yes'" {
    69                 if "$mandatory='yes'" {
    62                     // TODO FIXME error > «$widget_type» widget must have a «$name» element
    70                     error > «$widget_type» widget must have a «$name» element
    63                     warning > «$widget_type» widget must have a «$name» element
       
    64                 }
    71                 }
    65                 // otherwise produce nothing
    72                 // otherwise produce nothing
    66             }
    73             }
    67             otherwise {
    74             otherwise {
    68                 |     «$name»_elt: id("«$elt_id»"),
    75                 |     «$name»_elt: id("«$elt/@id»"),
       
    76                 if "$subelements" {
       
    77                 |     «$name»_sub: {
       
    78                     foreach "str:split($subelements)" {
       
    79                         const "subname",".";
       
    80                         const "subelt","$elt/*[@inkscape:label=$subname][1]";
       
    81                         choose {
       
    82                             when "not($subelt/@id)" {
       
    83                                 if "$mandatory='yes'" {
       
    84                                     error > «$widget_type» widget must have a «$name»/«$subname» element
       
    85                                 }
       
    86                 |         /* missing «$name»/«$subname» element */
       
    87                             }
       
    88                             otherwise {
       
    89                 |         "«$subname»": id("«$subelt/@id»")`if "position()!=last()" > ,`
       
    90                             }
       
    91                         }
       
    92                     }
       
    93                 |     },
       
    94                 }
    69             }
    95             }
    70         }
    96         }
    71     }
    97     }
    72 }
    98 }
    73 
    99