Stateless writer that renders a MeshResult plus CouplingMap as SWMM [2D_*] section text and writes or patches it into a .inp and, in External mode, a sidecar .2dm.
More...
#include <mesh/inpmeshwriter.h>
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 native geometry, coupling and infiltration sections into an owned text block. | |
| static QString | buildBCSectionText (const QVector< MeshEdgeBC > &bcs) |
| Render authored cell/local-edge boundary rows with raw variant parameters. | |
| static QString | buildConveyanceSectionText (const MeshResult &mesh, const QVector< MeshEdgeBC > &bcs) |
| Render one nondefault conveyance factor per undirected real mesh edge. | |
| 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={}) |
| Publish a native mesh sidecar, then retarget an existing INP to that sidecar. | |
| 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={}) |
| Publish sidecar/reference first, then append requested boundary/conveyance sections to the INP. | |
| static bool | writeInline (const QString &inpPath, const MeshResult &mesh, const CouplingMap &coupling, double defaultMannings=0.035, QString *errorOut=nullptr, const UnitInfo &units={}) |
| Replace GUI-owned mesh sections and any external mesh reference with an inline mesh. | |
| static bool | writeInline (const QString &inpPath, const MeshResult &mesh, const CouplingMap &coupling, const QVector< MeshEdgeBC > &bcs, double defaultMannings, QString *errorOut=nullptr, const UnitInfo &units={}) |
| Commit inline geometry, then append requested boundary/conveyance text in a second commit. | |
| static bool | writeMeshFileRef (const QString &inpPath, const QString &meshFilePath, QString *errorOut=nullptr) |
| Replace GUI-owned inline mesh sections with a reference to an existing filesystem entry. | |
| static bool | writePreparedMeshFileRef (const QString &inpPath, const QString &logicalFinalMeshPath, const QString &physicalStagedMeshPath, QString *errorOut=nullptr) |
| Publish an INP reference to a final logical mesh name after checking a physical staged file. | |
| static bool | validateTopologyReplacement (const QString &filePath, QString *errorOut=nullptr) |
| Read a model and reject recognized unsupported mesh-indexed assignments before replacement. | |
| static bool | replaceMeshSections (const QString &filePath, const MeshResult &mesh, const QVector< MeshEdgeBC > &bcs, QString *errorOut=nullptr, double defaultMannings=0.035, const UnitInfo *units=nullptr) |
| Replace the complete owned topology and attributes in one checked single-file commit. | |
| static bool | patchBCSections (const QString &filePath, const MeshResult &mesh, const QVector< MeshEdgeBC > &bcs, QString *errorOut=nullptr) |
| Replace only owned boundary/conveyance sections in one file. | |
| static bool | patchAttributeSections (const QString &filePath, const MeshResult &mesh, QString *errorOut=nullptr, double defaultMannings=0.035, const UnitInfo *units=nullptr) |
| Rewrite owned geometry attributes/coupling/infiltration after matching row counts. | |
| static bool | patchMeshSections (const QString &filePath, const MeshResult &mesh, const QVector< MeshEdgeBC > &bcs, QString *errorOut=nullptr, double defaultMannings=0.035, const UnitInfo *units=nullptr) |
| Patch matched mesh attributes and complete boundary state in one atomic file update. | |
| static bool | clearMeshFileRef (const QString &inpPath, QString *errorOut=nullptr) |
| Strip recognized external-reference blocks while preserving inline mesh and other 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={}) |
| Dispatch to the geometry-only external or inline publication strategy. | |
Stateless writer that renders a MeshResult plus CouplingMap as SWMM [2D_*] section text and writes or patches it into a .inp and, in External mode, a sidecar .2dm.
Every function is static and keeps no state between calls; values are written in the units the mesh already carries (no conversion). File commits use QSaveFile per file, but a two-file write is not a transaction; see each function for its failure behaviour.
|
staticnodiscard |
Render authored cell/local-edge boundary rows with raw variant parameters.
| [in] | bcs | Borrowed stride-four cell-edge vector, unchanged; caller supplies all slots, default triangle padding, consistent shared-edge factors and valid variant values/names. |
Slice §V.VD.1 — render the [2D_BOUNDARY_CONDITIONS] section for the per-edge BC vector. Returns an empty string when every edge is default Wall without a group (avoids polluting the .inp with a section that round-trips to default). Format:
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).
|
staticnodiscard |
Render one nondefault conveyance factor per undirected real mesh edge.
| [in] | mesh | Borrowed authoring mesh, unchanged. Coordinates/depths/parameters retain supplied units; caller validates finite geometry, indices, token-safe tags and triangle-before-quad engine order. |
| [in] | bcs | Borrowed stride-four cell-edge vector, unchanged; caller supplies all slots, default triangle padding, consistent shared-edge factors and valid variant values/names. |
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):
CONVEYANCE is a dimensionless multiplier in [0, 1]. 1.0 (default) is unrestricted; 0.0 is a closed (impermeable) edge.
|
staticnodiscard |
Render native geometry, coupling and infiltration sections into an owned text block.
| [in] | mesh | Borrowed authoring mesh, unchanged. Coordinates/depths/parameters retain supplied units; caller validates finite geometry, indices, token-safe tags and triangle-before-quad engine order. |
| [in] | coupling | Borrowed node/roughness maps, unchanged. Node identifiers/tags must be whitespace-grammar-safe. Cell roughness comes from triangleMannings/defaultMannings, not MeshTriangle::mannings. |
| [in] | defaultMannings | Manning roughness in the authored model convention, used where the coupling map lacks a cell entry; no physical/range validation. |
| [in] | units | Borrowed UNITS/SOURCE_CRS metadata, unchanged; no reprojection or numerical unit conversion. Nonempty values emit comments. |
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.
|
staticnodiscard |
Strip recognized external-reference blocks while preserving inline mesh and other sections.
| [in] | inpPath | Borrowed existing readable INP pathname. |
| [out] | errorOut | Optional borrowed diagnostic, set on checked failure; not cleared on success. No pointer retained. |
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.
|
staticnodiscard |
Rewrite owned geometry attributes/coupling/infiltration after matching row counts.
| [in] | filePath | Borrowed existing readable INP/native mesh target. |
| [in] | mesh | Borrowed authoring mesh, unchanged. Coordinates/depths/parameters retain supplied units; caller validates finite geometry, indices, token-safe tags and triangle-before-quad engine order. |
| [out] | errorOut | Optional borrowed diagnostic, set on checked failure; not cleared on success. No pointer retained. |
| [in] | defaultMannings | Roughness materialized only when a row needs later depth/tag columns and neither a positive finite mesh value nor a parseable old roughness token is available. |
| [in] | units | Optional borrowed metadata. Null preserves last existing UNITS/SOURCE_CRS values; nonnull replaces UNITS even with empty text and replaces SOURCE_CRS only when nonempty. No numerical conversion. |
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.
Re-emits the layer's geometry, attributes, coupling and infiltration. The layer is authoritative for these editable fields; 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.
|
staticnodiscard |
Replace only owned boundary/conveyance sections in one file.
| [in] | filePath | Borrowed existing readable INP/native mesh target. |
| [in] | mesh | Borrowed authoring mesh, unchanged. Coordinates/depths/parameters retain supplied units; caller validates finite geometry, indices, token-safe tags and triangle-before-quad engine order. |
| [in] | bcs | Borrowed stride-four cell-edge vector, unchanged; caller supplies all slots, default triangle padding, consistent shared-edge factors and valid variant values/names. |
| [out] | errorOut | Optional borrowed diagnostic, set on checked failure; not cleared on success. No pointer retained. |
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.
All-default bcs strips the sections without appending (reset-to-Wall round-trips). Atomic via QSaveFile.
|
staticnodiscard |
Patch matched mesh attributes and complete boundary state in one atomic file update.
| [in] | filePath | Borrowed existing readable INP/native mesh target. |
| [in] | mesh | Borrowed authoring mesh, unchanged. Coordinates/depths/parameters retain supplied units; caller validates finite geometry, indices, token-safe tags and triangle-before-quad engine order. |
| [in] | bcs | Borrowed stride-four cell-edge vector, unchanged; caller supplies all slots, default triangle padding, consistent shared-edge factors and valid variant values/names. |
| [out] | errorOut | Optional borrowed diagnostic, set on checked failure; not cleared on success. No pointer retained. |
| [in] | defaultMannings | Positional-column fallback roughness, using patchAttributeSections rules. |
| [in] | units | Optional borrowed metadata. Null preserves last existing UNITS/SOURCE_CRS values; nonnull replaces UNITS even with empty text and replaces SOURCE_CRS only when nonempty. No numerical conversion. |
Replace mesh attributes and BC/conveyance sections together.
Uses the same payload and metadata rules as patchAttributeSections and patchBCSections, with one checked read and one atomic QSaveFile commit. Row counts and the complete edge-slot vector must match. Validation or write failure leaves this file unchanged; other files involved in a project Save are outside this single-file guarantee.
|
staticnodiscard |
Replace the complete owned topology and attributes in one checked single-file commit.
| [in] | filePath | Borrowed existing readable target INP/native mesh pathname. |
| [in] | mesh | Borrowed authoring mesh, unchanged. Coordinates/depths/parameters retain supplied units; caller validates finite geometry, indices, token-safe tags and triangle-before-quad engine order. |
| [in] | bcs | Borrowed stride-four cell-edge vector, unchanged; caller supplies all slots, default triangle padding, consistent shared-edge factors and valid variant values/names. |
| [out] | errorOut | Optional borrowed diagnostic, set on checked failure; not cleared on success. No pointer retained. |
| [in] | defaultMannings | Authored roughness fallback for cells whose mesh.mannings is nonfinite; finite values, including nonpositive ones, are copied without physical validation. |
| [in] | units | Optional borrowed metadata. Null preserves last existing UNITS/SOURCE_CRS values; nonnull replaces UNITS even with empty text and replaces SOURCE_CRS only when nonempty. No numerical conversion. |
Replace the complete GUI-owned mesh in a prepared INP/mesh file, without requiring its old topology or row counts to match. Rebuilds coupling from coupledNode/cellCouplings and replaces geometry, attributes, infiltration, boundary conditions and conveyance in one atomic write. Unsupported topology-indexed rows fail without changing the file. Removes any old external mesh reference. Null units preserve metadata; explicit units follow patchMeshSections' metadata rules.
|
staticnodiscard |
Read a model and reject recognized unsupported mesh-indexed assignments before replacement.
| [in] | filePath | Borrowed input/sidecar pathname, read only; whole UTF-8 content is loaded. |
| [out] | errorOut | Optional borrowed diagnostic, set on checked failure; not cleared on success. No pointer retained. |
Refuse unsupported mesh-indexed velocity, quality and groundwater assignments before topology replacement, including tag assignments whose meaning needs remapping. Global/XY/AUTO configuration is retained. This is an ownership guard, not a complete engine syntax validator. Does not modify the file.
|
staticnodiscard |
Dispatch to the geometry-only external or inline publication strategy.
| [in] | mode | External or Inline; unknown enum values return false without setting errorOut. |
| [in] | inpPath | Borrowed existing readable INP target. |
| [in] | meshFilePath | Borrowed sidecar target used only for External; empty selects the default. |
| [in] | mesh | Borrowed authoring mesh, unchanged. Coordinates/depths/parameters retain supplied units; caller validates finite geometry, indices, token-safe tags and triangle-before-quad engine order. |
| [in] | coupling | Borrowed node/roughness maps, unchanged. Node identifiers/tags must be whitespace-grammar-safe. Cell roughness comes from triangleMannings/defaultMannings, not MeshTriangle::mannings. |
| [in] | defaultMannings | Manning roughness in the authored model convention, used where the coupling map lacks a cell entry; no physical/range validation. |
| [out] | errorOut | Optional borrowed diagnostic, set on checked failure; not cleared on success. No pointer retained. |
| [in] | units | Borrowed UNITS/SOURCE_CRS metadata, unchanged; no reprojection or numerical unit conversion. Nonempty values emit comments. |
Convenience dispatch on MeshOutputMode.
|
staticnodiscard |
Publish sidecar/reference first, then append requested boundary/conveyance sections to the INP.
| [in] | inpPath | Borrowed readable INP target and relative-path anchor. |
| [in] | meshFilePath | Borrowed distinct sidecar target; empty chooses the default .2dm name. |
| [in] | mesh | Borrowed authoring mesh, unchanged. Coordinates/depths/parameters retain supplied units; caller validates finite geometry, indices, token-safe tags and triangle-before-quad engine order. |
| [in] | coupling | Borrowed node/roughness maps, unchanged. Node identifiers/tags must be whitespace-grammar-safe. Cell roughness comes from triangleMannings/defaultMannings, not MeshTriangle::mannings. |
| [in] | bcs | Borrowed stride-four cell-edge vector, unchanged; caller supplies all slots, default triangle padding, consistent shared-edge factors and valid variant values/names. |
| [in] | defaultMannings | Manning roughness in the authored model convention, used where the coupling map lacks a cell entry; no physical/range validation. |
| [out] | errorOut | Optional borrowed diagnostic, set on checked failure; not cleared on success. No pointer retained. |
| [in] | units | Borrowed UNITS/SOURCE_CRS metadata, unchanged; no reprojection or numerical unit conversion. Nonempty values emit comments. |
§V.VD.1 overload — additionally writes the [2D_BOUNDARY_CONDITIONS] section. Empty / fully default BC vector is equivalent to the non-BC overload (section is omitted).
|
staticnodiscard |
Publish a native mesh sidecar, then retarget an existing INP to that sidecar.
| [in] | inpPath | Borrowed existing readable INP pathname, also the anchor for stored relative paths. |
| [in] | meshFilePath | Borrowed distinct sidecar pathname; empty selects the INP complete base name followed by .2dm in its directory. Existing sidecar may be replaced. |
| [in] | mesh | Borrowed authoring mesh, unchanged. Coordinates/depths/parameters retain supplied units; caller validates finite geometry, indices, token-safe tags and triangle-before-quad engine order. |
| [in] | coupling | Borrowed node/roughness maps, unchanged. Node identifiers/tags must be whitespace-grammar-safe. Cell roughness comes from triangleMannings/defaultMannings, not MeshTriangle::mannings. |
| [in] | defaultMannings | Manning roughness in the authored model convention, used where the coupling map lacks a cell entry; no physical/range validation. |
| [out] | errorOut | Optional borrowed diagnostic, set on checked failure; not cleared on success. No pointer retained. |
| [in] | units | Borrowed UNITS/SOURCE_CRS metadata, unchanged; no reprojection or numerical unit conversion. Nonempty values emit comments. |
Default mode: write the mesh into a sibling .2dm file and patch the .inp with a [2D_MESH_FILE] reference.
Both writes are atomic via QSaveFile. The .inp's GUI-owned mesh-data 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 whenever representable, including parent-directory paths; absolute otherwise.
|
staticnodiscard |
Commit inline geometry, then append requested boundary/conveyance text in a second commit.
| [in] | inpPath | Borrowed existing readable INP pathname. |
| [in] | mesh | Borrowed authoring mesh, unchanged. Coordinates/depths/parameters retain supplied units; caller validates finite geometry, indices, token-safe tags and triangle-before-quad engine order. |
| [in] | coupling | Borrowed node/roughness maps, unchanged. Node identifiers/tags must be whitespace-grammar-safe. Cell roughness comes from triangleMannings/defaultMannings, not MeshTriangle::mannings. |
| [in] | bcs | Borrowed stride-four cell-edge vector, unchanged; caller supplies all slots, default triangle padding, consistent shared-edge factors and valid variant values/names. |
| [in] | defaultMannings | Manning roughness in the authored model convention, used where the coupling map lacks a cell entry; no physical/range validation. |
| [out] | errorOut | Optional borrowed diagnostic, set on checked failure; not cleared on success. No pointer retained. |
| [in] | units | Borrowed UNITS/SOURCE_CRS metadata, unchanged; no reprojection or numerical unit conversion. Nonempty values emit comments. |
§V.VD.1 overload — additionally writes the [2D_BOUNDARY_CONDITIONS] section inline.
|
staticnodiscard |
Replace GUI-owned mesh sections and any external mesh reference with an inline mesh.
| [in] | inpPath | Borrowed existing readable INP pathname to replace atomically. |
| [in] | mesh | Borrowed authoring mesh, unchanged. Coordinates/depths/parameters retain supplied units; caller validates finite geometry, indices, token-safe tags and triangle-before-quad engine order. |
| [in] | coupling | Borrowed node/roughness maps, unchanged. Node identifiers/tags must be whitespace-grammar-safe. Cell roughness comes from triangleMannings/defaultMannings, not MeshTriangle::mannings. |
| [in] | defaultMannings | Manning roughness in the authored model convention, used where the coupling map lacks a cell entry; no physical/range validation. |
| [out] | errorOut | Optional borrowed diagnostic, set on checked failure; not cleared on success. No pointer retained. |
| [in] | units | Borrowed UNITS/SOURCE_CRS metadata, unchanged; no reprojection or numerical unit conversion. Nonempty values emit comments. |
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.
|
staticnodiscard |
Replace GUI-owned inline mesh sections with a reference to an existing filesystem entry.
| [in] | inpPath | Borrowed existing readable INP to publish. |
| [in] | meshFilePath | Borrowed nonempty existing target; checked for existence only, not regularity, size, grammar or valid mesh contents. |
| [out] | errorOut | Optional borrowed diagnostic, set on checked failure; not cleared on success. No pointer retained. |
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 whenever representable, absolute otherwise — identical to writeExternal. Atomic via QSaveFile.
|
staticnodiscard |
Publish an INP reference to a final logical mesh name after checking a physical staged file.
| [in] | inpPath | Borrowed readable INP target; must retain the final model directory anchor so relative references resolve correctly after adoption. |
| [in] | logicalFinalMeshPath | Borrowed nonempty logical target, not required to exist yet. |
| [in] | physicalStagedMeshPath | Borrowed existing regular nonempty staged file to check; contents and correspondence to the logical target are not validated. |
| [out] | errorOut | Optional borrowed diagnostic, set on checked failure; not cleared on success. No pointer retained. |
Reference a prepared mesh using its final logical name. The physical staged file must exist, be regular and nonempty; the logical final file need not exist yet. inpPath must retain the final model's directory anchor for relative references. Publishes only inpPath, atomically.