svghmi/gen_index_xhtml.ysl2
branchsvghmi
changeset 2852 f7349ca820c9
parent 2851 8d15c6238e62
child 2853 6d39beb19f38
equal deleted inserted replaced
2851:8d15c6238e62 2852:f7349ca820c9
   482         */
   482         */
   483 
   483 
   484         | var hmi_widgets = {
   484         | var hmi_widgets = {
   485         foreach "$hmi_elements" {
   485         foreach "$hmi_elements" {
   486             const "widget", "func:parselabel(@inkscape:label)/widget";
   486             const "widget", "func:parselabel(@inkscape:label)/widget";
   487         |     "«@id»": {
   487         |   "«@id»": {
   488         |         type: "«$widget/@type»",
   488         |     type: "«$widget/@type»",
   489         |         args: [
   489         |     args: [
   490             foreach "$widget/arg"
   490             foreach "$widget/arg"
   491         |             "«@value»"`if "position()!=last()" > ,`
   491         |         "«@value»"`if "position()!=last()" > ,`
   492         |         ],
   492         |     ],
   493         |         indexes: [
   493         |     indexes: [
   494             foreach "$widget/path" {
   494             foreach "$widget/path" {
   495                 const "hmipath","@value";
   495                 const "hmipath","@value";
   496                 const "hmitree_match","$indexed_hmitree/*[@hmipath = $hmipath]";
   496                 const "hmitree_match","$indexed_hmitree/*[@hmipath = $hmipath]";
   497                 choose {
   497                 choose {
   498                     when "count($hmitree_match) = 0" {
   498                     when "count($hmitree_match) = 0" {
   539 
   539 
   540             const "all_page_ids","$page_all_elements[@id = $hmi_elements/@id and @id != $page/@id]/@id";
   540             const "all_page_ids","$page_all_elements[@id = $hmi_elements/@id and @id != $page/@id]/@id";
   541 
   541 
   542             const "required_detachables", "func:sumarized_elements($page_all_elements)";
   542             const "required_detachables", "func:sumarized_elements($page_all_elements)";
   543 
   543 
   544             |     "«$desc/arg[1]/@value»": {
   544             |   "«$desc/arg[1]/@value»": {
   545             |         widget: hmi_widgets["«@id»"],
   545             |     widget: hmi_widgets["«@id»"],
   546             |         bbox: [«$p/@x», «$p/@y», «$p/@w», «$p/@h»],
   546             |     bbox: [«$p/@x», «$p/@y», «$p/@w», «$p/@h»],
   547             |         widgets: [
   547             |     widgets: [
   548             foreach "$all_page_ids" {
   548             foreach "$all_page_ids" {
   549             |             hmi_widgets["«.»"]`if "position()!=last()" > ,`
   549             |         hmi_widgets["«.»"]`if "position()!=last()" > ,`
   550             }
   550             }
   551             |         ],
   551             |     ],
   552             |         required_detachables: {
   552             |     required_detachables: {
   553             foreach "$required_detachables" {
   553             foreach "$required_detachables" {
   554             |             "«@id»": detachable_elements["«@id»"]`if "position()!=last()" > ,`
   554             |         "«@id»": detachable_elements["«@id»"]`if "position()!=last()" > ,`
   555             }
   555             }
   556             |         }
   556             |     }
   557             |     }`if "position()!=last()" > ,`
   557             |   }`if "position()!=last()" > ,`
   558         }
   558         }
   559         | }
   559         | }
   560 
   560 
   561         |
   561         |
   562         | var default_page = "«$default_page»";
   562         | var default_page = "«$default_page»";
   627                         warning > «$widget_type» widget must have a «$name» element
   627                         warning > «$widget_type» widget must have a «$name» element
   628                     }
   628                     }
   629                     // otherwise produce nothing 
   629                     // otherwise produce nothing 
   630                 }
   630                 }
   631                 otherwise {
   631                 otherwise {
   632                     | «$name»_elt: id("«$elt_id»"),
   632                     |     «$name»_elt: id("«$elt_id»"),
   633                 }
   633                 }
   634             }
   634             }
   635         }
   635         }
   636     }
   636     }
   637 
   637 
   638 
   638 
   639     template "widget[@type='Display']", mode="widget_defs" {
   639     template "widget[@type='Display']", mode="widget_defs" {
   640         param "hmi_element";
   640         param "hmi_element";
   641         | frequency: 5,
   641         |     frequency: 5,
   642         | dispatch: function(value) {
   642         |     dispatch: function(value) {
   643         choose {
   643         choose {
   644             when "$hmi_element[self::svg:text]"{
   644             when "$hmi_element[self::svg:text]"{
   645             // TODO : care about <tspan> ?
   645             // TODO : care about <tspan> ?
   646         |   this.element.textContent = String(value);
   646         |       this.element.textContent = String(value);
   647             }
   647             }
   648             otherwise {
   648             otherwise {
   649                 warning > Display widget as a group not implemented
   649                 warning > Display widget as a group not implemented
   650             }
   650             }
   651         }
   651         }
   652         | },
   652         |     },
   653 
   653 
   654     }
   654     }
   655     template "widget[@type='Meter']", mode="widget_defs" {
   655     template "widget[@type='Meter']", mode="widget_defs" {
   656         param "hmi_element";
   656         param "hmi_element";
   657         | frequency: 10,
   657         |     frequency: 10,
   658         labels("value min max needle range");
   658         labels("value min max needle range");
   659         | dispatch: function(value) {
   659         |     dispatch: function(value) {
   660         |     this.value_elt.textContent = String(value);
   660         |         this.value_elt.textContent = String(value);
   661         |     let [min,max,totallength] = this.range;
   661         |         let [min,max,totallength] = this.range;
   662         |     let length = Math.max(0,Math.min(totallength,(Number(value)-min)*totallength/(max-min)));
   662         |         let length = Math.max(0,Math.min(totallength,(Number(value)-min)*totallength/(max-min)));
   663         |     let tip = this.range_elt.getPointAtLength(length);
   663         |         let tip = this.range_elt.getPointAtLength(length);
   664         // TODO : deal with transformations between needle and range
   664         |         this.needle_elt.setAttribute('d', "M "+this.origin.x+","+this.origin.y+" "+tip.x+","+tip.y);
   665         |     this.needle_elt.setAttribute('d', "M "+this.origin.x+","+this.origin.y+" "+tip.x+","+tip.y);
   665         |     },
   666         | },
   666         |     origin: undefined,
   667         | origin: undefined,
   667         |     range: undefined,
   668         | range: undefined,
   668         |     init: function() {
   669         | init: function() {
   669         |         this.range = [Number(this.min_elt.textContent), Number(this.max_elt.textContent), this.range_elt.getTotalLength()]
   670         |     this.range = [Number(this.min_elt.textContent), Number(this.max_elt.textContent), this.range_elt.getTotalLength()]
   670         |         this.origin = this.needle_elt.getPointAtLength(0);
   671         |     this.origin = this.needle_elt.getPointAtLength(0);
   671         |     },
   672         | },
       
   673     }
   672     }
   674 
   673 
   675     def "func:escape_quotes" {
   674     def "func:escape_quotes" {
   676         param "txt";
   675         param "txt";
   677         // have to use a python string to enter escaped quote
   676         // have to use a python string to enter escaped quote