OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
openswmm_model.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2//
3// Copyright 2026 Caleb Buahin
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
38
39#ifndef OPENSWMM_MODEL_H
40#define OPENSWMM_MODEL_H
41
42#include "openswmm_engine.h"
43
44#ifdef __cplusplus
45extern "C" {
46#endif
47
48/* =========================================================================
49 * Model building — programmatic construction (state guard: BUILDING only)
50 * ========================================================================= */
51
61
62/* =========================================================================
63 * Model finalisation and validation
64 * ========================================================================= */
65
78
92
93/* =========================================================================
94 * Model serialisation
95 * ========================================================================= */
96
111SWMM_ENGINE_API int swmm_model_write(SWMM_Engine engine, const char* new_inp_path);
112
126typedef const char* (*SWMM_StageOutputCallback)(void* user_data, const char* final_path, int kind);
144SWMM_ENGINE_API int swmm_model_write_staged(SWMM_Engine engine, const char* final_inp_path,
145 SWMM_StageOutputCallback mapper, void* user_data);
146
153
181SWMM_ENGINE_API int swmm_model_write_compat(SWMM_Engine engine, const char* new_inp_path,
182 int profile);
183
200SWMM_ENGINE_API int swmm_model_write_with_plugin(SWMM_Engine engine, const char* new_path,
201 const char* output_plugin_id);
202
203/* =========================================================================
204 * [PLUGINS] section access (Slice AA-3.1 Phase B)
205 *
206 * The [PLUGINS] section of an .inp file is a list of rows, one per
207 * plugin to load. Each row is `path arg1 arg2 …` where `path` resolves
208 * via the same logic as the input plugin lib (a library path, an id, or
209 * an `id:version` pair) and the trailing tokens are passed to the
210 * plugin's initialize() method as `init_args`.
211 *
212 * The accessors below let a host (GUI) read, mutate, and remove rows
213 * without re-parsing the .inp file. Plugins themselves are
214 * (re-)resolved by PluginFactory at swmm_engine_open / swmm_model_write
215 * time — these accessors only mutate the in-memory `plugin_specs` list.
216 * ========================================================================= */
217
228SWMM_ENGINE_API int swmm_plugins_count(SWMM_Engine engine, int* count);
229
244SWMM_ENGINE_API int swmm_plugin_get(SWMM_Engine engine, int idx, char* path_buf, int path_buf_sz,
245 char* args_buf, int args_buf_sz);
246
261SWMM_ENGINE_API int swmm_plugin_set(SWMM_Engine engine, const char* path_or_id, const char* args);
262
274SWMM_ENGINE_API int swmm_plugin_remove(SWMM_Engine engine, const char* path_or_id);
275
276/* =========================================================================
277 * [FILES] section access (Slice AA-3 follow-up — secondary file refs)
278 *
279 * Read / write the legacy SWMM5 `[FILES]` section: rainfall, runoff,
280 * RDII, inflows, outflows, and hot-start file references. The
281 * accessors are keyed by an uppercase string so callers don't depend
282 * on the field layout of `FilesSpec`.
283 *
284 * Recognised keys (case-insensitive):
285 * "RAINFALL_PATH" / "RAINFALL_MODE"
286 * "RUNOFF_PATH" / "RUNOFF_MODE"
287 * "RDII_PATH" / "RDII_MODE"
288 * "INFLOWS_PATH"
289 * "OUTFLOWS_PATH"
290 * "HOTSTART_USE_PATH"
291 * "HOTSTART_SAVE_PATH" / "HOTSTART_SAVE_DATETIME"
292 *
293 * `*_MODE` keys take "SAVE" / "USE" / "" (empty clears the slot).
294 * `HOTSTART_SAVE_DATETIME` is a SWMM decimal-day floating-point string
295 * (0 == unset, write at end of run).
296 * ========================================================================= */
297
313SWMM_ENGINE_API int swmm_files_get(SWMM_Engine engine, const char* key, char* buf, int buflen);
314
331SWMM_ENGINE_API int swmm_files_set(SWMM_Engine engine, const char* key, const char* value);
332
333/* =========================================================================
334 * External-file path slots — typed, broader API (Slice IO-9)
335 * =========================================================================
336 *
337 * Reaches every external-file slot in the model — not just the [FILES]
338 * section — so the GUI's portability normalizer can walk a uniform list
339 * before save without per-role plumbing.
340 *
341 * Each slot carries both:
342 * - the original token as it appeared in the source `.inp`
343 * (relative-or-absolute, with whichever separators the author used);
344 * - the resolved absolute path the engine uses for `fopen`.
345 *
346 * The slot getter exposes both strings to the caller; the slot setter
347 * updates the original token and clears the cached absolute resolution
348 * (PostParseResolver re-fills it the next time it runs).
349 *
350 * See openswmm.gui/docs/IO_PORTABILITY_PLAN.md §3.3 for the storage model
351 * and §3.7 for the GUI editor contract.
352 * ========================================================================= */
353
361typedef enum SWMM_FilePathRole {
362 /* Scalar slots — `owner` ignored. */
370
371 /* Vector slots — `owner` selects the entry. */
378
379 /* Scalar slots — `owner` ignored. Unavailable (SWMM_ERR_BADPARAM) in
380 * builds without 2D support. */
383
384 /* Vector slot — `owner` selects the entry. */
388
410 const char* owner, char* absolute_buf, int absolute_buflen,
411 char* original_buf, int original_buflen);
412
429 const char* owner, const char* new_path);
430
431/* =========================================================================
432 * Title / notes access
433 * ========================================================================= */
434
443SWMM_ENGINE_API int swmm_title_get_count(SWMM_Engine engine, int* count);
444
456SWMM_ENGINE_API int swmm_title_get_line(SWMM_Engine engine, int index, char* buf, int buflen);
457
467SWMM_ENGINE_API int swmm_title_add_line(SWMM_Engine engine, const char* line);
468
480SWMM_ENGINE_API int swmm_title_set(SWMM_Engine engine, const char* text);
481
489
490/* =========================================================================
491 * OPTIONS access
492 * ========================================================================= */
493
509SWMM_ENGINE_API int swmm_options_get(SWMM_Engine engine, const char* key, char* buf, int buflen);
510
527SWMM_ENGINE_API int swmm_options_set(SWMM_Engine engine, const char* key, const char* value);
528
545SWMM_ENGINE_API int swmm_options_get_ext(SWMM_Engine engine, const char* key, char* buf,
546 int buflen);
547
565SWMM_ENGINE_API int swmm_options_set_ext(SWMM_Engine engine, const char* key, const char* value);
566
576
586SWMM_ENGINE_API int swmm_options_key_at(int index, char* buf, int buflen);
587
601
613SWMM_ENGINE_API int swmm_options_ext_key_at(SWMM_Engine engine, int index, char* buf,
614 int buflen);
615
629SWMM_ENGINE_API int swmm_get_crs(SWMM_Engine engine, char* buf, int buflen);
630
631/* =========================================================================
632 * Typed time-control accessors
633 *
634 * Date values are SWMM OADate doubles: the integer part is days since
635 * 1899-12-30 and the fractional part is the time-of-day fraction.
636 * ========================================================================= */
637
648
661
671SWMM_ENGINE_API int swmm_options_get_end_date(SWMM_Engine engine, double* value);
672
685
696
709
710/* =========================================================================
711 * User flags
712 *
713 * Flag names are case-insensitive: they are stored uppercase, matching the
714 * [USER_FLAGS] INP handler.
715 * ========================================================================= */
716
731SWMM_ENGINE_API int swmm_userflag_get_bool(SWMM_Engine engine, const char* name, int* value);
732
747SWMM_ENGINE_API int swmm_userflag_get_int(SWMM_Engine engine, const char* name, int* value);
748
763SWMM_ENGINE_API int swmm_userflag_get_real(SWMM_Engine engine, const char* name, double* value);
764
778SWMM_ENGINE_API int swmm_userflag_set_bool(SWMM_Engine engine, const char* name, int value);
779
793SWMM_ENGINE_API int swmm_userflag_set_int(SWMM_Engine engine, const char* name, int value);
794
808SWMM_ENGINE_API int swmm_userflag_set_real(SWMM_Engine engine, const char* name, double value);
809
810/* -------------------------------------------------------------------------
811 * User flag schema definitions ([USER_FLAGS]) and per-object values
812 * ([USER_FLAG_VALUES]).
813 *
814 * Flag types (matching openswmm::UserFlagType):
815 * 0 = BOOLEAN, 1 = INTEGER, 2 = REAL, 3 = STRING.
816 *
817 * Per-object values use string form symmetric with the INP encoding:
818 * BOOLEAN as YES/NO, INTEGER as %d, REAL as %g, STRING verbatim (no quotes).
819 * Object types and flag names are case-insensitive (stored uppercase);
820 * object names are case-preserved.
821 * ------------------------------------------------------------------------- */
822
832
848SWMM_ENGINE_API int swmm_userflag_def_get(SWMM_Engine engine, int index, char* name_buf,
849 int name_buflen, int* type, char* desc_buf,
850 int desc_buflen);
851
866SWMM_ENGINE_API int swmm_userflag_define(SWMM_Engine engine, const char* name, int type,
867 const char* description);
868
877SWMM_ENGINE_API int swmm_userflag_undefine(SWMM_Engine engine, const char* name);
878
900SWMM_ENGINE_API int swmm_userflag_value_get(SWMM_Engine engine, const char* obj_type,
901 const char* obj_name, const char* flag_name, char* buf,
902 int buflen, int* found);
903
924SWMM_ENGINE_API int swmm_userflag_value_set(SWMM_Engine engine, const char* obj_type,
925 const char* obj_name, const char* flag_name,
926 const char* value);
927
943SWMM_ENGINE_API int swmm_userflag_value_clear(SWMM_Engine engine, const char* obj_type,
944 const char* obj_name, const char* flag_name);
945
946#ifdef __cplusplus
947} /* extern "C" */
948#endif
949
950#endif /* OPENSWMM_MODEL_H */
#define SWMM_ENGINE_API
Definition openswmm_2d.h:62
void * SWMM_Engine
Opaque handle to an OpenSWMM Engine instance.
Definition openswmm_callbacks.h:55
OpenSWMM Engine — primary transparent C API (master header).
SWMM_ENGINE_API int swmm_model_write(SWMM_Engine engine, const char *new_inp_path)
Serialize the current model with the built-in INP writer.
Definition openswmm_model_impl.cpp:455
SWMM_ENGINE_API int swmm_userflag_value_set(SWMM_Engine engine, const char *obj_type, const char *obj_name, const char *flag_name, const char *value)
Parse a copied assignment using an existing flag schema.
Definition openswmm_model_impl.cpp:2690
SWMM_ENGINE_API int swmm_options_set_start_date(SWMM_Engine engine, double value)
Assign the simulation start calendar value directly.
Definition openswmm_model_impl.cpp:2468
SWMM_ENGINE_API int swmm_options_set_end_date(SWMM_Engine engine, double value)
Assign the simulation end calendar value directly.
Definition openswmm_model_impl.cpp:2484
SWMM_ENGINE_API int swmm_userflag_def_count(SWMM_Engine engine, int *count)
Count user-flag schema definitions.
Definition openswmm_model_impl.cpp:2611
SWMM_ENGINE_API int swmm_userflag_get_bool(SWMM_Engine engine, const char *name, int *value)
Read a model-level BOOLEAN flag assignment.
Definition openswmm_model_impl.cpp:2510
SWMM_ENGINE_API int swmm_title_set(SWMM_Engine engine, const char *text)
Replace title entries by splitting copied text at newline characters.
Definition openswmm_model_impl.cpp:1080
SWMM_ENGINE_API int swmm_options_key_at(int index, char *buf, int buflen)
Copy one standard option key by position.
Definition openswmm_model_impl.cpp:2387
SWMM_ENGINE_API int swmm_model_write_compat(SWMM_Engine engine, const char *new_inp_path, int profile)
Serialize the model to a selected INP compatibility profile.
Definition openswmm_model_impl.cpp:481
SWMM_ENGINE_API SWMM_Engine swmm_engine_new(void)
Create an empty programmatically editable engine in SWMM_STATE_BUILDING.
Definition openswmm_model_impl.cpp:328
SWMM_ENGINE_API int swmm_finalize_model(SWMM_Engine engine)
Resolve and initialize a programmatically built model.
Definition openswmm_model_impl.cpp:373
SWMM_InpProfile
Definition openswmm_model.h:148
@ SWMM_INP_PROFILE_SWMM5_STOCK
Definition openswmm_model.h:151
@ SWMM_INP_PROFILE_SWMM5
Definition openswmm_model.h:150
@ SWMM_INP_PROFILE_FULL
Definition openswmm_model.h:149
SWMM_ENGINE_API int swmm_options_set_report_start(SWMM_Engine engine, double value)
Assign the report start calendar value directly.
Definition openswmm_model_impl.cpp:2500
SWMM_ENGINE_API int swmm_plugins_count(SWMM_Engine engine, int *count)
Count stored [PLUGINS] specifications.
Definition openswmm_model_impl.cpp:576
SWMM_ENGINE_API int swmm_options_ext_key_count(SWMM_Engine engine, int *count)
Number of keys swmm_options_get_ext() currently accepts on this engine.
Definition openswmm_model_impl.cpp:2420
SWMM_ENGINE_API int swmm_plugin_set(SWMM_Engine engine, const char *path_or_id, const char *args)
Add or replace a copied plugin specification by exact path/ID key.
Definition openswmm_model_impl.cpp:597
SWMM_ENGINE_API int swmm_options_set_ext(SWMM_Engine engine, const char *key, const char *value)
Set a recognized 2D option or retain a generic extension key/value.
Definition openswmm_model_impl.cpp:2293
SWMM_ENGINE_API int swmm_options_get_ext(SWMM_Engine engine, const char *key, char *buf, int buflen)
Read a live 2D option or stored extension string.
Definition openswmm_model_impl.cpp:2252
SWMM_ENGINE_API int swmm_title_clear(SWMM_Engine engine)
Remove all title/note entries.
Definition openswmm_model_impl.cpp:1100
SWMM_ENGINE_API int swmm_userflag_set_int(SWMM_Engine engine, const char *name, int value)
Define a INTEGER flag and assign its model-level value.
Definition openswmm_model_impl.cpp:2583
SWMM_ENGINE_API int swmm_userflag_get_int(SWMM_Engine engine, const char *name, int *value)
Read a model-level INTEGER flag assignment.
Definition openswmm_model_impl.cpp:2530
SWMM_ENGINE_API int swmm_userflag_set_real(SWMM_Engine engine, const char *name, double value)
Define a REAL flag and assign its model-level value.
Definition openswmm_model_impl.cpp:2594
SWMM_ENGINE_API int swmm_userflag_value_clear(SWMM_Engine engine, const char *obj_type, const char *obj_name, const char *flag_name)
Remove one per-object assignment, leaving its schema intact.
Definition openswmm_model_impl.cpp:2733
SWMM_ENGINE_API int swmm_userflag_undefine(SWMM_Engine engine, const char *name)
Remove a schema and all assignments of that flag.
Definition openswmm_model_impl.cpp:2649
SWMM_ENGINE_API int swmm_options_set(SWMM_Engine engine, const char *key, const char *value)
Parse and assign a supported standard simulation option.
Definition openswmm_model_impl.cpp:1617
const char *(* SWMM_StageOutputCallback)(void *user_data, const char *final_path, int kind)
Map a final writer output path to its private physical staging destination.
Definition openswmm_model.h:126
SWMM_ENGINE_API int swmm_get_crs(SWMM_Engine engine, char *buf, int buflen)
Copy the configured coordinate-reference-system string.
Definition openswmm_model_impl.cpp:2441
SWMM_ENGINE_API int swmm_title_add_line(SWMM_Engine engine, const char *line)
Append a copied title/note entry.
Definition openswmm_model_impl.cpp:1072
SWMM_ENGINE_API int swmm_options_get_report_start(SWMM_Engine engine, double *value)
Read the configured report start calendar value.
Definition openswmm_model_impl.cpp:2492
SWMM_ENGINE_API int swmm_file_path_get(SWMM_Engine engine, SWMM_FilePathRole role, const char *owner, char *absolute_buf, int absolute_buflen, char *original_buf, int original_buflen)
Read resolved and original strings for an existing external-file slot.
Definition openswmm_model_impl.cpp:869
SWMM_ENGINE_API int swmm_files_get(SWMM_Engine engine, const char *key, char *buf, int buflen)
Read a legacy [FILES] authoring field by case-insensitive key.
Definition openswmm_model_impl.cpp:640
SWMM_ENGINE_API int swmm_files_set(SWMM_Engine engine, const char *key, const char *value)
Set one copied legacy [FILES] authoring field.
Definition openswmm_model_impl.cpp:684
SWMM_ENGINE_API int swmm_options_get_end_date(SWMM_Engine engine, double *value)
Read the configured simulation end calendar value.
Definition openswmm_model_impl.cpp:2476
SWMM_ENGINE_API int swmm_plugin_get(SWMM_Engine engine, int idx, char *path_buf, int path_buf_sz, char *args_buf, int args_buf_sz)
Read one stored [PLUGINS] row without resolving/loading it.
Definition openswmm_model_impl.cpp:584
SWMM_ENGINE_API int swmm_validate_model(SWMM_Engine engine)
Check the minimal programmatic topology prerequisites without changing state.
Definition openswmm_model_impl.cpp:338
SWMM_ENGINE_API int swmm_options_get_start_date(SWMM_Engine engine, double *value)
Read the configured simulation start calendar value.
Definition openswmm_model_impl.cpp:2460
SWMM_ENGINE_API int swmm_model_write_staged(SWMM_Engine engine, const char *final_inp_path, SWMM_StageOutputCallback mapper, void *user_data)
Serialize built-in INP outputs through a mandatory caller staging mapper.
Definition openswmm_model_impl.cpp:465
SWMM_ENGINE_API int swmm_userflag_def_get(SWMM_Engine engine, int index, char *name_buf, int name_buflen, int *type, char *desc_buf, int desc_buflen)
Read a flag definition by insertion-order index.
Definition openswmm_model_impl.cpp:2619
SWMM_ENGINE_API int swmm_userflag_get_real(SWMM_Engine engine, const char *name, double *value)
Read a model-level REAL flag assignment.
Definition openswmm_model_impl.cpp:2550
SWMM_ENGINE_API int swmm_model_write_with_plugin(SWMM_Engine engine, const char *new_path, const char *output_plugin_id)
Serialize through a transient named input/writer plugin.
Definition openswmm_model_impl.cpp:506
SWMM_ENGINE_API int swmm_userflag_define(SWMM_Engine engine, const char *name, int type, const char *description)
Define or replace a flag schema without converting assigned values.
Definition openswmm_model_impl.cpp:2636
SWMM_ENGINE_API int swmm_plugin_remove(SWMM_Engine engine, const char *path_or_id)
Remove the first exact-matching stored plugin specification.
Definition openswmm_model_impl.cpp:620
SWMM_ENGINE_API int swmm_title_get_line(SWMM_Engine engine, int index, char *buf, int buflen)
Copy one stored title/note line.
Definition openswmm_model_impl.cpp:1059
SWMM_ENGINE_API int swmm_title_get_count(SWMM_Engine engine, int *count)
Count stored [TITLE] note lines.
Definition openswmm_model_impl.cpp:1051
SWMM_ENGINE_API int swmm_userflag_set_bool(SWMM_Engine engine, const char *name, int value)
Define a BOOLEAN flag and assign its model-level value.
Definition openswmm_model_impl.cpp:2570
SWMM_FilePathRole
Identifies a single external-file slot on the model.
Definition openswmm_model.h:361
@ SWMM_FILE_RAINGAGE_DATA
Definition openswmm_model.h:374
@ SWMM_FILE_INFLOWS
Definition openswmm_model.h:366
@ SWMM_FILE_HOTSTART_USE
Definition openswmm_model.h:368
@ SWMM_FILE_LID_REPORT
Definition openswmm_model.h:385
@ SWMM_FILE_TIMESERIES_DATA
Definition openswmm_model.h:376
@ SWMM_FILE_RAINFALL
Definition openswmm_model.h:363
@ SWMM_FILE_OUTFLOWS
Definition openswmm_model.h:367
@ SWMM_FILE_RDII
Definition openswmm_model.h:365
@ SWMM_FILE_RUNOFF
Definition openswmm_model.h:364
@ SWMM_FILE_CLIMATE_TEMP
Definition openswmm_model.h:369
@ SWMM_FILE_HOTSTART_SAVE
Definition openswmm_model.h:372
@ SWMM_FILE_OUTPUT_2D
Definition openswmm_model.h:382
@ SWMM_FILE_MESH_2D
Definition openswmm_model.h:381
SWMM_ENGINE_API int swmm_userflag_value_get(SWMM_Engine engine, const char *obj_type, const char *obj_name, const char *flag_name, char *buf, int buflen, int *found)
Format a stored per-object flag assignment as text.
Definition openswmm_model_impl.cpp:2657
SWMM_ENGINE_API int swmm_file_path_set(SWMM_Engine engine, SWMM_FilePathRole role, const char *owner, const char *new_path)
Replace an external-file token and invalidate its cached absolute path.
Definition openswmm_model_impl.cpp:884
SWMM_ENGINE_API int swmm_options_ext_key_at(SWMM_Engine engine, int index, char *buf, int buflen)
Copy one key accepted by swmm_options_get_ext() by position.
Definition openswmm_model_impl.cpp:2428
SWMM_ENGINE_API int swmm_options_get(SWMM_Engine engine, const char *key, char *buf, int buflen)
Format a supported standard option in input-compatible string form.
Definition openswmm_model_impl.cpp:1138
SWMM_ENGINE_API int swmm_options_key_count(void)
Number of standard option keys accepted by swmm_options_get() and swmm_options_set().
Definition openswmm_model_impl.cpp:2383