void KstPluginDialogI::updateForm() {
    KstSharedPtr<Plugin> plugin = PluginCollection::self()->plugin(_pluginList[_w->PluginCombo->currentItem()]);
    if (plugin) {
        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);
                    vs->update();
                }
            } else if ((*it)._type == Plugin::Data::IOValue::StringType) { // string
                QObject *field = _w->_pluginInputOutputFrame->child((*it)._name.latin1(), "StringSelector");
                assert(field);
                if (field) {
                    StringSelector *ss = static_cast<StringSelector*>(field);
                    ss->update();
                }
            } 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);
                    ss->update();
                }
            }
        }
    }
}
Exemple #2
0
void KstPluginDialogI::update(int new_index) {
  Q_UNUSED(new_index);
  
  QString selectedVector;
  QString selectedScalar;
  KstSharedPtr<Plugin> pPtr;
  
  pPtr = PluginCollection::self()->plugin(_pluginList[PluginCombo->currentItem()]);
  if( pPtr != NULL ) {
    const QValueList<Plugin::Data::IOValue>& itable = pPtr->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 = _frameWidget->child((*it)._name.latin1(), "VectorSelector");
        assert(field);
        if (field) {
          VectorSelector *vs = static_cast<VectorSelector*>(field);
          vs->update();
        }
      } else {
        QObject *field = _frameWidget->child((*it)._name.latin1(), "ScalarSelector");
        assert(field);
        if (field) {
          ScalarSelector *ss = static_cast<ScalarSelector*>(field);
          ss->update();
        }
      }
    }
  }
}
Exemple #3
0
int PluginCollection::unloadPlugin(const KstSharedPtr<Plugin> p) {
  if (!p.data()) {
    return -1;
  }

  QString key = p->data()._name;
  _plugins.remove(key);

  emit pluginUnloaded(key);

  return 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;
}
Exemple #5
0
bool KstPlugin::setPlugin(KstSharedPtr<Plugin> plugin) {
  kdDebug() << "KstPlugin::setPlugin" << endl;

  if (plugin == _plugin) {
    return true;
  }

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

  countScalarsAndVectors(plugin->data()._inputs, _inScalarCnt, _inArrayCnt);

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

  _outScalarCnt = 0;
  _outArrayCnt = 0;
  _outputVectors.clear();
  _outputScalars.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) {
      _outputVectors.insert((*it)._name, new KstVector);
      _outArrayCnt++;
    } else if ((*it)._type == Plugin::Data::IOValue::FloatType) {
      _outputScalars.insert((*it)._name, new KstScalar);
      _outScalarCnt++;
    }
  }

  _plugin = plugin;
  return true;
}
Exemple #6
0
bool KstPluginDialogI::saveOutputs(KstPluginPtr plugin, KstSharedPtr<Plugin> p) {
  const QValueList<Plugin::Data::IOValue>& otable = p->data()._outputs;

  for (QValueList<Plugin::Data::IOValue>::ConstIterator it = otable.begin(); it != otable.end(); ++it) {
    QObject *field = _frameWidget->child((*it)._name.latin1(), "QLineEdit");
    assert(field);

    QLineEdit *li = static_cast<QLineEdit*>(field);

    if (li->text().isEmpty()) {
      QString tagName = Select->currentText();
      if (tagName.endsWith(newPluginString)) {
        tagName = plugin->tagName();
      }
      li->setText(tagName+"-"+(*it)._name);
    }

    QString nt = li->text();
    if ((*it)._type == Plugin::Data::IOValue::TableType) {
      if (!KST::vectorTagNameNotUnique(nt, false)) {
        plugin->outputVectors()[(*it)._name]->setTagName(nt);
      } else if (plugin->outputVectors()[(*it)._name]->tagName() != nt) {
          while (KST::vectorTagNameNotUnique(nt, false)) {
            nt += "'";
          }
          plugin->outputVectors()[(*it)._name]->setTagName(nt);
      }
    } else if ((*it)._type == Plugin::Data::IOValue::FloatType) {
      if (!KST::vectorTagNameNotUnique(nt, false)) {
        plugin->outputScalars()[(*it)._name]->setTagName(nt);
      } else if (plugin->outputScalars()[(*it)._name]->tagName() != nt) {
          while (KST::vectorTagNameNotUnique(nt, false)) {
            nt += "'";
          }
          plugin->outputScalars()[(*it)._name]->setTagName(nt);
      }
    }
  }

return true;
}
Exemple #7
0
bool KstPluginDialogI::saveInputs(KstPluginPtr plugin, KstSharedPtr<Plugin> p) {
  KST::vectorList.lock().readLock();
  KST::scalarList.lock().readLock();
  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 = _frameWidget->child((*it)._name.latin1(), "VectorSelector");
      assert(field);
      VectorSelector *vs = static_cast<VectorSelector*>(field);
      KstVectorPtr v = *KST::vectorList.findTag(vs->selectedVector());
      plugin->inputVectors().insert((*it)._name, v);
    } else {
      QObject *field = _frameWidget->child((*it)._name.latin1(), "ScalarSelector");
      assert(field);
      ScalarSelector *ss = static_cast<ScalarSelector*>(field);
      KstScalarPtr s = *KST::scalarList.findTag(ss->selectedScalar());
      plugin->inputScalars().insert((*it)._name, s);
    }
  }
  KST::scalarList.lock().readUnlock();
  KST::vectorList.lock().readUnlock();
