# HG changeset patch # User Edouard Tisserant # Date 1608825379 -3600 # Node ID a098b2dd9dff387f040eb4368a414cb29a0c1d4c # Parent fc5a0b1ece1071e35c5ee5d1f3f613acdeb5fe1b SVGHMI: Added parsing of min and max value that can be given as @path,min,max in widget description diff -r fc5a0b1ece10 -r a098b2dd9dff svghmi/gen_index_xhtml.xslt --- a/svghmi/gen_index_xhtml.xslt Tue Dec 22 14:57:59 2020 +0100 +++ b/svghmi/gen_index_xhtml.xslt Thu Dec 24 16:56:19 2020 +0100 @@ -55,7 +55,27 @@ - ] + ]; + + + + var hmitree_paths = [ + + + /* + + + + */ " + + " + + , + + + + + ]; @@ -122,6 +142,7 @@ + @@ -148,7 +169,7 @@ - + @@ -164,33 +185,65 @@ + + + - + - - - - - + + + + + + + + + + Widget id: + + label: + + has wrong syntax of path section + + + + + + - + PAGE_LOCAL + + + + + HMI_LOCAL - - - - PAGE_LOCAL - - - - - HMI_LOCAL - - - + + + + + Widget id: + + label: + + path section + + use min and max on non mumeric value + + + + + + + + + + @@ -1223,6 +1276,8 @@ if(typeof(index) == "string"){ + /* XXX return index as path */ + index = page_local_index(index, this.container_id); } else { @@ -1233,19 +1288,27 @@ } + /* XXX check for hmi_paths and return path */ + } return index; } + + change_hmi_value(index, opstr) { let realindex = this.get_variable_index(index); if(realindex == undefined) return undefined; - return change_hmi_value(realindex, opstr); + let old_val = cache[realindex]; + + let new_val = eval_operation_string(old_val, opstr); + + return apply_hmi_value(realindex, new_val); } @@ -3995,7 +4058,7 @@ on_op_click(opstr) { - let new_val = this.change_hmi_value(0, opstr); + this.change_hmi_value(0, opstr); } @@ -6827,71 +6890,83 @@ + function eval_operation_string(old_val, opstr) { + + let op = opstr[0]; + + let given_val; + + if(opstr.length < 2) + + return undefined; + + if(opstr[1] in quotes){ + + if(opstr.length < 3) + + return undefined; + + if(opstr[opstr.length-1] == opstr[1]){ + + given_val = opstr.slice(2,opstr.length-1); + + } + + } else { + + given_val = Number(opstr.slice(1)); + + } + + let new_val; + + switch(op){ + + case "=": + + new_val = given_val; + + break; + + case "+": + + new_val = old_val + given_val; + + break; + + case "-": + + new_val = old_val - given_val; + + break; + + case "*": + + new_val = old_val * given_val; + + break; + + case "/": + + new_val = old_val / given_val; + + break; + + } + + return new_val; + + } + + + + /* + function change_hmi_value(index, opstr) { - let op = opstr[0]; - - let given_val; - - if(opstr.length < 2) - - return undefined; // TODO raise - - if(opstr[1] in quotes){ - - if(opstr.length < 3) - - return undefined; // TODO raise - - if(opstr[opstr.length-1] == opstr[1]){ - - given_val = opstr.slice(2,opstr.length-1); - - } - - } else { - - given_val = Number(opstr.slice(1)); - - } - let old_val = cache[index]; - let new_val; - - switch(op){ - - case "=": - - new_val = given_val; - - break; - - case "+": - - new_val = old_val + given_val; - - break; - - case "-": - - new_val = old_val - given_val; - - break; - - case "*": - - new_val = old_val * given_val; - - break; - - case "/": - - new_val = old_val / given_val; - - break; - - } + let new_val = eval_operation_string(old_val, opstr); if(new_val != undefined && old_val != new_val) @@ -6903,6 +6978,8 @@ } + */ + var current_visible_page; diff -r fc5a0b1ece10 -r a098b2dd9dff svghmi/hmi_tree.ysl2 --- a/svghmi/hmi_tree.ysl2 Tue Dec 22 14:57:59 2020 +0100 +++ b/svghmi/hmi_tree.ysl2 Thu Dec 24 16:56:19 2020 +0100 @@ -24,7 +24,7 @@ foreach "$indexed_hmitree/*" | /* «@index» «@hmipath» */ "«substring(local-name(), 5)»"`if "position()!=last()" > ,` - | ] + | ]; | } @@ -67,19 +67,20 @@ } // Parses: -// "HMI:WidgetType:param1:param2@path1@path2" +// "HMI:WidgetType:param1:param2@path1,path1min,path1max@path2" // // Into: // widget type="WidgetType" id="blah456" { // arg value="param1"; // arg value="param2"; -// path value=".path1" index=".path1" type="PAGE_LOCAL"; +// path value=".path1" index=".path1" min="path1min" max="path1max" type="PAGE_LOCAL"; // path value="/path1" index="348" type="HMI_INT"; // path value="path4" index="path4" type="HMI_LOCAL"; // } // template "*", mode="parselabel" { const "label","@inkscape:label"; + const "id","@id"; const "description", "substring-after($label,'HMI:')"; const "_args", "substring-before($description,'@')"; @@ -95,7 +96,7 @@ } if "$type" widget { - attrib "id" > «@id» + attrib "id" > «$id» attrib "type" > «$type» foreach "str:split(substring-after($args, ':'), ':')" { arg { @@ -105,22 +106,35 @@ const "paths", "substring-after($description,'@')"; foreach "str:split($paths, '@')" { if "string-length(.) > 0" path { - attrib "value" > «.» - const "path", "."; - const "item", "$indexed_hmitree/*[@hmipath = $path]"; + const "pathminmax", "str:split(.,',')"; + const "path", "$pathminmax[1]"; + const "pathminmaxcount", "count($pathminmax)"; + attrib "value" > «$path» choose { - when "count($item) = 1" { - attrib "index" > «$item/@index» - attrib "type" > «local-name($item)» + when "$pathminmaxcount = 3" { + attrib "min" > «$pathminmax[2]» + attrib "max" > «$pathminmax[3]» + } + when "$pathminmaxcount = 2" { + error > Widget id:«$id» label:«$label» has wrong syntax of path section «$pathminmax» + } + } + choose { + when "regexp:test($path,'^\.[a-zA-Z0-9_]+')" { + attrib "type" > PAGE_LOCAL + } + when "regexp:test($path,'^[a-zA-Z0-9_]+')" { + attrib "type" > HMI_LOCAL } otherwise { - choose { - when "regexp:test($path,'^\.[a-zA-Z0-9_]+')" { - attrib "type" > PAGE_LOCAL - } - when "regexp:test($path,'^[a-zA-Z0-9_]+')" { - attrib "type" > HMI_LOCAL - } + const "item", "$indexed_hmitree/*[@hmipath = $path]"; + const "pathtype", "local-name($item)"; + if "$pathminmaxcount = 3 and not($pathtype = 'HMI_INT' or $pathtype = 'HMI_REAL')" { + error > Widget id:«$id» label:«$label» path section «$pathminmax» use min and max on non mumeric value + } + if "count($item) = 1" { + attrib "index" > «$item/@index» + attrib "type" > «$pathtype» } } } diff -r fc5a0b1ece10 -r a098b2dd9dff tests/svghmi/svghmi_0@svghmi/svghmi.svg --- a/tests/svghmi/svghmi_0@svghmi/svghmi.svg Tue Dec 22 14:57:59 2020 +0100 +++ b/tests/svghmi/svghmi_0@svghmi/svghmi.svg Thu Dec 24 16:56:19 2020 +0100 @@ -304,7 +304,7 @@