SWMMVis  6.0.0-alpha.4
Qt6/C++ GIS-based graphical user interface for the SWMMVis engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
simulationoptionsdialog.h
Go to the documentation of this file.
1
11#ifndef SIMULATIONOPTIONSDIALOG_H
12#define SIMULATIONOPTIONSDIALOG_H
13
14#include <QDateTime>
15#include <QDialog>
16#include <QList>
17#include <QPair>
18#include <QString>
19#include <QStringList>
20
21class QCheckBox;
22class QComboBox;
23class QGroupBox;
24class QDateEdit;
25class QDateTimeEdit;
26class QDoubleSpinBox;
27class QLabel;
28class QLineEdit;
29class QPushButton;
30class QSpinBox;
31class QTableView;
32class QTableWidget;
33class QTabWidget;
34class QListWidget;
35class QStackedWidget;
36class QTextEdit;
37class QToolButton;
38class QAction;
39class QButtonGroup;
40class QRadioButton;
41class QCustomTimespanEdit;
42
43class SWMMModelLayer;
51
52namespace openswmmvis::ui {
53 class RelativePathPicker;
54}
55
56#include <openswmm/engine/openswmm_engine.h>
57
58#include <memory>
59
60#include <QVector>
61
62#include <functional>
63
65// Full definition, not a forward declaration: the dialog holds a
66// unique_ptr<SimOptionsContext> and its destructor is inline (moc vtable).
68
69namespace openswmmvis::ui {
70class SimOptionsPage;
71class DatesPage;
72class FilesPage;
73class HydraulicsPage;
74class MeshPage;
75class ModelsPage;
76class PerformancePage;
77class QualityPage;
78class SpatialPage;
79class TitleNotesPage;
80class TwoDPage;
81}
82
95class SimulationOptionsDialog : public QDialog
96{
97 Q_OBJECT
98
99public:
116 explicit SimulationOptionsDialog(SWMM_Engine engine,
117 SWMMModelLayer *layer = nullptr,
118 const QString &engineVersion = QStringLiteral("6.0.0"),
119 SWMMVisProjectWindow *projectWindow = nullptr,
120 QWidget *parent = nullptr);
121 // Inline so leaf tests that only compile simulationoptionshelpers.cpp can
122 // still link the moc-generated vtable. Defining it out-of-line in the
123 // main .cpp would force the test to drag in the entire dialog (and its
124 // OGR/GDAL deps via the spatial-tab code).
125 ~SimulationOptionsDialog() override = default;
126
128 [[nodiscard]] bool wroteAnyChanges() const { return m_wroteChanges; }
129
138 [[nodiscard]] QStringList lastWriteKeys() const;
139
140 // ---- Pure helpers (testable without an engine) ------------------------
141
144 [[nodiscard]] static int parseEngineBool(const QString &s);
145
147 [[nodiscard]] static QString engineBoolString(bool on);
148
154 static void fastPresetValues(int &out_threads, double &out_min_step_sec);
155
158 static int fastPresetThreads();
159
162 static QString threadLimitsSummary(const SWMM_ThreadInfo &ti);
163
166 static void formatEngineDateTime(const QDateTime &dt,
167 QString &out_date,
168 QString &out_time);
169
172 [[nodiscard]] static QDateTime parseEngineDateTime(const QString &date,
173 const QString &time);
174
179 [[nodiscard]] static double oaDateFromQDateTime(const QDateTime &dt);
180
182 [[nodiscard]] static QDateTime qDateTimeFromOaDate(double oa);
183
190 [[nodiscard]] static qint64 parseStepSeconds(const QString &s,
191 qint64 fallback);
192
201 [[nodiscard]] static bool optionValueEquals(const QString &a,
202 const QString &b);
203
210 [[nodiscard]] static QList<int> selectedRowsDescending(
211 const QTableWidget *table);
212
213private slots:
214 void onApply();
215 void onAccept();
216
217private:
220 bool confirmBeforeWrite();
221
225 void applyEngineConstraints();
226
227 void buildUi();
228
236 struct PageGate {
237 enum class Target { SidebarRow, Tab, Widget };
238 Target target = Target::Widget;
239 int row = -1;
240 QTabWidget *tabs = nullptr;
241 int tabIndex = -1;
242 QWidget *widget = nullptr;
243 std::function<bool()> enabled;
244 QString reasonWhenOff;
245 };
246
247 void refreshGates();
248 void buildGateTable();
249
250 void addCategory(const QString &title, QWidget *page);
252 void addPage(openswmmvis::ui::SimOptionsPage *page);
253
254 void readFromEngine();
255 int writeToEngine();
256
257 SWMM_Engine m_engine = nullptr;
258 SWMMModelLayer *m_layer = nullptr;
259 SWMMVisProjectWindow *m_projectWindow = nullptr;
260 QString m_engineVersion;
261 bool m_wroteChanges = false;
262
263 // ---- sidebar rows the gate table names ------------------------------
264 int m_2DRow = -1;
265 int m_meshRow = -1;
266 int m_qualityRow = -1;
267 int m_hydraulicsRow = -1;
268 QVector<PageGate> m_gates;
269 QListWidget *m_categoryList = nullptr;
270 QStackedWidget *m_pages = nullptr;
271
272 // ---- page registry ---------------------------------------------------
274 std::unique_ptr<openswmmvis::ui::SimOptionsContext> m_ctx;
275 QVector<openswmmvis::ui::SimOptionsPage *> m_pageOrder;
276 // Pages the dialog talks to by name — every one of these is either a gate
277 // input, a gate target, or one half of a cross-page hook (PLAN §4.1).
278 openswmmvis::ui::DatesPage *m_datesPage = nullptr;
279 openswmmvis::ui::FilesPage *m_filesPage = nullptr;
280 openswmmvis::ui::HydraulicsPage *m_hydraulicsPage = nullptr;
281 openswmmvis::ui::ModelsPage *m_modelsPage = nullptr;
282 openswmmvis::ui::QualityPage *m_qualityPage = nullptr;
283 openswmmvis::ui::SpatialPage *m_spatialPage = nullptr;
284#ifdef OPENSWMM_HAS_2D
285 openswmmvis::ui::TwoDPage *m_twoDPage = nullptr;
286#endif
287};
288
289#endif // SIMULATIONOPTIONSDIALOG_H
Delegate for the Datetime column. Editor is a QDateTimeEdit whose minimum date-time renders as the sp...
Definition hotstartsavesmodel.h:73
Row schema: {path relative to the .inp dir, OLE-Automation datetime sentinel}. An oaDate of 0....
Definition hotstartsavesmodel.h:30
Definition pathbrowsedelegate.h:24
Definition pluginstablemodel.h:21
Combo editor over the built-in catalogue, editable for free-form ids.
Definition processcomponentsmodel.h:85
Definition processcomponentsmodel.h:31
Renders the SWMM network elements (nodes, links, subcatchments, rain gages) for one OpenSWMMEngine mo...
Definition swmmmodellayer.h:133
MDI sub-window owning a MapCanvas, SWMMModelLayer, and map tools.
Definition swmmvisprojectwindow.h:58
Edit OPTIONS for the active SWMM project.
Definition simulationoptionsdialog.h:96
static qint64 parseStepSeconds(const QString &s, qint64 fallback)
Parse a step value as returned by swmm_options_get() into whole seconds. The engine round-trip is loo...
Definition simulationoptionshelpers.cpp:120
static QString threadLimitsSummary(const SWMM_ThreadInfo &ti)
Human-readable summary of the machine / OpenMP thread limits (from swmm_get_thread_info) for tooltips...
Definition simulationoptionsdialog.cpp:402
static int fastPresetThreads()
THREADS the fast preset uses: the machine's performance-core count (macOS), else its logical-CPU coun...
Definition simulationoptionshelpers.cpp:52
static void formatEngineDateTime(const QDateTime &dt, QString &out_date, QString &out_time)
Format a Qt date+time as the engine's expected MM/DD/YYYY + HH:MM:SS pair (returned as out_date and o...
Definition simulationoptionshelpers.cpp:67
static QList< int > selectedRowsDescending(const QTableWidget *table)
Distinct selected row indices of table, sorted descending (safe order for removeRow())....
Definition simulationoptionshelpers.cpp:168
static void fastPresetValues(int &out_threads, double &out_min_step_sec)
Canonical "fast preset" recipe for 1D/2D-coupled runs: all worker threads on, and the adaptive routin...
Definition simulationoptionshelpers.cpp:38
static int parseEngineBool(const QString &s)
Map an engine boolean string ("YES"/"NO"/"TRUE"/"FALSE"/"1"/"0") to a Qt::CheckState....
Definition simulationoptionshelpers.cpp:28
~SimulationOptionsDialog() override=default
static bool optionValueEquals(const QString &a, const QString &b)
Compare an option value from swmm_options_get() against a freshly formatted one, tolerating formattin...
Definition simulationoptionshelpers.cpp:151
static QString engineBoolString(bool on)
Render a checkbox state as the canonical engine string.
Definition simulationoptionshelpers.cpp:62
bool wroteAnyChanges() const
True after a successful Apply / OK that wrote at least one key.
Definition simulationoptionsdialog.h:128
static QDateTime parseEngineDateTime(const QString &date, const QString &time)
Inverse of formatEngineDateTime. Returns an invalid QDateTime if either string is malformed.
Definition simulationoptionshelpers.cpp:75
static double oaDateFromQDateTime(const QDateTime &dt)
Convert a QDateTime to SWMM's OLE Automation Date (decimal days since 1899-12-30 00:00)....
Definition simulationoptionshelpers.cpp:107
static QDateTime qDateTimeFromOaDate(double oa)
Inverse of oaDateFromQDateTime.
Definition simulationoptionshelpers.cpp:113
QStringList lastWriteKeys() const
Every option key offered to writeIfChanged during the last write pass — whether or not the value actu...
Definition simulationoptionsdialog.cpp:384
Definition datespage.h:43
Definition filespage.h:42
Definition hydraulicspage.h:37
Definition modelspage.h:38
Definition qualitypage.h:38
Definition simoptionspage.h:25
Definition spatialpage.h:26
double s
Scene px per model length unit.
Definition inletdrawingview.cpp:82
int b
local residual indices, a < b
Definition meshquadmatch.cpp:46
int a
Definition meshquadmatch.cpp:46
Definition openswmmvislayer.h:43
void * SWMM_Engine
Definition objectdefaultsapplier.h:19
QVector< int > parent
union-find
Definition pslgminsize.cpp:176
const char * title
Definition snowpackeditordialog.cpp:71
What this engine build accepts, probed once.
Definition enginecapabilities.h:37