KJS::Value KstBindDataSource::isValidField(KJS::ExecState *exec, const KJS::List& args) {
  if (args.size() != 1) {
    KJS::Object eobj = KJS::Error::create(exec, KJS::SyntaxError, "Requires exactly one argument.");
    exec->setException(eobj);
    return KJS::Boolean(false);
  }

  if (args[0].type() != KJS::StringType) {
    KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
    exec->setException(eobj);
    return KJS::Boolean(false);
  }

  KstDataSourcePtr s = makeSource(_d);
  if (!s) {
    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
    exec->setException(eobj);
    return KJS::Boolean(false);
  }

  s->writeLock();
  bool rc = s->isValidField(args[0].toString(exec).qstring());
  s->unlock();

  return KJS::Boolean(rc);
}
Пример #2
0
void KstVectorDialogI::new_I() {
  KstDataSourcePtr file;
  KstRVectorPtr vector;
  KstRVectorList vectorList = kstObjectSubList<KstVector,KstRVector>(KST::vectorList);
  QString tag_name = Select->currentText();
  tag_name.replace(i18n("<New_Vector>"), Field->currentText());

  KST::vectorList.lock().readLock();
  int i_c = KST::vectorList.count() + 1;
  KST::vectorList.lock().readUnlock();
  while (KST::dataTagNameNotUnique(tag_name, false)) {
    tag_name.sprintf("V%d-", i_c);
    tag_name += Field->currentText();
    i_c++;
  }

  /* if there is not an active KstFile, create one */
  {
    KST::dataSourceList.lock().writeLock();
    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;
    }
    KST::dataSourceList.lock().writeUnlock();
  }
  if (!file->isValidField(Field->currentText())) {
    KMessageBox::sorry(0L, i18n("The requested field is not defined for the requested file."));
    return;
  }

  /* create the vector */
  vector = new KstRVector(file, Field->currentText(),
                         tag_name,
                         (CountFromEnd->isChecked() ? -1 : F0->value()),
                         (ReadToEnd->isChecked() ? -1 : N->value()),
                         Skip->value(),
			 DoSkip->isChecked(),
			 DoFilter->isChecked());

  emit vectorCreated(KstVectorPtr(vector));
  vector = 0L;
  vectorList.clear();
  emit modified();
}
Пример #3
0
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;
}
Пример #4
0
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();
}
Пример #5
0
void KstVectorDialogI::edit_I() {
  KstDataSourcePtr file;
  KstRVectorPtr vector;

  int index = Select->currentItem();
  if (index < 0) {
    KMessageBox::sorry(0L, i18n("You need to select an active vector to edit."));
    return;
  }

  KstRVectorList vectorList = kstObjectSubList<KstVector,KstRVector>(KST::vectorList);

  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 */
    {
      KST::dataSourceList.lock().writeLock();
      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 opened."));
          return;
        }
        if (file->frameCount() < 1) {
          KMessageBox::sorry(0L, i18n("The file does not contain data."));
          return;
        }
        KST::dataSourceList.append(file);
      } else {
        file = *it;
      }
      KST::dataSourceList.lock().writeUnlock();
    }
    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();
  }
}
Пример #6
0
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);
                }
              }
            }
          }
        }
      }
    }
  }
