lpcmanager

Parents cea582965856
Children d7d8098e92f7
Add HMI:CloudImage widget. Behaves similarly to HMI:Image, but links to cloudfolder endpoint to use /media/data/cloud folder as source folder for files
--- a/LPCSVGHMI/analyse_widget.xslt Mon Jul 21 16:13:12 2025 +0200
+++ b/LPCSVGHMI/analyse_widget.xslt Wed Jul 23 13:43:06 2025 +0200
@@ -1110,6 +1110,22 @@
</xsl:variable>
<func:result select="$res"/>
</func:function>
+ <xsl:template match="widget[@type='CloudImage']" mode="widget_desc">
+ <type>
+ <xsl:value-of select="@type"/>
+ </type>
+ <longdesc>
+ <xsl:text>If CloudImage widget is a svg:image element, then href content is replaced by
+</xsl:text>
+ <xsl:text>link to the file whose name is the value of given variable, being served from
+</xsl:text>
+ <xsl:text>/media/data/cloud folder.
+</xsl:text>
+ </longdesc>
+ <shortdesc>
+ <xsl:text>Image display</xsl:text>
+ </shortdesc>
+ </xsl:template>
<xsl:template match="widget[@type='Swipe']" mode="widget_desc">
<type>
<xsl:value-of select="@type"/>
--- a/LPCSVGHMI/gen_index_xhtml.xslt Mon Jul 21 16:13:12 2025 +0200
+++ b/LPCSVGHMI/gen_index_xhtml.xslt Wed Jul 23 13:43:06 2025 +0200
@@ -697,7 +697,7 @@
<func:function name="func:sumarized_elements">
<xsl:param name="elements"/>
<xsl:variable name="short_list" select="$elements[not(ancestor::*/@id = $elements/@id)]"/>
- <xsl:variable name="filled_groups" select="$short_list/parent::*[&#10; not(child::*[&#10; not(@id = $discardable_elements/@id) and&#10; not(@id = $short_list/@id)&#10; ])]"/>
+ <xsl:variable name="filled_groups" select="$short_list/parent::svg:g[&#10; not(child::*[&#10; not(@id = $discardable_elements/@id) and&#10; not(@id = $short_list/@id)&#10; ])]"/>
<xsl:variable name="groups_to_add" select="$filled_groups[not(ancestor::*/@id = $filled_groups/@id)]"/>
<func:result select="$groups_to_add | $short_list[not(ancestor::*/@id = $filled_groups/@id)]"/>
</func:function>
@@ -9380,6 +9380,75 @@
<xsl:text>
</xsl:text>
</xsl:template>
+ <xsl:template match="widget[@type='CloudImage']" mode="widget_desc">
+ <type>
+ <xsl:value-of select="@type"/>
+ </type>
+ <longdesc>
+ <xsl:text>If CloudImage widget is a svg:image element, then href content is replaced by
+</xsl:text>
+ <xsl:text>link to the file whose name is the value of given variable, being served from
+</xsl:text>
+ <xsl:text>/media/data/cloud folder.
+</xsl:text>
+ </longdesc>
+ <shortdesc>
+ <xsl:text>Image display</xsl:text>
+ </shortdesc>
+ </xsl:template>
+ <xsl:template match="widget[@type='CloudImage']" mode="widget_class">
+ <xsl:text>class </xsl:text>
+ <xsl:text>CloudImageWidget</xsl:text>
+ <xsl:text> extends Widget{
+</xsl:text>
+ <xsl:text> frequency = 5;
+</xsl:text>
+ <xsl:text> dispatch(value, oldval, index) {
+</xsl:text>
+ <xsl:text> if (index == 0) {
+</xsl:text>
+ <xsl:text> this.given_url = "cloudfolder?image=" + value;
+</xsl:text>
+ <xsl:text> this.ready = true;
+</xsl:text>
+ <xsl:text> this.request_animate();
+</xsl:text>
+ <xsl:text> }
+</xsl:text>
+ <xsl:text> }
+</xsl:text>
+ <xsl:text>}
+</xsl:text>
+ </xsl:template>
+ <xsl:template match="widget[@type='CloudImage']" mode="widget_defs">
+ <xsl:param name="hmi_element"/>
+ <xsl:variable name="disability">
+ <xsl:call-template name="defs_by_labels">
+ <xsl:with-param name="hmi_element" select="$hmi_element"/>
+ <xsl:with-param name="labels">
+ <xsl:text>/disabled</xsl:text>
+ </xsl:with-param>
+ <xsl:with-param name="mandatory" select="'no'"/>
+ </xsl:call-template>
+ </xsl:variable>
+ <xsl:value-of select="$disability"/>
+ <xsl:variable name="has_disability" select="string-length($disability)&gt;0"/>
+ <xsl:text> given_url: "",
+</xsl:text>
+ <xsl:text> ready: false,
+</xsl:text>
+ <xsl:text> animate: function(){
+</xsl:text>
+ <xsl:text> this.element.setAttribute('href', this.given_url);
+</xsl:text>
+ <xsl:text> },
+</xsl:text>
+ </xsl:template>
+ <xsl:template xmlns="http://www.w3.org/2000/svg" mode="inline_svg" match="svg:image[starts-with(@inkscape:label, 'HMI:CloudImage')]">
+ <xsl:copy>
+ <xsl:apply-templates mode="inline_svg" select="@*[not(contains(name(), 'href'))] | node()"/>
+ </xsl:copy>
+ </xsl:template>
<xsl:template match="widget[@type='Swipe']" mode="widget_desc">
<type>
<xsl:value-of select="@type"/>
@@ -10759,8 +10828,6 @@
</xsl:text>
<xsl:text> let widget = hmi_widgets[id];
</xsl:text>
- <xsl:text> if(widget.curr_value != undefined) return;
-</xsl:text>
<xsl:text> widget.do_init();
</xsl:text>
<xsl:text> });
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/LPCSVGHMI/widget_cloudimage.ysl2 Wed Jul 23 13:43:06 2025 +0200
@@ -0,0 +1,44 @@
+// widget_cloudimage.ysl2
+
+widget_desc("CloudImage") {
+ longdesc
+ ||
+ If CloudImage widget is a svg:image element, then href content is replaced by
+ link to the file whose name is the value of given variable, being served from
+ /media/data/cloud folder.
+ ||
+
+ shortdesc > Image display
+}
+
+widget_class("CloudImage")
+ ||
+ frequency = 5;
+ dispatch(value, oldval, index) {
+ if (index == 0) {
+ this.given_url = "cloudfolder?image=" + value;
+ this.ready = true;
+ this.request_animate();
+ }
+ }
+ ||
+
+widget_defs("CloudImage") {
+ | given_url: "",
+ | ready: false,
+ | animate: function(){
+ | this.element.setAttribute('href', this.given_url);
+ | },
+}
+
+
+gen_index_xhtml { // following content is only available when generating xhtml file
+
+// strip inkscape embedded bitmap when it is meant to be replaced by HMI:CloudImage widget
+svgtmpl "svg:image[starts-with(@inkscape:label, 'HMI:CloudImage')]", mode="inline_svg" {
+ xsl:copy {
+ apply "@*[not(contains(name(), 'href'))] | node()", mode="inline_svg";
+ }
+}
+
+}