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
mesh::InpMeshWriter Class Reference

#include <inpmeshwriter.h>

Collaboration diagram for mesh::InpMeshWriter:

Classes

struct  UnitInfo
 Unit & provenance metadata written as ;; header comments. More...
 

Static Public Member Functions

static QString buildSectionText (const MeshResult &mesh, const CouplingMap &coupling, double defaultMannings=0.035, const UnitInfo &units={})
 Render the 2D mesh sections as a single text block.
 
static QString buildBCSectionText (const QVector< MeshEdgeBC > &bcs)
 Slice §V.VD.1 — render the [2D_BOUNDARY_CONDITIONS] section for the per-edge BC vector. Returns an empty string when every edge is Wall (avoids polluting the .inp with a section that round-trips to default). Format:
 
static QString buildConveyanceSectionText (const MeshResult &mesh, const QVector< MeshEdgeBC > &bcs)
 Engine §11A — render the [2D_EDGE_CONVEYANCE] section.
 
static bool writeExternal (const QString &inpPath, const QString &meshFilePath, const MeshResult &mesh, const CouplingMap &coupling, double defaultMannings=0.035, QString *errorOut=nullptr, const UnitInfo &units={})
 Default mode: write the mesh into a sibling .2dm file and patch the .inp with a [2D_MESH_FILE] reference.
 
static bool writeExternal (const QString &inpPath, const QString &meshFilePath, const MeshResult &mesh, const CouplingMap &coupling, const QVector< MeshEdgeBC > &bcs, double defaultMannings, QString *errorOut=nullptr, const UnitInfo &units={})
 §V.VD.1 overload — additionally writes the [2D_BOUNDARY_CONDITIONS] section. Empty / all-Wall BC vector is equivalent to the non-BC overload (section is omitted).
 
static bool writeInline (const QString &inpPath, const MeshResult &mesh, const CouplingMap &coupling, double defaultMannings=0.035, QString *errorOut=nullptr, const UnitInfo &units={})
 Replace (or append) all four 2D sections in the .inp at inpPath. Existing 2D sections are stripped first; any existing [2D_MESH_FILE] block is also removed so the engine reads the freshly-inlined sections instead.
 
static bool writeInline (const QString &inpPath, const MeshResult &mesh, const CouplingMap &coupling, const QVector< MeshEdgeBC > &bcs, double defaultMannings, QString *errorOut=nullptr, const UnitInfo &units={})
 §V.VD.1 overload — additionally writes the [2D_BOUNDARY_CONDITIONS] section inline.
 
static bool writeMeshFileRef (const QString &inpPath, const QString &meshFilePath, QString *errorOut=nullptr)
 Retarget the .inp's [2D_MESH_FILE] reference at an already-existing .2dm without writing any mesh geometry.
 
static bool patchBCSections (const QString &filePath, const MeshResult &mesh, const QVector< MeshEdgeBC > &bcs, QString *errorOut=nullptr)
 Replace the [2D_BOUNDARY_CONDITIONS] and [2D_EDGE_CONVEYANCE] sections of filePath (a .inp or external .2dm) with sections built from bcs, leaving every other section untouched.
 
static bool patchAttributeSections (const QString &filePath, const MeshResult &mesh, QString *errorOut=nullptr, double defaultMannings=0.035)
 Replace the [2D_VERTICES], [2D_TRIANGLES], [2D_QUADS], [2D_VERTEX_NODE_MAP], [2D_TRIANGLE_NODE_MAP] and [2D_INFILTRATION_OPTIONS] / [2D_INFILTRATION_DEFAULTS] / [2D_INFILTRATION] sections of filePath with sections rebuilt from the layer's editable mesh state, leaving every other section untouched.
 
static bool clearMeshFileRef (const QString &inpPath, QString *errorOut=nullptr)
 Strip any [2D_MESH_FILE] reference from the .inp so the engine falls back to the inline [2D_*] mesh sections.
 
