svghmi/widget_jump.ysl2
author Edouard Tisserant
Thu, 25 Mar 2021 10:13:12 +0100
branchsvghmi
changeset 3199 1582753e409b
parent 3107 ee0704cc6dc8
child 3232 7bdb766c2a4d
child 3240 5f756332ada1
permissions -rw-r--r--
SVGHMI: Filter unseen geometry from inkscape CSV output.

When inkscape exports geometry form all objects, then it also includes objects from svg:defs. This makes problems when deciding if an object is part of a page, since coordinate of objects in svg:defs can eventualy be contained in a page. In the end, those objects where getting detached when leaving pages where they where found, leading for exemple to non working text on clipping when the clipped text was cloned in multiple page.
// widget_jump.ysl2

template "widget[@type='Jump']", mode="widget_class"{
||
    class JumpWidget extends Widget{

        activable = false;
        active = false;
        disabled = false;
        frequency = 2;

        update_activity() {
            if(this.active) {
                 /* show active */ 
                 this.active_elt.setAttribute("style", this.active_elt_style);
                 /* hide inactive */ 
                 this.inactive_elt.setAttribute("style", "display:none");
            } else {
                 /* show inactive */ 
                 this.inactive_elt.setAttribute("style", this.inactive_elt_style);
                 /* hide active */ 
                 this.active_elt.setAttribute("style", "display:none");
            }
        }

        make_on_click() {
            let that = this;
            const name = this.args[0];
            return function(evt){
                /* TODO: suport path pointing to local variable whom value 
                   would be an HMI_TREE index to jump to a relative page */
                const index = that.indexes.length > 0 ? that.indexes[0] + that.offset : undefined;
                switch_page(name, index);
            }
        }

        notify_page_change(page_name, index) {
            if(this.activable) {
                const ref_index = this.indexes.length > 0 ? this.indexes[0] + this.offset : undefined;
                const ref_name = this.args[0];
                this.active = ((ref_name == undefined || ref_name == page_name) && index == ref_index);
                this.update_activity();
            }
        }

        dispatch(value) {
            this.disabled = !Number(value);
            if(this.disabled) {
              /* show disabled */ 
              this.disabled_elt.setAttribute("style", this.disabled_elt_style);
              /* hide inactive */ 
              this.inactive_elt.setAttribute("style", "display:none");
              /* hide active */ 
              this.active_elt.setAttribute("style", "display:none");
            } else {
              /* hide disabled */ 
              this.disabled_elt.setAttribute("style", "display:none");
              this.update_activity();
            }
        }
    }
||
}

template "widget[@type='Jump']", mode="widget_defs" {
    param "hmi_element";
    const "activity" optional_labels("active inactive");
    const "have_activity","string-length($activity)>0";
    value "$activity";

    const "disability" optional_labels("disabled");
    const "have_disability","$have_activity and string-length($disability)>0";
    value "$disability";

    |     init: function() {
    |         this.element.onclick = this.make_on_click();
    if "$have_activity" {
    |         this.active_elt_style = this.active_elt.getAttribute("style");
    |         this.inactive_elt_style = this.inactive_elt.getAttribute("style");
    |         this.activable = true;
    }
    choose {
        when "$have_disability" {
    |         this.disabled_elt_style = this.disabled_elt.getAttribute("style");
        }
        otherwise {
    |         this.unsubscribable = true;
        }
    }
    |     },
}

template "widget[@type='Jump']", mode="per_page_widget_template"{
    param "page_desc";
    /* check that given path is compatible with page's reference path */
    if "path" {
        /* TODO: suport local variable containing an HMI_TREE index to jump to a relative page */
        /* when no page name provided, check for same page */
        const "target_page_name" choose {
            when "arg" value "arg[1]/@value";
            otherwise value "$page_desc/arg[1]/@value";
        }
        const "target_page_path" choose {
            when "arg" value "$hmi_pages_descs[arg[1]/@value = $target_page_name]/path[1]/@value";
            otherwise value "$page_desc/path[1]/@value";
        }

        if "not(func:same_class_paths($target_page_path, path[1]/@value))"
            error > Jump id="«@id»" to page "«$target_page_name»" with incompatible path "«path[1]/@value» (must be same class as "«$target_page_path»")
    }
}

emit "declarations:jump"
||
var jumps_need_update = false;
var jump_history = [[default_page, undefined]];

function update_jumps() {
    page_desc[current_visible_page].jumps.map(w=>w.notify_page_change(current_visible_page,current_page_index));
    jumps_need_update = false;
};

||