# HG changeset patch # User Edouard Tisserant # Date 1636377036 -3600 # Node ID ecefd38d5c7d3be6428fcbf7718d433546836d1e # Parent 608f48ad3dfcebee15a2efef64b93b58b9969513 SVGHMI: update tests/evghmi to reflect/test latest changes. update generated XSLT. diff -r 608f48ad3dfc -r ecefd38d5c7d svghmi/analyse_widget.xslt --- a/svghmi/analyse_widget.xslt Mon Nov 08 14:09:44 2021 +0100 +++ b/svghmi/analyse_widget.xslt Mon Nov 08 14:10:36 2021 +0100 @@ -471,7 +471,7 @@ </xsl:text> <xsl:text> </xsl:text> - <xsl:text>Documentation to be written. see svbghmi exemple. + <xsl:text>Documentation to be written. see svghmi exemple. </xsl:text> </longdesc> <shortdesc> @@ -566,6 +566,37 @@ </shortdesc> <arg name="listname"/> </xsl:template> + <xsl:template match="widget[@type='ListSwitch']" mode="widget_desc"> + <type> + <xsl:value-of select="@type"/> + </type> + <longdesc> + <xsl:text>ListSwitch widget displays one item of an HMI:List depending on value of +</xsl:text> + <xsl:text>given variable. Main element of the widget must be a clone of the list or +</xsl:text> + <xsl:text>of an item of that list. +</xsl:text> + <xsl:text> +</xsl:text> + <xsl:text>Given variable's current value is compared to list items +</xsl:text> + <xsl:text>label. For exemple if given variable type +</xsl:text> + <xsl:text>is HMI_INT and value is 1, then item with label '1' will be displayed. +</xsl:text> + <xsl:text>If matching variable of type HMI_STRING, then no quotes are needed. +</xsl:text> + <xsl:text>For exemple, 'hello' match HMI_STRING 'hello'. +</xsl:text> + </longdesc> + <shortdesc> + <xsl:text>Displays item of an HMI:List whose label matches value.</xsl:text> + </shortdesc> + <path name="value" accepts="HMI_INT,HMI_STRING"> + <xsl:text>value to compare to labels</xsl:text> + </path> + </xsl:template> <xsl:template match="widget[@type='Meter']" mode="widget_desc"> <type> <xsl:value-of select="@type"/> @@ -687,7 +718,7 @@ </xsl:text> </longdesc> <shortdesc> - <xsl:text>Show elements whose label match value.</xsl:text> + <xsl:text>Show elements whose label matches value.</xsl:text> </shortdesc> <path name="value" accepts="HMI_INT,HMI_STRING"> <xsl:text>value to compare to labels</xsl:text> diff -r 608f48ad3dfc -r ecefd38d5c7d svghmi/gen_index_xhtml.xslt --- a/svghmi/gen_index_xhtml.xslt Mon Nov 08 14:09:44 2021 +0100 +++ b/svghmi/gen_index_xhtml.xslt Mon Nov 08 14:10:36 2021 +0100 @@ -572,7 +572,7 @@ </xsl:choose> </func:function> <xsl:variable name="required_page_elements" select="func:required_elements($hmi_pages | $keypads)/ancestor-or-self::svg:*"/> - <xsl:variable name="required_list_elements" select="func:refered_elements(($hmi_lists | $hmi_textlists)[@id = $required_page_elements/@id])"/> + <xsl:variable name="required_list_elements" select="func:refered_elements(($hmi_lists | $hmi_textlists)[@id = $required_page_elements/@id])/ancestor-or-self::svg:*"/> <xsl:variable name="required_elements" select="$defs | $required_list_elements | $required_page_elements"/> <xsl:variable name="discardable_elements" select="//svg:*[not(@id = $required_elements/@id)]"/> <func:function name="func:sumarized_elements"> @@ -846,7 +846,7 @@ </xsl:attribute> </xsl:template> <xsl:variable name="targets_not_to_unlink" select="$hmi_lists/descendant-or-self::svg:*"/> - <xsl:variable name="to_unlink" select="$hmi_elements[not(@id = $hmi_pages/@id)]/descendant-or-self::svg:use"/> + <xsl:variable name="to_unlink" select="$hmi_widgets/descendant-or-self::svg:use"/> <func:function name="func:is_unlinkable"> <xsl:param name="targetid"/> <xsl:param name="eltid"/> @@ -4583,7 +4583,7 @@ </xsl:text> <xsl:text> </xsl:text> - <xsl:text>Documentation to be written. see svbghmi exemple. + <xsl:text>Documentation to be written. see svghmi exemple. </xsl:text> </longdesc> <shortdesc> @@ -4833,13 +4833,13 @@ <xsl:when test="count($from_list) > 0"> <xsl:text> id("</xsl:text> <xsl:value-of select="@id"/> - <xsl:text>").setAttribute("xlink:href", + <xsl:text>").href.baseVal = </xsl:text> <xsl:text> "#"+hmi_widgets["</xsl:text> <xsl:value-of select="$from_list/@id"/> <xsl:text>"].items[</xsl:text> <xsl:value-of select="$expressions/expression[1]/@content"/> - <xsl:text>]); + <xsl:text>]; </xsl:text> </xsl:when> <xsl:otherwise> @@ -5675,9 +5675,9 @@ <xsl:text> items: { </xsl:text> <xsl:for-each select="$hmi_element/*[@inkscape:label]"> - <xsl:text> </xsl:text> + <xsl:text> "</xsl:text> <xsl:value-of select="@inkscape:label"/> - <xsl:text>: "</xsl:text> + <xsl:text>": "</xsl:text> <xsl:value-of select="@id"/> <xsl:text>", </xsl:text> @@ -5685,6 +5685,60 @@ <xsl:text> }, </xsl:text> </xsl:template> + <xsl:template match="widget[@type='ListSwitch']" mode="widget_desc"> + <type> + <xsl:value-of select="@type"/> + </type> + <longdesc> + <xsl:text>ListSwitch widget displays one item of an HMI:List depending on value of +</xsl:text> + <xsl:text>given variable. Main element of the widget must be a clone of the list or +</xsl:text> + <xsl:text>of an item of that list. +</xsl:text> + <xsl:text> +</xsl:text> + <xsl:text>Given variable's current value is compared to list items +</xsl:text> + <xsl:text>label. For exemple if given variable type +</xsl:text> + <xsl:text>is HMI_INT and value is 1, then item with label '1' will be displayed. +</xsl:text> + <xsl:text>If matching variable of type HMI_STRING, then no quotes are needed. +</xsl:text> + <xsl:text>For exemple, 'hello' match HMI_STRING 'hello'. +</xsl:text> + </longdesc> + <shortdesc> + <xsl:text>Displays item of an HMI:List whose label matches value.</xsl:text> + </shortdesc> + <path name="value" accepts="HMI_INT,HMI_STRING"> + <xsl:text>value to compare to labels</xsl:text> + </path> + </xsl:template> + <xsl:template match="widget[@type='ListSwitch']" mode="widget_class"> + <xsl:text>class </xsl:text> + <xsl:text>ListSwitchWidget</xsl:text> + <xsl:text> extends Widget{ +</xsl:text> + <xsl:text> frequency = 5; +</xsl:text> + <xsl:text>} +</xsl:text> + </xsl:template> + <xsl:template match="widget[@type='ListSwitch']" mode="widget_defs"> + <xsl:param name="hmi_element"/> + <xsl:variable name="targetid" select="substring-after($hmi_element/@xlink:href,'#')"/> + <xsl:variable name="from_list" select="$hmi_lists[(@id | */@id) = $targetid]"/> + <xsl:text> dispatch: function(value) { +</xsl:text> + <xsl:text> this.element.href.baseVal = "#"+hmi_widgets["</xsl:text> + <xsl:value-of select="$from_list/@id"/> + <xsl:text>"].items[value]; +</xsl:text> + <xsl:text> }, +</xsl:text> + </xsl:template> <xsl:template match="widget[@type='Meter']" mode="widget_desc"> <type> <xsl:value-of select="@type"/> @@ -7239,7 +7293,7 @@ </xsl:text> </longdesc> <shortdesc> - <xsl:text>Show elements whose label match value.</xsl:text> + <xsl:text>Show elements whose label matches value.</xsl:text> </shortdesc> <path name="value" accepts="HMI_INT,HMI_STRING"> <xsl:text>value to compare to labels</xsl:text> @@ -8432,6 +8486,8 @@ </xsl:text> <xsl:text>// subscribe to per instance current page hmi variable </xsl:text> + <xsl:text>// PLC must prefix page name with "!" for page switch to happen +</xsl:text> <xsl:text>subscribers(current_page_var_index).add({ </xsl:text> <xsl:text> frequency: 1, @@ -8440,7 +8496,9 @@ </xsl:text> <xsl:text> new_hmi_value: function(index, value, oldval) { </xsl:text> - <xsl:text> switch_page(value); + <xsl:text> if(value.startsWith("!")) +</xsl:text> + <xsl:text> switch_page(value.slice(1)); </xsl:text> <xsl:text> } </xsl:text> @@ -8946,13 +9004,11 @@ </xsl:text> <xsl:text> </xsl:text> - <xsl:text> apply_hmi_value(current_page_var_index, -</xsl:text> - <xsl:text> page_index == undefined -</xsl:text> - <xsl:text> ? page_name -</xsl:text> - <xsl:text> : page_name + "@" + hmitree_paths[page_index]); + <xsl:text> apply_hmi_value(current_page_var_index, page_index == undefined +</xsl:text> + <xsl:text> ? page_name +</xsl:text> + <xsl:text> : page_name + "@" + hmitree_paths[page_index]); </xsl:text> <xsl:text> </xsl:text> diff -r 608f48ad3dfc -r ecefd38d5c7d tests/svghmi/plc.xml --- a/tests/svghmi/plc.xml Mon Nov 08 14:09:44 2021 +0100 +++ b/tests/svghmi/plc.xml Mon Nov 08 14:10:36 2021 +0100 @@ -1,7 +1,7 @@ <?xml version='1.0' encoding='utf-8'?> <project xmlns:ns1="http://www.plcopen.org/xml/tc6_0201" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.plcopen.org/xml/tc6_0201"> <fileHeader companyName="Unknown" productName="Unnamed" productVersion="1" creationDateTime="2019-08-06T14:23:42"/> - <contentHeader name="Unnamed" modificationDateTime="2021-11-04T11:35:21"> + <contentHeader name="Unnamed" modificationDateTime="2021-11-08T13:54:01"> <coordinateInfo> <fbd> <scaling x="5" y="5"/> @@ -376,7 +376,7 @@ <connectionPointOut> <relPosition x="220" y="10"/> </connectionPointOut> - <expression>'RelativePageTest@/TRUMP2'</expression> + <expression>'!RelativePageTest@/PUMP2'</expression> </inVariable> <block localId="17" typeName="R_TRIG" instanceName="R_TRIG0" executionOrderId="0" height="40" width="60"> <position x="220" y="185"/> diff -r 608f48ad3dfc -r ecefd38d5c7d tests/svghmi/svghmi_0@svghmi/svghmi.svg --- a/tests/svghmi/svghmi_0@svghmi/svghmi.svg Mon Nov 08 14:09:44 2021 +0100 +++ b/tests/svghmi/svghmi_0@svghmi/svghmi.svg Mon Nov 08 14:10:36 2021 +0100 @@ -128,14 +128,14 @@ inkscape:current-layer="hmi0" showgrid="false" units="px" - inkscape:zoom="0.42177818" - inkscape:cx="543.13877" - inkscape:cy="-467.92793" - inkscape:window-width="2400" - inkscape:window-height="2096" - inkscape:window-x="3200" + inkscape:zoom="0.84355636" + inkscape:cx="-1054.5035" + inkscape:cy="482.64214" + inkscape:window-width="1600" + inkscape:window-height="836" + inkscape:window-x="0" inkscape:window-y="27" - inkscape:window-maximized="0" + inkscape:window-maximized="1" showguides="true" inkscape:guide-bbox="true" inkscape:snap-global="true" @@ -7538,4 +7538,26 @@ y="606.89435" style="text-align:center;text-anchor:middle;fill:#ff6600;stroke-width:0.99999994px" id="tspan1330">000</tspan></text> + <use + transform="translate(-2307.336,346.33773)" + x="0" + y="0" + xlink:href="#use1299" + inkscape:transform-center-x="0.14620371" + inkscape:transform-center-y="2.9995242" + id="use1176" + width="100%" + height="100%" + inkscape:label="HMI:ListSwitch@/ALARMSTATUS" /> + <use + height="100%" + width="100%" + id="use1193" + inkscape:transform-center-y="2.9995242" + inkscape:transform-center-x="0.14620371" + xlink:href="#use1299" + y="0" + x="0" + transform="translate(-2307.336,1146.3377)" + inkscape:label="HMI:ListSwitch@/ALARMSTATUS" /> </svg>