svghmi/gen_index_xhtml.ysl2
branchsvghmi
changeset 2854 c7d5f46cc306
parent 2853 6d39beb19f38
child 2855 525211a54b14
equal deleted inserted replaced
2853:6d39beb19f38 2854:c7d5f46cc306
    13     with "labels"{text *ptr};
    13     with "labels"{text *ptr};
    14     with "mandatory","'no'";
    14     with "mandatory","'no'";
    15 };
    15 };
    16 
    16 
    17 in xsl decl svgtmpl(match, xmlns="http://www.w3.org/2000/svg") alias template;
    17 in xsl decl svgtmpl(match, xmlns="http://www.w3.org/2000/svg") alias template;
       
    18 in xsl decl svgfunc(name, xmlns="http://www.w3.org/2000/svg") alias template;
    18 
    19 
    19 istylesheet
    20 istylesheet
    20             /* From Inkscape */
    21             /* From Inkscape */
    21             xmlns:dc="http://purl.org/dc/elements/1.1/"
    22             xmlns:dc="http://purl.org/dc/elements/1.1/"
    22             xmlns:cc="http://creativecommons.org/ns#"
    23             xmlns:cc="http://creativecommons.org/ns#"
    27             xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
    28             xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
    28             xmlns:xhtml="http://www.w3.org/1999/xhtml"
    29             xmlns:xhtml="http://www.w3.org/1999/xhtml"
    29 
    30 
    30             /* Our namespace to invoke python code */
    31             /* Our namespace to invoke python code */
    31             xmlns:ns="beremiz"
    32             xmlns:ns="beremiz"
    32             extension-element-prefixes="ns func"
    33             extension-element-prefixes="ns func exsl regexp str dyn"
    33             exclude-result-prefixes="ns str regexp exsl func" {
    34             exclude-result-prefixes="ns str regexp exsl func dyn" {
    34 
    35 
    35     /* This retrieves geometry obtained through "inkscape -S"
    36     /* This retrieves geometry obtained through "inkscape -S"
    36      * already parsed by python and presented as a list of
    37      * already parsed by python and presented as a list of
    37      * <bbox x="0" y="0" w="42" h="42">
    38      * <bbox x="0" y="0" w="42" h="42">
    38      */
    39      */
   328     // ensure that coordinate in CSV file generated by inkscape match svg default unit
   329     // ensure that coordinate in CSV file generated by inkscape match svg default unit
   329     template "sodipodi:namedview[@units!='px' or @inkscape:document-units!='px']", mode="inline_svg" {
   330     template "sodipodi:namedview[@units!='px' or @inkscape:document-units!='px']", mode="inline_svg" {
   330         error > All units must be set to "px" in Inkscape's document properties
   331         error > All units must be set to "px" in Inkscape's document properties
   331     }
   332     }
   332 
   333 
   333     
   334 
   334     //// Commented out before implementing runtime DOM remove/append on page switch - would have side effect
   335     //////////////// Clone Unlinking
   335     ////
   336 
   336     //// /* clone unlinkink until widget for better perf with webkit */
   337     // svg:use (inkscape's clones) inside a widgets are
   337     //// svgtmpl "svg:use", mode="inline_svg" 
   338     // replaced by real elements they refer in order to :
   338     //// {
   339     //  - allow finding "needle" element in "meter" widget,
   339     ////     g{
   340     //    even if "needle" is in a group refered by a svg use.
   340     ////         attrib "style" > «@style»
   341     //  - if "needle" is visible through a svg:use for
   341     ////         attrib "transform" > «@transform»
   342     //    each instance of the widget, then needle would show
   342     ////         /* keep same id and label in case it is a widget */
   343     //    the same position in all instances
   343     ////         //attrib "inkscape:label","@inkscape:label";
   344     //
   344     ////         attrib "id" > «@id»
   345     // For now, clone unlinkink applies to descendants of all widget except HMI:Page
   345     ////         const "targetid","substring-after(@xlink:href,'#')";
   346     // TODO: narrow application of clone unlinking to active elements,
   346     ////         apply "//svg:*[@id = $targetid]", mode="unlink_clone";
   347     //       while keeping static decoration cloned
   347     ////     }
   348     const "to_unlink", "$hmi_elements[not(@id = $hmi_pages)]//svg:use";
   348     //// }
   349     svgtmpl "svg:use", mode="inline_svg"
   349     //// svgtmpl "@*", mode="unlink_clone" xsl:copy;
   350     {
   350     //// svgtmpl "svg:*", mode="unlink_clone" {
   351         choose {
   351     ////     choose {
   352             when "@id = $to_unlink/@id"
   352     ////         when "@id = $hmi_elements/@id" {
   353                 call "unlink_clone";
   353     ////             use{
   354             otherwise
   354     ////                 attrib "xlink:href" > «concat('#',@id)»
   355                 xsl:copy apply "@* | node()", mode="inline_svg";
   355     ////             }
   356         }
   356     ////         }
   357     }
   357     ////         otherwise {
   358 
   358     ////             xsl:copy apply "@* | node()", mode="unlink_clone";
   359     // to unlink a clone, an group containing a copy of target element is created
   359     ////         }
   360     // that way, style and transforms can be preserved
   360     ////     }
   361     const "_excluded_use_attrs" {
   361     //// }
   362         name > href
   362 
   363         name > width
   363     // template "svg:use/@style", mode="inline_svg"{
   364         name > height
   364     //     attrib "style" > all:initial;
   365         name > x
   365     //     //«.»
   366         name > y
   366     // }
   367     }
   367 
   368     const "excluded_use_attrs","exsl:node-set($_excluded_use_attrs)";
   368     // template "svg:*[concat('#',@id) = //svg:use/@xlink:href]/@style", mode="inline_svg"{
   369 
   369     //     attrib "style" > all:unset;
   370     svgfunc "unlink_clone"{
   370     //     //«.»
   371         g{
   371     // }
   372             // include non excluded attributes
       
   373             foreach "@*[not(local-name() = $excluded_use_attrs/name)]"
       
   374                 attrib "{name()}" > «.»
       
   375 
       
   376             const "targetid","substring-after(@xlink:href,'#')";
       
   377             apply "//svg:*[@id = $targetid]", mode="unlink_clone"{
       
   378                 with "seed","@id";
       
   379             }
       
   380         }
       
   381     }
       
   382 
       
   383     // clone unlinking is really similar to deep-copy
       
   384     // all nodes are sytematically copied
       
   385     svgtmpl "@id", mode="unlink_clone" {
       
   386         param "seed";
       
   387         attrib "id" > «$seed»_«.»
       
   388     }
       
   389 
       
   390     svgtmpl "@*", mode="unlink_clone" xsl:copy;
       
   391 
       
   392     // copying widgets would have unwanted effect
       
   393     // instead widget is refered through a svg:use.
       
   394     svgtmpl "svg:*", mode="unlink_clone" {
       
   395         param "seed";
       
   396         choose {
       
   397             // node recursive copy ends when finding a widget
       
   398             when "@id = $hmi_elements/@id" {
       
   399                 // place a clone instead of copying
       
   400                 use{
       
   401                     attrib "xlink:href" > «concat('#',@id)»
       
   402                 }
       
   403             }
       
   404             otherwise {
       
   405                 xsl:copy apply "@* | node()", mode="unlink_clone" {
       
   406                     with "seed","$seed";
       
   407                 }
       
   408             }
       
   409         }
       
   410     }
   372 
   411 
   373     /*const "mark" > =HMI=\n*/
   412     /*const "mark" > =HMI=\n*/
       
   413 
       
   414     const "result_svg" apply "/", mode="inline_svg";
       
   415     const "result_svg_ns", "exsl:node-set($result_svg)";
   374 
   416 
   375     /* copy root node and add geometry as comment for a test */
   417     /* copy root node and add geometry as comment for a test */
   376     template "/" {
   418     template "/" {
   377         comment > Made with SVGHMI. https://beremiz.org
   419         comment > Made with SVGHMI. https://beremiz.org
   378         /* DEBUG DATA */
   420         /* DEBUG DATA */
   395             | Discardable :
   437             | Discardable :
   396             foreach "$discardable_elements"{
   438             foreach "$discardable_elements"{
   397                 | «@id»
   439                 | «@id»
   398             }
   440             }
   399         }
   441         }
       
   442         comment {
       
   443             | Unlinked :
       
   444             foreach "$to_unlink"{
       
   445                 | «@id»
       
   446             }
       
   447         }
   400         /**/
   448         /**/
   401         html xmlns="http://www.w3.org/1999/xhtml"
   449         html xmlns="http://www.w3.org/1999/xhtml"
   402              xmlns:svg="http://www.w3.org/2000/svg"
   450              xmlns:svg="http://www.w3.org/2000/svg"
   403              xmlns:xlink="http://www.w3.org/1999/xlink" {
   451              xmlns:xlink="http://www.w3.org/1999/xlink" {
   404             head;
   452             head;
   405             body style="margin:0;overflow:hidden;" {
   453             body style="margin:0;overflow:hidden;" {
   406                 apply "svg:svg", mode="inline_svg";
   454                 copy "$result_svg";
   407                 script{
   455                 script{
   408                     call "scripts";
   456                     call "scripts";
   409                 }
   457                 }
   410             }
   458             }
   411         }
   459         }
   620         param "mandatory","'yes'";
   668         param "mandatory","'yes'";
   621         param "hmi_element";
   669         param "hmi_element";
   622         const "widget_type","@type";
   670         const "widget_type","@type";
   623         foreach "str:split($labels)" {
   671         foreach "str:split($labels)" {
   624             const "name",".";
   672             const "name",".";
   625             const "elt_id","$hmi_element//*[@inkscape:label=$name][1]/@id";
   673             const "elt_id","$result_svg_ns//*[@id = $hmi_element/@id]//*[@inkscape:label=$name][1]/@id";
   626             choose {
   674             choose {
   627                 when "not($elt_id)" {
   675                 when "not($elt_id)" {
   628                     if "$mandatory='yes'" {
   676                     if "$mandatory='yes'" {
   629                         // TODO FIXME error > «$widget_type» widget must have a «$name» element
   677                         // TODO FIXME error > «$widget_type» widget must have a «$name» element
   630                         warning > «$widget_type» widget must have a «$name» element
   678                         warning > «$widget_type» widget must have a «$name» element