コード例 #1
0
bool KstPluginDialogI::saveInputs(KstCPluginPtr plugin, KstSharedPtr<Plugin> p) {
    bool rc = true;

    const QValueList<Plugin::Data::IOValue>& itable = p->data()._inputs;
    for (QValueList<Plugin::Data::IOValue>::ConstIterator it = itable.begin(); it != itable.end(); ++it) {
        if ((*it)._type == Plugin::Data::IOValue::TableType) {
            QObject *field = _w->_pluginInputOutputFrame->child((*it)._name.latin1(), "VectorSelector");
            assert(field);
            VectorSelector *vs = static_cast<VectorSelector*>(field);
            KstReadLocker vl(&KST::vectorList.lock());
            KstVectorPtr v = *KST::vectorList.findTag(vs->selectedVector());
            if (v) {
                plugin->inputVectors().insert((*it)._name, v);
            } else if (plugin->inputVectors().contains((*it)._name)) {
                plugin->inputVectors().erase((*it)._name);
                rc = false;
            }
        } else if ((*it)._type == Plugin::Data::IOValue::StringType) {
            QObject *field = _w->_pluginInputOutputFrame->child((*it)._name.latin1(), "StringSelector");
            assert(field);
            StringSelector *ss = static_cast<StringSelector*>(field);
            KstWriteLocker sl(&KST::stringList.lock());
            KstStringPtr s = *KST::stringList.findTag(ss->selectedString());
            if (s == *KST::stringList.end()) {
                QString val = ss->_string->currentText();
                KstStringPtr newString = new KstString(KstObjectTag::fromString(ss->_string->currentText()), 0L, val, true);
                if (!newString) {
                    rc = false;
                }
                plugin->inputStrings().insert((*it)._name, newString);
            } else {
                plugin->inputStrings().insert((*it)._name, s);
            }
        } else if ((*it)._type == Plugin::Data::IOValue::PidType) {
            // Nothing
        } else if ((*it)._type == Plugin::Data::IOValue::FloatType) {
            QObject *field = _w->_pluginInputOutputFrame->child((*it)._name.latin1(), "ScalarSelector");
            assert(field);
            ScalarSelector *ss = static_cast<ScalarSelector*>(field);
            KstWriteLocker sl(&KST::scalarList.lock());
            KstScalarPtr s = *KST::scalarList.findTag(ss->selectedScalar());
            if (s == *KST::scalarList.end()) {
                bool ok;
                double val = ss->_scalar->currentText().toDouble(&ok);

                if (ok) {
                    KstScalarPtr newScalar = new KstScalar(KstObjectTag::fromString(ss->_scalar->currentText()), 0L, val, true, false);
                    plugin->inputScalars().insert((*it)._name, newScalar);
                } else {
                    rc = false;
                }
            } else {
                plugin->inputScalars().insert((*it)._name, s);
            }
        } else {
        }
    }

    return rc;
}
コード例 #2
0
bool KstPluginDialogI::editObject() {
  KstCPluginPtr pp = kst_cast<KstCPlugin>(_dp);
  if (!pp) { // something is dreadfully wrong - this should never happen
    return false;
  }

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

  pp->setTagName(_tagName->text());

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

  // Must unlock before clear()
  for (KstVectorMap::Iterator i = pp->inputVectors().begin(); i != pp->inputVectors().end(); ++i) {
    (*i)->unlock();
  }
  for (KstScalarMap::Iterator i = pp->inputScalars().begin(); i != pp->inputScalars().end(); ++i) {
    (*i)->unlock();
  }
  for (KstStringMap::Iterator i = pp->inputStrings().begin(); i != pp->inputStrings().end(); ++i) {
    (*i)->unlock();
  }
  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 plugin you entered."));
    pp->unlock();
    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 plugin you entered."));
    pp->unlock();
    return false;
  }

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

  emit modified();
  return true;
}
コード例 #3
0
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);
}
コード例 #4
0
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) {
    KstVectorPtr v = new KstVector(iter.data()->tagName() + "'", 0, plugin.data());
    plugin->outputVectors().insert(iter.key(), v);
    KST::addVectorToList(v);
  }
  for (KstScalarMap::ConstIterator iter = outputScalars().begin(); iter != outputScalars().end(); ++iter) {
    KstScalarPtr s = new KstScalar(iter.data()->tagName() + "'", plugin.data());
    plugin->outputScalars().insert(iter.key(), s);
  }
  for (KstStringMap::ConstIterator iter = outputStrings().begin(); iter != outputStrings().end(); ++iter) {
    KstStringPtr s = new KstString(iter.data()->tagName() + "'", plugin.data());
    plugin->outputStrings().insert(iter.key(), s);
  }
  
  // set the same plugin
  plugin->setPlugin(_plugin);
  plugin->setTagName(tagName() + "'");
  duplicatedMap.insert(this, KstDataObjectPtr(plugin));  
  return KstDataObjectPtr(plugin);
}
コード例 #5
0
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;
}
コード例 #6
0
void KstPluginDialogI::fillVectorScalarCombos(KstSharedPtr<Plugin> plugin) {
    bool DPvalid = false;
    KstCPluginPtr pp = kst_cast<KstCPlugin>(_dp);

    if (pp) {
        pp->readLock();
        DPvalid = pp->isValid();
        pp->unlock();
    }

    if (plugin) {
        if (DPvalid) {
            pp->readLock();
        }
        // Update input vector and scalar combos
        const QValueList<Plugin::Data::IOValue>& itable = plugin->data()._inputs;
        for (QValueList<Plugin::Data::IOValue>::ConstIterator it = itable.begin();
                it != itable.end(); ++it) {
            if ((*it)._type == Plugin::Data::IOValue::TableType) { // vector
                QObject *field = _w->_pluginInputOutputFrame->child((*it)._name.latin1(), "VectorSelector");
                assert(field);
                if (field) {
                    VectorSelector *vs = static_cast<VectorSelector*>(field);
                    QString selectedVector = vs->selectedVector();
                    vs->update();
                    if (DPvalid) {
                        vs->setSelection(pp->inputVectors()[(*it)._name]->tag().displayString());
                    } else {
                        vs->setSelection(selectedVector);
                    }
                }
            } else if ((*it)._type == Plugin::Data::IOValue::StringType) {
                QObject *field = _w->_pluginInputOutputFrame->child((*it)._name.latin1(), "StringSelector");
                assert(field);
                if (field) {
                    StringSelector *ss = static_cast<StringSelector*>(field);
                    QString selectedString = ss->selectedString();
                    ss->update();
                    if (DPvalid) {
                        ss->setSelection(pp->inputStrings()[(*it)._name]->tag().displayString());
                    } else {
                        ss->setSelection(selectedString);
                    }
                }
            } else if ((*it)._type == Plugin::Data::IOValue::PidType) {
                // Nothing
            } else {
                QObject *field = _w->_pluginInputOutputFrame->child((*it)._name.latin1(), "ScalarSelector");
                assert(field);
                if (field) {
                    ScalarSelector *ss = static_cast<ScalarSelector*>(field);
                    QString selectedScalar = ss->selectedScalar();
                    ss->update();
                    if (DPvalid) {
                        ss->setSelection(pp->inputScalars()[(*it)._name]->tag().displayString());
                    } else {
                        ss->setSelection(selectedScalar);
                    }
                }
            }
        }

        // Update output vector and scalar lineedits
        if (DPvalid) {
            const QValueList<Plugin::Data::IOValue>& otable = plugin->data()._outputs;
            for (QValueList<Plugin::Data::IOValue>::ConstIterator it = otable.begin(); it != otable.end(); ++it) {
                QObject *field = _w->_pluginInputOutputFrame->child((*it)._name.latin1(), "QLineEdit");
                assert(field);
                if (field) {
                    QLineEdit *li = static_cast<QLineEdit*>(field);
                    QString ts;
                    if ((*it)._type == Plugin::Data::IOValue::TableType) { // vector
                        ts = pp->outputVectors()[(*it)._name]->tagName();
                    } else if ((*it)._type == Plugin::Data::IOValue::PidType) {
                    } else if ((*it)._type == Plugin::Data::IOValue::StringType) {
                        ts = pp->outputStrings()[(*it)._name]->tagName();
                    } else { // scalar
                        ts = pp->outputScalars()[(*it)._name]->tagName();
                    }
                    li->setText(ts);
                }
            }
            pp->unlock();
        }
    } else { // invalid plugin
        PluginCollection *pc = PluginCollection::self();
        QString cur = _pluginList[_w->PluginCombo->currentItem()];
        Plugin::Data pdata = pc->pluginList()[pc->pluginNameList()[cur]];
        for (QValueList<Plugin::Data::IOValue>::ConstIterator it = pdata._outputs.begin(); it != pdata._outputs.end(); ++it) {
            QObject *field = _w->_pluginInputOutputFrame->child((*it)._name.latin1(), "QLineEdit");
            if (field) {
                static_cast<QLineEdit*>(field)->setText(QString::null);
            }
        }
    }
}
コード例 #7
0
bool KstFilterDialogI::saveInputs(KstCPluginPtr plugin, KstSharedPtr<Plugin> p) {
  KST::vectorList.lock().readLock();
  KST::scalarList.lock().writeLock();
  KST::stringList.lock().writeLock();
  const QValueList<Plugin::Data::IOValue>& itable = p->data()._inputs;
  for (QValueList<Plugin::Data::IOValue>::ConstIterator it = itable.begin(); it != itable.end(); ++it) {
    if ((*it)._type == Plugin::Data::IOValue::TableType) {
      if ((*it)._name == p->data()._filterInputVector) {
        KstVectorPtr v = *KST::vectorList.findTag(_yvector);
        plugin->inputVectors().insert((*it)._name, v);
      } else {
        QObject *field = _w->_pluginInputOutputFrame->child((*it)._name.latin1(), "VectorSelector");
        if (field) {
          VectorSelector *vs = static_cast<VectorSelector*>(field);
          KstVectorPtr v = *KST::vectorList.findTag(vs->selectedVector());
          plugin->inputVectors().insert((*it)._name, v);
        }
      }
    } else if ((*it)._type == Plugin::Data::IOValue::StringType) {
      QObject *field = _w->_pluginInputOutputFrame->child((*it)._name.latin1(), "StringSelector");
      if (field) {
        StringSelector *ss = static_cast<StringSelector*>(field);
        KstStringPtr s = *KST::stringList.findTag(ss->selectedString());
        if (s == *KST::stringList.end()) {
          QString val = ss->_string->currentText();
          // create orphan string
          KstStringPtr newString = new KstString(KstObjectTag(ss->_string->currentText(), KstObjectTag::orphanTagContext), 0L, val, true);
          plugin->inputStrings().insert((*it)._name, newString);
        } else {
          plugin->inputStrings().insert((*it)._name, s);
        }
      }
    } else if ((*it)._type == Plugin::Data::IOValue::PidType) {
      // Nothing
    } else {
      QObject *field = _w->_pluginInputOutputFrame->child((*it)._name.latin1(), "ScalarSelector");
      if (field) {
        ScalarSelector *ss = static_cast<ScalarSelector*>(field);
        KstScalarPtr s = *KST::scalarList.findTag(ss->selectedScalar());
        if (s == *KST::scalarList.end()) {
          bool ok;
          double val = ss->_scalar->currentText().toDouble(&ok);

          if (ok) {
            // create orphan scalar
            KstScalarPtr newScalar = new KstScalar(KstObjectTag(ss->_scalar->currentText(), KstObjectTag::orphanTagContext), 0L, val, true, false);
            plugin->inputScalars().insert((*it)._name, newScalar);
          } else {
            plugin->inputScalars().insert((*it)._name, s);
          }
        } else {
          plugin->inputScalars().insert((*it)._name, s);
        }
      }
    }
  }
  KST::stringList.lock().unlock();
  KST::scalarList.lock().unlock();
  KST::vectorList.lock().unlock();

  return true;
}