return true;
}
Exemple #8
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, this, true);
      } else {
        v = new KstVector(QString::null, 0, this, false);
      }
      v->KstObject::writeLock();
      _outputVectors.insert((*it)._name, v);
      ++_outArrayCnt;
      KST::addVectorToList(v);
    } else if ((*it)._type == Plugin::Data::IOValue::FloatType) {
      KstScalarPtr s = new KstScalar(QString::null, this);
      s->KstObject::writeLock();
      _outputScalars.insert((*it)._name, s);
      ++_outScalarCnt;
    } else if ((*it)._type == Plugin::Data::IOValue::StringType) {
      KstStringPtr s = new KstString(QString::null, this);
      s->KstObject::writeLock();
      _outputStrings.insert((*it)._name, s);
      ++_outStringCnt;
    }
  }

  allocateParameters();
  _plugin = plugin;
  return true;
}
bool KstPluginDialogI::saveOutputs(KstCPluginPtr plugin, KstSharedPtr<Plugin> p) {
    const QValueList<Plugin::Data::IOValue>& otable = p->data()._outputs;

    for (QValueList<Plugin::Data::IOValue>::ConstIterator it = otable.begin(); it != otable.end(); ++it) {
        QObject *field = _w->_pluginInputOutputFrame->child((*it)._name.latin1(), "QLineEdit");
        if (!field) {
            continue; // Some are unsupported
        }

        QLineEdit *li = static_cast<QLineEdit*>(field);

        if (li->text().isEmpty()) {
            li->setText((*it)._name);
        }

        QString nt = li->text();
        if ((*it)._type == Plugin::Data::IOValue::TableType) {
            if (!KstData::self()->vectorTagNameNotUnique(nt, false)) {
                // Implicitly creates it if it doesn't exist
                KstVectorPtr v = plugin->outputVectors()[(*it)._name];
                if (!v) {
                    KstWriteLocker blockVectorUpdates(&KST::vectorList.lock());
                    v = new KstVector(KstObjectTag(nt, plugin->tag()), 0, plugin.data());
                    plugin->outputVectors().insert((*it)._name, v);
                }
                v->setTagName(KstObjectTag(nt, plugin->tag()));
            } else if (plugin->outputVectors()[(*it)._name]->tagName() != nt) {
                while (KstData::self()->vectorTagNameNotUnique(nt, false)) {
                    nt += "'";
                }
                KstVectorPtr v;
                if (plugin->outputVectors().contains((*it)._name)) {
                    v = plugin->outputVectors()[(*it)._name];
                } else {
                    KstWriteLocker blockVectorUpdates(&KST::vectorList.lock());
                    v = new KstVector(KstObjectTag(nt, plugin->tag()), 0, plugin.data());
                    plugin->outputVectors().insert((*it)._name, v);
                }
                v->setTagName(KstObjectTag(nt, plugin->tag()));
            }
        } else if ((*it)._type == Plugin::Data::IOValue::StringType) {
            if (!KstData::self()->vectorTagNameNotUnique(nt, false)) {
                KstStringPtr s;
                if (plugin->outputStrings().contains((*it)._name)) {
                    s = plugin->outputStrings()[(*it)._name];
                } else {
                    KstWriteLocker blockStringUpdates(&KST::stringList.lock());
                    s = new KstString(KstObjectTag(nt, plugin->tag()), plugin.data());
                    plugin->outputStrings().insert((*it)._name, s);
                }
                s->setTagName(KstObjectTag(nt, plugin->tag()));

            } else if (plugin->outputStrings()[(*it)._name]->tagName() != nt) {
                while (KstData::self()->vectorTagNameNotUnique(nt, false)) {
                    nt += "'";
                }
                KstStringPtr s;
                if (plugin->outputStrings().contains((*it)._name)) {
                    s = plugin->outputStrings()[(*it)._name];
                } else {
                    KstWriteLocker blockStringUpdates(&KST::stringList.lock());
                    s = new KstString(KstObjectTag(nt, plugin->tag()), plugin.data());
                    plugin->outputStrings().insert((*it)._name, s);
                }
                s->setTagName(KstObjectTag(nt, plugin->tag()));
            }
        } else if ((*it)._type == Plugin::Data::IOValue::PidType) {
            // Nothing
        } else if ((*it)._type == Plugin::Data::IOValue::FloatType) {
            if (!KstData::self()->vectorTagNameNotUnique(nt, false)) {
                KstScalarPtr s;
                if (plugin->outputScalars().contains((*it)._name)) {
                    s = plugin->outputScalars()[(*it)._name];
                } else {
                    KstWriteLocker blockScalarUpdates(&KST::scalarList.lock());
                    s = new KstScalar(KstObjectTag(nt, plugin->tag()), plugin.data());
                    plugin->outputScalars().insert((*it)._name, s);
                }
                s->setTagName(KstObjectTag(nt, plugin->tag()));
            } else if (plugin->outputScalars()[(*it)._name]->tagName() != nt) {
                while (KstData::self()->vectorTagNameNotUnique(nt, false)) {
                    nt += "'";
                }
                KstScalarPtr s;
                if (plugin->outputScalars().contains((*it)._name)) {
                    s = plugin->outputScalars()[(*it)._name];
                } else {
                    KstWriteLocker blockScalarUpdates(&KST::scalarList.lock());
                    s = new KstScalar(KstObjectTag(nt, plugin->tag()), plugin.data());
                    plugin->outputScalars().insert((*it)._name, s);
                }
                s->setTagName(KstObjectTag(nt, plugin->tag()));
            }
        }
    }

    return true;
}
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);
            }
        }
    }
}
Exemple #11
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;
}
bool KstCPlugin::setPlugin(KstSharedPtr<Plugin> plugin) {
  // Assumes that this is called with a write lock in place on this object
  Q_ASSERT(myLockStatus() == KstRWLock::WRITELOCKED);

  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) {
      KstWriteLocker blockVectorUpdates(&KST::vectorList.lock());
      KstVectorPtr v;

      if ((*it)._subType == Plugin::Data::IOValue::FloatNonVectorSubType) {
        v = new KstVector(KstObjectTag((*it)._name, tag()), 0, this, true);
      } else {
        v = new KstVector(KstObjectTag((*it)._name, tag()), 0, this, false);
      }
      _outputVectors.insert((*it)._name, v);
      ++_outArrayCnt;
    } else if ((*it)._type == Plugin::Data::IOValue::FloatType) {
      KstWriteLocker blockScalarUpdates(&KST::scalarList.lock());
      KstScalarPtr s = new KstScalar(KstObjectTag((*it)._name, tag()), this);
      _outputScalars.insert((*it)._name, s);
      ++_outScalarCnt;
    } else if ((*it)._type == Plugin::Data::IOValue::StringType) {
      KstWriteLocker blockStringUpdates(&KST::stringList.lock());
      KstStringPtr s = new KstString(KstObjectTag((*it)._name, tag()), this);
      _outputStrings.insert((*it)._name, s);
      ++_outStringCnt;
    }
  }

  allocateParameters();
  _plugin = plugin;

  return true;
}
Exemple #13
0
void KstPluginDialogI::updatePlugin(int new_index) {
  QString selectedVector;
  QString selectedScalar;
  int oldSelect = Select->currentItem();
  int oldCount = Select->count();

  KstPluginList pl = kstObjectSubList<KstDataObject, KstPlugin>(KST::dataObjectList);

  Select->clear();

  for (KstPluginList::iterator it = pl.begin(); it != pl.end(); ++it) {
    Select->insertItem((*it)->tagName());
  }

  if (new_index == -2 || Select->count() == 0) {
    Select->insertItem(i18n("P%1-%2").arg(Select->count()+1).arg(newPluginString));
    Select->setCurrentItem(Select->count()-1);
  } else if (new_index >= 0 && new_index < Select->count()) {
    Select->setCurrentItem(new_index);
  } else if (oldCount != Select->count()) {
    Select->setCurrentItem(Select->count()-1);
  } else {
    Select->setCurrentItem(oldSelect < Select->count() ? oldSelect : Select->count()-1);
  }

  if (_pluginList.isEmpty()) {
    updatePluginList();
  }

  KstPluginPtr plugin = pl[Select->currentItem()];
  if (!plugin) {
    kdWarning() << "Couldn't find plugin in list: " << Select->currentItem() << endl;
    return;
  }

  int oldPluginIndex = PluginCombo->currentItem();
  int newPluginIndex = _pluginList.findIndex(plugin->plugin()->data()._name);
  bool updateCombos = (newPluginIndex != oldPluginIndex);

  if (updateCombos) {
    PluginCombo->setCurrentItem(newPluginIndex);
    pluginChanged(PluginCombo->currentItem());
  }
  
  KstSharedPtr<Plugin> pPtr = PluginCollection::self()->plugin(_pluginList[PluginCombo->currentItem()]);
  if( pPtr != 0 ) {
    // Update input vector and scalar combos
    const QValueList<Plugin::Data::IOValue>& itable = pPtr->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 = _frameWidget->child((*it)._name.latin1(), "VectorSelector");
        assert(field);
        if (field) {
          VectorSelector *vs = static_cast<VectorSelector*>(field);
          selectedVector = vs->selectedVector();
          if (!updateCombos) {
            vs->update();
          }
          if (plugin.data() && plugin->isValid()) {
            vs->setSelection(plugin->inputVectors()[(*it)._name]->tagName());
          } else {
            vs->setSelection(selectedVector);
          }
        }
      } else {
        QObject *field = _frameWidget->child((*it)._name.latin1(), "ScalarSelector");
        assert(field);
        if (field) {
          ScalarSelector *ss = static_cast<ScalarSelector*>(field);
          selectedScalar = ss->selectedScalar( );
          if (!updateCombos) {
            ss->update();
          }
          if (plugin.data() && plugin->isValid()) {
            ss->setSelection(plugin->inputScalars()[(*it)._name]->tagName());
          } else {
            ss->setSelection(selectedScalar);
          }
        }
      }
    }
    
    // Update output vector and scalar lineedits
    //    const QValueList<Plugin::Data::IOValue>& otable = plugin->plugin()->data()._outputs;
    if (plugin.data() && plugin->isValid()) {
      const QValueList<Plugin::Data::IOValue>& otable = pPtr->data()._outputs;
      for (QValueList<Plugin::Data::IOValue>::ConstIterator it = otable.begin(); it != otable.end(); ++it) {
        QObject *field = _frameWidget->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 = plugin->outputVectors()[(*it)._name]->tagName();
          } else { // scalar
            ts = plugin->outputScalars()[(*it)._name]->tagName();
          }
          li->setText(ts);
        }
      }
    }
  } else { // invalid plugin
    PluginCollection *pc = PluginCollection::self();
    QString cur = _pluginList[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 = _frameWidget->child((*it)._name.latin1(), "QLineEdit");
      if (field) {
        static_cast<QLineEdit*>(field)->setText(QString::null);
      }
    }
  }

  QTimer::singleShot(0, this, SLOT(fixupLayout()));
}