Skip to content

Commit 1e8303a

Browse files
committed
Move arrow position, velocity and acceleration to a dedicated tab
Closes #292
1 parent 9c3d010 commit 1e8303a

4 files changed

Lines changed: 133 additions & 1 deletion

File tree

gui/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ add_executable(
199199
source/pre/widgets/ScrollArea.hpp
200200
source/post/ResultWindow.cpp
201201
source/post/ResultWindow.hpp
202+
source/post/ArrowPlot.cpp
203+
source/post/ArrowPlot.hpp
202204
source/post/ComboPlot.cpp
203205
source/post/ComboPlot.hpp
204206
source/post/CurvaturePlot.cpp

gui/source/post/ArrowPlot.cpp

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#include "ArrowPlot.hpp"
2+
#include "pre/widgets/PlotWidget.hpp"
3+
#include "pre/models/units/UnitSystem.hpp"
4+
5+
ArrowPlot::ArrowPlot(const Common& common, const States& states)
6+
: common(common),
7+
states(states)
8+
{
9+
posPlot = new PlotWidget();
10+
velPlot = new PlotWidget();
11+
accPlot = new PlotWidget();
12+
13+
posGraph = posPlot->addGraph();
14+
posGraph->setName("Position");
15+
posGraph->setPen({Qt::blue, 2.0});
16+
17+
velGraph = velPlot->addGraph();
18+
velGraph->setName("Velocity");
19+
velGraph->setPen({QColor(128, 0, 128), 2.0});
20+
21+
accGraph = accPlot->addGraph();
22+
accGraph->setName("Acceleration");
23+
accGraph->setPen({Qt::red, 2.0});
24+
25+
auto vbox = new QVBoxLayout();
26+
vbox->setContentsMargins({});
27+
vbox->setSpacing(0);
28+
vbox->addWidget(posPlot);
29+
vbox->addWidget(velPlot);
30+
vbox->addWidget(accPlot);
31+
setLayout(vbox);
32+
33+
// Connect x-axis ranges of the plots to each other
34+
QObject::connect(posPlot->xAxis, QOverload<const QCPRange&>::of(&QCPAxis::rangeChanged), this, &ArrowPlot::updateRanges);
35+
QObject::connect(velPlot->xAxis, QOverload<const QCPRange&>::of(&QCPAxis::rangeChanged), this, &ArrowPlot::updateRanges);
36+
QObject::connect(accPlot->xAxis, QOverload<const QCPRange&>::of(&QCPAxis::rangeChanged), this, &ArrowPlot::updateRanges);
37+
38+
39+
// Update plots on unit changes
40+
QObject::connect(&Quantities::time, &Quantity::unitChanged, this, &ArrowPlot::updatePlots);
41+
QObject::connect(&Quantities::position, &Quantity::unitChanged, this, &ArrowPlot::updatePlots);
42+
QObject::connect(&Quantities::velocity, &Quantity::unitChanged, this, &ArrowPlot::updatePlots);
43+
QObject::connect(&Quantities::acceleration, &Quantity::unitChanged, this, &ArrowPlot::updatePlots);
44+
45+
// Initialize plots once
46+
updatePlots();
47+
}
48+
49+
void ArrowPlot::updateRanges(const QCPRange& range) {
50+
posPlot->xAxis->setRange(range);
51+
velPlot->xAxis->setRange(range);
52+
accPlot->xAxis->setRange(range);
53+
54+
posPlot->replot();
55+
velPlot->replot();
56+
accPlot->replot();
57+
}
58+
59+
void ArrowPlot::updatePlots() {
60+
posPlot->xAxis->setLabel("Time " + Quantities::time.getUnit().getLabel());
61+
posPlot->yAxis->setLabel("Position " + Quantities::position.getUnit().getLabel());
62+
63+
velPlot->xAxis->setLabel("Time " + Quantities::time.getUnit().getLabel());
64+
velPlot->yAxis->setLabel("Velocity " + Quantities::velocity.getUnit().getLabel());
65+
66+
accPlot->xAxis->setLabel("Time " + Quantities::time.getUnit().getLabel());
67+
accPlot->yAxis->setLabel("Acceleration " + Quantities::acceleration.getUnit().getLabel());
68+
69+
posGraph->setData(
70+
Quantities::time.getUnit().fromBase(states.time),
71+
Quantities::position.getUnit().fromBase(states.arrow_pos)
72+
);
73+
74+
velGraph->setData(
75+
Quantities::time.getUnit().fromBase(states.time),
76+
Quantities::velocity.getUnit().fromBase(states.arrow_vel)
77+
);
78+
79+
accGraph->setData(
80+
Quantities::time.getUnit().fromBase(states.time),
81+
Quantities::acceleration.getUnit().fromBase(states.arrow_acc)
82+
);
83+
84+
// Rescale axes without triggering ranges update
85+
{
86+
QSignalBlocker blocker1(posPlot->xAxis);
87+
posPlot->rescaleAxes();
88+
89+
QSignalBlocker blocker2(velPlot->xAxis);
90+
velPlot->rescaleAxes();
91+
92+
QSignalBlocker blocker3(accPlot->xAxis);
93+
accPlot->rescaleAxes();
94+
}
95+
96+
97+
posPlot->replot();
98+
velPlot->replot();
99+
accPlot->replot();
100+
}

gui/source/post/ArrowPlot.hpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#pragma once
2+
#include "solver/BowResult.hpp"
3+
#include <QWidget>
4+
5+
class QCPGraph;
6+
class QCPRange;
7+
class PlotWidget;
8+
9+
class ArrowPlot: public QWidget {
10+
public:
11+
ArrowPlot(const Common& common, const States& states);
12+
13+
private:
14+
const Common& common;
15+
const States& states;
16+
17+
PlotWidget* posPlot;
18+
PlotWidget* velPlot;
19+
PlotWidget* accPlot;
20+
21+
QCPGraph* posGraph;
22+
QCPGraph* velGraph;
23+
QCPGraph* accGraph;
24+
25+
void updateRanges(const QCPRange& range);
26+
void updatePlots();
27+
};

gui/source/post/OutputWidget.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "OutputWidget.hpp"
44
#include "NumberGrid.hpp"
55
#include "ShapePlot.hpp"
6+
#include "ArrowPlot.hpp"
67
#include "DrawForcePlot.hpp"
78
#include "StressPlot.hpp"
89
#include "CurvaturePlot.hpp"
@@ -149,7 +150,7 @@ StaticOutputWidget::StaticOutputWidget(const BowResult& data)
149150

150151
tabs->addTab(scrollArea(numbers), "Characteristics");
151152
tabs->addTab(plot_shapes, "Shape");
152-
tabs->addTab(plot_draw, "Draw Force");
153+
tabs->addTab(plot_draw, "Draw");
153154
tabs->addTab(plot_stress, "Stress");
154155
tabs->addTab(plot_curvature, "Curvature");
155156
tabs->addTab(plot_energy, "Energy");
@@ -250,6 +251,7 @@ DynamicOutputWidget::DynamicOutputWidget(const BowResult& data)
250251
numbers->addValue("String force (strand)", std::get<0>(data.dynamics->max_forces.max_strand_force), Quantities::force);
251252

252253
auto plot_shapes = new ShapePlot(data.common, data.dynamics->states, 0);
254+
auto plot_arrow = new ArrowPlot(data.common, data.dynamics->states);
253255
auto plot_stress = new StressPlot(data.common, data.dynamics->states);
254256
auto plot_curvature = new CurvaturePlot(data.common, data.dynamics->states);
255257
auto plot_energy = new EnergyPlot(data.dynamics->states, data.dynamics->states.time, "Time", Quantities::time, Quantities::energy);
@@ -272,6 +274,7 @@ DynamicOutputWidget::DynamicOutputWidget(const BowResult& data)
272274

273275
tabs->addTab(scrollArea(numbers), "Characteristics");
274276
tabs->addTab(plot_shapes, "Shape");
277+
tabs->addTab(plot_arrow, "Arrow");
275278
tabs->addTab(plot_stress, "Stress");
276279
tabs->addTab(plot_curvature, "Curvature");
277280
tabs->addTab(plot_energy, "Energy");

0 commit comments

Comments
 (0)