svghmi/widgets_common.ysl2
branchsvghmi
changeset 3024 0a9f6f29b7dd
parent 3022 f6fe42b7ce60
parent 3019 497aac6522a3
child 3025 48e7e336c052
equal deleted inserted replaced
3023:407a0205405a 3024:0a9f6f29b7dd
    22 };
    22 };
    23 
    23 
    24 template "svg:*", mode="hmi_widgets" {
    24 template "svg:*", mode="hmi_widgets" {
    25     const "widget", "func:widget(@id)";
    25     const "widget", "func:widget(@id)";
    26     const "eltid","@id";
    26     const "eltid","@id";
    27     const "args" foreach "$widget/arg" > "«@value»"`if "position()!=last()" > ,`
    27     const "args" foreach "$widget/arg" > "«func:escape_quotes(@value)»"`if "position()!=last()" > ,`
    28     const "indexes" foreach "$widget/path" {
    28     const "indexes" foreach "$widget/path" {
    29         choose {
    29         choose {
    30             when "not(@index)" {
    30             when "not(@index)" {
    31                 choose {
    31                 choose {
    32                     when "not(@type)" 
    32                     when "not(@type)" 
    90             }
    90             }
    91 
    91 
    92             new_index = next_available_index++;
    92             new_index = next_available_index++;
    93             pagevars[varname] = new_index;
    93             pagevars[varname] = new_index;
    94         }
    94         }
    95         cache[new_index] = "";
       
    96         return new_index;
    95         return new_index;
    97     }
    96     }
    98 
    97 
    99     function hmi_local_index(varname){
    98     function hmi_local_index(varname){
   100         return page_local_index(varname, "HMI_LOCAL");
    99         return page_local_index(varname, "HMI_LOCAL");
   102     ||
   101     ||
   103 }
   102 }
   104 
   103 
   105 emit "preamble:widget-base-class" {
   104 emit "preamble:widget-base-class" {
   106     ||
   105     ||
       
   106     var pending_widget_animates = [];
       
   107 
   107     class Widget {
   108     class Widget {
   108         offset = 0;
   109         offset = 0;
   109         frequency = 10; /* FIXME arbitrary default max freq. Obtain from config ? */
   110         frequency = 10; /* FIXME arbitrary default max freq. Obtain from config ? */
   110         unsubscribable = false;
   111         unsubscribable = false;
       
   112         pending_animate = false;
       
   113 
   111         constructor(elt_id,args,indexes,members){
   114         constructor(elt_id,args,indexes,members){
   112             this.element_id = elt_id;
   115             this.element_id = elt_id;
   113             this.element = id(elt_id);
   116             this.element = id(elt_id);
   114             this.args = args;
   117             this.args = args;
   115             this.indexes = indexes;
   118             this.indexes = indexes;
   141                 }
   144                 }
   142             need_cache_apply.push(this); 
   145             need_cache_apply.push(this); 
   143         }
   146         }
   144 
   147 
   145         apply_cache() {
   148         apply_cache() {
   146             if(!this.unsubscribable) for(let i = 0; i < this.indexes.length; i++) {
   149             if(!this.unsubscribable) for(let index of this.indexes){
   147                 /* dispatch current cache in newly opened page widgets */
   150                 /* dispatch current cache in newly opened page widgets */
   148                 let realindex = this.get_variable_index(i);
   151                 let realindex = this.get_variable_index(index);
   149                 let cached_val = cache[realindex];
   152                 let cached_val = cache[realindex];
   150                 if(cached_val != undefined)
   153                 if(cached_val != undefined)
   151                     this.new_hmi_value(realindex, cached_val, cached_val);
   154                     this.new_hmi_value(realindex, cached_val, cached_val);
   152             }
   155             }
   153         }
   156         }
   194                 }
   197                 }
   195             } catch(err) {
   198             } catch(err) {
   196                 console.log(err);
   199                 console.log(err);
   197             }
   200             }
   198         }
   201         }
       
   202         
       
   203         _animate(){
       
   204             this.animate();
       
   205             this.pending_animate = false;
       
   206         }
       
   207 
       
   208         request_animate(){
       
   209             if(!this.pending_animate){
       
   210                 pending_widget_animates.push(this);
       
   211                 this.pending_animate = true;
       
   212                 requestHMIAnimation();
       
   213             }
       
   214 
       
   215         }
   199     }
   216     }
   200     ||
   217     ||
   201 }
   218 }
   202 
   219 
   203 emit "declarations:hmi-classes" {
   220 emit "declarations:hmi-classes" {
   210 class «@type»Widget extends Widget{
   227 class «@type»Widget extends Widget{
   211     /* empty class, as «@type» widget didn't provide any */
   228     /* empty class, as «@type» widget didn't provide any */
   212 }
   229 }
   213 ||
   230 ||
   214 
   231 
   215 const "excluded_types", "str:split('Page Lang')";
   232 const "excluded_types", "str:split('Page Lang VarInit')";
   216 const "excluded_ids","$parsed_widgets/widget[not(@type = $excluded_types)]/@id";
   233 const "included_ids","$parsed_widgets/widget[not(@type = $excluded_types)]/@id";
   217 
   234 
   218 emit "declarations:hmi-elements" {
   235 emit "declarations:hmi-elements" {
   219     | var hmi_widgets = {
   236     | var hmi_widgets = {
   220     apply  "$hmi_elements[@id = $excluded_ids]", mode="hmi_widgets";
   237     apply "$hmi_elements[@id = $included_ids]", mode="hmi_widgets";
   221     | }
   238     | }
   222 }
   239 }
   223 
   240 
   224 function "defs_by_labels" {
   241 function "defs_by_labels" {
   225     param "labels","''";
   242     param "labels","''";
   264 }
   281 }
   265 
   282 
   266 def "func:escape_quotes" {
   283 def "func:escape_quotes" {
   267     param "txt";
   284     param "txt";
   268     // have to use a python string to enter escaped quote
   285     // have to use a python string to enter escaped quote
   269     const "frst", !"substring-before($txt,'\"')"!;
   286     // const "frstln", "string-length($frst)";
   270     const "frstln", "string-length($frst)";
       
   271     choose {
   287     choose {
   272         when "$frstln > 0 and string-length($txt) > $frstln" {
   288         when !"contains($txt,'\"')"! {
   273             result !"concat($frst,'\\\"',func:escape_quotes(substring-after($txt,'\"')))"!;
   289             result !"concat(substring-before($txt,'\"'),'\\\"',func:escape_quotes(substring-after($txt,'\"')))"!;
   274         }
   290         }
   275         otherwise {
   291         otherwise {
   276             result "$txt";
   292             result "$txt";
   277         }
   293         }
   278     }
   294     }