void KstPluginDialogI::fillFieldsForEdit() {
    KstCPluginPtr pp = kst_cast<KstCPlugin>(_dp);
    if (!pp) {
        return;
    }
    pp->readLock();
    if (!pp->plugin()) { // plugin() can be null if the kst file is invalid
        pp->unlock();
        return;
    }
    const QString pluginName(pp->tagName());
    const QString pluginObjectName(pp->plugin()->data()._name);
    const int usage = pp->getUsage();
    KstSharedPtr<Plugin> plug = pp->plugin();
    pp->unlock();

    _tagName->setText(pluginName);
    updatePluginList();

    int i = _pluginList.findIndex(pluginObjectName);
    _w->PluginCombo->setCurrentItem(i);
    pluginChanged(_w->PluginCombo->currentItem());

    fillVectorScalarCombos(plug);
    _w->PluginCombo->setEnabled(usage < 3);

    fixupLayout();
}
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;
}
Пример #3
0
void KstViewFitsDialog::fillComboBox(const QString& str) {
  KstCPluginList::iterator it;
  KstCPluginList fits;
  QString fitName = str;
  bool changed = false;
  uint i;

  _comboBoxFits->clear();
  fits = kstObjectSubList<KstDataObject,KstCPlugin>(KST::dataObjectList);

  for (it = fits.begin(); it != fits.end(); ++it) {
    KstCPluginPtr fit;

    fit = *it;
    fit->readLock();

    if (fit->plugin()->data()._isFit) {
      _comboBoxFits->insertItem(0, fit->tagName());
      if (fitName == fit->tagName() || fitName.isEmpty()) {
        _comboBoxFits->setCurrentIndex(_comboBoxFits->count() - 1);
        if (fitName.isEmpty()) {
          fitName = fit->tagName();
        }
        changed = true;
        fitChanged(fitName);
      }
    }

    fit->unlock();
  }

  if (!changed) {
    fitChanged(_comboBoxFits->currentText());
  }
}
Пример #4
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();
}