void KstDataManagerI::contextMenu(QListViewItem *i, const QPoint& p, int col) { Q_UNUSED(col) KstObjectItem *koi = static_cast<KstObjectItem*>(i); KstBaseCurve *c; if (koi->rtti() == RTTI_OBJ_OBJECT || koi->rtti() == RTTI_OBJ_DATA_VECTOR) { KPopupMenu *m = new KPopupMenu(this); m->setTitle(koi->text(0)); int id = m->insertItem(i18n("&Edit..."), this, SLOT(edit_I())); //m->setItemEnabled(id, RTTI_OBJ_VECTOR != koi->rtti()); if (koi->rtti() == RTTI_OBJ_DATA_VECTOR) { id = m->insertItem(i18n("&Make Curve..."), koi, SLOT(makeCurve())); } else if ((c = dynamic_cast<KstBaseCurve*>(koi->dataObject().data()))) { KPopupMenu *addMenu = new KPopupMenu(this); KPopupMenu *removeMenu = new KPopupMenu(this); PlotMap.clear(); id = 100; bool haveAdd = false, haveRemove = false; for (KstPlot *p = KST::plotList.first(); p; p = KST::plotList.next()) { if (!p->Curves.contains(c)) { addMenu->insertItem(p->tagName(), koi, SLOT(addToPlot(int)), 0, id); haveAdd = true; } else {
void KstObjectItem::removeFromPlot(int id) { KstPlot *p = KST::plotList.FindKstPlot(PlotMap[id]); KstBaseCurve *c = dynamic_cast<KstBaseCurve*>(dataObject().data()); if (p && c) { p->removeCurve(c); emit updated(); } }
int KstMouse::getLabelNum(const QMouseEvent *e) { KstPlot *plot = KST::plotList.at(getPlotNum()); if (plot) { QPoint pt = plot->GetWinRegion().topLeft(); int x = e->x() - pt.x(), y = e->y() - pt.y(); for(unsigned i = 0; i < plot->labelList.count(); i++) { if (plot->labelList.at(i)->extents.contains(x, y)) { return i; } } } return -1; }
const QString& KstIfaceImpl::createPlot(const QString& name) { QString n = name; if (KST::plotList.FindKstPlot(n)) { n = KST::plotList.generatePlotName(); } KstPlot *p = new KstPlot(n); KST::plotList.append(p); _doc->forceUpdate(); _doc->setModified(); KST::plotList.arrangePlots(KST::plotList.getPlotCols()); return p->tagName(); }
bool KstIfaceImpl::addCurveToPlot(const QString& plot, const QString& curve) { KstPlot *p = KST::plotList.FindKstPlot(plot); KstBaseCurveList bcl = kstObjectSubList<KstDataObject,KstBaseCurve>(KST::dataObjectList); KstBaseCurveList::Iterator ci = bcl.findTag(curve); if (p && ci != bcl.end()) { if (!p->Curves.contains(*ci)) { p->addCurve(*ci); } _doc->forceUpdate(); _doc->setModified(); return true; } return false; }
void CreatePlots(struct InType &in) { KstPlot *plot; int i_plot; int size_boost; for (i_plot=0; i_plot < in.n_plots; i_plot++) { plot = new KstPlot(QString("P") + QString::number(i_plot), 1.0/double(in.n_cols), 1.0/double(in.n_rows), double(i_plot%in.n_cols)/double(in.n_cols), double(i_plot/in.n_cols)/double(in.n_rows)); size_boost = (in.n_rows + in.n_cols)/2-1; size_boost = size_boost*12/2; plot->initFonts(QFont::QFont(), size_boost); KST::plotList.append(plot); } }
void KstPsdDialogI::new_I() { KstPSDCurvePtr curve; double new_freq; int new_len; QString tag_name = Select->currentText(); tag_name.replace(i18n("<New_PSD>"), "PSD_" + _vector->selectedVector()); /* verify that the curve name is unique */ if (KST::dataTagNameNotUnique(tag_name)) { Select->setFocus(); return; } if (_vector->selectedVector().isEmpty()) { KMessageBox::sorry(0L, i18n("New PSD not made: define vectors first.")); return; } /* find new_freq */ new_freq = SampRate->text().toDouble(); if (new_freq <= 0) { KMessageBox::sorry(0L, i18n("The sample rate must be greater than 0.")); return; } /* find new_len */ new_len = FFTLen->text().toInt(); if (new_len < 2) { KMessageBox::sorry(0L, i18n("The FFT length must be greater than 2^2.")); return; } { KST::vectorList.lock().readLock(); KstVectorList::Iterator i = KST::vectorList.findTag(_vector->selectedVector()); if (i == KST::vectorList.end()) { kdFatal() << "Bug in kst: the vector field in plotDialog (PSD) refers to " << "a non existant vector...." << endl; } KstVectorPtr p = *i; KST::vectorList.lock().readUnlock(); /* create the psd curve */ curve = new KstPSDCurve(tag_name, p, new_freq, new_len, VectorUnits->text(), RateUnits->text(), _curveAppearance->color()); } curve->setHasPoints(_curveAppearance->showPoints()); curve->setHasLines(_curveAppearance->showLines()); curve->Point.setType(_curveAppearance->pointType()); curve->setAppodize(Appodize->isChecked()); curve->setRemoveMean(RemoveMean->isChecked()); KstPlot *plot = 0L; if (_curvePlacement->existingPlot()) { /* assign curve to plot */ plot = KST::plotList.FindKstPlot(_curvePlacement->plotName()); plot->addCurve(curve); } if (_curvePlacement->newPlot()) { /* assign curve to plot */ plot = KST::plotList.addPlot(QString::null, _curvePlacement->columns()); _curvePlacement->appendPlot(plot->tagName(), true); plot->addCurve(curve); plot->GenerateDefaultLabels(); } KST::dataObjectList.lock().writeLock(); KST::dataObjectList.append(curve.data()); KST::dataObjectList.lock().writeUnlock(); curve = 0L; emit modified(); }
void KstQuickPSDDialogI::addPlot() { KstPlot *plot = KST::plotList.addPlot(QString::null, PlotCols->value()); PlotList->insertItem(plot->tagName()); PlotList->setCurrentItem(PlotList->count()-1); apply(true); }
void KstQuickPSDDialogI::apply(bool autolabel) { KstDataSourcePtr file; KstVectorPtr vx; KstRVectorPtr trv; KstPlot *plot; int i_v; QString v_name, c_name; bool x_is_new; KstPSDCurvePtr curve; double new_freq; int new_len; if (KST::plotList.count() < 1) { addPlot(); return; } if (SourceVector->isChecked()) { // set vx from existing vectors i_v = Vectors->currentItem(); KstReadLocker ml(&KST::vectorList.lock()); if (i_v >= (int)KST::vectorList.count()) { return; } vx = KST::vectorList[i_v]; } else { // set vx from data file specification KstReadLocker ml(&KST::dataSourceList.lock()); /* generate or find the kstfile */ KstDataSourceList::Iterator it = KST::dataSourceList.findFileName(FileName->url()); if (it == KST::dataSourceList.end()) { file = KstDataSource::loadSource(FileName->url()); if (!file || !file->isValid()) { KMessageBox::sorry(0L, i18n("The file could not be loaded.")); return; } if (file->frameCount() < 1) { KMessageBox::sorry(0L, i18n("The file does not contain data.")); return; } KST::dataSourceList.append(file); } else { file = *it; } KstRVectorList rvl = kstObjectSubList<KstVector,KstRVector>(KST::vectorList); x_is_new = true; /**** Build the XVector ***/ /* make sure there are no vectors with the current vectors props */ for (i_v = 0; unsigned(i_v) < rvl.count(); i_v++) { trv = rvl[i_v]; if ((trv->filename() == FileName->url()) && (trv->getField() == Field->text()) && (trv->reqStartFrame() == F0->value()) && (trv->reqNumFrames() == N->value()) && (trv->skip() == Skip->value()) && (trv->doSkip() == DoSkip->isChecked()) && (trv->doAve() == DoFilter->isChecked()) && (trv->readToEOF() == ReadToEnd->isChecked()) && (trv->countFromEOF() == CountFromEnd->isChecked())) { x_is_new = false; i_v = rvl.count(); vx = trv; } } if (x_is_new) { KST::vectorList.lock().readLock(); /* If not, Generate a unique vector name */ v_name = "V" + QString::number(KST::vectorList.count()+1)+"-" + Field->text(); while (KST::vectorList.findTag(v_name) != KST::vectorList.end()) { v_name += "'"; } KST::vectorList.lock().readUnlock(); KST::dataObjectList.lock().readLock(); while (KST::dataObjectList.findTag(v_name) != KST::dataObjectList.end()) { v_name += "'"; } KST::dataObjectList.lock().readUnlock(); if (!file->isValidField(Field->text())) { KMessageBox::sorry(0L, i18n("The requested field is not defined for the requested file.")); return; } /* generate and append the vector */ trv = new KstRVector(file, Field->text(), v_name, (CountFromEnd->isChecked() ? -1 : F0->value()), (ReadToEnd->isChecked() ? -1 : N->value()), Skip->value(), DoSkip->isChecked(), DoFilter->isChecked()); KST::addVectorToList(KstVectorPtr(trv)); vx = trv; } } /**** Build the PSD ***/ /* find new_freq */ new_freq = PSDSampRate->text().toDouble(); if (new_freq <= 0) { KMessageBox::sorry(0L, i18n("The sample rate must be greater than 0.")); return; } /* find new_len */ new_len = PSDFFTLen->text().toInt(); if (new_len < 2) { KMessageBox::sorry(0L, i18n("The FFT length must be greater than 2^2.")); return; } /* create the psd curve name */ KST::dataObjectList.lock().writeLock(); c_name = "PSD"+QString::number(KST::dataObjectList.count()+1) + "-" + vx->tagName(); while (KST::dataObjectList.findTag(c_name) != KST::dataObjectList.end()) { c_name+="'"; } KST::vectorList.lock().readLock(); while (KST::vectorList.findTag(c_name) != KST::vectorList.end()) { c_name+="'"; } KST::vectorList.lock().readUnlock(); /* create the psd curve */ curve = new KstPSDCurve(c_name, vx, new_freq, new_len, PSDVectorUnits->text(), PSDRateUnits->text(), _curveAppearance->color()); curve->setHasPoints(_curveAppearance->showPoints()); curve->setHasLines(_curveAppearance->showLines()); curve->setLineWidth(_curveAppearance->lineWidth()); curve->setLineStyle(_curveAppearance->lineStyle()); curve->Point.setType(_curveAppearance->pointType()); KST::dataObjectList.append(curve.data()); KST::dataObjectList.lock().writeUnlock(); /* assign curve to plot */ plot = KST::plotList.FindKstPlot(PlotList->currentText()); plot->addCurve(curve); if (autolabel) plot->GenerateDefaultLabels(); close(); emit docChanged(); update(); }
void KstCurveDialogI::new_I() { KstWriteLocker ml(&KST::vectorList.lock()); KstVectorList::Iterator VX, VY; KstVectorList::Iterator EX, EY; KstVCurvePtr curve; KstPlot *plot; if (_xVector->selectedVector().isEmpty()) { KMessageBox::sorry(0L, i18n("New curve not made: define vectors first.")); return; } /* find VX and VY */ VX = KST::vectorList.findTag(_xVector->selectedVector()); VY = KST::vectorList.findTag(_yVector->selectedVector()); EX = KST::vectorList.findTag(_xError->selectedVector()); EY = KST::vectorList.findTag(_yError->selectedVector()); if (VX == KST::vectorList.end() || VY == KST::vectorList.end()) { kdFatal() << "Bug in kst: the XVector field in plotDialog refers to " << "a non existant vector...." << endl; } KstReadLocker rl1(*VX), rl2(*VY); QString tag_name = Select->currentText(); tag_name.replace(i18n("<New_Curve>"), (*VY)->tagName()); /* verify that the curve name is unique */ if (KST::dataTagNameNotUnique(tag_name)) { return; } /* create the curve */ curve = new KstVCurve(tag_name, *VX, *VY, EX != KST::vectorList.end() ? *EX : KstVectorPtr(0L), EY != KST::vectorList.end() ? *EY : KstVectorPtr(0L), _curveAppearance->color()); curve->setHasPoints(_curveAppearance->showPoints()); curve->setHasLines(_curveAppearance->showLines()); curve->Point.setType(_curveAppearance->pointType()); if (_curvePlacement->existingPlot()) { /* assign curve to plot */ plot = KST::plotList.FindKstPlot(_curvePlacement->plotName()); plot->addCurve(curve); } if (_curvePlacement->newPlot()) { /* assign curve to plot */ plot = KST::plotList.addPlot(QString::null, _curvePlacement->columns()); _curvePlacement->appendPlot(plot->tagName(), true); plot->addCurve(curve); plot->GenerateDefaultLabels(); } KST::dataObjectList.lock().readLock(); KST::dataObjectList.append(curve.data()); KST::dataObjectList.lock().writeUnlock(); curve = 0L; emit modified(); }
int main(int argc, char *argv[]) { int i_file, i_v, i_curve; int i_plot; KAboutData aboutData( "kst", I18N_NOOP("Kst"), "0.95-devel", description, KAboutData::License_GPL, I18N_NOOP("(c) 2000-2003 Barth Netterfield"), 0, "http://extragear.kde.org/apps/kst.php"); 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/"); KCmdLineArgs::init( argc, argv, &aboutData ); KCmdLineArgs::addCmdLineOptions( options ); // Add our own options. KApplication app; KImageIO::registerFormats(); if (app.isRestored()) { RESTORE(KstApp) } else { KstApp *kst = new KstApp; struct InType in; QColor color; QCStringList ycolList; QCStringList yEqList; QCStringList psdList; QCStringList hsList; QCStringList errorList; unsigned int i_ycol; QCStringList::Iterator psd; QCStringList::Iterator hs; QCStringList::Iterator eq_i; bool nOK; /* temp variables: these all get stuck into list objects */ KstDataSourcePtr file; KstRVector *xvector=NULL; KstRVector *yvector; KstRVector *evector; KstVCurve *curve; KstPSDCurve *psdcurve; KstEquationCurve *eqcurve; KstHistogram *hscurve; KstPlot *plot; int n_y, n_eq=0; /* Parse command line args */ KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); CheckForCMDErrors(args); // Initialise the plugin loader and collection. PluginCollection::self(); /* get Y axis collums */ ycolList = args->getOptionList("y"); 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(); if (n_y > 0) { SetCMDOptions(args, in, n_y); CreatePlots(in); i_plot = 0; plot = KST::plotList.at(i_plot); /* 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) { for (eq_i = yEqList.begin(); eq_i != yEqList.end(); ++eq_i) { eqS = *eq_i; if (NoVectorEq(eqS)) { eqcurve = new KstEquationCurve(QString("E")+QString::number(n_eq+1)+ "-" + eqS, eqS, min,max,n, KstColorSequence::next()); KST::dataObjectList.lock().writeLock(); KST::dataObjectList.append(eqcurve); KST::dataObjectList.lock().writeUnlock(); plot->addCurve(eqcurve); if (in.sep_plots) { i_plot++; if (i_plot <in.n_plots) plot = KST::plotList.at(i_plot); } } } } } } /* Make the requested curves for each data file */ for (i_curve = i_v = 0, i_file = 0; i_file < args->count(); i_file++) { /* Make the file */ file = KstDataSource::loadSource(args->arg(i_file)); if (!file) { kdWarning() << I18N_NOOP("Error: No data in file: ") << args->arg(i_file) << endl; delete kst; exit(0); } if (!file->isValid() || file->frameCount() < 1) { kdWarning() << I18N_NOOP("Error: No data in file: ") << args->arg(i_file) << endl; // The file might get data later! } KST::dataObjectList.lock().writeLock(); KST::dataSourceList.append(file); KST::dataObjectList.lock().writeUnlock(); if (!ycolList.isEmpty()) { // if there are some xy plots /* make the x axis vector */ xvector = GetOrCreateVector(args->getOption("x"), file, in); /* make the y axis vectors */ for (i_ycol = 0; i_ycol < ycolList.count(); ++i_ycol ) { yvector = GetOrCreateVector(*(ycolList.at(i_ycol)), file, in); /* make the curves */ color = KstColorSequence::next(); curve = new KstVCurve(QString("C") + QString::number(1+i_curve++) + "-" + yvector->getField(), KstVectorPtr(xvector), KstVectorPtr(yvector), 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); curve->setYError(KstVectorPtr(evector)); } KST::dataObjectList.lock().writeLock(); KST::dataObjectList.append(curve); KST::dataObjectList.lock().writeUnlock(); plot->addCurve(curve); if (in.sep_plots) { i_plot++; if (i_plot < in.n_plots) plot = KST::plotList.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) { eqS = *eq_i; ProcessEq(eqS, file, in, &eq_ok); if (xeq) { eqcurve = new KstEquationCurve(QString("E")+QString::number(n_eq+1)+ "-" + eqS, eqS, min,max,n, KstColorSequence::next()); } else { if (xvector==NULL) xvector = GetOrCreateVector(args->getOption("x"), file, in); eqcurve = new KstEquationCurve(QString("E")+QString::number(n_eq+1)+eqS, eqS, KstVectorPtr(xvector), true, KstColorSequence::next()); } KST::dataObjectList.lock().writeLock(); KST::dataObjectList.append(eqcurve); KST::dataObjectList.lock().writeUnlock(); plot->addCurve(eqcurve); if (in.sep_plots) { i_plot++; if (i_plot <in.n_plots) plot = KST::plotList.at(i_plot); } } } if (psdList.count() > 0) { // if there are some psd plots KstRVectorList rvl = kstObjectSubList<KstVector,KstRVector>(KST::vectorList); for(psd = psdList.begin(); psd != psdList.end(); ++psd ) { yvector = GetOrCreateVector(*psd, file, in); color = KstColorSequence::next(); psdcurve = new KstPSDCurve(QString("P") + QString::number(1+i_curve++) + "-" + yvector->getField(), KstVectorPtr(yvector), in.rate, in.len, in.VUnits,in.RUnits, color); if (in.has_points) { psdcurve->setHasPoints(true); psdcurve->setHasLines(false); } KST::dataObjectList.lock().writeLock(); KST::dataObjectList.append(psdcurve); KST::dataObjectList.lock().writeUnlock(); plot->addCurve(psdcurve); if (in.sep_plots) { i_plot++; if (i_plot <in.n_plots) plot = KST::plotList.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 = hsList.begin(); hs != hsList.end(); ++hs ) { yvector = GetOrCreateVector(*hs, file, in); color = KstColorSequence::next(); KstHistogram::AutoBin(KstVectorPtr(yvector), &N, &max, &min); hscurve = new KstHistogram(QString("H") + QString::number(1+i_curve++) + "-" + yvector->getField(), KstVectorPtr(yvector), min, max, N, KST_HS_NUMBER, color); KST::dataObjectList.lock().writeLock(); KST::dataObjectList.append(KstDataObjectPtr(hscurve)); KST::dataObjectList.lock().writeUnlock(); plot->addCurve(hscurve); if (in.sep_plots) { i_plot++; if (i_plot < in.n_plots) plot = KST::plotList.at(i_plot); } } // next histogram } // end (if there are some histograms) } // next data file for (i_plot = 0; i_plot < in.n_plots; i_plot++) { KST::plotList.at(i_plot)->GenerateDefaultLabels(); } KST::plotList.setPlotCols(in.n_cols); } 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 // override number of frames args->getOption("n").toInt(&nOK), // override starting frame args->getOption("f").toInt(&nOK), // override skip args->getOption("s").toInt(&nOK), // add averaging args->isSet("a")); } else { //kst->openDocumentFile(); } QString printfile; printfile = args->getOption("print"); QString pngfile; pngfile = args->getOption("png"); bool print_and_exit = false; if (printfile!="<none>") { args->clear(); kst->forceUpdate(); kst->immediatePrintToFile(printfile); print_and_exit = true; } if (pngfile!="<none>") { args->clear(); kst->forceUpdate(); kst->immediatePrintToPng(pngfile); print_and_exit = true; } if (print_and_exit) { delete kst; exit(0); } else { args->clear(); app.setMainWidget(kst); kst->show(); } // LEAVE THIS HERE - causes crashes otherwise! int rc = app.exec(); delete kst; return rc; } return app.exec(); }