Locus No Pilotus
Project of four first grade MIPT DAFE/RSE students (for engineering practical work in the second semester) in Qt C++
Loading...
Searching...
No Matches
MainWindow Class Reference

#include <mainwindow.h>

Inheritance diagram for MainWindow:
Collaboration diagram for MainWindow:

Public Slots

void AddHill (const std::vector< std::pair< double, double > > &points)
 
void AddTarget (double x, double y)
 
void AddTrappyCircle (double x, double y, double radius)
 
void AddTrappyLine (double x1, double y1, double x2, double y2)
 

Public Member Functions

 MainWindow (QWidget *parent=nullptr)
 
 ~MainWindow ()
 

Private Slots

void closeEvent (QCloseEvent *event) override
 Проверяет при закрытии приложения, есть ли изменения в текущем файле
 
void DisconnectObject (gui::ObjectType obj_type)
 
void keyPressEvent (QKeyEvent *key_event) override
 
void mouseMoveAddVertice (QMouseEvent *mouse_event)
 
void mouseMoveSetRadiusFromPlot (QMouseEvent *mouse_event)
 
void mousePressAddVertice (QMouseEvent *mouse_event)
 
void mousePressContextMenu (QMouseEvent *mouse_event)
 
void mousePressDeleteLastVertice (QMouseEvent *mouse_event)
 
void mousePressObjectsButton (QMouseEvent *mouse_event)
 
void mousePressRemoveObject ()
 
void mousePressSelectSecondTarget (QMouseEvent *mouse_event)
 
void mousePressSetRadiusFromPlot (QMouseEvent *mouse_event)
 
void moveRobot ()
 
void on_actionBeautify_triggered ()
 
void on_actionHelp_triggered ()
 
void on_addHillPushButton_clicked ()
 
void on_addTargetPushButton_clicked ()
 
void on_addTrappyCirclePushButton_clicked ()
 
void on_addTrappyLinePushButton_clicked ()
 
void on_calcTrajectoryPushButton_clicked ()
 
void on_editObjectsPushButton_clicked ()
 
void on_flyRobotPushButton_clicked ()
 
void on_HighSpeedButton_clicked ()
 
void on_hillAction_triggered ()
 
void on_hillAddFromTablePushButton_clicked ()
 
void on_homeScalePushButton_clicked ()
 
void on_LowSpeedButton_clicked ()
 
void on_MediumSpeedButton_clicked ()
 
void on_newFileAction_triggered ()
 Кнопка "New".
 
void on_openFileAction_triggered ()
 Кнопка "Open".
 
void on_robotsApplyAmountPushButton_clicked ()
 
bool on_saveAsFileAction_triggered ()
 Кнопка "Save as".
 
bool on_saveFileAction_triggered ()
 Кнопка "Save".
 
void on_targetAction_triggered ()
 
void on_targetAddFromTablePushButton_clicked ()
 
void on_trappyCircleAction_triggered ()
 
void on_trappyCircleAddFromTablePushButton_clicked ()
 
void on_trappyLineAction_triggered ()
 
void on_trappyLineAddFromTablePushButton_clicked ()
 
void on_xAxis_rangeChanged (QCPRange range)
 
void on_yAxis_rangeChanged (QCPRange range)
 

Private Member Functions

void CalcTrajectory ()
 
void DeCalcTrajectory ()
 
void DeleteLastAddedObject ()
 Удаляет последний добавленный объект с помощью кнопок слева, причем его добавление не закончилось. Она должна вызывается везде, где происходит взаимодействие пользователя с кнопками класса "MainWindow".
 
void FlyRobot ()
 
gui::ObjectType GetObjType () const
 
bool OpenMessageWindow ()
 Вызов окна, которое сообщает об изменениях в файле
 
void StopRobot ()
 

Private Attributes

std::unique_ptr< data_tools::PlotAreaarea_
 
CursorType cursor_ {CursorType::DefaultCursor}
 
bool is_drown_trajectory_ = false
 
bool is_robot_flying_ = false
 
GuiJsonFile json_file_
 
std::unique_ptr< data_tools::DataManagermanager_
 
std::unique_ptr< data_tools::TablesConnectiont_connection_
 
QTimer * timer_ {new QTimer(this)}
 
Ui::MainWindow * ui
 
WhatObjectAddition what_obj_addition_ {WhatObjectAddition::Nothing}
 

Constructor & Destructor Documentation

◆ MainWindow()