Пример #7
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;
}
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;
}
bool KstVectorDialogI::newObject() {
  KstDataSourcePtr file;
  QString tag_name = _tagName->text();

  if (_w->_readFromSource->isChecked()) {
    tag_name.replace(defaultTag, _w->Field->currentText());
    tag_name = KST::suggestVectorName(tag_name);

    // if there is not an active DataSource, 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 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();
    }
    file->readLock();
    if (!file->isValidField(_w->Field->currentText())) {
      file->unlock();
      KMessageBox::sorry(this, i18n("The requested field is not defined for the requested file."));
      return false;
    }

    int f0, n;
    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 (_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());
    }
    file->unlock();

    // create the vector
    KstRVectorPtr vector = new KstRVector(
        file, _w->Field->currentText(),
        KstObjectTag(tag_name, file->tag(), false),
        _w->_kstDataRange->CountFromEnd->isChecked() ? -1 : f0,
        _w->_kstDataRange->ReadToEnd->isChecked() ? -1 : n,
        _w->_kstDataRange->Skip->value(),
        _w->_kstDataRange->DoSkip->isChecked(),
        _w->_kstDataRange->DoFilter->isChecked());

    emit vectorCreated(KstVectorPtr(vector));
    vector = 0L;
    emit modified();
  } else {
    double x0 = _w->_xMin->text().toDouble();
    double x1 = _w->_xMax->text().toDouble();
    int n = _w->_N->value();
    QString tagname = _tagName->text();
    if (tagname == defaultTag) {
      tagname = KST::suggestVectorName(QString("(%1..%2)").arg(x0).arg(x1));
    }

    KstSVectorPtr svector = new KstSVector(x0, x1, n, KstObjectTag(tagname, KstObjectTag::globalTagContext));
    emit vectorCreated(KstVectorPtr(svector));
    svector = 0L;
    emit modified();
  }

  return true;
}
Пример #11
0
int main(int argc, char *argv[]) {
  atexit(exitHelper);
  KInstance inst("d2asc");
  KstDataSourcePtr file;

  KConfig *kConfigObject = new KConfig("kstdatarc", false, false);
  KstDataSource::setupOnStartup(kConfigObject);

  fieldEntry field;
  QValueList<fieldEntry> fieldList;
  char *filename;
  bool do_ave = false, do_skip = false;
  int start_frame=0, n_frames=2000000;
  int n_skip = 0;
  int NS=0, i_S;
  int i;

  if (argc < 3 || argv[1][0] == '-') {
    Usage();
    return -1;
  }

  filename = argv[1];

  for (i = 2; i < argc; i++) {
    if (argv[i][0] == '-') {
      if (argv[i][1] == 'f') {
        i++;
        start_frame = atoi(argv[i]);
      } else if (argv[i][1] == 'n') {
        i++;
        n_frames = atoi(argv[i]);
      } else if (argv[i][1] == 's') {
        i++;
        n_skip = atoi(argv[i]);
        if (n_skip>0) do_skip = true;
      } else if (argv[i][1] == 'a') {
        do_ave = true;
      } else if (argv[i][1] == 'x') {
        i++;
        field.field = argv[i];
        field.doHex = true;
        fieldList.append(field);
      } else {
        Usage();
      }
    } else {
      field.field = argv[i];
      field.doHex = false;
      fieldList.append(field);
    }
  }

  if (!do_skip) {
    do_ave = false;
  }

  file = KstDataSource::loadSource(filename);
  if (!file || !file->isValid() || file->isEmpty()) {
    fprintf(stderr, "d2asc error: file %s has no data\n", filename);
    return -2;
  }
  /** make vectors and fill the list **/
  QPtrList<KstRVector> vlist;

  for (i=0; i<int(fieldList.size()); i++) {
    if (!file->isValidField(fieldList[i].field)) {
      fprintf(stderr, "d2asc error: field %s in file %s is not valid\n",
              fieldList[i].field.latin1(), filename);
      return -3;
    }
    KstRVectorPtr v = new KstRVector(file, fieldList[i].field, KstObjectTag("tag", KstObjectTag::globalTagContext), start_frame, n_frames, n_skip, n_skip>0, do_ave);
    vlist.append(v);
  }

  /* find NS */
  for (i = 0; i < int(fieldList.size()); i++) {
    while (vlist.at(i)->update(-1) != KstObject::NO_CHANGE)
      ; // read vector
    if (vlist.at(i)->length() > NS) {
      NS = vlist.at(i)->length();
    }
  }

  for (i_S = 0; i_S < NS; i_S++) {
    for (i = 0; i < int(fieldList.size()); i++) {
      if (fieldList[i].doHex) {
        printf("%4x ",  (int)vlist.at(i)->interpolate(i_S, NS));
      } else {
        printf("%.16g ", vlist.at(i)->interpolate(i_S, NS));
      }
    }
    printf("\n");
  }
}
Пример #12
0
bool KstVectorDialogI::edit_I() {
  KstDataSourcePtr file;

  KstRVectorList vectorList = kstObjectSubList<KstVector,KstRVector>(KST::vectorList);

  /* verify that the vector name is unique */
  DP->readLock();
  if (_tagName->text() != DP->tagName() && KST::vectorTagNameNotUnique(_tagName->text())) {
    DP->readUnlock();
    return false;
  }
  DP->readUnlock();

  /* if there is not an active KstFile, create one */
  {
    KST::dataSourceList.lock().writeLock();
    KstDataSourceList::Iterator it =
      KST::dataSourceList.findFileName(FileName->url());

    if (it == KST::dataSourceList.end()) {
      file = KstDataSource::loadSource(FileName->url());
      if (!file || !file->isValid()) {
        KST::dataSourceList.lock().writeUnlock();
        KMessageBox::sorry(this, i18n("The file could not be opened."));
        return false;
      }
      if (file->isEmpty()) {
        KST::dataSourceList.lock().writeUnlock();
        KMessageBox::sorry(this, i18n("The file does not contain data."));
        return false;
      }
      KST::dataSourceList.append(file);
    } else {
      file = *it;
    }
    KST::dataSourceList.lock().writeUnlock();
  }
  file->readLock();
  if (!file->isValidField(Field->currentText())) {
    file->readUnlock();
    KMessageBox::sorry(this, i18n("The requested field is not defined for "
                                "the requested file\n"));
    return false;
  }
  file->readUnlock();

  int f0, n;
  if (_kstDataRange->isTime()) {
    file->readLock();
    f0 = file->sampleForTime(_kstDataRange->f0Value());
    n = file->sampleForTime(_kstDataRange->nValue());
    file->readUnlock();
  } else {
    f0 = _kstDataRange->f0Value();
    n = _kstDataRange->nValue();
  }
  /* change the vector */
  DP->writeLock();
  DP->change(file, Field->currentText(),
             _tagName->text(),
             (_kstDataRange->CountFromEnd->isChecked() ?  -1 : f0),
             (_kstDataRange->ReadToEnd->isChecked() ?  -1 : n),
             _kstDataRange->Skip->value(),
             _kstDataRange->DoSkip->isChecked(),
             _kstDataRange->DoFilter->isChecked());
  DP->writeUnlock();

  vectorList.clear();
  emit modified();
  return true;
}
Пример #13
0
bool KstVectorDialogI::new_I() {
  KstDataSourcePtr file;
  KstRVectorList vectorList = kstObjectSubList<KstVector,KstRVector>(KST::vectorList);
  QString tag_name = _tagName->text();

  tag_name.replace("<New_Vector>", Field->currentText());

  KST::vectorList.lock().readLock();
  int i_c = KST::vectorList.count() + 1;
  KST::vectorList.lock().readUnlock();
  while (KST::vectorTagNameNotUnique(tag_name, false)) {
    tag_name.sprintf("V%d-", i_c);
    tag_name += Field->currentText();
    i_c++;
  }
  vectorList.clear();

  /* if there is not an active DataSource, create one */
  {
    KST::dataSourceList.lock().writeLock();
    KstDataSourceList::Iterator it = KST::dataSourceList.findFileName(FileName->url());

    if (it == KST::dataSourceList.end()) {
      file = KstDataSource::loadSource(FileName->url());
      if (!file || !file->isValid()) {
        KST::dataSourceList.lock().writeUnlock();
        KMessageBox::sorry(this, i18n("The file could not be loaded."));
        return false;
      }
      if (file->isEmpty()) {
        KST::dataSourceList.lock().writeUnlock();
        KMessageBox::sorry(this, i18n("The file does not contain data."));
        return false;
      }
      KST::dataSourceList.append(file);
    } else {
      file = *it;
    }
    KST::dataSourceList.lock().writeUnlock();
  }
  file->readLock();
  if (!file->isValidField(Field->currentText())) {
    file->readUnlock();
    KMessageBox::sorry(this, i18n("The requested field is not defined for the requested file."));
    return false;
  }
  file->readUnlock();

  int f0, n;
  if (_kstDataRange->isTime()) {
    file->readLock();
    f0 = file->sampleForTime(_kstDataRange->f0Value());
    n = file->sampleForTime(_kstDataRange->nValue());
    file->readUnlock();
  } else {
    f0 = _kstDataRange->f0Value();
    n = _kstDataRange->nValue();
  }
  /* create the vector */
  KstRVectorPtr vector = new KstRVector(
    file, Field->currentText(),
    tag_name,
    (_kstDataRange->CountFromEnd->isChecked() ? -1 : f0),
    (_kstDataRange->ReadToEnd->isChecked() ? -1 : n),
    _kstDataRange->Skip->value(),
    _kstDataRange->DoSkip->isChecked(),
    _kstDataRange->DoFilter->isChecked());

  KST::addVectorToList(KstVectorPtr(vector));

  emit vectorCreated(KstVectorPtr(vector));
  vector = 0L;
  emit modified();

  return true;
}
Пример #14
0
int main(int argc, char *argv[]) {
  KInstance inst("d2asc");
  KstDataSourcePtr file;
  int i;

  char field_list[40][120], filename[180];
  bool do_hex[40];
  int n_field=0;
  int start_frame=0, n_frames=2000000;
  bool do_ave = false, do_skip = false;
  int n_skip = 0;
  int NS=0, i_S;

  if (argc < 3 || argv[1][0] == '-')
    Usage();

  for (i = 0; i < 40; i++)
    do_hex[i] = false;

  strcpy(filename, argv[1]);
  for (i = 2; i < argc; i++) {
    if (argv[i][0] == '-') {
      if (argv[i][1] == 'f') {
        i++;
        start_frame = atoi(argv[i]);
      } else if (argv[i][1] == 'n') {
        i++;
        n_frames = atoi(argv[i]);
      } else if (argv[i][1] == 's') {
        i++;
        n_skip = atoi(argv[i]);
        if (n_skip>0) do_skip = true;
      } else if (argv[i][1] == 'a') {
        do_ave = true;
      } else if (argv[i][1] == 'x') {
        i++;
        strcpy(field_list[n_field], argv[i]);
        do_hex[n_field] = true;
        n_field++;
      } else {
        Usage();
      }
    } else {
      strcpy(field_list[n_field], argv[i]);
      n_field++;
    }
  }

  if (!do_skip) do_ave = false;

  file = KstDataSource::loadSource(filename);
  if (!file || !file->isValid() || file->frameCount() < 1) {
    fprintf(stderr, "d2asc error: file %s has no data\n", filename);
    exit(0);
  }
  /** make vectors and fill the list **/
  QPtrList<KstRVector> vlist;
  vlist.setAutoDelete(true);

  for (i=0; i<n_field; i++) {

    if (!file->isValidField(field_list[i])) {
      fprintf(stderr, "d2asc error: field %s in file %s is not valid\n",
              field_list[i], filename);
      exit(0);
    }
    vlist.append(new KstRVector(file, field_list[i], "tag", start_frame, n_frames, n_skip, n_skip>0, do_ave));
  }

  /* find NS */
  for (i = 0; i < n_field; i++) {

    while (vlist.at(i)->update(-1) != KstObject::NO_CHANGE)
      ; // read vector

    if (vlist.at(i)->sampleCount() > NS)
      NS = vlist.at(i)->sampleCount();
  }

  for (i_S = 0; i_S < NS; i_S++) {
    for (i = 0; i < n_field; i++) {
      if (do_hex[i]) {
        printf("%4x ",  (int)vlist.at(i)->interpolate(i_S, NS));
      } else {
        printf("%.12g ", vlist.at(i)->interpolate(i_S, NS));
      }
    }
    printf("\n");
  }
}