NeTrainSim 0.1.1 beta
The Open-Source Network Trains Simulator
 
Loading...
Searching...
No Matches
netrainsimmainwindow.h
Go to the documentation of this file.
1
6#ifndef NETRAINSIMMAINWINDOW_H
7#define NETRAINSIMMAINWINDOW_H
8
9#include "qtrpt.h"
10#include "qlineedit.h"
11#include "gui/aboutwindow.h"
12#include "gui/customplot.h"
13#include <QMainWindow>
14#include "../NeTrainSim/util/map.h"
15#include <iostream>
16//#include "qtrpt/QtRPT/qtrpt.h"
17#include "simulationworker.h"
19#include "settingswindow.h"
20
21QT_BEGIN_NAMESPACE
22namespace Ui { class NeTrainSim; }
23QT_END_NAMESPACE
24
39class NeTrainSim : public QMainWindow
40{
41 Q_OBJECT
42
43signals:
54 void nodesDataChanged(QVector<double>& xData, QVector<double>& yData, QVector<QString>& labels);
55
64 void linksDataChanged(QVector<QString>& startNodeID, QVector<QString> endNodeID);
65
66public slots:
77 void setNodesData(QVector<double>& xData, QVector<double>& yData, QVector<QString>& labels);
78
88 void setLinksData(QVector<QString>& startNodeIDs, QVector<QString> endNodeIDs);
89
98 void updateTrainsPlot(Vector<std::pair<std::string, Vector<std::pair<double,double>>>> trainsStartEndPoints);
99
106 void closeApplication();
107
114 void clearForm();
115
122 void handleSampleProject();
123
124 void pauseSimulation();
125 void resumeSimulation();
126
127private slots:
134 void showReport();
135
147 void setValue(const int recNo, const QString paramName, QVariant &paramValue, const int reportPage);
148
157 void setDSInfo(DataSetInfo &dsInfo);
158
167 void handleError(std::string error);
168
178 void handleSimulationFinished(Vector<std::pair<string, string> > summaryData, std::string trajectoryFile);
179
186 void updateCombo_visualizeTrains();
187
196 void trainPointSelected(QPointF selectedPoint);
197
206 void trainPointDeleted(QPointF selectedPoint);
207
208
209public:
210
215
217
224 void loadDefaults();
225
231 bool saveDefaults(QStringList defaults);
232
241 NeTrainSim(QWidget *parent = nullptr);
242
249 ~NeTrainSim();
250
258 void showNotification(QString text);
259
267 void showWarning(QString text);
268
276 void loadProjectFiles(QString projectFilename);
277
278
279private:
280 // The user interface
281 Ui::NeTrainSim *ui;
282
283 // Pointer to the SimulationWorker object used for running the simulation in a separate thread.
284 SimulationWorker* worker = nullptr;
285
286 // Pointer to the QThread object that is used for running the simulation worker.
287 QThread* thread = nullptr;
288
289 // Vector to hold the labels displayed on the plot.
290 // Each label is represented by a QCPItemText object.
291 QVector<QCPItemText*> labelsVector;
292
293 // Map to hold the coordinates of the network nodes.
294 // The keys are node IDs (QString), and the values are pairs of x
295 // and y coordinates (std::pair<double, double>).
297
298 // QVector to store the x-coordinates of the nodes.
299 QVector<double> nodesXData;
300
301 // QVector to store the y-coordinates of the nodes.
302 QVector<double> nodesYData;
303
304 // QVector to store the labels of the nodes.
305 QVector<QString> nodesLabelData;
306
307 // QVector to store the start node IDs of the links.
308 QVector<QString> linksStartNodeIDs;
309
310 // QVector to store the end node IDs of the links.
311 QVector<QString> linksEndNodeIDs;
312
313 // Pointer to the AboutWindow object used to display information about the application.
314 std::shared_ptr<AboutWindow> aboutWindow = nullptr;
315
316 std::shared_ptr<settingsWindow> theSettingsWindow = nullptr;
317
318 // String to store the project name.
319 QString projectName;
320
321 // String to store the author's name.
322 QString author;
323
324 // String to store the network name.
325 QString networkName;
326
327 // String to store the filename of the nodes data.
328 QString nodesFilename;
329
330 // String to store the filename of the links data.
331 QString linksFilename;
332
333 // String to store the filename of the trains data.
334 QString trainsFilename;
335
336 // String to store the filename of the project file.
337 QString projectFileName;
338
339 // Vector of pairs to store the summary data of the trains after simulation.
340 // Each pair represents the train ID (std::string) and its corresponding summary data (std::string).
342
343 // holds the summary report
344 QtRPT * report = nullptr;
345
346 // holds the summary report printer
347 QPrinter *printer = nullptr;
348
349 ConfigurationManager* configManager;
350
351 void showDetailedReport(QString trajectoryFilename);
352
353 void drawLineGraph(CustomPlot &plot, const QVector<double> &xData,
354 const QVector<double> &yData, QString xLabel,
355 QString yLabel, QString graphName, int plotIndex);
356
357
358
359 void saveProjectFile(bool saveAs = false);
360
367 void setupGenerals();
368
369
376 void setupPage0();
377
384 void setupPage1();
385
392 void setupPage2();
393
400 void setupPage3();
401
408 void setupPage4();
409
414 void setupNodesTable();
415
420 void setupLinksTable();
421
426 void setupLocomotivesTable();
427
432 void setupCarsTable();
433
438 void setupConfigurationsTable();
439
444 void setupTrainsTable();
445
453 Vector<std::tuple<int, double, double, std::string,
454 double, double>> getNodesDataFromNodesTable();
455
464 std::tuple<QVector<double>, QVector<double>, QVector<QString>>
465 getNodesPlottableData(Vector<std::tuple<int, double,
466 double, std::string, double, double>>& nodeRecords);
467
479 void updateNodesPlot(CustomPlot& plot, QVector<double> xData,
480 QVector<double> yData, QVector<QString> labels,
481 bool showLabels = false);
482
491 Vector<std::tuple<int, int, int, double, int,
492 double, double, int, double, bool,
493 std::string, std::string,
494 double>> getLinkesDataFromLinksFile(QString fileName);
495
503 Vector<std::tuple<int, int, int, double, int, double, double,
504 int, double, bool,std::string, std::string,
505 double>> getLinkesDataFromLinksTable();
506
515 std::tuple<QVector<QString>, QVector<QString>>
516 getLinksPlottableData(Vector<std::tuple<int, int, int,
517 double, int, double,
518 double, int, double, bool,
519 std::string, std::string,
520 double>> linksRecords);
521
531 void updateLinksPlot(CustomPlot& plot, QVector<QString> startNodeIDs, QVector<QString> endNodeIDs);
532
540 QString browseFiles(QLineEdit* theLineEdit, const QString& theFileName);
541
550 Vector<std::tuple<int, double, double, std::string, double,
551 double>> getNodesDataFromNodesFile(QString fileName);
552
559 void browseFolder(QLineEdit* theLineEdit, const QString& theHelpMessage);
560
569 Vector<std::tuple<
570 int, double, double,
571 int, double, double,
572 double, double, int>>,
573 Vector<std::tuple<int, int, double, double,
574 double, double,
575 double, int>>,
576 bool>> getTrainsDataFromTables();
577
582 void simulate();
583
591 QCPItemText* findLabelByPosition(CustomPlot* plot, const QPointF& targetPosition);
592
593
594
595protected:
603 void closeEvent(QCloseEvent* event) override;
604};
605#endif // NETRAINSIMMAINWINDOW_H
This file contains the declaration of the AboutWindow class.
Definition configurationmanager.h:9
The CustomPlot class is a subclass of QCustomPlot, providing additional functionality and customizati...
Definition customplot.h:18
A map.
Definition map.h:26
A network train simulation GUI.
Definition netrainsimmainwindow.h:40
void linksDataChanged(QVector< QString > &startNodeID, QVector< QString > endNodeID)
Signal emitted when the links data is changed.
void resumeSimulation()
Definition netrainsimmainwindow.cpp:2437
void handleSampleProject()
Slot for handling loading the sample project files.
Definition netrainsimmainwindow.cpp:2314
void closeEvent(QCloseEvent *event) override
Event handler for the close event of the NeTrainSim window.
Definition netrainsimmainwindow.cpp:2248
void showNotification(QString text)
Displays a notification with the given text for 3000 millisecond.
Definition netrainsimmainwindow.cpp:1713
void setNodesData(QVector< double > &xData, QVector< double > &yData, QVector< QString > &labels)
Slot for setting the nodes data.
Definition netrainsimmainwindow.cpp:1681
void clearForm()
Slot for clearing the form.
Definition netrainsimmainwindow.cpp:2267
void showWarning(QString text)
Displays a warning message with the given text.
Definition netrainsimmainwindow.cpp:1718
void setLinksData(QVector< QString > &startNodeIDs, QVector< QString > endNodeIDs)
Slot for setting the links data.
Definition netrainsimmainwindow.cpp:1703
QString defaultBrowsePath
default Browse Path
Definition netrainsimmainwindow.h:214
void closeApplication()
Slot for closing the application.
Definition netrainsimmainwindow.cpp:2262
void nodesDataChanged(QVector< double > &xData, QVector< double > &yData, QVector< QString > &labels)
Signal emitted when the nodes data is changed.
void loadProjectFiles(QString projectFilename)
load the Project Files to the simulator GUI
Definition netrainsimmainwindow.cpp:2320
void loadDefaults()
load default settings
Definition netrainsimmainwindow.cpp:201
void pauseSimulation()
Definition netrainsimmainwindow.cpp:2433
~NeTrainSim()
Destructor.
Definition netrainsimmainwindow.cpp:2395
void updateTrainsPlot(Vector< std::pair< std::string, Vector< std::pair< double, double > > > > trainsStartEndPoints)
Slot for updating the trains plot.
Definition netrainsimmainwindow.cpp:2006
QString userBrowsePath
Definition netrainsimmainwindow.h:216
bool saveDefaults(QStringList defaults)
NeTrainSim::save Default values.
Definition netrainsimmainwindow.cpp:230
The SimulationWorker class performs simulation work in a separate thread.
Definition simulationworker.h:27
A vector.
Definition vector.h:24
Definition aboutwindow.h:15
This file contains the declaration of the SimulationWorker class.