Exemplo n.º 1
0
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();
}
Exemplo n.º 2
0
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();
  }
}
Exemplo n.º 3
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();
}
Exemplo n.º 4
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;
}
Exemplo n.º 5
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;
}