hivemind 1.0.0
Loading...
Searching...
No Matches
main_window.cpp
Go to the documentation of this file.
1#include "gui/main_window.h"
2
3#include <QDebug>
4#include <QRandomGenerator>
5
6static QColor
8{
9 QRandomGenerator* generator{ QRandomGenerator::global() };
10 auto r = static_cast<float>(generator->generateDouble());
11 auto g = static_cast<float>(generator->generateDouble());
12 auto b = static_cast<float>(generator->generateDouble());
13 return QColor::fromRgbF(r, g, b);
14}
15
16namespace Gui
17{
18 MainWindow::MainWindow(QWidget* parent)
19 : QMainWindow(parent), m_MenuBar{ new MenuBar(this) },
20 m_MainContent{ new MainContent(this) },
21 m_Scenario{ std::make_shared<CompileScenario::Scenario>(
22 "Untitled Scenario",
23 Core::GeographicalCoordinate(59.66584230, 9.65059460), 2700) },
24 m_ScenarioSettingsDialog{ new MapDialog(this) }
25 {
26 setObjectName("MainWindow");
27 setWindowTitle("Hivemind");
28 setWindowIcon(QIcon(":/icons/logo_transparent_512.png"));
29 setMenuBar(m_MenuBar);
30 setCentralWidget(m_MainContent);
31 resize(1280, 720);
32
35 }
36
38
39 void
41 {
42 // Menu bar signals
43 connect(m_MenuBar, SIGNAL(SaveScenario(const std::string&)), this,
44 SLOT(SaveScenario(const std::string&)));
45 connect(m_MenuBar, SIGNAL(LoadScenario(const std::string&)), this,
46 SLOT(LoadScenario(const std::string&)));
47
48 // Connect keyframe list and keyframe manager
49 auto keyframeList{ findChild<KeyframeList*>("KeyframeList") };
50 if (keyframeList) {
52 SIGNAL(KeyframeAdded()), keyframeList, SLOT(Update()));
53 connect(this, SIGNAL(ScenarioLoaded()), keyframeList,
54 SLOT(Update()));
55 }
56
57 auto mapViewer{ findChild<MapViewer*>("MapViewer") };
58 if (mapViewer) {
59 // Connect map viewer and keyframe manager
61 SIGNAL(KeyframeAdded()), mapViewer, SLOT(update()));
62
63 // Connect satellite image request and map loading
70
71 connect(
72 this,
73 SIGNAL(ScenarioCompiled(
74 std::pair<CompileScenario::Scenario::RouteMap::iterator,
75 CompileScenario::Scenario::RouteMap::iterator>)),
76 mapViewer,
77 SLOT(UpdateRoutes(
78 std::pair<CompileScenario::Scenario::RouteMap::iterator,
79 CompileScenario::Scenario::RouteMap::iterator>)));
80
81 auto timeline{ findChild<Timeline*>("Timeline") };
82 if (timeline) {
83 connect(timeline, SIGNAL(timeStampSelected(float)), mapViewer,
84 SLOT(UpdateTimeStamp(float)));
85 }
86 }
87
88 // Connect deletion of keyframes in GUI
89 auto keyframeControls{ findChild<KeyframeControls*>(
90 "KeyframeControls") };
91 if (keyframeControls && keyframeList) {
92 connect(keyframeControls, SIGNAL(DeleteSelectedKeyframes()),
93 keyframeList, SLOT(DeleteSelected()));
94 }
95
96 auto scenarioControls{ findChild<ScenarioControls*>(
97 "ScenarioControls") };
98 if (scenarioControls) {
99 connect(scenarioControls, SIGNAL(OpenSettingsDialog()),
100 m_ScenarioSettingsDialog, SLOT(exec()));
102 SIGNAL(MapDataReady(float, float, float)), this,
103 SLOT(UpdateScenario(float, float, float)));
104 connect(scenarioControls, SIGNAL(CompileScenario()), this,
105 SLOT(CompileScenario()));
106 }
107
108 auto agentControls{ findChild<AgentControls*>("AgentControls") };
109 if (agentControls) {
110 connect(this, SIGNAL(SyncAgentColor()), agentControls,
111 SLOT(SyncColor()));
112 if (mapViewer) {
113 connect(agentControls,
114 SIGNAL(AgentChanged(
115 std::pair<std::vector<Core::Agent>::iterator,
116 std::vector<Core::Agent>::iterator>)),
117 mapViewer,
118 SLOT(UpdateAgents(
119 std::pair<std::vector<Core::Agent>::iterator,
120 std::vector<Core::Agent>::iterator>)));
121 connect(agentControls, SIGNAL(ActiveAgentChanged(int)),
122 mapViewer, SLOT(UpdateActiveAgent(int)));
123 }
124
125 connect(
126 this,
127 SIGNAL(AgentAdded(std::pair<std::vector<Core::Agent>::iterator,
128 std::vector<Core::Agent>::iterator>)),
129 agentControls,
130 SLOT(UpdateAgents(std::pair<std::vector<Core::Agent>::iterator,
131 std::vector<Core::Agent>::iterator>)));
132
133 connect(agentControls, SIGNAL(AddAgent()), this,
134 SLOT(CreateNewAgent()));
135 }
136 }
137
138 void
139 MainWindow::SaveScenario(const std::string& filepath)
140 {
141 m_Scenario->save(filepath);
142 }
143
144 void
145 MainWindow::LoadScenario(const std::string& filepath)
146 {
147 m_Scenario->load(filepath);
148 emit AgentAdded(m_Scenario->GetAgents());
149 emit ScenarioLoaded();
150 update();
151 }
152
153 void
154 MainWindow::UpdateScenario(float latitude, float longitude, float size)
155 {
156 Core::GeographicalCoordinate coord{ latitude, longitude };
157 m_Scenario->SetOrigin(coord, static_cast<int>(size));
158 }
159
160 void
162 {
163 m_Scenario->Compile();
164 auto routes = m_Scenario->GetRoutes();
165 emit ScenarioCompiled(m_Scenario->GetRoutes());
166 }
167
168 void
170 {
171 int maxId{ -1 };
172 auto agents = m_Scenario->GetAgents();
173 for (auto iter{ agents.first }; iter != agents.second; ++iter) {
174 maxId = std::max(maxId, iter->Id);
175 }
176 int id{ maxId == -1 ? 0 : maxId + 1 };
177
178 std::string color = getRandomColor().name().toStdString();
179 m_Scenario->AddAgent({ id, "Untitled agent", color });
180 emit AgentAdded(m_Scenario->GetAgents());
181 emit SyncAgentColor();
182 }
183
184} // namespace Gui
The main content of the main window.
Definition: main_content.h:17
std::shared_ptr< CompileScenario::Scenario > m_Scenario
Definition: main_window.h:57
void UpdateScenario(float, float, float)
~MainWindow()
Descructs the main window.
Definition: main_window.cpp:37
void AgentAdded(std::pair< std::vector< Core::Agent >::iterator, std::vector< Core::Agent >::iterator >)
void LoadScenario(const std::string &filepath)
void CompileScenario()
void SyncAgentColor()
MainContent * m_MainContent
The main content of the main window.
Definition: main_window.h:55
MapDialog * m_ScenarioSettingsDialog
Definition: main_window.h:58
MenuBar * m_MenuBar
The menu bar of the main window.
Definition: main_window.h:51
void ScenarioLoaded()
void SaveScenario(const std::string &filepath)
void ScenarioCompiled(std::pair< CompileScenario::Scenario::RouteMap::iterator, CompileScenario::Scenario::RouteMap::iterator >)
MainWindow(QWidget *parent=nullptr)
Constructs the main window.
Definition: main_window.cpp:18
void ConnectSlotsAndSignals()
Definition: main_window.cpp:40
The MapDialog class represents a dialog window for inputting map data.
Definition: map_dialog.h:16
void WaitForData()
Definition: map_viewer.cpp:123
void DataReceived()
Definition: map_viewer.cpp:132
The main menubar of the user interface.
Definition: menu_bar.h:14
static KeyframeManager & Instance()
Returns the singleton instance of the KeyframeManager.
static MapManager & Instance()
Returns the singleton instance of the class.
Definition: map_manager.h:20
void GotImage()
Signal emitted when the map image data has been retrieved.
static QColor getRandomColor()
Definition: main_window.cpp:7
Definition: types.h:6
Definition: action.h:6
A structure that represents a geographic coordinate.
Definition: types.h:29