Пример #1
0
KstDataObjectPtr KstPlugin::makeDuplicate(KstDataObjectDataObjectMap& duplicatedMap) {
  KstPluginPtr plugin = new KstPlugin;

  // 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) {
    KstVectorPtr v = new KstVector;
    v->writeLock();
    plugin->outputVectors().insert(iter.key(), v);
    v->setTagName(iter.data()->tagName() + "'");
    v->setProvider(plugin.data());
    KST::addVectorToList(v);
    v->writeUnlock();
  }
  for (KstScalarMap::ConstIterator iter = outputScalars().begin(); iter != outputScalars().end(); ++iter) {
    KstScalarPtr s = new KstScalar;
    s->writeLock();
    plugin->outputScalars().insert(iter.key(), s);
    s->setTagName(iter.data()->tagName() + "'");
    s->setProvider(plugin.data());
    s->writeUnlock();
  }
  for (KstStringMap::ConstIterator iter = outputStrings().begin(); iter != outputStrings().end(); ++iter) {
    KstStringPtr s = new KstString;
    s->writeLock();
    plugin->outputStrings().insert(iter.key(), s);
    s->setTagName(iter.data()->tagName() + "'");
    s->setProvider(plugin.data());
    s->writeUnlock();  
  }
  
  // set the same plugin
  plugin->setPlugin(_plugin);
  plugin->setTagName(tagName() + "'");
  duplicatedMap.insert(this, KstDataObjectPtr(plugin));  
  return KstDataObjectPtr(plugin);
}
Пример #2
0
void KstEquation::commonConstructor(const QString& in_tag, const QString& in_equation) {
  _ns = 2;
  _pe = 0L;
  _typeString = i18n("Equation");
  _type = "Equation";
  KstObject::setTagName(in_tag);

  KstVectorPtr yv = new KstVector(tagName()+"-sv" , 2);
  KST::addVectorToList(yv);
  _yVector = _outputVectors.insert(OUTVECTOR, yv);
  yv->setProvider(this);

  _isValid = false;
  _numNew = _numShifted = 0;

  setEquation(in_equation);
}
Пример #3
0
bool KstPlugin::setPlugin(KstSharedPtr<Plugin> plugin) {
  // Assumes that this is called with a write lock in place on this object
  if (plugin == _plugin) {
    return true;
  }

  freeParameters();

  if (_localData) {
    if (!_plugin || !_plugin->freeLocalData(&_localData)) {
      free(_localData);
    }
    _localData = 0L;
  }

  if (!plugin) {
    _inputVectors.clear();
    _inputScalars.clear();
    _inputStrings.clear();
    _outputVectors.clear();
    _outputScalars.clear();
    _outputStrings.clear();
    _plugin = 0L;
    return true;
  }

  Plugin::countScalarsVectorsAndStrings(plugin->data()._inputs, _inScalarCnt, _inArrayCnt, _inStringCnt, _inPid);

  if (_inputVectors.count() != _inArrayCnt ||
      _inputScalars.count() != _inScalarCnt - _inPid ||
      _inputStrings.count() != _inStringCnt) {
    _plugin = 0L;
    return false;
  }

  _outScalarCnt = 0;
  _outArrayCnt = 0;
  _outStringCnt = 0;
  _outputVectors.clear();
  _outputScalars.clear();
  _outputStrings.clear();

  const QValueList<Plugin::Data::IOValue>& otable = plugin->data()._outputs;
  for (QValueList<Plugin::Data::IOValue>::ConstIterator it = otable.begin();
                                                         it != otable.end();
                                                                        ++it) {
    if ((*it)._type == Plugin::Data::IOValue::TableType) {
      KstVectorPtr v;

      if ((*it)._subType == Plugin::Data::IOValue::FloatNonVectorSubType) {
        v = new KstVector(QString::null, 0, true);
      } else {
        v = new KstVector;
      }
      v->writeLock();
      v->setProvider(this);
      _outputVectors.insert((*it)._name, v);
      _outArrayCnt++;
      KST::addVectorToList(v);
    } else if ((*it)._type == Plugin::Data::IOValue::FloatType) {
      KstScalarPtr s = new KstScalar;
      s->writeLock();
      s->setProvider(this);
      _outputScalars.insert((*it)._name, s);
      _outScalarCnt++;
    } else if ((*it)._type == Plugin::Data::IOValue::StringType) {
      KstStringPtr s = new KstString;
      s->writeLock();
      s->setProvider(this);
      _outputStrings.insert((*it)._name, s);
      _outStringCnt++;
    }
  }

  allocateParameters();
  _plugin = plugin;
  return true;
}
Пример #4
0
KstPlugin::KstPlugin(const QDomElement& e)
: KstDataObject(e) {
  QString pluginName;

  _inStringCnt = 0;
  _outStringCnt = 0;
  commonConstructor();

  QDomNode n = e.firstChild();

  while (!n.isNull()) {
    QDomElement e = n.toElement();
    if (!e.isNull()) {
      if (e.tagName() == "tag") {
        setTagName(e.text());
      } else if (e.tagName() == "name") {
        pluginName = 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") {
        KstVectorPtr v;
        if (e.attribute("scalarList", "0").toInt()) {
          v = new KstVector(e.text(), 0, true);
        } else {
          v = new KstVector(e.text(), 0, false);
        }
        v->setProvider(this);
        _outputVectors.insert(e.attribute("name"), v);
        KST::addVectorToList(v);
      } else if (e.tagName() == "oscalar") {
        KstScalarPtr sp = new KstScalar(e.text());
        sp->writeLock();
        sp->setProvider(this);
        sp->writeUnlock();
        _outputScalars.insert(e.attribute("name"), sp);
      } else if (e.tagName() == "ostring") {
        KstStringPtr sp = new KstString(e.text());
        sp->writeLock();
        sp->setProvider(this);
        sp->writeUnlock();
        _outputStrings.insert(e.attribute("name"), sp);
      }
    }
    n = n.nextSibling();
  }

  _plugin = PluginCollection::self()->plugin(pluginName);

  if (!_plugin.data()) {
    KstDebug::self()->log(i18n("Unable to load plugin %1 for \"%2\".").arg(pluginName).arg(tagName()), KstDebug::Warning);
  } else {
    Plugin::countScalarsVectorsAndStrings(_plugin->data()._inputs, _inScalarCnt, _inArrayCnt, _inStringCnt, _inPid);

    const QValueList<Plugin::Data::IOValue>& otable = _plugin->data()._outputs;
    for (QValueList<Plugin::Data::IOValue>::ConstIterator it = otable.begin();
                                                           it != otable.end();
                                                                         ++it) {
      // FIXME: i18n?
      if ((*it)._type == Plugin::Data::IOValue::TableType) {
        _outArrayCnt++;
        if (!_outputVectors.contains((*it)._name)) {
          KstVectorPtr v;

          if ((*it)._subType == Plugin::Data::IOValue::FloatNonVectorSubType) {
            v = new KstVector(tagName() + " vector - " + (*it)._name, 0, true);
          } else {
            v = new KstVector(tagName() + " vector - " + (*it)._name, 0, false);
          }
          v->setProvider(this);
          _outputVectors.insert((*it)._name, v);
          KST::addVectorToList(v);
        }
      } else if ((*it)._type == Plugin::Data::IOValue::MatrixType) {
          abort(); // FIXME:
#if 0
        _outArrayCnt += 2;
        if (!_outputMatrices.contains((*it)._name)) {
          KstMatrixPtr m;

          if ((*it)._subType == Plugin::Data::IOValue::FloatNonVectorSubType) {
            m = new KstMatrix(tagName() + " matrix - " + (*it)._name, 0, true);
          } else {
            m = new KstMatrix(tagName() + " matrix - " + (*it)._name, 0, false);
          }
          m->setProvider(this);
          _outputMatrices.insert((*it)._name, m);
          KST::addVectorToList(v);
        }
#endif
      } else if ((*it)._type == Plugin::Data::IOValue::FloatType) {
        _outScalarCnt++;
        if (!_outputScalars.contains((*it)._name)) {
          KstScalarPtr s = new KstScalar(tagName() + " scalar - " + (*it)._name);
          s->writeLock();
          s->setProvider(this);
          s->writeUnlock();
          _outputScalars.insert((*it)._name, s);
        }
      } else if ((*it)._type == Plugin::Data::IOValue::StringType) {
        _outStringCnt++;
        if (!_outputStrings.contains((*it)._name)) {
          KstStringPtr s = new KstString(tagName() + " string - " + (*it)._name);
          s->writeLock();
          s->setProvider(this);
          s->writeUnlock();
          _outputStrings.insert((*it)._name, s);
        }
      }
    }
    allocateParameters();
  }
}