svghmi/widgets_common.ysl2
changeset 3466 eadb3a85ceb7
parent 3455 2716cd8e498d
child 3469 97622e9560b5
equal deleted inserted replaced
3465:2f5b5c14a650 3466:eadb3a85ceb7
    83         if "position()!=last()" > ,
    83         if "position()!=last()" > ,
    84     }
    84     }
    85 
    85 
    86     const "freq" choose {
    86     const "freq" choose {
    87         when "$widget/@freq"
    87         when "$widget/@freq"
    88             > «$widget/@freq»
    88             > "«$widget/@freq»"
    89         otherwise
    89         otherwise
    90             > undefined
    90             > undefined
    91     }
    91     }
    92 
    92 
    93     |   "«@id»": new «$widget/@type»Widget ("«@id»",«$freq»,[«$args»],[«$indexes»],[«$minmaxes»],{
    93     |   "«@id»": new «$widget/@type»Widget ("«@id»",«$freq»,[«$args»],[«$indexes»],[«$minmaxes»],{
   181             this.lastapply = indexes.map(() => undefined);
   181             this.lastapply = indexes.map(() => undefined);
   182             this.inhibit = indexes.map(() => undefined);
   182             this.inhibit = indexes.map(() => undefined);
   183             this.pending = indexes.map(() => undefined);
   183             this.pending = indexes.map(() => undefined);
   184             this.bound_unhinibit = this.unhinibit.bind(this);
   184             this.bound_unhinibit = this.unhinibit.bind(this);
   185             this.forced_frequency = freq;
   185             this.forced_frequency = freq;
       
   186             this.clip = true;
       
   187         }
       
   188 
       
   189         do_init(){
       
   190             if(widget.forced_frequency !== undefined){
       
   191                 let s = widget.forced_frequency;
       
   192                 /*
       
   193                 once every 10 seconds : 10s
       
   194                 once per minute : 1m
       
   195                 once per hour : 1h
       
   196                 once per day : 1d
       
   197                 */
       
   198                 let unit = s.slice(-1);
       
   199                 let factor = {
       
   200                     "s":1,
       
   201                     "m":60,
       
   202                     "h":3600,
       
   203                     "d":86400}[unit];
       
   204 
       
   205                 widget.frequency = factor ? 1/(factor * Number(s.slice(0,-1)))
       
   206                                           : Number(s);
       
   207             }
       
   208 
       
   209             let init = this.init;
       
   210             if(typeof(init) == "function"){
       
   211                 try {
       
   212                     init.call(this);
       
   213                 } catch(err) {
       
   214                     console.log(err);
       
   215                 }
       
   216             }
   186         }
   217         }
   187 
   218 
   188         unsub(){
   219         unsub(){
   189             /* remove subsribers */
   220             /* remove subsribers */
   190             if(!this.unsubscribable)
   221             if(!this.unsubscribable)
   267         change_hmi_value(index, opstr) {
   298         change_hmi_value(index, opstr) {
   268             let realindex = this.get_variable_index(index);
   299             let realindex = this.get_variable_index(index);
   269             if(realindex == undefined) return undefined;
   300             if(realindex == undefined) return undefined;
   270             let old_val = cache[realindex];
   301             let old_val = cache[realindex];
   271             let new_val = eval_operation_string(old_val, opstr);
   302             let new_val = eval_operation_string(old_val, opstr);
   272             new_val = this.clip_min_max(index, new_val);
   303             if(this.clip)
       
   304                 new_val = this.clip_min_max(index, new_val);
   273             return apply_hmi_value(realindex, new_val);
   305             return apply_hmi_value(realindex, new_val);
   274         }
   306         }
   275 
   307 
   276         _apply_hmi_value(index, new_val) {
   308         _apply_hmi_value(index, new_val) {
   277             let realindex = this.get_variable_index(index);
   309             let realindex = this.get_variable_index(index);
   278             if(realindex == undefined) return undefined;
   310             if(realindex == undefined) return undefined;
   279             new_val = this.clip_min_max(index, new_val);
   311             if(this.clip)
       
   312                 new_val = this.clip_min_max(index, new_val);
   280             return apply_hmi_value(realindex, new_val);
   313             return apply_hmi_value(realindex, new_val);
   281         }
   314         }
   282 
   315 
   283         unhinibit(index){
   316         unhinibit(index){
   284             this.inhibit[index] = undefined;
   317             this.inhibit[index] = undefined;
   393     param "mandatory","'yes'";
   426     param "mandatory","'yes'";
   394     param "subelements","/..";
   427     param "subelements","/..";
   395     param "hmi_element";
   428     param "hmi_element";
   396     const "widget_type","@type";
   429     const "widget_type","@type";
   397     foreach "str:split($labels)" {
   430     foreach "str:split($labels)" {
   398         const "name",".";
   431         const "absolute", "starts-with(., '/')";
   399         const "elt","$result_widgets[@id = $hmi_element/@id]//*[@inkscape:label=$name][1]";
   432         const "name","substring(.,number($absolute)+1)";
       
   433         const "widget","$result_widgets[@id = $hmi_element/@id]";
       
   434         const "elt","($widget//*[not($absolute) and @inkscape:label=$name] | $widget/*[$absolute and @inkscape:label=$name])[1]";
   400         choose {
   435         choose {
   401             when "not($elt/@id)" {
   436             when "not($elt/@id)" {
   402                 if "$mandatory='yes'" {
   437                 if "$mandatory='yes'" {
   403                     error > «$widget_type» widget must have a «$name» element
   438                     error > «$widget_type» widget must have a «$name» element
   404                 }
   439                 }