MainWindow::MainWindow ( QWidget * parent = nullptr)
5 : QMainWindow(parent),
6 ui(new Ui::MainWindow),
10 ui->setupUi(this);
11 ui->plotSettingsDockWidget->setVisible(false);
12
13 ui->plot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom |
14 QCP::iSelectPlottables | QCP::iSelectItems);
15
16 connect(ui->plot, &QCustomPlot::mousePress, this,
18
19 connect(ui->plot->xAxis, SIGNAL(rangeChanged(QCPRange)), this,
20 SLOT(on_xAxis_rangeChanged(QCPRange)));
21
22 connect(ui->plot->yAxis, SIGNAL(rangeChanged(QCPRange)), this,
23 SLOT(on_yAxis_rangeChanged(QCPRange)));
24
25 area_->Setup(manager_.get());
26 t_connection_->Setup(manager_.get(), area_.get());
27
28 area_->SetPlot(ui->plot);
29
31 ui->targetInfoTableWidget, ui->hillInfoTableWidget,
32 ui->trappyCircleInfoTableWidget, ui->trappyLineInfoTableWidget);
33
35 ui->targetRemovePushButton, ui->hillRemovePushButton,
36 ui->trappyCircleRemovePushButton, ui->trappyLineRemovePushButton);
37
39
40 QIntValidator* int_validator{new QIntValidator()};
41 int_validator->setRange(1, 9);
42 ui->robotsAmountLineEdit->setValidator(int_validator);
43
44 connect(ui->plotSettingsDockWidget, &QDockWidget::visibilityChanged, this,
45 [this](bool visible) {
46 if (is_drown_trajectory_)
47 ui->flyRobotPushButton->setEnabled(!visible);
48 });
49}
void SetUntitledFile()
Нужно для того, чтобы при открытии приложения менялось имя "Untitled" файла, так как может быть такое...
Definition new.cpp:8
void mousePressContextMenu(QMouseEvent *mouse_event)
Definition other_connections.cpp:174
std::unique_ptr< data_tools::PlotArea > area_
Definition mainwindow.h:113
std::unique_ptr< data_tools::DataManager > manager_
Definition mainwindow.h:114
Ui::MainWindow * ui
Definition mainwindow.h:110
void on_yAxis_rangeChanged(QCPRange range)
Definition other_connections.cpp:106
void on_xAxis_rangeChanged(QCPRange range)
Definition other_connections.cpp:86
GuiJsonFile json_file_
Definition mainwindow.h:117
std::unique_ptr< data_tools::TablesConnection > t_connection_
Definition mainwindow.h:115
Класс, хранящий gui объекты и связывающий их с QCustomPlot.
Definition data_manager.h:9
Класс, упрощающий управление классами gui на QCustomPlot.
Definition plot_area.h:9
void SetPlot(QCustomPlot *plot)
Устанавливает значение plot.
Definition plot_area.h:21
void Setup(DataManager *manager)
Definition plot_area.cpp:6
Класс, упрощающий отображение классов gui в QTableWidget's.
Definition tables_connection.h:12
void SetSettingsTables(QTableWidget *targets_info, QTableWidget *hills_info, QTableWidget *tr_circles_info, QTableWidget *tr_lines_info)
Устанавливает значения всех таблиц с информацией
Definition tables_connection.h:25
void SetRemoveButtons(QPushButton *targets_remove_button, QPushButton *hills_remove_button, QPushButton *tr_circles_remove_button, QPushButton *tr_lines_remove_button)
Устанавливает значение всех кнопок для удаления объектов
Definition tables_connection.h:42
void Setup(DataManager *manager, PlotArea *area)
Definition tables_connection.cpp:6
Here is the call graph for this function:

◆ ~MainWindow()

MainWindow::~MainWindow ( )
51{ delete ui; }

Member Function Documentation

◆ AddHill

void MainWindow::AddHill ( const std::vector< std::pair< double, double > > & points)
slot
43 {
44 try {
45 std::vector<lib::Point> lib_points;
46 for (const auto& point : points) {
47 lib_points.push_back({point.first, point.second});
48 }
49
50 manager_->Add(new gui::Hill(lib_points));
51
52 area_->ReDraw();
54
55 } catch (const std::exception& e) {
56 QMessageBox::critical(this, "Error!", e.what());
57 }
58}
void Add(gui::Target *t)
Definition data_manager.cpp:49
void ReDraw()
Перерисовывает на полотне все объекты и обновляет данные
Definition plot_area.cpp:8
void UpdateTable(gui::ObjectType obj_type)
Обновляет значения таблицы с определенным типом объекта
Definition tables_connection.cpp:232
Фигура рельефа с высотой
Definition hill.h:15
Here is the call graph for this function:
Here is the caller graph for this function:

◆ AddTarget

void MainWindow::AddTarget ( double x,
double y )
slot
4 {
5 try {
6 manager_->Add(new gui::Target(x, y));
7 area_->ReDraw();
9
10 } catch (const std::exception& e) {
11 QMessageBox::critical(this, "Error!", e.what());
12 }
13}
Фигура контрольной точки
Definition target.h:13
Here is the call graph for this function:
Here is the caller graph for this function:

◆ AddTrappyCircle

void MainWindow::AddTrappyCircle ( double x,
double y,
double radius )
slot
15 {
16 try {
17 manager_->Add(new gui::TrappyCircle(x, y, radius));
18 area_->ReDraw();
20
21 } catch (const std::exception& e) {
22 QMessageBox::critical(this, "Error!", e.what());
23 }
24}
Фигура опасной зоны
Definition trappy_circle.h:14
Here is the call graph for this function:
Here is the caller graph for this function:

◆ AddTrappyLine

void MainWindow::AddTrappyLine ( double x1,
double y1,
double x2,
double y2 )
slot
26 {
27 try {
28 manager_->Add(new gui::Target(x1, y1));
29 manager_->Add(new gui::Target(x2, y2));
30
33 manager_->GetTargetsPtrs()[manager_->GetTargets().size() - 1]));
34
35 area_->ReDraw();
37
38 } catch (const std::exception& e) {
39 QMessageBox::critical(this, "Error!", e.what());
40 }
41}
std::vector< gui::Target > GetTargets() const
Возвращает значение Targets.
Definition data_manager.cpp:136
std::vector< gui::Target * > GetTargetsPtrs()
Возвращает значение Targets.
Definition data_manager.cpp:127
Фигура линии опасного перелета
Definition trappy_line.h:14
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CalcTrajectory()

void MainWindow::CalcTrajectory ( )
private
39 {
41
43
44 if (area_->TrajectorySize()) ui->calcTrajectoryPushButton->setEnabled(false);
45
46 if (area_->TrajectorySize() && !ui->plotSettingsDockWidget->isVisible())
47 ui->flyRobotPushButton->setEnabled(true);
48}
bool is_drown_trajectory_
Definition mainwindow.h:122
size_t TrajectorySize() const
Definition plot_area.h:35
void ReDrawTrajectory()
Перерисовывает на полотне траекторию
Definition plot_area.cpp:27
Here is the call graph for this function:
Here is the caller graph for this function:

◆ closeEvent

void MainWindow::closeEvent ( QCloseEvent * event)
overrideprivateslot

