bool KstFilterDialogI::createCurve(KstCPluginPtr plugin) {
  KstVectorPtr xVector;
  KstVectorPtr yVector;

  KST::vectorList.lock().readLock();
  KstVectorList::Iterator it = KST::vectorList.findTag(_xvector);
  if (it != KST::vectorList.end()) {
    xVector = *it;
  }
  KST::vectorList.lock().unlock();

  if (plugin->outputVectors().contains(plugin->plugin()->data()._filterOutputVector)) {
    yVector = plugin->outputVectors()[plugin->plugin()->data()._filterOutputVector];
  }

  if (!xVector || !yVector) {
    return false;
  }
  plugin->setDirty();
  QString c_name = KST::suggestCurveName(plugin->tag(), true);
  QColor color = KstApp::inst()->chooseColorDlg()->getColorForCurve(KstVectorPtr(xVector), KstVectorPtr(yVector));
  if (!color.isValid()) {
    color = _w->_curveAppearance->color();
  }
  KstVCurvePtr fit = new KstVCurve(c_name, KstVectorPtr(xVector), KstVectorPtr(yVector), KstVectorPtr(0L), KstVectorPtr(0L), KstVectorPtr(0L), KstVectorPtr(0L), color);

  fit->setHasPoints(_w->_curveAppearance->showPoints());
  fit->setHasLines(_w->_curveAppearance->showLines());
  fit->setHasBars(_w->_curveAppearance->showBars());
  fit->setLineWidth(_w->_curveAppearance->lineWidth());
  fit->setLineStyle(_w->_curveAppearance->lineStyle());
  fit->setPointStyle(_w->_curveAppearance->pointType());
  fit->setBarStyle(_w->_curveAppearance->barStyle());
  fit->setPointDensity(_w->_curveAppearance->pointDensity());

  KstViewWindow *w = dynamic_cast<KstViewWindow*>(KstApp::inst()->findWindow(_window));
  if (w && w->view()->findChild(_plotName)) {
    Kst2DPlotPtr plot = kst_cast<Kst2DPlot>(w->view()->findChild(_plotName));
    if (plot) {
      plot->addCurve(fit.data());
    }
  }

  KST::dataObjectList.lock().writeLock();
  KST::dataObjectList.append(fit.data());
  KST::dataObjectList.lock().unlock();

  return true;
}
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);
}
示例#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) {
    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);
}
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);
            }
        }
    }
}
示例#6
0
void KstViewFitsDialog::fitChanged(const QString& strFit) {
  KstCPluginList fits;
  KstCPluginPtr plugin;
  double* params = 0L;
  double* covars = 0L;
  double chi2Nu = 0.0;
  int numParams = 0;
  int numCovars = 0;
  int i;

  fits = kstObjectSubList<KstDataObject,KstCPlugin>(KST::dataObjectList);
  plugin = *(fits.findTag(strFit));
  if (plugin) {
    KstScalarPtr scalarChi2Nu;
    KstVectorPtr vectorParam;
    plugin->readLock();

    const KstScalarMap& scalars = plugin->outputScalars();
    
    scalarChi2Nu = scalars["chi^2/nu"];
    if (scalarChi2Nu) {
      scalarChi2Nu->readLock();
      chi2Nu = scalarChi2Nu->value();
      scalarChi2Nu->unlock();
    }

    const KstVectorMap& vectors = plugin->outputVectors();
    vectorParam = vectors["Parameters"];

    if (vectorParam) {
      KstVectorPtr vectorCovar;

      vectorParam->readLock();
      vectorCovar = vectors["Covariance"];
      if (vectorCovar) {
        vectorCovar->readLock();
        numParams = vectorParam->length();
        numCovars = vectorCovar->length();

        if (numParams > 0 && numCovars > 0) {
          params = new double[numParams];
          covars = new double[numCovars];

          for (i = 0; i < numParams; i++) {
            params[i] = vectorParam->value(i);
          }

          for (i = 0; i < numCovars; i++) {
            covars[i] = vectorCovar->value(i);
          }
        }
        vectorCovar->unlock();
      }
      vectorParam->unlock();
    }
    plugin->unlock();
  }

  _tableFits->setParameters(params, numParams, covars, numCovars, chi2Nu);

  if (numParams > 0) {
    _tableFits->horizontalHeaderItem(0)->setText(QObject::tr("Value"));
    _tableFits->horizontalHeaderItem(1)->setText(QObject::tr("Covariance:"));

    _tableFits->verticalHeaderItem(numParams+0)->setText("---");
    _tableFits->verticalHeaderItem(numParams+1)->setText(QObject::tr("Chi^2/Nu"));

    if (plugin) {
      QExplicitlySharedDataPointer<Plugin> pluginBase;

      plugin->readLock();
      pluginBase = plugin->plugin();

      if (pluginBase) {
        textLabelFit->setText(pluginBase->data()._readableName);
        for (i = 0; i < numParams; i++) {
          QString parameterName = pluginBase->parameterName(i);
          _tableFits->horizontalHeaderItem(i+2)->setText(parameterName);
          _tableFits->verticalHeaderItem(i)->setText(parameterName);
        }
      }
      plugin->unlock();
    }
  }

  _tableFits->update();
}