# HG changeset patch
# User Edouard Tisserant
# Date 1589441049 -7200
# Node ID 7349063b19d8d0aecb894c8b6334fcc3c097a4bd
# Parent 8f928cee01e536bdefeb7986274f83197de49ad8# Parent 113e2f2e324d31b7b5ff3a0add1dff04dd6a8e4f
merge
diff -r 8f928cee01e5 -r 7349063b19d8 svghmi/gen_index_xhtml.xslt
--- a/svghmi/gen_index_xhtml.xslt Wed May 13 14:48:52 2020 +0200
+++ b/svghmi/gen_index_xhtml.xslt Thu May 14 09:24:09 2020 +0200
@@ -866,20 +866,26 @@
class Widget {
+ offset = 0;
+
+ frequency = 10; /* FIXME arbitrary default max freq. Obtain from config ? */
+
constructor(elt_id,args,indexes,members){
+ this.element_id = elt_id;
+
this.element = id(elt_id);
this.args = args;
this.indexes = indexes;
- this.offset = 0;
-
Object.keys(members).forEach(prop => this[prop]=members[prop]);
}
+
+
unsub(){
/* remove subsribers */
@@ -1078,9 +1084,10 @@
-
-
- on_click: function(evt) {
+
+ class BackWidget extends Widget{
+
+ on_click(evt) {
if(jump_history.length > 1){
@@ -1092,44 +1099,51 @@
}
- },
-
- init: function() {
-
- this.element.setAttribute("onclick", "hmi_widgets['
-
- '].on_click(evt)");
-
- },
-
-
-
-
- frequency: 5,
-
- init: function() {
-
- this.element.addEventListener(
-
- "mousedown",
-
- evt => {
-
- change_hmi_value(this.indexes[0], "=1");
-
- });
-
- this.element.addEventListener(
-
- "mouseup",
-
- evt => {
-
- change_hmi_value(this.indexes[0], "=0");
-
- });
-
- },
+ }
+
+ init() {
+
+ this.element.setAttribute("onclick", "hmi_widgets['"+this.element_id+"'].on_click(evt)");
+
+ }
+
+ }
+
+
+
+ class ButtonWidget extends Widget{
+
+ frequency = 5;
+
+ init() {
+
+ // TODO : use attributes to allow interaction through svg:use
+
+ // TODO : deal with dragging
+
+ this.element.addEventListener(
+
+ "mousedown",
+
+ evt => {
+
+ change_hmi_value(this.indexes[0], "=1");
+
+ });
+
+ this.element.addEventListener(
+
+ "mouseup",
+
+ evt => {
+
+ change_hmi_value(this.indexes[0], "=0");
+
+ });
+
+ }
+
+ }
@@ -1767,7 +1781,6 @@
-
@@ -2585,34 +2598,34 @@
},
+
+ class SwitchWidget extends Widget{
+
+ frequency = 5;
+
+ dispatch(value) {
+
+ for(let choice of this.choices){
+
+ if(value != choice.value){
+
+ choice.elt.setAttribute("style", "display:none");
+
+ } else {
+
+ choice.elt.setAttribute("style", choice.style);
+
+ }
+
+ }
+
+ }
+
+ }
+
+
- frequency: 5,
-
- dispatch: function(value) {
-
- for(let choice of this.choices){
-
- if(value != choice.value){
-
- choice.elt.setAttribute("style", "display:none");
-
- } else {
-
- choice.elt.setAttribute("style", choice.style);
-
- }
-
- }
-
- },
-
- init: function() {
-
- // Hello Switch
-
- },
-
choices: [
@@ -3104,11 +3117,15 @@
let maxfreq = 0;
- for(let widget of widgets)
-
- if(maxfreq < widget.frequency)
-
- maxfreq = widget.frequency;
+ for(let widget of widgets){
+
+ let wf = widget.frequency;
+
+ if(wf != undefined && maxfreq < wf)
+
+ maxfreq = wf;
+
+ }
diff -r 8f928cee01e5 -r 7349063b19d8 svghmi/svghmi.js
--- a/svghmi/svghmi.js Wed May 13 14:48:52 2020 +0200
+++ b/svghmi/svghmi.js Thu May 14 09:24:09 2020 +0200
@@ -207,9 +207,11 @@
let new_period = 0;
if(widgets.size > 0) {
let maxfreq = 0;
- for(let widget of widgets)
- if(maxfreq < widget.frequency)
- maxfreq = widget.frequency;
+ for(let widget of widgets){
+ let wf = widget.frequency;
+ if(wf != undefined && maxfreq < wf)
+ maxfreq = wf;
+ }
if(maxfreq != 0)
new_period = 1000/maxfreq;
diff -r 8f928cee01e5 -r 7349063b19d8 svghmi/widget_back.ysl2
--- a/svghmi/widget_back.ysl2 Wed May 13 14:48:52 2020 +0200
+++ b/svghmi/widget_back.ysl2 Thu May 14 09:24:09 2020 +0200
@@ -1,17 +1,17 @@
// widget_back.ysl2
-template "widget[@type='Back']", mode="widget_defs" {
- param "hmi_element";
-
- | on_click: function(evt) {
- | if(jump_history.length > 1){
- | jump_history.pop();
- | let [page_name, index] = jump_history.pop();
- | switch_page(page_name, index);
- | }
- | },
- | init: function() {
- | this.element.setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_click(evt)");
- | },
-}
-
+template "widget[@type='Back']", mode="widget_class"
+ ||
+ class BackWidget extends Widget{
+ on_click(evt) {
+ if(jump_history.length > 1){
+ jump_history.pop();
+ let [page_name, index] = jump_history.pop();
+ switch_page(page_name, index);
+ }
+ }
+ init() {
+ this.element.setAttribute("onclick", "hmi_widgets['"+this.element_id+"'].on_click(evt)");
+ }
+ }
+ ||
diff -r 8f928cee01e5 -r 7349063b19d8 svghmi/widget_button.ysl2
--- a/svghmi/widget_button.ysl2 Wed May 13 14:48:52 2020 +0200
+++ b/svghmi/widget_button.ysl2 Thu May 14 09:24:09 2020 +0200
@@ -1,18 +1,20 @@
// widget_button.ysl2
-template "widget[@type='Button']", mode="widget_defs" {
- param "hmi_element";
- | frequency: 5,
- | init: function() {
- | this.element.addEventListener(
- | "mousedown",
- | evt => {
- | change_hmi_value(this.indexes[0], "=1");
- | });
- | this.element.addEventListener(
- | "mouseup",
- | evt => {
- | change_hmi_value(this.indexes[0], "=0");
- | });
- | },
-}
\ No newline at end of file
+template "widget[@type='Button']", mode="widget_class"
+ ||
+ class ButtonWidget extends Widget{
+ frequency = 5;
+ init() {
+ this.element.addEventListener(
+ "mousedown",
+ evt => {
+ change_hmi_value(this.indexes[0], "=1");
+ });
+ this.element.addEventListener(
+ "mouseup",
+ evt => {
+ change_hmi_value(this.indexes[0], "=0");
+ });
+ }
+ }
+ ||
diff -r 8f928cee01e5 -r 7349063b19d8 svghmi/widget_foreach.ysl2
--- a/svghmi/widget_foreach.ysl2 Wed May 13 14:48:52 2020 +0200
+++ b/svghmi/widget_foreach.ysl2 Thu May 14 09:24:09 2020 +0200
@@ -1,7 +1,6 @@
template "widget[@type='ForEach']", mode="widget_defs" {
param "hmi_element";
- const "widgets", "func:refered_elements($forEach_widgets)[not(@id = $forEach_widgets_ids)]";
const "class","arg[1]/@value";
diff -r 8f928cee01e5 -r 7349063b19d8 svghmi/widget_switch.ysl2
--- a/svghmi/widget_switch.ysl2 Wed May 13 14:48:52 2020 +0200
+++ b/svghmi/widget_switch.ysl2 Thu May 14 09:24:09 2020 +0200
@@ -1,20 +1,23 @@
// widget_switch.ysl2
+template "widget[@type='Switch']", mode="widget_class"
+ ||
+ class SwitchWidget extends Widget{
+ frequency = 5;
+ dispatch(value) {
+ for(let choice of this.choices){
+ if(value != choice.value){
+ choice.elt.setAttribute("style", "display:none");
+ } else {
+ choice.elt.setAttribute("style", choice.style);
+ }
+ }
+ }
+ }
+ ||
+
template "widget[@type='Switch']", mode="widget_defs" {
param "hmi_element";
- | frequency: 5,
- | dispatch: function(value) {
- | for(let choice of this.choices){
- | if(value != choice.value){
- | choice.elt.setAttribute("style", "display:none");
- | } else {
- | choice.elt.setAttribute("style", choice.style);
- | }
- | }
- | },
- | init: function() {
- | // Hello Switch
- | },
| choices: [
const "regex",!"'^(\"[^\"].*\"|\-?[0-9]+|false|true)(#.*)?$'"!;
foreach "$hmi_element/*[regexp:test(@inkscape:label,$regex)]" {
diff -r 8f928cee01e5 -r 7349063b19d8 svghmi/widgets_common.ysl2
--- a/svghmi/widgets_common.ysl2 Wed May 13 14:48:52 2020 +0200
+++ b/svghmi/widgets_common.ysl2 Thu May 14 09:24:09 2020 +0200
@@ -65,13 +65,16 @@
emit "preamble:widget-base-class" {
||
class Widget {
+ offset = 0;
+ frequency = 10; /* FIXME arbitrary default max freq. Obtain from config ? */
constructor(elt_id,args,indexes,members){
+ this.element_id = elt_id;
this.element = id(elt_id);
this.args = args;
this.indexes = indexes;
- this.offset = 0;
Object.keys(members).forEach(prop => this[prop]=members[prop]);
}
+
unsub(){
/* remove subsribers */
for(let index of this.indexes){
diff -r 8f928cee01e5 -r 7349063b19d8 tests/svghmi/svghmi_0@svghmi/svghmi.svg
--- a/tests/svghmi/svghmi_0@svghmi/svghmi.svg Wed May 13 14:48:52 2020 +0200
+++ b/tests/svghmi/svghmi_0@svghmi/svghmi.svg Thu May 14 09:24:09 2020 +0200
@@ -16,7 +16,7 @@
version="1.1"
id="hmi0"
sodipodi:docname="svghmi.svg"
- inkscape:version="0.92.4 (5da689c313, 2019-01-14)">
+ inkscape:version="0.92.5 (2060ec1f9f, 2020-04-08)">
@@ -31,6 +31,20 @@
+
+
@@ -912,29 +926,29 @@
8888
8888
@@ -1124,196 +1138,6 @@
- 8888
-
-
-
- dhu
-
-
-
- plop
-
-
-
- mhoo
-
-
-
- yodl
-
-
-
- mhe
-
-
-
+
+
+
+
+
+ up
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+