Проверяет при закрытии приложения, есть ли изменения в текущем файле

35 {
37
38 bool is_closed = false;
39
41 is_closed = OpenMessageWindow();
42
43 else if (!json_file_.IsExistsFile() && (manager_->GetTargets().size() +
44 manager_->GetTrappyCircles().size() +
45 manager_->GetTrappyLines().size() +
46 manager_->GetHills().size()) != 0) {
47 is_closed = OpenMessageWindow();
48 }
49
50 if (is_closed)
51 event->ignore();
52 else
53 event->accept();
54}
bool IsChanged(data_tools::DataManager *plot_area) const
Definition new.cpp:31
bool IsExistsFile() const
Definition gui_json_file.h:32
bool OpenMessageWindow()
Вызов окна, которое сообщает об изменениях в файле
Definition menu_file_actions.cpp:8
void DeleteLastAddedObject()
Удаляет последний добавленный объект с помощью кнопок слева, причем его добавление не закончилось....
Definition interaction_buttons.cpp:49
std::vector< gui::Hill > GetHills() const
Возвращает значение Hills.
Definition data_manager.cpp:226
std::vector< gui::TrappyLine > GetTrappyLines() const
Возвращает значение TrappyLines.
Definition data_manager.cpp:406
std::vector< gui::TrappyCircle > GetTrappyCircles() const
Возвращает значение TrappyCircles.
Definition data_manager.cpp:316
Here is the call graph for this function:

◆ DeCalcTrajectory()

void MainWindow::DeCalcTrajectory ( )
private
50 {
52
54
55 ui->calcTrajectoryPushButton->setEnabled(true);
56
57 ui->flyRobotPushButton->setEnabled(false);
58
60}
bool is_robot_flying_
Definition mainwindow.h:121
void StopRobot()
Definition trajectory_and_robot.cpp:4
void ClearTrajectory()
Definition plot_area.h:33
Here is the call graph for this function:
Here is the caller graph for this function:

◆ DeleteLastAddedObject()

void MainWindow::DeleteLastAddedObject ( )
private

Удаляет последний добавленный объект с помощью кнопок слева, причем его добавление не закончилось. Она должна вызывается везде, где происходит взаимодействие пользователя с кнопками класса "MainWindow".

49 {
51 switch (what_obj_addition_) {
53 size_t last = manager_->GetTrappyCircles().size() - 1;
55 break;
56 }
57
59 size_t last = manager_->GetTrappyLines().size() - 1;
61 break;
62 }
63
65 size_t last = manager_->GetHills().size() - 1;
67 break;
68 }
69
70 default:
71 break;
72 }
73
74 area_->ReDraw();
76
78}
void DeCalcTrajectory()
Definition trajectory_and_robot.cpp:50
WhatObjectAddition what_obj_addition_
Definition mainwindow.h:119
void DisconnectObject(gui::ObjectType obj_type)
Definition interaction_buttons.cpp:4
gui::ObjectType GetObjType() const
Definition other_connections.cpp:5
void Remove(gui::ObjectType obj_type, size_t index)
Удаляет объект из менеджера по индексу
Definition data_manager.cpp:6
Here is the call graph for this function:
Here is the caller graph for this function:

◆ DisconnectObject

