Changeset 5445


Ignore:
Timestamp:
08/14/09 17:53:21 (4 years ago)
Author:
werner
Message:
  • when selecting an item in the canvas, we now check that the underlying object is still connected. This prevents surprises when making extensive changes during instantiation failure.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/eda/fped/inst.c

    r5440 r5445  
    4141static unsigned long active_set = 0; 
    4242 
     43static struct inst_ops vec_ops; 
     44static struct inst_ops frame_ops; 
     45 
    4346 
    4447#define IS_ACTIVE       ((active_set & 1)) 
     
    8891 
    8992 
     93/* ----- check connectedness ----------------------------------------------- */ 
     94 
     95 
     96/* 
     97 * After an instantiation failure, the instances can get out of sync with the 
     98 * object tree, and attempts to select an item on the canvas can cause accesses 
     99 * to objects that aren't there anymore. So we need to check if we can still 
     100 * reach the corresponding object. 
     101 * 
     102 * Note: even this isn't bullet-proof. Theoretically, we may get a new object 
     103 * in the old place. However, this probably doesn't do any serious damage. 
     104 */ 
     105 
     106 
     107static int inst_connected(const struct inst *inst) 
     108{ 
     109        const struct frame *frame; 
     110        const struct vec *vec; 
     111        const struct obj *obj; 
     112 
     113        for (frame = frames; frame; frame = frame->next) { 
     114                if (inst->ops == &vec_ops) { 
     115                        for (vec = frame->vecs; vec; vec = vec->next) 
     116                                if (vec == inst->vec) 
     117                                        return 1; 
     118                } else { 
     119                        for (obj = frame->objs; obj; obj = obj->next) 
     120                                if (obj == inst->obj) 
     121                                        return 1; 
     122                } 
     123        } 
     124        return 0; 
     125} 
     126 
     127 
    90128/* ----- selection --------------------------------------------------------- */ 
    91  
    92  
    93 static struct inst_ops vec_ops; 
    94 static struct inst_ops frame_ops; 
    95129 
    96130 
     
    140174                for (inst = insts[prio]; inst; inst = inst->next) { 
    141175                        if (!inst->active || !inst->ops->distance) 
     176                                continue; 
     177                        if (!inst_connected(inst)) 
    142178                                continue; 
    143179                        dist = inst->ops->distance(inst, pos, draw_ctx.scale); 
     
    158194        for (inst = insts[ip_vec]; inst; inst = inst->next) { 
    159195                if (!inst->active) 
     196                        continue; 
     197                if (!inst_connected(inst)) 
    160198                        continue; 
    161199                dist = gui_dist_vec_fallback(inst, pos, draw_ctx.scale); 
Note: See TracChangeset for help on using the changeset viewer.