Example #1
0
// Move all contours in current object to new object
void imodMoveAllContours(ImodView *vi, int obNew)
{
  int co;
  Imod *imod = vi->imod;
  Iobj *obj = imodObjectGet(imod);

  // Just record an object property change since there may be max surface number changes
  // as well as the store info
  vi->undo->objectPropChg();
  vi->undo->objectPropChg(obNew);

  // If object has mesh but no contours, transfers the meshes
  if (!obj->contsize && obj->meshsize) {
    for (co = 0; co < obj->meshsize; co++)
      imod->obj[obNew].mesh = imodel_mesh_add(&obj->mesh[co], imod->obj[obNew].mesh,
                                              &imod->obj[obNew].meshsize);
    return;
  }

  // Move all the fine grain information over then delete the store
  if (ilistSize(obj->store)) {
    for (co = 0; co <= obj->surfsize; co++)
      istoreCopyContSurfItems(obj->store, &imod->obj[obNew].store, co, co, 1);
    for (co = 0; co < obj->contsize; co++)
      istoreCopyContSurfItems(obj->store, &imod->obj[obNew].store, co, 
                                    imod->obj[obNew].contsize + co, 0);
    ilistDelete(obj->store);
    obj->store = NULL;
  }

  // Record all contours as moving
  vi->undo->allContourMove(imod->cindex.object, obNew);
  
  /* DNM: need to set contour inside loop because each deletion
     sets it to -1; and need to not increment counter!  */
  for (co = 0; co < (int)obj->contsize; ) {
    imod->cindex.contour = 0;
    imodObjectAddContour(&imod->obj[obNew], &obj->cont[co]);
    imodObjectRemoveContour(obj, co);
  }
}
Example #2
0
// Changes the size of the current point given the zoom and scroll wheel delta value
void utilWheelChangePointSize(ImodView *vi, float zoom, int delta)
{
  int ix, iy, pt;
  Iobj *obj;
  Icont *cont;
  float size;
  imodGetIndex(vi->imod, &ix, &iy, &pt);
  obj = imodObjectGet(vi->imod);
  cont = imodContourGet(vi->imod);
  if (!cont || pt < 0)
    return;
  size = imodPointGetSize(obj, cont, pt);
  if (!size && (!cont->sizes || (cont->sizes && cont->sizes[pt] < 0)))
    return;
  size += delta * utilWheelToPointSizeScaling(zoom);
  size = B3DMAX(0., size);
  vi->undo->contourDataChg();
  imodPointSetSize(cont, pt, size);
  vi->undo->finishUnit();
  imodDraw(vi, IMOD_DRAW_MOD);
}
Example #3
0
Icont *utilAutoNewContour(ImodView *vi, Icont *cont, bool notInPlane, bool timeMismatch,
                          int timeLock, int setSurface, const char *planeText,
                          const char *surfText)
{
  Iobj *obj = imodObjectGet(vi->imod);
  const char *baseMess = "Started a new contour even though last contour had only 1 pt. ";
  if (cont->psize == 1) {
    if (notInPlane && iobjClose(obj->flags))
      wprint("\a%s Use open contours to model across %s.\n", baseMess, planeText);
    else if (notInPlane)
      wprint("\a%s Turn off \"Start new contour at new Z\" to model "
             "across %s.\n", baseMess, planeText);
    else
      wprint("\a%s Set contour time to 0 to model across times.\n", baseMess);
  }
  inputNewContourOrSurface(vi, setSurface, timeLock);
  cont = imodContourGet(vi->imod);
  if (!cont)
    return NULL;
  if (setSurface == INCOS_NEW_SURF)
    wprint("Started new surface # %d due to change in %s\n", cont->surf, surfText);
  return cont;
}
Example #4
0
void ContourCopy::apply()
{
  const char *badCopy = "Copy operation cancelled.  ";
  /*     char *badObjectErrorMsg = 
         "\nCopy operation cancelled.\n"
         "Object out of range or invalid\n.";
  */

  Imod *imod = sData.vw->imod;
  Iobj *obj   = imodObjectGet(imod);
  Icont *cont = imodContourGet(imod);
  Icont *ncont;
  bool doingSection = false;
  int ob, co, errcode, maxcont;

  if (!obj){
    wprint("\a%sBad input object.\n",badCopy);
    return;
  }

  /* DNM: check validity of current contour: here test on all the
     conditions where a current contour is not needed */
  if (!((sData.doAll || sData.doAllObj) && 
        (sData.copyOperation == COPY_TO_OBJECT ||
         sData.copyOperation == COPY_TO_CURRENT || 
         sData.copyOperation == COPY_TO_TIME))) {
    if ((!cont) || (cont->psize <= 0)){
      wprint("\a%sBad input contour.\n", badCopy);
      return;
    }
    
    /* Set surface number here since we know we have a contour */
    sData.surfaceNumber = cont->surf;
  }

  /* check copy to place is valid. */
  switch(sData.copyOperation){
  case COPY_TO_OBJECT:
    if ((sData.objectNumber < 1) ||
        (sData.objectNumber > (int)imod->objsize) ||
        (sData.objectNumber == imod->cindex.object + 1)){
      wprint("\a%sBad destination object.\n", badCopy);
      return;
    }
    if (sData.makeEllipse && 
        (!iobjClose(obj->flags) || !iobjClose(imod->obj[sData.objectNumber - 1].flags))) {
      wprint("\aTo make ellipses, objects to copy from and to must both be closed.\n");
      return;
    }
    break;

  case COPY_TO_CURRENT:
    break;

  case COPY_TO_SECTION:
    /* get section number to copy from.*/
    sData.currentSection = (int)floor(cont->pts->z + 0.5);

    /* check section number to copy to. */
    if ((sData.sectionNumber <= 0) || 
        ( sData.sectionNumber > sData.vw->zsize ) ||
        (sData.currentSection + 1 == sData.sectionNumber)){
      wprint("\a%sBad destination section.\n", badCopy);
      return;
    }
    doingSection = true;
    break;

  case COPY_TO_TIME:
    sData.currentTime = cont->time;
    if ((sData.timeIndex > sData.vw->numTimes) ||
        ( sData.timeIndex < 1) || 
        (sData.timeIndex ==  sData.vw->curTime)) {
      wprint("\a%sBad destination time index.\n", badCopy);
      return;
    }
    break;

    /* DNM 2/16/01: made these work relative to section of current
       contour */
  case COPY_TO_NEXT_SECTION:
    sData.currentSection = (int)floor(cont->pts->z + 0.5);
    if (sData.currentSection == (sData.vw->zsize - 1)){
      wprint("\a%sNext section invalid.\n", badCopy);
      return;
    }
    sData.sectionNumber = sData.currentSection + 2;
    doingSection = true;
    break;

  case COPY_TO_PREV_SECTION:
    sData.currentSection = (int)floor(cont->pts->z + 0.5);
    if (!sData.currentSection){
      wprint("\a%sPrevious section invalid.\n", badCopy);
      return;
    }
    sData.sectionNumber = sData.currentSection;
    doingSection = true;
    break;

  }


  /* Loop on all objects, skip if not doing all or it is not current one or it is not 
     selected and it is an allowed operation */
  for (ob = 0; ob < (int)imod->objsize; ob++) {
    if (!(sData.doAllObj || ob == imod->cindex.object || 
          (!sData.doAllObj && !sData.doSurface && !sData.doAll && 
           (doingSection || sData.copyOperation == COPY_TO_TIME) &&
           imodSelectionListQuery(sData.vw, ob, -1) > -2)))
      continue;

    sData.currentObject = ob;
    obj = &imod->obj[ob];
    maxcont = obj->contsize;

    /* look at all contours in current object */
    for (co = 0; co < maxcont; co++) {
      cont = &obj->cont[co];

      /* If copying to section, check for being at source section */
      if (doingSection) {
        if (!cont->psize)
          continue;
        if (floor(cont->pts->z + 0.5) != sData.currentSection)
          continue;
      }
        
      /* If copying to time, check for being at source time */
      if ((sData.copyOperation == COPY_TO_TIME) &&
          (cont->time != sData.currentTime))
        continue;

      /* If copying surface, make sure surface matches */
      if (sData.doSurface && cont->surf != sData.surfaceNumber)
        continue;

      /* copy the entire contour */
      if (cont->psize && (sData.doAll || sData.doAllObj || sData.doSurface || 
                          (co == imod->cindex.contour && ob == imod->cindex.object) || 
                          imodSelectionListQuery(sData.vw, ob, co) > -2)) {
        if (sData.copyOperation == COPY_TO_OBJECT && sData.makeEllipse) {
          errcode = copyAsEllipse(cont);
        } else {
          ncont  = imodContourDup(cont);
          errcode = copyContour(ncont, co);
          free(ncont);
        }
        if (errcode)
          wprint("\a%sFailed to duplicate contour correctly.\n", badCopy);
      }
    }
  }
  sData.vw->undo->finishUnit();
  wprint("Copy operation completed\n");
  imodDraw(sData.vw, IMOD_DRAW_MOD);
  imod_setxyzmouse();
}
Example #5
0
/*
 * Copy a single contour, cont, to the place it needs to go.
 *
 */
