svghmi/gen_dnd_widget_svg.xslt
branchsvghmi
changeset 3264 51645afeded9
parent 3234 f2bfb047d0e6
child 3410 eac5832a1489
equal deleted inserted replaced
3263:1205b2d0acf2 3264:51645afeded9
     1 <?xml version="1.0"?>
     1 <?xml version="1.0"?>
     2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common" xmlns:regexp="http://exslt.org/regular-expressions" xmlns:str="http://exslt.org/strings" xmlns:func="http://exslt.org/functions" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:ns="beremiz" version="1.0" extension-element-prefixes="ns func exsl regexp str dyn" exclude-result-prefixes="ns func exsl regexp str dyn">
     2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common" xmlns:regexp="http://exslt.org/regular-expressions" xmlns:str="http://exslt.org/strings" xmlns:func="http://exslt.org/functions" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:ns="beremiz" version="1.0" extension-element-prefixes="ns func exsl regexp str dyn" exclude-result-prefixes="ns func exsl regexp str dyn">
     3   <xsl:output method="xml"/>
     3   <xsl:output method="xml"/>
     4   <xsl:param name="hmi_path"/>
       
     5   <xsl:variable name="hmi_elements" select="//svg:*[starts-with(@inkscape:label, 'HMI:')]"/>
     4   <xsl:variable name="hmi_elements" select="//svg:*[starts-with(@inkscape:label, 'HMI:')]"/>
     6   <xsl:variable name="subhmitree" select="ns:GetSubHMITree()"/>
     5   <xsl:variable name="widgetparams" select="ns:GetWidgetParams()"/>
     7   <xsl:variable name="indexed_hmitree" select="/.."/>
     6   <xsl:variable name="indexed_hmitree" select="/.."/>
     8   <xsl:variable name="pathregex" select="'^([^\[,]+)(\[[^\]]+\])?([\d,]*)$'"/>
     7   <xsl:variable name="pathregex" select="'^([^\[,]+)(\[[^\]]+\])?([\d,]*)$'"/>
     9   <xsl:template mode="parselabel" match="*">
     8   <xsl:template mode="parselabel" match="*">
    10     <xsl:variable name="label" select="@inkscape:label"/>
     9     <xsl:variable name="label" select="@inkscape:label"/>
    11     <xsl:variable name="id" select="@id"/>
    10     <xsl:variable name="id" select="@id"/>
   122                 </xsl:choose>
   121                 </xsl:choose>
   123               </xsl:if>
   122               </xsl:if>
   124             </path>
   123             </path>
   125           </xsl:if>
   124           </xsl:if>
   126         </xsl:for-each>
   125         </xsl:for-each>
       
   126         <xsl:if test="svg:desc">
       
   127           <desc>
       
   128             <xsl:value-of select="svg:desc/text()"/>
       
   129           </desc>
       
   130         </xsl:if>
   127       </widget>
   131       </widget>
   128     </xsl:if>
   132     </xsl:if>
   129   </xsl:template>
   133   </xsl:template>
   130   <xsl:template mode="genlabel" match="arg">
   134   <xsl:template mode="genlabel" match="arg">
   131     <xsl:text>:</xsl:text>
   135     <xsl:text>:</xsl:text>
   149   </xsl:template>
   153   </xsl:template>
   150   <xsl:variable name="_parsed_widgets">
   154   <xsl:variable name="_parsed_widgets">
   151     <xsl:apply-templates mode="parselabel" select="$hmi_elements"/>
   155     <xsl:apply-templates mode="parselabel" select="$hmi_elements"/>
   152   </xsl:variable>
   156   </xsl:variable>
   153   <xsl:variable name="parsed_widgets" select="exsl:node-set($_parsed_widgets)"/>
   157   <xsl:variable name="parsed_widgets" select="exsl:node-set($_parsed_widgets)"/>
   154   <xsl:variable name="selected_node_type" select="local-name($subhmitree)"/>
       
   155   <xsl:variable name="svg_widget" select="$parsed_widgets/widget[1]"/>
   158   <xsl:variable name="svg_widget" select="$parsed_widgets/widget[1]"/>
   156   <xsl:variable name="svg_widget_type" select="$svg_widget/@type"/>
   159   <xsl:variable name="svg_widget_type" select="$svg_widget/@type"/>
   157   <xsl:variable name="svg_widget_path" select="$svg_widget/@path"/>
   160   <xsl:variable name="svg_widget_path" select="$svg_widget/@path"/>
   158   <xsl:variable name="svg_widget_count" select="count($parsed_widgets/widget)"/>
   161   <xsl:variable name="svg_widget_count" select="count($parsed_widgets/widget)"/>
   159   <xsl:template mode="replace_path" match="@* | node()">
   162   <xsl:template mode="replace_params" match="@* | node()">
   160     <xsl:copy>
   163     <xsl:copy>
   161       <xsl:apply-templates mode="replace_path" select="@* | node()"/>
   164       <xsl:apply-templates mode="replace_params" select="@* | node()"/>
   162     </xsl:copy>
   165     </xsl:copy>
   163   </xsl:template>
   166   </xsl:template>
   164   <xsl:template mode="replace_path" match="path/@value">
   167   <xsl:template mode="replace_params" match="arg"/>
   165     <xsl:attribute name="value">
   168   <xsl:template mode="replace_params" match="path"/>
   166       <xsl:value-of select="$hmi_path"/>
   169   <xsl:template mode="replace_params" match="widget">
   167     </xsl:attribute>
   170     <xsl:copy>
       
   171       <xsl:apply-templates mode="replace_params" select="@* | node()"/>
       
   172       <xsl:copy-of select="$widgetparams/*"/>
       
   173     </xsl:copy>
   168   </xsl:template>
   174   </xsl:template>
   169   <xsl:template xmlns="http://www.w3.org/2000/svg" mode="inline_svg" match="@*">
   175   <xsl:template xmlns="http://www.w3.org/2000/svg" mode="inline_svg" match="@*">
   170     <xsl:copy/>
   176     <xsl:copy/>
   171   </xsl:template>
   177   </xsl:template>
   172   <xsl:template xmlns="http://www.w3.org/2000/svg" mode="inline_svg" match="@inkscape:label[starts-with(., 'HMI:')]"/>
   178   <xsl:template xmlns="http://www.w3.org/2000/svg" mode="inline_svg" match="@inkscape:label[starts-with(., 'HMI:')]"/>
   173   <xsl:template mode="inline_svg" match="node()">
   179   <xsl:template mode="inline_svg" match="node()">
   174     <xsl:copy>
   180     <xsl:copy>
   175       <xsl:if test="@id = $svg_widget/@id">
   181       <xsl:if test="@id = $svg_widget/@id">
   176         <xsl:variable name="substituted_widget">
   182         <xsl:variable name="substituted_widget">
   177           <xsl:apply-templates mode="replace_path" select="$svg_widget"/>
   183           <xsl:apply-templates mode="replace_params" select="$svg_widget"/>
   178         </xsl:variable>
   184         </xsl:variable>
   179         <xsl:variable name="substituted_widget_ns" select="exsl:node-set($substituted_widget)"/>
   185         <xsl:variable name="substituted_widget_ns" select="exsl:node-set($substituted_widget)"/>
   180         <xsl:variable name="new_label">
   186         <xsl:variable name="new_label">
   181           <xsl:apply-templates mode="genlabel" select="$substituted_widget_ns"/>
   187           <xsl:apply-templates mode="genlabel" select="$substituted_widget_ns"/>
   182         </xsl:variable>
   188         </xsl:variable>
   185         </xsl:attribute>
   191         </xsl:attribute>
   186       </xsl:if>
   192       </xsl:if>
   187       <xsl:apply-templates mode="inline_svg" select="@* | node()"/>
   193       <xsl:apply-templates mode="inline_svg" select="@* | node()"/>
   188     </xsl:copy>
   194     </xsl:copy>
   189   </xsl:template>
   195   </xsl:template>
   190   <xsl:variable name="NODES_TYPES" select="str:split('HMI_ROOT HMI_NODE')"/>
       
   191   <xsl:variable name="HMI_NODES_COMPAT" select="str:split('Page Jump Foreach')"/>
       
   192   <xsl:template match="/">
   196   <xsl:template match="/">
   193     <xsl:comment>
   197     <xsl:comment>
   194       <xsl:text>Widget dropped in Inkscape from Beremiz</xsl:text>
   198       <xsl:text>Widget dropped in Inkscape from Beremiz</xsl:text>
   195     </xsl:comment>
   199     </xsl:comment>
   196     <xsl:choose>
   200     <xsl:choose>
   202       <xsl:when test="$svg_widget_count &gt; 1">
   206       <xsl:when test="$svg_widget_count &gt; 1">
   203         <xsl:message terminate="yes">
   207         <xsl:message terminate="yes">
   204           <xsl:text>Multiple widget DnD not yet supported</xsl:text>
   208           <xsl:text>Multiple widget DnD not yet supported</xsl:text>
   205         </xsl:message>
   209         </xsl:message>
   206       </xsl:when>
   210       </xsl:when>
   207       <xsl:when test="$selected_node_type = $NODES_TYPES and                     not($svg_widget_type = $HMI_NODES_COMPAT)">
       
   208         <xsl:message terminate="yes">
       
   209           <xsl:text>Widget incompatible with selected HMI tree node</xsl:text>
       
   210         </xsl:message>
       
   211       </xsl:when>
       
   212     </xsl:choose>
   211     </xsl:choose>
   213     <xsl:variable name="testmsg">
       
   214       <msg>
       
   215         <xsl:value-of select="$hmi_path"/>
       
   216       </msg>
       
   217       <msg>
       
   218         <xsl:value-of select="$selected_node_type"/>
       
   219       </msg>
       
   220       <msg>
       
   221         <xsl:value-of select="$svg_widget_type"/>
       
   222       </msg>
       
   223     </xsl:variable>
       
   224     <xsl:value-of select="ns:PassMessage($testmsg)"/>
       
   225     <xsl:apply-templates mode="inline_svg" select="/"/>
   212     <xsl:apply-templates mode="inline_svg" select="/"/>
   226   </xsl:template>
   213   </xsl:template>
   227 </xsl:stylesheet>
   214 </xsl:stylesheet>