From f4d4a8aa46d3811abe993abc1fcc6ea485bfab7e Mon Sep 17 00:00:00 2001 From: Rebecca Cox Date: Tue, 27 Feb 2018 12:40:33 +0100 Subject: [PATCH] #2531 Mohr Circle: Add Info text --- .../UserInterface/RiuMohrsCirclePlot.cpp | 75 ++++++++++++++----- .../UserInterface/RiuMohrsCirclePlot.h | 38 ++++++---- 2 files changed, 80 insertions(+), 33 deletions(-) diff --git a/ApplicationCode/UserInterface/RiuMohrsCirclePlot.cpp b/ApplicationCode/UserInterface/RiuMohrsCirclePlot.cpp index 86d254aaa5..07dcbd5595 100644 --- a/ApplicationCode/UserInterface/RiuMohrsCirclePlot.cpp +++ b/ApplicationCode/UserInterface/RiuMohrsCirclePlot.cpp @@ -44,6 +44,7 @@ #include "qwt_plot_marker.h" #include "qwt_plot_rescaler.h" #include "qwt_plot_shapeitem.h" +#include "qwt_plot_textlabel.h" #include @@ -102,6 +103,7 @@ void RiuMohrsCirclePlot::setPrincipalsAndRedrawPlot(double p1, double p2, double redrawEnvelope(); redrawCircles(); + addInfoLabel(); } //-------------------------------------------------------------------------------------------------- @@ -140,6 +142,7 @@ void RiuMohrsCirclePlot::clearPlot() { deleteCircles(); deleteEnvelope(); + deleteInfoLabel(); this->replot(); } @@ -281,6 +284,46 @@ void RiuMohrsCirclePlot::deleteEnvelope() } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiuMohrsCirclePlot::addInfoLabel() +{ + deleteInfoLabel(); + + QString textBuilder; + + textBuilder.append(QString("Factor of Safety: %1
").arg("Coming soon")); + textBuilder.append(QString("Friction Angle: %1
").arg(m_frictionAngle)); + textBuilder.append(QString("Cohesion: %1
").arg(m_cohesion)); + textBuilder.append(QString("σ1: %1
").arg(m_principal1)); + textBuilder.append(QString("σ2: %1
").arg(m_principal2)); + textBuilder.append(QString("σ3: %1
").arg(m_principal3)); + + QwtText text = textBuilder; + + text.setRenderFlags(Qt::AlignLeft | Qt::AlignTop); + + m_infoTextItem = new QwtPlotTextLabel(); + m_infoTextItem->setText(text); + m_infoTextItem->attach(this); + + this->replot(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiuMohrsCirclePlot::deleteInfoLabel() +{ + if (m_infoTextItem) + { + m_infoTextItem->detach(); + delete m_infoTextItem; + m_infoTextItem = nullptr; + } +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -305,10 +348,9 @@ void RiuMohrsCirclePlot::queryDataAndUpdatePlot(RimGeoMechView* geoMechView, siz clearPlot(); return; } - + setCohesion(geoMechView->geoMechCase()->cohesion()); setFrictionAngle(geoMechView->geoMechCase()->frictionAngleDeg()); - RigFemPart* femPart = geoMechView->geoMechCase()->geoMechData()->femParts()->part(gridIndex); size_t i, j, k; @@ -317,23 +359,9 @@ void RiuMohrsCirclePlot::queryDataAndUpdatePlot(RimGeoMechView* geoMechView, siz int elmId = femPart->elmId(cellIndex); QString title; - QString resultPos; QString fieldName = geoMechView->cellResultResultDefinition()->resultFieldUiName(); - - switch (geoMechView->cellResultResultDefinition()->resultPositionType()) - { - case RIG_ELEMENT_NODAL: - resultPos = "Element Nodal"; - break; - - case RIG_INTEGRATION_POINT: - resultPos = "Integration Point"; - break; - default: - break; - } - title += QString("%1, %2").arg(resultPos).arg(fieldName); + title += QString("%1").arg(fieldName); title += QString(", Element Id[%1], ijk[%2,%3,%4]").arg(elmId).arg(i).arg(j).arg(k); this->setTitle(title); @@ -375,8 +403,13 @@ void RiuMohrsCirclePlot::setDefaults() m_envolopePlotItem = nullptr; m_transparentCurve = nullptr; + + m_infoTextItem = nullptr; + m_cohesion = HUGE_VAL; m_frictionAngle = HUGE_VAL; + + m_factorOfSafety = 0; } //-------------------------------------------------------------------------------------------------- @@ -413,6 +446,14 @@ void RiuMohrsCirclePlot::setCohesion(double cohesion) m_cohesion = cohesion; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiuMohrsCirclePlot::setFactorOfSafety(double fos) +{ + m_factorOfSafety = fos; +} + //-------------------------------------------------------------------------------------------------- /// Add a transparent curve to make tooltip available on principals crossing the x-axis //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/UserInterface/RiuMohrsCirclePlot.h b/ApplicationCode/UserInterface/RiuMohrsCirclePlot.h index 85bd3798de..12cbd0165a 100644 --- a/ApplicationCode/UserInterface/RiuMohrsCirclePlot.h +++ b/ApplicationCode/UserInterface/RiuMohrsCirclePlot.h @@ -23,12 +23,13 @@ #include -class RiuSelectionItem; -class RimGeoMechView; -class QwtRoundScaleDraw; -class QwtPlotRescaler; class QWidget; class QwtPlotCurve; +class QwtPlotRescaler; +class QwtPlotTextLabel; +class QwtRoundScaleDraw; +class RimGeoMechView; +class RiuSelectionItem; //================================================================================================== // @@ -49,18 +50,6 @@ class RiuMohrsCirclePlot : public QwtPlot void updateOnSelectionChanged(const RiuSelectionItem* selectionItem); void clearPlot(); -protected: - virtual QSize sizeHint() const override; - virtual QSize minimumSizeHint() const override; - - void redrawCircles(); - void deleteCircles(); - - void redrawEnvelope(); - void deleteEnvelope(); - - void queryDataAndUpdatePlot(RimGeoMechView* geoMechView, size_t gridIndex, size_t cellIndex); - private: struct MohrCircle { @@ -73,11 +62,26 @@ class RiuMohrsCirclePlot : public QwtPlot }; private: + virtual QSize sizeHint() const override; + virtual QSize minimumSizeHint() const override; + + void redrawCircles(); + void deleteCircles(); + + void redrawEnvelope(); + void deleteEnvelope(); + + void addInfoLabel(); + void deleteInfoLabel(); + + void queryDataAndUpdatePlot(RimGeoMechView* geoMechView, size_t gridIndex, size_t cellIndex); + void setDefaults(); void createMohrCircles(); void setFrictionAngle(double frictionAngle); void setCohesion(double cohesion); + void setFactorOfSafety(double fos); void updateTransparentCurveOnPrincipals(); @@ -101,5 +105,7 @@ class RiuMohrsCirclePlot : public QwtPlot double m_cohesion; double m_factorOfSafety; + QwtPlotTextLabel* m_infoTextItem; + QwtPlotRescaler* m_rescaler; };