Skip to content

Commit 3aa1a67

Browse files
committed
Added graph window that can show dynamic data. This is now used to plot data on a curve probe.
1 parent c6c5159 commit 3aa1a67

File tree

3 files changed

+87
-19
lines changed

3 files changed

+87
-19
lines changed

FEBioStudio/GraphWindow.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2948,3 +2948,33 @@ void CModelGraphWindow::TrackElementHistory(int nelem, float* pval, int nfield,
29482948
pval[n] = val;
29492949
}
29502950
}
2951+
2952+
//=====================================================================================
2953+
CDynamicDataGraphWindow::CDynamicDataGraphWindow(CMainWindow* wnd, CPostDocument* doc) : CGraphWindow(wnd, doc)
2954+
{
2955+
m_src = nullptr;
2956+
AddPlotData(new CPlotData());
2957+
}
2958+
2959+
void CDynamicDataGraphWindow::Update(bool breset, bool bfit)
2960+
{
2961+
if (m_src)
2962+
{
2963+
CPlotData* plot = dynamic_cast<CPlotData*>(GetPlotData(0));
2964+
if (plot)
2965+
{
2966+
m_src->UpdatePlot(*plot);
2967+
}
2968+
}
2969+
RedrawPlot();
2970+
}
2971+
2972+
void CDynamicDataGraphWindow::showEvent(QShowEvent* ev)
2973+
{
2974+
Update(true, true);
2975+
}
2976+
2977+
void CDynamicDataGraphWindow::closeEvent(QCloseEvent* ev)
2978+
{
2979+
CGraphWindow::closeEvent(ev);
2980+
}

FEBioStudio/GraphWindow.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,3 +457,32 @@ class CModelGraphWindow : public CGraphWindow
457457
int m_pltCounter;
458458
};
459459

460+
//=================================================================================================
461+
// This graph window is used by plot objects for displaying their data.
462+
// It is not associated with a specific data field, but instead the data is passed to it directly
463+
464+
class CPlotDataSource
465+
{
466+
public:
467+
CPlotDataSource() {}
468+
virtual ~CPlotDataSource() {}
469+
470+
virtual void UpdatePlot(CPlotData& data) = 0;
471+
};
472+
473+
class CDynamicDataGraphWindow : public CGraphWindow
474+
{
475+
public:
476+
CDynamicDataGraphWindow(CMainWindow* wnd, CPostDocument* doc);
477+
478+
void SetDataSource(CPlotDataSource* src) { m_src.reset(src); }
479+
480+
void Update(bool breset = true, bool bfit = false);
481+
482+
void showEvent(QShowEvent* ev);
483+
484+
void closeEvent(QCloseEvent* ev);
485+
486+
private:
487+
std::unique_ptr<CPlotDataSource> m_src;
488+
};

FEBioStudio/PostModelPanel.cpp

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2011,37 +2011,46 @@ void CPostModelPanel::OnSwapMusclePathEndPoints()
20112011
GetMainWindow()->RedrawGL();
20122012
}
20132013

2014-
void CPostModelPanel::OnCurveProbePlotData()
2014+
class CCurveProbeData : public CPlotDataSource
20152015
{
2016-
CPostDocument* doc = dynamic_cast<CPostDocument*>(GetDocument());
2017-
if (doc == nullptr) return;
2016+
public:
2017+
CCurveProbeData(Post::GLCurveProbe* po) : m_probe(po) {}
20182018

2019-
Post::GLCurveProbe* po = dynamic_cast<Post::GLCurveProbe*>(ui->currentObject());
2020-
if (po)
2019+
void UpdatePlot(CPlotData& data) override
20212020
{
2022-
int N = (int)po->Points();
2023-
vector<double> xpoints = po->SectionLenghts(false);
2021+
int N = (int)m_probe->Points();
2022+
vector<double> xpoints = m_probe->SectionLenghts(false);
20242023
vector<double> ypoints(N, 0.0);
2025-
#pragma omp parallel for
20262024
for (int i = 0; i < N; ++i)
20272025
{
2028-
ypoints[i] = po->GetPointValue(i);
2026+
ypoints[i] = m_probe->GetPointValue(i);
20292027
}
20302028

2031-
CPlotData* data = new CPlotData;
2032-
for (int i = 0; i < po->Points(); ++i)
2029+
data.clear();
2030+
for (int i = 0; i < m_probe->Points(); ++i)
20332031
{
2034-
data->addPoint(xpoints[i], ypoints[i]);
2032+
data.addPoint(xpoints[i], ypoints[i]);
20352033
}
2036-
data->setLabel(QString::fromStdString(po->GetName()));
2037-
data->setLineColor(toQColor(po->GetColor()));
2038-
data->setFillColor(toQColor(po->GetColor()));
20392034

2040-
CGraphData* graph = new CGraphData;
2041-
graph->m_data.push_back(data);
2035+
data.setLabel(QString::fromStdString(m_probe->GetName()));
2036+
data.setLineColor(toQColor(m_probe->GetColor()));
2037+
data.setFillColor(toQColor(m_probe->GetColor()));
2038+
}
20422039

2043-
CDataGraphWindow* w = new CDataGraphWindow(GetMainWindow(), doc);
2044-
w->SetData(graph);
2040+
private:
2041+
Post::GLCurveProbe* m_probe;
2042+
};
2043+
2044+
void CPostModelPanel::OnCurveProbePlotData()
2045+
{
2046+
CPostDocument* doc = dynamic_cast<CPostDocument*>(GetDocument());
2047+
if (doc == nullptr) return;
2048+
2049+
Post::GLCurveProbe* po = dynamic_cast<Post::GLCurveProbe*>(ui->currentObject());
2050+
if (po)
2051+
{
2052+
CDynamicDataGraphWindow* w = new CDynamicDataGraphWindow(GetMainWindow(), doc);
2053+
w->SetDataSource(new CCurveProbeData(po));
20452054
GetMainWindow()->AddGraph(w);
20462055
w->setWindowTitle(QString::fromStdString(po->GetName()));
20472056
w->show();

0 commit comments

Comments
 (0)