Skip to content

Commit

Permalink
Merge f5e50b4 into b1ebcde
Browse files Browse the repository at this point in the history
  • Loading branch information
agarny committed Oct 26, 2018
2 parents b1ebcde + f5e50b4 commit 2f1dd85
Show file tree
Hide file tree
Showing 3 changed files with 175 additions and 5 deletions.
1 change: 1 addition & 0 deletions doc/downloads/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var jsonData = { "versions": [
],
"changes": [
{ "change": "<strong>General:</strong> unmanage and (re)manage a new file that has been saved (see issue <a href=\"https://github.com/opencor/opencor/issues/1846\">#1846</a>). Overlayed icons now have the same resolution as standard icons on HiDPI screens (see issue <a href=\"https://github.com/opencor/opencor/issues/1850\">#1850</a>). Recognise macOS Mojave (10.14) (see issue <a href=\"https://github.com/opencor/opencor/issues/1851\">#1851</a>)." },
{ "change": "<strong>Graph Panel widget:</strong> prevent OpenCOR from potentially freezing when plotting invalid data (see issue <a href=\"https://github.com/opencor/opencor/issues/1853\">#1853</a>)." },
{ "change": "<strong>Simulation Experiment view:</strong> now have two reset buttons rather than one with a drop-down menu (see issue <a href=\"https://github.com/opencor/opencor/issues/1835\">#1835</a>)." },
{ "change": "<strong>Third-party libraries:</strong> upgraded <a href=\"https://riverbankcomputing.com/software/qscintilla/intro\">QScintilla</a> to version 2.10.8 (see issue <a href=\"https://github.com/opencor/opencor/issues/1833\">#1833</a>). Upgraded <a href=\"https://libgit2.github.com/\">libgit2</a> to version 0.27.5 (see issue <a href=\"https://github.com/opencor/opencor/issues/1838\">#1838</a>). Upgraded the <a href=\"http://computation.llnl.gov/projects/sundials\">SUNDIALS</a> library to version 3.2.1 (see issue <a href=\"https://github.com/opencor/opencor/issues/1847\">#1847</a>)." }
]
Expand Down
166 changes: 161 additions & 5 deletions src/plugins/widget/GraphPanelWidget/src/graphpanelplotwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
//==============================================================================

#include "qwtbegin.h"
#include "qwt_clipper.h"
#include "qwt_curve_fitter.h"
#include "qwt_dyngrid_layout.h"
#include "qwt_legend_label.h"
#include "qwt_painter.h"
Expand All @@ -55,6 +57,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "qwt_plot_grid.h"
#include "qwt_plot_layout.h"
#include "qwt_plot_renderer.h"
#include "qwt_point_mapper.h"
#include "qwt_scale_engine.h"
#include "qwt_text_label.h"
#include "qwtend.h"
Expand Down Expand Up @@ -183,7 +186,9 @@ QColor GraphPanelPlotGraphProperties::symbolFillColor() const

GraphPanelPlotGraphRun::GraphPanelPlotGraphRun(GraphPanelPlotGraph *pOwner) :
QwtPlotCurve(),
mOwner(pOwner)
mOwner(pOwner),
mSize(0),
mValidData(QList<QPair<int, int>>())
{
// Customise ourselves a bit

Expand All @@ -204,6 +209,104 @@ GraphPanelPlotGraph * GraphPanelPlotGraphRun::owner() const

//==============================================================================

void GraphPanelPlotGraphRun::setRawSamples(const double *pDataX,
const double *pDataY,
int pSize)
{
// Set the given raw samples and keep track of those that are valid

static const QPair<int, int> EmptyValidData = QPair<int, int>();

QPair<int, int> validData = EmptyValidData;

if (!mValidData.isEmpty()) {
validData = mValidData.last();

mValidData.removeLast();
}

for (int i = mSize; i < pSize; ++i) {
if ( !qIsInf(pDataX[i]) && !qIsNaN(pDataX[i])
&& !qIsInf(pDataY[i]) && !qIsNaN(pDataY[i])) {
if (validData == EmptyValidData) {
validData.first = i;
validData.second = i;
} else if (validData.second == i-1) {
validData.second = i;
} else {
mValidData << validData;

validData.first = i;
validData.second = i;
}
}
}

if (validData != EmptyValidData)
mValidData << validData;

mSize = pSize;

QwtPlotCurve::setRawSamples(pDataX, pDataY, pSize);
}

//==============================================================================

void GraphPanelPlotGraphRun::drawLines(QPainter *pPainter,
const QwtScaleMap &pMapX,
const QwtScaleMap &pMapY,
const QRectF &pCanvasRect,
int pFrom, int pTo) const
{
// Draw our lines

for (int i = 0, iMax = mValidData.count(); i < iMax; ++i) {
if ((pFrom <= mValidData[i].first) || (pTo >= mValidData[i].second)) {
int from = ( (pFrom >= mValidData[i].first)
&& (pFrom <= mValidData[i].second))?
pFrom:
mValidData[i].first;
int to = ( (pTo >= mValidData[i].first)
&& (pTo <= mValidData[i].second))?
pTo:
mValidData[i].second;

QwtPlotCurve::drawLines(pPainter, pMapX, pMapY,
pCanvasRect, from, to);
}
}
}

//==============================================================================

void GraphPanelPlotGraphRun::drawSymbols(QPainter *pPainter,
const QwtSymbol &pSymbol,
const QwtScaleMap &pMapX,
const QwtScaleMap &pMapY,
const QRectF &pCanvasRect,
int pFrom, int pTo) const
{
// Draw our symbols

for (int i = 0, iMax = mValidData.count(); i < iMax; ++i) {
if ((pFrom <= mValidData[i].first) || (pTo >= mValidData[i].second)) {
int from = ( (pFrom >= mValidData[i].first)
&& (pFrom <= mValidData[i].second))?
pFrom:
mValidData[i].first;
int to = ( (pTo >= mValidData[i].first)
&& (pTo <= mValidData[i].second))?
pTo:
mValidData[i].second;

QwtPlotCurve::drawSymbols(pPainter, pSymbol, pMapX, pMapY,
pCanvasRect, from, to);
}
}
}

//==============================================================================

static const QRectF InvalidRect = QRectF(0.0, 0.0, -1.0, -1.0);

//==============================================================================
Expand Down Expand Up @@ -636,9 +739,60 @@ QRectF GraphPanelPlotGraph::boundingRect()
QRectF boundingRect = mBoundingRects.value(run, InvalidRect);

if (boundingRect == InvalidRect) {
boundingRect = run->boundingRect();
bool needInitMinX = true;
bool needInitMaxX = true;
bool needInitMinY = true;
bool needInitMaxY = true;
double minX = 1.0;
double maxX = 1.0;
double minY = 1.0;
double maxY = 1.0;

for (size_t i = 0, iMax = run->dataSize(); i < iMax; ++i) {
QPointF sample = run->data()->sample(i);

if (!qIsInf(sample.x()) && !qIsNaN(sample.x())) {
if (needInitMinX) {
minX = sample.x();

needInitMinX = false;
} else if (sample.x() < minX) {
minX = sample.x();
}

if (needInitMaxX) {
maxX = sample.x();

needInitMaxX = false;
} else if (sample.x() > maxX) {
maxX = sample.x();
}
}

mBoundingRects.insert(run, boundingRect);
if (!qIsInf(sample.y()) && !qIsNaN(sample.y())) {
if (needInitMinY) {
minY = sample.y();

needInitMinY = false;
} else if (sample.y() < minY) {
minY = sample.y();
}

if (needInitMaxY) {
maxY = sample.y();

needInitMaxY = false;
} else if (sample.y() > maxY) {
maxY = sample.y();
}
}
}

if (!needInitMinX && !needInitMaxX && !needInitMinY && !needInitMaxY) {
boundingRect = QRectF(minX, minY, maxX-minX, maxY-minY);

mBoundingRects.insert(run, boundingRect);
}
}

mBoundingRect |= boundingRect;
Expand Down Expand Up @@ -676,7 +830,8 @@ QRectF GraphPanelPlotGraph::boundingLogRect()
for (size_t i = 0, iMax = run->dataSize(); i < iMax; ++i) {
QPointF sample = run->data()->sample(i);

if (sample.x() > 0.0) {
if ( !qIsInf(sample.x()) && !qIsNaN(sample.x())
&& (sample.x() > 0.0)) {
if (needInitMinX) {
minX = sample.x();

Expand All @@ -694,7 +849,8 @@ QRectF GraphPanelPlotGraph::boundingLogRect()
}
}

if (sample.y() > 0.0) {
if ( !qIsInf(sample.y()) && !qIsNaN(sample.y())
&& (sample.y() > 0.0)) {
if (needInitMinY) {
minY = sample.y();

Expand Down
13 changes: 13 additions & 0 deletions src/plugins/widget/GraphPanelWidget/src/graphpanelplotwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,21 @@ class GraphPanelPlotGraphRun : public QwtPlotCurve

GraphPanelPlotGraph * owner() const;

void setRawSamples(const double *pDataX, const double *pDataY, int pSize);

protected:
void drawLines(QPainter *pPainter, const QwtScaleMap &pMapX,
const QwtScaleMap &pMapY, const QRectF &pCanvasRect,
int pFrom, int pTo) const override;
void drawSymbols(QPainter *pPainter, const QwtSymbol &pSymbol,
const QwtScaleMap &pMapX, const QwtScaleMap &pMapY,
const QRectF &pCanvasRect, int pFrom, int pTo) const override;

private:
GraphPanelPlotGraph *mOwner;

int mSize;
QList<QPair<int, int>> mValidData;
};

//==============================================================================
Expand Down

0 comments on commit 2f1dd85

Please sign in to comment.