void MainWindow::DisconnectObject ( gui::ObjectType obj_type)
privateslot
4 {
5 switch (obj_type) {
7 disconnect(ui->plot, &QCustomPlot::mouseMove, this,
9 disconnect(ui->plot, &QCustomPlot::mouseDoubleClick, this,
11 break;
12 }
13
15 disconnect(ui->plot, &QCustomPlot::mouseDoubleClick, this,
17 break;
18 }
19
21 disconnect(ui->plot, &QCustomPlot::mouseDoubleClick, this,
23 disconnect(ui->plot, &QCustomPlot::mousePress, this,
25 disconnect(ui->plot, &QCustomPlot::mouseMove, this,
27 break;
28 }
29
30 default:
31 break;
32 }
33
34 disconnect(ui->plot, &QCustomPlot::mouseDoubleClick, this,
36
37 connect(ui->plot, &QCustomPlot::mousePress, this,
39
40 ui->plot->setCursor(Qt::CrossCursor);
42}
CursorType cursor_
Definition mainwindow.h:118
void mousePressObjectsButton(QMouseEvent *mouse_event)
Definition interaction_buttons.cpp:88
void mouseMoveSetRadiusFromPlot(QMouseEvent *mouse_event)
Definition interaction_buttons.cpp:190
void mousePressSelectSecondTarget(QMouseEvent *mouse_event)
Definition interaction_buttons.cpp:208
void mousePressSetRadiusFromPlot(QMouseEvent *mouse_event)
Definition interaction_buttons.cpp:178
void mousePressDeleteLastVertice(QMouseEvent *mouse_event)
Definition interaction_buttons.cpp:281
void mousePressAddVertice(QMouseEvent *mouse_event)
Definition interaction_buttons.cpp:235
void mouseMoveAddVertice(QMouseEvent *mouse_event)
Definition interaction_buttons.cpp:302
Here is the call graph for this function:
Here is the caller graph for this function:

◆ FlyRobot()

void MainWindow::FlyRobot ( )
private
20 {
21 if (!is_robot_flying_) {
22 connect(timer_, &QTimer::timeout, this, &MainWindow::moveRobot);
23 timer_->start(5);
24 is_robot_flying_ = true;
25
26 ui->flyRobotPushButton->setIcon(QPixmap("../images/stop_square.png"));
27
28 if (!area_->GetRobot()->GetTrajectory())
30
31 area_->GetRobot()->Draw(ui->plot);
32 ui->plot->replot();
33
34 ui->plotSettingsDockWidget->setVisible(false);
35 ui->editObjectsPushButton->setEnabled(false);
36 }
37}
QTimer * timer_
Definition mainwindow.h:111
void moveRobot()
Definition other_connections.cpp:191
gui::Trajectory * GetTrajectory()
Definition plot_area.h:28
gui::FlyingRobot * GetRobot()
Definition plot_area.h:26
gui::Trajectory * GetTrajectory() const
Definition flying_robot.h:46
void SetTrajectory(gui::Trajectory *trj)
Definition flying_robot.cpp:6
void Draw(QCustomPlot *plot) override
Отрисовывает png картинку
Definition flying_robot.cpp:126
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetObjType()

gui::ObjectType MainWindow::GetObjType ( ) const
private
Here is the caller graph for this function:

◆ keyPressEvent

void MainWindow::keyPressEvent ( QKeyEvent * key_event)
overrideprivateslot
80 {
81 if (key_event->key() == Qt::Key_Escape) {
82 // Проверка на то, что пользователь уже начал создавать объект,
83 // поэтому при нажатии Esc мы должны удалять последний добавленный объект
85 }
86}
Here is the call graph for this function:

◆ mouseMoveAddVertice

void MainWindow::mouseMoveAddVertice ( QMouseEvent * mouse_event)
privateslot
302 {
303 size_t last = manager_->GetHills().size() - 1;
304 size_t last_vertice =
305 manager_->GetHillsPtrs()[last]->GetVertices().size() - 1;
306
307 if (last_vertice > 0) {
308 double x = ui->plot->xAxis->pixelToCoord(mouse_event->pos().x());
309 double y = ui->plot->yAxis->pixelToCoord(mouse_event->pos().y());
310
311 manager_->GetHillsPtrs()[last]->GetVertices().erase(
312 manager_->GetHillsPtrs()[last]->GetVertices().begin() + last_vertice);
313
314 manager_->GetHillsPtrs()[last]->AddVertice({x, y});
315 area_->ReDraw();
316 }
317}
std::vector< gui::Hill * > GetHillsPtrs()
Возвращает значение Hills.
Definition data_manager.cpp:217
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mouseMoveSetRadiusFromPlot

void MainWindow::mouseMoveSetRadiusFromPlot ( QMouseEvent * mouse_event)
privateslot
190 {
191 size_t last = manager_->GetTrappyCircles().size() - 1;
192
193 // Расстояние от центра до курсора (по оси x)
194 double x = abs(ui->plot->xAxis->pixelToCoord(mouse_event->pos().x()) -
195 manager_->GetTrappyCircles()[last].GetCenter().x);
196
197 // Расстояние от центра до курсора (по оси y)
198 double y = abs(ui->plot->yAxis->pixelToCoord(mouse_event->pos().y()) -
199 manager_->GetTrappyCircles()[last].GetCenter().y);
200
201 // Значение радиуса
202 double r = sqrt(pow(x, 2) + pow(y, 2));
203
204 manager_->GetTrappyCirclesPtrs()[last]->SetRadius(r);
205 area_->ReDraw();
206}
std::vector< gui::TrappyCircle * > GetTrappyCirclesPtrs()
Возвращает значение TrappyCircles.
Definition data_manager.cpp:307
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mousePressAddVertice

void MainWindow::mousePressAddVertice ( QMouseEvent * mouse_event)
privateslot
235 {
236 if (mouse_event->button() == Qt::LeftButton) {
237 // Позиция курсора в пикселях
238 int x_pixels = mouse_event->pos().x();
239 int y_pixels = mouse_event->pos().y();
240
241 // Позиция курсора в координатах
242 double x = ui->plot->xAxis->pixelToCoord(x_pixels);
243 double y = ui->plot->yAxis->pixelToCoord(y_pixels);
244
245 size_t last = manager_->GetHills().size() - 1;
246
247 // Позиция начальной точки в пикселях
248 double x2_pixels = ui->plot->xAxis->coordToPixel(
249 manager_->GetHills()[last].GetVertices()[0].x);
250 double y2_pixels = ui->plot->yAxis->coordToPixel(
251 manager_->GetHills()[last].GetVertices()[0].y);
252
253 // Проверка на то, что расстояние от курсора до начальной точки меньше 10
254 // пикселей. Если это так, то мы считаем, что он завершил создание Hill
255 if (sqrt(pow(x_pixels - x2_pixels, 2) + pow(y_pixels - y2_pixels, 2)) <
256 10 &&
257 manager_->GetHills()[last].GetVertices().size() > 3) {
258 size_t last_vertice =
259 manager_->GetHillsPtrs()[last]->GetVertices().size() - 1;
260 manager_->GetHillsPtrs()[last]->GetVertices().erase(
261 manager_->GetHillsPtrs()[last]->GetVertices().begin() + last_vertice);
264
265 // после финального добавления обновляем таблицу
267
268 } else if (manager_->GetHills()[last].GetVertices()[0] ==
269 manager_->GetHills()[last].GetVertices()[1]) {
270 size_t last_p = manager_->GetHills()[last].GetVertices().size() - 1;
271 manager_->GetHillsPtrs()[last]->GetVertices()[last_p].x = x;
272 manager_->GetHillsPtrs()[last]->GetVertices()[last_p].y = y;
273
274 } else
275 manager_->GetHillsPtrs()[last]->AddVertice({x, y});
276
277 area_->ReDraw();
278 }
279}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mousePressContextMenu

void MainWindow::mousePressContextMenu ( QMouseEvent * mouse_event)
privateslot
174 {
175 if (mouse_event->button() == Qt::RightButton &&
176 (!ui->plot->selectedGraphs().empty() ||
177 !ui->plot->selectedItems().empty() ||
178 !ui->plot->selectedPlottables().empty())) {
179 ui->plot->setContextMenuPolicy(Qt::ActionsContextMenu);
180
181 QMenu* menu{new QMenu(this)};
182 QAction* remove_button{new QAction("Remove", this)};
183 menu->addAction(remove_button);
184 connect(remove_button, &QAction::triggered, this,
186
187 menu->exec(mouse_event->globalPosition().toPoint());
188 }
189}
void mousePressRemoveObject()
Definition other_connections.cpp:126
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mousePressDeleteLastVertice

void MainWindow::mousePressDeleteLastVertice ( QMouseEvent * mouse_event)
privateslot
281 {
282 if (mouse_event->button() == Qt::RightButton) {
283 size_t last = manager_->GetHills().size() - 1;
284 size_t vertices_size = manager_->GetHills()[last].GetVertices().size();
285 if (vertices_size > 2)
286 manager_->GetHillsPtrs()[last]->GetVertices().pop_back();
287
288 else {
289 if (manager_->GetHills()[last].GetVertices()[0] !=
290 manager_->GetHills()[last].GetVertices()[1]) {
291 manager_->GetHillsPtrs()[last]->GetVertices()[1] =
292 manager_->GetHills()[last].GetVertices()[0];
293
294 } else
296 }
297
298 area_->ReDraw();
299 }
300}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mousePressObjectsButton

void MainWindow::mousePressObjectsButton ( QMouseEvent * mouse_event)
privateslot
88 {
89 if (mouse_event->button() != Qt::LeftButton) return;
90 disconnect(ui->plot, &QCustomPlot::mouseDoubleClick, this,
92
93 double x = ui->plot->xAxis->pixelToCoord(mouse_event->pos().x());
94 double y = ui->plot->yAxis->pixelToCoord(mouse_event->pos().y());
95
96 try {
97 switch (cursor_) {
99 manager_->Add(new gui::Target(x, y));
100
101 ui->plot->setCursor(Qt::CrossCursor);
103
104 // после финального добавления обновляем таблицу
106
107 break;
108 }
109
111 manager_->Add(new gui::TrappyCircle({x, y}, 0));
112 disconnect(ui->plot, &QCustomPlot::mouseDoubleClick, this,
114 disconnect(ui->plot, &QCustomPlot::mousePress, this,
116
117 connect(ui->plot, &QCustomPlot::mouseMove, this,
119 connect(ui->plot, &QCustomPlot::mouseDoubleClick, this,
121
122 ui->plot->setCursor(Qt::ClosedHandCursor);
124 break;
125 }
126
128 if (ui->plot->selectedGraphs().empty()) return;
129
130 for (const auto& t_ptr : manager_->GetTargetsPtrs()) {
131 if (t_ptr->GetGraphPtr() == ui->plot->selectedGraphs()[0]) {
132 manager_->Add(new gui::TrappyLine(t_ptr, t_ptr));
133 disconnect(ui->plot, &QCustomPlot::mouseDoubleClick, this,
135 disconnect(ui->plot, &QCustomPlot::mousePress, this,
137
138 connect(ui->plot, &QCustomPlot::mouseDoubleClick, this,
140
142 break;
143 }
144 }
145 break;
146 }
147
149 manager_->Add(new gui::Hill{{x, y}, {x, y}});
150
151 disconnect(ui->plot, &QCustomPlot::mouseDoubleClick, this,
153 disconnect(ui->plot, &QCustomPlot::mousePress, this,
155
156 connect(ui->plot, &QCustomPlot::mouseDoubleClick, this,
158 connect(ui->plot, &QCustomPlot::mousePress, this,
160 connect(ui->plot, &QCustomPlot::mouseMove, this,
162
164 break;
165 }
166
167 default:
168 break;
169 }
170
171 area_->ReDraw();
172
173 } catch (const std::exception& e) {
174 QMessageBox::critical(this, "Error!", e.what());
175 }
176}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mousePressRemoveObject

void MainWindow::mousePressRemoveObject ( )
privateslot
126 {
128
129 if (ui->plot->selectedGraphs().size() > 0) {
130 bool is_found = false;
131 for (size_t i = 0; i < manager_->GetTargets().size(); i++) {
132 if (ui->plot->selectedGraphs()[0] ==
133 manager_->GetTargetsPtrs()[i]->GetGraphPtr()) {
136 is_found = true;
137 break;
138 }
139 }
140
141 if (!is_found)
142 for (size_t i = 0; i < manager_->GetTrappyLines().size(); i++) {
143 if (ui->plot->selectedGraphs()[0] ==
144 manager_->GetTrappyLinesPtrs()[i]->GetGraphPtr()) {
147 break;
148 }
149 }
150
151 } else if (ui->plot->selectedPlottables().size() > 0) {
152 for (size_t i = 0; i < manager_->GetHills().size(); i++) {
153 if (ui->plot->selectedPlottables()[0] ==
154 manager_->GetHillsPtrs()[i]->GetCurvePtr()) {
157 break;
158 }
159 }
160
161 } else if (ui->plot->selectedItems().size() > 0)
162 for (size_t i = 0; i < manager_->GetTrappyCircles().size(); i++) {
163 if (ui->plot->selectedItems()[0] ==
164 manager_->GetTrappyCirclesPtrs()[i]->GetItemEllipsePtr()) {
167 break;
168 }
169 }
170
171 area_->ReDraw();
172}
std::vector< gui::TrappyLine * > GetTrappyLinesPtrs()
Возвращает значение TrappyLines.
Definition data_manager.cpp:397
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mousePressSelectSecondTarget

void MainWindow::mousePressSelectSecondTarget ( QMouseEvent * mouse_event)
privateslot
208 {
209 if (mouse_event->button() != Qt::LeftButton) return;
210 if (ui->plot->selectedGraphs().empty()) return;
211
212 for (const auto& t_ptr : manager_->GetTargetsPtrs()) {
213 if (t_ptr->GetGraphPtr() != ui->plot->selectedGraphs()[0]) continue;
214
215 size_t last = manager_->GetTrappyLines().size() - 1;
216
217 // если это та же точка - пропускаем
218 if (manager_->GetTrappyLinesPtrs()[last]->GetTargetsPtrs().second == t_ptr)
219 continue;
220
221 manager_->GetTrappyLinesPtrs()[last]->SetSecondTarget(t_ptr);
222
225
226 area_->ReDraw();
227
228 // после финального добавления обновляем таблицу
230
231 return;
232 }
233}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mousePressSetRadiusFromPlot

void MainWindow::mousePressSetRadiusFromPlot ( QMouseEvent * mouse_event)
privateslot
178 {
179 if (mouse_event->button() == Qt::LeftButton) {
182
183 area_->ReDraw();
184
185 // после финального добавления обновляем таблицу
187 }
188}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ moveRobot

void MainWindow::moveRobot ( )
privateslot
191{ area_->GetRobot()->ReDraw(ui->plot); }
void ReDraw(QCustomPlot *plot)
Эта функция нужна для того, чтобы обновлять позицию картинки на полотне
Definition flying_robot.cpp:138
Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_actionBeautify_triggered

void MainWindow::on_actionBeautify_triggered ( )
privateslot
65 {
66 ui->plot->xAxis->setScaleRatio(ui->plot->yAxis);
67 ui->plot->replot();
68}
Here is the caller graph for this function:

◆ on_actionHelp_triggered

void MainWindow::on_actionHelp_triggered ( )
privateslot
193 {
194 QDesktopServices::openUrl(
195 QUrl("https://umbrellaleaf5.github.io/locus_no_pilotus/index.html"));
196}

◆ on_addHillPushButton_clicked

void MainWindow::on_addHillPushButton_clicked ( )
privateslot
48 {
50 connect(ui->plot, &QCustomPlot::mouseDoubleClick, this,
52
53 ui->plot->setCursor(QCursor(QPixmap("../images/move_cursor.png")
54 .scaled(QSize(24, 24), Qt::KeepAspectRatio)));
56}
Here is the call graph for this function:

◆ on_addTargetPushButton_clicked

void MainWindow::on_addTargetPushButton_clicked ( )
privateslot
18 {
20 connect(ui->plot, &QCustomPlot::mouseDoubleClick, this,
22
23 ui->plot->setCursor(QCursor(QPixmap("../images/better_cross_cursor.png")
24 .scaled(QSize(24, 24), Qt::KeepAspectRatio)));
26}
Here is the call graph for this function:

◆ on_addTrappyCirclePushButton_clicked

void MainWindow::on_addTrappyCirclePushButton_clicked ( )
privateslot
28 {
30 connect(ui->plot, &QCustomPlot::mouseDoubleClick, this,
32
33 ui->plot->setCursor(QCursor(QPixmap("../images/move_cursor.png")
34 .scaled(QSize(24, 24), Qt::KeepAspectRatio)));
36}
Here is the call graph for this function:

◆ on_addTrappyLinePushButton_clicked

void MainWindow::on_addTrappyLinePushButton_clicked ( )
privateslot
38 {
40 connect(ui->plot, &QCustomPlot::mouseDoubleClick, this,
42
43 ui->plot->setCursor(QCursor(QPixmap("../images/choose_cursor.png")
44 .scaled(QSize(24, 24), Qt::KeepAspectRatio)));
46}
Here is the call graph for this function:

◆ on_calcTrajectoryPushButton_clicked

void MainWindow::on_calcTrajectoryPushButton_clicked ( )
privateslot
62 {
66 area_->ReDraw();
67
69}
void CalcTrajectory()
Definition trajectory_and_robot.cpp:39
bool RemoveAllDuplicates()
Удаляет все повторяющиеся объекты в векторах объектов
Definition data_manager.cpp:455
void UpdateTables()
Обновляет данные в таблицах всех объектов
Definition tables_connection.cpp:252
Here is the call graph for this function:

◆ on_editObjectsPushButton_clicked

void MainWindow::on_editObjectsPushButton_clicked ( )
privateslot
58 {
59 ui->plotSettingsDockWidget->setVisible(true);
61
62 ui->flyRobotPushButton->setEnabled(false);
63}
void on_actionBeautify_triggered()
Definition other_connections.cpp:65
Here is the call graph for this function:

◆ on_flyRobotPushButton_clicked

void MainWindow::on_flyRobotPushButton_clicked ( )
privateslot
71 {
72 try {
74 StopRobot();
75 else
76 FlyRobot();
77
78 } catch (const std::exception& e) {
79 QMessageBox::warning(this, "Cannot add Robot!", e.what());
80 }
81}
void FlyRobot()
Definition trajectory_and_robot.cpp:20
Here is the call graph for this function:

◆ on_HighSpeedButton_clicked

void MainWindow::on_HighSpeedButton_clicked ( )
privateslot
218 {
220}
void SetSpeed(SpeedOfRobot speed)
Definition flying_robot.h:48
Here is the call graph for this function:

◆ on_hillAction_triggered

void MainWindow::on_hillAction_triggered ( )
privateslot
86 {
88
89 AddHillForm* adh = new AddHillForm;
90 adh->show();
91 connect(adh, &AddHillForm::AddHill, this, &MainWindow::AddHill);
92}
Definition add_hill_form.h:33
void AddHill(const std::vector< std::pair< double, double > > &points)
void AddHill(const std::vector< std::pair< double, double > > &points)
Definition menu_add_actions.cpp:43
Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_hillAddFromTablePushButton_clicked

void MainWindow::on_hillAddFromTablePushButton_clicked ( )
privateslot
74 {
76}
void on_hillAction_triggered()
Definition menu_add_actions.cpp:86
Here is the call graph for this function:

◆ on_homeScalePushButton_clicked

void MainWindow::on_homeScalePushButton_clicked ( )
privateslot
319 {
320 lib::Point first_target = {0, 0};
321 double max_distance = 10;
322
323 if (!manager_->GetTargets().empty()) {
324 first_target = manager_->GetTargets()[0].GetPoint();
325 if (manager_->GetTargets().size() > 1)
326 for (size_t i = 1; i < manager_->GetTargets().size(); i++) {
327 double distance = lib::DistanceBetweenPoints(
328 first_target, manager_->GetTargets()[i].GetPoint());
329 if (max_distance < distance) max_distance = distance;
330 }
331 }
332
333 if (first_target.x - max_distance <= -max_scale ||
334 first_target.x + max_distance >= max_scale ||
335 first_target.y - max_distance <= -max_scale ||
336 first_target.y + max_distance >= max_scale)
337 max_distance /= 2.;
338 ui->plot->xAxis->setRange(first_target.x - max_distance,
339 first_target.x + max_distance);
340 ui->plot->yAxis->setRange(first_target.y - max_distance,
341 first_target.y + max_distance);
343}
constexpr double max_scale
Definition mainwindow.h:22
double DistanceBetweenPoints(const Point &first_point, const Point &second_point)
Находит расстояние между двумя мат. точками
Definition point.cpp:27
Математическая точка
Definition point.h:16
double y
Definition point.h:18
double x
Definition point.h:17
Here is the call graph for this function:

◆ on_LowSpeedButton_clicked

void MainWindow::on_LowSpeedButton_clicked ( )
privateslot
Here is the call graph for this function:

◆ on_MediumSpeedButton_clicked

void MainWindow::on_MediumSpeedButton_clicked ( )
privateslot
Here is the call graph for this function:

◆ on_newFileAction_triggered

void MainWindow::on_newFileAction_triggered ( )
privateslot

Кнопка "New".

57 {
59
60 bool is_closed = false;
61
63 is_closed = OpenMessageWindow();
64
65 else if (!json_file_.IsExistsFile() && (manager_->GetTargets().size() +
66 manager_->GetTrappyCircles().size() +
67 manager_->GetTrappyLines().size() +
68 manager_->GetHills().size()) != 0)
69 is_closed = OpenMessageWindow();
70
71 if (!is_closed) {
72 manager_->Clear();
74 area_->ReDraw();
76 }
77}
void Clear()
Очищает все вектора объектов
Definition data_manager.cpp:38
Here is the call graph for this function:

◆ on_openFileAction_triggered

void MainWindow::on_openFileAction_triggered ( )
privateslot

Кнопка "Open".

80 {
82
83 bool is_closed = false;
84
86 is_closed = OpenMessageWindow();
87
88 else if (!json_file_.IsExistsFile() && (manager_->GetTargets().size() +
89 manager_->GetTrappyCircles().size() +
90 manager_->GetTrappyLines().size() +
91 manager_->GetHills().size()) != 0)
92 is_closed = OpenMessageWindow();
93
94 if (is_closed) return;
95
96 QString file_name = QFileDialog::getOpenFileName(
97 this, tr("Open"), json_file_.GetParentPath(), tr("File (*.json)"));
98
99 if (file_name.isEmpty()) return;
100
101 QString old_filename = json_file_.GetAbsolutePath();
102
103 try {
104 json_file_.SetFile(file_name);
105 manager_->Clear();
106 json_file_.Open(manager_.get());
107
108 } catch (const std::exception& e) {
109 QMessageBox::critical(this, "Error!", e.what());
111 manager_->Clear();
112 json_file_.SetFile(old_filename);
113 json_file_.Open(manager_.get());
114 }
115
116 area_->ReDraw();
118}
QString GetAbsolutePath() const
Definition gui_json_file.h:20
void Open(data_tools::DataManager *plot_area)
Definition open.cpp:41
void Close()
Definition gui_json_file.h:13
QString GetParentPath() const
Definition gui_json_file.h:24
void SetFile(const QString &file_name)
Definition gui_json_file.h:29
Here is the call graph for this function:

◆ on_robotsApplyAmountPushButton_clicked

void MainWindow::on_robotsApplyAmountPushButton_clicked ( )
privateslot
198 {
200 area_->ReDraw();
201 unsigned short amount = ui->robotsAmountLineEdit->displayText().toUShort();
202
203 if (amount > 0)
204 area_->SetAmountOfRobots(amount);
205 else
206 QMessageBox::warning(this, "Zero flying robot!",
207 "Flying robots must be at list 1!");
208}
void SetAmountOfRobots(unsigned short amount)
Definition plot_area.h:37
Here is the call graph for this function:

◆ on_saveAsFileAction_triggered

bool MainWindow::on_saveAsFileAction_triggered ( )
privateslot

Кнопка "Save as".

Returns
true: закрыто окно сохранения файла
139 {
141
142 QString file_name = QFileDialog::getSaveFileName(
143 this, tr("Save as"), json_file_.GetAbsolutePath(), tr("File (*.json)"));
144
145 if (!file_name.isEmpty()) {
146 json_file_.SetFile(file_name);
147 json_file_.Save(manager_.get());
148 return false;
149 }
150 return true;
151}
void Save(data_tools::DataManager *plot_area)
Definition save.cpp:4
Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_saveFileAction_triggered

bool MainWindow::on_saveFileAction_triggered ( )
privateslot

Кнопка "Save".

Returns
true: закрыто окно сохранения файла
124 {
126
129 else {
130 json_file_.Save(manager_.get());
131 return false;
132 }
133}
bool on_saveAsFileAction_triggered()
Кнопка "Save as".
Definition menu_file_actions.cpp:139
Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_targetAction_triggered

void MainWindow::on_targetAction_triggered ( )
privateslot
60 {
62
64 atf->show();
66}
Definition add_target_form.h:12
void AddTarget(double x, double y)
void AddTarget(double x, double y)
Definition menu_add_actions.cpp:4
Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_targetAddFromTablePushButton_clicked

void MainWindow::on_targetAddFromTablePushButton_clicked ( )
privateslot
70 {
72}
void on_targetAction_triggered()
Definition menu_add_actions.cpp:60
Here is the call graph for this function:

◆ on_trappyCircleAction_triggered

void MainWindow::on_trappyCircleAction_triggered ( )
privateslot
68 {
70
72 adf->show();
73 connect(adf, &AddTrappyCircleForm::AddTrappyCircle, this,
75}
Definition add_trappy_circle_form.h:12
void AddTrappyCircle(double x, double y, double radius)
void AddTrappyCircle(double x, double y, double radius)
Definition menu_add_actions.cpp:15
Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_trappyCircleAddFromTablePushButton_clicked

void MainWindow::on_trappyCircleAddFromTablePushButton_clicked ( )
privateslot
78 {
80}
void on_trappyCircleAction_triggered()
Definition menu_add_actions.cpp:68
Here is the call graph for this function:

◆ on_trappyLineAction_triggered

void MainWindow::on_trappyLineAction_triggered ( )
privateslot
77 {
79
81 adl->show();
82 connect(adl, &AddTrappyLineForm::AddTrappyLine, this,
84}
Definition add_trappy_line_form.h:12
void AddTrappyLine(double x1, double y1, double x2, double y2)
void AddTrappyLine(double x1, double y1, double x2, double y2)
Definition menu_add_actions.cpp:26
Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_trappyLineAddFromTablePushButton_clicked

void MainWindow::on_trappyLineAddFromTablePushButton_clicked ( )
privateslot
82 {
84}
void on_trappyLineAction_triggered()
Definition menu_add_actions.cpp:77
Here is the call graph for this function:

◆ on_xAxis_rangeChanged

void MainWindow::on_xAxis_rangeChanged ( QCPRange range)
privateslot
86 {
87 if (range.upper > max_scale) {
88 range.upper = max_scale;
89 range.lower = max_scale - (range.upper - range.lower);
90 }
91
92 if (range.lower < -max_scale) {
93 range.lower = -max_scale;
94 range.upper = -max_scale + (range.upper - range.lower);
95 }
96
97 if (range.upper - range.lower < min_scale) {
98 double mid = (range.upper + range.lower) / 2;
99 range.lower = mid - min_scale / 2;
100 range.upper = mid + min_scale / 2;
101 }
102
103 ui->plot->xAxis->setRange(range);
104}
constexpr double min_scale
Definition mainwindow.h:23
Here is the caller graph for this function:

◆ on_yAxis_rangeChanged

void MainWindow::on_yAxis_rangeChanged ( QCPRange range)
privateslot
106 {
107 if (range.upper > max_scale) {
108 range.upper = max_scale;
109 range.lower = max_scale - (range.upper - range.lower);
110 }
111
112 if (range.lower < -max_scale) {
113 range.lower = -max_scale;
114 range.upper = -max_scale + (range.upper - range.lower);
115 }
116
117 if (range.upper - range.lower < min_scale) {
118 double mid = (range.upper + range.lower) / 2;
119 range.lower = mid - min_scale / 2;
120 range.upper = mid + min_scale / 2;
121 }
122
123 ui->plot->yAxis->setRange(range);
124}
Here is the caller graph for this function:

◆ OpenMessageWindow()

bool MainWindow::OpenMessageWindow ( )
private

Вызов окна, которое сообщает об изменениях в файле

Returns
true: если окно было закрыто
8 {
9 QString text =
10 "Do you want save changes in file " + json_file_.GetFileName() + "?";
11 int ret = QMessageBox::question(
12 this, "Are you sure?", text,
13 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
14
15 switch (ret) {
16 case QMessageBox::Save: {
17 bool is_closed = on_saveFileAction_triggered();
18 if (is_closed) return true;
19 break;
20 }
21
22 case QMessageBox::Discard:
23 break;
24
25 case QMessageBox::Cancel:
26 case QMessageBox::Close:
27 return true;
28 break;
29 }
30
31 return false;
32}
QString GetFileName() const
Definition gui_json_file.h:15
bool on_saveFileAction_triggered()
Кнопка "Save".
Definition menu_file_actions.cpp:124
Here is the call graph for this function:
Here is the caller graph for this function:

◆ StopRobot()

void MainWindow::StopRobot ( )
private
4 {
6 disconnect(timer_, &QTimer::timeout, this, &MainWindow::moveRobot);
7 timer_->stop();
8 is_robot_flying_ = false;
9
10 ui->flyRobotPushButton->setIcon(QPixmap("../images/play_triangle.png"));
11 area_->ReDraw();
13 area_->GetRobot()->SetTrajectory(nullptr);
14 ui->plot->replot();
15
16 ui->editObjectsPushButton->setEnabled(true);
17 }
18}
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ area_

std::unique_ptr<data_tools::PlotArea> MainWindow::area_
private

◆ cursor_

CursorType MainWindow::cursor_ {CursorType::DefaultCursor}
private

◆ is_drown_trajectory_

bool MainWindow::is_drown_trajectory_ = false
private

◆ is_robot_flying_

bool MainWindow::is_robot_flying_ = false
private

◆ json_file_

GuiJsonFile MainWindow::json_file_
private

◆ manager_

std::unique_ptr<data_tools::DataManager> MainWindow::manager_
private

◆ t_connection_

std::unique_ptr<data_tools::TablesConnection> MainWindow::t_connection_
private

◆ timer_

QTimer* MainWindow::timer_ {new QTimer(this)}
private
111{new QTimer(this)};

◆ ui

Ui::MainWindow* MainWindow::ui
private

◆ what_obj_addition_

WhatObjectAddition MainWindow::what_obj_addition_ {WhatObjectAddition::Nothing}
private

The documentation for this class was generated from the following files: