Date:2012-05-26 00:20:29 (11 years 10 months ago)
Author:Werner Almesberger
Commit:e0351bdf738ee187c68fecc0016d71dc0eb68668
Message:make active package track active variables (for the GUI)

If the package whose name is produced by the active variable values
is active and the variables change, then make the newly active
package the one whose name is produced by the changed variables.

This way, iterating through a table or a loop will automatically
switch to the right package, with the exception that, if the user
choses to explicitly select a different package (by clicking on
its name in the packages line), then that selection takes priority.

Explicit selection loses its priority when active package and active
variables coincide again. I.e., one can simply "catch" the active
package by activating the corresponding values.
Files: gui.c (1 diff)
inst.c (4 diffs)
inst.h (2 diffs)
meas.c (1 diff)
obj.c (2 diffs)

Change Details

gui.c
322322void change_world(void)
323323{
324324    struct bbox before, after;
325    int reachable_is_active;
325326
326327    inst_deselect();
327328    status_begin_reporting();
328329    before = inst_get_bbox();
330    reachable_is_active = reachable_pkg && reachable_pkg == active_pkg;
331    reachable_pkg = NULL;
329332    instantiate();
333    if (reachable_is_active && reachable_pkg &&
334         reachable_pkg != active_pkg) {
335        active_pkg = reachable_pkg;
336        instantiate();
337    }
330338    after = inst_get_bbox();
331339    label_in_box_bg(active_frame->label, COLOR_FRAME_SELECTED);
332340    do_build_frames();
inst.c
3535struct inst *selected_inst = NULL;
3636struct bbox active_frame_bbox;
3737struct pkg *pkgs, *active_pkg, *curr_pkg;
38struct pkg *reachable_pkg = NULL;
3839struct inst *frame_instantiating = NULL;
3940
4041static struct pkg *prev_pkgs;
...... 
11731174/* ----- package ----------------------------------------------------------- */
11741175
11751176
1176void inst_select_pkg(const char *name)
1177void inst_select_pkg(const char *name, int active)
11771178{
11781179    struct pkg **pkg;
11791180    enum inst_prio prio;
...... 
11921193        (*pkg)->n_samples = n_samples;
11931194    }
11941195    curr_pkg = *pkg;
1196    if (active && name)
1197        reachable_pkg = curr_pkg;
11951198}
11961199
11971200
...... 
12461249    active_frame_bbox = bbox_zero;
12471250    prev_pkgs = pkgs;
12481251    pkgs = NULL;
1249    inst_select_pkg(NULL);
1252    inst_select_pkg(NULL, 0);
12501253    curr_pkg = pkgs;
12511254    frame_instantiating = NULL;
12521255}
inst.h
134134extern struct pkg *pkgs; /* list of packages */
135135extern struct pkg *active_pkg; /* package selected in GUI */
136136extern struct pkg *curr_pkg; /* package currently being instantiated */
137extern struct pkg *reachable_pkg; /* package reachable with active vars */
137138extern struct bbox active_frame_bbox;
138139
139140/*
...... 
195196    struct coord base, int active, int is_active_frame);
196197void inst_end_frame(const struct frame *frame);
197198
198void inst_select_pkg(const char *name);
199void inst_select_pkg(const char *name, int active);
199200
200201struct bbox inst_get_bbox(void);
201202
meas.c
317317    frame_instantiating = pkgs->insts[ip_frame];
318318    for (pkg = pkgs; pkg; pkg = pkg->next)
319319        if (pkg->name) {
320            inst_select_pkg(pkg->name);
320            inst_select_pkg(pkg->name, 0);
321321            if (!instantiate_meas_pkg(n_frames))
322322                return 0;
323323            purge_meas(pkg);
obj.c
11/*
22 * obj.c - Object definition model
33 *
4 * Written 2009-2011 by Werner Almesberger
5 * Copyright 2009-2011 by Werner Almesberger
4 * Written 2009-2012 by Werner Almesberger
5 * Copyright 2009-2012 by Werner Almesberger
66 *
77 * This program is free software; you can redistribute it and/or modify
88 * it under the terms of the GNU General Public License as published by
...... 
336336    if (frame == frames) {
337337        s = expand(pkg_name, frame);
338338        /* s is NULL if expansion failed */
339        inst_select_pkg(s ? s : "_");
339        inst_select_pkg(s ? s : "_", active);
340340        free(s);
341341    }
342342    inst_begin_active(active && frame == active_frame);

Archive Download the corresponding diff file

Branches:
master



interactive