svghmi/gen_index_xhtml.xslt
branchsvghmi
changeset 2834 6ac6a9dff594
parent 2833 e74123b966ac
child 2836 ce6cecdb7320
equal deleted inserted replaced
2833:e74123b966ac 2834:6ac6a9dff594
   228       <xsl:text>    indexes: [
   228       <xsl:text>    indexes: [
   229 </xsl:text>
   229 </xsl:text>
   230       <xsl:for-each select="$widget/path">
   230       <xsl:for-each select="$widget/path">
   231         <xsl:variable name="hmipath" select="@value"/>
   231         <xsl:variable name="hmipath" select="@value"/>
   232         <xsl:variable name="hmitree_match" select="$indexed_hmitree/*[@hmipath = $hmipath]"/>
   232         <xsl:variable name="hmitree_match" select="$indexed_hmitree/*[@hmipath = $hmipath]"/>
   233         <xsl:if test="count($hmitree_match) = 0">
   233         <xsl:choose>
   234           <xsl:message terminate="yes">
   234           <xsl:when test="count($hmitree_match) = 0">
   235             <xsl:text>No match for path "</xsl:text>
   235             <xsl:message terminate="no">
   236             <xsl:value-of select="$hmipath"/>
   236               <xsl:text>No match for path "</xsl:text>
   237             <xsl:text>" in HMI tree</xsl:text>
   237               <xsl:value-of select="$hmipath"/>
   238           </xsl:message>
   238               <xsl:text>" in HMI tree</xsl:text>
   239         </xsl:if>
   239             </xsl:message>
   240         <xsl:text>        </xsl:text>
   240           </xsl:when>
   241         <xsl:value-of select="$hmitree_match/@index"/>
   241           <xsl:otherwise>
   242         <xsl:if test="position()!=last()">
   242             <xsl:text>        </xsl:text>
   243           <xsl:text>,</xsl:text>
   243             <xsl:value-of select="$hmitree_match/@index"/>
   244         </xsl:if>
   244             <xsl:if test="position()!=last()">
   245         <xsl:text>
   245               <xsl:text>,</xsl:text>
   246 </xsl:text>
   246             </xsl:if>
       
   247             <xsl:text>
       
   248 </xsl:text>
       
   249           </xsl:otherwise>
       
   250         </xsl:choose>
   247       </xsl:for-each>
   251       </xsl:for-each>
   248       <xsl:text>    ],
   252       <xsl:text>    ],
   249 </xsl:text>
   253 </xsl:text>
   250       <xsl:text>    element: document.getElementById("</xsl:text>
   254       <xsl:text>    element: document.getElementById("</xsl:text>
   251       <xsl:value-of select="@id"/>
   255       <xsl:value-of select="@id"/>
   358 </xsl:text>
   362 </xsl:text>
   359     <xsl:text>
   363     <xsl:text>
   360 </xsl:text>
   364 </xsl:text>
   361     <xsl:text>function dispatch_value_to_widget(widget, index, value, oldval) {
   365     <xsl:text>function dispatch_value_to_widget(widget, index, value, oldval) {
   362 </xsl:text>
   366 </xsl:text>
   363     <xsl:text>    let idxidx = widget.indexes.indexOf(index);
   367     <xsl:text>    try {
   364 </xsl:text>
   368 </xsl:text>
   365     <xsl:text>    if(idxidx == -1){
   369     <xsl:text>        let idxidx = widget.indexes.indexOf(index);
   366 </xsl:text>
   370 </xsl:text>
   367     <xsl:text>        throw new Error("Dispatching to widget not interested, should not happen.");
   371     <xsl:text>        let d = widget.dispatch;
       
   372 </xsl:text>
       
   373     <xsl:text>        if(typeof(d) == "function" &amp;&amp; idxidx == 0){
       
   374 </xsl:text>
       
   375     <xsl:text>            d.call(widget, value, oldval);
       
   376 </xsl:text>
       
   377     <xsl:text>        }else if(typeof(d) == "object" &amp;&amp; d.length &gt;= idxidx){
       
   378 </xsl:text>
       
   379     <xsl:text>            d[idxidx].call(widget, value, oldval);
       
   380 </xsl:text>
       
   381     <xsl:text>        }/* else dispatch_0, ..., dispatch_n ? */
       
   382 </xsl:text>
       
   383     <xsl:text>        /*else {
       
   384 </xsl:text>
       
   385     <xsl:text>            throw new Error("Dunno how to dispatch to widget at index = " + index);
       
   386 </xsl:text>
       
   387     <xsl:text>        }*/
   368 </xsl:text>
   388 </xsl:text>
   369     <xsl:text>    }
   389     <xsl:text>    }
   370 </xsl:text>
   390 </xsl:text>
   371     <xsl:text>    let d = widget.dispatch;
       
   372 </xsl:text>
       
   373     <xsl:text>    if(typeof(d) == "function" &amp;&amp; idxidx == 0){
       
   374 </xsl:text>
       
   375     <xsl:text>        return d.call(widget, value, oldval);
       
   376 </xsl:text>
       
   377     <xsl:text>    }else if(typeof(d) == "object" &amp;&amp; d.length &gt;= idxidx){
       
   378 </xsl:text>
       
   379     <xsl:text>        return d[idxidx].call(widget, value, oldval);
       
   380 </xsl:text>
       
   381     <xsl:text>    }/* else dispatch_0, ..., dispatch_n ? */
       
   382 </xsl:text>
       
   383     <xsl:text>    /*else {
       
   384 </xsl:text>
       
   385     <xsl:text>        throw new Error("Dunno how to dispatch to widget at index = " + index);
       
   386 </xsl:text>
       
   387     <xsl:text>    }*/
       
   388 </xsl:text>
       
   389     <xsl:text>}
   391     <xsl:text>}
   390 </xsl:text>
   392 </xsl:text>
   391     <xsl:text>
   393     <xsl:text>
   392 </xsl:text>
   394 </xsl:text>
   393     <xsl:text>function dispatch_value(index, value) {
   395     <xsl:text>function dispatch_value(index, value) {
   424 </xsl:text>
   426 </xsl:text>
   425     <xsl:text>        let init = widget.init;
   427     <xsl:text>        let init = widget.init;
   426 </xsl:text>
   428 </xsl:text>
   427     <xsl:text>        if(typeof(init) == "function"){
   429     <xsl:text>        if(typeof(init) == "function"){
   428 </xsl:text>
   430 </xsl:text>
   429     <xsl:text>            return init.call(widget);
   431     <xsl:text>            try {
       
   432 </xsl:text>
       
   433     <xsl:text>                init.call(widget);
       
   434 </xsl:text>
       
   435     <xsl:text>            } catch(err) {
       
   436 </xsl:text>
       
   437     <xsl:text>                console.log("Widget initialization error : "+err.message);
       
   438 </xsl:text>
       
   439     <xsl:text>
       
   440 </xsl:text>
       
   441     <xsl:text>            }
   430 </xsl:text>
   442 </xsl:text>
   431     <xsl:text>        }
   443     <xsl:text>        }
   432 </xsl:text>
   444 </xsl:text>
   433     <xsl:text>    });
   445     <xsl:text>    });
   434 </xsl:text>
   446 </xsl:text>
   911   </xsl:template>
   923   </xsl:template>
   912   <xsl:template name="defs_by_labels">
   924   <xsl:template name="defs_by_labels">
   913     <xsl:param name="labels" select="''"/>
   925     <xsl:param name="labels" select="''"/>
   914     <xsl:param name="mandatory" select="'yes'"/>
   926     <xsl:param name="mandatory" select="'yes'"/>
   915     <xsl:param name="hmi_element"/>
   927     <xsl:param name="hmi_element"/>
       
   928     <xsl:variable name="widget_type" select="@type"/>
   916     <xsl:for-each select="str:split($labels)">
   929     <xsl:for-each select="str:split($labels)">
   917       <xsl:variable name="name" select="."/>
   930       <xsl:variable name="name" select="."/>
   918       <xsl:variable name="elt_id" select="$hmi_element//*[@inkscape:label=$name][1]/@id"/>
   931       <xsl:variable name="elt_id" select="$hmi_element//*[@inkscape:label=$name][1]/@id"/>
   919       <xsl:if test="$mandatory='yes' and not($elt_id)">
   932       <xsl:if test="$mandatory='yes' and not($elt_id)">
   920         <xsl:message terminate="yes">
   933         <xsl:message terminate="no">
   921           <xsl:text>Meter widget must have a </xsl:text>
   934           <xsl:value-of select="$widget_type"/>
       
   935           <xsl:text> widget must have a </xsl:text>
   922           <xsl:value-of select="$name"/>
   936           <xsl:value-of select="$name"/>
   923           <xsl:text> element</xsl:text>
   937           <xsl:text> element</xsl:text>
   924         </xsl:message>
   938         </xsl:message>
   925       </xsl:if>
   939       </xsl:if>
   926       <xsl:value-of select="$name"/>
   940       <xsl:value-of select="$name"/>
   940       <xsl:when test="$hmi_element[self::svg:text]">
   954       <xsl:when test="$hmi_element[self::svg:text]">
   941         <xsl:text>  this.element.textContent = String(value);
   955         <xsl:text>  this.element.textContent = String(value);
   942 </xsl:text>
   956 </xsl:text>
   943       </xsl:when>
   957       </xsl:when>
   944       <xsl:otherwise>
   958       <xsl:otherwise>
   945         <xsl:message terminate="yes">
   959         <xsl:message terminate="no">
   946           <xsl:text>Display widget as a group not implemented</xsl:text>
   960           <xsl:text>Display widget as a group not implemented</xsl:text>
   947         </xsl:message>
   961         </xsl:message>
   948       </xsl:otherwise>
   962       </xsl:otherwise>
   949     </xsl:choose>
   963     </xsl:choose>
   950     <xsl:text>},
   964     <xsl:text>},