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;
}
Пример #2
0
bool KstPsdDialog::newObject() {
  QString tag_name = _tagName->text();
  bool retVal = false;

  if (tag_name == defaultTag) {
    tag_name = KST::suggestPSDName(KstObjectTag::fromString(_w->_vector->selectedVector()));
  }

  if (KstData::self()->dataTagNameNotUnique(tag_name)) {
    _tagName->setFocus();
    return false;
  }

  if (_w->_vector->selectedVector().isEmpty()) {
    QMessageBox::warning(this, QObject::tr("Kst"), QObject::tr("New spectrum not made: define vectors first."));
    return false;
  }

  KST::vectorList.lock().readLock();
  KstVectorPtr p = *KST::vectorList.findTag(_w->_vector->selectedVector());
  KST::vectorList.lock().unlock();

  if (_w->_kstFFTOptions->checkValues()) {
    if (p) {
      KstVCurvePtr vc;
      KstPSDPtr psd;
      QColor color;

      p->readLock();
      psd = new KstPSD(tag_name, p,
                       _w->_kstFFTOptions->SampRate->text().toDouble(),
                       _w->_kstFFTOptions->Interleaved->isChecked(),
                       _w->_kstFFTOptions->FFTLen->text().toInt(),
                       _w->_kstFFTOptions->Apodize->isChecked(),
                       _w->_kstFFTOptions->RemoveMean->isChecked(),
                       _w->_kstFFTOptions->VectorUnits->text(),
                       _w->_kstFFTOptions->RateUnits->text(),
                       ApodizeFunction(_w->_kstFFTOptions->ApodizeFxn->currentIndex()),
                       _w->_kstFFTOptions->Sigma->value(),
                       PSDType(_w->_kstFFTOptions->Output->currentIndex()));
      psd->setInterpolateHoles(_w->_kstFFTOptions->InterpolateHoles->isChecked());
      p->unlock();
  
// xxx      color = KstApp::inst()->chooseColorDlg()->getColorForCurve(psd->vX(), psd->vY());
      if (!color.isValid()) {
        color = _w->_curveAppearance->color();
      }

      vc = new KstVCurve(KST::suggestCurveName(psd->tag(),true), psd->vX(), psd->vY(), KstVectorPtr(), KstVectorPtr(), KstVectorPtr(), KstVectorPtr(), color);
      vc->setHasPoints(_w->_curveAppearance->showPoints());
      vc->setHasLines(_w->_curveAppearance->showLines());
      vc->setHasBars(_w->_curveAppearance->showBars());
      vc->setPointStyle(_w->_curveAppearance->pointType());
      vc->setLineWidth(_w->_curveAppearance->lineWidth());
      vc->setLineStyle(_w->_curveAppearance->lineStyle());
      vc->setBarStyle(_w->_curveAppearance->barStyle());
      vc->setPointDensity(_w->_curveAppearance->pointDensity());
  
      QString legend_text = _legendText->text();

      if (legend_text == defaultTag) {
        vc->setLegendText(QString::null);
      } else {
        vc->setLegendText(legend_text);
      }
  
      Kst2DPlotPtr plot;
      KstViewWindow *w;
/* xxx
      w = dynamic_cast<KstViewWindow*>(KstApp::inst()->findWindow(_w->_curvePlacement->_plotWindow->currentText()));
      if (!w) {
        QString n = KstApp::inst()->newWindow(KST::suggestWinName());
        w = static_cast<KstViewWindow*>(KstApp::inst()->findWindow(n));
      }
*/
      if (w) {
        if (_w->_curvePlacement->existingPlot()) {
          plot = kst_cast<Kst2DPlot>(w->view()->findChild(_w->_curvePlacement->plotName()));
          if (plot) {
            plot->addCurve(vc);
          }
        }
  
        if (_w->_curvePlacement->newPlot()) {
          QString name = w->createPlot(KST::suggestPlotName());

          if (_w->_curvePlacement->reGrid()) {
            w->view()->cleanup(_w->_curvePlacement->columns());
          }
          plot = kst_cast<Kst2DPlot>(w->view()->findChild(name));
          if (plot) {
            plot->setXAxisInterpretation(false, KstAxisInterpretation(), KstAxisDisplay());
            plot->setYAxisInterpretation(false, KstAxisInterpretation(), KstAxisDisplay());
            _w->_curvePlacement->update();
            _w->_curvePlacement->setCurrentPlot(plot->tagName());
            plot->addCurve(vc);
            plot->generateDefaultLabels();
          }
        }
      }
      KST::dataObjectList.lock().writeLock();
      KST::dataObjectList.append(psd);
      KST::dataObjectList.append(vc);
      KST::dataObjectList.lock().unlock();

      psd = 0L;
      vc = 0L;

      emit modified();

      retVal = true;
    }
  }

  return retVal;
}
Пример #3
0
bool KstHsDialog::newObject() {
  QString tag_name = _tagName->text();

  if (tag_name == defaultTag) {
    tag_name = KST::suggestHistogramName(KstObjectTag::fromString(_w->_vector->selectedVector()));
  }

  //
  // verify that the curve name is unique...
  //

  if (KstData::self()->dataTagNameNotUnique(tag_name)) {
    _tagName->setFocus();
    return false;
  }

  if (_w->_vector->selectedVector().isEmpty()) {
    QMessageBox::warning(this, QObject::tr("Kst"), QObject::tr("New Histogram not made: define vectors first."));
    return false;
  }

  //
  // find max and min...
  //

  double new_min = _w->Min->text().toDouble();
  double new_max = _w->Max->text().toDouble();

  if (new_max < new_min) {
    double m = new_max;

    new_max = new_min;
    new_min = m;
  }

  if (new_max == new_min) {
    QMessageBox::warning(this, QObject::tr("kst"), QObject::tr("Max and Min can not be equal."));
    return false;
  }

  int new_n_bins = _w->N->text().toInt();
  if (new_n_bins < 1) {
    QMessageBox::warning(this, QObject::tr("kst"), QObject::tr("You must have one or more bins in a histogram."));
    return false;
  }

  KstHsNormType new_norm_mode;
  if (_w->NormIsPercent->isChecked()) {
    new_norm_mode = KST_HS_PERCENT;
  } else if (_w->NormIsFraction->isChecked()) {
    new_norm_mode = KST_HS_FRACTION;
  } else if (_w->PeakIs1->isChecked()) {
    new_norm_mode = KST_HS_MAX_ONE;
  } else {
    new_norm_mode = KST_HS_NUMBER;
  }

  KstHistogramPtr hs;

  KST::vectorList.lock().readLock();
  KstVectorPtr vp = *KST::vectorList.findTag(_w->_vector->selectedVector());
  KST::vectorList.lock().unlock();
  if (vp) {
    KstVCurvePtr vc;
    KstViewWindow *w;
    QColor color;

    vp->readLock();
    hs = new KstHistogram(tag_name, vp, new_min, new_max,
                          new_n_bins, new_norm_mode);
    vp->unlock();

    hs->setRealTimeAutoBin(_w->_realTimeAutoBin->isChecked());
  
// xxx    color = KstApp::inst()->chooseColorDlg()->getColorForCurve(hs->vX(), hs->vY());
    if (!color.isValid()) {
      color = _w->_curveAppearance->color();
    }
    vc = new KstVCurve(KST::suggestCurveName(hs->tag(), true), hs->vX(), hs->vY(), KstVectorPtr(), KstVectorPtr(), KstVectorPtr(), KstVectorPtr(), color);
  
    vc->setHasPoints(_w->_curveAppearance->showPoints());
    vc->setHasLines(_w->_curveAppearance->showLines());
    vc->setHasBars(_w->_curveAppearance->showBars());
    vc->setPointStyle(_w->_curveAppearance->pointType());
    vc->setLineWidth(_w->_curveAppearance->lineWidth());
    vc->setLineStyle(_w->_curveAppearance->lineStyle());
    vc->setBarStyle(_w->_curveAppearance->barStyle());
    vc->setPointDensity(_w->_curveAppearance->pointDensity());
  
    QString legendText = _legendText->text();

    if (legendText == defaultTag) {
      vc->setLegendText(QString(""));
    } else {
      vc->setLegendText(legendText);
    }
/* xxx  
    w = dynamic_cast<KstViewWindow*>(KstApp::inst()->findWindow(_w->_curvePlacement->_plotWindow->currentText()));
*/
    if (!w) {
      QString n = KstApp::inst()->newWindow(KST::suggestWinName());

// xxx      w = static_cast<KstViewWindow*>(KstApp::inst()->findWindow(n));
    }
    
    if (w) {
      Kst2DPlotPtr plot;
    
      if (_w->_curvePlacement->existingPlot()) {
        plot = kst_cast<Kst2DPlot>(w->view()->findChild(_w->_curvePlacement->plotName()));
        if (plot) {
          plot->addCurve(vc);
        }
      }
  
      if (_w->_curvePlacement->newPlot()) {
        QString name = w->createPlot(KST::suggestPlotName());

        if (_w->_curvePlacement->reGrid()) {
          w->view()->cleanup(_w->_curvePlacement->columns());
        }
        plot = kst_cast<Kst2DPlot>(w->view()->findChild(name));
        if (plot) {
          _w->_curvePlacement->update();
          _w->_curvePlacement->setCurrentPlot(plot->tagName());
          plot->addCurve(vc);
          plot->generateDefaultLabels();
        }
      }
    }
  
    KST::dataObjectList.lock().writeLock();
    KST::dataObjectList.append(hs);
    KST::dataObjectList.append(vc);
    KST::dataObjectList.lock().unlock();
  
    hs = 0L;
    vc = 0L;

    emit modified();
  }

  return true;
}
Пример #4
0
bool KstEqDialog::newObject() {
  QString tag_name = _tagName->text();
  QString etext = _w->_equation->text();

  etext.remove(QRegExp("[^a-zA-Z0-9\\(\\)\\+\\-\\*/\\%\\^\\|\\&\\!<>=_.]"));
  etext.replace(KstObjectTag::tagSeparator, KstObjectTag::tagSeparatorReplacement);
  if (etext.length() > 12) {
    etext.truncate(12);
    etext += "...";
  }

  if (tag_name == defaultTag) {
    tag_name = KST::suggestEQName(etext);
  }

  if (KstData::self()->dataTagNameNotUnique(tag_name)) {
    _tagName->setFocus();
    return false;
  }

  if (!checkEntries()) {
    return false;
  }

  KST::vectorList.lock().readLock();
  KstVectorPtr vp = *KST::vectorList.findTag(_w->_xVectors->selectedVector());
  if (vp) {
    KST::vectorList.lock().unlock();
  
    KstEquationPtr eq;

    eq = new KstEquation(tag_name, _w->_equation->text(), vp, _w->_doInterpolation->isChecked());
  
    if (!eq->isValid()) {
      QStringList::const_iterator i;
      QString strWarning = QObject::tr("There is an error in the equation you entered.\n");
  
      eq = 0L;
  
      for (i = Equation::errorStack.begin(); i != Equation::errorStack.end(); ++i) {
        strWarning += *i;
        strWarning += "\n";
      }
  
      QMessageBox::warning(this, QObject::tr("Kst"), strWarning);

      return false;
    }
  
    KstVCurvePtr vc;
    QColor color;

// xxx    color = KstApp::inst()->chooseColorDlg()->getColorForCurve(eq->vX(), eq->vY());
    if (!color.isValid()) {
      color = _w->_curveAppearance->color();
    }

    vc = new KstVCurve(KST::suggestCurveName(eq->tag(), true), eq->vX(), eq->vY(), KstVectorPtr(), KstVectorPtr(), KstVectorPtr(), KstVectorPtr(), color);
    vc->setHasPoints(_w->_curveAppearance->showPoints());
    vc->setHasLines(_w->_curveAppearance->showLines());
    vc->setHasBars(_w->_curveAppearance->showBars());
    vc->setLineWidth(_w->_curveAppearance->lineWidth());
    vc->setLineStyle(_w->_curveAppearance->lineStyle());
    vc->setPointStyle(_w->_curveAppearance->pointType());
    vc->setPointDensity(_w->_curveAppearance->pointDensity());
    vc->setBarStyle(_w->_curveAppearance->barStyle());
  
    QString legend_text = _legendText->text();
    if (legend_text == defaultTag) {
      vc->setLegendText(QString(""));
    } else {
      vc->setLegendText(legend_text);
    }
  
    KstViewWindow *w;
/* xxx
    w = dynamic_cast<KstViewWindow*>(KstApp::inst()->findWindow(_w->_curvePlacement->_plotWindow->currentText()));
    if (!w) {
      QString n = KstApp::inst()->newWindow(KST::suggestWinName());

      w = dynamic_cast<KstViewWindow*>(KstApp::inst()->findWindow(n));
    }
*/  
    if (w) {
      Kst2DPlotPtr plot;

      if (_w->_curvePlacement->existingPlot()) {
        plot = kst_cast<Kst2DPlot>(w->view()->findChild(_w->_curvePlacement->plotName()));
        if (plot) {
          plot->addCurve(vc);
        }
      }
  
      if (_w->_curvePlacement->newPlot()) {
        QString name = w->createPlot(KST::suggestPlotName());

        if (_w->_curvePlacement->reGrid()) {
          w->view()->cleanup(_w->_curvePlacement->columns());
        }
        plot = kst_cast<Kst2DPlot>(w->view()->findChild(name));
        if (plot) {
          _w->_curvePlacement->update();
          _w->_curvePlacement->setCurrentPlot(plot->tagName());
          plot->addCurve(vc);
          plot->generateDefaultLabels();
        }
      }
    }
  
    KST::dataObjectList.lock().writeLock();
    KST::dataObjectList.append(eq);
    KST::dataObjectList.append(vc);
    KST::dataObjectList.lock().unlock();
  
    //
    // drop the reference before we update...
    //

    eq = 0L; 
    vc = 0L;

    emit modified();
  }

  return true;
}