KJS::Value KstBindDataSource::frameCount(KJS::ExecState *exec, const KJS::List& args) {
  QString field;

  if (args.size() == 1) {
    if (args[0].type() != KJS::StringType) {
      KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
      exec->setException(eobj);
      return KJS::Number(0);
    }
    field = args[0].toString(exec).qstring();
  } else if (args.size() != 0) {
    KJS::Object eobj = KJS::Error::create(exec, KJS::SyntaxError, "Requires at most one argument.");
    exec->setException(eobj);
    return KJS::Number(0);
  }

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

  s->writeLock();
  int rc = s->frameCount(field);
  s->unlock();

  return KJS::Number(rc);
}
void KstVectorDialogI::configureSource() {
  bool isNew = false;
  KST::dataSourceList.lock().readLock();
  KstDataSourcePtr ds = *KST::dataSourceList.findReusableFileName(_w->FileName->url());
  KST::dataSourceList.lock().unlock();
  if (!ds) {
    isNew = true;
    ds = KstDataSource::loadSource(_w->FileName->url());
    if (!ds || !ds->isValid()) {
      _w->_configure->setEnabled(false);
      return;
    }
  }

  assert(_configWidget);
  KDialogBase *dlg = new KDialogBase(this, "Data Config Dialog", true, i18n("Configure Data Source"));
  if (isNew) {
    connect(dlg, SIGNAL(okClicked()), _configWidget, SLOT(save()));
    connect(dlg, SIGNAL(applyClicked()), _configWidget, SLOT(save()));
  } else {
    connect(dlg, SIGNAL(okClicked()), this, SLOT(markSourceAndSave()));
    connect(dlg, SIGNAL(applyClicked()), this, SLOT(markSourceAndSave()));
  }
  _configWidget->reparent(dlg, QPoint(0, 0));
  dlg->setMainWidget(_configWidget);
  _configWidget->setInstance(ds);
  _configWidget->load();
  dlg->exec();
  _configWidget->reparent(0L, QPoint(0, 0));
  dlg->setMainWidget(0L);
  delete dlg;
  updateCompletion(); // could be smarter by only running if Ok/Apply clicked
}
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);
}
Example #4
0
KstObject::UpdateType IndirectSource::update(int u) {
    if (KstObject::checkUpdateCounter(u)) {
        return lastUpdateResult();
    }

    // recheck the indirect file for a changed filename
    QFile f(_filename);
    if (f.open(QIODevice::ReadOnly)) {
        char* data;

        if (0 < f.readLine(data,1000)) {
            QString ifn(data);
            KUrl url(ifn);
            if (url.isLocalFile() || url.protocol().isEmpty()) {
                if (QFileInfo(ifn).isRelative()) {
                    ifn = QFileInfo(_filename).absolutePath() + QDir::separator() + ifn;
                }
            }

            if (!_child || ifn.trimmed() != _child->fileName()) {
                _child = 0L; // release
                KstDataSourcePtr p = KstDataSource::loadSource(ifn.trimmed());
                if (p) {
                    _child = p;
                    _fieldList = p->fieldList();
                    _valid = true;
                } else {
                    _valid = false;
                }
            }
        }
    }

    return setLastUpdateResult(_child ? _child->update(u) : KstObject::NO_CHANGE);
}
KJS::Value KstBindDataSource::samplesPerFrame(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::Number(0);
  }

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

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

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

  return KJS::Number(rc);
}
void KstVectorDialogI::markSourceAndSave() {
  assert(_configWidget);
  KstDataSourcePtr src = static_cast<KstDataSourceConfigWidget*>((QWidget*)_configWidget)->instance();
  if (src) {
    src->disableReuse();
  }
  static_cast<KstDataSourceConfigWidget*>((QWidget*)_configWidget)->save();
}
KJS::Value KstBindDataSource::completeFieldList(KJS::ExecState *exec) const {
  Q_UNUSED(exec)
  KstDataSourcePtr s = makeSource(_d);
  if (s) {
    KstReadLocker rl(s);
    return KJS::Boolean(s->fieldListIsComplete());
  }
  return KJS::Boolean(false);
}
KJS::Value KstBindDataSource::source(KJS::ExecState *exec) const {
  Q_UNUSED(exec)
  KstDataSourcePtr s = makeSource(_d);
  if (s) {
    KstReadLocker rl(s);
    return KJS::String(s->sourceName());
  }
  return KJS::String();
}
KJS::Value KstBindDataSource::empty(KJS::ExecState *exec) const {
  Q_UNUSED(exec)
  KstDataSourcePtr s = makeSource(_d);
  if (s) {
    KstReadLocker rl(s);
    return KJS::Boolean(s->isEmpty());
  }
  return KJS::Boolean(false);
}
Example #10
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();
}
Example #11
0
void KstChangeFileDialog::markSourceAndSave()
{
  if (_configWidget) {
    KstDataSourcePtr src = static_cast<KstDataSourceConfigWidget*>((QWidget*)_configWidget)->instance();
    if (src) {
      src->disableReuse();
    }
    static_cast<KstDataSourceConfigWidget*>((QWidget*)_configWidget)->save();
  }
}
Example #12
0
KJS::Value KstBindDataSource::metaData(KJS::ExecState *exec) const {
  KJS::Object array(exec->interpreter()->builtinArray().construct(exec, 0));
  KstDataSourcePtr s = makeSource(_d);
  if (s) {
    s->readLock();
    QMap<QString,QString> data = s->metaData();
    s->readUnlock();
    for (QMap<QString,QString>::ConstIterator i = data.begin(); i != data.end(); ++i) {
      array.put(exec, KJS::Identifier(i.key().latin1()), KJS::String(i.data()));
    }
  }
  return array;
}
KJS::Value KstBindDataSource::metaData(KJS::ExecState *exec) const {
  KJS::Object array(exec->interpreter()->builtinArray().construct(exec, 0));
  KstDataSourcePtr s = makeSource(_d);
  if (s) {
    s->readLock();
    QDict<KstString> data = s->metaData();
    s->unlock();
    for (QDictIterator<KstString> i(data); i.current(); ++i) {
      array.put(exec, KJS::Identifier(i.currentKey().latin1()), KJS::String(i.current() ? i.current()->value() : QString::null));
    }
  }
  return array;
}
Example #14
0
void KstChangeFileDialog::sourceChanged(const QString& text)
{
  delete _configWidget;
  _configWidget = 0L;
  _configureSource->setEnabled(false);
  _file = QString::null;
  if (!text.isEmpty() && text != "stdin" && text != "-") {
    KUrl url;
    QString txt = _dataFile->completionObject()->replacedPath(text);
    if (QFile::exists(txt) && QFileInfo(txt).isRelative()) {
      url.setPath(txt);
    } else {
      url = KUrl::fromPathOrURL(txt);
    }

    if (!url.isLocalFile() && url.protocol() != "file" && !url.protocol().isEmpty()) {
      _fileType->setText(QString::null);
      return;
    }

    if (!url.isValid()) {
      _fileType->setText(QString::null);
      return;
    }

    QString file = txt;

    KstDataSourcePtr ds = *KST::dataSourceList.findReusableFileName(file);
    QStringList fl;
    QString fileType;

    if (ds) {
      ds->readLock();
      fl = ds->fieldList();
      fileType = ds->fileType();
      ds->unlock();
      ds = 0L;
    } else {
      bool complete = false;
      fl = KstDataSource::fieldListForSource(file, QString::null, &fileType, &complete);
    }

    if (!fl.isEmpty() && !fileType.isEmpty()) {
      if (ds) {
        ds->writeLock();
        _configWidget = ds->configWidget();
        ds->unlock();
      } else {
        _configWidget = KstDataSource::configWidgetForSource(file, fileType);
      }
    }

    _configureSource->setEnabled(_configWidget);
    _file = file;
    _fileType->setText(fileType.isEmpty() ? QString::null : tr("Data source of type: %1").arg(fileType));
  } else {
    _fileType->setText(QString::null);
  }
}
Example #15
0
void KstMatrixDialog::configureSource() {
  KstDataSourcePtr ds;
  bool isNew = false;

  KST::dataSourceList.lock().readLock();
// xxx  ds = *KST::dataSourceList.findReusableFileName(_w->_fileName->url());
  KST::dataSourceList.lock().unlock();

  if (!ds) {
    isNew = true;
// xxx    ds = KstDataSource::loadSource(_w->_fileName->url());
    if (!ds || !ds->isValid()) {
      _w->_configure->setEnabled(false);

      return;
    }
  }

  if (_configWidget) {
    QDialog *dlg;
  
    dlg = new QDialog(this);
    dlg->setWindowTitle(QObject::tr("Configure Data Source"));

    if (isNew) {
      connect(dlg, SIGNAL(okClicked()), _configWidget, SLOT(save()));
      connect(dlg, SIGNAL(applyClicked()), _configWidget, SLOT(save()));
    } else {
      connect(dlg, SIGNAL(okClicked()), this, SLOT(markSourceAndSave()));
      connect(dlg, SIGNAL(applyClicked()), this, SLOT(markSourceAndSave()));
    }

    _configWidget->setParent(dlg);
// xxx    dlg->setMainWidget(_configWidget);
    _configWidget->setInstance(ds);
    _configWidget->load();
    dlg->exec();
// xxx    _configWidget->reparent(0L, QPoint(0, 0));
// xxx    dlg->setMainWidget(0L);

    delete dlg;
  }

  updateCompletion(); // could be smarter by only running if Ok/Apply clicked
}
Example #16
0
QString KstIfaceImpl::loadMatrix(const QString& name, const QString& file, const QString& field,
                                int xStart, int yStart, int xNumSteps, int yNumSteps, 
                                int skipFrames, bool boxcarFilter) {
  KstDataSourcePtr src;
  /* generate or find the kstfile */
  KST::dataSourceList.lock().writeLock();
  KstDataSourceList::Iterator it = KST::dataSourceList.findReusableFileName(file);

  if (it == KST::dataSourceList.end()) {
    src = KstDataSource::loadSource(file);
    if (!src || !src->isValid()) {
      KST::dataSourceList.lock().unlock();
      return QString::null;
    }
    if (src->isEmpty()) {
      KST::dataSourceList.lock().unlock();
      return QString::null;
    }
    KST::dataSourceList.append(src);
  } else {
    src = *it;
  }
  src->writeLock();
  KST::dataSourceList.lock().unlock();

  // make sure field is valid
  if (!src->isValidMatrix(field)) {
    src->unlock();
    return QString::null;  
  }
  
  // make sure name is unique, else generate a unique one
  KST::matrixList.lock().readLock();
 
  QString matrixName;
  if (name.isEmpty()) {
    matrixName = "M" + QString::number(KST::matrixList.count() + 1); 
  } else {
    matrixName = name;  
  }

  while (KstData::self()->matrixTagNameNotUnique(matrixName, false)) {
    matrixName = "M" + QString::number(KST::matrixList.count() + 1);
  }
  KST::matrixList.lock().unlock();

  KstMatrixPtr p = new KstRMatrix(src, field, matrixName, xStart, yStart, xNumSteps, yNumSteps, 
                                  boxcarFilter, skipFrames > 0, skipFrames);
  KST::addMatrixToList(p);

  src->unlock();

  if (p) {
    _doc->forceUpdate();
    _doc->setModified();
    return p->tagName();
  }

  return QString::null;
}
Example #17
0
IndirectSource::IndirectSource(QSettings *cfg, const QString& filename, KstDataSourcePtr child)
    : KstDataSource(cfg, filename, QString::null), _child(child) {
    if (child) {
        _valid = true;
        _fieldList = child->fieldList();
    } else {
        _valid = false;
    }
}
KJS::Value KstBindDataSource::fieldList(KJS::ExecState *exec, const KJS::List& args) {
  Q_UNUSED(args)
  KJS::List rc;
  KstDataSourcePtr s = makeSource(_d);
  if (!s) {
    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
    exec->setException(eobj);
    return KJS::Object(exec->interpreter()->builtinArray().construct(exec, rc));
  }
  s->readLock();
  QStringList l = s->fieldList();
  s->unlock();
  for (QStringList::ConstIterator i = l.begin(); i != l.end(); ++i) {
    rc.append(KJS::String(*i));
  }

  return KJS::Object(exec->interpreter()->builtinArray().construct(exec, rc));
}
Example #19
0
const QString& KstIfaceImpl::loadVector(const QString& file, const QString& field) {
  KstDataSourcePtr src;
  /* generate or find the kstfile */
  KST::dataSourceList.lock().writeLock();
  KstDataSourceList::Iterator it = KST::dataSourceList.findReusableFileName(file);

  if (it == KST::dataSourceList.end()) {
    src = KstDataSource::loadSource(file);
    if (!src || !src->isValid()) {
      KST::dataSourceList.lock().unlock();
      return QString::null;
    }
    if (src->isEmpty()) {
      KST::dataSourceList.lock().unlock();
      return QString::null;
    }
    KST::dataSourceList.append(src);
  } else {
    src = *it;
  }
  src->writeLock();
  KST::dataSourceList.lock().unlock();

  KST::vectorList.lock().readLock();
  QString vname = "V" + QString::number(KST::vectorList.count() + 1);

  while (KstData::self()->vectorTagNameNotUnique(vname, false)) {
    vname = "V" + QString::number(KST::vectorList.count() + 1);
  }
  KST::vectorList.lock().unlock();

  KstVectorPtr p = new KstRVector(src, field, vname, 0, -1, 0, false, false);
  KST::addVectorToList(p);

  src->unlock();

  if (p) {
    _doc->forceUpdate();
    _doc->setModified();
    return p->tagName();
  }

  return QString::null;
}
Example #20
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();
}
Example #21
0
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);
}
Example #23
0
void KstChangeFileDialog::configureSource()
{
  bool isNew = false;
  KST::dataSourceList.lock().readLock();
  KstDataSourcePtr ds = *KST::dataSourceList.findReusableFileName(_file);
  KST::dataSourceList.lock().unlock();
  if (!ds) {
    isNew = true;
    ds = KstDataSource::loadSource(_file);
    if (!ds || !ds->isValid()) {
      _configureSource->setEnabled(false);
      return;
    }
  }

  if (_configWidget) {
    KDialogBase *dlg = new KDialogBase(this, "Data Config Dialog", true, tr("Configure Data Source"));
    if (isNew) {
      connect(dlg, SIGNAL(okClicked()), _configWidget, SLOT(save()));
      connect(dlg, SIGNAL(applyClicked()), _configWidget, SLOT(save()));
    } else {
      connect(dlg, SIGNAL(okClicked()), this, SLOT(markSourceAndSave()));
      connect(dlg, SIGNAL(applyClicked()), this, SLOT(markSourceAndSave()));
    }

    _configWidget->reparent(dlg, QPoint(0, 0));
    dlg->setMainWidget(_configWidget);
    static_cast<KstDataSourceConfigWidget*>((QWidget*)_configWidget)->setInstance(ds);
    static_cast<KstDataSourceConfigWidget*>((QWidget*)_configWidget)->load();
    dlg->exec();
    _configWidget->reparent(0L, QPoint(0, 0));
    dlg->setMainWidget(0L);
    delete dlg;
    sourceChanged(_dataFile->url());
  }
}
Example #24
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;
}
Example #25
0
void KstVectorDialogI::updateCompletion() {
  QString current_text = Field->currentText();
  Field->clear();

  /* update filename list and ll axes combo boxes */
  KST::dataSourceList.lock().readLock();
  KstDataSourcePtr ds = *KST::dataSourceList.findFileName(FileName->url());
  KST::dataSourceList.lock().readUnlock();

  delete _configWidget; // FIXME: very inefficient!!!!
  _configWidget = 0L;
  QStringList list;
  if (ds) {
    ds->readLock();
    list = ds->fieldList();
    Field->setEditable(!ds->fieldListIsComplete());
    _configWidget = ds->configWidget();
    ds->readUnlock();
  } else {
    QString type;
    bool complete = false;
    list = KstDataSource::fieldListForSource(FileName->url(), QString::null, &type, &complete);
    Field->setEditable(!complete);
    if (!list.isEmpty() && !type.isEmpty()) {
      _configWidget = KstDataSource::configWidgetForSource(FileName->url(), type);
    }
  }

  _configure->setEnabled(_configWidget);

  _fieldCompletion = Field->completionObject();

  Field->insertStringList(list);
  if (_fieldCompletion) {
    _fieldCompletion->clear();
    _fieldCompletion->insertItems(list);
  }
  if (!current_text.isEmpty() && (list.contains(current_text) || Field->editable())) {
    Field->setCurrentText(current_text);
  }
  _kstDataRange->setAllowTime(ds && ds->supportsTimeConversions());
}
Example #26
0
void KstMatrixDialog::updateCompletion() {
  KstDataSourcePtr ds;
  QString current_text = _w->_field->currentText();
  QStringList list;

  _w->_field->clear();

  //
  // update filename list and ll axes combo boxes...
  //

  KST::dataSourceList.lock().readLock();
// xxx  ds = *KST::dataSourceList.findReusableFileName(_w->_fileName->url());
  KST::dataSourceList.lock().unlock();

  delete _configWidget;
  _configWidget = 0L;

  if (ds) {
    ds->readLock();
    list = ds->matrixList();
    _w->_field->setEditable(!ds->fieldListIsComplete());
    _configWidget = ds->configWidget();
    ds->unlock();
    _w->_field->setEnabled(true);
    _w->_connect->hide();
  //  _kstDataRange->setAllowTime(ds->supportsTimeConversions());
  } else {
    bool complete = false;
    QString u;
    QString type;

/* xxx
    u = _w->_fileName->url();
    
    if (QFile::exists(u) && QFileInfo(u).isRelative()) {
      url.setPath(u);
    } else {
      url = QUrl(u);
    }

    if (!_inTest && !url.scheme()=="file" && url.scheme() != "file" && !url.isRelative()) {
      _w->_connect->show();
    } else if (url.isValid()) {
      list = KstDataSource::matrixListForSource(u, QString::null, &type, &complete);

      //
      // pretend we're getting the full field list...
      //

      if (list.isEmpty()) {
        QStringList fullList = KstDataSource::fieldListForSource(u, QString::null, &type, &complete);
      }

      if (!_inTest || (_inTest && !list.isEmpty())) {
        _w->_connect->hide();
      }
    }
*/
    _w->_field->setEditable(!complete);
    _w->_field->setEnabled(!list.isEmpty());
    if (!type.isEmpty()) {
      _configWidget = KstDataSource::configWidgetForSource(u, type);
    }
//    _kstDataRange->setAllowTime(KstDataSource::supportsTime(u, type));
  }

  _w->_configure->setEnabled(_configWidget);

// xxx  _fieldCompletion = _w->_field->completionObject();

  _w->_field->insertItems(0, list);
/* xxx
  if (_fieldCompletion) {
    _fieldCompletion->clear();
    _fieldCompletion->insertItems(list);
  }
*/

  if (!current_text.isEmpty() && (list.contains(current_text) || _w->_field->isEditable())) {
    _w->_field->setItemText(_w->_field->currentIndex(), current_text);
  }

  _ok->setEnabled(_w->_field->isEnabled() || _editMultipleMode);
}
Example #27
0
bool KstMatrixDialog::editSingleRMatrix(KstRMatrixPtr rmp) {
  KstDataSourcePtr file;
  QString pField;
  bool doSkip, doAve;
  int xStart;
  int yStart;
  int xNumSteps;
  int yNumSteps;
  int skip;

  if (_fileNameDirty) {
    KstDataSourceList::iterator it;

    //
    // if there is not an active KstFile, create one...
    //

    KST::dataSourceList.lock().writeLock();
// xxx    it = KST::dataSourceList.findReusableFileName(_w->_fileName->url());

    if (it == KST::dataSourceList.end()) {
// xxx      file = KstDataSource::loadSource(_w->_fileName->url());
      if (!file || !file->isValid()) {
        KST::dataSourceList.lock().unlock();
        QMessageBox::warning(this, QObject::tr("Kst"), QObject::tr("The file could not be opened."));

        return false;
      }

      if (file->isEmpty()) {
        KST::dataSourceList.lock().unlock();
        QMessageBox::warning(this, QObject::tr("Kst"), QObject::tr("The file does not contain data."));

        return false;
      }
      KST::dataSourceList.append(file);
    } else {
      file = *it;
    }
    KST::dataSourceList.lock().unlock();

    pField = _w->_field->currentText();
    if (!file->isValidMatrix(pField)) {
      QMessageBox::warning(this, QObject::tr("Kst"), QObject::tr("The requested field is not defined for the requested file."));
      file->unlock();

      return false;
    }
  } else {
    rmp->readLock();
    file = rmp->dataSource();
    pField = rmp->field();
    rmp->unlock();
  }

  rmp->readLock();

  if (_xStartDirty || _xStartCountFromEndDirty) {
    xStart = _w->_xStartCountFromEnd->isChecked() ? -1 : _w->_xStart->value();
  } else {
    xStart = rmp->reqXStart();
  }

  if (_yStartDirty || _yStartCountFromEndDirty) {
    yStart = _w->_yStartCountFromEnd->isChecked() ? -1 : _w->_yStart->value();
  } else {
    yStart = rmp->reqYStart();
  }

  if (_xNumStepsDirty || _xNumStepsReadToEndDirty) {
    xNumSteps = _w->_xNumStepsReadToEnd->isChecked() ? -1 : _w->_xNumSteps->value();
  } else {
    xNumSteps = rmp->reqXNumSteps();
  }

  if (_yNumStepsDirty || _yNumStepsReadToEndDirty) {
    yNumSteps = _w->_yNumStepsReadToEnd->isChecked() ? -1 : _w->_yNumSteps->value();
  } else {
    yNumSteps = rmp->reqYNumSteps();
  }

  if (_doSkipDirty) {
    doSkip = _w->_doSkip->isChecked();
  } else {
    doSkip = rmp->doSkip();
  }

  if (_doAveDirty) {
    doAve = _w->_doAve->isChecked();
  } else {
    doAve = rmp->doAverage();
  }

  if (_skipDirty) {
    skip = _w->_skip->value();
  } else {
    skip = rmp->skip();
  }

  rmp->unlock();

  rmp->writeLock();
  rmp->change(file, pField, KstObjectTag(rmp->tag().tag(), rmp->tag().context()), xStart, yStart, xNumSteps, yNumSteps, doAve, doSkip, skip);
  rmp->unlock();

  return true;
}
Example #28
0
bool KstMatrixDialog::new_IRMatrix() {
  KstDataSourcePtr file;
  KstRMatrixPtr matrix;
  KstDataSourceList::iterator it;
  QString pField;
  QString tagName;
  bool doSkip;
  bool doAve;
  int xStart = _w->_xStartCountFromEnd->isChecked() ? -1 : _w->_xStart->value();
  int yStart = _w->_yStartCountFromEnd->isChecked() ? -1 : _w->_yStart->value();
  int xNumSteps = _w->_xNumStepsReadToEnd->isChecked() ? -1 : _w->_xNumSteps->value();
  int yNumSteps = _w->_yNumStepsReadToEnd->isChecked() ? -1 : _w->_yNumSteps->value();
  int skip;

  //
  // create a unique name...
  //

  tagName = (_tagName->text() == "<New_Matrix>") ? KST::suggestMatrixName(_w->_field->currentText()) : _tagName->text();
  if (KstData::self()->matrixTagNameNotUnique(tagName)) {
    _tagName->setFocus();

    return false;
  }

  //
  // if there is not an active KstFile, create one...
  //

  KST::dataSourceList.lock().writeLock();
// xxx  it = KST::dataSourceList.findReusableFileName(_w->_fileName->url());

  if (it == KST::dataSourceList.end()) {
// xxx    file = KstDataSource::loadSource(_w->_fileName->url());
    if (!file || !file->isValid()) {
      KST::dataSourceList.lock().unlock();
      QMessageBox::warning(this, QObject::tr("Kst"), QObject::tr("The file could not be opened."));

      return false;
    }

    if (file->isEmpty()) {
      KST::dataSourceList.lock().unlock();
      QMessageBox::warning(this, QObject::tr("Kst"), QObject::tr("The file does not contain data."));

      return false;
    }
    KST::dataSourceList.append(file);
  } else {
    file = *it;
  }
  KST::dataSourceList.lock().unlock();

  pField = _w->_field->currentText();

  if (!file->isValidMatrix(pField)) {
    QMessageBox::warning(this, QObject::tr("Kst"), QObject::tr("The requested matrix is not defined for the requested file."));
    file->unlock();

    return false;
  }

  doSkip = _w->_doSkip->isChecked();
  doAve = _w->_doAve->isChecked();
  skip = _w->_skip->value();

  matrix = new KstRMatrix(file, pField, KstObjectTag(tagName, file->tag(), false),
                          xStart, yStart, xNumSteps, yNumSteps, doAve, doSkip, skip);

  emit matrixCreated(KstMatrixPtr(matrix));

  matrix = 0L; // drop the reference

  emit modified();

  return true;
}
Example #29
0
void KstMatrixDialog::fillFieldsForRMatrixEdit() {
  KstRMatrixPtr rmp;

  //
  // first hide/show the correct widgets...
  //

  _w->_readFromSource->setChecked(true);
  _w->_generateGradient->setChecked(false);
  _w->_dataSourceGroup->show();
  _w->_dataRangeGroup->show();
  _w->_gradientGroup->hide();
  _w->_scalingGroup->hide();

  rmp = kst_cast<KstRMatrix>(_dp);
  if (rmp) {
    rmp->readLock();
  
    //
    // fill in the list of fields...
    //

    _w->_field->clear();
/* xxx
    if (_fieldCompletion) {
      _fieldCompletion->clear();
    }
*/
    //
    // scope for iterator...
    //

    {
      KstDataSourcePtr tf;
      KstDataSourceList::iterator it;

      KST::dataSourceList.lock().readLock();
      it = KST::dataSourceList.findReusableFileName(rmp->filename());
      if (it != KST::dataSourceList.end()) {
        tf = *it;
        tf->readLock();
        _w->_field->insertItems(0, tf->matrixList());
/* xxx
        if (_fieldCompletion) {
          _fieldCompletion->insertItems(tf->matrixList());
        }
*/
        tf->unlock();
      } else {
        QStringList list;

// xxx        list = KstDataSource::matrixListForSource(_w->_fileName->url());
        _w->_field->insertItems(0, list);
/* xxx
        if (_fieldCompletion) {
          _fieldCompletion->insertItems(list);
        }
*/
      }
      KST::dataSourceList.lock().unlock();
    }

    _w->_field->setEnabled(_w->_field->count() > 0);
    _ok->setEnabled(_w->_field->isEnabled());
    _w->_field->setItemText(_w->_field->currentIndex(), rmp->field());
  
    //
    // fill in the other parameters...
    //

// xxx    _w->_fileName->setURL(rmp->filename());
  
    _w->_xStart->setValue(rmp->reqXStart());
    _w->_yStart->setValue(rmp->reqYStart());
    _w->_xNumSteps->setValue(rmp->reqXNumSteps());
    _w->_yNumSteps->setValue(rmp->reqYNumSteps());
  
    _w->_xStartCountFromEnd->setChecked(rmp->xCountFromEnd());
    _w->_yStartCountFromEnd->setChecked(rmp->yCountFromEnd());
    _w->_xNumStepsReadToEnd->setChecked(rmp->xReadToEnd());
    _w->_yNumStepsReadToEnd->setChecked(rmp->yReadToEnd());
  
    _w->_doSkip->setChecked(rmp->doSkip());
    _w->_skip->setValue(rmp->skip());
    _w->_doAve->setChecked(rmp->doAverage());
  
    rmp->unlock();
  }
}
Example #30
0
bool UpdateThread::doUpdates(bool force, bool *gotData) {
  KstObject::UpdateType U = KstObject::NO_CHANGE;

  _updatedCurves.clear(); // HACK

  if (gotData) {
    *gotData = false;
  }
  
#if UPDATEDEBUG > 0
  if (force) {
    qDebug() << "Forced update!" << endl;
  }
#endif

  _updateCounter++;
  if (_updateCounter < 1) {
    _updateCounter = 1; // check for wrap around
  }

#if UPDATEDEBUG > 2
  qDebug() << "UPDATE: counter=" << _updateCounter << endl;
#endif

  {
    // Must make a copy to avoid deadlock
    KstBaseCurveList cl;
    KstDataObjectList dol;
    kstObjectSplitList<KstDataObject, KstBaseCurve>(KST::dataObjectList, cl, dol);
    qSort(cl); 
    qSort(dol); 

    // Update all curves
    for (uint i = 0; i < cl.count(); ++i) {
      KstBaseCurvePtr bcp = cl[i];
      bcp->writeLock();
      assert(bcp.data());
#if UPDATEDEBUG > 1
      qDebug() << "updating curve: " << (void*)bcp << " - " << bcp->tagName() << endl;
#endif
      KstObject::UpdateType ut = bcp->update(_updateCounter);
      bcp->unlock();

      if (ut == KstObject::UPDATE) { // HACK
        _updatedCurves.append(bcp);
      }

      if (U != KstObject::UPDATE) {
        U = ut;
        if (U == KstObject::UPDATE) {
#if UPDATEDEBUG > 0
          qDebug() << "Curve " << bcp->tagName() << " said UPDATE" << endl;
#endif
        }
      }

      if (_done || (_paused && !force)) {
#if UPDATEDEBUG > 1
        qDebug() << "5 Returning from scan with U=" << (int)U << endl;
#endif
        return U == KstObject::UPDATE;
      }
    }

    // Update all data objects
    for (uint i = 0; i < dol.count(); ++i) {
      KstDataObjectPtr dp = dol[i];
      dp->writeLock();
      assert(dp.data());
#if UPDATEDEBUG > 1
      qDebug() << "updating data object: " << (void*)dp << " - " << dp->tagName() << endl;
#endif
      dp->update(_updateCounter);
      dp->unlock();

      if (_done || (_paused && !force)) {
#if UPDATEDEBUG > 1
        qDebug() << "5 Returning from scan with U=" << (int)U << endl;
#endif
        return U == KstObject::UPDATE;
      }
    }
  }

  // Update the files
  if (!_paused) { // don't update even if paused && force
    KST::dataSourceList.lock().readLock();
    unsigned cnt = KST::dataSourceList.count();
    for (uint i = 0; i < cnt; ++i) {
      KstDataSourcePtr dsp = KST::dataSourceList[i];

      dsp->writeLock();
      dsp->update(_updateCounter);
      dsp->unlock();

      if (_done) {
        KST::dataSourceList.lock().unlock();
        return false;
      }
    }
    KST::dataSourceList.lock().unlock();
  }

  if (KstScalar::scalarsDirty()) {
    KstScalar::clearScalarsDirty(); // Must do this first and take a risk of
                                    // falling slightly behind
    KST::scalarList.lock().readLock();
    KstScalarList sl = Q3DeepCopy<KstScalarList>(KST::scalarList.list()); // avoid deadlock on exit
    KST::scalarList.lock().unlock();
    for (KstScalarList::ConstIterator i = sl.begin(); i != sl.end(); ++i) {
      KstScalarPtr sp = *i;

      sp->writeLock();
      KstObject::UpdateType ut = sp->update(_updateCounter);
      sp->unlock();

      if (ut == KstObject::UPDATE) {
        U = KstObject::UPDATE;
      }

      if (_done) {
        return false;
      }
    }
  }

  if (U == KstObject::UPDATE) {
    qDebug() << "Update plots" << endl;
    if (gotData) { // FIXME: do we need to consider all the other exit points?
      *gotData = true;
    }
  }

#if UPDATEDEBUG > 1
  qDebug() << "6 Returning from scan with U=" << (int)U << endl;
#endif
  return U == KstObject::UPDATE;
}