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
63
64/* =========================================================================
65 * Model finalisation and validation
66 * ========================================================================= */
67
79
92
93/* =========================================================================
94 * Model serialisation
95 * ========================================================================= */
96
109SWMM_ENGINE_API int swmm_model_write(SWMM_Engine engine, const char* new_inp_path);
110
116
138SWMM_ENGINE_API int swmm_model_write_compat(SWMM_Engine engine, const char* new_inp_path,
139 int profile);
140
182 const char* new_path,
183 const char* output_plugin_id);
184
185/* =========================================================================
186 * [PLUGINS] section access (Slice AA-3.1 Phase B)
187 *
188 * The [PLUGINS] section of an .inp file is a list of rows, one per
189 * plugin to load. Each row is `path arg1 arg2 …` where `path` resolves
190 * via the same logic as the input plugin lib (a library path, an id, or
191 * an `id:version` pair) and the trailing tokens are passed to the
192 * plugin's initialize() method as `init_args`.
193 *
194 * The accessors below let a host (GUI) read, mutate, and remove rows
195 * without re-parsing the .inp file. Plugins themselves are
196 * (re-)resolved by PluginFactory at swmm_engine_open / swmm_model_write
197 * time — these accessors only mutate the in-memory `plugin_specs` list.
198 * ========================================================================= */
199
204SWMM_ENGINE_API int swmm_plugins_count(SWMM_Engine engine, int* count);
205
225 int idx,
226 char* path_buf,
227 int path_buf_sz,
228 char* args_buf,
229 int args_buf_sz);
230
248 const char* path_or_id,
249 const char* args);
250
261swmm_plugin_remove(SWMM_Engine engine, const char* path_or_id);
262
263/* =========================================================================
264 * [FILES] section access (Slice AA-3 follow-up — secondary file refs)
265 *
266 * Read / write the legacy SWMM5 `[FILES]` section: rainfall, runoff,
267 * RDII, inflows, outflows, and hot-start file references. The
268 * accessors are keyed by an uppercase string so callers don't depend
269 * on the field layout of `FilesSpec`.
270 *
271 * Recognised keys (case-insensitive):
272 * "RAINFALL_PATH" / "RAINFALL_MODE"
273 * "RUNOFF_PATH" / "RUNOFF_MODE"
274 * "RDII_PATH" / "RDII_MODE"
275 * "INFLOWS_PATH"
276 * "OUTFLOWS_PATH"
277 * "HOTSTART_USE_PATH"
278 * "HOTSTART_SAVE_PATH" / "HOTSTART_SAVE_DATETIME"
279 *
280 * `*_MODE` keys take "SAVE" / "USE" / "" (empty clears the slot).
281 * `HOTSTART_SAVE_DATETIME` is a SWMM decimal-day floating-point string
282 * (0 == unset, write at end of run).
283 * ========================================================================= */
284
298swmm_files_get(SWMM_Engine engine, const char* key, char* buf, int buflen);
299
313swmm_files_set(SWMM_Engine engine, const char* key, const char* value);
314
315/* =========================================================================
316 * External-file path slots — typed, broader API (Slice IO-9)
317 * =========================================================================
318 *
319 * Reaches every external-file slot in the model — not just the [FILES]
320 * section — so the GUI's portability normalizer can walk a uniform list
321 * before save without per-role plumbing.
322 *
323 * Each slot carries both:
324 * - the original token as it appeared in the source `.inp`
325 * (relative-or-absolute, with whichever separators the author used);
326 * - the resolved absolute path the engine uses for `fopen`.
327 *
328 * The slot getter exposes both strings to the caller; the slot setter
329 * updates the original token and clears the cached absolute resolution
330 * (PostParseResolver re-fills it the next time it runs).
331 *
332 * See openswmm.gui/docs/IO_PORTABILITY_PLAN.md §3.3 for the storage model
333 * and §3.7 for the GUI editor contract.
334 * ========================================================================= */
335
343typedef enum SWMM_FilePathRole {
344 /* Scalar slots — `owner` ignored. */
352
353 /* Vector slots — `owner` selects the entry. */
360
361 /* Scalar slots — `owner` ignored. Unavailable (SWMM_ERR_BADPARAM) in
362 * builds without 2D support. */
365
366 /* Vector slot — `owner` selects the entry. */
370
391 const char* owner,
392 char* absolute_buf,
393 int absolute_buflen,
394 char* original_buf,
395 int original_buflen);
396
412 const char* owner,
413 const char* new_path);
414
415/* =========================================================================
416 * Title / notes access
417 * ========================================================================= */
418
426SWMM_ENGINE_API int swmm_title_get_count(SWMM_Engine engine, int* count);
427
438 SWMM_Engine engine,
439 int index,
440 char* buf,
441 int buflen
442);
443
451SWMM_ENGINE_API int swmm_title_add_line(SWMM_Engine engine, const char* line);
452
463SWMM_ENGINE_API int swmm_title_set(SWMM_Engine engine, const char* text);
464
472
473/* =========================================================================
474 * OPTIONS access
475 * ========================================================================= */
476
493 SWMM_Engine engine,
494 const char* key,
495 char* buf,
496 int buflen
497);
498
508 SWMM_Engine engine,
509 const char* key,
510 const char* value
511);
512
523 SWMM_Engine engine,
524 const char* key,
525 char* buf,
526 int buflen
527);
528
538 SWMM_Engine engine,
539 const char* key,
540 const char* value
541);
542
551SWMM_ENGINE_API int swmm_get_crs(SWMM_Engine engine, char* buf, int buflen);
552
553/* =========================================================================
554 * Typed time-control accessors
555 *
556 * Date values are SWMM OADate doubles: the integer part is days since
557 * 1899-12-30 and the fractional part is the time-of-day fraction.
558 * ========================================================================= */
559
567
575
582SWMM_ENGINE_API int swmm_options_get_end_date(SWMM_Engine engine, double* value);
583
591
599
607
608/* =========================================================================
609 * User flags
610 *
611 * Flag names are case-insensitive: they are stored uppercase, matching the
612 * [USER_FLAGS] INP handler.
613 * ========================================================================= */
614
622SWMM_ENGINE_API int swmm_userflag_get_bool(SWMM_Engine engine, const char* name, int* value);
623
631SWMM_ENGINE_API int swmm_userflag_get_int (SWMM_Engine engine, const char* name, int* value);
632
640SWMM_ENGINE_API int swmm_userflag_get_real(SWMM_Engine engine, const char* name, double* value);
641
643SWMM_ENGINE_API int swmm_userflag_set_bool(SWMM_Engine engine, const char* name, int value);
644
646SWMM_ENGINE_API int swmm_userflag_set_int (SWMM_Engine engine, const char* name, int value);
647
649SWMM_ENGINE_API int swmm_userflag_set_real(SWMM_Engine engine, const char* name, double value);
650
651/* -------------------------------------------------------------------------
652 * User flag schema definitions ([USER_FLAGS]) and per-object values
653 * ([USER_FLAG_VALUES]).
654 *
655 * Flag types (matching openswmm::UserFlagType):
656 * 0 = BOOLEAN, 1 = INTEGER, 2 = REAL, 3 = STRING.
657 *
658 * Per-object values use string form symmetric with the INP encoding:
659 * BOOLEAN as YES/NO, INTEGER as %d, REAL as %g, STRING verbatim (no quotes).
660 * Object types and flag names are case-insensitive (stored uppercase);
661 * object names are case-preserved.
662 * ------------------------------------------------------------------------- */
663
671
684 SWMM_Engine engine,
685 int index,
686 char* name_buf,
687 int name_buflen,
688 int* type,
689 char* desc_buf,
690 int desc_buflen
691);
692
704 SWMM_Engine engine,
705 const char* name,
706 int type,
707 const char* description
708);
709
716SWMM_ENGINE_API int swmm_userflag_undefine(SWMM_Engine engine, const char* name);
717
730 SWMM_Engine engine,
731 const char* obj_type,
732 const char* obj_name,
733 const char* flag_name,
734 char* buf,
735 int buflen,
736 int* found
737);
738
753 SWMM_Engine engine,
754 const char* obj_type,
755 const char* obj_name,
756 const char* flag_name,
757 const char* value
758);
759
770 SWMM_Engine engine,
771 const char* obj_type,
772 const char* obj_name,
773 const char* flag_name
774);
775
776#ifdef __cplusplus
777} /* extern "C" */
778#endif
779
780#endif /* OPENSWMM_MODEL_H */
#define SWMM_ENGINE_API
Definition openswmm_2d.h:53
void * SWMM_Engine
Opaque handle to an OpenSWMM Engine instance.
Definition openswmm_callbacks.h:51
OpenSWMM Engine — primary transparent C API (master header).
SWMM_ENGINE_API int swmm_model_write(SWMM_Engine engine, const char *new_inp_path)
Write the current model state to a SWMM input (.inp) file.
Definition openswmm_model_impl.cpp:290
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)
Assign a flag value to a specific object from a string.
Definition openswmm_model_impl.cpp:1939
SWMM_ENGINE_API int swmm_options_set_start_date(SWMM_Engine engine, double value)
Set the simulation start date/time from an OADate.
Definition openswmm_model_impl.cpp:1735
SWMM_ENGINE_API int swmm_options_set_end_date(SWMM_Engine engine, double value)
Set the simulation end date/time from an OADate.
Definition openswmm_model_impl.cpp:1750
SWMM_ENGINE_API int swmm_userflag_def_count(SWMM_Engine engine, int *count)
Number of user-flag schema definitions.
Definition openswmm_model_impl.cpp:1861
SWMM_ENGINE_API int swmm_userflag_get_bool(SWMM_Engine engine, const char *name, int *value)
Get the value of a BOOLEAN user flag (schema-level).
Definition openswmm_model_impl.cpp:1775
SWMM_ENGINE_API int swmm_title_set(SWMM_Engine engine, const char *text)
Replace all title/note lines with a single block of text.
Definition openswmm_model_impl.cpp:771
SWMM_ENGINE_API int swmm_model_write_compat(SWMM_Engine engine, const char *new_inp_path, int profile)
Write the current model state as an .inp for a given engine profile.
Definition openswmm_model_impl.cpp:300
SWMM_ENGINE_API SWMM_Engine swmm_engine_new(void)
Create an empty engine in BUILDING state (no .inp file required).
Definition openswmm_model_impl.cpp:186
SWMM_ENGINE_API int swmm_finalize_model(SWMM_Engine engine)
Finalise a programmatically-built model.
Definition openswmm_model_impl.cpp:230
SWMM_InpProfile
Definition openswmm_model.h:112
@ SWMM_INP_PROFILE_SWMM5
Definition openswmm_model.h:114
@ SWMM_INP_PROFILE_FULL
Definition openswmm_model.h:113
SWMM_ENGINE_API int swmm_options_set_report_start(SWMM_Engine engine, double value)
Set the report start date/time from an OADate.
Definition openswmm_model_impl.cpp:1765
SWMM_ENGINE_API int swmm_plugins_count(SWMM_Engine engine, int *count)
Number of [PLUGINS] entries currently registered on the engine.
Definition openswmm_model_impl.cpp:364
SWMM_ENGINE_API int swmm_plugin_set(SWMM_Engine engine, const char *path_or_id, const char *args)
Add or replace a [PLUGINS] row keyed by path_or_id.
Definition openswmm_model_impl.cpp:387
SWMM_ENGINE_API int swmm_options_set_ext(SWMM_Engine engine, const char *key, const char *value)
Set (or create) an extension OPTIONS value.
Definition openswmm_model_impl.cpp:1637
SWMM_ENGINE_API int swmm_options_get_ext(SWMM_Engine engine, const char *key, char *buf, int buflen)
Retrieve an extension OPTIONS value (keys unknown to standard SWMM).
Definition openswmm_model_impl.cpp:1598
SWMM_ENGINE_API int swmm_title_clear(SWMM_Engine engine)
Remove all lines from the [TITLE] section.
Definition openswmm_model_impl.cpp:790
SWMM_ENGINE_API int swmm_userflag_set_int(SWMM_Engine engine, const char *name, int value)
Set an INTEGER user flag at runtime.
Definition openswmm_model_impl.cpp:1833
SWMM_ENGINE_API int swmm_userflag_get_int(SWMM_Engine engine, const char *name, int *value)
Get the value of an INTEGER user flag.
Definition openswmm_model_impl.cpp:1790
SWMM_ENGINE_API int swmm_userflag_set_real(SWMM_Engine engine, const char *name, double value)
Set a REAL user flag at runtime.
Definition openswmm_model_impl.cpp:1844
SWMM_ENGINE_API int swmm_userflag_value_clear(SWMM_Engine engine, const char *obj_type, const char *obj_name, const char *flag_name)
Remove the flag value assigned to a specific object (mark unset).
Definition openswmm_model_impl.cpp:1984
SWMM_ENGINE_API int swmm_userflag_undefine(SWMM_Engine engine, const char *name)
Remove a user-flag definition and all per-object values assigned to it.
Definition openswmm_model_impl.cpp:1896
SWMM_ENGINE_API int swmm_options_set(SWMM_Engine engine, const char *key, const char *value)
Set a standard OPTIONS value.
Definition openswmm_model_impl.cpp:1137
SWMM_ENGINE_API int swmm_get_crs(SWMM_Engine engine, char *buf, int buflen)
Retrieve the CRS string (e.g., "EPSG:4326" or PROJ string).
Definition openswmm_model_impl.cpp:1714
SWMM_ENGINE_API int swmm_title_add_line(SWMM_Engine engine, const char *line)
Add a new line to the end of the [TITLE] section.
Definition openswmm_model_impl.cpp:764
SWMM_ENGINE_API int swmm_options_get_report_start(SWMM_Engine engine, double *value)
Retrieve the report start date/time as an OADate.
Definition openswmm_model_impl.cpp:1758
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 both strings from an external-file slot.
Definition openswmm_model_impl.cpp:610
SWMM_ENGINE_API int swmm_files_get(SWMM_Engine engine, const char *key, char *buf, int buflen)
Read one [FILES] field by key.
Definition openswmm_model_impl.cpp:427
SWMM_ENGINE_API int swmm_files_set(SWMM_Engine engine, const char *key, const char *value)
Write one [FILES] field by key.
Definition openswmm_model_impl.cpp:463
SWMM_ENGINE_API int swmm_options_get_end_date(SWMM_Engine engine, double *value)
Retrieve the simulation end date/time as an OADate.
Definition openswmm_model_impl.cpp:1743
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 [PLUGINS] row by index.
Definition openswmm_model_impl.cpp:371
SWMM_ENGINE_API int swmm_validate_model(SWMM_Engine engine)
Validate model topology without changing state.
Definition openswmm_model_impl.cpp:196
SWMM_ENGINE_API int swmm_options_get_start_date(SWMM_Engine engine, double *value)
Retrieve the simulation start date/time as an OADate.
Definition openswmm_model_impl.cpp:1728
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)
Retrieve a user-flag schema definition by index (insertion order).
Definition openswmm_model_impl.cpp:1869
SWMM_ENGINE_API int swmm_userflag_get_real(SWMM_Engine engine, const char *name, double *value)
Get the value of a REAL user flag.
Definition openswmm_model_impl.cpp:1805
SWMM_ENGINE_API int swmm_model_write_with_plugin(SWMM_Engine engine, const char *new_path, const char *output_plugin_id)
Write the current model state via a named writer plugin.
Definition openswmm_model_impl.cpp:317
SWMM_ENGINE_API int swmm_userflag_define(SWMM_Engine engine, const char *name, int type, const char *description)
Define (or redefine) a user flag.
Definition openswmm_model_impl.cpp:1884
SWMM_ENGINE_API int swmm_plugin_remove(SWMM_Engine engine, const char *path_or_id)
Remove the [PLUGINS] row matching path_or_id.
Definition openswmm_model_impl.cpp:411
SWMM_ENGINE_API int swmm_title_get_line(SWMM_Engine engine, int index, char *buf, int buflen)
Get a specific title/note line by index.
Definition openswmm_model_impl.cpp:751
SWMM_ENGINE_API int swmm_title_get_count(SWMM_Engine engine, int *count)
Get the number of title/note lines in the [TITLE] section.
Definition openswmm_model_impl.cpp:744
SWMM_ENGINE_API int swmm_userflag_set_bool(SWMM_Engine engine, const char *name, int value)
Set a BOOLEAN user flag at runtime.
Definition openswmm_model_impl.cpp:1820
SWMM_FilePathRole
Identifies a single external-file slot on the model.
Definition openswmm_model.h:343
@ SWMM_FILE_RAINGAGE_DATA
Definition openswmm_model.h:356
@ SWMM_FILE_INFLOWS
Definition openswmm_model.h:348
@ SWMM_FILE_HOTSTART_USE
Definition openswmm_model.h:350
@ SWMM_FILE_LID_REPORT
Definition openswmm_model.h:367
@ SWMM_FILE_TIMESERIES_DATA
Definition openswmm_model.h:358
@ SWMM_FILE_RAINFALL
Definition openswmm_model.h:345
@ SWMM_FILE_OUTFLOWS
Definition openswmm_model.h:349
@ SWMM_FILE_RDII
Definition openswmm_model.h:347
@ SWMM_FILE_RUNOFF
Definition openswmm_model.h:346
@ SWMM_FILE_CLIMATE_TEMP
Definition openswmm_model.h:351
@ SWMM_FILE_HOTSTART_SAVE
Definition openswmm_model.h:354
@ SWMM_FILE_OUTPUT_2D
Definition openswmm_model.h:364
@ SWMM_FILE_MESH_2D
Definition openswmm_model.h:363
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)
Read the flag value assigned to a specific object, as a string.
Definition openswmm_model_impl.cpp:1903
SWMM_ENGINE_API int swmm_file_path_set(SWMM_Engine engine, SWMM_FilePathRole role, const char *owner, const char *new_path)
Set the original token for an external-file slot; clears the cached absolute resolution.
Definition openswmm_model_impl.cpp:630
SWMM_ENGINE_API int swmm_options_get(SWMM_Engine engine, const char *key, char *buf, int buflen)
Retrieve a standard OPTIONS value as a string.
Definition openswmm_model_impl.cpp:800