void QgsVectorGradientColorRampV2Dialog::addPlotMarker( double x, double y, const QColor& color, bool isSelected )
{
  QColor borderColor = color.darker( 200 );
  borderColor.setAlpha( 255 );

  QColor brushColor = color;
  brushColor.setAlpha( 255 );

  QwtPlotMarker *marker = new QwtPlotMarker();
#if defined(QWT_VERSION) && QWT_VERSION>=0x060000
  marker->setSymbol( new QwtSymbol( QwtSymbol::Ellipse,  QBrush( brushColor ), QPen( borderColor, isSelected ? 2 : 1 ), QSize( 10, 10 ) ) );
#else
  marker->setSymbol( QwtSymbol( QwtSymbol::Ellipse,  QBrush( brushColor ), QPen( borderColor, isSelected ? 2 : 1 ), QSize( 10, 10 ) ) );
#endif
  marker->setValue( x, y );
  marker->attach( mPlot );
  marker->setRenderHint( QwtPlotItem::RenderAntialiased, true );
  mMarkers << marker;
}
/*!
  \brief Assign a symbol to a specified marker
  \param key Marker key
  \param s new symbol
  \return \c TRUE if the specified marker exists
*/
bool QwtPlot::setMarkerSymbol(long key, const QwtSymbol &s)
{
    int rv = FALSE;
    QwtPlotMarker *m;
    if ((m = d_markers->find(key)))
    {
        m->setSymbol(s);
        rv = TRUE;
    }
    return rv;
}
Esempio n. 3
0
void QgsCurveEditorWidget::addPlotMarker( double x, double y, bool isSelected )
{
  QColor borderColor( 0, 0, 0 );

  QColor brushColor = isSelected ? borderColor : QColor( 255, 255, 255, 0 );

  QwtPlotMarker *marker = new QwtPlotMarker();
  marker->setSymbol( new QwtSymbol( QwtSymbol::Ellipse,  QBrush( brushColor ), QPen( borderColor, isSelected ? 2 : 1 ), QSize( 8, 8 ) ) );
  marker->setValue( x, y );
  marker->attach( mPlot );
  marker->setRenderHint( QwtPlotItem::RenderAntialiased, true );
  mMarkers << marker;
}
void QgsGradientColorRampDialog::addPlotMarker( double x, double y, const QColor &color, bool isSelected )
{
  QColor borderColor = color.darker( 200 );
  borderColor.setAlpha( 255 );

  QColor brushColor = color;
  brushColor.setAlpha( 255 );

  QwtPlotMarker *marker = new QwtPlotMarker();
  marker->setSymbol( new QwtSymbol( QwtSymbol::Ellipse,  QBrush( brushColor ), QPen( borderColor, isSelected ? 2 : 1 ), QSize( 8, 8 ) ) );
  marker->setValue( x, y );
  marker->attach( mPlot );
  marker->setRenderHint( QwtPlotItem::RenderAntialiased, true );
  mMarkers << marker;
}
/*! 
   Reset color and fonts of a plot
   \sa QwtPlotPrintFilter::apply
*/
void QwtPlotPrintFilter::reset(QwtPlot *plot) const
{
    if ( d_cache == 0 )
        return;

    QFont *font;
    QColor *color;

    if ( plot->d_lblTitle )
    {
        QPalette palette = plot->d_lblTitle->palette();
        palette.setColor(
            QPalette::Active, QColorGroup::Foreground, d_cache->titleColor);
        plot->d_lblTitle->setPalette(palette);

        plot->d_lblTitle->setFont(d_cache->titleFont);
    }

    if ( plot->d_legend )
    {
        QIntDictIterator<QWidget> it = plot->d_legend->itemIterator();
        for ( QWidget *w = it.toFirst(); w != 0; w = ++it)
        {
            const int key = it.currentKey();

            font = d_cache->legendFonts.find(key);
            if ( font )
                w->setFont(*font);

            if ( w->inherits("QwtLegendButton") )
            {
                QwtLegendButton *btn = (QwtLegendButton *)w;

                QwtSymbol symbol = btn->symbol();
                color = d_cache->curveSymbolPenColors.find(key);
                if ( color )
                {
                    QPen pen = symbol.pen();
                    pen.setColor(*color);
                    symbol.setPen(pen);
                }

                color = d_cache->curveSymbolBrushColors.find(key);
                if ( color )
                {
                    QBrush brush = symbol.brush();
                    brush.setColor(*color);
                    symbol.setBrush(brush);
                }
                btn->setSymbol(symbol);

                color = d_cache->curveColors.find(key);
                if ( color )
                {
                    QPen pen = btn->curvePen();
                    pen.setColor(*color);
                    btn->setCurvePen(pen);
                }
            }
        }
    }
    for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
    {
        QwtScale *scale = plot->d_scale[axis];
        if ( scale )
        {
            QPalette palette = scale->palette();
            palette.setColor(QPalette::Active, QColorGroup::Foreground,
                             d_cache->scaleColor[axis]);
            scale->setPalette(palette);
            scale->setFont(d_cache->scaleFont[axis]);

            scale->setTitleColor(d_cache->scaleTitleColor[axis]);
            scale->setTitleFont(d_cache->scaleTitleFont[axis]);

            int startDist, endDist;
            scale->minBorderDist(startDist, endDist);
            scale->setBorderDist(startDist, endDist);
        }
    }

    plot->setBackgroundColor(d_cache->widgetBackground);
    plot->setCanvasBackground(d_cache->canvasBackground);

    QPen pen = plot->d_grid->majPen();
    pen.setColor(d_cache->gridColors[0]);
    plot->d_grid->setMajPen(pen);

    pen = plot->d_grid->minPen();
    pen.setColor(d_cache->gridColors[1]);
    plot->d_grid->setMinPen(pen);
    
    QIntDictIterator<QwtPlotCurve> itc(*plot->d_curves);
    for (QwtPlotCurve *c = itc.toFirst(); c != 0; c = ++itc )
    {
        const int key = itc.currentKey();

        QwtSymbol symbol = c->symbol();

        color = d_cache->curveSymbolPenColors.find(key);
        if ( color )
        {
            QPen pen = symbol.pen();
            pen.setColor(*color);
            symbol.setPen(pen);
        }

        color = d_cache->curveSymbolBrushColors.find(key);
        if ( color )
        {
            QBrush brush = symbol.brush();
            brush.setColor(*color);
            symbol.setBrush(brush);
        }
        c->setSymbol(symbol);

        color = d_cache->curveColors.find(key);
        if ( color )
        {
            QPen pen = c->pen();
            pen.setColor(*color);
            c->setPen(pen);
        }
    }

    QIntDictIterator<QwtPlotMarker> itm(*plot->d_markers);
    for (QwtPlotMarker *m = itm.toFirst(); m != 0; m = ++itm )
    {
        const int key = itm.currentKey();

        font = d_cache->markerFonts.find(key);
        if ( font )
            m->setFont(*font);

        color = d_cache->markerLabelColors.find(key);
        if ( color )
        {
            QPen pen = m->labelPen();
            pen.setColor(*color);
            m->setLabelPen(pen);
        }

        color = d_cache->markerLineColors.find(key);
        if ( color )
        {
            QPen pen = m->linePen();
            pen.setColor(*color);
            m->setLinePen(pen);
        }
        
        QwtSymbol symbol = m->symbol();

        color = d_cache->markerSymbolPenColors.find(key);
        if ( color )
        {
            QPen pen = symbol.pen();
            pen.setColor(*color);
            symbol.setPen(pen);
        }

        color = d_cache->markerSymbolBrushColors.find(key);
        if ( color )
        {
            QBrush brush = symbol.brush();
            brush.setColor(*color);
            symbol.setBrush(brush);
        }

        m->setSymbol(symbol);

    }

    QwtPlotPrintFilter *that = (QwtPlotPrintFilter *)this;
    delete that->d_cache;
    that->d_cache = 0;
}
/*! 
  Change color and fonts of a plot
  \sa QwtPlotPrintFilter::apply
*/
void QwtPlotPrintFilter::apply(QwtPlot *plot) const
{
    QwtPlotPrintFilter *that = (QwtPlotPrintFilter *)this;

    delete that->d_cache;
    that->d_cache = new QwtPlotPrintFilterCache;

    QwtPlotPrintFilterCache &cache = *that->d_cache;

    if ( plot->d_lblTitle )
    {
        QPalette palette = plot->d_lblTitle->palette();
        cache.titleColor = palette.color(
            QPalette::Active, QColorGroup::Foreground);
        palette.setColor(QPalette::Active, QColorGroup::Foreground,
                         color(cache.titleColor, Title));
        plot->d_lblTitle->setPalette(palette);

        cache.titleFont = plot->d_lblTitle->font();
        plot->d_lblTitle->setFont(font(cache.titleFont, Title));
    }
    if ( plot->d_legend )
    {
        QIntDictIterator<QWidget> it = plot->d_legend->itemIterator();
        for ( QWidget *w = it.toFirst(); w != 0; w = ++it)
        {
            const int key = it.currentKey();

            cache.legendFonts.insert(it.currentKey(), new QFont(w->font()));
            w->setFont(font(w->font(), Legend, key));

            if ( w->inherits("QwtLegendButton") )
            {
                QwtLegendButton *btn = (QwtLegendButton *)w;

                QwtSymbol symbol = btn->symbol();
                QPen pen = symbol.pen();
                QBrush brush = symbol.brush();

                pen.setColor(color(pen.color(), CurveSymbol, key));
                brush.setColor(color(brush.color(), CurveSymbol, key));

                symbol.setPen(pen);
                symbol.setBrush(brush);
                btn->setSymbol(symbol);

                pen = btn->curvePen();
                pen.setColor(color(pen.color(), Curve, key));
                btn->setCurvePen(pen);
            }
        }
    }
    for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
    {
        QwtScale *scale = plot->d_scale[axis];
        if ( scale )
        {
            cache.scaleColor[axis] = scale->palette().color(
                QPalette::Active, QColorGroup::Foreground);
            QPalette palette = scale->palette();
            palette.setColor(QPalette::Active, QColorGroup::Foreground,
                             color(cache.scaleColor[axis], AxisScale, axis));
            scale->setPalette(palette);

            cache.scaleFont[axis] = scale->font();
            scale->setFont(font(cache.scaleFont[axis], AxisScale, axis));

            cache.scaleTitleColor[axis] = scale->titleColor();
            scale->setTitleColor(
                color(cache.scaleTitleColor[axis], AxisTitle, axis));

            cache.scaleTitleFont[axis] = scale->titleFont();
            scale->setTitleFont(
                font(cache.scaleTitleFont[axis], AxisTitle, axis));

            int startDist, endDist;
            scale->minBorderDist(startDist, endDist);
            scale->setBorderDist(startDist, endDist);
        }
    }

    cache.widgetBackground = plot->backgroundColor();
    plot->setBackgroundColor(color(cache.widgetBackground, WidgetBackground));

    cache.canvasBackground = plot->canvasBackground();
    plot->setCanvasBackground(color(cache.canvasBackground, CanvasBackground));

    QPen pen = plot->d_grid->majPen();
    cache.gridColors[0] = pen.color();
    pen.setColor(color(pen.color(), MajorGrid));
    plot->d_grid->setMajPen(pen);

    pen = plot->d_grid->minPen();
    cache.gridColors[1] = pen.color();
    pen.setColor(color(pen.color(), MinorGrid));
    plot->d_grid->setMinPen(pen);
    
    QIntDictIterator<QwtPlotCurve> itc(*plot->d_curves);
    for (QwtPlotCurve *c = itc.toFirst(); c != 0; c = ++itc )
    {
        const int key = itc.currentKey();

        QwtSymbol symbol = c->symbol();

        QPen pen = symbol.pen();
        cache.curveSymbolPenColors.insert(key, new QColor(pen.color()));
        pen.setColor(color(pen.color(), CurveSymbol, key));
        symbol.setPen(pen);

        QBrush brush = symbol.brush();
        cache.curveSymbolBrushColors.insert(key, new QColor(brush.color()));
        brush.setColor(color(brush.color(), CurveSymbol, key));
        symbol.setBrush(brush);

        c->setSymbol(symbol);

        pen = c->pen();
        cache.curveColors.insert(key, new QColor(pen.color()));
        pen.setColor(color(pen.color(), Curve, key));
        c->setPen(pen);
    }

    QIntDictIterator<QwtPlotMarker> itm(*plot->d_markers);
    for (QwtPlotMarker *m = itm.toFirst(); m != 0; m = ++itm )
    {
        const int key = itm.currentKey();

        cache.markerFonts.insert(key, new QFont(m->font()));
        m->setFont(font(m->font(), Marker, key));

        QPen pen = m->labelPen();
        cache.markerLabelColors.insert(key, new QColor(pen.color()));
        pen.setColor(color(pen.color(), Marker, key));
        m->setLabelPen(pen);
        
        pen = m->linePen();
        cache.markerLineColors.insert(key, new QColor(pen.color()));
        pen.setColor(color(pen.color(), Marker, key));
        m->setLinePen(pen);

        QwtSymbol symbol = m->symbol();

        pen = symbol.pen();
        cache.markerSymbolPenColors.insert(key, new QColor(pen.color()));
        pen.setColor(color(pen.color(), MarkerSymbol, key));
        symbol.setPen(pen);

        QBrush brush = symbol.brush();
        cache.markerSymbolBrushColors.insert(key, new QColor(brush.color()));
        brush.setColor(color(brush.color(), MarkerSymbol, key));
        symbol.setBrush(brush);

        m->setSymbol(symbol);
    }
}
void QwtPlotPrintFilter::reset(QwtPlotItem *item) const
{
    if ( d_data->cache == 0 )
        return;

    const PrivateData::Cache &cache = *d_data->cache;

    switch(item->rtti())
    {
        case QwtPlotItem::Rtti_PlotGrid:
        {
            QwtPlotGrid *grid = (QwtPlotGrid *)item;

            QPen pen = grid->majPen();
            pen.setColor(cache.gridColors[0]);
            grid->setMajPen(pen);

            pen = grid->minPen();
            pen.setColor(cache.gridColors[1]);
            grid->setMinPen(pen);

            break;
        }
        case QwtPlotItem::Rtti_PlotCurve:
        {
            QwtPlotCurve *c = (QwtPlotCurve *)item;

            QwtSymbol symbol = c->symbol();

            if ( cache.curveSymbolPenColors.contains(c) )
            {
                symbol.setPen(cache.curveSymbolPenColors[c]);
            }

            if ( cache.curveSymbolBrushColors.contains(c) )
            {
                QBrush brush = symbol.brush();
                brush.setColor(cache.curveSymbolBrushColors[c]);
                symbol.setBrush(brush);
            }
            c->setSymbol(symbol);

            if ( cache.curveColors.contains(c) )
            {
                QPen pen = c->pen();
                pen.setColor(cache.curveColors[c]);
                c->setPen(pen);
            }

            break;
        }
        case QwtPlotItem::Rtti_PlotMarker:
        {
            QwtPlotMarker *m = (QwtPlotMarker *)item;

            if ( cache.markerFonts.contains(m) )
            {
                QwtText label = m->label();
                label.setFont(cache.markerFonts[m]);
                m->setLabel(label);
            }

            if ( cache.markerLabelColors.contains(m) )
            {
                QwtText label = m->label();
                label.setColor(cache.markerLabelColors[m]);
                m->setLabel(label);
            }

            if ( cache.markerLineColors.contains(m) )
            {
                QPen pen = m->linePen();
                pen.setColor(cache.markerLineColors[m]);
                m->setLinePen(pen);
            }
            
            QwtSymbol symbol = m->symbol();

            if ( cache.markerSymbolPenColors.contains(m) )
            {
                QPen pen = symbol.pen();
                pen.setColor(cache.markerSymbolPenColors[m]);
                symbol.setPen(pen);
            }

            if ( cache.markerSymbolBrushColors.contains(m) )
            {
                QBrush brush = symbol.brush();
                brush.setColor(cache.markerSymbolBrushColors[m]);
                symbol.setBrush(brush);
            }

            m->setSymbol(symbol);

            break;
        }
        default:
            break;
    }
}
void QwtPlotPrintFilter::apply(QwtPlotItem *item) const
{
    PrivateData::Cache &cache = *d_data->cache;

    switch(item->rtti())
    {
        case QwtPlotItem::Rtti_PlotGrid:
        {
            QwtPlotGrid *grid = (QwtPlotGrid *)item;

            QPen pen = grid->majPen();
            cache.gridColors[0] = pen.color();
            pen.setColor(color(pen.color(), MajorGrid));
            grid->setMajPen(pen);

            pen = grid->minPen();
            cache.gridColors[1] = pen.color();
            pen.setColor(color(pen.color(), MinorGrid));
            grid->setMinPen(pen);

            break;
        }
        case QwtPlotItem::Rtti_PlotCurve:
        {
            QwtPlotCurve *c = (QwtPlotCurve *)item;

            QwtSymbol symbol = c->symbol();

            QPen pen = symbol.pen();
            cache.curveSymbolPenColors.insert(c, pen.color());
            pen.setColor(color(pen.color(), CurveSymbol));
            symbol.setPen(pen);

            QBrush brush = symbol.brush();
            cache.curveSymbolBrushColors.insert(c, brush.color());
            brush.setColor(color(brush.color(), CurveSymbol));
            symbol.setBrush(brush);

            c->setSymbol(symbol);

            pen = c->pen();
            cache.curveColors.insert(c, pen.color());
            pen.setColor(color(pen.color(), Curve));
            c->setPen(pen);

            break;
        }
        case QwtPlotItem::Rtti_PlotMarker:
        {
            QwtPlotMarker *m = (QwtPlotMarker *)item;

            QwtText label = m->label();
            cache.markerFonts.insert(m, label.font());
            label.setFont(font(label.font(), Marker));
            cache.markerLabelColors.insert(m, label.color());
            label.setColor(color(label.color(), Marker));
            m->setLabel(label);
            
            QPen pen = m->linePen();
            cache.markerLineColors.insert(m, pen.color());
            pen.setColor(color(pen.color(), Marker));
            m->setLinePen(pen);

            QwtSymbol symbol = m->symbol();

            pen = symbol.pen();
            cache.markerSymbolPenColors.insert(m, pen.color());
            pen.setColor(color(pen.color(), MarkerSymbol));
            symbol.setPen(pen);

            QBrush brush = symbol.brush();
            cache.markerSymbolBrushColors.insert(m, brush.color());
            brush.setColor(color(brush.color(), MarkerSymbol));
            symbol.setBrush(brush);

            m->setSymbol(symbol);

            break;
        }
        default:    
            break;
    }
}
Esempio n. 9
0
void Nullcline::MakePlotItems()
{
#ifdef DEBUG_FUNC
    ScopeTracker st("Nullcline::MakePlotItems", std::this_thread::get_id());
#endif

    std::unique_lock<std::mutex> lock( Mutex() );
    if (_packets.empty()) return;
    while (_packets.size()>1)
    {
        delete _packets.front();
        _packets.pop_front();
    }
    Record* record = _packets.front();
    _packets.pop_front();
    if (!record) return;
    lock.unlock();

    ClearPlotItems();

    const size_t xidx = Spec_toi("xidx"),
            yidx = Spec_toi("yidx"),
            resolution2 = NumParserMgrs(),
            resolution = (int)sqrt(resolution2);

    const std::vector< std::pair<int,int> >& xcross_h = record->xcross_h,
            & xcross_v = record->xcross_v,
            & ycross_h = record->ycross_h,
            & ycross_v = record->ycross_v;
    const double* x = record->x,
            * y = record->y;
    const double xinc = record->xinc,
            yinc = record->yinc;

    const size_t xnum_pts_h = xcross_h.size(),
            xnum_pts_v = xcross_v.size(),
            ynum_pts_h = ycross_h.size(),
            ynum_pts_v = ycross_v.size();

    ReservePlotItems(xnum_pts_h + xnum_pts_v + ynum_pts_h + ynum_pts_v);

    const QColor& xcolor = _colors.at(xidx+1);
    for (size_t i=0; i<xnum_pts_h; ++i)
    {
        QwtSymbol *symbol = new QwtSymbol( QwtSymbol::Ellipse,
            QBrush(xcolor), QPen(xcolor, 2), QSize(5, 5) );
        QwtPlotMarker* marker = new QwtPlotMarker();
        marker->setSymbol(symbol);
        const int idx = xcross_h.at(i).first*resolution + xcross_h.at(i).second;
        marker->setXValue(x[idx] + xinc/2.0);
        marker->setYValue(y[idx]);
        marker->setZ(-1);
        AddPlotItem(marker);
    }
    for (size_t i=0; i<xnum_pts_v; ++i)
    {
        QwtSymbol *symbol = new QwtSymbol( QwtSymbol::Ellipse,
            QBrush(xcolor), QPen(xcolor, 2), QSize(5, 5) );
        QwtPlotMarker* marker = new QwtPlotMarker();
        marker->setSymbol(symbol);
        const int idx = xcross_v.at(i).first*resolution + xcross_v.at(i).second;
        marker->setXValue(x[idx]);
        marker->setYValue(y[idx] + yinc/2.0);
        marker->setZ(-1);
        AddPlotItem(marker);
    }

    QColor ycolor = _colors.at(yidx+1);
    for (size_t i=0; i<ynum_pts_h; ++i)
    {
        QwtSymbol *symbol = new QwtSymbol( QwtSymbol::Ellipse,
            QBrush(ycolor), QPen(ycolor, 2), QSize(5, 5) );
        QwtPlotMarker* marker = new QwtPlotMarker();
        marker->setSymbol(symbol);
        const int idx = ycross_h.at(i).first*resolution + ycross_h.at(i).second;
        marker->setXValue(x[idx] + xinc/2.0);
        marker->setYValue(y[idx]);
        marker->setZ(-1);
        AddPlotItem(marker);
    }
    for (size_t i=0; i<ynum_pts_v; ++i)
    {
        QwtSymbol *symbol = new QwtSymbol( QwtSymbol::Ellipse,
            QBrush(ycolor), QPen(ycolor, 2), QSize(5, 5) );
        QwtPlotMarker* marker = new QwtPlotMarker();
        marker->setSymbol(symbol);
        const int idx = ycross_v.at(i).first*resolution + ycross_v.at(i).second;
        marker->setXValue(x[idx]);
        marker->setYValue(y[idx] + yinc/2.0);
        marker->setZ(-1);
        AddPlotItem(marker);
    }

    DrawBase::Initialize(); //Have to wait on this, since we don't know how many objects there
        //are until the analysis is complete

    delete record;
}
Esempio n. 10
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RiuPvtPlotWidget::plotCurves(RiaEclipseUnitTools::UnitSystem unitSystem, const std::vector<RigFlowDiagSolverInterface::PvtCurve>& curveArr, double pressure, double pointMarkerYValue, QString pointMarkerLabel, QString plotTitle, QString yAxisTitle)
{
    m_qwtPlot->detachItems(QwtPlotItem::Rtti_PlotCurve);
    m_qwtPlot->detachItems(QwtPlotItem::Rtti_PlotMarker);
    m_qwtCurveArr.clear();
    m_pvtCurveArr.clear();
    m_trackerPlotMarker = nullptr;


    // Construct an auxiliary curve that connects the first point in all the input curves as a visual aid
    // This should only be shown when the phase being plotted is oil
    // Will not be added to our array of qwt curves since we do not expect the user to interact with it
    {
        std::vector<double> xVals;
        std::vector<double> yVals;
        for (size_t i = 0; i < curveArr.size(); i++)
        {
            const RigFlowDiagSolverInterface::PvtCurve& curve = curveArr[i];
            if (curve.phase == RigFlowDiagSolverInterface::PvtCurve::OIL && curve.pressureVals.size() > 0 && curve.yVals.size() > 0)
            {
                xVals.push_back(curve.pressureVals[0]);
                yVals.push_back(curve.yVals[0]);
            }
        }

        if (xVals.size() > 1)
        {
            QwtPlotCurve* qwtCurve = new QwtPlotCurve();
            qwtCurve->setSamples(xVals.data(), yVals.data(), static_cast<int>(xVals.size()));

            qwtCurve->setStyle(QwtPlotCurve::Lines);
            qwtCurve->setRenderHint(QwtPlotItem::RenderAntialiased, true);

            QColor curveClr = Qt::darkGreen;
            const QPen curvePen(curveClr);
            qwtCurve->setPen(curvePen);

            qwtCurve->attach(m_qwtPlot);
        }
    }


    // Add the primary curves
    for (size_t i = 0; i < curveArr.size(); i++)
    {
        const RigFlowDiagSolverInterface::PvtCurve& curve = curveArr[i];
        QwtPlotCurve* qwtCurve = new QwtPlotCurve();

        CVF_ASSERT(curve.pressureVals.size() == curve.yVals.size());
        qwtCurve->setSamples(curve.pressureVals.data(), curve.yVals.data(), static_cast<int>(curve.pressureVals.size()));

        qwtCurve->setStyle(QwtPlotCurve::Lines);

        QColor curveClr = Qt::magenta;
        if      (curve.phase == RigFlowDiagSolverInterface::PvtCurve::GAS)   curveClr = QColor(Qt::red);
        else if (curve.phase == RigFlowDiagSolverInterface::PvtCurve::OIL)   curveClr = QColor(Qt::green);
        const QPen curvePen(curveClr);
        qwtCurve->setPen(curvePen);

        qwtCurve->setRenderHint(QwtPlotItem::RenderAntialiased, true);

        QwtSymbol* curveSymbol = new QwtSymbol(QwtSymbol::Ellipse);
        curveSymbol->setSize(6, 6);
        curveSymbol->setPen(curvePen);
        curveSymbol->setBrush(Qt::NoBrush);
        qwtCurve->setSymbol(curveSymbol);

        qwtCurve->attach(m_qwtPlot);

        m_qwtCurveArr.push_back(qwtCurve);
    }

    m_pvtCurveArr = curveArr;
    CVF_ASSERT(m_pvtCurveArr.size() == m_qwtCurveArr.size());


    // Add vertical marker line to indicate cell pressure
    if (pressure != HUGE_VAL)
    {
        QwtPlotMarker* lineMarker = new QwtPlotMarker;
        lineMarker->setXValue(pressure);
        lineMarker->setLineStyle(QwtPlotMarker::VLine);
        lineMarker->setLinePen(QPen(QColor(128, 128, 255), 1, Qt::DashLine));
        lineMarker->setLabel(QString("PRESSURE"));
        lineMarker->setLabelAlignment(Qt::AlignTop | Qt::AlignRight);
        lineMarker->setLabelOrientation(Qt::Vertical);
        lineMarker->attach(m_qwtPlot);
    }

    // Then point marker
    if (pressure != HUGE_VAL && pointMarkerYValue != HUGE_VAL)
    {
        QwtPlotMarker* pointMarker = new QwtPlotMarker;
        pointMarker->setValue(pressure, pointMarkerYValue);

        QColor markerClr(128, 0, 255);
        QwtSymbol* symbol = new QwtSymbol(QwtSymbol::Ellipse);
        symbol->setSize(13, 13);
        symbol->setPen(QPen(markerClr, 2));
        symbol->setBrush(Qt::NoBrush);
        pointMarker->setSymbol(symbol);

        if (!pointMarkerLabel.isEmpty())
        {
            QwtText text(pointMarkerLabel);
            text.setRenderFlags(Qt::AlignLeft);
            text.setColor(markerClr);
            pointMarker->setLabel(text);
            pointMarker->setLabelAlignment(Qt::AlignTop | Qt::AlignRight);
        }

        pointMarker->attach(m_qwtPlot);
    }

    m_qwtPlot->setTitle(plotTitle);

    m_qwtPlot->setAxisTitle(QwtPlot::xBottom, QString("Pressure [%1]").arg(RiaEclipseUnitTools::unitStringPressure(unitSystem)));
    m_qwtPlot->setAxisTitle(QwtPlot::yLeft, yAxisTitle);

    updateTrackerPlotMarkerAndLabelFromPicker();

    m_qwtPlot->replot();
}
Esempio n. 11
0
MainWindow::MainWindow(QWidget *parent) :
  QMainWindow(parent),
  ui(new Ui::MainWindow),
  m_accelXPoints(100, QPointF(0, 0)), m_accelYPoints(100, QPointF(0, 0)),
  m_gyroXPoints(100, QPointF(0, 0)), m_gyroYPoints(100, QPointF(0, 0)),
  m_counter(0), m_power(0)
{
	ui->setupUi(this);

	// init scenes
	xScene = new QGraphicsScene();
	yScene = new QGraphicsScene();
	xScene->setBackgroundBrush(Qt::white);
	yScene->setBackgroundBrush(Qt::white);
	ui->xGraphicsView->setScene(xScene);
	ui->yGraphicsView->setScene(yScene);

	m_tcpSocket = new QTcpSocket(this);
	connect(m_tcpSocket, SIGNAL(readyRead()), this, SLOT(onTcpRead()));

	m_controlSocket = new QTcpSocket(this);
	connect(m_tcpSocket, SIGNAL(readyRead()), this, SLOT(onControlRead()));

	// connecting
	connect(ui->connectButton, SIGNAL(clicked()), this, SLOT(connectToServer()));
	connect(ui->disconnectButton, SIGNAL(clicked()), this, SLOT(disconnectFromServer()));

	// control buttons
	connect(ui->up2Button, SIGNAL(clicked()), this, SLOT(handleControlButton()));
	connect(ui->up1Button, SIGNAL(clicked()), this, SLOT(handleControlButton()));
	connect(ui->zeroButton, SIGNAL(clicked()), this, SLOT(handleControlButton()));
	connect(ui->down1Button, SIGNAL(clicked()), this, SLOT(handleControlButton()));
	connect(ui->down2Button, SIGNAL(clicked()), this, SLOT(handleControlButton()));

	// plotting setup
	m_accelXData = new QwtPointSeriesData();
	m_accelYData = new QwtPointSeriesData();
	m_accelXCurve = new QwtPlotCurve("Accel X");
	m_accelYCurve = new QwtPlotCurve("Accel Y");
	m_accelXCurve->setPen( QPen( Qt::black ) );
	m_accelYCurve->setPen( QPen( Qt::red));
	m_accelXCurve->attach( ui->plot );
	m_accelYCurve->attach(ui->plot);

	m_gyroXData = new QwtPointSeriesData();
	m_gyroYData = new QwtPointSeriesData();
	m_gyroXCurve = new QwtPlotCurve("Gyro X");
	m_gyroYCurve = new QwtPlotCurve("Gyro Y");
	m_gyroXCurve->setPen( QPen( Qt::green ) );
	m_gyroYCurve->setPen( QPen( Qt::blue));
	m_gyroXCurve->attach( ui->plot );
	m_gyroYCurve->attach(ui->plot);

	ui->plot->setCanvasBackground(Qt::white);
	// Axes
	ui->plot->setAxisTitle( QwtPlot::xBottom, "Seconds" );
	ui->plot->setAxisTitle( QwtPlot::yLeft, "Degrees" );
	ui->plot->setAxisScale( QwtPlot::yLeft, -90, 90 );

	// zero line
	QwtPlotMarker* zeroMarker = new QwtPlotMarker();
	zeroMarker->setLineStyle(QwtPlotMarker::HLine);
	zeroMarker->setLinePen(QPen(Qt::DotLine));
	zeroMarker->setSymbol(new QwtSymbol(QwtSymbol::HLine));
	zeroMarker->setYValue(0);
	zeroMarker->attach(ui->plot);

	updatePlot(0, 0, 0, 0);
}