bool KstIfaceImpl::setPlotAxes(const QString& plotName, int XLower, int XUpper, int YLower, int YUpper) { //find the plot KstApp *app = KstApp::inst(); KMdiIterator<KMdiChildView*> *iter = app->createIterator(); while (iter->currentItem()) { KMdiChildView *childview = iter->currentItem(); KstViewWindow *viewwindow = dynamic_cast<KstViewWindow*>(childview); if (viewwindow) { Kst2DPlotList plotlist = viewwindow->view()->findChildrenType<Kst2DPlot>(false); Kst2DPlotList::Iterator plot_iter=plotlist.findTag(plotName); if (plot_iter != plotlist.end()) { app->deleteIterator(iter); (*plot_iter)->setXScaleMode(FIXED); (*plot_iter)->setYScaleMode(FIXED); (*plot_iter)->setScale(XLower, YLower, XUpper, YUpper); //set the scale // repaint the plot (*plot_iter)->setDirty(); viewwindow->view()->paint(KstPainter::P_PLOT); return true; } } iter->next(); } app->deleteIterator(iter); return false; }
void KstCurveDifferentiateI::cycleWindow(KstViewWindow *window) { KstTopLevelViewPtr tlv = kst_cast<KstTopLevelView>(window->view()); if (tlv) { Kst2DPlotList plotList = tlv->findChildrenType<Kst2DPlot>(false); for (Kst2DPlotList::Iterator it = plotList.begin(); it != plotList.end(); ++it ) { if (_repeatAcross == 0) { _seqVect[0]->reset(); } KstVCurveList vcurves = kstObjectSubList<KstBaseCurve,KstVCurve>((*it)->Curves); for (KstVCurveList::Iterator i = vcurves.begin(); i != vcurves.end(); ++i) { if (_lineColorOrder > -1) { (*i)->setColor(KstColorSequence::entry(_lineColorSeq.current())); } if (_pointStyleOrder > -1) { (*i)->Point.setType(_pointStyleSeq.current()); (*i)->setHasPoints(true); (*i)->setPointDensity(_pointDensity); } if (_lineStyleOrder > -1) { (*i)->setLineStyle(_lineStyleSeq.current()); } if (_lineWidthOrder > -1) { (*i)->setLineWidth(_lineWidthSeq.current()); } (_seqVect[0])->next(); } } } }
bool KstTopLevelView::tiedZoomMode(int zoom, bool flag, double center, int mode, int modeExtra, const QString& plotName) { Kst2DPlotList pl = findChildrenType<Kst2DPlot>(true); bool repaint = false; for (Kst2DPlotList::Iterator i = pl.begin(); i != pl.end(); ++i) { Kst2DPlotPtr p = *i; if (p->isTied() && p->tagName() != plotName) { p->tiedZoomMode((ZoomType)zoom, flag, center, (KstScaleModeType)mode, (KstScaleModeType)modeExtra); repaint = true; } } return repaint; }
bool KstTopLevelView::tiedZoom(bool x, double xmin, double xmax, bool y, double ymin, double ymax, const QString& plotName) { Kst2DPlotList pl = findChildrenType<Kst2DPlot>(true); bool repaint = false; for (Kst2DPlotList::Iterator i = pl.begin(); i != pl.end(); ++i) { Kst2DPlotPtr p = *i; if (p->isTied() && p->tagName() != plotName) { p->tiedZoom(x, xmin, xmax, y, ymin, ymax); repaint = true; } } return repaint; }
bool KstTopLevelView::tiedZoomPrev(const QString& plotName) { Kst2DPlotList pl = findChildrenType<Kst2DPlot>(true); bool repaint = false; for (Kst2DPlotList::Iterator i = pl.begin(); i != pl.end(); ++i) { Kst2DPlotPtr p = *i; if (p->isTied() && p->tagName() != plotName) { if (p->tiedZoomPrev(widget())) { repaint = true; } } } return repaint; }
QStringList KstIfaceImpl::plotList(const QString& window) { QStringList rc; KstApp *app = KstApp::inst(); KMdiChildView *c = app->findWindow(window); KstViewWindow *v = dynamic_cast<KstViewWindow*>(c); if (v) { Kst2DPlotList l = v->view()->findChildrenType<Kst2DPlot>(false); for (Kst2DPlotList::Iterator i = l.begin(); i != l.end(); ++i) { rc += (*i)->tagName(); } } return rc; }
QStringList KstGuiData::plotList(const QString& window) { if (window.isEmpty()) { return Kst2DPlot::globalPlotList().tagNames(); } KstApp *app = KstApp::inst(); KMdiChildView *c = app->findWindow(window); QStringList rc; if (c) { Kst2DPlotList plots = static_cast<KstViewWindow*>(c)->view()->findChildrenType<Kst2DPlot>(); for (Kst2DPlotList::ConstIterator i = plots.begin(); i != plots.end(); ++i) { rc << (*i)->tagName(); } } return rc; }
bool KstIfaceImpl::toggleMaximizePlot(const QString& plotName) { KstApp *app = KstApp::inst(); KMdiIterator<KMdiChildView*> *iter = app->createIterator(); while (iter->currentItem()) { KMdiChildView *childview = iter->currentItem(); KstViewWindow *viewwindow = dynamic_cast<KstViewWindow*>(childview); if (viewwindow) { Kst2DPlotList plotlist = viewwindow->view()->findChildrenType<Kst2DPlot>(false); Kst2DPlotList::Iterator plot_iter = plotlist.findTag(plotName); if (plot_iter != plotlist.end()) { app->deleteIterator(iter); (*plot_iter)->zoomToggle(); return true; } } iter->next(); } app->deleteIterator(iter); return false; }
QStringList KstIfaceImpl::plotContents(const QString& name) { //iterate through the windows until plot is found KstApp *app = KstApp::inst(); KMdiIterator<KMdiChildView*> *iter = app->createIterator(); while (iter->currentItem()) { KMdiChildView *childview = iter->currentItem(); KstViewWindow *viewwindow = dynamic_cast<KstViewWindow*>(childview); if (viewwindow) { Kst2DPlotList plotlist = viewwindow->view()->findChildrenType<Kst2DPlot>(false); Kst2DPlotList::Iterator plot_iter=plotlist.findTag(name); if (plot_iter != plotlist.end()) { app->deleteIterator(iter); return (*plot_iter)->Curves.tagNames(); } } iter->next(); } app->deleteIterator(iter); return QStringList(); }
bool KstIfaceImpl::removeCurveFromPlot(KMdiChildView *win, const QString& plot, const QString& curve) { KstViewWindow *w = dynamic_cast<KstViewWindow*>(win); if (w) { KstTopLevelViewPtr view = kst_cast<KstTopLevelView>(w->view()); if (view) { Kst2DPlotList plots = view->findChildrenType<Kst2DPlot>(true); if (plots.findTag(plot) != plots.end()) { Kst2DPlotPtr p = *(plots.findTag(plot)); KstBaseCurveList bcl = kstObjectSubList<KstDataObject,KstBaseCurve>(KST::dataObjectList); KstBaseCurveList::Iterator ci = bcl.findTag(curve); if (p && ci != bcl.end()) { p->removeCurve(*ci); _doc->forceUpdate(); return true; } } } } return false; }
bool KstIfaceImpl::addPlotMarker(const QString &plotName, double markerValue) { //find the plot KstApp *app = KstApp::inst(); KMdiIterator<KMdiChildView*> *iter = app->createIterator(); while (iter->currentItem()) { KMdiChildView *childview = iter->currentItem(); KstViewWindow *viewwindow = dynamic_cast<KstViewWindow*>(childview); if (viewwindow) { Kst2DPlotList plotlist = viewwindow->view()->findChildrenType<Kst2DPlot>(false); Kst2DPlotList::Iterator plot_iter=plotlist.findTag(plotName); if (plot_iter != plotlist.end() && (*plot_iter)->setPlotMarker(markerValue)) { app->deleteIterator(iter); // repaint the plot (*plot_iter)->setDirty(); viewwindow->view()->paint(KstPainter::P_PLOT); return true; } } iter->next(); } app->deleteIterator(iter); return false; }
bool KstChangeFileDialog::applyFileChange() { KstDataSourcePtr file; KST::dataSourceList.lock().writeLock(); KstDataSourceList::Iterator it = KST::dataSourceList.findReusableFileName(_dataFile->url()); QString invalidSources; int invalid = 0; if (it == KST::dataSourceList.end()) { file = KstDataSource::loadSource(_dataFile->url()); if (!file || !file->isValid()) { KST::dataSourceList.lock().unlock(); QMessageBox::warning(this, tr("Kst"), tr("The file could not be loaded.")); return false; } if (file->isEmpty()) { KST::dataSourceList.lock().unlock(); QMessageBox::warning(this, tr("Kst"), tr("The file does not contain data.")); return false; } KST::dataSourceList.append(file); } else { file = *it; } KST::dataSourceList.lock().unlock(); KstApp *app = KstApp::inst(); KstRVectorList rvl = kstObjectSubList<KstVector,KstRVector>(KST::vectorList); KstRMatrixList rml = kstObjectSubList<KstMatrix,KstRMatrix>(KST::matrixList); int selected = 0; int handled = 0; int count = (int)ChangeFileCurveList->count(); for (int i = 0; i < count; i++) { if (ChangeFileCurveList->isSelected(i)) { ++selected; } } // a map to keep track of which objects have been duplicated, and mapping // old object -> new object KstDataObjectDataObjectMap duplicatedMap; QMap<KstVectorPtr, KstVectorPtr> duplicatedVectors; QMap<KstMatrixPtr, KstMatrixPtr> duplicatedMatrices; KstDataSourceList oldSources; // go through the vectors for (int i = 0; i < (int)rvl.count(); i++) { if (ChangeFileCurveList->isSelected(i)) { KstRVectorPtr vector = rvl[i]; vector->writeLock(); file->readLock(); bool valid = file->isValidField(vector->field()); file->unlock(); if (!valid) { if (invalid > 0) { invalidSources = tr("%1, %2").arg(invalidSources).arg(vector->field()); } else { invalidSources = vector->field(); } ++invalid; } else { if (_duplicateSelected->isChecked()) { // block vector updates until vector is setup properly KST::vectorList.lock().writeLock(); // create a new vector KstRVectorPtr newVector = vector->makeDuplicate(); if (!oldSources.contains(newVector->dataSource())) { oldSources << newVector->dataSource(); } newVector->changeFile(file); KST::vectorList.lock().unlock(); // duplicate dependents if (_duplicateDependents->isChecked()) { duplicatedVectors.insert(KstVectorPtr(vector), KstVectorPtr(newVector)); KST::duplicateDependents(KstVectorPtr(vector), duplicatedMap, duplicatedVectors); } } else { if (!oldSources.contains(vector->dataSource())) { oldSources << vector->dataSource(); } vector->changeFile(file); } } vector->unlock(); app->slotUpdateProgress(selected, ++handled, tr("Updating vectors...")); } } // go through the matrices for (int i = (int)rvl.count(); i < (int)ChangeFileCurveList->count(); i++) { if (ChangeFileCurveList->isSelected(i)) { KstRMatrixPtr matrix = rml[i-rvl.count()]; matrix->writeLock(); file->readLock(); bool valid = file->isValidMatrix(matrix->field()); file->unlock(); if (!valid) { if (invalid > 0) { invalidSources = tr("%1, %2").arg(invalidSources).arg(matrix->field()); } else { invalidSources = matrix->field(); } ++invalid; } else { if (_duplicateSelected->isChecked()) { // block matrix updates until matrix is setup properly KST::matrixList.lock().writeLock(); // create a new matrix KstRMatrixPtr newMatrix = matrix->makeDuplicate(); if (!oldSources.contains(newMatrix->dataSource())) { oldSources << newMatrix->dataSource(); } newMatrix->changeFile(file); KST::matrixList.lock().unlock(); // duplicate dependents if (_duplicateDependents->isChecked()) { duplicatedMatrices.insert(KstMatrixPtr(matrix), KstMatrixPtr(newMatrix)); KST::duplicateDependents(KstMatrixPtr(matrix), duplicatedMap, duplicatedMatrices); } } else { if (!oldSources.contains(matrix->dataSource())) { oldSources << matrix->dataSource(); } matrix->changeFile(file); } } matrix->unlock(); app->slotUpdateProgress(selected, ++handled, tr("Updating matrices...")); } } app->slotUpdateProgress(0, 0, QString::null); file = 0L; // now add any curves and images to plots if they were duplicated if (_duplicateSelected->isChecked() && _duplicateDependents->isChecked()) { KstApp *app = KstApp::inst(); QList<QMdiSubWindow*> windows; QList<QMdiSubWindow*>::const_iterator i; windows = app->subWindowList( CreationOrder ); for (i = windows.constBegin(); i != windows.constEnd(); ++i) KstViewWindow *viewWindow = dynamic_cast<KstViewWindow*>(*i); if (viewWindow) { KstTopLevelViewPtr view = kst_cast<KstTopLevelView>(viewWindow->view()); if (view) { Kst2DPlotList plots = view->findChildrenType<Kst2DPlot>(true); for (Kst2DPlotList::Iterator plotIter = plots.begin(); plotIter != plots.end(); ++plotIter) { for (KstDataObjectDataObjectMap::ConstIterator iter = duplicatedMap.begin(); iter != duplicatedMap.end(); ++iter) { if (KstBaseCurvePtr curve = kst_cast<KstBaseCurve>(iter.data())) { if ((*plotIter)->Curves.contains(kst_cast<KstBaseCurve>(iter.key())) && !(*plotIter)->Curves.contains(kst_cast<KstBaseCurve>(curve))) { (*plotIter)->addCurve(curve); } } } } } } } }
bool KstChangeFileDialogI::applyFileChange() { KstDataSourcePtr file; KST::dataSourceList.lock().writeLock(); KstDataSourceList::Iterator it = KST::dataSourceList.findReusableFileName(_dataFile->url()); QString invalidSources; int invalid = 0; if (it == KST::dataSourceList.end()) { file = KstDataSource::loadSource(_dataFile->url()); if (!file || !file->isValid()) { KST::dataSourceList.lock().unlock(); KMessageBox::sorry(this, i18n("The file could not be loaded.")); return false; } if (file->isEmpty()) { KST::dataSourceList.lock().unlock(); KMessageBox::sorry(this, i18n("The file does not contain data.")); return false; } KST::dataSourceList.append(file); } else { file = *it; } KST::dataSourceList.lock().unlock(); KstApp *app = KstApp::inst(); KstRVectorList rvl = kstObjectSubList<KstVector,KstRVector>(KST::vectorList); KstRMatrixList rml = kstObjectSubList<KstMatrix,KstRMatrix>(KST::matrixList); int selected = 0; int handled = 0; int count = (int)ChangeFileCurveList->count(); for (int i = 0; i < count; i++) { if (ChangeFileCurveList->isSelected(i)) { ++selected; } } // a map to keep track of which objects have been duplicated, and mapping // old object -> new object KstDataObjectDataObjectMap duplicatedMap; QMap<KstVectorPtr, KstVectorPtr> duplicatedVectors; QMap<KstMatrixPtr, KstMatrixPtr> duplicatedMatrices; KstDataSourceList oldSources; // go through the vectors for (int i = 0; i < (int)rvl.count(); i++) { if (ChangeFileCurveList->isSelected(i)) { KstRVectorPtr vector = rvl[i]; vector->writeLock(); file->readLock(); bool valid = file->isValidField(vector->field()); file->unlock(); if (!valid) { if (invalid > 0) { // FIXME: invalid list construction for i18n invalidSources = i18n("%1, %2").arg(invalidSources).arg(vector->field()); } else { invalidSources = vector->field(); } ++invalid; } else { if (_duplicateSelected->isChecked()) { // block vector updates until vector is setup properly KST::vectorList.lock().writeLock(); // create a new vector KstRVectorPtr newVector = vector->makeDuplicate(); if (!oldSources.contains(newVector->dataSource())) { oldSources << newVector->dataSource(); } newVector->changeFile(file); KST::vectorList.lock().unlock(); // duplicate dependents if (_duplicateDependents->isChecked()) { duplicatedVectors.insert(KstVectorPtr(vector), KstVectorPtr(newVector)); KST::duplicateDependents(KstVectorPtr(vector), duplicatedMap, duplicatedVectors); } } else { if (!oldSources.contains(vector->dataSource())) { oldSources << vector->dataSource(); } vector->changeFile(file); } } vector->unlock(); app->slotUpdateProgress(selected, ++handled, i18n("Updating vectors...")); } } // go through the matrices for (int i = (int)rvl.count(); i < (int)ChangeFileCurveList->count(); i++) { if (ChangeFileCurveList->isSelected(i)) { KstRMatrixPtr matrix = rml[i-rvl.count()]; matrix->writeLock(); file->readLock(); bool valid = file->isValidMatrix(matrix->field()); file->unlock(); if (!valid) { if (invalid > 0) { // FIXME: invalid list construction for i18n invalidSources = i18n("%1, %2").arg(invalidSources).arg(matrix->field()); } else { invalidSources = matrix->field(); } ++invalid; } else { if (_duplicateSelected->isChecked()) { // block matrix updates until matrix is setup properly KST::matrixList.lock().writeLock(); // create a new matrix KstRMatrixPtr newMatrix = matrix->makeDuplicate(); if (!oldSources.contains(newMatrix->dataSource())) { oldSources << newMatrix->dataSource(); } newMatrix->changeFile(file); KST::matrixList.lock().unlock(); // duplicate dependents if (_duplicateDependents->isChecked()) { duplicatedMatrices.insert(KstMatrixPtr(matrix), KstMatrixPtr(newMatrix)); KST::duplicateDependents(KstMatrixPtr(matrix), duplicatedMap, duplicatedMatrices); } } else { if (!oldSources.contains(matrix->dataSource())) { oldSources << matrix->dataSource(); } matrix->changeFile(file); } } matrix->unlock(); app->slotUpdateProgress(selected, ++handled, i18n("Updating matrices...")); } } app->slotUpdateProgress(0, 0, QString::null); file = 0L; // now add any curves and images to plots if they were duplicated if (_duplicateSelected->isChecked() && _duplicateDependents->isChecked()) { KstApp *app = KstApp::inst(); KMdiIterator<KMdiChildView*> *it = app->createIterator(); while (it->currentItem()) { KstViewWindow *w = dynamic_cast<KstViewWindow*>(it->currentItem()); if (w) { KstTopLevelViewPtr view = kst_cast<KstTopLevelView>(w->view()); if (view) { Kst2DPlotList plots = view->findChildrenType<Kst2DPlot>(true); for (Kst2DPlotList::Iterator plotIter = plots.begin(); plotIter != plots.end(); ++plotIter) { for (KstDataObjectDataObjectMap::ConstIterator iter = duplicatedMap.begin(); iter != duplicatedMap.end(); ++iter) { if (KstBaseCurvePtr curve = kst_cast<KstBaseCurve>(iter.data())) { if ((*plotIter)->Curves.contains(kst_cast<KstBaseCurve>(iter.key())) && !(*plotIter)->Curves.contains(kst_cast<KstBaseCurve>(curve))) { (*plotIter)->addCurve(curve); } } } } } } it->next(); } app->deleteIterator(it); } // clean up unused data sources // kstdDebug() << "cleaning up data sources" << endl; KST::dataSourceList.lock().writeLock(); for (KstDataSourceList::Iterator it = oldSources.begin(); it != oldSources.end(); ++it) { // kstdDebug() << "DATA SOURCE: " << (*it)->tag().displayString() << " (" << (void*)(*it) << ") USAGE: " << (*it)->getUsage() << endl; if ((*it)->getUsage() == 1) { // kstdDebug() << " -> REMOVED" << endl; KST::dataSourceList.remove((*it).data()); } } KST::dataSourceList.lock().unlock(); if (!invalidSources.isEmpty()) { if (invalid == 1) { KMessageBox::sorry(this, i18n("The following field is not defined for the requested file:\n%1").arg(invalidSources)); } else { KMessageBox::sorry(this, i18n("The following fields are not defined for the requested file:\n%1").arg(invalidSources)); } } emit docChanged(); // force an update in case we're in paused mode KstApp::inst()->forceUpdate(); return true; }
KstBindPlotCollection::KstBindPlotCollection(KJS::ExecState *exec, Kst2DPlotList plots) : KstBindCollection(exec, "PlotCollection") { _isWindow = false; _plots = plots.tagNames(); }
bool KstIfaceImpl::plotEquation(const QString& xvector, const QString& equation, const QString& plotName, const QColor& color) { KstVectorPtr v; Kst2DPlotPtr plot; QString etag, ptag; KST::vectorList.lock().readLock(); KstVectorList::Iterator it = KST::vectorList.findTag(xvector); KST::vectorList.lock().unlock(); KstApp *app = KstApp::inst(); if (equation.isEmpty() || it == KST::vectorList.end()) { return false; } v = *it; etag = KST::suggestEQName(QString(equation).replace(QRegExp("[\\[\\]\\s]"), "_")); ptag = "P-" + plotName; if (!plotName.isEmpty()) { //find the plot, or P-plotName KMdiIterator<KMdiChildView*> *iter = app->createIterator(); bool found = false; while (iter->currentItem() && !found) { KMdiChildView *childview = iter->currentItem(); KstViewWindow *viewwindow = dynamic_cast<KstViewWindow*>(childview); if (viewwindow && !found) { Kst2DPlotList plotlist = viewwindow->view()->findChildrenType<Kst2DPlot>(false); Kst2DPlotList::Iterator plot_iter = plotlist.findTag(plotName); if (plot_iter != plotlist.end()) { plot = *plot_iter; found = true; } else { Kst2DPlotList::Iterator plot_iter = plotlist.findTag(ptag); if (plot_iter != plotlist.end()) { plot = *plot_iter; found = true; } } } iter->next(); } app->deleteIterator(iter); } //if the plot does not exist, create it if (!plot) { //put the plot in the active window KMdiChildView *activewin = app->activeWindow(); if (!activewin) { QString windowname = app->newWindow("W1"); activewin = app->findWindow(windowname); } KstViewWindow *viewwindow = dynamic_cast<KstViewWindow*>(activewin); if (viewwindow) { KstTopLevelViewPtr pTLV = viewwindow->view(); plot = pTLV->createObject<Kst2DPlot>(ptag); } } KstEquationPtr eq = new KstEquation(etag, equation, v, true); if (!eq->isValid()) { return false; } KstVCurveList vcurves = kstObjectSubList<KstBaseCurve,KstVCurve>(plot->Curves); KstVCurvePtr vc = new KstVCurve(KST::suggestCurveName(etag, true), eq->vX(), eq->vY(), 0L, 0L, 0L, 0L, color.isValid() ? color : KstColorSequence::next(vcurves,plot->backgroundColor())); KST::dataObjectList.lock().writeLock(); KST::dataObjectList.append(KstDataObjectPtr(eq)); KST::dataObjectList.append(KstDataObjectPtr(vc)); KST::dataObjectList.lock().unlock(); plot->addCurve(KstBaseCurvePtr(vc)); _doc->forceUpdate(); _doc->setModified(); return true; }
void KST::removeCurveFromPlots(KstBaseCurve *c) { Kst2DPlotList pl = Kst2DPlot::globalPlotList(); for (Kst2DPlotList::Iterator i = pl.begin(); i != pl.end(); ++i) { (*i)->removeCurve(c); } }
int main(int argc, char *argv[]) { int i_file, i_v, i_curve; int i_plot; QString fullPath; KAboutData aboutData("kst", I18N_NOOP("Kst"), KSTVERSION, description, KAboutData::License_GPL, I18N_NOOP("(c) 2000-2007 Barth Netterfield"), 0, "http://kst.kde.org/"); aboutData.addAuthor("Barth Netterfield", I18N_NOOP("Original author and maintainer."), "*****@*****.**", "http://omega.astro.utoronto.ca/"); aboutData.addAuthor("Staikos Computing Services Inc.", I18N_NOOP("Developed for the University of Toronto."), "*****@*****.**", "http://www.staikos.net/"); aboutData.addAuthor("Sumus Technology Limited", I18N_NOOP("Developed for the University of British Columbia"), "*****@*****.**", "http://www.sumusltd.com/"); aboutData.addAuthor("Rick Chern", I18N_NOOP("University of British Columbia"), "", ""); aboutData.addAuthor("Duncan Hanson", I18N_NOOP("University of British Columbia"), "", ""); aboutData.addAuthor("Nicolas Brisset", "", "", ""); aboutData.addAuthor("Matthew Truch", "", "http://matt.truch.net/", "*****@*****.**"); aboutData.addAuthor("Theodore Kisner", "", "*****@*****.**", ""); aboutData.setTranslator(I18N_NOOP("_: NAME OF TRANSLATORS\nYour names"), I18N_NOOP("_: EMAIL OF TRANSLATORS\nYour emails")); KCmdLineArgs::init( argc, argv, &aboutData ); KCmdLineArgs::addCmdLineOptions( options ); // Add our own options. KApplication app; KImageIO::registerFormats(); KstDialogs::replaceSelf(new KstGuiDialogs); KstData::replaceSelf(new KstGuiData); KstApp::initialize(); atexit(exitHelper); if (app.isRestored()) { RESTORE(KstApp) } else { KstApp *kst = new KstApp; InType in; QColor color; QCStringList ycolList; QCStringList matrixList; QCStringList yEqList; QCStringList psdList; QCStringList hsList; QCStringList errorList; unsigned int i_ycol; QCStringList::Iterator hs_string; QCStringList::Iterator eq_i; QCStringList::Iterator mat_i; bool showQuickStart = false; bool showDataWizard = false; bool nOK; int n_y = 0; KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); CheckForCMDErrors(args); QString wizardfile = args->getOption("w"); QString printfile = args->getOption("print"); QString pngfile = args->getOption("png"); bool print_and_exit = false; if (printfile != "<none>") { print_and_exit = true; } if (pngfile != "<none>") { print_and_exit = true; } if (!print_and_exit) { app.setMainWidget(kst); QRect rect = KGlobalSettings::desktopGeometry(kst); kst->resize(5 * rect.width() / 6, 5 * rect.height() / 6); kst->show(); } // get Y axis columns ycolList = args->getOptionList("y"); matrixList = args->getOptionList("z"); yEqList = args->getOptionList("ye"); psdList = args->getOptionList("p"); hsList = args->getOptionList("h"); errorList = args->getOptionList("e"); // y axis or PSD specified, so the files are data files, not kst files. n_y = ycolList.count() + psdList.count() + hsList.count() + yEqList.count() + matrixList.count(); if (n_y > 0) { QString creatingEquations = i18n("Creating equations"); QString creatingCurves = i18n("Creating curves"); QString creatingPlots = i18n("Creating plots"); int count; int handled; kst->slotUpdateProgress( 0, 0, QString::null ); SetCMDOptions(args, in, n_y); KstTopLevelViewPtr tlv = kst->activeView(); if (!tlv) { // if there was no active view then we create one... kst->newWindow(false); tlv = kst->activeView(); } if (!tlv) { kstdError() << i18n("Can't create a view.") << endl; return 0; } CreatePlots(in, tlv); Kst2DPlotList plist = kstObjectSubList<KstViewObject, Kst2DPlot>(tlv->children()); i_plot = 0; Kst2DPlotPtr plot = *plist.at(i_plot); KstVCurveList vcurves = kstObjectSubList<KstBaseCurve,KstVCurve>(plot->Curves); // make stand alone equations if there are no files if (args->count() < 1) { if (!yEqList.isEmpty()) { QString eqS; double max, min; int n; bool xeq; SetEqXRanges(args->getOption("xe"), &min, &max, &n, &xeq); if (xeq) { count = yEqList.size(); handled = 0; kst->slotUpdateProgress( count, handled, creatingEquations ); for (eq_i = yEqList.begin(); eq_i != yEqList.end(); ++eq_i) { eqS = *eq_i; if (NoVectorEq(eqS)) { KstEquationPtr eq = new KstEquation(KST::suggestEQName(eqS), eqS, min, max, n); KstVCurvePtr vc = new KstVCurve(KST::suggestCurveName(eq->tag(), true), eq->vX(), eq->vY(), 0L, 0L, 0L, 0L, KstColorSequence::next(vcurves,plot->backgroundColor())); KST::dataObjectList.lock().writeLock(); KST::dataObjectList.append(eq.data()); KST::dataObjectList.append(vc.data()); KST::dataObjectList.lock().unlock(); plot->addCurve(vc.data()); if (in.sep_plots) { i_plot++; if (i_plot < in.n_plots) { plot = *plist.at(i_plot); } } } handled++; kst->slotUpdateProgress( count, handled, creatingEquations ); } } } } // make the requested curves for each data file count = args->count(); handled = 0; kst->slotUpdateProgress( count, handled, creatingCurves ); for (i_curve = i_v = 0, i_file = 0; i_file < args->count(); i_file++) { // make the file if (QFile::exists(args->arg(i_file))) { fullPath = QFileInfo(args->arg(i_file)).absFilePath(); } else { fullPath = args->arg(i_file); } KstDataSourcePtr file = KstDataSource::loadSource(fullPath); if (file) { if (!file->isValid() || file->isEmpty()) { kstdError() << i18n("No data in file %1. Trying to continue...").arg(args->arg(i_file)) << endl; // The file might get data later! } KST::dataObjectList.lock().writeLock(); KST::dataSourceList.append(file); KST::dataObjectList.lock().unlock(); KstRVectorPtr yvector; KstRVectorPtr evector; KstVCurvePtr curve; KstPSDPtr psd; KstHistogramPtr hs; KstRVectorPtr xvector; if (!ycolList.isEmpty()) { // if there are some xy plots // make the x axis vector xvector = GetOrCreateVector(args->getOption("x"), file, in); if (xvector) { // make the y axis vectors for (i_ycol = 0; i_ycol < ycolList.count(); ++i_ycol ) { yvector = GetOrCreateVector(*(ycolList.at(i_ycol)), file, in); if (yvector) { // make the curves color = KstColorSequence::next(vcurves,plot->backgroundColor()); curve = new KstVCurve(KST::suggestCurveName(yvector->tag(), false), KstVectorPtr(xvector), KstVectorPtr(yvector), 0L, 0L, 0L, 0L, color); if (in.has_points) { curve->setHasPoints(true); curve->setHasLines(false); } if (i_ycol<errorList.count()) { evector = GetOrCreateVector(*(errorList.at(i_ycol)), file, in); if (evector) { curve->setYError(KstVectorPtr(evector)); curve->setYMinusError(KstVectorPtr(evector)); } } KST::dataObjectList.lock().writeLock(); KST::dataObjectList.append(curve.data()); KST::dataObjectList.lock().unlock(); plot->addCurve(curve.data()); if (in.sep_plots) { plot->setTagName(curve->tag()); i_plot++; if (i_plot < in.n_plots) { plot = *plist.at(i_plot); } } // end (if they are separate plots) } } // next y col } } // end (if there are some xy plots) if (!yEqList.isEmpty()) { QString eqS; double max, min; int n; bool xeq, eq_ok; SetEqXRanges(args->getOption("xe"), &min, &max, &n, &xeq); for (eq_i = yEqList.begin(); eq_i != yEqList.end(); ++eq_i) { KstEquationPtr eq; eqS = *eq_i; ProcessEq(eqS, file, in, &eq_ok); if (xeq) { eq = new KstEquation(KST::suggestEQName(eqS), eqS, min,max,n); } else { if (!xvector) { xvector = GetOrCreateVector(args->getOption("x"), file, in); } if (xvector) { eq = new KstEquation(KST::suggestEQName(eqS), eqS, KstVectorPtr(xvector), true); } } if (eq) { KstVCurvePtr vc = new KstVCurve(KST::suggestCurveName(eq->tag(), true), eq->vX(), eq->vY(), 0L, 0L, 0L, 0L, KstColorSequence::next(vcurves,plot->backgroundColor())); KST::dataObjectList.lock().writeLock(); KST::dataObjectList.append(eq.data()); KST::dataObjectList.append(vc.data()); KST::dataObjectList.lock().unlock(); plot->addCurve(vc.data()); if (in.sep_plots) { plot->setTagName(eq->tag()); i_plot++; if (i_plot <in.n_plots) { plot = *plist.at(i_plot); } } } } } if (psdList.count() > 0) { // if there are some psd plots KstRVectorList rvl = kstObjectSubList<KstVector,KstRVector>(KST::vectorList); for (QCStringList::ConstIterator it = psdList.begin(); it != psdList.end(); ++it) { yvector = GetOrCreateVector(*it, file, in); if (yvector) { color = KstColorSequence::next(vcurves,plot->backgroundColor()); psd = new KstPSD( KST::suggestPSDName(yvector->tag()), // FIXME: this was yvector->field(), is this right? KstVectorPtr(yvector), in.rate, true, in.len, true, true, in.VUnits, in.RUnits, WindowOriginal); KstVCurvePtr vc = new KstVCurve(KST::suggestCurveName(psd->tag(), true), psd->vX(), psd->vY(), 0L, 0L, 0L, 0L, color); if (in.has_points) { vc->setHasPoints(true); vc->setHasLines(false); } KST::dataObjectList.lock().writeLock(); KST::dataObjectList.append(psd.data()); KST::dataObjectList.append(vc.data()); KST::dataObjectList.lock().unlock(); plot->addCurve(vc.data()); if (in.sep_plots) { plot->setTagName(psd->tag()); i_plot++; if (i_plot <in.n_plots) { plot = *plist.at(i_plot); } } } } // next psd } // end (if there are some psds) if (hsList.count() > 0) { // if there are some histograms double max, min; int N; KstRVectorList rvl = kstObjectSubList<KstVector,KstRVector>(KST::vectorList); for (hs_string = hsList.begin(); hs_string != hsList.end(); ++hs_string) { yvector = GetOrCreateVector(*hs_string, file, in); if (yvector) { color = KstColorSequence::next(vcurves,plot->backgroundColor()); KstHistogram::AutoBin(KstVectorPtr(yvector), &N, &max, &min); hs = new KstHistogram(KST::suggestHistogramName(yvector->tag()), KstVectorPtr(yvector), min, max, N, KST_HS_NUMBER); KstVCurvePtr vc = new KstVCurve(KST::suggestCurveName(hs->tag(), true), hs->vX(), hs->vY(), 0L, 0L, 0L, 0L, color); vc->setHasPoints(false); vc->setHasLines(false); vc->setHasBars(true); vc->setBarStyle(1); KST::dataObjectList.lock().writeLock(); KST::dataObjectList.append(hs.data()); KST::dataObjectList.append(vc.data()); KST::dataObjectList.lock().unlock(); plot->addCurve(vc.data()); if (in.sep_plots) { plot->setTagName(hs->tag()); i_plot++; if (i_plot < in.n_plots) { plot = *plist.at(i_plot); } } } } // next histogram } // end (if there are some histograms) if (matrixList.count() > 0) { // if there are some matrixes for (mat_i = matrixList.begin(); mat_i != matrixList.end(); ++mat_i) { QString tag_name = KST::suggestMatrixName(*mat_i); if (!file->isValidMatrix(*mat_i)) { startupErrors.append(i18n("Failed to create matrix '%1' from file '%2'.").arg(*mat_i).arg(file->fileName())); } KstRMatrixPtr matrix = new KstRMatrix(file, *mat_i, KstObjectTag(tag_name, file->tag()), 0,0,-1,-1,false,false,0); // xStart, yStart, xNumSteps, yNumSteps, //doAve, doSkip, skip); // Time to create the image from the matrix tag_name = KST::suggestImageName(matrix->tag()); QStringList palList = KPalette::getPaletteList(); QString pal; if (palList.contains("IDL 13 RAINBOW")) { pal = QString("IDL 13 RAINBOW"); } else { pal = QString(*palList.at(0)); } KPalette* newPal = new KPalette(pal); KstImagePtr image = new KstImage(tag_name, KstMatrixPtr(matrix), 0.0, 1.0, true, newPal); plot->addCurve(KstBaseCurvePtr(image)); KST::dataObjectList.lock().writeLock(); KST::dataObjectList.append(image.data()); KST::dataObjectList.lock().unlock(); image = 0L; // drop the reference if (in.sep_plots) { plot->setTagName(matrix->tag()); i_plot++; if (i_plot < in.n_plots) { plot = *plist.at(i_plot); } } } } } else { startupErrors.append(i18n("Failed to load file '%1'.").arg(args->arg(i_file))); } handled++; kst->slotUpdateProgress( count, handled, creatingCurves ); } // next data file count = in.n_plots; handled = 0; kst->slotUpdateProgress( count, handled, creatingPlots ); for (i_plot = 0; i_plot < in.n_plots; i_plot++) { plot = *plist.at(i_plot); plot->generateDefaultLabels(); // if we have only images in a plot then set the scale mode to AUTO (instead of AUTOBORDER) KstImageList images = kstObjectSubList<KstBaseCurve,KstImage>(plot->Curves); if (images.count() == plot->Curves.count()) { plot->setXScaleMode(AUTO); plot->setYScaleMode(AUTO); } if (plot->Curves.count() > 3 || in.dolegend) { KstViewLegendPtr vl = plot->getOrCreateLegend(); vl->resizeFromAspect(0.1, 0.1, 0.2, 0.1); vl->setBorderWidth(2); } handled++; kst->slotUpdateProgress( count, handled, creatingPlots ); } kst->slotUpdateProgress( 0, 0, QString::null ); } else if (args->count() > 0) { // open a kst file // some of the options can be overridden kst->openDocumentFile(args->arg(0), args->getOption("F"), // override FileName args->getOption("n").toInt(&nOK), // override number of frames args->getOption("f").toInt(&nOK), // override starting frame args->getOption("s").toInt(&nOK), // override skip args->isSet("a"), // add averaging !print_and_exit); // delayed } else { //kst->openDocumentFile(); showQuickStart = true; } if (args->isSet("nq")) { showQuickStart = false; } if (args->isSet("w")) { showDataWizard = true; showQuickStart = false; } if (printfile != "<none>") { kst->forceUpdate(); kst->immediatePrintToFile(printfile, false); } if (pngfile != "<none>") { kst->forceUpdate(); kst->immediatePrintToPng(pngfile); } kst->document()->setModified(false); if (print_and_exit) { delete kst; return 0; } else { kst->updateDialogs(); if (showQuickStart) { kst->showQuickStartDialog(); } if (showDataWizard) { kst->showDataWizardWithFile(wizardfile); } for (size_t i = 0; i < startupErrors.size(); ++i) { KstDebug::self()->log(startupErrors[i], KstDebug::Error); } startupErrors.clear(); } // LEAVE THIS HERE - causes crashes otherwise! int rc = app.exec(); delete kst; return rc; } return app.exec(); }