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
irunlayer.h
Go to the documentation of this file.
1
22#ifndef OPENSWMMVIS_PLOT_IRUNLAYER_H
23#define OPENSWMMVIS_PLOT_IRUNLAYER_H
24
25#include "plot/plotattribute.h"
27
28#include <QDateTime>
29#include <QString>
30#include <QStringList>
31
32#include <vector>
33
34namespace openswmmvis::plot {
35
38struct ObjectRef {
39 enum class Kind {
40 Unknown = 0,
41 Node = 1,
42 Link = 2,
43 Subcatch = 3,
44 Mesh2DCell = 4,
45 Observed = 5,
46 System = 6,
47 Mesh2DEdge = 7,
48 Mesh2DVertex = 8,
49 };
50
52 QString name;
53 int triIdx = -1;
54 int edgeLocal = -1;
55
56 constexpr ObjectRef() = default;
57 ObjectRef(Kind k, QString n) : kind(k), name(std::move(n)) {}
58 static ObjectRef forNode(QString n) { return ObjectRef(Kind::Node, std::move(n)); }
59 static ObjectRef forLink(QString n) { return ObjectRef(Kind::Link, std::move(n)); }
60 static ObjectRef forSubcatch(QString n) { return ObjectRef(Kind::Subcatch, std::move(n)); }
61 static ObjectRef forMesh2DCell(int idx) { ObjectRef r; r.kind = Kind::Mesh2DCell; r.triIdx = idx; return r; }
62 static ObjectRef forMesh2DEdge(int tri, int edge)
63 { ObjectRef r; r.kind = Kind::Mesh2DEdge; r.triIdx = tri; r.edgeLocal = edge; return r; }
64 static ObjectRef forMesh2DVertex(int idx)
65 { ObjectRef r; r.kind = Kind::Mesh2DVertex; r.triIdx = idx; return r; }
66 static ObjectRef forObserved(QString lbl) { return ObjectRef(Kind::Observed, std::move(lbl)); }
67 static ObjectRef forSystem() { ObjectRef r; r.kind = Kind::System; return r; }
68
69 bool isValid() const noexcept
70 {
71 switch (kind) {
72 case Kind::Mesh2DCell: return triIdx >= 0;
73 case Kind::Mesh2DVertex: return triIdx >= 0;
74 case Kind::Mesh2DEdge: return triIdx >= 0 && edgeLocal >= 0 && edgeLocal <= 2;
75 case Kind::System: return true; // name is unused
76 case Kind::Unknown: return false;
77 default: return !name.isEmpty();
78 }
79 }
80
81 bool operator==(const ObjectRef& other) const noexcept
82 {
83 return kind == other.kind && name == other.name
84 && triIdx == other.triIdx && edgeLocal == other.edgeLocal;
85 }
86 bool operator!=(const ObjectRef& other) const noexcept { return !(*this == other); }
87};
88
96inline const QVector<PlotAttribute> &attributesForKind(ObjectRef::Kind k)
97{
98 switch (k) {
106 default: {
107 static const QVector<PlotAttribute> kEmpty;
108 return kEmpty;
109 }
110 }
111}
112
124inline QVector<ResultDescriptor> resultDescriptorsForKind(
125 ObjectRef::Kind kind, const QStringList &speciesNames)
126{
127 QVector<ResultDescriptor> out;
128 const QVector<PlotAttribute> &fixed = attributesForKind(kind);
129 out.reserve(fixed.size() + speciesNames.size());
130 for (const PlotAttribute a : fixed)
132
133 // Species columns exist for the element kinds the .out carries them
134 // on (node/link/subcatch — Y2a's rule); System series and mesh kinds
135 // have none. Order is the run's .out order — the engine's order — so
136 // two pickers over the same run agree.
137 const bool speciesKind = kind == ObjectRef::Kind::Node ||
140 if (speciesKind)
141 for (const QString &sp : speciesNames)
142 if (!sp.isEmpty())
143 out.append(ResultDescriptor::forSpecies(sp));
144 return out;
145}
146
152 std::vector<double> timesJulian;
153 std::vector<double> values;
154 bool ok = false;
155 QString errorMessage;
156
164 int firstPeriod = 0;
167 int periodCount = 0;
168};
169
172public:
173 virtual ~IRunLayer() = default;
174
176 virtual QString scenarioName() const = 0;
177
179 virtual UnitSystem unitSystem() const = 0;
180
182 virtual double startDateJulian() const = 0;
183
185 virtual int periodCount() const = 0;
186
188 virtual int reportStepSeconds() const = 0;
189
195 virtual void getSeriesAt(const ObjectRef& ref,
196 PlotAttribute attr,
197 SeriesData& out) const = 0;
198
202 virtual bool supportsAttribute(PlotAttribute /*attr*/) const { return true; }
203
211 virtual void getSeriesAt(const ObjectRef& ref,
212 const ResultDescriptor& descriptor,
213 SeriesData& out) const
214 {
215 if (descriptor.isSpecies()) {
216 out.ok = false;
217 out.errorMessage =
218 QStringLiteral("Source '%1' carries no species results")
219 .arg(scenarioName());
220 return;
221 }
222 getSeriesAt(ref, descriptor.attr, out);
223 }
224
236 virtual QVector<ResultDescriptor> resultDescriptorsForKind(
237 ObjectRef::Kind kind) const
238 { return plot::resultDescriptorsForKind(kind, QStringList()); }
239
242 virtual QString persistenceKey() const { return scenarioName(); }
243};
244
245} // namespace openswmmvis::plot
246
247#endif // OPENSWMMVIS_PLOT_IRUNLAYER_H
Per-project flow-units state + label helpers.
Definition unitsystem.h:28
Abstract source backing one comparison-plot run.
Definition irunlayer.h:171
virtual QString persistenceKey() const
Stable identity string for .oswp round-trip. Defaults to the scenario name; subclasses may override w...
Definition irunlayer.h:242
virtual int reportStepSeconds() const =0
Report step in seconds. 0 if unknown.
virtual ~IRunLayer()=default
virtual UnitSystem unitSystem() const =0
Unit system the source advertises (drives axis labels).
virtual double startDateJulian() const =0
Start date of the simulation as SWMM Julian, or NaN if unknown.
virtual QVector< ResultDescriptor > resultDescriptorsForKind(ObjectRef::Kind kind) const
Y2b-1 (amendment D-Y4): everything plottable for kind on THIS run — the fixed attribute set as descri...
Definition irunlayer.h:236
virtual void getSeriesAt(const ObjectRef &ref, const ResultDescriptor &descriptor, SeriesData &out) const
Y2b-2 (amendment D-Y4): resolve a series by DESCRIPTOR. Fixed attributes forward to the enum overload...
Definition irunlayer.h:211
virtual void getSeriesAt(const ObjectRef &ref, PlotAttribute attr, SeriesData &out) const =0
Resolve a series. Returns timesJulian + values for the spec. Implementations are responsible for reso...
virtual QString scenarioName() const =0
Human label shown in the SeriesPanel tree + legends.
virtual int periodCount() const =0
Total number of time periods available (grows during live mode).
virtual bool supportsAttribute(PlotAttribute) const
Convenience: does this source carry the given attribute at all? Default impl returns true; subclasses...
Definition irunlayer.h:202
std::size_t n
Definition mesh2dresultsexport.cpp:426
int k
Definition mesh2dresultsexport.cpp:549
int a
Definition meshquadmatch.cpp:46
Definition chartproperties.h:34
const QVector< PlotAttribute > & mesh2DCellPlotAttributes()
The 7 per-2D-cell attributes, presentation order.
Definition plotattribute.cpp:69
const QVector< PlotAttribute > & mesh2DVertexPlotAttributes()
The 2 per-2D-vertex attributes (depth, HGL — interpolated).
Definition plotattribute.cpp:92
const QVector< PlotAttribute > & nodePlotAttributes()
The 6 per-node attributes, presentation order.
Definition plotattribute.cpp:11
PlotAttribute
What a series plots. One row per attribute in the Nx2 grid.
Definition plotattribute.h:38
const QVector< PlotAttribute > & mesh2DEdgePlotAttributes()
The 2 per-2D-edge attributes (flow, unit-width flux).
Definition plotattribute.cpp:83
const QVector< PlotAttribute > & attributesForKind(ObjectRef::Kind k)
The canonical plottable-attribute list for k (presentation order), dispatching to the shared lists in...
Definition irunlayer.h:96
QVector< ResultDescriptor > resultDescriptorsForKind(ObjectRef::Kind kind, const QStringList &speciesNames)
Y2b-1 (amendment D-Y4): the kind-keyed DESCRIPTOR list — the fixed attributesForKind(kind) set wrappe...
Definition irunlayer.h:124
const QVector< PlotAttribute > & systemPlotAttributes()
The 14 system-wide attributes, presentation order (matches the long-standing system picker menu: Rain...
Definition plotattribute.cpp:48
const QVector< PlotAttribute > & subcatchPlotAttributes()
The 5 per-subcatchment attributes, presentation order.
Definition plotattribute.cpp:36
const QVector< PlotAttribute > & linkPlotAttributes()
The 5 per-link attributes, presentation order.
Definition plotattribute.cpp:24
Slice BL — canonical enumeration of plottable result attributes.
EdgeRef ref
Definition pslgminsize.cpp:377
TokenKind kind
Definition queryparser.cpp:34
Y2b-1 (amendment D-Y4) — one plottable result, fixed or species.
Identifies what object a series is about. Kind is the discriminator; the active union member is impli...
Definition irunlayer.h:38
static ObjectRef forObserved(QString lbl)
Definition irunlayer.h:66
static ObjectRef forSystem()
Definition irunlayer.h:67
bool isValid() const noexcept
Definition irunlayer.h:69
Kind
Definition irunlayer.h:39
@ Mesh2DEdge
triIdx + edgeLocal valid; name unused — for edge-flux series
@ Observed
name = observed series label (e.g. CSV header)
@ System
single global series per attribute; name unused (AT.2)
@ Mesh2DCell
triIdx valid; name unused (CF.3)
@ Mesh2DVertex
triIdx holds the vertex index; depth/HGL interpolated from incident cells
@ Subcatch
name = SWMM subcatchment ID
constexpr ObjectRef()=default
QString name
SWMM ID for 1D kinds; observed-series label for Observed; unused for System.
Definition irunlayer.h:52
static ObjectRef forMesh2DVertex(int idx)
Definition irunlayer.h:64
static ObjectRef forNode(QString n)
Definition irunlayer.h:58
bool operator!=(const ObjectRef &other) const noexcept
Definition irunlayer.h:86
static ObjectRef forLink(QString n)
Definition irunlayer.h:59
ObjectRef(Kind k, QString n)
Definition irunlayer.h:57
static ObjectRef forMesh2DEdge(int tri, int edge)
Definition irunlayer.h:62
static ObjectRef forSubcatch(QString n)
Definition irunlayer.h:60
static ObjectRef forMesh2DCell(int idx)
Definition irunlayer.h:61
bool operator==(const ObjectRef &other) const noexcept
Definition irunlayer.h:81
int edgeLocal
Local edge index 0..2 for Mesh2DEdge; -1 otherwise.
Definition irunlayer.h:54
Kind kind
Definition irunlayer.h:51
int triIdx
Triangle index for Mesh2DCell / Mesh2DEdge; vertex index for Mesh2DVertex; -1 otherwise.
Definition irunlayer.h:53
One plottable result: a fixed attribute OR a species by name.
Definition resultdescriptor.h:39
bool isSpecies() const noexcept
Definition resultdescriptor.h:47
static ResultDescriptor forAttribute(PlotAttribute a)
Definition resultdescriptor.h:65
PlotAttribute attr
Definition resultdescriptor.h:41
static ResultDescriptor forSpecies(const QString &name)
Definition resultdescriptor.h:68
Result of one series resolution. Times are SWMM DateTime doubles (OLE-Automation epoch,...
Definition irunlayer.h:151
QString errorMessage
Populated when ok == false.
Definition irunlayer.h:155
std::vector< double > values
Same length as timesJulian.
Definition irunlayer.h:153
int firstPeriod
Definition irunlayer.h:164
std::vector< double > timesJulian
SWMM DateTime; convert via openswmmvis::core::swmmDateTimeToQDateTime.
Definition irunlayer.h:152
bool ok
False if the source couldn't fulfil the request.
Definition irunlayer.h:154
int periodCount
Definition irunlayer.h:167