properly honor default values of sphere radius and speed limit

This commit is contained in:
ccolin 2021-01-04 15:09:38 +01:00
parent 0c28d9dc80
commit 81108c1b0f
5 changed files with 30 additions and 11 deletions

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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);

View File

@ -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),

View File

@ -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);