static bool write (MeshOutputMode mode, const QString &inpPath, const QString &meshFilePath, const MeshResult &mesh, const CouplingMap &coupling, double defaultMannings=0.035, QString *errorOut=nullptr, const UnitInfo &units={})
 Convenience dispatch on MeshOutputMode.
 

Member Function Documentation

◆ buildBCSectionText()

QString mesh::InpMeshWriter::buildBCSectionText ( const QVector< MeshEdgeBC > &  bcs)
static

Slice §V.VD.1 — render the [2D_BOUNDARY_CONDITIONS] section for the per-edge BC vector. Returns an empty string when every edge is Wall (avoids polluting the .inp with a section that round-trips to default). Format:

[2D_BOUNDARY_CONDITIONS]
;; TRI  EDGE  TYPE             PARAM_1        PARAM_2  GROUP
   12   0     NORMAL_FLOW      0.002          *        *
   12   1     SPECIFIED_STAGE  95.4           *        *
   45   2     TS_STAGE         DownstreamTS   *        Outlet

TYPE is one of WALL / NORMAL_FLOW / SPECIFIED_STAGE / TS_STAGE / SPECIFIED_FLOW / TS_FLOW / RATING_CURVE (see mesh::MeshBCTypes). PARAM_1 is the type's primary parameter (slope / head / TS name / flow / TS name / curve name). PARAM_2 is reserved for future extensions; today always "*". GROUP is the optional named group ("*" = none).

Here is the call graph for this function:
Here is the caller graph for this function:

◆ buildConveyanceSectionText()

QString mesh::InpMeshWriter::buildConveyanceSectionText ( const MeshResult mesh,
const QVector< MeshEdgeBC > &  bcs 
)
static

Engine §11A — render the [2D_EDGE_CONVEYANCE] section.

Walks bcs (flat-indexed mesh::edgeSlot(cell, edge), parallel to mesh; endpoints via mesh::edgeEndpoints, every edge of a quad included) and emits one row per edge whose conveyance differs from the default 1.0. Interior edges occupy two slots that the GUI keeps in sync (see SWMM2DMeshLayer::applyMeshEdgeConveyance), so the writer canonicalises on the first encountered vertex-pair and silently drops the second half — interior edges appear exactly once. Returns an empty string when every edge is at default.

Format (matches the engine parser in SectionHandlers2D.cpp):

[2D_EDGE_CONVEYANCE]
;; FROM_VERTEX  TO_VERTEX  CONVEYANCE
   12           37         0.5
   12           45         0

CONVEYANCE is a dimensionless multiplier in [0, 1]. 1.0 (default) is unrestricted; 0.0 is a closed (impermeable) edge.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ buildSectionText()

QString mesh::InpMeshWriter::buildSectionText ( const MeshResult mesh,
const CouplingMap coupling,
double  defaultMannings = 0.035,
const UnitInfo units = {} 
)
static

Render the 2D mesh sections as a single text block.

Order: [2D_VERTICES], [2D_TRIANGLES] (triangle cells), [2D_QUADS] (V1 V2 V3 V4 MANNINGS_N [INIT_DEPTH] [TAG], quad cells — emitted ONLY when the mesh holds a quad, so all-triangle output is byte-identical to the pre-quad writer), [2D_VERTEX_NODE_MAP], [2D_TRIANGLE_NODE_MAP], then the GG0a infiltration family [2D_INFILTRATION_OPTIONS] / [2D_INFILTRATION_DEFAULTS] / [2D_INFILTRATION]. Each section starts with a ;;-prefixed header comment. Sections with no content (e.g. empty vertex_node_map, a mesh with no infiltration data) are omitted entirely.

The infiltration sections are per-cell mesh attributes, so they ride with the mesh — into the .2dm in external mode, inline otherwise. They are deliberately NOT appended to [2D_TRIANGLES], whose columns are positional.

