Changeset 2254


Ignore:
Timestamp:
02/09/07 13:15:22 (13 years ago)
Author:
sorber
Message:

No more single-node freeforms. They are either never constructed or deleted when the node count drops to 1.

Location:
trunk/loci/visbio/overlays
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/visbio/overlays/FreeformTool.java

    r2249 r2254  
    4343  protected static final double DRAW_THRESH = 2.0; 
    4444 
     45  /**  
     46   * How close a mouseDrag event must be to a node 
     47   * in order to erase it 
     48   */ 
     49  protected static final double ERASE_THRESH = 10.0; 
     50 
    4551  /** Threshhold within which click must occur to invoke edit mode. */ 
    4652  protected static final double EDIT_THRESH = 6.0; 
     
    5258  protected static final double RECONNECT_THRESH = 1.0; 
    5359 
    54   /** Constant for "erase" edit mode. */ 
     60  /** Constant for "erase" mode. */ 
    5561  protected static final int ERASE = -1; 
    5662 
    57   /** Constant for "chill" edit mode. */ 
     63  /** Constant for "wait" mode. */ 
    5864  protected static final int CHILL = 0; // could call this WAIT... 
    5965 
    60   /** Consant for "draw" edit mode. */ 
     66  /** Consant for "draw" mode. */ 
    6167  protected static final int DRAW = 1; 
    6268 
    63   /** Constant for "edit" edit mode. */ 
     69  /** Constant for "edit" mode. */ 
    6470  protected static final int EDIT = 2; 
     71 
     72  /** Constant for "init" mode */ 
     73  protected static final int INIT = 3; 
    6574 
    6675  // -- Fields -- 
     
    8089  /** Chunks of curve tracked during EDIT */ 
    8190  protected float[][] pre, post;  
     91 
     92  /** Point at which mouseDown occurs */ 
     93  protected float downX, downY; 
    8294 
    8395  // -- Constructor -- 
     
    165177      if (!ctl) { 
    166178        deselectAll(); 
    167         freeform = new OverlayFreeform(overlay, dx, dy, dx, dy); 
    168         configureOverlay(freeform); 
    169         overlay.addObject(freeform, pos); 
    170         setMode(DRAW); 
     179        // record initial coordinates of freeform 
     180        downX = dx; 
     181        downY = dy; 
     182        setMode(INIT); 
    171183      } 
    172184    } 
     
    180192    float dx, float dy, int[] pos, int mods) 
    181193  { 
     194    if (mode == INIT) { 
     195      freeform = new OverlayFreeform(overlay, downX, downY, downX, downY); 
     196      configureOverlay(freeform); 
     197      overlay.addObject(freeform, pos); 
     198      setMode(DRAW); 
     199    } 
     200 
    182201    boolean shift = (mods & InputEvent.SHIFT_MASK) != 0; 
    183202    boolean ctl = (mods & InputEvent.CTRL_MASK) != 0; 
     
    290309      double mdist = closerToEnd ? edist : bdist; 
    291310 
    292       if (mdist < DRAW_THRESH) { 
     311      if (mdist < ERASE_THRESH) { 
    293312        if (!closerToEnd) freeform.reverseNodes(); 
    294313        if (ctl) { 
     
    542561   */ 
    543562  private void setMode(int newMode) { 
     563    // ACS TODO clean this logic up 
    544564    mode = newMode; 
    545565    if (mode == DRAW || mode == EDIT || mode == ERASE) { 
     
    562582 
    563583    if (mode == CHILL && freeform != null) { 
    564       freeform.computeLength(); 
    565       freeform.updateBoundingBox(); 
    566       freeform.computeGridParameters(); 
    567       freeform.setDrawing(false); 
    568       freeform = null; 
     584      if (freeform.getNumNodes() <= 1) overlay.removeObject(freeform); 
     585      else { 
     586        freeform.computeLength(); 
     587        freeform.updateBoundingBox(); 
     588        freeform.computeGridParameters(); 
     589        freeform.setDrawing(false); 
     590        freeform = null; 
     591      } 
    569592    } 
    570593  } 
  • trunk/loci/visbio/overlays/OverlayObject.java

    r2123 r2254  
    500500      nodes = newNodes; 
    501501      if (numNodes == 0) overlay.removeObject(this); 
     502      if (numNodes <= 1) overlay.removeObject(this); 
    502503    } else { 
    503504      //System.out.println("deleteBetween(int, int) out of bounds error"); 
     
    524525        overlay.removeObject(this); 
    525526      } 
     527      if (numNodes <= 1) overlay.removeObject(this); 
    526528    } 
    527529  } 
Note: See TracChangeset for help on using the changeset viewer.