// Save model to new filename void imodvSaveModelAs() { /* DNM: added rename of existing file and improved error checks */ ImodvApp *a = Imodv; char *filename; FILE *fout; int len, error; char *nfname1; QString qname; struct stat buf; a->mainWin->releaseKeyboard(); qname = imodPlugGetSaveName(NULL, "Select file to save model into:"); if (qname.isEmpty()) return; filename = strdup(LATIN1(qname)); /* DNM 8/4/01: store the current view when saving, if appropriate */ imodvAutoStoreView(a); len = strlen(filename)+1; nfname1 = (char *)malloc(len + 1); sprintf(nfname1, "%s~", filename); if (!stat(filename, &buf)) { remove(nfname1); rename(filename, nfname1); } fout = fopen(LATIN1(QDir::toNativeSeparators(QString(filename))), "wb"); if (fout){ error = writeOpenedModelFile(a, fout); if (!error) { if (a->imod->fileName) free(a->imod->fileName); a->imod->fileName = (char *)malloc(len); if (a->imod->fileName) memcpy(a->imod->fileName, filename, len); if ((strlen(filename)+1) < IMOD_STRSIZE) memcpy(a->imod->name, filename, strlen(filename)+1); else a->imod->name[0] = 0x00; } } else { error = 1; } if (error) { dia_err("Error writing model; attempting to restore backup file"); if (!stat(nfname1, &buf)) remove(filename); rename(nfname1, filename); } free(nfname1); free(filename); }
/* * Prints a measurement with optional conversion to units */ void utilWprintMeasure(QString &baseMess, Imod *imod, float measure, bool area) { measure *= imod->pixsize; if (area) measure *= imod->pixsize; if (strcmp("pixels", imodUnits(imod))) wprint("%s, %g %s%s\n", LATIN1(baseMess), measure, imodUnits(imod), area ? "^2" : ""); else wprint("%s\n", LATIN1(baseMess)); }
// The clipboard changed - check for window ID and OK or ERROR // NOTE: on Windows, Qt 3 needed to exit with ::exit instead of // QApplication::exit, otherwise it would hang for a long time or until the // timeout occurred. It complains in Qt 4 about deleting an object during its // event handler, but qapp::exit seems fine now. void ImodSendEvent::clipboardChanged() { QClipboard *cb = QApplication::clipboard(); //cb->setSelectionMode(false); QString text = cb->text(); if (debugOut) fprintf(stderr, "Imodsendevent - clipboard = %s\n", LATIN1(text)); // Ignore if empty text, no spaces, starting space, or wrong ID if (text.isEmpty()) return; int index = text.indexOf(" "); if (index <= 0) return; if ((text.left(index)).toInt() != winID) return; // If OK, just exit; if ERROR, give message and exit with error status if (text.mid(index + 1) == "OK") { QApplication::exit(0); return; } if (text.mid(index + 1) != "ERROR") return; fprintf(stderr, "ERROR: imodsendevent - message received but error occurred " "executing it\n"); QApplication::exit(3); }
/* * Performs final tasks for a montage snapshot: sets up line pointers, composes * the filename, and performs the right kind of snapshot. */ void utilFinishMontSnap(unsigned char **linePtrs, int xFullSize, int yFullSize, int format, int &fileno, int digits, float zoom, const char *prefix, const char *message) { int limits[4]; QString fname, sname; limits[0] = limits[1] = 0; limits[2] = xFullSize; limits[3] = yFullSize; if (format == 2) ImodPrefs->set2ndSnapFormat(); b3dSetDpiScaling(zoom); fname = b3dGetSnapshotName(prefix, format ? SnapShot_RGB : SnapShot_TIF, digits, fileno); sname = b3dShortSnapName(fname); imodPrintStderr("%s montage to %s", message, LATIN1(sname)); if (format) b3dSnapshot_NonTIF(fname, 4, limits, linePtrs); else b3dSnapshot_TIF(fname, 4, limits, linePtrs, strcmp(prefix, "modv") != 0); if (format == 2) ImodPrefs->restoreSnapFormat(); imodPuts(""); b3dSetDpiScaling(1.); }
// Parse the message, see if it is for us, and save in local variables bool ImodClipboard::handleMessage() { int newStamp, arg; QStringList tmpStrings; if (!ImodInfoWin && ImodvClosed) return false; // get the text from the clipboard QClipboard *cb = QApplication::clipboard(); //cb->setSelectionMode(false); QString text = cb->text(); if (Imod_debug) { imodPrintStderr("imodHCM in handleMessage = %s\n", LATIN1(text)); wprint("handleMessage = %s\n", LATIN1(text)); } // Return if text is empty if (text.isEmpty()) return false; // Split the string, ignoring multiple spaces, and return false if fewer // than 3 elements tmpStrings = text.split(" ", QString::SkipEmptyParts); if (tmpStrings.count() < 3) return false; // Return false if this is not our info window ID if (tmpStrings[0].toUInt() != ourWindowID()) return false; // If we see the same message again, send the last response again newStamp = tmpStrings[1].toInt(); if (newStamp == sMessageStamp) { sendResponse(-1); return false; } sMessageStamp = newStamp; // Clear out the list or accumulate it in initial load, then strip ID and stamp if (!sInitialLoad) sMessageStrings.clear(); for (arg = 2; arg < tmpStrings.count(); arg++) sMessageStrings << tmpStrings[arg]; return true; }
void ImodvOlist::nameChanged(const QString &str) { IobjGroup *group = (IobjGroup *)ilistItem(Imodv->imod->groupList, Imodv->imod->curObjGroup); if (!group) return; strncpy(&group->name[0], LATIN1(str), OBJGRP_STRSIZE); group->name[OBJGRP_STRSIZE - 1] = 0x00; }
void imod_usage(char *name) { QString qstr; char *progName = imodProgName(name); imodVersion(progName); imodCopyright(); qstr.sprintf("Usage: %s [options] <Image files> <model file>\n", progName); qstr += "Options:\n"; qstr += " -xyz Open xyz window first.\n"; qstr += " -S Open slicer window first.\n"; qstr += " -V Open model view window first.\n"; qstr += " -Z Open Zap window (use with -S, -xyz, or -V).\n"; qstr += " -O Set options with startup dialog box.\n"; qstr += " -x min,max Load in sub image.\n"; qstr += " -y min,max Load in sub image.\n"; qstr += " -z min,max Load in sub image.\n"; qstr += " -s min,max Scale input to range [min,max] (0,0 for all files the same).\n"; qstr += " -ic x,y,z Set initial center position of slicer and/or Zap.\n"; qstr += " -ia x,y,z Set initial angles of slicer window.\n"; qstr += " -iz # Set initial zoom of slicer and/or Zap.\n"; qstr += " -I # Load data as 16-bit integers (# = 1) or as bytes (# = 0).\n"; qstr += " -C # Set # of sections or Mbytes to cache (#M or #m for Mbytes).\n"; qstr += " -CT # Set # of sections or Mbytes for cache of tiles or strips.\n"; qstr += " -F Fill cache right after starting program.\n"; qstr += " -Y Rotate volume around X to model planes normal to Y axis.\n"; qstr += " -B # Bin images by # in X, Y, and Z.\n"; qstr += " -b nxy,nz Bin images by nxy in X and Y, by nz in Z (nz " "default=1).\n"; qstr += " -a <file name> Load tilt angles from file.\n"; qstr += " -p <file name> Load piece list file.\n"; qstr += " -P nx,ny Display images as montage in nx by ny array.\n"; qstr += " -o nx,ny Set X and X overlaps for montage display.\n"; qstr += " -f Load as frames even if image file has piece " "coordinates.\n"; qstr += " -py Image files are a pyramid of same data at different resolutions.\n"; qstr += " -r nx,ny,nz Dimensions for raw image files.\n"; qstr += " -ri Raw file is inverted in Y.\n"; qstr += " -t # Mode for raw files: -1/0=byte, 1/6=int, 2=float, " "4=complex, 16=RGB,\n"; qstr += " -H # Header size in bytes in raw image files.\n"; qstr += " -w Swap bytes from raw image files.\n"; qstr += " -R Read image data from standard input, not from file." "\n"; qstr += " -m Load model with model coords (override scaling).\n"; qstr += " -2 Treat model as 2D only.\n"; qstr += " -T Display multiple single-image files as times not " "sections.\n"; qstr += " -G Display RGB-mode MRC file in gray-scale.\n"; qstr += " -M Do not mirror FFT data around Y axis.\n"; qstr += " -ci Display images in color index mode with colormap.\n"; qstr += " -cm <file name> Load custom false color table.\n"; qstr += " -E <keys> Open windows specified by key letters.\n"; qstr += " -h Print this help message.\n"; imodPrintInfo(LATIN1(qstr)); return; }
const CharacterList * CharacterList::forCharSet(int charset) { switch(charset) { case IFont::CHINESEBIG5: case IFont::GB2312: return & CHINESE(); default: return & LATIN1(); } }
/* * Clipboard change event slot and timeout for performing actions */ void ImodClipboard::clipboardChanged() { if (Imod_debug) { QClipboard *cb = QApplication::clipboard(); //cb->setSelectionMode(false); QString text = cb->text(); imodPrintStderr("imodHCM in clipboardChanged - clipboard = %s\n", LATIN1(text)); if (ImodInfoWin) wprint("clipboardChanged = %s\n", LATIN1(text)); } // If already handling a change or the message is not for us, return if (mHandling || !handleMessage()) return; // Otherwise create and start a timer to execute the action // Set flag because event comes in twice in Windows mHandling = true; QTimer::singleShot(10, this, SLOT(clipTimeout())); }
/* Takes an intro without a :, and returns a qstring with intro: filename or just intro */ QString imodCaption(const char *intro) { QString qstr = intro; qstr += ":"; char *name = imodwfname(LATIN1(qstr)); if (name) { qstr = name; free(name); } else qstr = intro; return qstr; }
// load a specified model (only in standalone model) int imodvLoadModel() { Imod **tmoda; Imod *tmod; ImodvApp *a = Imodv; int i, ob, co; QString qname; const char *filter[] = {"Model files (*.*mod)"}; if (ImodvClosed || !a->standalone) return -1; // Need to release the keyboard because window grabs it on ctrl a->mainWin->releaseKeyboard(); qname = utilOpenFileName(NULL, "Select Model file to load", 1, filter); if (qname.isEmpty()) return 1; tmod = imodRead(LATIN1(qname)); if (!tmod) return(-1); utilExchangeFlipRotation(tmod, FLIP_TO_ROTATION); /* DNM 6/20/01: find out max time and set current time */ tmod->tmax = 0; for (ob = 0; ob < tmod->objsize; ob++) for (co = 0; co < tmod->obj[ob].contsize; co++) if (tmod->tmax < tmod->obj[ob].cont[co].time) tmod->tmax = tmod->obj[ob].cont[co].time; tmod->ctime = tmod->tmax ? 1 : 0; tmoda = (Imod **)malloc(sizeof(Imod *) * (a->numMods + 1)); for (i = 0; i < a->numMods; i++) tmoda[i] = a->mod[i]; tmoda[i] = tmod; if (a->numMods) free(a->mod); a->mod = tmoda; /* a->curMod = a->numMods; */ a->numMods++; /* a->imod = tmod; */ /* DNM: changes for storage of object properties in view and relying on default scaling - switched to new method 6/26/03 */ imodvViewsInitialize(tmod); imodvSelectModel(a, a->numMods - 1); return(0); }
// The timeout occurred - if count has not expired, resend message with an // added space, otherwise write error message and exit with error void ImodSendEvent::timerEvent(QTimerEvent *e) { if (++retryCount < retryLimit) { timeStr += " "; QString qstr = timeStr + cmdStr; QClipboard *cb = QApplication::clipboard(); //cb->setSelectionMode(false); if (debugOut) fprintf(stderr, "Imodsendevent - resending %s \n", LATIN1(qstr)); cb->setText(qstr); return; } fprintf(stderr, "ERROR: imodsendevent - timeout before response received " "from target 3dmod\n"); QApplication::exit(2); }
// Save to the existing filename void imodvFileSave() { /* DNM: added rename of existing file to backup. Also eliminated use of Imodv pointer in favor of a->, and the double save (!?!), and added error checks */ int len, error; char *nfname1; FILE *fout = NULL; ImodvApp *a = Imodv; char *filename = a->imod->fileName; struct stat buf; /* DNM 8/4/01: store the current view when saving, if appropriate */ imodvAutoStoreView(a); len = strlen(filename)+1; nfname1 = (char *)malloc(len + 1); sprintf(nfname1, "%s~", filename); /* DNM 10/20/03: remove backup and rename only if file already exists */ if (!stat(filename, &buf)) { remove(nfname1); rename(filename, nfname1); } if (a->imod->fileName) fout = fopen(LATIN1(QDir::toNativeSeparators(QString(a->imod->fileName))), "wb"); if (fout){ error = writeOpenedModelFile(a, fout); } else error = 1; if (error) { dia_err("File not saved, bad filename or error;" " attempting to restore backup file."); /* If the backup actually exists, remove regular file first */ if (!stat(nfname1, &buf)) remove(filename); rename (nfname1, filename); } free(nfname1); }
void ContSurfPoint::pointLabelChanged( const QString &str ) { iceLabelChanged(LATIN1(str), 1); }
void ContSurfPoint::surfLabelChanged( const QString & str ) { iceLabelChanged(LATIN1(str), 2); }
/* * Load the sequence from a file */ void MovieSequenceForm::loadClicked() { int numSeg, iseg, err, se, cl, numObj; char *buffer; int *intArray = NULL; MovieSegment *segp; MovieTerminus *term; QString key; if (mModified) { iseg = dia_choice("Save current movie sequence before loading a new one?", "Yes", "No", "Cancel"); if (iseg == 3) return; if (iseg == 1 && saveSequence() < 0) return; } key = utilOpenFileName(this, "Select movie sequence file to load", 0, NULL); if (key.isEmpty()) return; if (AdocRead(LATIN1(key)) < 0) { dia_err("Error reading the movie sequence file as an autodoc"); AdocDone(); return; } mSegments->clear(); numSeg = AdocGetNumberOfSections(MSA_SEGMENT); if (numSeg <= 0) { dia_err(numSeg ? "Error getting number of segments from autodoc" : "No segments were found in the file"); loadTable(); return; } mSegments->resize(numSeg); for (iseg = 0; iseg < numSeg; iseg++) { err = 1; segp = &(mSegments->at(iseg)); // General segment items if (AdocGetInteger(MSA_SEGMENT, iseg, MSA_FRAMES, &segp->numFrames)) break; err++; if (AdocGetInteger(MSA_SEGMENT, iseg, MSA_VIEW, &segp->viewNum)) break; err++; if (AdocGetInteger(MSA_SEGMENT, iseg, MSA_FULL_AXIS, &segp->fullAxis)) break; err++; if (AdocGetInteger(MSA_SEGMENT, iseg, MSA_NUM_CLIPS, &segp->numClips)) break; err++; if (AdocGetInteger(MSA_SEGMENT, iseg, MSA_CLIP_FLAGS, &segp->clipFlags)) break; err++; if (AdocGetInteger(MSA_SEGMENT, iseg, MSA_IMG_AXIS, &segp->imgAxisFlags)) break; // Segment image drawing state if (segp->imgAxisFlags) { if (AdocGetThreeIntegers(MSA_SEGMENT, iseg, MSA_IMG_SIZE, &segp->imgXsize, &segp->imgYsize, &segp->imgZsize)) break; if (AdocGetTwoIntegers(MSA_SEGMENT, iseg, MSA_IMG_LEVELS, &segp->imgBlackLevel, &segp->imgWhiteLevel)) break; if (AdocGetInteger(MSA_SEGMENT, iseg, MSA_IMG_FALSE, &segp->imgFalseColor)) break; } // Segment clip normals for (cl = 0; cl < segp->numClips; cl++) { key.sprintf("%s%d", MSA_CLIP_NORM, cl + 1); if (AdocGetThreeFloats(MSA_SEGMENT, iseg, LATIN1(key), &segp->clipNormal[cl].x, &segp->clipNormal[cl].y, &segp->clipNormal[cl].z)) break; } if (cl < segp->numClips) break; err++; if (AdocGetString(MSA_SEGMENT, iseg, MSA_LABEL, &buffer) == 0) { segp->label = QString(buffer); free(buffer); } err++; // The object states if (AdocGetInteger(MSA_SEGMENT, iseg, MSA_NUM_ONOFF, &numObj) || !numObj) break; err++; segp->objStates.resize(numObj); if (AdocGetString(MSA_SEGMENT, iseg, MSA_OBJ_ONOFF, &buffer)) break; err++; if (strlen(buffer) < 2 * numObj - 1) { free(buffer); break; } for (cl = 0; cl < numObj; cl++) segp->objStates[cl] = buffer[cl * 2] == '0' ? 0 : 1; free(buffer); err++; // Objects with changed transparency if (AdocGetInteger(MSA_SEGMENT, iseg, MSA_NUMOBJ_DELTRANS, &numObj)) break; err++; if (numObj > 0) { intArray = B3DMALLOC(int, numObj); if (!intArray) break; if (AdocGetIntegerArray(MSA_SEGMENT, iseg, MSA_OBJ_DELTRANS, intArray, &numObj, numObj)) break; segp->transChangeObjs.resize(numObj); for (cl = 0; cl < numObj; cl++) segp->transChangeObjs[cl] = intArray[cl]; } err++; // Now start and end data term = &segp->start; for (se = 0; se < 2; se++) { key.sprintf("%s%s", MSA_ROTATION, se ? "End" : "Start"); if (AdocGetThreeFloats(MSA_SEGMENT, iseg, LATIN1(key), &term->rotation.x, &term->rotation.y, &term->rotation.z)) break; err++; key.sprintf("%s%s", MSA_TRANSLATE, se ? "End" : "Start"); if (AdocGetThreeFloats(MSA_SEGMENT, iseg, LATIN1(key), &term->translate.x, &term->translate.y, &term->translate.z)) break; err++; key.sprintf("%s%s", MSA_ZOOM, se ? "End" : "Start"); if (AdocGetFloat(MSA_SEGMENT, iseg, LATIN1(key), &term->zoomRad)) break; // Terminus image drawing if (segp->imgAxisFlags) { key.sprintf("%s%s", MSA_IMG_CEN, se ? "End" : "Start"); if (AdocGetThreeIntegers(MSA_SEGMENT, iseg, LATIN1(key), &term->imgXcenter, &term->imgYcenter, &term->imgZcenter)) break; key.sprintf("%s%s", MSA_IMG_SLICES, se ? "End" : "Start"); if (AdocGetInteger(MSA_SEGMENT, iseg, LATIN1(key), &term->imgSlices)) break; key.sprintf("%s%s", MSA_IMG_TRANSP, se ? "End" : "Start"); if (AdocGetInteger(MSA_SEGMENT, iseg, LATIN1(key), &term->imgTransparency)) break; } // Terminus clip points for (cl = 0; cl < segp->numClips; cl++) { key.sprintf("%s%s%d", MSA_CLIP_POINT, se ? "End" : "Start", cl + 1); if (AdocGetThreeFloats(MSA_SEGMENT, iseg, LATIN1(key), &term->clipPoint[cl].x, &term->clipPoint[cl].y, &term->clipPoint[cl].z)) break; } if (cl < segp->numClips) break; err++; // Terminus transparencies if (numObj > 0) { key.sprintf("%s%s", MSA_OBJ_TRANSP, se ? "End" : "Start"); if (AdocGetIntegerArray(MSA_SEGMENT, iseg, LATIN1(key), intArray, &numObj, numObj)) break; for (cl = 0; cl < numObj; cl++) term->objTrans[cl] = (unsigned char)intArray[cl]; } term= &segp->end; } if (se < 2) break; err = 0; }
/* * Save sequence with return code of -1 for error, 1 for cancel or failure to back up */ int MovieSequenceForm::saveSequence() { QString key, value, oneVal; int iseg, err, se, cl; char buffer[2 * MAX_OBJ_ONOFF]; MovieSegment *segp; MovieTerminus *term; if (AdocNew() < 0) { dia_err("Failed to create a new autodoc structure"); AdocDone(); return -1; } for (iseg = 0; iseg < mSegments->size(); iseg++) { err = 1; segp = &(mSegments->at(iseg)); key.sprintf("%d", iseg + 1); if (AdocAddSection(MSA_SEGMENT, LATIN1(key)) < 0) break; err = 2; // General segment items if (AdocSetInteger(MSA_SEGMENT, iseg, MSA_FRAMES, segp->numFrames)) break; if (AdocSetInteger(MSA_SEGMENT, iseg, MSA_VIEW, segp->viewNum)) break; if (AdocSetInteger(MSA_SEGMENT, iseg, MSA_FULL_AXIS, segp->fullAxis)) break; if (AdocSetInteger(MSA_SEGMENT, iseg, MSA_NUM_CLIPS, segp->numClips)) break; if (AdocSetInteger(MSA_SEGMENT, iseg, MSA_CLIP_FLAGS, segp->clipFlags)) break; if (AdocSetInteger(MSA_SEGMENT, iseg, MSA_IMG_AXIS, segp->imgAxisFlags)) break; // Segment image drawing state if (segp->imgAxisFlags) { if (AdocSetThreeIntegers(MSA_SEGMENT, iseg, MSA_IMG_SIZE, segp->imgXsize, segp->imgYsize, segp->imgZsize)) break; if (AdocSetTwoIntegers(MSA_SEGMENT, iseg, MSA_IMG_LEVELS, segp->imgBlackLevel, segp->imgWhiteLevel)) break; if (AdocSetInteger(MSA_SEGMENT, iseg, MSA_IMG_FALSE, segp->imgFalseColor)) break; } // Segment clip normals for (cl = 0; cl < segp->numClips; cl++) { key.sprintf("%s%d", MSA_CLIP_NORM, cl + 1); if (AdocSetThreeFloats(MSA_SEGMENT, iseg, LATIN1(key), segp->clipNormal[cl].x, segp->clipNormal[cl].y, segp->clipNormal[cl].z)) break; } if (cl < segp->numClips) break; if (!segp->label.isEmpty() && AdocSetKeyValue(MSA_SEGMENT, iseg, MSA_LABEL, LATIN1(segp->label))) break; // The object states if (AdocSetInteger(MSA_SEGMENT, iseg, MSA_NUM_ONOFF, segp->objStates.size())) break; for (cl = 0; cl < segp->objStates.size(); cl++) { buffer[2 * cl] = segp->objStates[cl] ? '1' : '0'; buffer[2 * cl + 1] = ' '; } buffer[2 * cl - 1] = 0x00; if (AdocSetKeyValue(MSA_SEGMENT, iseg, MSA_OBJ_ONOFF, buffer)) break; // Objects with trans changing if (AdocSetInteger(MSA_SEGMENT, iseg, MSA_NUMOBJ_DELTRANS, segp->transChangeObjs.size())) break; if (segp->transChangeObjs.size()) { value = ""; for (cl = 0; cl < segp->transChangeObjs.size(); cl++) { oneVal.sprintf(" %d", segp->transChangeObjs[cl]); value += oneVal; } if (AdocSetKeyValue(MSA_SEGMENT, iseg, MSA_OBJ_DELTRANS, LATIN1(value))) break; } // Now put out start and end data term = &segp->start; for (se = 0; se < 2; se++) { key.sprintf("%s%s", MSA_ROTATION, se ? "End" : "Start"); if (AdocSetThreeFloats(MSA_SEGMENT, iseg, LATIN1(key), term->rotation.x, term->rotation.y, term->rotation.z)) break; key.sprintf("%s%s", MSA_TRANSLATE, se ? "End" : "Start"); if (AdocSetThreeFloats(MSA_SEGMENT, iseg, LATIN1(key), term->translate.x, term->translate.y, term->translate.z)) break; key.sprintf("%s%s", MSA_ZOOM, se ? "End" : "Start"); if (AdocSetFloat(MSA_SEGMENT, iseg, LATIN1(key), term->zoomRad)) break; // Terminus image drawing if (segp->imgAxisFlags) { key.sprintf("%s%s", MSA_IMG_CEN, se ? "End" : "Start"); if (AdocSetThreeIntegers(MSA_SEGMENT, iseg, LATIN1(key), term->imgXcenter, term->imgYcenter, term->imgZcenter)) break; key.sprintf("%s%s", MSA_IMG_SLICES, se ? "End" : "Start"); if (AdocSetInteger(MSA_SEGMENT, iseg, LATIN1(key), term->imgSlices)) break; key.sprintf("%s%s", MSA_IMG_TRANSP, se ? "End" : "Start"); if (AdocSetInteger(MSA_SEGMENT, iseg, LATIN1(key), term->imgTransparency)) break; } // Terminus clip points for (cl = 0; cl < segp->numClips; cl++) { key.sprintf("%s%s%d", MSA_CLIP_POINT, se ? "End" : "Start", cl + 1); if (AdocSetThreeFloats(MSA_SEGMENT, iseg, LATIN1(key), term->clipPoint[cl].x, term->clipPoint[cl].y, term->clipPoint[cl].z)) break; } if (cl < segp->numClips) break; // Terminal transparency values if (segp->transChangeObjs.size()) { value = ""; for (cl = 0; cl < segp->transChangeObjs.size(); cl++) { oneVal.sprintf(" %d", (int)term->objTrans[cl]); value += oneVal; } key.sprintf("%s%s", MSA_OBJ_TRANSP, se ? "End" : "Start"); if (AdocSetKeyValue(MSA_SEGMENT, iseg, LATIN1(key), LATIN1(value))) break; } term= &segp->end; } if (se < 2) break; err = 0; } if (err) { dia_err(err == 1 ? "Failed to add a section to autodoc" : "Failed to add a key-value pair to autodoc"); AdocDone(); return -1; } key = imodPlugGetSaveName(this, "Select file to save movie sequence into:"); if (key.isEmpty()) { AdocDone(); return 1; } err = AdocWrite(LATIN1(key)); AdocDone(); if (err) dia_err(err == 1 ? "Failed to back up existing copy of file" : "Error writing the movie sequence to file"); mModified = err < 0; return err; }
TumblerWindow::TumblerWindow(TumblerStruct *xtum, bool rgba, bool doubleBuffer, bool enableDepth, QWidget * parent, const char * name, Qt::WindowFlags f) : QMainWindow(parent, f) { int j; QString str; mTum = xtum; setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_AlwaysShowToolTips); if (firstTime) utilFileListsToIcons(fileList, icons, MAX_XTUM_TOGGLES); firstTime = 0; // Make central vbox and top frame containing an hboxlayout QWidget *central = new QWidget(this); setCentralWidget(central); QVBoxLayout *cenlay = new QVBoxLayout(central); cenlay->setContentsMargins(0,0,0,0); cenlay->setSpacing(0); QFrame * topFrame = new QFrame(central); cenlay->addWidget(topFrame); topFrame->setFrameStyle(QFrame::Raised | QFrame::StyledPanel); QHBoxLayout *topLayout = new QHBoxLayout(topFrame); topLayout->setContentsMargins(2,2,2,2); topLayout->setSpacing(3); QVBoxLayout *topVBox = diaVBoxLayout(topLayout); topVBox->setSpacing(4); QHBoxLayout *topHBox = diaHBoxLayout(topVBox); topHBox->setContentsMargins(0,0,0,0); topHBox->setSpacing(3); // Add the toolbar widgets // Zoom spin box // If you try to make a spin box narrower, it makes the arrows tiny mZoomBox = (QSpinBox *)diaLabeledSpin(0, 1., XTUM_MAX_ZOOM, 1., "Zoom", topFrame, topHBox); mZoomBox->setValue(xtum->zoom); connect(mZoomBox, SIGNAL(valueChanged(int)), this, SLOT(zoomChanged(int))); mZoomBox->setToolTip("Change zoom of display"); // Make the 2 toggle buttons and their signal mapper QSignalMapper *toggleMapper = new QSignalMapper(topFrame); connect(toggleMapper, SIGNAL(mapped(int)), this, SLOT(toggleClicked(int))); for (j = 0; j < 2; j++) { utilSetupToggleButton(topFrame, NULL, topHBox, toggleMapper, icons, toggleTips, mToggleButs, mToggleStates, j); connect(mToggleButs[j], SIGNAL(clicked()), toggleMapper, SLOT(map())); } // Help button mHelpButton = diaPushButton("Help", topFrame, topHBox); connect(mHelpButton, SIGNAL(clicked()), this, SLOT(help())); setFontDependentWidths(); topHBox->addStretch(); // Make second row for size spin boxes, and signal map them QHBoxLayout *botHBox = diaHBoxLayout(topVBox); botHBox->setContentsMargins(0,0,0,0); botHBox->setSpacing(3); QSignalMapper *sizeMapper = new QSignalMapper(topFrame); connect(sizeMapper, SIGNAL(mapped(int)), this, SLOT(sizeChanged(int))); // Make the spin boxes for (j = 0; j < 3; j++) { str = xyzLabels[j]; mSizeBoxes[j] = (QSpinBox *)diaLabeledSpin(0, XTUM_SIZE_MIN, XTUM_SIZE_MAX, XTUM_SIZE_INC, LATIN1(str), topFrame, botHBox); mSizeBoxes[j]->setValue(XTUM_SIZE_INI); sizeMapper->setMapping(mSizeBoxes[j], j); connect(mSizeBoxes[j], SIGNAL(valueChanged(int)), sizeMapper, SLOT(map())); mSizeBoxes[j]->setToolTip("Change size of box in " + str); } // Spacer for the second row botHBox->addStretch(); // Add a vertical line QFrame *vertLine = new QFrame(topFrame); vertLine->setFrameStyle(QFrame::Sunken | QFrame::VLine); topLayout->addWidget(vertLine); // Threshold sliders mSliders = new MultiSlider(topFrame, 2, sliderLabels); topLayout->addLayout(mSliders->getLayout()); connect(mSliders, SIGNAL(sliderChanged(int, int, bool)), this, SLOT(thresholdChanged(int, int, bool))); mSliders->setValue(0, xtum->minval); mSliders->setValue(1, xtum->maxval); mSliders->getSlider(0)->setToolTip( "Level below which pixels will be set to black"); mSliders->getSlider(1)->setToolTip( "Level above which pixels will be set to white"); QGLFormat glFormat; glFormat.setRgba(rgba); glFormat.setDoubleBuffer(doubleBuffer); glFormat.setDepth(enableDepth); mGLw = new TumblerGL(xtum, glFormat, central); cenlay->addWidget(mGLw); cenlay->setStretchFactor(mGLw, 1); resize(XTUM_WIDTH, XTUM_HEIGHT); setFocusPolicy(Qt::StrongFocus); }
int main(int argc, char **argv) { int action; double timeout = 5.; int argIndex, numArgs; int interval; char *endptr; QString qstr; QTime curTime = QTime::currentTime(); int timeStamp = 60000 * curTime.minute() + 1000 * curTime.second() + curTime.msec(); for (argIndex = 1; argIndex < argc - 1 ; argIndex++) { if (argv[argIndex][0] == '-'){ switch (argv[argIndex][1]){ case 't': /* timeout interval */ timeout = strtod(argv[++argIndex], &endptr); if (endptr - argv[argIndex] < (int)strlen(argv[argIndex])) { fprintf(stderr, "ERROR: imodsendevent - invalid timeout entry %s\n", argv[argIndex]); exit(3); } break; case 'D': /* debug */ debugOut = 1; break; default: fprintf(stderr, "ERROR: imodsendevent - invalid argument %s\n", argv[argIndex]); exit(3); break; } } else break; } numArgs = argc - argIndex; if (numArgs < 2) { fprintf(stderr, "ERROR: imodsendevent - Wrong number of arguments\n" " Usage: imodsendevent [-t timeout] [-D] Window_ID action " "[arguments]\n"); exit(3); } // Check the arguments for odd characters winID = strtol(argv[argIndex], &endptr, 10); if (endptr - argv[argIndex] < (int)strlen(argv[argIndex])) { fprintf(stderr, "ERROR: imodsendevent - invalid characters in window ID" " entry %s\n", argv[argIndex]); exit(3); } action = strtol(argv[argIndex + 1], &endptr, 10); if (endptr - argv[argIndex + 1] < (int)strlen(argv[argIndex + 1])) { fprintf(stderr, "ERROR: imodsendevent - invalid characters in action " "entry %s\n", argv[argIndex + 1]); exit(3); } // Create the application ImodSendEvent a(argc, argv); setlocale(LC_NUMERIC, "C"); // Pack the arguments into a QString timeStr.sprintf(" %d ", timeStamp); timeStr = QString(argv[argIndex]) + timeStr; cmdStr = QString(argv[argIndex + 1]); for (; argIndex + 2 < argc; argIndex++) cmdStr += QString(" ") + QString(argv[argIndex + 2]); qstr = timeStr + cmdStr; // Connect to the clipboard, start the timeout, and send the text QClipboard *cb = QApplication::clipboard(); // Default for setText and text() is Clipboard mode //cb->setSelectionMode(false); cb->blockSignals(true); QObject::connect(cb, SIGNAL(dataChanged()), &a, SLOT(clipboardChanged())); cb->blockSignals(false); // Start a timeout timer if the interval is not zero. interval = (int)(1000. * timeout + 0.5); if (interval > 0) { // If this hack is defined and > 0, divide the total timeout into intervals // of this length and retry sending message #ifdef SENDEVENT_RETRY_HACK if (SENDEVENT_RETRY_HACK > 0) { retryLimit = interval / SENDEVENT_RETRY_HACK; if (!retryLimit) retryLimit = 1; interval = SENDEVENT_RETRY_HACK; } #endif a.startTimer(interval); } if (debugOut) fprintf(stderr, "Imodsendevent sending: %s\n", LATIN1(qstr)); cb->setText(qstr); // If the hack is defined as zero, just process events and set the text again #ifdef SENDEVENT_RETRY_HACK if (SENDEVENT_RETRY_HACK == 0) { qApp->processEvents(); cb->setText(qstr); } #endif return a.exec(); }
void imodvObjedForm::nameChanged(const QString & str ) { imodvObjedName(LATIN1(str)); }
int main( int argc, char *argv[]) { ImodApp app; ImodView vi; IloadInfo li; FILE *fin = NULL; FILE *mfin = NULL; char *plistfname = NULL; char *anglefname = NULL; int xyzwinopen = FALSE; int sliceropen = FALSE; int zapOpen = FALSE; int modelViewOpen= FALSE; bool print_wid = false; int fillCache = FALSE; bool newModelCreated = false; int i = 0; int nx, ny, nz, mode; int minxpiece, numXpieces, xoverlap, minypiece, numYpieces, yoverlap; float initAngles[3], initZoom; Ipoint initCenter; int setAngles = 0; int setCenter = 0; int setZoom = 0; int frames = 0; int firstfile = 0; int lastimage; int pathlen; int nframex = 0; int nframey = 0; int overx = 0; int overy = 0; int doStartup = 0; QString qname; QStringList plFileNames; int doFork = 1; char *cmdLineStyle = NULL; int doImodv = 0; int rawSet = 0; int overEntered = 0; int useMdoc = 0; bool useStdin = false; bool dataFromStdin = false; bool anyHavePieceList = false; bool anyImageFail = false; bool useChooserPlug = false; int argScan, argcHere; QRect infoGeom; StartupForm *startup = NULL; /* Initialize data. */ App = &app; App->rgba = 1; /* Set to 1 to force RGB visual */ App->exiting = 0; App->closing = 0; App->cvi = &vi; App->base = Rampbase; App->convertSnap = 0; App->glInitialized = 0; App->chooserPlugin = 0; /* Set up fixed indexes */ App->background = IMOD_BACKGROUND; App->foreground = IMOD_FOREGROUND; App->select = IMOD_SELECT; App->shadow = IMOD_SHADOW; App->endpoint = IMOD_ENDPOINT; App->bgnpoint = IMOD_BGNPOINT; App->curpoint = IMOD_CURPOINT; App->ghost = IMOD_GHOST; App->arrow[0] = IMOD_ARROW; App->arrow[1] = IMOD_ARROW2; App->arrow[2] = IMOD_ARROW3; App->arrow[3] = IMOD_ARROW4; /*DNM: prescan for debug, ci and style flags before the display_init */ /* Cancel forking on debug or -W output, or -L or -R or -h */ for (i = 1; i < argc; i++){ if (!strncmp("-D", argv[i], 2)) { Imod_debug = TRUE; debugKeys = strdup(argv[i] + 2); doFork = 0; } if (!strcmp("-W", argv[i]) || !strcmp("-R", argv[i]) || !strcmp("-h", argv[i])) doFork = 0; if (!strcmp("-L", argv[i])) { doFork = 0; #if defined(_WIN32) && !defined(QT_THREAD_SUPPORT) imodError(NULL, "Error: -L option cannot be used because " "3dmod was not built with Qt thread support\n"); exit(1); #endif } if (!strcmp("-ci", argv[i])) App->rgba = -1; /* Set to -1 to force worthless Color index visual */ if (argv[i][0] == '-' && argv[i][1] == 's' && argv[i][2] == 't' && argv[i][3] == 'y' && argv[i][4] == 'l' && argv[i][5] == 'e') { if (argv[i][6] == '=') cmdLineStyle = strdup(&(argv[i][7])); else if (i < argc - 1) cmdLineStyle = strdup(argv[i + 1]); } if (!strcmp("-modv", argv[i]) || !strcmp("-view", argv[i])) doImodv = 1; if (!strcmp("-O", argv[i])) doStartup = 1; if (argv[i][0] == '-') firstfile = i + 1; } #ifndef NO_IMOD_FORK /* Fork now to avoid conflicts */ if (doFork) if (fork()) exit(0); #endif #ifdef Q_OS_MACX // fix OS X 10.9 font issue https://bugreports.qt-project.org/browse/QTBUG-32789 // MV_10_8 is not defined in Qt 4.6 etc, this is the value in Qt 4.8 if (QSysInfo::MacintoshVersion > 0x000A) QFont::insertSubstitution(".Lucida Grande UI", "Lucida Grande"); #endif /* Open the Qt application */ // Once we have told Qt about the original arguments, we must not modify argc here // Somehow later it accesses the old argument vector with the new number of args QApplication qapp(argc, argv); argcHere = argc; /* Set title for error dialogs, and set up to store error strings */ diaSetTitle("3dmod"); b3dSetStoreError(1); setlocale(LC_NUMERIC, "C"); ImodPrefs = new ImodPreferences(cmdLineStyle); ImodHelp = new ImodAssistant("html", "IMOD.qhc", "3dmod", false, false, "3dmodHelp"); // Set up the application icon for windows to use App->iconPixmap = new QPixmap(QPixmap::fromImage(QImage(b3dicon))); // Load in all the imod plugins that we can use (moved up so file chooser available) imodPlugInit(); /* if no input files, open startup window */ i = strlen(argv[0]); if (argv[0][i-1] == 'v') doImodv = 1; if (argcHere < 2 || (doStartup && doImodv)) { useChooserPlug = true; startup = new StartupForm(NULL, true, Qt::Window); startup->setWindowIcon(*(App->iconPixmap)); if (doImodv) { mrc_init_li(&li, NULL); ivwInit(&vi, false); vi.li = &li; startup->setValues(&vi, argv, firstfile, argcHere, doImodv, plFileNames, anglefname, useMdoc, xyzwinopen, sliceropen, zapOpen, modelViewOpen, fillCache, ImodTrans, 0, frames, nframex, nframey, overx, overy, overEntered); } if (startup->exec() == QDialog::Rejected) { imod_usage(argv[0]); exit(1); } argv = startup->getArguments(argcHere); doImodv = 0; /*for (i = 0; i < argcHere; i++) imodPrintStderr("%s ", argv[i]); imodPrintStderr("\n");*/ doStartup = 0; } /* Run the program as imodv? */ i = strlen(argv[0]); if (doImodv || argv[0][i-1] == 'v'){ if (!useChooserPlug) App->chooserPlugin = 0; imodv_main(argcHere, argv); exit(0); } QDir *curdir = new QDir(); /* 3/14/11: eliminated old code for out how many imods this user is running. */ /*******************/ /* Loop once or twice on arguments; initialize Data each time */ for (argScan = 0; argScan <= doStartup; argScan++) { mrc_init_li(&li, NULL); ivwInit(&vi, false); vi.li = &li; if (ImodPrefs->loadUshorts()) vi.rawImageStore = MRC_MODE_USHORT; plistfname = NULL; xyzwinopen = FALSE; sliceropen = FALSE; zapOpen = FALSE; modelViewOpen= FALSE; fillCache = FALSE; ImodTrans = TRUE; frames = 0; nframex = 0; nframey = 0; overx = 0; overy = 0; firstfile = 0; overEntered = 0; /* handle input options. */ for (i = 1; i < argcHere; i++){ if (argv[i][0] == '-'){ if (firstfile) { imodError(NULL, "3dmod: invalid to have argument %s after" " first filename\n", argv[i]); exit(1); } switch (argv[i][1]){ case 'c': if (argv[i][2] == 'i') break; /* 1/5/04: eliminated colormap selection option */ if (argv[i][2] == 'm') { if (xcramp_readfalsemap(argv[++i])) { qname = b3dGetError(); imodError(NULL, LATIN1(qname)); } break; } badOption(argv[i]); case 'C': if (argv[i][2] == 'T') vi.stripOrTileCache = 1; else if (strlen(argv[i]) > 2) badOption(argv[i]); /* value ending in m or M is megabytes, store as minus */ pathlen = strlen(argv[++i]); sscanf(argv[i], "%d%*c", &vi.vmSize); if (argv[i][pathlen - 1] == 'M' || argv[i][pathlen - 1] == 'm') vi.vmSize = -vi.vmSize; else if (!vi.vmSize) vi.vmSize = HUGE_CACHE; vi.keepCacheFull = 0; break; case 'F': fillCache = TRUE; break; case 'x': if (argv[i][2] == 'y') if(argv[i][3] == 'z'){ xyzwinopen = TRUE; break; } if (argv[i][2] >= '0' && argv[i][2] <= '9') sscanf(argv[i], "-x%d%*c%d", &(li.xmin), &(li.xmax)); else if (strlen(argv[i]) > 2) badOption(argv[i]); else sscanf(argv[++i], "%d%*c%d", &(li.xmin), &(li.xmax)); break; case 'y': if (argv[i][2] >= '0' && argv[i][2] <= '9') sscanf(argv[i], "-y%d%*c%d", &(li.ymin), &(li.ymax)); else if (strlen(argv[i]) > 2) badOption(argv[i]); else sscanf(argv[++i], "%d%*c%d", &(li.ymin), &(li.ymax)); break; case 'z': if (argv[i][2] >= '0' && argv[i][2] <= '9') sscanf(argv[i], "-z%d%*c%d", &(li.zmin), &(li.zmax)); else if (strlen(argv[i]) > 2) badOption(argv[i]); else sscanf(argv[++i], "%d%*c%d", &(li.zmin), &(li.zmax)); break; case 's': sscanf(argv[++i], "%f%*c%f", &(li.smin), &(li.smax)); if (li.smin || li.smax) iiRawSetScale(li.smin, li.smax); else vi.equalScaling = 1; break; case 'b': sscanf(argv[++i], "%d%*c%d", &(vi.xybin), &(vi.zbin)); if (!vi.zbin) vi.zbin = 1; break; case 'B': sscanf(argv[++i], "%d", &(vi.xybin)); vi.zbin = vi.xybin; break; case 'i': if (argv[i][2] == 'c') { sscanf(argv[++i], "%f%*c%f%*c%f", &initCenter.x, &initCenter.y, &initCenter.z); setCenter = 1; } else if (argv[i][2] == 'a') { sscanf(argv[++i], "%f%*c%f%*c%f", &initAngles[0], &initAngles[1], &initAngles[2]); setAngles = 1; } else if (argv[i][2] == 'z') { sscanf(argv[++i], "%f", &initZoom); setZoom = 1; } else badOption(argv[i]); break; case 'D': Imod_debug = TRUE; break; case 'E': windowKeys = strdup(argv[++i]); break; case 'm': ImodTrans = FALSE; break; case 'M': vi.li->mirrorFFT = -1; break; case 'Y': li.axis = 2; break; case 'h': imod_usage(argv[0]); exit(1); break; case 'p': if (argv[i][2] == 'y') { vi.imagePyramid = 1; break; } if (strlen(argv[i]) > 2) badOption(argv[i]); plistfname = argv[++i]; plFileNames << QDir::toNativeSeparators(curdir->cleanPath(QString(plistfname))); break; case 'a': anglefname = argv[++i]; break; case 'f': frames = 1; break; case 'G': vi.grayRGBs = 1; break; case '2': vi.dim &= ~4; break; case 'P': sscanf(argv[++i], "%d%*c%d", &nframex, &nframey); break; case 'o': overEntered = 1; sscanf(argv[++i], "%d%*c%d", &overx, &overy); break; case 'S': sliceropen = TRUE; break; case 'V': modelViewOpen = TRUE; break; case 'Z': zapOpen = TRUE; break; case 'T': vi.multiFileZ = -1; break; case 'W': print_wid = true; break; case 'r': if (argv[i][2] == 'i') { iiRawSetInverted(); } else if (strlen(argv[i]) > 2) { badOption(argv[i]); } else { sscanf(argv[++i], "%d,%d,%d", &nx, &ny, &nz); iiRawSetSize(nx, ny, nz); } rawSet = 1; break; case 't': sscanf(argv[++i], "%d", &mode); iiRawSetMode(mode); rawSet = 1; break; case 'H': sscanf(argv[++i], "%d", &mode); iiRawSetHeaderSize(mode); rawSet = 1; break; case 'w': iiRawSetSwap(); rawSet = 1; break; case 'I': sscanf(argv[++i], "%d", &mode); if (mode) vi.rawImageStore = MRC_MODE_USHORT; else vi.rawImageStore = 0; break; case 'R': dataFromStdin = true; break; case 'L': useStdin = true; break; case 'O': break; default: badOption(argv[i]); } } else if (!firstfile) firstfile = i; } /* First time through when doing startup, open startup and give it options */ if (!argScan && doStartup) { useChooserPlug = true; startup = new StartupForm(NULL, true, Qt::Window); startup->setWindowIcon(*(App->iconPixmap)); startup->setValues(&vi, argv, firstfile, argcHere, doImodv, plFileNames, anglefname, useMdoc, xyzwinopen, sliceropen, zapOpen, modelViewOpen, fillCache, ImodTrans, vi.li->mirrorFFT, frames, nframex, nframey, overx, overy, overEntered); if (startup->exec() == QDialog::Rejected) { imod_usage(argv[0]); exit(1); } argv = startup->getArguments(argcHere); if (Imod_debug) { for (i = 0; i < argcHere; i++) imodPrintStderr("%s ", argv[i]); imodPrintStderr("\n"); } // Run 3dmodv if they asked for it! if (argv[0][strlen(argv[0]) - 1] == 'v') { imodv_main(argcHere, argv); exit(0); } } } /* If the user did not limit cache and specified Fill cache, then restore the flag to keep cache full */ if (fillCache && vi.vmSize == HUGE_CACHE) vi.keepCacheFull = 1; // If cache is being filled, then cancel strip/tile option if (vi.keepCacheFull) vi.stripOrTileCache = 0; /* Initialize the display system - defer color ramps until image type is known */ imod_display_init(App, argv); /* Add check function for raw and QImage formats after plugins so plugins can add them first. But if any raw options were entered, put raw check first. But if reading from stdin, put MRC check first! */ if (dataFromStdin) iiInsertCheckFunction(iiMRCCheck, 0); iiAddCheckFunction(iiQImageCheck); if (rawSet) iiInsertCheckFunction(iiRawCheck,0); else iiAddCheckFunction(iiRawCheck); tiffFilterWarnings(); iiRegisterQuitCheck(imodQuitCheck); /* Try to open the last file if there is one */ if (firstfile) { qname = QDir::toNativeSeparators(QString(argv[argcHere - 1])); // first check if it is directory, if so say it is last image QFileInfo info(qname); if (info.isDir()) { lastimage = argcHere - 1; } else { mfin = fopen(LATIN1(qname), "rb"); if (mfin == NULL) { /* Fail to open, and it is the only filename, then exit */ if (firstfile == argcHere - 1) { imodError(NULL, "Couldn't open input file %s.\n", argv[argcHere - 1]); exit(10); } /* But if there are other files, set up to open new model with that name*/ imodPrintStderr("Model file (%s) not found: opening " "new model by that name.\n", argv[argcHere - 1]); lastimage = argcHere - 2; newModelCreated = true; } else { /* * Try loading file as a model. Turn it on if successful */ Model = LoadModel(mfin); if (Model) { if (Imod_debug) imodPrintStderr("Loaded model %s\n", argv[argcHere -1]); lastimage = argcHere - 2; Model->drawmode = 1; // Set this now in case image load is interrupted Model->csum = imodChecksum(Model); } else { /* If fail, last file is an image */ lastimage = argcHere - 1; } fclose(mfin); } } } if (dataFromStdin) { // Data from stdin: check for contradictory options if (li.xmin != -1 || li.xmax != -1 || li.ymin != -1 || li.ymax != -1 || li.zmin != -1 || li.zmax != -1) { imodError(NULL, "You cannot set subareas when reading data from stdin\n"); exit(3); } if (plistfname || useStdin || rawSet || vi.vmSize || vi.imagePyramid) { imodError(NULL, "You cannot use -C, -L, -p, -py, or raw options when " "reading data from stdin\n"); exit(3); } if (firstfile && lastimage >= firstfile) { imodError(NULL, "You cannot enter any image files when reading data from stdin\n"); exit(3); } Imod_imagefile = strdup(""); vi.noReadableImage = 1; ivwMultipleFiles(&vi, &Imod_imagefile, 0, 0, anyHavePieceList); } else if (lastimage < firstfile && Model) { /* If we have a model and no image files before that, then it's a fake image */ vi.fakeImage = 1; Imod_imagefile = NULL; vi.numTimes = Model->tmax = imodGetMaxTime(Model); } else if (!firstfile || lastimage == firstfile) { /* If there are no filenames, or one image file, then treat as image file or IFD. First get filename if none */ if (!firstfile) { imodVersion(NULL); imodCopyright(); useChooserPlug = true; qname = utilOpenFileName(NULL, "3dmod: Select Image file to load:", 0, NULL); if (qname.isEmpty()) { imodError(NULL, "3DMOD: file not selected\n"); exit(3); } Imod_imagefile = strdup(LATIN1(qname)); } else { /* Or, just set the image file name */ Imod_imagefile = strdup(LATIN1(curdir->cleanPath(QString(argv[firstfile])))); } if (Imod_debug){ imodPrintStderr("Loading %s\n", Imod_imagefile); } qname = QDir::toNativeSeparators(QString(Imod_imagefile)); // Check if it is directory (again) QFileInfo info(qname); if (info.isDir()) { // Get a QDir there and look for files ending in "list" (could add more) QDir argDir(qname); QStringList filters; filters << "*list"; QStringList dirList = argDir.entryList(filters); if (dirList.isEmpty()) { imodError(NULL, "3dmod: %s is a directory but it does not contain a file " "ending in \"list\"", Imod_imagefile); exit(10); } if (dirList.size() > 1) { imodError(NULL, "3dmod: the directory %s contains more than one file " "ending in \"list\"", Imod_imagefile); exit(10); } // There is one file, now compose name and try to open it free(Imod_imagefile); qname += QDir::separator() + dirList[0]; Imod_imagefile = strdup(LATIN1(qname)); } // Now open the argument or the file found in the directory vi.fp = fin = fopen(LATIN1(qname), "r"); if (fin == NULL) { imodError(NULL, "Couldn't open input file %s.\n", Imod_imagefile); exit(10); } /* A single image file name can be either * IMOD image file desc. * or mrc image file. */ vi.ifd = imodImageFileDesc(fin); if (Imod_debug) imodPrintStderr( "Image file type %d\n", vi.ifd); if (vi.ifd) { /* The file is an image list */ if (vi.ifd > 2) { imodError(NULL, "3dmod: Image list file version too high.\n"); exit (11); } /* take directory path to IFD file as new current directory for reading images */ Imod_cwdpath = QDir::currentPath(); Imod_IFDpath = QString(Imod_imagefile); pathlen = Imod_IFDpath.lastIndexOf('/'); if (pathlen < 0) Imod_IFDpath = ""; else { Imod_IFDpath.truncate(pathlen + 1); QDir::setCurrent(Imod_IFDpath); if (Imod_debug) imodPrintStderr("chdir %s\n", LATIN1(Imod_IFDpath)); } /* Load list of images and reset current directory */ ivwLoadIMODifd(&vi, plFileNames, anyHavePieceList, anyImageFail); if (!Imod_IFDpath.isEmpty()) QDir::setCurrent(Imod_cwdpath); } else { // It is a single image file - build list with this image ivwMultipleFiles(&vi, &Imod_imagefile, 0, 0, anyHavePieceList); } } else { /* Multiple image files - build list of images */ ivwMultipleFiles(&vi, argv, firstfile, lastimage, anyHavePieceList); } // A pyramid is implied if there is any montage and more than one file if (vi.numTimes > 1 && ((anyHavePieceList && !frames) || plFileNames.size() > 0) && !vi.imagePyramid) vi.imagePyramid = -1; // If pyramid or tile cache, start the class if (vi.imagePyramid || vi.stripOrTileCache) vi.pyrCache = new PyramidCache(&vi, plFileNames, frames, anyImageFail); /* Now look for piece coordinates - moved up from below 1/2/04 */ if (!vi.fakeImage && vi.numTimes <= 1 && !vi.li->plist && !dataFromStdin) { // If there was a piece list entered with an IFD and not here, go load it if (vi.ifd && plFileNames.size() > 0 && plistfname == NULL) { if (ivwLoadIFDpieceList(LATIN1(plFileNames[0]), vi.li, vi.hdr->nx, vi.hdr->ny, vi.hdr->nz)) { imodError(NULL, "3dmod: Error loading piece list file listed in image list file"); exit (12); } } else { /* Otherwise check for piece list file and read it */ iiPlistLoad(plistfname, vi.li, vi.hdr->nx, vi.hdr->ny, vi.hdr->nz); } /* Or use the -P specification */ if (!vi.li->plist && nframex > 0 && nframey > 0) mrc_plist_create(vi.li, vi.hdr->nx, vi.hdr->ny, vi.hdr->nz, nframex, nframey, overx, overy); /* Or, check for piece coordinates in image header */ if (!vi.li->plist && !frames && (vi.image->file == IIFILE_MRC || vi.image->file == IIFILE_HDF)) { ivwReopen(vi.image); if (QFile::exists(QString(vi.image->filename) + ".mdoc")) useMdoc = 1; iiLoadPCoord(vi.image, useMdoc, vi.li, vi.hdr->nx, vi.hdr->ny, vi.hdr->nz); iiClose(vi.image); } // If an overlap was entered and there were piece coordinates, adjust the overlap if (vi.li->plist && !nframex && !nframey && overEntered) { if (checkPieceList(vi.li->pcoords, 3, vi.li->plist, 1, vi.hdr->nx, &minxpiece, &numXpieces, &xoverlap) || checkPieceList(vi.li->pcoords + 1, 3, vi.li->plist, 1, vi.hdr->ny, &minypiece, &numYpieces, &yoverlap)) { imodError(NULL, "3dmod: Piece coordinates are not on a regular grid so overlap" " cannot be adjusted.\n"); exit (12); } if (numXpieces > 1) adjustPieceOverlap(vi.li->pcoords, 3, vi.li->plist, vi.hdr->nx, minxpiece, xoverlap, overx); if (numYpieces > 1) adjustPieceOverlap(vi.li->pcoords + 1, 3, vi.li->plist, vi.hdr->ny, minypiece, yoverlap, overy); vi.li->px = (vi.hdr->nx - overx) * (numXpieces - 1) + vi.hdr->nx; vi.li->py = (vi.hdr->ny - overy) * (numYpieces - 1) + vi.hdr->ny; } /* DNM 1/2/04: move adjusting of loading coordinates to fix_li call, and move that call into list processing */ } /* A montage is not flippable unless cache full */ if (vi.li->plist || vi.stripOrTileCache) vi.flippable = 0; if (vi.li->axis == 2 && vi.stripOrTileCache) { imodError(NULL, "3dmod: You cannot use a tile/strip cache with flipping of Y and Z"); exit(12); } if (vi.numTimes > 1 && !vi.imagePyramid && vi.stripOrTileCache) { imodError(NULL, "3dmod: You cannot use a tile/strip cache with multiple image files"); exit(12); } // Set up a tile cache now if (vi.stripOrTileCache && !vi.imagePyramid) vi.pyrCache->setupStripOrTileCache(); /* set the model filename, or set to get a new model with empty name */ if (Model || newModelCreated) { setImod_filename(LATIN1(curdir->cleanPath(QString(argv[argcHere - 1])))); } else { Imod_filename[0] = 0x00; newModelCreated = true; } // Read tilt angles if any if (anglefname) ivwReadAngleFile(&vi, anglefname); // Disallow use of file chooser plugin if no chooser was used in startup if (!useChooserPlug) App->chooserPlugin = 0; /*********************/ /* Open Main Window. */ imod_info_open(); if (Imod_debug) imodPuts("info opened"); if (Model && imodDebug('C')) wprint("main set checksum %d\n", Model->csum); /* report window before loading data */ if (print_wid) { unsigned int winID = (unsigned int)ImodInfoWin->winId(); imodPrintStderr("Window id = %u\n", winID); if (Imod_debug) wprint("Window id = %u\n", winID); } /* Get the clipboard messaging object on heap (doesn't work on stack!) */ if (print_wid || useStdin) ClipHandler = new ImodClipboard(useStdin, true); App->listening = (print_wid ? 1 : 0) + (useStdin ? 2 : 0); // Safe to delete startup now, we have all the arguments it was storing delete startup; /********************************************/ /* Load in image data, set up image buffer. */ /* Finish setting up and loading images */ errno = 0; QTime loadTime; loadTime.start(); if (ivwLoadImage(&vi)){ qname = b3dGetError(); qname += "3dmod: Fatal Error -- while reading image data.\n"; if (errno) qname += QString("System error: ") + QString(QString(strerror(errno))); imodError(NULL, LATIN1(qname)); exit(3); } iiRegisterQuitCheck(NULL); // Now we can set to middle Z if (ImodPrefs->startAtMidZ()) vi.zmouse = (int)(vi.zsize / 2); if (Imod_debug) imodPrintStderr("Loading time %.3f\n", loadTime.elapsed() / 1000.); /* 11/13/06: remove setting of time flag in new model */ /* Fill cache if user specified it - loader already filled if keepCacheFull*/ if (fillCache && vi.vmSize) imodCacheFill(&vi); if (Imod_debug) imodPuts("Read image data OK."); /* DNM 1/1/04: eliminate filename output, it is all over the place */ if (vi.fakeImage) wprint("\nNo image loaded.\n"); delete curdir; ImodInfoWin->manageMenus(); /*************************************/ /* add all work procs and time outs. (DNM: no more for imodv) */ /* imodv_add_anim(); */ imod_start_autosave(App->cvi); /* Satisfy the lawyers. */ wprint("3dmod %s Copyright %s\n" "Regents of the Univ. of Colo.\n", VERSION_NAME, COPYRIGHT_YEARS); imod_draw_window(); xcramp_setlevels(App->cvi->cramp,App->cvi->black,App->cvi->white); // Set mouse center and constrain it if (setCenter) { vi.xmouse = initCenter.x; vi.ymouse = initCenter.y; vi.zmouse = initCenter.z; ivwBindMouse(&vi); initCenter.x = vi.xmouse; initCenter.y = vi.ymouse; initCenter.z = vi.zmouse; } /*********************************/ /* Open up default Image Windows. */ if (xyzwinopen) xxyz_open(&vi); if (sliceropen) slicerOpen(&vi, 0); if (modelViewOpen) { imodv_open(); imodvOpenSelectedWindows(windowKeys); } if (zapOpen || !(xyzwinopen || sliceropen || modelViewOpen)) { imod_zap_open(&vi, 0); if (setCenter) ivwSetTopZapCenter(&vi, vi.xmouse, vi.ymouse, B3DNINT(vi.zmouse), false); if (setZoom) ivwSetTopZapZoom(&vi, initZoom, false); } if (Imod_debug) imodPuts("initial windows opened"); if (App->rgba) imod_info_setbw(App->cvi->black, App->cvi->white); /* Open up requested dialog windows */ ImodInfoWin->openSelectedWindows(windowKeys, modelViewOpen); // Set center and angles if appropriate if (sliceropen && setCenter && setAngles) setTopSlicerAngles(initAngles, &initCenter, false); if (sliceropen && setZoom) setTopSlicerZoom(initZoom, false); /* Start main application input loop. */ if (Imod_debug) imodPuts("mainloop"); imodPlugCall(&vi, 0, IMOD_REASON_STARTUP); nx = ImodPrefs->autoConAtStart(); if (!vi.fakeImage && !vi.rgbStore && (nx > 1 || (nx && (newModelCreated || (Model->flags & IMODF_NEW_TO_3DMOD))))) ImodInfoWin->setupAutoContrast(); loopStarted = 1; #ifdef Q_OS_MACX inputRaiseWindows(); #endif return qapp.exec(); }
// 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; }
/* è - ï */ 2|L|P, 2|L|P, 2|L|P, 2|L|P, 2|L|P, 2|L|P, 2|L|P, 2|L|P, \ /* ð - ÷ */ 2|L|P, 2|L|P, 2|L|P, 2|L|P, 2|L|P, 2|L|P, 2|L|P, P, \ /* ø - ÿ */ 2|L|P, 2|L|P, 2|L|P, 2|L|P, 2|L|P, 2|L|P, 2|L|P, ff #define FF 3|L|P /* The entry for 0xff, "ÿ". */ /* _Cconv[] must have 12 entries: four from OFFSETS followed by eight zeros. _Ctype[] must have an entry for each index that might be a valid character, and also for EOF (-1). The following is non-portable because it assumes that _Cconv[] and _Ctype[] will be contiguous in memory. */ #ifdef __CHAR_UNSIGNED__ /* Here we take advantage of the fact that ASCII begins with ample zeros; the explicit "0" is there to provide the right value for _Ctype[EOF]. */ const unsigned char _Cconv[] = { OFFSETS, 0 }; const unsigned char _Ctype[] = { ASCII, LATIN1 (FF) }; #else /* Here it is useful to ensure that Latin-1 characters get the right answers whether they are presented as signed chars (with values less than 0) or correctly converted to unsigned. But you must present '\xff' correctly, because -1 is superseded by EOF. */ const unsigned char _Cconv[] = { OFFSETS, 0,0,0,0, 0,0,0,0, LATIN1 (0) }; const unsigned char _Ctype[] = { ASCII, LATIN1 (FF) }; #endif #endif #ifdef Lisalnum int (isalnum) (int c) { return isalnum (c); } #endif #ifdef Lisalpha int (isalpha) (int c) { return isalpha (c); }
/* * Object list class constructor */ ImodvOlist::ImodvOlist(QWidget *parent, Qt::WFlags fl) : QWidget(parent, fl) { int nPerCol, olistNcol, ob, i; QString qstr; QLabel *label; const char *labels[] = {"New", "Delete", "Clear", "Add All", "Swap", "ON", "OFF", "On", "Off"}; const char *tips[] = {"Start a new object group, copied from current group", "Remove the current object group from list of groups", "Remove all objects from the current group", "Add all objects to the current group", "Remove current members and add all non-members", "Turn ON all objects in the current group", "Turn OFF all objects in the current group", "Turn ON objects NOT in the current group", "Turn OFF objects NOT in the current group"}; setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_AlwaysShowToolTips); QVBoxLayout *layout = new QVBoxLayout(this); layout->setContentsMargins(5, 5, 5, 5); layout->setSpacing(6); QGroupBox *grpbox = new QGroupBox("Object Group Selection"); layout->addWidget(grpbox); QVBoxLayout *gblay = new QVBoxLayout(grpbox); gblay->setContentsMargins(6, 3, 6, 6); gblay->setSpacing(6); QHBoxLayout *hbox = diaHBoxLayout(gblay); mGroupSpin = (QSpinBox *)diaLabeledSpin(0, 0., 0., 1., "Group", grpbox,hbox); mGroupSpin->setSpecialValueText("None"); connect(mGroupSpin, SIGNAL(valueChanged(int)), this, SLOT(curGroupChanged(int))); mGroupSpin->setToolTip("Select the current object group or turn off " "selection"); mNumberLabel = diaLabel("/99", grpbox, hbox); mNameEdit = new QLineEdit(grpbox); hbox->addWidget(mNameEdit); mNameEdit->setMaxLength(OBJGRP_STRSIZE - 1); mNameEdit->setFocusPolicy(Qt::ClickFocus); connect(mNameEdit, SIGNAL(returnPressed()), this, SLOT(returnPressed())); connect(mNameEdit, SIGNAL(textChanged(const QString&)), this, SLOT(nameChanged(const QString&))); mNameEdit->setToolTip("Enter a name for the current group"); QSignalMapper *clickMapper = new QSignalMapper(this); connect(clickMapper, SIGNAL(mapped(int)), this, SLOT(actionButtonClicked(int))); // Make the buttons and put in hbox for (i = 0; i < OBJLIST_NUMBUTTONS; i++) { if (i == 0 || i == 5) hbox = diaHBoxLayout(gblay); if (i == 7) { label = diaLabel("Others:", grpbox, hbox); label->setAlignment(Qt::AlignRight | Qt::AlignVCenter); } qstr = labels[i]; mButtons[i] = diaPushButton(LATIN1(qstr), grpbox, hbox); clickMapper->setMapping(mButtons[i], i); connect(mButtons[i], SIGNAL(clicked()), clickMapper, SLOT(map())); mButtons[i]->setToolTip(tips[i]); } mScroll = new QScrollArea(this); layout->addWidget(mScroll); mFrame = new QFrame(); mScroll->setAutoFillBackground(true); QPalette palette = mFrame->palette(); QColor bkg = palette.color(mFrame->backgroundRole()); diaSetWidgetColor(mScroll->viewport(), bkg); mGrid = new QGridLayout(mFrame); mGrid->setSpacing(2); olistNcol = (numOolistButtons + MAX_LIST_IN_COL - 1) / MAX_LIST_IN_COL; nPerCol = (numOolistButtons + olistNcol - 1) / olistNcol; // Get a signal mapper, connect to the slot for these buttons QSignalMapper *mapper = new QSignalMapper(this); connect(mapper, SIGNAL(mapped(int)), this, SLOT(toggleListSlot(int))); QSignalMapper *gmapper = new QSignalMapper(this); connect(gmapper, SIGNAL(mapped(int)), this, SLOT(toggleGroupSlot(int))); // Make the buttons, set properties and map them for (ob = 0; ob < numOolistButtons; ob++) { QHBoxLayout *hLayout = new QHBoxLayout(); mGrid->addLayout(hLayout, ob % nPerCol, ob / nPerCol); groupButtons[ob] = diaCheckBox("", mFrame, hLayout); qstr.sprintf("%d: ",ob + 1); OolistButtons[ob] = diaCheckBox(LATIN1(qstr), mFrame, hLayout); OolistButtons[ob]->setAutoFillBackground(true); mapper->setMapping(OolistButtons[ob], ob); connect(OolistButtons[ob], SIGNAL(toggled(bool)), mapper, SLOT(map())); gmapper->setMapping(groupButtons[ob], ob); connect(groupButtons[ob], SIGNAL(toggled(bool)), gmapper, SLOT(map())); hLayout->setStretchFactor(OolistButtons[ob], 100); // Hide the buttons later after window size is set grouping = true; } mScroll->setWidget(mFrame); // Make a line QFrame *line = new QFrame(this); line->setFrameShape( QFrame::HLine ); line->setFrameShadow( QFrame::Sunken ); layout->addWidget(line); QHBoxLayout *box = diaHBoxLayout(layout); mDoneButton = diaPushButton("Done", this, box); connect(mDoneButton, SIGNAL(clicked()), this, SLOT(donePressed())); mHelpButton = diaPushButton("Help", this, box); connect(mHelpButton, SIGNAL(clicked()), this, SLOT(helpPressed())); setFontDependentWidths(); }