edouard@2884: // widgets_common.ysl2 edouard@2884: Edouard@2808: in xsl decl labels(*ptr, name="defs_by_labels") alias call-template { Edouard@2808: with "hmi_element", "$hmi_element"; Edouard@2810: with "labels"{text *ptr}; Edouard@2808: }; Edouard@2808: Edouard@2836: in xsl decl optional_labels(*ptr, name="defs_by_labels") alias call-template { Edouard@2836: with "hmi_element", "$hmi_element"; Edouard@2836: with "labels"{text *ptr}; Edouard@2836: with "mandatory","'no'"; Edouard@2836: }; Edouard@2836: Edouard@2881: template "svg:*", mode="hmi_elements" { edouard@2886: const "widget", "func:widget(@id)"; Edouard@2881: const "eltid","@id"; Edouard@2881: | "«@id»": { Edouard@2881: | type: "«$widget/@type»", Edouard@2881: | args: [ edouard@2889: foreach "$widget/arg" Edouard@2881: | "«@value»"`if "position()!=last()" > ,` Edouard@2881: | ], edouard@2889: | offset: 0, Edouard@2881: | indexes: [ Edouard@2881: foreach "$widget/path" { Edouard@2881: choose { Edouard@2881: when "not(@index)" { Edouard@2881: warning > Widget «$widget/@type» id="«$eltid»" : No match for path "«@value»" in HMI tree Edouard@2881: } Edouard@2881: otherwise { Edouard@2893: | «@index» /* «@value» */ `if "position()!=last()" > ,` Edouard@2792: } Edouard@2792: } Edouard@2792: } Edouard@2881: | ], Edouard@2881: | element: id("«@id»"), Edouard@2881: apply "$widget", mode="widget_defs" with "hmi_element","."; edouard@2889: apply "$widget", mode="widget_subscribe" with "hmi_element","."; Edouard@2881: | }`if "position()!=last()" > ,` Edouard@2881: } Edouard@2810: edouard@2889: // default : normal subscribing edouard@2889: template "widget", mode="widget_subscribe" { edouard@2889: | sub: subscribe, edouard@2889: | unsub: unsubscribe, Edouard@2897: | apply_cache: widget_apply_cache, edouard@2889: } edouard@2889: // page aren't subscribers edouard@2889: template "widget[@type='Page']", mode="widget_subscribe"; Edouard@2793: Edouard@2881: function "defs_by_labels" { Edouard@2881: param "labels","''"; Edouard@2881: param "mandatory","'yes'"; Edouard@2881: param "hmi_element"; Edouard@2881: const "widget_type","@type"; Edouard@2881: foreach "str:split($labels)" { Edouard@2881: const "name","."; Edouard@2881: const "elt_id","$result_svg_ns//*[@id = $hmi_element/@id]//*[@inkscape:label=$name][1]/@id"; Edouard@2881: choose { Edouard@2881: when "not($elt_id)" { Edouard@2881: if "$mandatory='yes'" { Edouard@2881: // TODO FIXME error > «$widget_type» widget must have a «$name» element Edouard@2881: warning > «$widget_type» widget must have a «$name» element Edouard@2834: } Edouard@2881: // otherwise produce nothing Edouard@2797: } Edouard@2881: otherwise { Edouard@2881: | «$name»_elt: id("«$elt_id»"), Edouard@2836: } Edouard@2808: } Edouard@2808: } Edouard@2881: } Edouard@2808: edouard@2883: def "func:escape_quotes" { edouard@2883: param "txt"; edouard@2883: // have to use a python string to enter escaped quote edouard@2883: const "frst", !"substring-before($txt,'\"')"!; edouard@2883: const "frstln", "string-length($frst)"; edouard@2883: choose { edouard@2883: when "$frstln > 0 and string-length($txt) > $frstln" { edouard@2883: result !"concat($frst,'\\\"',func:escape_quotes(substring-after($txt,'\"')))"!; edouard@2883: } edouard@2883: otherwise { edouard@2883: result "$txt"; edouard@2883: } edouard@2883: } edouard@2883: } edouard@2883: