コード例 #1
0
ファイル: mv_image.cpp プロジェクト: LabShare/IMOD
// respond to a change of transparency or contrast
void ImodvImage::sliderMoved(int which, int value, bool dragging)
{
  switch (which) {
  case IIS_X_COORD:
    Imodv->vi->xmouse = value - 1;
    ivwBindMouse(Imodv->vi);
    break;
  case IIS_Y_COORD:
    Imodv->vi->ymouse = value - 1;
    ivwBindMouse(Imodv->vi);
    break;
  case IIS_Z_COORD:
    Imodv->vi->zmouse = value - 1;
    ivwBindMouse(Imodv->vi);
    break;

  case IIS_X_SIZE:
    sXdrawSize = value;
    break;
  case IIS_Y_SIZE:
    sYdrawSize = value;
    break;
  case IIS_Z_SIZE:
    sZdrawSize = value;
    break;

  case IIS_SLICES: 
    sNumSlices = value;
    break;

  case IIS_TRANSPARENCY: 
    sImageTrans = value;
    Imodv->texTrans = sImageTrans;
    break;

  case IIS_BLACK:
    sBlackLevel = value;
    makeColorMap();
    break;
  case IIS_WHITE:
    sWhiteLevel = value;
    makeColorMap();
    break;
  }

  // draw if slider clicked or is in hot state
  if (!dragging || ImodPrefs->hotSliderActive(mCtrlPressed)) {
    if (which > IIS_Z_COORD)
      imodvDraw(Imodv);
    else
      imodDraw(Imodv->vi, IMOD_DRAW_XYZ);
  }
}
コード例 #2
0
ファイル: utilities.cpp プロジェクト: imod-mirror/IMOD
// 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);
}
コード例 #3
0
ファイル: client_message.cpp プロジェクト: LabShare/IMOD
// This function performs the action after the delay is up.  It returns
// true if the program is still to quit
bool ImodClipboard::executeMessage()
{
  int returnValue, arg;
  int succeeded = 1;
  static int checkSum = 0;
  int newCheck;
  QString convName;
  QDir *curdir;
  ZapFuncs *zap;
  int movieVal, xaxis, yaxis, zaxis, taxis;
  int objNum, type, symbol, symSize, ptSize, mode, mask, interval;
  bool props1;
  Imod *imod;
  Iobj *obj;
  int symTable[] = 
    { IOBJ_SYM_NONE, IOBJ_SYM_CIRCLE, IOBJ_SYM_SQUARE, IOBJ_SYM_TRIANGLE };

  // Number of arguments required - for backward compatibility, going to
  // model mode does not require one but should have one
  int requiredArgs[] = {0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 5, 5, 0, 2, 4, 4, 3, 1, 1};
  int numArgs = sMessageStrings.count();

  // Loop on the actions in the list; set arg to numArgs to break loop
  for (arg = 0; arg < numArgs; arg++) {
    imod = App->cvi->imod;

    // Get the action, then check that there are enough values for it
    sMessageAction = sMessageStrings[arg].toInt();
    if (sMessageAction >= 0 && sMessageAction < sizeof(requiredArgs) / sizeof(int) &&
        arg + requiredArgs[sMessageAction] >= numArgs) {
        imodPrintStderr("imodExecuteMessage: not enough values sent"
                " with action command %d\n", sMessageAction);
        succeeded = 0;
        break;
    }

    // If still in initial load, skip the arguments (and one more if model mode message)
    if (sInitialLoad) {
      if (sMessageAction >= 0 && sMessageAction < sizeof(requiredArgs) / sizeof(int))
        arg += requiredArgs[sMessageAction];
      if (arg < numArgs - 1 && sMessageAction == MESSAGE_MODEL_MODE)
        arg++;

      // Stop processing after a plugin message because the length is unknown
      // and stop after seeing a quit
      if (sMessageAction == MESSAGE_PLUGIN_EXECUTE || sMessageAction == MESSAGE_QUIT) 
        arg = numArgs;
      continue;
    }

    if (Imod_debug) {
      QTime curTime = QTime::currentTime();
      wprint("%02d:%02d.%03d: Executing message action %d\n", 
             curTime.minute(), curTime.second(), curTime.msec(), sMessageAction);
      imodPrintStderr("%02d:%02d.%03d: imodHCM in executeMessage: executing message "
                      "action %d\n", 
                      curTime.minute(), curTime.second(), curTime.msec(), sMessageAction);
      if (imodDebug('C')) {
        newCheck = imodChecksum(App->cvi->imod);
        wprint("Checksum before = %d\n", newCheck);
        if (checkSum && newCheck != checkSum)
          wprint("\aIT CHANGED SINCE LAST TIME\n");
        checkSum = newCheck;
      }
    }

    if (ImodvClosed || !Imodv->standalone) {
      switch (sMessageAction) {
        
      case MESSAGE_OPEN_MODEL:
      case MESSAGE_OPEN_KEEP_BW:
        curdir = new QDir();
        convName = curdir->cleanPath(sMessageStrings[++arg]);
        delete curdir;
    
        // Since this could open a dialog with an indefinite delay, just send
        // the OK signal now
        succeeded = -1;
        sendResponse(1);
        inputRaiseWindows();

        // DNM 6/3/04: switch to keeping BW values in the first place
        returnValue = openModel(LATIN1(convName), 
                                sMessageAction == MESSAGE_OPEN_KEEP_BW, false);
        if(returnValue == IMOD_IO_SUCCESS) {
          wprint("%s loaded.\n", 
                 LATIN1(QDir::convertSeparators(QString(Imod_filename))));

        }
        else if(returnValue == IMOD_IO_SAVE_ERROR) {
          wprint("Error Saving Model. New model not loaded.\n");
          arg = numArgs;
        }
        else if(returnValue == IMOD_IO_SAVE_CANCEL) {
          wprint("Operation cancelled. New model not loaded.\n");
          arg = numArgs;
        }

        // The model does not exist yet.  Try creating a new model.
        else if(returnValue == IMOD_IO_DOES_NOT_EXIST) {
          returnValue = createNewModel(LATIN1(convName));
          if(returnValue == IMOD_IO_SUCCESS) {
        
            wprint("New model %s created.\n", 
                   LATIN1(QDir::convertSeparators(QString(Imod_filename))));
          }
          else {
            wprint("Could not create a new model %s.\n", 
                   LATIN1(sMessageStrings[arg]));
            arg = numArgs;
          }
        }
        else if(returnValue == IMOD_IO_NO_ACCESS_ERROR) {
          wprint("Error opening model. Check file permissions\n.");
          arg = numArgs;
        }
        else {
          wprint("Unknown return code, new model not loaded!!\n");
          arg = numArgs;
        }
        break;

      case MESSAGE_SAVE_MODEL:
        succeeded = -1;
        sendResponse(1);
        imod->blacklevel = App->cvi->black;
        imod->whitelevel = App->cvi->white;
        returnValue = SaveModel(imod);
        break;

      case MESSAGE_VIEW_MODEL:
        imod_autosave(imod);
        inputRaiseWindows();
        imodv_open();
        break;

      case MESSAGE_QUIT:
        arg = numArgs;
        break;

      case MESSAGE_RAISE_WINDOWS:
        inputRaiseWindows();
        break;

      case MESSAGE_MODEL_MODE:
        movieVal = 1;
        if (arg < numArgs - 1)
          movieVal = sMessageStrings[++arg].toInt();
        if (movieVal > 0)
          imod_set_mmode(IMOD_MMODEL);
        else {
          imod_set_mmode(IMOD_MMOVIE);
          if (movieVal < 0) {
            xaxis = (-movieVal) & 1 ? 1 : 0;
            yaxis = (-movieVal) & 2 ? 1 : 0;
            zaxis = (-movieVal) & 4 ? 1 : 0;
            taxis = (-movieVal) & 8 ? 1 : 0;
            imodMovieXYZT(App->cvi, xaxis, yaxis, zaxis, taxis);
          }
        }
        break;

      case MESSAGE_OPEN_BEADFIXER:
        imodPlugOpenByName("Bead Fixer");
        break;

      case MESSAGE_ONE_ZAP_OPEN:
        inputRaiseWindows();
        if (!imodDialogManager.windowCount(ZAP_WINDOW_TYPE) &&
            imodLoopStarted())
          imod_zap_open(App->cvi, 0);
        break;

      case MESSAGE_RUBBERBAND:
        zapReportRubberband();
        break;

      case MESSAGE_SLICER_ANGLES:
        slicerReportAngles();
        break;

      case MESSAGE_OBJ_PROPERTIES:
      case MESSAGE_NEWOBJ_PROPERTIES:
      case MESSAGE_OBJ_PROPS_2:
      case MESSAGE_NEWOBJ_PROPS_2:
        props1 = sMessageAction == MESSAGE_OBJ_PROPERTIES ||
          sMessageAction == MESSAGE_NEWOBJ_PROPERTIES;
        objNum = sMessageStrings[++arg].toInt();
        type = sMessageStrings[++arg].toInt();
        symbol = sMessageStrings[++arg].toInt();
        symSize = sMessageStrings[++arg].toInt();
        if (props1)
          ptSize = sMessageStrings[++arg].toInt();

        // Object is numbered from 1, so decrement and test for substituting
        // current object
        if (--objNum < 0)
          objNum = imod->cindex.object;
        if (objNum < 0 || objNum >= imod->objsize) {
          imodPrintStderr("imodExecuteMessage: illegal object # sent with "
                          "object property command\n");
          succeeded = 0;
          arg = numArgs;
          break;
        }
        obj = &imod->obj[objNum];

        // If object has contours, skip for NEWOBJ message
        if (obj->contsize && (sMessageAction == MESSAGE_NEWOBJ_PROPERTIES ||
                              sMessageAction == MESSAGE_NEWOBJ_PROPS_2))
          break;

        if (props1) {

          // Process the changes if not -1: object type
          if (type >= 0 && type < 3) {
            switch (type) {
            case 0:
              obj->flags &= ~(IMOD_OBJFLAG_OPEN | IMOD_OBJFLAG_SCAT);
              break;
            case 1:
              obj->flags |= IMOD_OBJFLAG_OPEN;
              obj->flags &= ~IMOD_OBJFLAG_SCAT;
              break;
            case 2:
              obj->flags |= IMOD_OBJFLAG_SCAT | IMOD_OBJFLAG_OPEN;
              break;
            }
          }
        
          // Symbol type and filled
          if (symbol >= 0) {
            if ((symbol & 7) < (sizeof(symTable) / sizeof(int)))
              obj->symbol = symTable[symbol & 7];
            utilSetObjFlag(obj, 0, (symbol & 8) != 0, IOBJ_SYMF_FILL);
          }
          
          // Symbol size, 3d point size
          if (symSize > 0)
            obj->symsize = symSize;
          if (ptSize >= 0)
            obj->pdrawsize = ptSize;
        } else {

          // Points per contour
          if (type >= 0)
            obj->extra[IOBJ_EX_PNT_LIMIT] = type;

          // Planar contours
          if (symbol >= 0)
            utilSetObjFlag(obj, 0, symbol != 0, IMOD_OBJFLAG_PLANAR);

          // Sphere on sec only
          if (symSize >= 0)
            utilSetObjFlag(obj, 0, symSize != 0, IMOD_OBJFLAG_PNT_ON_SEC);
        }        

        // The general draw updates object edit window, but need to call 
        // imodv object edit for it to update
        imodDraw(App->cvi, IMOD_DRAW_MOD);
        imodvObjedNewView();

        // If no contours and only 1 obj, set checksum to avoid save requests
        if (imod->objsize == 1 && !obj->contsize) {
          imod->csum = imodChecksum(imod);
          if (imodDebug('C'))
            wprint("handleMessage set checksum %d\n", imod->csum);
        }
        break;

      case MESSAGE_GHOST_MODE:
        mode = sMessageStrings[++arg].toInt();
        mask = sMessageStrings[++arg].toInt();
        App->cvi->ghostmode = (App->cvi->ghostmode & ~mask) | (mode & mask);
        interval = sMessageStrings[++arg].toInt();
        if (interval >= 0)
          App->cvi->ghostdist = interval;
        imodDraw(App->cvi, IMOD_DRAW_MOD);
        break;
        
      case MESSAGE_ZAP_HQ_MODE:
        mode = sMessageStrings[++arg].toInt() != 0 ? 1 : 0;
        zap = getTopZapWindow(false);
        if (zap) {
          zap->stateToggled(ZAP_TOGGLE_RESOL, mode);
          zap->mQtWindow->setToggleState(ZAP_TOGGLE_RESOL, mode);
        } else
          zapSetNextOpenHQstate(mode);
        break;

      case MESSAGE_OPEN_DIALOGS:
        if (!ImodvClosed)
          imodvOpenSelectedWindows(LATIN1(sMessageStrings[arg + 1]));
        ImodInfoWin->openSelectedWindows(LATIN1(sMessageStrings[++arg]),
                                         ImodvClosed ? 0 : 1);
        break;

      case MESSAGE_PLUGIN_EXECUTE:
        arg++;
        if (imodPlugMessage(App->cvi, &sMessageStrings, &arg)) {
          succeeded = 0;
          arg = numArgs;
          break;
        }
        break;

      default:
        imodPrintStderr("imodExecuteMessage: action %d not recognized\n"
                        , sMessageAction);
        succeeded = 0;
        arg = numArgs;
      }
    } else {
      
      // Messages for 3dmodv
      switch (sMessageAction) {
      case MESSAGE_QUIT:
        arg = numArgs;
        break;
        
      case MESSAGE_RAISE_WINDOWS:
        imodvInputRaise();
        break;
        
      case MESSAGE_OPEN_DIALOGS:
        imodvOpenSelectedWindows(LATIN1(sMessageStrings[++arg]));
        break;

      default:
        imodPrintStderr("imodExecuteMessage: action %d not recognized by"
                        " 3dmodv\n" , sMessageAction);
        succeeded = 0;
        arg = numArgs;
      }
    }
  }

  if (imodDebug('C')) {
    wprint("Checksum after = %d\n", newCheck);
    if (newCheck != checkSum)
      wprint("\aIT CHANGED IN THAT OPERATION\n");
    checkSum = newCheck;
  }

  // Now set the clipboard with the response as long as we aren't doing deferred
  if (succeeded >= 0 && mDeferredHandling <= 0)
    sendResponse(succeeded);

  // Only do deferred handling once
  if (mDeferredHandling > 0)
    mDeferredHandling = 0;
  return sMessageAction == MESSAGE_QUIT;
}
コード例 #4
0
ファイル: cont_copy.cpp プロジェクト: imod-mirror/IMOD
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();
}