KstDataObjectPtr KstCPlugin::makeDuplicate(KstDataObjectDataObjectMap& duplicatedMap) {
  KstCPluginPtr plugin = new KstCPlugin;

  // use same inputs
  for (KstVectorMap::ConstIterator iter = _inputVectors.begin(); iter != _inputVectors.end(); ++iter) {
    plugin->inputVectors().insert(iter.key(), iter.data());
  }
  for (KstScalarMap::ConstIterator iter = _inputScalars.begin(); iter != _inputScalars.end(); ++iter) {
    plugin->inputScalars().insert(iter.key(), iter.data());  
  }
  for (KstStringMap::ConstIterator iter = _inputStrings.begin(); iter != _inputStrings.end(); ++iter) {
    plugin->inputStrings().insert(iter.key(), iter.data());  
  }

  // create new outputs
  for (KstVectorMap::ConstIterator iter = outputVectors().begin(); iter != outputVectors().end(); ++iter) {
    KstWriteLocker blockVectorUpdates(&KST::vectorList.lock());
    KstVectorPtr v = new KstVector(KstObjectTag(iter.data()->tag().tag() + "'", iter.data()->tag().context()), 0, plugin.data()); // FIXME: unique tag generation
    plugin->outputVectors().insert(iter.key(), v);
  }
  for (KstScalarMap::ConstIterator iter = outputScalars().begin(); iter != outputScalars().end(); ++iter) {
    KstScalarPtr s = new KstScalar(KstObjectTag(iter.data()->tag().tag() + "'", iter.data()->tag().context()), plugin.data()); // FIXME: unique tag generation
    plugin->outputScalars().insert(iter.key(), s);
  }
  for (KstStringMap::ConstIterator iter = outputStrings().begin(); iter != outputStrings().end(); ++iter) {
    KstStringPtr s = new KstString(KstObjectTag(iter.data()->tag().tag() + "'", iter.data()->tag().context()), plugin.data()); // FIXME: unique tag generation
    plugin->outputStrings().insert(iter.key(), s);
  }

  // set the same plugin
  plugin->setPlugin(_plugin);
  plugin->setTagName(KstObjectTag(tag().tag() + "'", tag().context())); // FIXME: unique tag generation method
  duplicatedMap.insert(this, KstDataObjectPtr(plugin));  
  return KstDataObjectPtr(plugin);
}
void doTests() {
  KstVectorPtr v1 = new KstVector(KstObjectTag("V1"), 15);
  doTest(v1->tagName() == "V1");
  doTest(v1->length() == 15);
  v1->zero();
  for (int i = 0; i < 15; ++i) {
    doTest(v1->value()[i] == 0);
  }
  doTest(!v1->isScalarList());
  v1->value()[0] = -42;
  v1->resize(3);
  doTest(v1->length() == 3);
  doTest(v1->value()[0] == -42);

  KstVectorPtr v2 = new KstVector(KstObjectTag(QString::null), 0);
  doTest(v2->length() == 1);
  doTest(v2->tagName().startsWith("Anonymous")); // valid only in en_*
  v2 = new KstVector(KstObjectTag("V2"), 1);
  doTest(v2->length() == 1);
  v2 = new KstVector(KstObjectTag("V2"), 2);
  doTest(v2->length() == 2);

  v2->resize(3);
  double *data = v2->value();
  data[0] = 1;
  data[1] = 2;
  data[2] = 3;
  doTest(v2->interpolate(0, 5) == 1);
  doTest(v2->interpolate(1, 5) == 1.5);
  doTest(v2->interpolate(2, 5) == 2);
  doTest(v2->interpolate(3, 5) == 2.5);
  doTest(v2->interpolate(4, 5) == 3);
}
void KstPSD::setTagName(const QString &in_tag) {
  KstObjectTag newTag(in_tag, tag().context());

  if (newTag == tag()) {
    return;
  }

  KstObject::setTagName(newTag);
  (*_sVector)->setTagName(KstObjectTag("sv", tag()));
  (*_fVector)->setTagName(KstObjectTag("freq", tag()));
}
KstPlotGroup::KstPlotGroup(const KstPlotGroup& plotGroup)
: KstMetaPlot(plotGroup) {
  _type = "PlotGroup";
  _container = false; // plot group is a container that doesn't behave like one

  setTagName(KstObjectTag(i18n("Plot Group %1").arg(++pgcount), KstObjectTag::globalTagContext));  // FIXME: tag context?
}
static KstRVector *GetOrCreateVector(const QString& field, KstDataSourcePtr file, InType &in) {
    int i_v = 0, n_v;
    KstRVector *V;
    KstRVectorList vectorList = kstObjectSubList<KstVector,KstRVector>(KST::vectorList);

    n_v = vectorList.count();

    for (i_v=0; i_v<n_v; i_v++) {
        V = *vectorList.at(i_v);
        if (V->field() == field && V->filename() == file->fileName()) {
            return V;
        }
    }

    V = new KstRVector(file, field, KstObjectTag(KST::suggestVectorName(field), file->tag(), false), in.f, in.n, in.skip, in.doskip, in.doave);
    if (!V->isValid()) {
        if (file->fileType() == "stdin") {
            startupErrors.append(i18n("Failed to create vector '%1' from file '%2'.  Trying again later.").arg(field).arg(file->fileName()));
        } else {
            startupErrors.append(i18n("Failed to create vector '%1' from file '%2'.").arg(field).arg(file->fileName()));
            V = 0L;
        }
    } else {
    }

    return V;
}
void KstCPlugin::createFitScalars() {
  Q_ASSERT(myLockStatus() == KstRWLock::WRITELOCKED);
  // Assumes that this is called with a write lock in place on this object

  if (_plugin->data()._isFit && _outputVectors.contains("Parameters")) {
    KstVectorPtr vectorParam = _outputVectors["Parameters"];
    if (vectorParam) {
      QString paramName;
      int i = 0;
      int length = vectorParam->length();

      KstWriteLocker blockScalarUpdates(&KST::scalarList.lock());
      KST::scalarList.setUpdateDisplayTags(false);
      for (paramName = _plugin->parameterName(i); 
          !paramName.isEmpty() && i < length; 
           paramName = _plugin->parameterName(++i)) {
        double scalarValue = vectorParam->value(i);
        if (!_outputScalars.contains(paramName)) {
          KstScalarPtr s = new KstScalar(KstObjectTag(paramName, tag()), this, scalarValue);
          s->KstObject::writeLock();  // must write lock, since fit scalars are created from update()
          _outputScalars.insert(paramName, s);
          ++_outScalarCnt;
        } else {
          _outputScalars[paramName]->setValue(scalarValue);
        }
      }
      KST::scalarList.setUpdateDisplayTags(true);
    }
  }
}
Beispiel #7
0
bool LFIIOSource::initFile( )
{
  KstObject::UpdateType updateType;
  bool                  bRetVal = false;
  int                   iResult = 0;

  _numFrames = 0;

  //
  // read the metadata
  //
  if( !_filename.isNull( ) && !_filename.isEmpty( ) )
  {
    QString   str;
    fitsfile* ffits;
    int       iStatus = 0;

    if( _first )
    {
      iResult = fits_open_table( &ffits, _filename.toAscii( ), READONLY, &iStatus );
      if( iResult == 0 )
      {
        int keysexist;
        int morekeys;

        iResult = fits_get_hdrspace( ffits, &keysexist, &morekeys, &iStatus );
        if( iResult == 0 )
        {
          char  keyname[FLEN_KEYWORD];
          char  value[FLEN_VALUE];
          char  comment[FLEN_COMMENT];
          int   keynum;

          for( keynum=1; keynum <= keysexist; ++keynum )
          {
            iResult = fits_read_keyn( ffits, keynum, keyname, value, comment, &iStatus );
            if( iResult == 0 )
            {
              KstString *metaString;

              str.sprintf( "%s %s", value, comment );
              metaString = new KstString( KstObjectTag( keyname, tag() ), this, str );
              _metaData.insert( keyname, *metaString );
            }
          }

          _first = false;
        }
      }
    }
  }

  updateType = update( );
  if( updateType == KstObject::UPDATE )
  {
    bRetVal = true;
  }

  return bRetVal;
}
Beispiel #8
0
bool KstHsDialogI::editObject() {
  KstHistogramList hsList = kstObjectSubList<KstDataObject,KstHistogram>(KST::dataObjectList);

  // if editing multiple objects, edit each one
  if (_editMultipleMode) {
    // if the user selected no vector, treat it as non-dirty
    _vectorDirty = _w->_vector->_vector->currentItem() != 0;
    _nDirty = _w->N->text() != " ";
    _minDirty = !_w->Min->text().isEmpty();
    _maxDirty = !_w->Max->text().isEmpty();

    bool didEdit = false;
    for (uint i = 0; i < _editMultipleWidget->_objectList->count(); i++) {
      if (_editMultipleWidget->_objectList->isSelected(i)) {
        // get the pointer to the object
        KstHistogramList::Iterator hsIter = hsList.findTag(_editMultipleWidget->_objectList->text(i));
        if (hsIter == hsList.end()) {
          return false;
        }

        KstHistogramPtr hsPtr = *hsIter;

        if (!editSingleObject(hsPtr)) {
          return false;
        }
        didEdit = true;
      }
    }
    if (!didEdit) {
      KMessageBox::sorry(this, i18n("Select one or more objects to edit."));
      return false;
    }
  } else {
    KstHistogramPtr hp = kst_cast<KstHistogram>(_dp);
    // verify that the curve name is unique
    QString tag_name = _tagName->text();
    if (!hp || (tag_name != hp->tagName() && KstData::self()->dataTagNameNotUnique(tag_name))) {
      _tagName->setFocus();
      return false;
    }
    hp->setTagName(KstObjectTag(tag_name, hp->tag().context())); // FIXME: doesn't allow changing tag context

    // then edit the object
    _vectorDirty = true;
    _minDirty = true;
    _maxDirty = true;
    _nDirty = true;
    _realTimeAutoBinDirty = true;
    _normIsPercentDirty = true;
    _normIsFractionDirty = true;
    _peakIs1Dirty = true;
    _normIsNumberDirty = true;
    if (!editSingleObject(hp)) {
      return false;
    }
  }
  emit modified();
  return true;
}
Beispiel #9
0
void EventMonitorEntry::commonConstructor(const QString &in_tag) {
  const int NS = 1;

  _numDone = 0;
  _isValid = false;
  _pExpression = 0L;

  _typeString = i18n("Event");
  _type = "Event";
  KstObject::setTagName(KstObjectTag::fromString(in_tag));

  KstVectorPtr xv = new KstVector(KstObjectTag("x", tag()), NS, this);
  _xVector = _outputVectors.insert(OUTXVECTOR, xv);

  KstVectorPtr yv = new KstVector(KstObjectTag("y", tag()), NS, this);
  _yVector = _outputVectors.insert(OUTYVECTOR, yv);
}
Beispiel #10
0
void KstEquation::commonConstructor(const QString& in_tag, const QString& in_equation) {
  _ns = 2;
  _pe = 0L;
  _typeString = i18n("Equation");
  _type = "Equation";
  KstObject::setTagName(KstObjectTag::fromString(in_tag));

  KstVectorPtr xv = new KstVector(KstObjectTag("xsv", tag()), 2, this);
  _xOutVector = _outputVectors.insert(XOUTVECTOR, xv);
    
  KstVectorPtr yv = new KstVector(KstObjectTag("sv", tag()), 2, this);
  _yOutVector = _outputVectors.insert(YOUTVECTOR, yv);

  _isValid = false;
  _numNew = _numShifted = 0;

  setEquation(in_equation);
}
bool KstPluginDialogI::editObject() {
    KstCPluginPtr pp = kst_cast<KstCPlugin>(_dp);
    if (!pp) { // something is dreadfully wrong - this should never happen
        return false;
    }

    KstWriteLocker pl(pp);

    if (_tagName->text() != pp->tagName() && KstData::self()->dataTagNameNotUnique(_tagName->text())) {
        _tagName->setFocus();
        return false;
    }

    pp->setTagName(KstObjectTag(_tagName->text(), KstObjectTag::globalTagContext));  // FIXME: tag context always global?

    int pitem = _w->PluginCombo->currentItem();
    KstSharedPtr<Plugin> pPtr = PluginCollection::self()->plugin(_pluginList[pitem]);

    pp->setRecursed(false);
    pp->inputVectors().clear();
    pp->inputScalars().clear();
    pp->inputStrings().clear();

    // Save the vectors and scalars
    if (!saveInputs(pp, pPtr)) {
        KMessageBox::sorry(this, i18n("There is an error in the inputs you entered."));
        return false;
    }

    if (pitem >= 0 && _w->PluginCombo->count() > 0) {
        pp->setPlugin(pPtr);
    }

    if (!saveOutputs(pp, pPtr)) {
        KMessageBox::sorry(this, i18n("There is an error in the outputs you entered."));
        return false;
    }

    if (!pp->isValid()) {
        KMessageBox::sorry(this, i18n("There is an error in the plugin you entered."));
        return false;
    }

    pp->setRecursed(false);
    if (pp->recursion()) {
        pp->setRecursed(true);
        KMessageBox::sorry(this, i18n("There is a recursion resulting from the plugin you entered."));
        return false;
    }

    pp->setDirty();

    emit modified();

    return true;
}
void KstCPlugin::setTagName(const QString &in_tag) {
  KstObjectTag newTag(in_tag, tag().context());

  if (newTag == tag()) {
    return;
  }

  KstObject::setTagName(newTag);

  for (KstVectorMap::Iterator iter = outputVectors().begin(); iter != outputVectors().end(); ++iter) {
    (*iter)->setTagName(KstObjectTag(iter.data()->tag().tag(), tag()));
  }
  for (KstScalarMap::Iterator iter = outputScalars().begin(); iter != outputScalars().end(); ++iter) {
    (*iter)->setTagName(KstObjectTag(iter.data()->tag().tag(), tag()));
  }
  for (KstStringMap::Iterator iter = outputStrings().begin(); iter != outputStrings().end(); ++iter) {
    (*iter)->setTagName(KstObjectTag(iter.data()->tag().tag(), tag()));
  }
}
KstPlotGroup::KstPlotGroup()
: KstMetaPlot("PlotGroup") {
  _standardActions |= Delete | Raise | Zoom | Lower | RaiseToTop | LowerToBottom;
  _layoutActions |= Delete | Copy | Raise | Lower | RaiseToTop | LowerToBottom | Rename | MoveTo;
  setTagName(KstObjectTag(i18n("Plot Group %1").arg(++pgcount), KstObjectTag::globalTagContext));  // FIXME: tag context?
  _type = "PlotGroup";
  setBorderColor(Qt::blue);
  _container = false; // plot group is a container that doesn't behave like one
  setTransparent(true);
  setBorderWidth(0);
}
void BinnedMap::setHitsMap(const QString &name) {
  QString tname;
  if (name.isEmpty()) {
    tname = i18n("hits map");
  } else {
    tname = name;
  }
  KstWriteLocker blockMatrixUpdates(&KST::matrixList.lock());
  KstMatrixPtr m = new KstMatrix(KstObjectTag(tname, tag()), this);
  _outputMatrices.insert(HITSMAP, m);
}
void CrossPowerSpectrum::setFrequency(const QString &name) {
  QString tname;
  if (name.isEmpty()) {
    tname = i18n("frequency");
  } else {
    tname = name;
  }
  KstWriteLocker blockVectorUpdates(&KST::vectorList.lock());
  KstVectorPtr v = new KstVector(KstObjectTag(tname, tag()), 0, this, false);
  _outputVectors.insert(FREQUENCY, v);
}
void CrossPowerSpectrum::setImaginary(const QString &name) {
  QString tname;
  if (name.isEmpty()) {
    tname = i18n("the imaginary part of a complex number", "imaginary");
  } else {
    tname = name;
  }
  KstWriteLocker blockVectorUpdates(&KST::vectorList.lock());
  KstVectorPtr v = new KstVector(KstObjectTag(tname, tag()), 0, this, false);
  _outputVectors.insert(IMAGINARY, v);
}
KstVector::KstVector(const QDomElement& e)
    : KstPrimitive(), _nsum(0), _scalars(11) {
    QByteArray qba;
    _v = 0L;
    _size = 0;
    int sz = INITSIZE;
    KstObjectTag in_tag = KstObjectTag::invalidTag;

    _editable = false;
    NumShifted = 0;
    NumNew = 0;
    _isScalarList = false;
    _saveable = false;
    _saveData = false;

    QDomNode n = e.firstChild();
    while (!n.isNull()) {
        QDomElement e = n.toElement();
        if (!e.isNull()) {
            if (e.tagName() == "tag") {
                in_tag = KstObjectTag::fromString(e.text());
            } else if (e.tagName() == "data") {
                QCString qcs(e.text().latin1());
                QByteArray qbca;
                KCodecs::base64Decode(qcs, qbca);
                qba = qUncompress(qbca);
                sz = kMax((size_t)(INITSIZE), qba.size()/sizeof(double));
            }
        }
        n = n.nextSibling();
    }

    if (!in_tag.isValid()) {
        QString nt = i18n("Anonymous Vector %1");

        do {
            KstObject::setTagName(KstObjectTag(nt.arg(anonymousVectorCounter++), in_tag.context()));
        } while (KstData::self()->vectorTagNameNotUnique(tagName(), false));
    } else {
        KstObject::setTagName(KST::suggestUniqueVectorTag(in_tag));
    }

    createScalars();
    resize(sz, true);

    if (!qba.isEmpty()) {
        _saveable = true;
        _saveData = true;
        QDataStream qds(qba, IO_ReadOnly);
        for (int i = 0; !qds.atEnd(); ++i) {
            qds >> _v[i];
        }
    }
bool KstFilterDialogI::newObject() {
  QString tagName = _tagName->text();

  if (KstData::self()->dataTagNameNotUnique(tagName, true, this)) {
    _tagName->setFocus();
    return false;
  } else {
    int pitem = _w->PluginCombo->currentItem();

    if (pitem >= 0 && _w->PluginCombo->count() > 0) {
      KstSharedPtr<Plugin> pPtr = PluginCollection::self()->plugin(_pluginList[pitem]);

      if (pPtr) {
        KstCPluginPtr plugin = new KstCPlugin;
        KstWriteLocker pl(plugin);
        plugin->setDirty();
        if (saveInputs(plugin, pPtr)) {
          if (tagName == plugin_defaultTag) {
            tagName = KST::suggestPluginName(_pluginList[pitem], KstObjectTag::fromString(_yvector));
          }

          plugin->setTagName(KstObjectTag(tagName, KstObjectTag::globalTagContext)); // FIXME: tag context always global?

          plugin->setPlugin(pPtr);

          if (saveOutputs(plugin, pPtr)) {
            if (plugin->isValid()) {
              if (!createCurve(plugin)) {
                KMessageBox::sorry(this, i18n("There is an error in the plugin you entered."));
                return false;
              } else {
                KST::dataObjectList.lock().writeLock();
                KST::dataObjectList.append(plugin.data());
                KST::dataObjectList.lock().unlock();
              }
            } else {
              KMessageBox::sorry(this, i18n("There is an error in the plugin you entered."));
              return false;
            }
          } else {
            KMessageBox::sorry(this, i18n("There is an error in the outputs you entered."));
            return false;
          }
        } else {
          KMessageBox::sorry(this, i18n("There is an error in the inputs you entered."));
          return false;
        }
      }
    }
    emit modified();
  }
  return true;
}
bool KstPluginDialogI::newObject() {
    QString tagName = _tagName->text();

    if (tagName != plugin_defaultTag && KstData::self()->dataTagNameNotUnique(tagName, true, this)) {
        _tagName->setFocus();
        return false;
    }
    KstCPluginPtr plugin;
    int pitem = _w->PluginCombo->currentItem();
    if (pitem >= 0 && _w->PluginCombo->count() > 0) {
        KstSharedPtr<Plugin> pPtr = PluginCollection::self()->plugin(_pluginList[pitem]);
        if (pPtr) {
            plugin = new KstCPlugin;
            KstWriteLocker pl(plugin);

            // set the tag name before any dependents are created
            if (tagName == plugin_defaultTag) {
                tagName = KST::suggestPluginName(_pluginList[pitem]);
            }
            plugin->setTagName(KstObjectTag(tagName, KstObjectTag::globalTagContext));

            if (!saveInputs(plugin, pPtr)) {
                KMessageBox::sorry(this, i18n("There is an error in the inputs you entered."));
                plugin = 0L;
                return false;
            }

            plugin->setPlugin(pPtr);

            if (!saveOutputs(plugin, pPtr)) {
                KMessageBox::sorry(this, i18n("There is an error in the outputs you entered."));
                plugin = 0L;
                return false;
            }
        }
    }

    if (!plugin || !plugin->isValid()) {
        KMessageBox::sorry(this, i18n("There is an error in the plugin you entered."));
        return false;
    }

    plugin->setDirty();
    KST::dataObjectList.lock().writeLock();
    KST::dataObjectList.append(plugin.data());
    KST::dataObjectList.lock().unlock();
    plugin = 0L;
    emit modified();

    return true;
}
Beispiel #20
0
KstDataSource::KstDataSource(QSettings *cfg, const QString& filename, const QString& type)
: KstObject(), _filename(filename), _cfg(cfg) {
  Q_UNUSED(type)
  _valid = false;
  _reusable = true;
  _writable = false;

  QString shortFilename = filename;
  while (shortFilename.at(shortFilename.length() - 1) == '/') {
    shortFilename.truncate(shortFilename.length() - 1);
  }
  shortFilename = shortFilename.section('/', -1);
  QString tn = QObject::tr("DS-%1").arg(shortFilename);
  int count = 1;

  KstObject::setTag(KstObjectTag(tn, KstObjectTag::globalTagContext));  // are DataSources always top-level?
  while (KstData::self()->dataSourceTagNameNotUnique(tagName(), false)) {
    KstObject::setTag(KstObjectTag(tn + QString("-%1").arg(count++), KstObjectTag::globalTagContext));  // are DataSources always top-level?
  }

  _numFramesScalar = new KstScalar(KstObjectTag("frames", tag()));
  // Don't set provider - this is always up-to-date
}
Beispiel #21
0
KstEquation::KstEquation(const QString& in_tag, const QString& equation, double x0, double x1, int nx)
: KstDataObject() {

  KstVectorPtr xvector;
  QString vtag = KST::suggestVectorName(QString( "(%1..%2)" ).arg( x0 ).arg( x1 ) );

  xvector = new KstSVector(x0, x1, nx, KstObjectTag(vtag, QStringList(in_tag)));

  _doInterp = false;
  _xInVector = _inputVectors.insert(XINVECTOR, xvector);

  commonConstructor(in_tag, equation);
  setDirty();
}
void KstPSD::commonConstructor(const QString& in_tag, KstVectorPtr in_V,
                               double in_freq, bool in_average, int in_averageLen, bool in_apodize, 
                               bool in_removeMean, const QString& in_VUnits, const QString& in_RUnits, 
                               ApodizeFunction in_apodizeFxn, double in_gaussianSigma, PSDType in_output,
                               bool interpolateHoles) {

  _typeString = i18n("Spectrum");
  _type = "PowerSpectrum";
  if (in_V) {
    _inputVectors[INVECTOR] = in_V;
  }
  KstObject::setTagName(KstObjectTag::fromString(in_tag));
  _Freq = in_freq;
  _Average = in_average;
  _Apodize = in_apodize;
  _apodizeFxn = in_apodizeFxn;
  _gaussianSigma = in_gaussianSigma;
  _prevOutput = PSDUndefined;
  _RemoveMean = in_removeMean;
  _vUnits = in_VUnits;
  _rUnits = in_RUnits;
  _Output = in_output;
  _interpolateHoles = interpolateHoles;
  _averageLen = in_averageLen;

  _last_n_subsets = 0;
  _last_n_new = 0;

  _PSDLen = 1;
  KstVectorPtr ov = new KstVector(KstObjectTag("freq", tag()), _PSDLen, this);
  _fVector = _outputVectors.insert(FVECTOR, ov);

  ov = new KstVector(KstObjectTag("sv", tag()), _PSDLen, this);
  _sVector = _outputVectors.insert(SVECTOR, ov);

  updateVectorLabels();
}
void KstBasicPlugin::load(const QDomElement &e) {
    QDomNode n = e.firstChild();

    while (!n.isNull()) {
        QDomElement e = n.toElement();
        if (!e.isNull()) {
            if (e.tagName() == "tag") {
                KstObject::setTagName(KstObjectTag::fromString(e.text()));
            } else if (e.tagName() == "ivector") {
                _inputVectorLoadQueue.append(qMakePair(e.attribute("name"), e.text()));
            } else if (e.tagName() == "iscalar") {
                _inputScalarLoadQueue.append(qMakePair(e.attribute("name"), e.text()));
            } else if (e.tagName() == "istring") {
                _inputStringLoadQueue.append(qMakePair(e.attribute("name"), e.text()));
            } else if (e.tagName() == "ovector") {
                KstWriteLocker blockVectorUpdates(&KST::vectorList.lock());
                KstVectorPtr v;
                if (e.attribute("scalarList", "0").toInt()) {
                    v = new KstVector(KstObjectTag(e.text(), tag()), 0, this, true);
                } else {
                    v = new KstVector(KstObjectTag(e.text(), tag()), 0, this, false);
                }
                _outputVectors.insert(e.attribute("name"), v);
            } else if (e.tagName() == "oscalar") {
                KstWriteLocker blockScalarUpdates(&KST::scalarList.lock());
                KstScalarPtr sp = new KstScalar(KstObjectTag(e.text(), tag()), this);
                _outputScalars.insert(e.attribute("name"), sp);
            } else if (e.tagName() == "ostring") {
                KstWriteLocker blockStringUpdates(&KST::stringList.lock());
                KstStringPtr sp = new KstString(KstObjectTag(e.text(), tag()), this);
                _outputStrings.insert(e.attribute("name"), sp);
            }
        }
        n = n.nextSibling();
    }
}
Beispiel #24
0
bool KstMatrixDialog::new_ISMatrix() {
  KstSMatrixPtr matrix;
  QString tagPart = _w->_gradientZAtMin->text() + "-" + _w->_gradientZAtMax->text();
  QString tagName = (_tagName->text() == "<New_Matrix>") ? KST::suggestMatrixName(tagPart) : _tagName->text();
  double zMin, zMax, xStep, yStep, minX, minY;
  bool xDirection, ok1, ok2, ok3, ok4, ok5, ok6;
  int nX, nY;

  if (KstData::self()->matrixTagNameNotUnique(tagName)) {
    _tagName->setFocus();

    return false;
  }

  xDirection = _w->_gradientX->isChecked();
  zMin = _w->_gradientZAtMin->text().toDouble(&ok1);
  zMax = _w->_gradientZAtMax->text().toDouble(&ok2);
  nX = _w->_nX->value();
  nY = _w->_nY->value();

  xStep = _w->_xStep->text().toDouble(&ok3);
  yStep = _w->_yStep->text().toDouble(&ok4);
  minX = _w->_minX->text().toDouble(&ok5);
  minY = _w->_minY->text().toDouble(&ok6);

  if (!checkParameters(ok3, ok4, ok5, ok6, xStep, yStep)) {
    return false;
  }

  if (!ok1 || !ok2) {
    QMessageBox::warning(this, QObject::tr("Kst"), QObject::tr("Invalid gradient bounds.  Ensure only decimal values are entered."));

    return false;
  }

  matrix = new KstSMatrix(KstObjectTag(tagName, KstObjectTag::globalTagContext),
      nX, nY, minX, minY, xStep, yStep, zMin, zMax, xDirection);

  emit matrixCreated(KstMatrixPtr(matrix));

  matrix = 0L; // drop the reference

  emit modified();

  return true;
}
Beispiel #25
0
void KstDataSource::setTag(const KstObjectTag& in_tag) {
  if (in_tag == tag()) {
    return;
  }

  KstObject::setTag(in_tag);
  _numFramesScalar->setTag(KstObjectTag("frames", tag()));

  QHash<QString, KstString>::iterator it;
  
  for (it=_metaData.begin(); it != _metaData.end(); ++it) {
    KstObjectTag stag = it->tag();

    stag.setContext(tag().fullTag());
    it->setTag(stag);
  }
}
KstString::KstString(KstObjectTag in_tag, KstObject *provider, const QString& val, bool orphan)
: KstPrimitive(provider), _value(val), _orphan(orphan), _editable(false) {
  QString _tag = in_tag.tag();
  if (!in_tag.isValid()) {
    QString nt = i18n("Anonymous String %1");

    do {
      _tag = nt.arg(anonymousStringCounter++);
    } while (KstData::self()->vectorTagNameNotUniqueInternal(_tag));  // FIXME: why vector?
    KstObject::setTagName(KstObjectTag(_tag, in_tag.context()));
  } else {
    KstObject::setTagName(KST::suggestUniqueStringTag(in_tag));
  }

  KST::stringList.lock().writeLock();
  KST::stringList.append(this);
  KST::stringList.lock().unlock();
}
Beispiel #27
0
/** Create the base scalar */
KstScalar::KstScalar(KstObjectTag in_tag, KstObject *provider, double val, bool orphan, bool displayable, bool editable)
: KstPrimitive(provider), _value(val), _orphan(orphan), _displayable(displayable), _editable(editable) {
  QString _tag = in_tag.tag();
  if (_tag.isEmpty()) {
    QString nt = QObject::tr("Anonymous Scalar %1");

    do {
      _tag = nt.arg(iAnonymousScalarCounter++);
    } while (KstData::self()->vectorTagNameNotUniqueInternal(_tag));  // FIXME: why vector?
    KstObject::setTag(KstObjectTag(_tag, in_tag.context()));
  } else {
    KstObject::setTag(KST::suggestUniqueScalarTag(in_tag));
  }


  KST::scalarList.lock().writeLock();
  KST::scalarList.append(this);
  KST::scalarList.lock().unlock();
}
/** Create a vector */
KstVector::KstVector(KstObjectTag in_tag, int size, KstObject *provider, bool isScalarList)
    : KstPrimitive(provider), _nsum(0), _scalars(isScalarList ? 0 : 11) {
    //kstdDebug() << "+++ CREATING VECTOR: " << (void*) this << endl;
    _editable = false;
    NumShifted = 0;
    NumNew = 0;
    _saveData = false;
    _isScalarList = isScalarList;

    _saveable = false;

    if (size <= 0) {
        size = INITSIZE;
    }

    if (!in_tag.isValid()) {
        QString nt = i18n("Anonymous Vector %1");

        do {
            KstObject::setTagName(KstObjectTag(nt.arg(anonymousVectorCounter++), in_tag.context()));
        } while (KstData::self()->vectorTagNameNotUnique(tagName(), false));
    } else {
        KstObject::setTagName(KST::suggestUniqueVectorTag(in_tag));
    }

    _v = static_cast<double*>(KST::malloc(size * sizeof(double)));
    if (!_v) { // Malloc failed
        _v = static_cast<double*>(KST::malloc(sizeof(double)));
        _size = 1;
    } else {
        _size = size;
    }
    _is_rising = false;

    createScalars();
    blank();

    KST::vectorList.lock().writeLock();
    KST::vectorList.append(this);
    KST::vectorList.lock().unlock();
}
KstPlotGroup::KstPlotGroup(const QDomElement& e)
: KstMetaPlot(e) {
  setBorderWidth(0);
  QDomNode n = e.firstChild();
  while (!n.isNull()) {
    QDomElement el = n.toElement();
    if (!el.isNull()) {
      if (metaObject()->findProperty(el.tagName().latin1(), true) > -1) {
        setProperty(el.tagName().latin1(), QVariant(el.text()));
      }
    }
    n = n.nextSibling();
  }

  // always have these values
  _standardActions |= Delete | Raise | Zoom | Lower | RaiseToTop | LowerToBottom;
  _layoutActions |= Delete | Copy | Raise | Lower | RaiseToTop | LowerToBottom | Rename | MoveTo;
  setTagName(KstObjectTag(i18n("Plot Group %1").arg(++pgcount), KstObjectTag::globalTagContext));  // FIXME: tag context?
  _type = "PlotGroup";
  _container = false; // plot group is a container that doesn't behave like one
  setBorderColor(Qt::blue);
}
void KstCSD::commonConstructor(const QString& in_tag, KstVectorPtr in_V, double in_freq, bool in_average, 
                                bool in_removeMean, bool in_apodize, ApodizeFunction in_apodizeFxn, int in_windowSize, 
                                int in_averageLength, double in_gaussianSigma, const QString& in_vectorUnits,
                                const QString& in_rateUnits, PSDType in_outputType, bool in_interpolateHoles,
                                const QString& vecName) {
  _typeString = i18n("Spectrogram");
  _type = "Spectrogram";
  _inputVectors[INVECTOR] = in_V;
  setTagName(KstObjectTag::fromString(in_tag));
  _frequency = in_freq;
  _average = in_average;
  _apodize = in_apodize;
  _windowSize = in_windowSize;
  _apodizeFxn = in_apodizeFxn;
  _gaussianSigma = in_gaussianSigma;
  _removeMean = in_removeMean;
  _averageLength = in_averageLength;
  _vectorUnits = in_vectorUnits;
  _rateUnits = in_rateUnits;
  _outputType = in_outputType;
  _interpolateHoles = in_interpolateHoles;

  if (_frequency <= 0.0) {
    _frequency = 1.0;
  }

  {
    KstWriteLocker blockMatrixUpdates(&KST::matrixList.lock());

    KstMatrixPtr outMatrix = new KstMatrix(KstObjectTag("csd", tag()), this, 1, 1);
    outMatrix->setLabel(i18n("Power [%1/%2^{1/2}]").arg(_vectorUnits).arg(_rateUnits));
    outMatrix->setXLabel(i18n("%1 [%2]").arg(vecName).arg(_vectorUnits));
    outMatrix->setYLabel(i18n("Frequency [%1]").arg(_rateUnits));
    _outMatrix = _outputMatrices.insert(OUTMATRIX, outMatrix);
  }

  updateMatrixLabels();
  (*_outMatrix)->setDirty();
}