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());
  }
}
Example #2
0
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);
  }
}
Example #3
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();
}
Example #4
0
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);
  }
}
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();
}