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
maptoolselectprofile.h
Go to the documentation of this file.
1
24#ifndef MAPTOOLSELECTPROFILE_H
25#define MAPTOOLSELECTPROFILE_H
26
27#include "map/tools/maptool.h"
28#include "plot/profilerouter.h"
29
30#include <QPointer>
31#include <QVector>
32
33class SWMMModelLayer;
36class QGraphicsScene;
37template<typename T> class QFutureWatcher;
38
40{
41 Q_OBJECT
42
43public:
45 QObject *parent = nullptr);
47
48 void activate() override;
49 void deactivate() override;
50
51 void mousePressEvent(QMouseEvent *event) override;
52 void keyPressEvent (QKeyEvent *event) override;
53
59 [[nodiscard]] ProfileRouter::Path acceptedPath() const;
60
69 void clearSelection();
70
71signals:
78
83 void statusMessageChanged(const QString &message);
84
91 void routingBusyChanged(bool busy);
92
93private:
94 enum class State {
95 Idle,
96 AwaitingEnd,
97 PickingPath,
98 };
99
100 // Returns the engine node index for a click at (mapX, mapY), snapping
101 // through a link's nearest endpoint if a link is hit. Returns -1 on
102 // miss. `tolerance` is in map units.
103 [[nodiscard]] int resolveNodeAt(double mapX, double mapY, double tolerance) const;
104
105 // Computes the click tolerance in map units for the current viewport
106 // (12-pixel target like MapToolSelect).
107 [[nodiscard]] double clickTolerance() const;
108
109 // Materializes the candidate paths via ProfileNetworkAdapter +
110 // ProfileRouter on a worker thread. Returns immediately after
111 // kicking off the future and showing a busy progress dialog; the
112 // post-routing flow continues in onRoutingComplete().
113 void routeAndPick();
114
115 // Continuation invoked on the main thread once the worker thread's
116 // ProfileRouter call finishes (or is cancelled). Handles the
117 // single-path auto-accept and multi-path picker dialog flows.
118 void onRoutingComplete(const ProfileRouter::Result &result,
119 int graphNodeCount, int graphEdgeCount);
120
121 // Tears down the overlay, clears endpoints/waypoints, returns to Idle.
122 void resetState();
123
124 // Lighter cleanup that clears only the in-progress endpoint capture +
125 // any open picker, while leaving the persisted accepted path and its
126 // overlay alone. Used by `activate()` / `deactivate()` so toggling
127 // the tool off and back on preserves the previously-selected profile.
128 void clearInProgress();
129
130 SWMMModelLayer *activeModel() const;
131
132 State m_state = State::Idle;
133 int m_startNode = -1; // engine node index
134 int m_endNode = -1;
135 QVector<int> m_waypoints; // engine node indices, in order
136 ProfilePathOverlay *m_overlay = nullptr;
137 // QPointer to the scene that owns m_overlay — used as a liveness
138 // guard in the tool destructor / resetState() since QGraphicsItem
139 // is not a QObject and we cannot QPointer the overlay itself. If
140 // the scene was destroyed first (typical project-teardown order),
141 // the overlay is already freed and we must not touch it.
142 QPointer<QGraphicsScene> m_overlayScene;
143 ProfileRouter::Path m_acceptedPath;
144
145 // Non-modal picker state — kept on the tool so the map remains
146 // interactive while the dialog is open. Cleared in `resetState()`
147 // and on dialog accept/reject.
148 QPointer<ProfilePathPickerDialog> m_pendingPicker;
149 QVector<ProfileRouter::Path> m_pendingPaths;
150
151 // Async routing state — the worker future. Parented to `this` so it
152 // cleans up when the tool dies. Status-bar busy indication is
153 // surfaced via the routingBusyChanged() signal rather than a local
154 // progress dialog so the user can keep panning/zooming the map.
155 QFutureWatcher<ProfileRouter::Result> *m_routingWatcher = nullptr;
156};
157
158#endif // MAPTOOLSELECTPROFILE_H
The central map display widget — QGIS-style hybrid rendering.
Definition mapcanvas.h:63
Abstract base class for interactive map tools used in the MapCanvas.
Definition maptool.h:43
MapCanvas * canvas() const
Returns the MapCanvas this tool is attached to.
Definition maptool.cpp:29
Definition maptoolselectprofile.h:40
ProfileRouter::Path acceptedPath() const
Path that the user accepted from the picker (or the only candidate, when the router emitted exactly o...
Definition maptoolselectprofile.cpp:166
void deactivate() override
Called by the canvas when another tool replaces this one.
Definition maptoolselectprofile.cpp:158
void clearSelection()
Drop the accepted path, the on-map overlay, and any in-progress capture, then invalidate the canvas s...
Definition maptoolselectprofile.cpp:171
void mousePressEvent(QMouseEvent *event) override
Definition maptoolselectprofile.cpp:191
~OpenSWMMVisMapToolSelectProfile() override
Definition maptoolselectprofile.cpp:56
void keyPressEvent(QKeyEvent *event) override
Definition maptoolselectprofile.cpp:290
void profilePathSelected(const ProfileRouter::Path &path)
Fired immediately after the user accepts a path (or after a single-candidate route auto-confirms)....
void activate() override
Called by the canvas when this tool becomes the active tool.
Definition maptoolselectprofile.cpp:73
void statusMessageChanged(const QString &message)
Fired when the tool's status string changes — host can pipe this into the main-window status bar.
void routingBusyChanged(bool busy)
Fired when async routing starts (busy = true) and again when it completes (busy = false)....
Renders an ordered list of candidate paths over the map.
Definition profilepathoverlay.h:48
Definition profilepathpickerdialog.h:29
Definition maptoolselectprofile.h:37
Renders the SWMM network elements (nodes, links, subcatchments, rain gages) for one OpenSWMMEngine mo...
Definition swmmmodellayer.h:133
Abstract base class for all interactive tools attached to a MapCanvas.
Path-routing primitives over an abstract weighted graph, used by Slice BC's profile-path picker.
int path
Definition pslgminsize.cpp:234
QVector< int > parent
union-find
Definition pslgminsize.cpp:176
QString message
Definition queryparser.cpp:150
@ Idle
Row exists for an open model; no run yet.
A single candidate path: ordered node sequence (length N+1) of engine node indices,...
Definition profilerouter.h:80
What the router returns. Empty paths plus non-empty error means an outright failure (e....
Definition profilerouter.h:126