Parameters
meshoutput of MeshGenerator::generate()
couplingvertex/triangle → SWMM node map
defaultManningsused for triangles missing from coupling.triangleMannings (default 0.035 ≈ natural channel / grass).
unitsoptional ;; UNITS: / ;; SOURCE_CRS: header metadata (purely descriptive).
Here is the caller graph for this function:

◆ clearMeshFileRef()

bool mesh::InpMeshWriter::clearMeshFileRef ( const QString &  inpPath,
QString *  errorOut = nullptr 
)
static

Strip any [2D_MESH_FILE] reference from the .inp so the engine falls back to the inline [2D_*] mesh sections.

The inverse of writeMeshFileRef: removes only the [2D_MESH_FILE] block and leaves every other section (including the inline mesh data) untouched. Used when the user selects the inline mesh as the active 2D configuration. No-op-safe when the section is absent. Atomic via QSaveFile.

Parameters
inpPathSWMM input file to patch.
errorOutSet on failure.
Returns
true on success.

◆ patchAttributeSections()

bool mesh::InpMeshWriter::patchAttributeSections ( const QString &  filePath,
const MeshResult mesh,
QString *  errorOut = nullptr,
double  defaultMannings = 0.035 
)
static

Replace the [2D_VERTICES], [2D_TRIANGLES], [2D_QUADS], [2D_VERTEX_NODE_MAP], [2D_TRIANGLE_NODE_MAP] and [2D_INFILTRATION_OPTIONS] / [2D_INFILTRATION_DEFAULTS] / [2D_INFILTRATION] sections of filePath with sections rebuilt from the layer's editable mesh state, leaving every other section untouched.

Every GUI-owned mesh-attribute section must be listed here. A section this function does not re-emit is discarded on every project save, because the save path restores a pre-engine-write snapshot of the mesh file first — see the comment at src/swmmvisprojectwindow.cpp:1414-1419.

The BC-patch's sibling for mesh attributes: the post-save external-mesh restore rolls the sidecar back to its pre-write snapshot, which predates the engine's write of the current vertex elevation / tag / coupling and triangle Manning / tag edits — without this re-emit those edits silently vanish from the saved model (and the next run reads the old elevations). The layer is authoritative for exactly the fields pushMeshEditsToEngine() pushes; a triangle whose Manning is unset (NaN) keeps the file's existing token so a generation-time default survives the rewrite.

Fails without touching the file when the section row counts don't match mesh — rows map to mesh entries by position, so a mismatch means the file holds a different mesh. Atomic via QSaveFile.

Parameters
filePathExternal mesh file (or .inp) to patch.
meshThe layer's current mesh state.
errorOutSet on failure.
defaultManningsMANNINGS_N materialized for a row that must carry an INIT_DEPTH or TAG but has no Manning's value on either side (columns are positional, so the later ones cannot be written without it).
Returns
true on success.
Here is the caller graph for this function:

◆ patchBCSections()

bool mesh::InpMeshWriter::patchBCSections ( const QString &  filePath,
const MeshResult mesh,
const QVector< MeshEdgeBC > &  bcs,
QString *  errorOut = nullptr 
)
static

Replace the [2D_BOUNDARY_CONDITIONS] and [2D_EDGE_CONVEYANCE] sections of filePath (a .inp or external .2dm) with sections built from bcs, leaving every other section untouched.

Used by the post-save external-mesh restore: the pre-write .2dm snapshot predates the engine's write of the current BC/conveyance edits, so restoring it would silently discard them — this re-emits the layer's per-edge state into the restored file. All-default bcs strips the sections without appending (reset-to-Wall round-trips). Atomic via QSaveFile.

Parameters
filePathFile whose BC/conveyance sections are replaced.
meshMesh the flat-indexed bcs parallels.
bcsPer-edge BC state (mesh::edgeSlot(cell, edge), stride mesh::kEdgeStride; rows are written as TRI = slotCell, EDGE = slotLocal, 0..3 for a quad).
errorOutSet on failure.
Returns
true on success.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ write()

