QList<PlotItem*> PlotItemManager::plotsForView(View *view) {
  QList<QGraphicsItem*> graphics_items = view->scene()->items();
  QList<PlotItem *> plot_items;

  foreach(QGraphicsItem* graphics_item, graphics_items) {
    PlotItem *item = dynamic_cast<PlotItem*>(graphics_item);
    if (item && item->isVisible()) {
      plot_items.append(item);
    }
  }
Beispiel #2
0
ObjectPtr FilterFitDialog::createNewDataObject() {
    BasicPluginPtr dataObject = kst_cast<BasicPlugin>(DataObject::createPlugin(_filterFitTab->pluginName(), _document->objectStore(), _filterFitTab->configWidget()));
    Q_ASSERT(dataObject);

    if (!dataObject->isValid()) {
        _document->objectStore()->removeObject(dataObject);
        QString msg(tr("Unable to create Plugin Object using provided parameters.\n\n"));
        msg += dataObject->errorMessage();
        QMessageBox::warning(this, tr("Kst"), msg);

        return 0;
    }

    if(editMode()==New) {
        PlotItem *plotItem = 0;
        switch (_filterFitTab->curvePlacement()->place()) {
        case CurvePlacement::NoPlot:
            break;
        case CurvePlacement::ExistingPlot:
        {
            plotItem = static_cast<PlotItem*>(_filterFitTab->curvePlacement()->existingPlot());
            break;
        }
        case CurvePlacement::NewPlotNewTab:
            _document->createView();
        // fall through to case NewPlot.
        case CurvePlacement::NewPlot:
        {
            CreatePlotForCurve *cmd = new CreatePlotForCurve();
            cmd->createItem();

            plotItem = static_cast<PlotItem*>(cmd->item());
            if (_filterFitTab->curvePlacement()->scaleFonts()) {
                plotItem->view()->resetPlotFontSizes(plotItem);
                plotItem->view()->configurePlotFontDefaults(plotItem); // copy plots already in window
            }
            plotItem->view()->appendToLayout(_filterFitTab->curvePlacement()->layout(), plotItem,
                                             _filterFitTab->curvePlacement()->gridColumns());
            if (_filterFitTab->curvePlacement()->layout() == CurvePlacement::Custom) {
                plotItem->createCustomLayout(_filterFitTab->curvePlacement()->gridColumns());
            }
            break;
        }
        default:
            break;
        }

        if (plotItem) {
            CurvePtr curve = _document->objectStore()->createObject<Curve>();
            Q_ASSERT(curve);

            if (!_vectorX) {
                setVectorX(dataObject->inputVectors().value(dataObject->inputVectorList().first()));
            }
            Q_ASSERT(_vectorX);
            curve->setXVector(_vectorX);

            VectorPtr yVector = dataObject->outputVectors().value(dataObject->outputVectorList().first());
            Q_ASSERT(yVector);
            curve->setYVector(yVector);

            curve->setColor(_filterFitTab->curveAppearance()->color());
            curve->setHasPoints(_filterFitTab->curveAppearance()->showPoints());
            curve->setHasLines(_filterFitTab->curveAppearance()->showLines());
            curve->setHasBars(_filterFitTab->curveAppearance()->showBars());
            curve->setLineWidth(_filterFitTab->curveAppearance()->lineWidth());
            curve->setPointSize(_filterFitTab->curveAppearance()->pointSize());
            curve->setLineStyle(_filterFitTab->curveAppearance()->lineStyle());
            curve->setPointType(_filterFitTab->curveAppearance()->pointType());
            curve->setPointDensity(_filterFitTab->curveAppearance()->pointDensity());
            curve->setBarFillColor(_filterFitTab->curveAppearance()->barFillColor());

            curve->writeLock();
            curve->registerChange();
            curve->unlock();

            _filterFitTab->curveAppearance()->setWidgetDefaults();

            PlotRenderItem *renderItem = plotItem->renderItem(PlotRenderItem::Cartesian);
            renderItem->addRelation(kst_cast<Relation>(curve));

            dataObject->writeLock();
            dataObject->internalUpdate();
            dataObject->unlock();

            if (dataObject->hasParameterVector()) {
                CreateLabelCommand *cmd = new CreateLabelCommand;
                QString *tmpstring = new QString(dataObject->parameterVectorToString());

                cmd->createItem(tmpstring);
            }
            plotItem->update();

        }
    }

    _filterFitTab->configWidget()->save();

    return dataObject;
}
Beispiel #3
0
ObjectPtr CSDDialog::createNewDataObject() const {
  Q_ASSERT(_document && _document->objectStore());
  ObjectTag tag = _document->objectStore()->suggestObjectTag<CSD>(tagString(), ObjectTag::globalTagContext);
  CSDPtr csd = _document->objectStore()->createObject<CSD>(tag);
  csd->setVector(_CSDTab->vector());
  csd->setFreq(_CSDTab->FFTOptionsWidget()->sampleRate());
  csd->setAverage(_CSDTab->FFTOptionsWidget()->interleavedAverage());
  csd->setRemoveMean(_CSDTab->FFTOptionsWidget()->removeMean());
  csd->setApodize(_CSDTab->FFTOptionsWidget()->apodize());
  csd->setApodizeFxn(_CSDTab->FFTOptionsWidget()->apodizeFunction());
  csd->setWindowSize(_CSDTab->windowSize());
  csd->setLength(_CSDTab->FFTOptionsWidget()->FFTLength());
  csd->setGaussianSigma(_CSDTab->FFTOptionsWidget()->sigma());
  csd->setOutput(_CSDTab->FFTOptionsWidget()->output());
  csd->setVectorUnits(_CSDTab->FFTOptionsWidget()->vectorUnits());
  csd->setRateUnits(_CSDTab->FFTOptionsWidget()->rateUnits());

  csd->writeLock();
  csd->update(0);
  csd->unlock();

  Palette* newPalette = new Palette(_CSDTab->colorPalette()->selectedPalette());

  tag = _document->objectStore()->suggestObjectTag<Image>(csd->tag().tagString(), ObjectTag::globalTagContext);
  ImagePtr image = _document->objectStore()->createObject<Image>(tag);
  image->changeToColorOnly(csd->outputMatrix(), 0, 1, true, newPalette->paletteData());

  image->writeLock();
  image->update(0);
  image->unlock();

  PlotItem *plotItem = 0;
  switch (_CSDTab->curvePlacement()->place()) {
  case CurvePlacement::NoPlot:
    break;
  case CurvePlacement::ExistingPlot:
    {
      plotItem = static_cast<PlotItem*>(_CSDTab->curvePlacement()->existingPlot());
      break;
    }
  case CurvePlacement::NewPlot:
    {
      CreatePlotForCurve *cmd = new CreatePlotForCurve(
        _CSDTab->curvePlacement()->createLayout(),
        _CSDTab->curvePlacement()->appendToLayout());
      cmd->createItem();

      plotItem = static_cast<PlotItem*>(cmd->item());
      break;
    }
  default:
    break;
  }

  PlotRenderItem *renderItem = plotItem->renderItem(PlotRenderItem::Cartesian);
  //TODO  Adam, is this the correct way to draw an image?  It runs very slow.
  renderItem->addRelation(kst_cast<Relation>(image));
  plotItem->update();

  return ObjectPtr(image.data());
}
Beispiel #4
0
ObjectPtr PowerSpectrumDialog::createNewDataObject() const {
  Q_ASSERT(_document && _document->objectStore());
  ObjectTag tag = _document->objectStore()->suggestObjectTag<PSD>(tagString(), ObjectTag::globalTagContext);
  PSDPtr powerspectrum = _document->objectStore()->createObject<PSD>(tag);
  Q_ASSERT(powerspectrum);

  powerspectrum->setVector(_powerSpectrumTab->vector());
  powerspectrum->setFreq(_powerSpectrumTab->FFTOptionsWidget()->sampleRate());
  powerspectrum->setAverage(_powerSpectrumTab->FFTOptionsWidget()->interleavedAverage());
  powerspectrum->setLen(_powerSpectrumTab->FFTOptionsWidget()->FFTLength());
  powerspectrum->setApodize(_powerSpectrumTab->FFTOptionsWidget()->apodize());
  powerspectrum->setRemoveMean(_powerSpectrumTab->FFTOptionsWidget()->removeMean());
  powerspectrum->setVUnits(_powerSpectrumTab->FFTOptionsWidget()->vectorUnits());
  powerspectrum->setRUnits(_powerSpectrumTab->FFTOptionsWidget()->rateUnits());
  powerspectrum->setApodizeFxn(_powerSpectrumTab->FFTOptionsWidget()->apodizeFunction());
  powerspectrum->setGaussianSigma(_powerSpectrumTab->FFTOptionsWidget()->sigma());
  powerspectrum->setOutput(_powerSpectrumTab->FFTOptionsWidget()->output());
  powerspectrum->setInterpolateHoles(_powerSpectrumTab->FFTOptionsWidget()->interpolateOverHoles());

  powerspectrum->writeLock();
  powerspectrum->update(0);
  powerspectrum->unlock();

  //FIXME this should be a command...
  //FIXME need some smart placement...

  tag = _document->objectStore()->suggestObjectTag<Curve>(powerspectrum->tag().tagString(), ObjectTag::globalTagContext);
  CurvePtr curve = _document->objectStore()->createObject<Curve>(tag);
  Q_ASSERT(curve);

  curve->setXVector(powerspectrum->vX());
  curve->setYVector(powerspectrum->vY());
  curve->setColor(_powerSpectrumTab->curveAppearance()->color());
  curve->setHasPoints(_powerSpectrumTab->curveAppearance()->showPoints());
  curve->setHasLines(_powerSpectrumTab->curveAppearance()->showLines());
  curve->setHasBars(_powerSpectrumTab->curveAppearance()->showBars());
  curve->setLineWidth(_powerSpectrumTab->curveAppearance()->lineWidth());
  curve->setLineStyle(_powerSpectrumTab->curveAppearance()->lineStyle());
  curve->pointType = _powerSpectrumTab->curveAppearance()->pointType();
  curve->setPointDensity(_powerSpectrumTab->curveAppearance()->pointDensity());
  curve->setBarStyle(_powerSpectrumTab->curveAppearance()->barStyle());

  curve->writeLock();
  curve->update(0);
  curve->unlock();

  PlotItem *plotItem = 0;
  switch (_powerSpectrumTab->curvePlacement()->place()) {
  case CurvePlacement::NoPlot:
    break;
  case CurvePlacement::ExistingPlot:
    {
      plotItem = static_cast<PlotItem*>(_powerSpectrumTab->curvePlacement()->existingPlot());
      break;
    }
  case CurvePlacement::NewPlot:
    {
      CreatePlotForCurve *cmd = new CreatePlotForCurve(
        _powerSpectrumTab->curvePlacement()->createLayout(),
        _powerSpectrumTab->curvePlacement()->appendToLayout());
      cmd->createItem();

      plotItem = static_cast<PlotItem*>(cmd->item());
      break;
    }
  default:
    break;
  }

  PlotRenderItem *renderItem = plotItem->renderItem(PlotRenderItem::Cartesian);
  renderItem->addRelation(kst_cast<Relation>(curve));
  plotItem->update();

  return ObjectPtr(powerspectrum.data());
}