-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.cpp
More file actions
104 lines (88 loc) · 4.06 KB
/
MainWindow.cpp
File metadata and controls
104 lines (88 loc) · 4.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include "MainWindow.h"
#include "ui_MainWindow.h"
#include <QDateTime>
#include <QMovie>
#include <QMediaPlayer>
#include <QVideoWidget>
#include <QUrl>
using namespace std;
// Initializes the Main Window and Sets Up UI Components
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), decisionMaker(logger) {
ui->setupUi(this);
ui->dateTimeEdit->setDateTime(QDateTime::currentDateTime());
// Connects Buttons to Their Respective Slots
connect(ui->buttonSimulate, &QPushButton::clicked, this, &MainWindow::onSimulateClicked);
ui->buttonSimulate->setFocus();
connect(ui->buttonLog, &QPushButton::clicked, this, &MainWindow::onShowLogClicked);
connect(ui->buttonReset, &QPushButton::clicked, this, &MainWindow::onResetClicked);
// Loads and Starts Animated Driving GIF
movie = new QMovie("D:/Misc/College/Spring 2025/CS 136/SRC Project/Autonomous Vehicle Simulator/Media/Pixel_Art_Car_Driving_A_Highway_At_Night.gif");
// Source: OrkhanTheStargazer. "Pixel Art Car Driving a Highway at Night." Motion Array, motionarray.com/stock-video/pixel-art-car-driving-a-highway-at-night-2082701/.
movie->setScaledSize(ui->labelVideo->size());
movie->setCacheMode(QMovie::CacheAll);
movie->setSpeed(100);
ui->labelVideo->setMovie(movie);
movie->start();
}
MainWindow::~MainWindow() {
delete ui;
}
// Handles Simulation Logic and Displays Results
void MainWindow::onSimulateClicked() {
bool pedestrian = ui->checkBoxPedestrian->isChecked();
bool obstacle = ui->checkBoxObstacle->isChecked();
QString roadType = ui->comboBoxRoadType->currentText();
QString weather = ui->comboBoxWeather->currentText();
int speedLimit = ui->spinBoxSpeed->value();
// Evaluates Driving Conditions Using the DecisionMaker Class
decisionMaker.evaluateConditions(
pedestrian,
obstacle,
roadType.toStdString(),
speedLimit,
weather.toStdString(),
vehicle
);
// Retrieve the Final Decision and Rationale
QString decision = QString::fromStdString(vehicle.getStatus());
QString rationale;
// Determine the Rationale Based on Input
if (pedestrian) {
rationale = "Pedestrian detected. Prioritizing human life.";
} else if (obstacle) {
rationale = "Obstacle ahead. Minimizing potential harm.";
} else if (weather == "Fog" || weather == "Rain") {
rationale = "Poor visibility. Slowing down to ensure safety.";
} else {
rationale = "No immediate threats. Proceeding cautiously.";
}
// Output to the Log
ui->textBrowserLog->append("🚦 Decision Made: " + QString::fromStdString(vehicle.getStatus()));
ui->textBrowserLog->append("☑️ Simulation Run at " + ui->dateTimeEdit->dateTime().toString("MM/dd/yyyy hh:mm AP"));
ui->textBrowserLog->append("📝 Rationale: " + rationale);
ui->textBrowserLog->append(""); // Extra Space
ui->textBrowserLog->append("----------------------------"); // Visual Separator
ui->textBrowserLog->append(""); // Extra Space
}
// Displays Previously Logged Decisions
void MainWindow::onShowLogClicked() {
ui->textBrowserLog->clear();
for (const string &entry : logger.getLogs()) {
ui->textBrowserLog->append(QString::fromStdString(entry));
ui->textBrowserLog->append("----------------------------"); // Visual Separator
ui->textBrowserLog->append(""); // Extra Space
}
}
// Resets All Input Fields and Clears the Log
void MainWindow::onResetClicked() {
ui->textBrowserLog->clear();
ui->checkBoxPedestrian->setChecked(false);
ui->checkBoxObstacle->setChecked(false);
ui->comboBoxRoadType->setCurrentIndex(0);
ui->comboBoxWeather->setCurrentIndex(0);
ui->spinBoxSpeed->setValue(0);
ui->dateTimeEdit->setDateTime(QDateTime::currentDateTime());
ui->dateTimeEdit->setReadOnly(true);
ui->dateTimeEdit->setButtonSymbols(QAbstractSpinBox::NoButtons);
ui->dateTimeEdit->setFocusPolicy(Qt::NoFocus);
}