bool mesh::InpMeshWriter::write ( MeshOutputMode  mode,
const QString &  inpPath,
const QString &  meshFilePath,
const MeshResult mesh,
const CouplingMap coupling,
double  defaultMannings = 0.035,
QString *  errorOut = nullptr,
const UnitInfo units = {} 
)
static

Convenience dispatch on MeshOutputMode.

Here is the call graph for this function:

◆ writeExternal() [1/2]

bool mesh::InpMeshWriter::writeExternal ( const QString &  inpPath,
const QString &  meshFilePath,
const MeshResult mesh,
const CouplingMap coupling,
const QVector< MeshEdgeBC > &  bcs,
double  defaultMannings,
QString *  errorOut = nullptr,
const UnitInfo units = {} 
)
static

§V.VD.1 overload — additionally writes the [2D_BOUNDARY_CONDITIONS] section. Empty / all-Wall BC vector is equivalent to the non-BC overload (section is omitted).

Here is the call graph for this function:

◆ writeExternal() [2/2]

bool mesh::InpMeshWriter::writeExternal ( const QString &  inpPath,
const QString &  meshFilePath,
const MeshResult mesh,
const CouplingMap coupling,
double  defaultMannings = 0.035,
QString *  errorOut = nullptr,
const UnitInfo units = {} 
)
static

Default mode: write the mesh into a sibling .2dm file and patch the .inp with a [2D_MESH_FILE] reference.

Parameters
inpPathSWMM input file to patch.
meshFilePathOutput .2dm file. If empty, defaults to <inpDir>/<inpBasename>.2dm.
mesh,coupling,defaultManningsas in buildSectionText.
errorOutset on failure.

Both writes are atomic via QSaveFile. The .inp's existing [2D_*] sections are stripped (if present) so a stale inline mesh doesn't shadow the external file. Path stored in [2D_MESH_FILE] is relative to the .inp directory when the mesh sits beside the .inp; absolute otherwise.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeInline() [1/2]

bool mesh::InpMeshWriter::writeInline ( const QString &  inpPath,
const MeshResult mesh,
const CouplingMap coupling,
const QVector< MeshEdgeBC > &  bcs,
double  defaultMannings,
QString *  errorOut = nullptr,
const UnitInfo units = {} 
)
static

§V.VD.1 overload — additionally writes the [2D_BOUNDARY_CONDITIONS] section inline.

Here is the call graph for this function:

◆ writeInline() [2/2]

bool mesh::InpMeshWriter::writeInline ( const QString &  inpPath,
const MeshResult mesh,
const CouplingMap coupling,
double  defaultMannings = 0.035,
QString *  errorOut = nullptr,
const UnitInfo units = {} 
)
static

Replace (or append) all four 2D sections in the .inp at inpPath. Existing 2D sections are stripped first; any existing [2D_MESH_FILE] block is also removed so the engine reads the freshly-inlined sections instead.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeMeshFileRef()

bool mesh::InpMeshWriter::writeMeshFileRef ( const QString &  inpPath,
const QString &  meshFilePath,
QString *  errorOut = nullptr 
)
static

Retarget the .inp's [2D_MESH_FILE] reference at an already-existing .2dm without writing any mesh geometry.

Strips any inline [2D_*] mesh-data sections and any prior [2D_MESH_FILE] block, then injects a fresh [2D_MESH_FILE] FILE <path> pointing at meshFilePath. The stored path is relative to the .inp directory when the mesh is a sibling, absolute otherwise — identical to writeExternal. Atomic via QSaveFile.

Parameters
inpPathSWMM input file to patch.
meshFilePathExisting .2dm to reference (must exist on disk).
errorOutSet on failure.
Returns
true on success.
Here is the caller graph for this function:

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