// Manage the selection list when there is a new current point selected void imodSelectionNewCurPoint(ImodView *vi, Imod *imod, Iindex indSave, int controlDown) { Iindex *indp; bool contourless; // If ctrl-select, then manage selection list if (controlDown) { contourless = indSave.object >= 0 && !vi->imod->obj[indSave.object].contsize && vi->imod->obj[indSave.object].meshsize; // First add previous point if list is empty if (!ilistSize(vi->selectionList) && (indSave.contour >= 0 || contourless)) imodSelectionListAdd(vi, indSave); // If point not on list, add it. If point is on list, then remove // it and pop current point back to last item on list if (imodSelectionListQuery(vi, imod->cindex.object, imod->cindex.contour) < -1) { imodSelectionListAdd(vi, imod->cindex); } else { imodSelectionListRemove(vi, imod->cindex.object, imod->cindex.contour); if (ilistSize(vi->selectionList)) { indp = (Iindex *)ilistItem(vi->selectionList, ilistSize(vi->selectionList) - 1); imod->cindex = *indp; } } } else // But if Ctrl not down, clear out the list imodSelectionListClear(vi); }
// Returns the number of selected objects, and the minimum and maximum // selected object number int imodNumSelectedObjects(ImodView *vi, int &minOb, int &maxOb) { int ob, num; num = 0; for (ob = 0; ob < vi->imod->objsize; ob++) { if (imodSelectionListQuery(vi, ob, -1) > -2 || ob == vi->imod->cindex.object) { if (!num) minOb = ob; num++; maxOb = ob; } } return num; }
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(); }