aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorccolin2021-01-04 15:09:38 +0100
committerccolin2021-01-04 15:09:38 +0100
commit81108c1b0fa8f710ff7417476c10c83e70ae7a15 (patch)
treed03ba3ff458f79b104b8b62181b9775c8e035342 /src
parent0c28d9dc80e634ebfbabed5ad446b6a4f82056e3 (diff)
properly honor default values of sphere radius and speed limit
Diffstat (limited to 'src')
-rw-r--r--src/drone_controller.cc3
-rw-r--r--src/drone_controller.hh1
-rw-r--r--src/main_window.cc2
-rw-r--r--src/settings_pane.cc31
-rw-r--r--src/settings_pane.hh4
5 files changed, 30 insertions, 11 deletions
diff --git a/src/drone_controller.cc b/src/drone_controller.cc
index 58f0359..0a98a63 100644
--- a/src/drone_controller.cc
+++ b/src/drone_controller.cc
@@ -262,12 +262,11 @@ void DroneController::computeCollisions(double sphere_radius) {
void DroneController::computeSpeedingViolations(double speed) {
- speed_violations.clear();
+ speed_limit = speed;
for (int i = 0; i < duration; i++) {
for (Drone &d : drones) {
d.setTo(i);
if (d.getSpeed() > speed) {
- speed_violations[i].append(d.getId());
emit speedViolation(d.getId(), d.getSpeed(), i);
}
}
diff --git a/src/drone_controller.hh b/src/drone_controller.hh
index 3c09089..3ffe797 100644
--- a/src/drone_controller.hh
+++ b/src/drone_controller.hh
@@ -25,7 +25,6 @@ class DroneController : public QObject, public Painter {
QMap<int, QVector<QPair<int, int>>> collisions;
bool draw_trajectories = false;
bool draw_guides = false;
- QMap<int, QVector<int>> speed_violations;
double speed_limit = 0;
static OpenGLMesh *sphere;
diff --git a/src/main_window.cc b/src/main_window.cc
index 39261dd..ad3a7fe 100644
--- a/src/main_window.cc
+++ b/src/main_window.cc
@@ -92,11 +92,13 @@ void MainWindow::open(const QString &path) {
dc, &DroneController::computeCollisions);
connect(settings_pane, &SettingsPane::sphereRadiusChanged,
dc, &DroneController::displaySpheres);
+ dc->computeCollisions(settings_pane->getSphereRadius());
connect(settings_pane, &SettingsPane::speedLimitChanged,
[&](double _) { Q_UNUSED(_); settings_pane->clearSpeedingViolations(); });
connect(settings_pane, &SettingsPane::speedLimitChanged,
dc, &DroneController::computeSpeedingViolations);
+ dc->computeSpeedingViolations(settings_pane->getSpeedLimit());
connect(settings_pane, &SettingsPane::toggledTrajectories,
dc, &DroneController::setDrawTrajectories);
diff --git a/src/settings_pane.cc b/src/settings_pane.cc
index e580d37..856c45c 100644
--- a/src/settings_pane.cc
+++ b/src/settings_pane.cc
@@ -10,18 +10,24 @@
SettingsPane::SettingsPane(QWidget *parent)
:QWidget(parent) {
- QDoubleSpinBox *sphere_radius = new QDoubleSpinBox();
- sphere_radius->setSingleStep(.1);
- QDoubleSpinBox *speed_limit = new QDoubleSpinBox();
- speed_limit->setSingleStep(.1);
+ QDoubleSpinBox *sphere_radius_input = new QDoubleSpinBox();
+ sphere_radius_input->setSingleStep(.1);
+ sphere_radius_input->setValue(sphere_radius);
+ QDoubleSpinBox *speed_limit_input = new QDoubleSpinBox();
+ speed_limit_input->setSingleStep(.1);
+ speed_limit_input->setValue(speed_limit);
QCheckBox *show_trajectories = new QCheckBox();
QCheckBox *show_guides = new QCheckBox();
collisions = new QListWidget();
speeding_violations = new QListWidget();
- connect(sphere_radius, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
+ connect(sphere_radius_input, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
+ [&](double radius) { sphere_radius = radius; });
+ connect(sphere_radius_input, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
this, &SettingsPane::sphereRadiusChanged);
- connect(speed_limit, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
+ connect(speed_limit_input, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
+ [&](double speed) { speed_limit = speed; });
+ connect(speed_limit_input, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
this, &SettingsPane::speedLimitChanged);
connect(show_trajectories, &QCheckBox::stateChanged,
this, &SettingsPane::toggledTrajectories);
@@ -35,8 +41,8 @@ SettingsPane::SettingsPane(QWidget *parent)
QTabWidget *tabs = new QTabWidget();
QFormLayout *layout = new QFormLayout;
- layout->addRow("Taille de la sphère de collision", sphere_radius);
- layout->addRow("Limite de vitesse", speed_limit);
+ layout->addRow("Taille de la sphère de collision", sphere_radius_input);
+ layout->addRow("Limite de vitesse", speed_limit_input);
layout->addRow("Afficher les trajectoires", show_trajectories);
layout->addRow("Afficher les guides", show_guides);
@@ -48,6 +54,15 @@ SettingsPane::SettingsPane(QWidget *parent)
}
+double SettingsPane::getSphereRadius() const {
+ return sphere_radius;
+}
+
+double SettingsPane::getSpeedLimit() const {
+ return speed_limit;
+}
+
+
void SettingsPane::addCollision(int idA, int idB, int frame) {
BookmarkItem *item = new BookmarkItem("Frame " + QString::number(frame) + ": #"
+ QString::number(idA) + " et #" + QString::number(idB),
diff --git a/src/settings_pane.hh b/src/settings_pane.hh
index 8b92690..49fd194 100644
--- a/src/settings_pane.hh
+++ b/src/settings_pane.hh
@@ -22,9 +22,13 @@ class SettingsPane : public QWidget {
QListWidget *collisions = nullptr;
QListWidget *speeding_violations = nullptr;
+ double sphere_radius = .6;
+ double speed_limit = .5;
public:
SettingsPane(QWidget *parent=nullptr);
+ double getSphereRadius() const;
+ double getSpeedLimit() const;
public slots:
void addCollision(int idA, int idB, int frame);