static int copyContour(Icont *cont, int coNum)
{
  Iobj *toObj;
  int co,pt;
  int section;
  ImodView *vw = sData.vw;
  int obnum = vw->imod->cindex.object;

  if (!cont) return(-1);
  if (!cont->psize) return(-1);

  switch(sData.copyOperation){

  case COPY_TO_OBJECT:
    obnum = sData.objectNumber - 1;
    toObj = &vw->imod->obj[obnum];

    /* Don't copy if duplicate contour already exists. */
    for(co = 0; co < toObj->contsize; co++){
      if (contCompare(&toObj->cont[co], cont) == 0)
        return(0);
    }
    vbCleanupVBD(toObj);

    /* Remove duplicate points */
    if (iobjScat(toObj->flags)){
      for(co = 0; co < toObj->contsize; co++){
        contRmDup(&toObj->cont[co], cont);
      }
    }
    vw->undo->contourAddition(obnum, toObj->contsize);
    imodObjectAddContour(toObj, cont);
    break;

  case COPY_TO_CURRENT:
    toObj = imodObjectGet(vw->imod);
    vw->undo->contourAddition(obnum, toObj->contsize);
    imodObjectAddContour(toObj, cont);
    break;

  case COPY_TO_SECTION:
  case COPY_TO_NEXT_SECTION:
  case COPY_TO_PREV_SECTION:
    toObj   = &vw->imod->obj[sData.currentObject];
    section = sData.sectionNumber-1; 
    for(pt = 0; pt < cont->psize; pt++){
      cont->pts[pt].z = section;
    }
    vw->undo->contourAddition(sData.currentObject, toObj->contsize);
    imodObjectAddContour(toObj, cont);
    break;

  case COPY_TO_TIME:
  case COPY_TO_NEXT_TIME:
    toObj   = &vw->imod->obj[sData.currentObject];
    cont->time = sData.timeIndex;
    vw->undo->contourAddition(sData.currentObject, toObj->contsize);
    imodObjectAddContour(toObj, cont);
    break;
  }

  // Copy any contour properties from source to destination object
  if (istoreCountContSurfItems(vw->imod->obj[sData.currentObject].store, 
                               coNum, 0)) {
    vw->undo->objectPropChg(obnum);
    istoreCopyContSurfItems(vw->imod->obj[sData.currentObject].store, 
                             &toObj->store, coNum, toObj->contsize - 1, 0);
  }

  return(0);
}