bool KstChangeNptsDialogI::updateChangeNptsDialog() { QStringList qsl; int inserted = 0; for (uint i_vector = 0; i_vector < CurveList->count(); i_vector++) { if (CurveList->isSelected(i_vector)) { qsl.append(CurveList->text(i_vector)); } } CurveList->clear(); KstRVectorList rvl = kstObjectSubList<KstVector,KstRVector>(KST::vectorList); // insert vectors into ChangeNptsCurveList CurveList->blockSignals(true); // avoid deadlock for (KstRVectorList::ConstIterator i = rvl.begin(); i != rvl.end(); ++i) { KstRVectorPtr vector = *i; vector->readLock(); QString tag = vector->tag().displayString(); CurveList->insertItem(tag, -1); if (qsl.contains(tag)) { CurveList->setSelected(inserted, true); } ++inserted; vector->unlock(); } CurveList->blockSignals(false); return !qsl.isEmpty(); }
void KstObjectItem::showMetadata() { if (_rtti == RTTI_OBJ_DATA_VECTOR) { DataSourceMetaDataDialog *dlg = new DataSourceMetaDataDialog(_dm, 0, false, WDestructiveClose); KstReadLocker vl(&KST::vectorList.lock()); KstVectorList::Iterator m = KST::vectorList.findTag(_tag); KstRVectorPtr r = kst_cast<KstRVector>(*m); KstDataSourcePtr dsp; if (r) { r->readLock(); dsp = r->dataSource(); r->unlock(); } dlg->setDataSource(dsp); dlg->show(); } else if (_rtti == RTTI_OBJ_DATA_MATRIX) { DataSourceMetaDataDialog *dlg = new DataSourceMetaDataDialog(_dm, 0, false, WDestructiveClose); KstReadLocker ml(&KST::matrixList.lock()); KstMatrixList::Iterator m = KST::matrixList.findTag(_tag); KstRMatrixPtr r = kst_cast<KstRMatrix>(*m); KstDataSourcePtr dsp; if (r) { r->readLock(); dsp = r->dataSource(); r->unlock(); } dlg->setDataSource(dsp); dlg->show(); } }
void KstObjectItem::reload() { if (_rtti == RTTI_OBJ_DATA_VECTOR) { KstReadLocker ml(&KST::vectorList.lock()); KstVectorList::Iterator v = KST::vectorList.findTag(_tag); if (v != KST::vectorList.end()) { KstRVectorPtr r = kst_cast<KstRVector>(*v); if (r) { r->writeLock(); r->reload(); r->unlock(); } } } else if (_rtti == RTTI_OBJ_DATA_MATRIX) { KstReadLocker ml(&KST::matrixList.lock()); KstMatrixList::Iterator m = KST::matrixList.findTag(_tag); if (m != KST::matrixList.end()) { KstRMatrixPtr r = kst_cast<KstRMatrix>(*m); if (r) { r->writeLock(); r->reload(); r->unlock(); } } } }
void KstChangeNptsDialogI::updateDefaults(int index) { KstRVectorList rvl = kstObjectSubList<KstVector,KstRVector>(KST::vectorList); if (rvl.isEmpty() || index >= (int)rvl.count() || index < 0) { return; } KstRVectorPtr vector = rvl[index]; vector->readLock(); disconnect(_kstDataRange, SIGNAL(changed()), this, SLOT(modifiedRange())); _kstDataRange->_startUnits->setCurrentItem(0); _kstDataRange->_rangeUnits->setCurrentItem(0); /* fill the vector range entries */ _kstDataRange->CountFromEnd->setChecked(vector->countFromEOF()); _kstDataRange->setF0Value(vector->reqStartFrame()); /* fill number of frames entries */ _kstDataRange->ReadToEnd->setChecked(vector->readToEOF()); _kstDataRange->setNValue(vector->reqNumFrames()); /* fill in frames to skip box */ _kstDataRange->Skip->setValue(vector->skip()); _kstDataRange->DoSkip->setChecked(vector->doSkip()); _kstDataRange->DoFilter->setChecked(vector->doAve()); _kstDataRange->updateEnables(); connect(_kstDataRange, SIGNAL(changed()), this, SLOT(modifiedRange())); vector->unlock(); }
void KstVectorDialogI::edit_I() { int index; KstFilePtr file; KstRVectorPtr vector; index = Select->currentItem(); KstRVectorList vectorList = kstObjectSubList<KstVector,KstRVector>(KST::vectorList); if (index < 0) { KMessageBox::sorry(0L, i18n("You need to select an active vector to edit.")); return; } if (unsigned(index) >= vectorList.count()) { new_I(); } else { /* verify that the vector name is unique */ if (Select->currentText() != vectorList[index]->tagName()) { if (KST::dataTagNameNotUnique(Select->currentText())) return; } /* if there is not an active KstFile, create one */ KstFileList::Iterator it = KST::fileList.findFileName(FileName->url()); if (it == KST::fileList.end()) { file = new KstFile(FileName->url()); if (file->numFrames() < 1) { // No data in file KMessageBox::sorry(0L, i18n("The requested file does not contain data.")); return; } KST::fileList.append(file); } else { file = *it; } if (!file->isValidField(Field->currentText())) { KMessageBox::sorry(0L, i18n("The requested field is not defined for the requested file\n")); return; } vector = vectorList[index]; /* change the vector */ vector->change(file, Field->currentText(), Select->currentText(), (CountFromEnd->isChecked() ? -1 : F0->value()), (ReadToEnd->isChecked() ? -1 : N->value()), Skip->value(), DoSkip->isChecked(), DoFilter->isChecked()); /** purge unused files */ //doc->fileList.Purge(); vector = 0L; vectorList.clear(); emit modified(); } }
void KstVectorDialogI::delete_I() { int index; KstRVectorPtr vector; KstRVectorList vectorList = kstObjectSubList<KstVector,KstRVector>(KST::vectorList); index = Select->currentItem(); if (index < 0) { KMessageBox::sorry(0L, i18n("You need to select an active vector to delete.")); return; } if (unsigned(index) >= vectorList.count()) { return; } vector = vectorList[index]; if (vector->getUsage() > 2) { KMessageBox::sorry(0L, i18n("Cannot delete: Selected vector is used by at least one curve. Delete curves first.")); return; } KST::vectorList.lock().writeLock(); KST::vectorList.remove(vectorList[index].data()); KST::vectorList.lock().writeUnlock(); /** purge unused files */ //doc->fileList.Purge(); vector = 0L; vectorList.clear(); emit modified(); }
KstObjectItem::KstObjectItem(QListView *parent, KstRVectorPtr x, KstDataManagerI *dm) : QObject(), QListViewItem(parent), _rtti(RTTI_OBJ_DATA_VECTOR), _name(x->tagName()), _dm(dm) { assert(x); setText(0, x->tagName()); setText(1, i18n("Data Vector")); x = 0L; // keep the counts in sync update(); }
KstObjectItem::KstObjectItem(QListView *parent, KstRVectorPtr x, KstDataManagerI *dm, int localUseCount) : QObject(), QListViewItem(parent), _rtti(RTTI_OBJ_DATA_VECTOR), _tag(x->tag()), _dm(dm) { assert(x); _inUse = false; setText(0, x->tag().tag()); setText(1, i18n("Data Vector")); x = 0L; // keep the counts in sync update(true, localUseCount); }
KJS::Value KstBindDataVector::dataSource(KJS::ExecState *exec) const { KstRVectorPtr v = makeDataVector(_d); KstReadLocker rl(v); KstDataSourcePtr dp = v->dataSource(); if (!dp) { return KJS::Undefined(); } return KJS::Object(new KstBindDataSource(exec, dp)); }
void KstEventMonitorI::acceptChanges() { KstRVectorList rvl = kstObjectSubList<KstVector,KstRVector>(KST::vectorList); KstRVectorPtr vector; vector = *(rvl.findTag( _strVector )); if( vector != NULL ) { vector->setEventMonitors( &_eventMonitors ); } setChanged( FALSE ); }
KJS::Value KstBindDataVector::reload(KJS::ExecState *exec, const KJS::List& args) { Q_UNUSED(args) KstRVectorPtr v = makeDataVector(_d); if (!v) { KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError); exec->setException(eobj); return KJS::Undefined(); } KstWriteLocker wl(v); v->reload(); return KJS::Undefined(); }
void KstIfaceImpl::reloadVector(const QString& vector) { KstReadLocker ml(&KST::vectorList.lock()); KstVectorList::Iterator v = KST::vectorList.findTag(vector); if (v != KST::vectorList.end()) { (*v)->writeLock(); KstRVectorPtr r = kst_cast<KstRVector>(*v); if (r) { r->reload(); } (*v)->unlock(); } }
KJS::Value KstBindDataVector::changeFrames(KJS::ExecState *exec, const KJS::List& args) { KstRVectorPtr v = makeDataVector(_d); if (!v) { KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError); exec->setException(eobj); return KJS::Undefined(); } if (args.size() > 1) { if (args[0].type() != KJS::NumberType || args[1].type() != KJS::NumberType) { KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError); exec->setException(eobj); return KJS::Undefined(); } KstWriteLocker wl(v); int start = d2i(args[0].toNumber(exec)); int count = d2i(args[1].toNumber(exec)); int skip = v->doSkip() ? v->skip() : -1; bool ave = v->doAve(); if (args.size() > 2) { if (args[2].type() != KJS::NumberType) { KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError); exec->setException(eobj); return KJS::Undefined(); } skip = d2i(args[2].toNumber(exec)); if (args.size() > 3) { if (args[3].type() != KJS::BooleanType) { KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError); exec->setException(eobj); return KJS::Undefined(); } ave = d2i(args[3].toBoolean(exec)); } } v->changeFrames(start, count, skip, skip >= 0, ave); return KJS::Undefined(); } KJS::Object eobj = KJS::Error::create(exec, KJS::SyntaxError); exec->setException(eobj); return KJS::Undefined(); }
void KstChangeFileDialogI::allFromFile() { if (_files->count() <= 0) { return; } ChangeFileCurveList->selectAll(false); KstReadLocker rl(&KST::vectorList.lock()); for (uint i = 0; i < KST::vectorList.count(); ++i) { KstRVectorPtr v = kst_cast<KstRVector>(*KST::vectorList.findTag(ChangeFileCurveList->text(i))); ChangeFileCurveList->setSelected(i, v && v->filename() == _files->currentText()); } for (uint i = KST::vectorList.count(); i < ChangeFileCurveList->count(); i++) { KstRMatrixPtr m = kst_cast<KstRMatrix>(*KST::matrixList.findTag(ChangeFileCurveList->text(i))); ChangeFileCurveList->setSelected(i, m && m->filename() == _files->currentText()); } }
void KstChangeNptsDialogI::applyNptsChange() { KstRVectorList rvl = kstObjectSubList<KstVector,KstRVector>(KST::vectorList); for (uint i = 0; i < CurveList->count(); ++i) { if (CurveList->isSelected(i)) { KstRVectorPtr vector = *(rvl.findTag(CurveList->text(i))); if (vector) { int f0, n; vector->readLock(); KstDataSourcePtr ds = vector->dataSource(); if (_kstDataRange->isStartRelativeTime() && ds) { ds->readLock(); f0 = ds->sampleForTime(_kstDataRange->f0Value()); ds->unlock(); } else if (_kstDataRange->isStartAbsoluteTime() && ds) { ds->readLock(); f0 = ds->sampleForTime(_kstDataRange->f0DateTimeValue()); ds->unlock(); } else { f0 = int(_kstDataRange->f0Value()); } if (_kstDataRange->isRangeRelativeTime() && ds) { ds->readLock(); double nValStored = _kstDataRange->nValue(); if (_kstDataRange->CountFromEnd->isChecked()) { int frameCount = ds->frameCount(vector->field()); double msCount = ds->relativeTimeForSample(frameCount - 1); n = frameCount - 1 - ds->sampleForTime(msCount - nValStored); } else { double fTime = ds->relativeTimeForSample(f0); n = ds->sampleForTime(fTime + nValStored) - ds->sampleForTime(fTime); } ds->unlock(); } else { n = int(_kstDataRange->nValue()); } vector->unlock(); vector->writeLock(); vector->changeFrames( (_kstDataRange->CountFromEnd->isChecked() ? -1 : f0), (_kstDataRange->ReadToEnd->isChecked() ? -1 : n), _kstDataRange->Skip->value(), _kstDataRange->DoSkip->isChecked(), _kstDataRange->DoFilter->isChecked()); vector->unlock(); } } } _modifiedRange = false; // avoid re-entering the dialog QTimer::singleShot(0, this, SLOT(emitDocChanged())); }
void KstChangeFileDialogI::applyFileChange() { KstDataSourcePtr file; KstRVectorPtr vector; KstWriteLocker ml(&KST::dataSourceList.lock()); /* if there is not an active KstFile, create one */ KstDataSourceList::Iterator it; for (it = KST::dataSourceList.begin(); it != KST::dataSourceList.end(); ++it) { if ((*it)->fileName() == ChangeFileName->currentText()) { file = *it; break; } } if (it == KST::dataSourceList.end()) { file = KstDataSource::loadSource(ChangeFileName->currentText()); if (!file || !file->isValid()) { KMessageBox::sorry(0L, i18n("%1: Unable to open file.").arg(ChangeFileName->currentText())); return; } if (file->frameCount() < 1) { KMessageBox::sorry(0L, i18n("%1: File does not contain data. Operation canceled.").arg(ChangeFileName->currentText())); return; } KST::dataSourceList.append(file); } KstRVectorList rvl = kstObjectSubList<KstVector,KstRVector>(KST::vectorList); for (int i = 0; i < (int)ChangeFileCurveList->count(); i++) { if (ChangeFileCurveList->isSelected(i)) { vector = rvl[i]; if (!file->isValidField(vector->getField())) { KMessageBox::sorry(0L, i18n("%1: Field is not defined for the requested file.").arg(vector->getField())); } else { vector->changeFile(file); } } } /** purge unused files */ //KST::fileList.Purge(); emit docChanged(); }
KJS::Value KstBindDataVector::changeFile(KJS::ExecState *exec, const KJS::List& args) { KstRVectorPtr v = makeDataVector(_d); if (!v) { KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError); exec->setException(eobj); return KJS::Undefined(); } if (args.size() != 1) { KJS::Object eobj = KJS::Error::create(exec, KJS::SyntaxError, "Requires exactly one argument."); exec->setException(eobj); return KJS::Undefined(); } if (args[0].type() != KJS::ObjectType) { KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError); exec->setException(eobj); return KJS::Undefined(); } KstBindDataSource *imp = dynamic_cast<KstBindDataSource*>(args[0].toObject(exec).imp()); if (!imp) { KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError); exec->setException(eobj); return KJS::Undefined(); } #define makeSource(X) dynamic_cast<KstDataSource*>(const_cast<KstObject*>(X.data())) KstDataSourcePtr s = makeSource(imp->_d); if (!s) { KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError); exec->setException(eobj); return KJS::Undefined(); } v->writeLock(); s->writeLock(); v->changeFile(s); s->writeUnlock(); v->writeUnlock(); #undef makeSource return KJS::Undefined(); }
void KstChangeNptsDialogI::updateTimeCombo() { KstRVectorList rvl = kstObjectSubList<KstVector,KstRVector>(KST::vectorList); uint cnt = CurveList->count(); bool supportsTime = true; for (uint i = 0; i < cnt; ++i) { if (CurveList->isSelected(i)) { KstRVectorPtr vector = *(rvl.findTag(CurveList->text(i))); if (vector) { vector->readLock(); KstDataSourcePtr ds = vector->dataSource(); vector->unlock(); if (ds) { ds->readLock(); supportsTime = ds->supportsTimeConversions(); ds->unlock(); if (!supportsTime) { break; } } } } } _kstDataRange->setAllowTime(supportsTime); }
void KstEventMonitorI::displayEvents( const QString& strVector ) { KstRVectorList rvl = kstObjectSubList<KstVector,KstRVector>(KST::vectorList); KstRVectorPtr rvector; int i; rvector = *rvl.findTag(strVector); if( rvector != NULL ) { _eventMonitors = *(rvector->getEventMonitors()); tableEvents->setEventMonitors( &_eventMonitors ); _strVector = strVector; for( i=0; i<(int)_eventMonitors.size(); i++ ) { _eventMonitors[i].setExpression( NULL ); } pushButtonAdd->setEnabled( TRUE ); pushButtonDelete->setEnabled( TRUE ); enableEditing( TRUE ); } else { _strVector = ""; tableEvents->setEventMonitors( NULL ); pushButtonAdd->setEnabled( FALSE ); pushButtonDelete->setEnabled( FALSE ); enableEditing( FALSE ); } }
bool KstIfaceImpl::changeDataFile(const QString& vector, const QString& fileName, bool update) { KST::vectorList.lock().readLock(); KstRVectorPtr rvp = kst_cast<KstRVector>(*KST::vectorList.findTag(vector)); KST::vectorList.lock().unlock(); if (!rvp) { return false; } KST::dataSourceList.lock().writeLock(); KstDataSourceList::Iterator it = KST::dataSourceList.findReusableFileName(fileName); KstDataSourcePtr file; QString invalidSources; if (it == KST::dataSourceList.end()) { file = KstDataSource::loadSource(fileName); if (!file || !file->isValid() || file->isEmpty()) { KST::dataSourceList.lock().unlock(); return false; } KST::dataSourceList.append(file); } else { file = *it; } KST::dataSourceList.lock().unlock(); rvp->writeLock(); file->writeLock(); if (!file->isValidField(vector)) { file->unlock(); rvp->unlock(); return false; } rvp->changeFile(file); file->unlock(); bool rc = rvp->isValid(); rvp->unlock(); if (update) { KstApp::inst()->forceUpdate(); } return rc; }
void KstVectorDialogI::update(int new_index) { int i_vector, index, n_v; KstRVectorPtr vector; bool isNew = false; KstRVectorList vectorList = kstObjectSubList<KstVector,KstRVector>(KST::vectorList); if (new_index == -1) { if (vectorList.findTag(Select->currentText()) != vectorList.end()) { QString save = Select->currentText(); Select->blockSignals(true); Select->clear(); for (KstRVectorList::iterator i = vectorList.begin(); i != vectorList.end(); ++i) { Select->insertItem((*i)->tagName()); } Select->setCurrentText(save); Select->blockSignals(false); return; } } n_v = vectorList.count(); if (n_v < 1) { Select->clear(); Select->insertItem("V1-" + i18n("<New_Vector>")); Delete->setEnabled(false); return; } if (new_index == -2) { isNew = true; new_index = n_v-1; } if (new_index >= 0) { index = new_index; } else if (n_v > 0) { index = Select->currentItem(); } else { index = n_v-1; } /** fill VectorListBox with vector tags */ Select->clear(); for (KstRVectorList::iterator i = vectorList.begin(); i != vectorList.end(); ++i) { Select->insertItem((*i)->tagName()); } if (index >= 0 && index < n_v) { Select->setCurrentItem(index); } else if (n_v > 0) { Select->setCurrentItem(n_v - 1); } i_vector = Select->currentItem(); vector = vectorList[i_vector]; /* fill the fields */ Field->clear(); _fieldCompletion->clear(); KstDataSourcePtr tf; { KST::dataSourceList.lock().readLock(); KstDataSourceList::Iterator it = KST::dataSourceList.findFileName(vector->filename()); if (it != KST::dataSourceList.end()) { tf = *it; Field->insertStringList(tf->fieldList()); _fieldCompletion->insertItems(tf->fieldList()); //std::cout << "inserting string list: " << tf->fieldList().count() << "\n"; } KST::dataSourceList.lock().readUnlock(); } if (isNew) { Field->setCurrentText(QString::null); } else { Field->setCurrentText(vector->getField()); } /* select the proper file */ FileName->setURL(vector->filename()); /* fill the vector range entries */ if (vector->countFromEOF()) { CountFromEnd->setChecked(true); } else { CountFromEnd->setChecked(false); } F0->setValue(vector->reqStartFrame()); /* fill number of frames entries */ if (vector->readToEOF()) { ReadToEnd->setChecked(true); } else { ReadToEnd->setChecked(false); } N->setValue(vector->reqNumFrames()); /* fill in frames to skip box */ Skip->setValue(vector->skip()); DoSkip->setChecked(vector->doSkip()); DoFilter->setChecked(vector->doAve()); if (isNew) { QString new_label; new_label.sprintf("V%d-", n_v+1); new_label += i18n("<New_Vector>"); Select->insertItem(new_label); Select->setCurrentItem(n_v); Delete->setEnabled(false); } else { Delete->setEnabled(vector->getUsage() == 2); } }
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); } } } } } } } }
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(); }
void KstObjectItem::update(bool recursive) { switch (_rtti) { case RTTI_OBJ_DATA_VECTOR: { KstVectorPtr px = *KST::vectorList.findTag(_name); assert(px.data()); assert(dynamic_cast<KstRVector*>(px.data())); KstRVectorPtr x = static_cast<KstRVector*>(px.data()); setText(2, QString::number(x->getUsage() - 3)); // caller has a ptr setText(3, QString::number(x->sampleCount())); setText(4, i18n("%3: %4 [%1..%2]").arg(x->reqStartFrame()) .arg(x->reqStartFrame() + x->reqNumFrames()) .arg(x->getFilename()) .arg(x->getField())); _removable = x->getUsage() == 3; break; } case RTTI_OBJ_VECTOR: { KstVectorPtr x = *KST::vectorList.findTag(_name); assert(x.data()); setText(2, QString::number(x->getUsage() - 2)); //caller also points setText(3, QString::number(x->sampleCount())); setText(4, i18n("[%1..%2]").arg(x->min()).arg(x->max())); _removable = false; break; } case RTTI_OBJ_OBJECT: { KstDataObjectPtr x = *KST::dataObjectList.findTag(_name); assert(x.data()); setText(1, x->typeString()); setText(2, QString::number(x->getUsage() - 1)); // our pointer setText(3, QString::number(x->sampleCount())); setText(4, x->propertyString()); if (recursive) { QPtrStack<QListViewItem> trash; for (QListViewItem *i = firstChild(); i; i = i->nextSibling()) { KstObjectItem *oi = static_cast<KstObjectItem*>(i); if (x->outputVectors().findTag(oi->tagName()) == x->outputVectors().end()) { trash.push(i); } } trash.setAutoDelete(true); trash.clear(); for (KstVectorMap::Iterator p = x->outputVectors().begin(); p != x->outputVectors().end(); ++p) { bool found = false; for (QListViewItem *i = firstChild(); i; i = i->nextSibling()) { KstObjectItem *oi = static_cast<KstObjectItem*>(i); if (oi->tagName() == p.data()->tagName()) { oi->update(); found = true; break; } } if (!found) { new KstObjectItem(this, p.data(), _dm); } } } _removable = x->getUsage() == 1; break; } default: assert(0); } }
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(); }
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; }
void KstDataManagerI::delete_I() { QListViewItem *qi = DataView->selectedItems().at(0); if (!qi) { return; } KstObjectItem *koi = static_cast<KstObjectItem*>(qi); if (koi->removable()) { if (qi->rtti() == RTTI_OBJ_OBJECT) { doc->removeDataObject(koi->tag().tag()); } else if (qi->rtti() == RTTI_OBJ_DATA_VECTOR) { KST::vectorList.lock().writeLock(); KST::vectorList.removeTag(koi->tag().tag()); KST::vectorList.lock().unlock(); doUpdates(); } else if (qi->rtti() == RTTI_OBJ_STATIC_VECTOR) { KST::vectorList.lock().writeLock(); KST::vectorList.removeTag(koi->tag().tag()); KST::vectorList.lock().unlock(); doUpdates(); } else if (qi->rtti() == RTTI_OBJ_DATA_MATRIX) { KST::matrixList.lock().writeLock(); KST::matrixList.removeTag(koi->tag().tag()); KST::matrixList.lock().unlock(); doUpdates(); } else if (qi->rtti() == RTTI_OBJ_STATIC_MATRIX) { KST::matrixList.lock().writeLock(); KST::matrixList.removeTag(koi->tag().tag()); KST::matrixList.lock().unlock(); doUpdates(); } update(); } else { // Don't prompt for base curves KstBaseCurvePtr bc = kst_cast<KstBaseCurve>(koi->dataObject()); if (bc || KMessageBox::warningYesNo(this, i18n("There are other objects in memory that depend on %1. Do you wish to delete them too?").arg(koi->tag().tag())) == KMessageBox::Yes) { if (qi->rtti() == RTTI_OBJ_OBJECT) { koi->dataObject()->deleteDependents(); doc->removeDataObject(koi->tag().tag()); } else if (qi->rtti() == RTTI_OBJ_DATA_VECTOR) { KstRVectorPtr x = kst_cast<KstRVector>(*KST::vectorList.findTag(koi->tag().tag())); if (x) { x->deleteDependents(); x = 0L; KST::vectorList.lock().writeLock(); KST::vectorList.removeTag(koi->tag().tag()); KST::vectorList.lock().unlock(); doUpdates(); } else { KMessageBox::sorry(this, i18n("Unknown error deleting data vector.")); } } else if (qi->rtti() == RTTI_OBJ_STATIC_VECTOR) { KstSVectorPtr x = kst_cast<KstSVector>(*KST::vectorList.findTag(koi->tag().tag())); if (x) { x->deleteDependents(); x = 0L; KST::vectorList.lock().writeLock(); KST::vectorList.removeTag(koi->tag().tag()); KST::vectorList.lock().unlock(); doUpdates(); } else { KMessageBox::sorry(this, i18n("Unknown error deleting static vector.")); } } else if (qi->rtti() == RTTI_OBJ_DATA_MATRIX) { KstRMatrixPtr x = kst_cast<KstRMatrix>(*KST::matrixList.findTag(koi->tag().tag())); if (x) { x->deleteDependents(); x = 0L; KST::matrixList.lock().writeLock(); KST::matrixList.removeTag(koi->tag().tag()); KST::matrixList.lock().unlock(); doUpdates(); } else { KMessageBox::sorry(this, i18n("Unknown error deleting data matrix.")); } } else if (qi->rtti() == RTTI_OBJ_STATIC_MATRIX) { KstSMatrixPtr x = kst_cast<KstSMatrix>(*KST::matrixList.findTag(koi->tag().tag())); if (x) { x->deleteDependents(); x = 0L; KST::matrixList.lock().writeLock(); KST::matrixList.removeTag(koi->tag().tag()); KST::matrixList.lock().unlock(); doUpdates(); } else { KMessageBox::sorry(this, i18n("Unknown error deleting static matrix.")); } } KstApp::inst()->paintAll(KstPainter::P_PLOT); update(); } else { KMessageBox::sorry(this, i18n("Cannot delete objects with dependencies.")); } } }
void KstVectorDialogI::fillFieldsForRVEdit() { KstRVectorPtr rvp = kst_cast<KstRVector>(_dp); rvp->readLock(); _w->_readFromSource->setChecked(true); _w->_rvectorGroup->show(); _w->_kstDataRange->show(); _w->_kstDataRange->setEnabled(true); _w->_svectorGroup->hide(); _w->_svectorGroup->setEnabled(false); _w->sourceGroup->hide(); _tagName->setText(rvp->tagName()); _w->Field->clear(); if (_fieldCompletion) { _fieldCompletion->clear(); } { KstDataSourcePtr tf; KST::dataSourceList.lock().readLock(); KstDataSourceList::Iterator it = KST::dataSourceList.findReusableFileName(rvp->filename()); if (it != KST::dataSourceList.end()) { tf = *it; tf->readLock(); _w->Field->insertStringList(tf->fieldList()); if (_fieldCompletion) { _fieldCompletion->insertItems(tf->fieldList()); } tf->unlock(); } else { QStringList list = KstDataSource::fieldListForSource(_w->FileName->url()); _w->Field->insertStringList(list); if (_fieldCompletion) { _fieldCompletion->insertItems(list); } } KST::dataSourceList.lock().unlock(); } _w->Field->setEnabled(_w->Field->count() > 0); _ok->setEnabled(_w->Field->isEnabled()); _w->Field->setCurrentText(rvp->field()); // select the proper file _w->FileName->setURL(rvp->filename()); // fill the vector range entries _w->_kstDataRange->CountFromEnd->setChecked(rvp->countFromEOF()); _w->_kstDataRange->setF0Value(rvp->reqStartFrame()); // fill number of frames entries _w->_kstDataRange->ReadToEnd->setChecked(rvp->readToEOF()); _w->_kstDataRange->setNValue(rvp->reqNumFrames()); // fill in frames to skip box _w->_kstDataRange->Skip->setValue(rvp->skip()); _w->_kstDataRange->DoSkip->setChecked(rvp->doSkip()); _w->_kstDataRange->DoFilter->setChecked(rvp->doAve()); _w->_kstDataRange->updateEnables(); rvp->unlock(); }
bool KstVectorDialogI::editSingleObjectRV(KstVectorPtr vcPtr) { KstRVectorPtr rvp = kst_cast<KstRVector>(vcPtr); KstDataSourcePtr file; if (_fileNameDirty) { // if there is not an active KstFile, create one KST::dataSourceList.lock().writeLock(); KstDataSourceList::Iterator it = KST::dataSourceList.findReusableFileName(_w->FileName->url()); if (it == KST::dataSourceList.end()) { file = KstDataSource::loadSource(_w->FileName->url()); if (!file || !file->isValid()) { KST::dataSourceList.lock().unlock(); KMessageBox::sorry(this, i18n("The file could not be opened.")); 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(); } else { KstRVectorList vcList = kstObjectSubList<KstVector,KstRVector>(KST::vectorList); for (uint i = 0; i < _editMultipleWidget->_objectList->count(); i++) { if (_editMultipleWidget->_objectList->isSelected(i)) { // get the pointer to the object KstRVectorList::Iterator vcIter = vcList.findTag(_editMultipleWidget->_objectList->text(i)); if (vcIter == vcList.end()) { return false; } KstRVectorPtr rvp = *vcIter; rvp->readLock(); file = rvp->dataSource(); rvp->unlock(); } } } file->writeLock(); if (rvp) { QString pField; if (_fileNameDirty) { pField = _w->Field->currentText(); if (!file->isValidField(pField)) { KMessageBox::sorry(this, i18n("The requested field is not defined for the requested file.")); file->unlock(); return false; } } else { pField = rvp->field(); } int f0 = 0, n = 0; if (_f0Dirty) { if (_w->_kstDataRange->isStartRelativeTime()) { f0 = file->sampleForTime(_w->_kstDataRange->f0Value()); } else if (_w->_kstDataRange->isStartAbsoluteTime()) { bool ok = false; f0 = file->sampleForTime(_w->_kstDataRange->f0DateTimeValue(), &ok); if (!ok) { file->unlock(); KMessageBox::sorry(this, i18n("The requested field or file could not use the specified date.")); return false; } } else { f0 = int(_w->_kstDataRange->f0Value()); } } if (_nDirty) { if (_w->_kstDataRange->isRangeRelativeTime()) { double nValStored = _w->_kstDataRange->nValue(); if (_w->_kstDataRange->CountFromEnd->isChecked()) { int frameCount = file->frameCount(_w->Field->currentText()); double msCount = file->relativeTimeForSample(frameCount - 1); n = frameCount - 1 - file->sampleForTime(msCount - nValStored); } else { double fTime = file->relativeTimeForSample(f0); n = file->sampleForTime(fTime + nValStored) - file->sampleForTime(fTime); } } else { n = int(_w->_kstDataRange->nValue()); } } // use existing requested start and number of frames if not dirty rvp->readLock(); if (!_f0Dirty) { f0 = rvp->reqStartFrame(); } if (!_nDirty) { n = rvp->reqNumFrames(); } // other parameters for multiple edit bool pCountFromEnd, pReadToEnd, pDoSkip, pDoFilter; int pSkip; if (_countFromEndDirty) { pCountFromEnd = _w->_kstDataRange->CountFromEnd->isChecked(); } else { pCountFromEnd = rvp->countFromEOF(); } if (_readToEndDirty) { pReadToEnd = _w->_kstDataRange->ReadToEnd->isChecked(); } else { pReadToEnd = rvp->readToEOF(); } if (_skipDirty) { pSkip = _w->_kstDataRange->Skip->value(); } else { pSkip = rvp->skip(); } if (_doSkipDirty) { pDoSkip = _w->_kstDataRange->DoSkip->isChecked(); } else { pDoSkip = rvp->doSkip(); } if (_doFilterDirty) { pDoFilter = _w->_kstDataRange->DoFilter->isChecked(); } else { pDoFilter = rvp->doAve(); } rvp->unlock(); // change the vector rvp->writeLock(); rvp->change(file, pField, rvp->tag(), pCountFromEnd ? -1 : f0, pReadToEnd ? -1 : n, pSkip, pDoSkip, pDoFilter); rvp->unlock(); } else { KstSVectorPtr svp = kst_cast<KstSVector>(_dp); if (!svp) { file->unlock(); return true; // shouldn't be needed } double x0 = _w->_xMin->text().toDouble(); double x1 = _w->_xMax->text().toDouble(); int n = _w->_N->value(); svp->writeLock(); svp->changeRange(x0, x1, n); svp->setTagName(KstObjectTag(_tagName->text(), svp->tag().context())); // FIXME: doesn't verify uniqueness, doesn't allow changing tag context svp->unlock(); } file->unlock(); return true; }
void KstObjectItem::update(bool recursive, int localUseCount) { switch (_rtti) { case RTTI_OBJ_DATA_VECTOR: { KST::vectorList.lock().readLock(); KstRVectorPtr x = kst_cast<KstRVector>(*KST::vectorList.findTag(_tag)); KST::vectorList.lock().unlock(); if (x) { x->readLock(); // getUsage: subtract 1 for KstRVectorPtr x bool inUse = (x->getUsage() - 1 - localUseCount) > 0; if (inUse != _inUse) { _inUse = inUse; setPixmap(2, inUse ? _dm->yesPixmap() : QPixmap()); } QString field; if (inUse) { field = QString::number(x->length()); } else { field = "-"; } if (text(3) != field) { setText(3, field); } field = i18n("%3: %4 [%1..%2]").arg(x->reqStartFrame()) .arg(x->reqStartFrame() + x->reqNumFrames()) .arg(x->filename()) .arg(x->field()); if (text(4) != field) { setText(4, field); } _removable = x->getUsage() == 2; x->unlock(); } // Hmmm what happens if this if() fails?? We become inconsistent? break; } case RTTI_OBJ_STATIC_VECTOR: { KST::vectorList.lock().readLock(); KstSVectorPtr x = kst_cast<KstSVector>(*KST::vectorList.findTag(_tag)); KST::vectorList.lock().unlock(); if (x) { x->readLock(); // getUsage: subtract 1 for KstRVectorPtr x bool inUse = (x->getUsage() - 1 - localUseCount) > 0; if (inUse != _inUse) { _inUse = inUse; setPixmap(2, inUse ? _dm->yesPixmap() : QPixmap()); } QString field; if (inUse) { field = QString::number(x->length()); } else { field = "-"; } if (text(3) != field) { setText(3, field); } field = i18n("%1 to %2").arg(x->min()).arg(x->max()); if (text(4) != field) { setText(4, field); } _removable = x->getUsage() == 2; x->unlock(); } // Hmmm what happens if this if() fails?? We become inconsistent? break; } case RTTI_OBJ_VECTOR: { KST::vectorList.lock().readLock(); KstVectorPtr x = *KST::vectorList.findTag(_tag); KST::vectorList.lock().unlock(); if (x) { x->readLock(); // getUsage: // subtract 1 for KstVectorPtr x bool inUse = (x->getUsage() - 1 - localUseCount) > 0; if (inUse != _inUse) { _inUse = inUse; setPixmap(2, inUse ? _dm->yesPixmap() : QPixmap()); } QString field = QString::number(x->length()); if (text(3) != field) { setText(3, field); } field = i18n("[%1..%2]").arg(x->min()).arg(x->max()); if (text(4) != field) { setText(4, field); } x->unlock(); _removable = false; } break; } case RTTI_OBJ_OBJECT: { KST::dataObjectList.lock().readLock(); KstDataObjectPtr x = *KST::dataObjectList.findTag(_tag.tag()); KST::dataObjectList.lock().unlock(); if (x) { x->readLock(); QString field = x->typeString(); if (text(1) != field) { setText(1, field); } // getUsage: // subtract 1 for KstDataObjectPtr x bool inUse = (x->getUsage() - 1 - localUseCount) > 0; if (inUse != _inUse) { _inUse = inUse; setPixmap(2, inUse ? _dm->yesPixmap() : QPixmap()); } if (x->sampleCount() > 0) { field = QString::number(x->sampleCount()); if (text(3) != field) { setText(3, field); } } else { if (text(3) != "-") { setText(3, "-"); } } field = x->propertyString(); if (text(4) != field) { setText(4, field); } if (recursive) { QPtrStack<QListViewItem> trash; KstVectorMap vl = x->outputVectors(); KstVectorMap::Iterator vlEnd = vl.end(); for (QListViewItem *i = firstChild(); i; i = i->nextSibling()) { KstObjectItem *oi = static_cast<KstObjectItem*>(i); if (vl.findTag(oi->tag().tag()) == vlEnd) { trash.push(i); } } trash.setAutoDelete(true); trash.clear(); // get the output vectors for (KstVectorMap::Iterator p = vl.begin(); p != vlEnd; ++p) { bool found = false; QString tn = p.data()->tag().tag(); for (QListViewItem *i = firstChild(); i; i = i->nextSibling()) { KstObjectItem *oi = static_cast<KstObjectItem*>(i); if (oi->tag().tag() == tn) { oi->update(); found = true; break; } } if (!found) { KstObjectItem *item = new KstObjectItem(this, p.data(), _dm); connect(item, SIGNAL(updated()), this, SIGNAL(updated())); } } KstMatrixMap ml = x->outputMatrices(); KstMatrixMap::Iterator mlEnd = ml.end(); // also get the output matrices for (KstMatrixMap::Iterator p = ml.begin(); p != mlEnd; ++p) { bool found = false; QString tn = p.data()->tag().tag(); for (QListViewItem *i = firstChild(); i; i = i->nextSibling()) { KstObjectItem *oi = static_cast<KstObjectItem*>(i); if (oi->tag().tag() == tn) { oi->update(); found = true; break; } } if (!found) { KstObjectItem *item = new KstObjectItem(this, p.data(), _dm); connect(item, SIGNAL(updated()), this, SIGNAL(updated())); } } } _removable = x->getUsage() == 1; x->unlock(); } break; } case RTTI_OBJ_DATA_MATRIX: { KST::matrixList.lock().readLock(); KstRMatrixPtr x = kst_cast<KstRMatrix>(*KST::matrixList.findTag(_tag)); KST::matrixList.lock().unlock(); if (x) { x->readLock(); // getUsage: subtract 1 for KstRMatrixPtr x bool inUse = (x->getUsage() - 1 - localUseCount) > 0; if (inUse != _inUse) { _inUse = inUse; setPixmap(2, inUse ? _dm->yesPixmap() : QPixmap()); } QString field = QString::number(x->sampleCount()); if (text(3) != field) { setText(3, field); } field = i18n("%1: %2 (%3 by %4)").arg(x->filename()).arg(x->field()) .arg(x->xNumSteps()) .arg(x->yNumSteps()); if (text(4) != field) { setText(4, field); } _removable = x->getUsage() == 2; x->unlock(); } break; } case RTTI_OBJ_STATIC_MATRIX: { KST::matrixList.lock().readLock(); KstSMatrixPtr x = kst_cast<KstSMatrix>(*KST::matrixList.findTag(_tag)); KST::matrixList.lock().unlock(); if (x) { x->readLock(); // getUsage: subtract 1 for KstRMatrixPtr x bool inUse = (x->getUsage() - 1 - localUseCount) > 0; if (inUse != _inUse) { _inUse = inUse; setPixmap(2, inUse ? _dm->yesPixmap() : QPixmap()); } QString field = QString::number(x->sampleCount()); if (text(3) != field) { setText(3, field); } field = i18n("%1 to %2").arg(x->gradZMin()).arg(x->gradZMax()); if (text(4) != field) { setText(4, field); } _removable = x->getUsage() == 2; x->unlock(); } break; } case RTTI_OBJ_MATRIX: { KST::matrixList.lock().readLock(); KstMatrixPtr x = *KST::matrixList.findTag(_tag); KST::matrixList.lock().unlock(); if (x) { x->readLock(); // getUsage: // subtract 1 for KstVectorPtr x bool inUse = (x->getUsage() - 1 - localUseCount) > 0; if (inUse != _inUse) { _inUse = inUse; setPixmap(2, inUse ? _dm->yesPixmap() : QPixmap()); } QString field = QString::number(x->sampleCount()); if (text(3) != field) { setText(3, field); } field = i18n("[%1..%2]").arg(x->minValue()).arg(x->maxValue()); if (text(4) != field) { setText(4, field); } x->unlock(); _removable = false; } break; } default: assert(0); } }