OpenSWMM Engine  6.0.0-alpha.3
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.3)
Loading...
Searching...
No Matches
openswmm_model.h
Go to the documentation of this file.
1
22
23#ifndef OPENSWMM_MODEL_H
24#define OPENSWMM_MODEL_H
25
26#include "openswmm_engine.h"
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32/* =========================================================================
33 * Model building — programmatic construction (state guard: BUILDING only)
34 * ========================================================================= */
35
47
48/* =========================================================================
49 * Model finalisation and validation
50 * ========================================================================= */
51
63
76
77/* =========================================================================
78 * Model serialisation
79 * ========================================================================= */
80
93SWMM_ENGINE_API int swmm_model_write(SWMM_Engine engine, const char* new_inp_path);
94
136 const char* new_path,
137 const char* output_plugin_id);
138
139/* =========================================================================
140 * [PLUGINS] section access (Slice AA-3.1 Phase B)
141 *
142 * The [PLUGINS] section of an .inp file is a list of rows, one per
143 * plugin to load. Each row is `path arg1 arg2 …` where `path` resolves
144 * via the same logic as the input plugin lib (a library path, an id, or
145 * an `id:version` pair) and the trailing tokens are passed to the
146 * plugin's initialize() method as `init_args`.
147 *
148 * The accessors below let a host (GUI) read, mutate, and remove rows
149 * without re-parsing the .inp file. Plugins themselves are
150 * (re-)resolved by PluginFactory at swmm_engine_open / swmm_model_write
151 * time — these accessors only mutate the in-memory `plugin_specs` list.
152 * ========================================================================= */
153
158SWMM_ENGINE_API int swmm_plugins_count(SWMM_Engine engine, int* count);
159
179 int idx,
180 char* path_buf,
181 int path_buf_sz,
182 char* args_buf,
183 int args_buf_sz);
184
202 const char* path_or_id,
203 const char* args);
204
215swmm_plugin_remove(SWMM_Engine engine, const char* path_or_id);
216
217/* =========================================================================
218 * [FILES] section access (Slice AA-3 follow-up — secondary file refs)
219 *
220 * Read / write the legacy SWMM5 `[FILES]` section: rainfall, runoff,
221 * RDII, inflows, outflows, and hot-start file references. The
222 * accessors are keyed by an uppercase string so callers don't depend
223 * on the field layout of `FilesSpec`.
224 *
225 * Recognised keys (case-insensitive):
226 * "RAINFALL_PATH" / "RAINFALL_MODE"
227 * "RUNOFF_PATH" / "RUNOFF_MODE"
228 * "RDII_PATH" / "RDII_MODE"
229 * "INFLOWS_PATH"
230 * "OUTFLOWS_PATH"
231 * "HOTSTART_USE_PATH"
232 * "HOTSTART_SAVE_PATH" / "HOTSTART_SAVE_DATETIME"
233 *
234 * `*_MODE` keys take "SAVE" / "USE" / "" (empty clears the slot).
235 * `HOTSTART_SAVE_DATETIME` is a SWMM decimal-day floating-point string
236 * (0 == unset, write at end of run).
237 * ========================================================================= */
238
252swmm_files_get(SWMM_Engine engine, const char* key, char* buf, int buflen);
253
267swmm_files_set(SWMM_Engine engine, const char* key, const char* value);
268
269/* =========================================================================
270 * External-file path slots — typed, broader API (Slice IO-9)
271 * =========================================================================
272 *
273 * Reaches every external-file slot in the model — not just the [FILES]
274 * section — so the GUI's portability normalizer can walk a uniform list
275 * before save without per-role plumbing.
276 *
277 * Each slot carries both:
278 * - the original token as it appeared in the source `.inp`
279 * (relative-or-absolute, with whichever separators the author used);
280 * - the resolved absolute path the engine uses for `fopen`.
281 *
282 * The slot getter exposes both strings to the caller; the slot setter
283 * updates the original token and clears the cached absolute resolution
284 * (PostParseResolver re-fills it the next time it runs).
285 *
286 * See openswmm.gui/docs/IO_PORTABILITY_PLAN.md §3.3 for the storage model
287 * and §3.7 for the GUI editor contract.
288 * ========================================================================= */
289
315
336 const char* owner,
337 char* absolute_buf,
338 int absolute_buflen,
339 char* original_buf,
340 int original_buflen);
341
357 const char* owner,
358 const char* new_path);
359
360/* =========================================================================
361 * Title / notes access
362 * ========================================================================= */
363
371SWMM_ENGINE_API int swmm_title_get_count(SWMM_Engine engine, int* count);
372
383 SWMM_Engine engine,
384 int index,
385 char* buf,
386 int buflen
387);
388
396SWMM_ENGINE_API int swmm_title_add_line(SWMM_Engine engine, const char* line);
397
408SWMM_ENGINE_API int swmm_title_set(SWMM_Engine engine, const char* text);
409
417
418/* =========================================================================
419 * OPTIONS access
420 * ========================================================================= */
421
438 SWMM_Engine engine,
439 const char* key,
440 char* buf,
441 int buflen
442);
443
453 SWMM_Engine engine,
454 const char* key,
455 const char* value
456);
457
468 SWMM_Engine engine,
469 const char* key,
470 char* buf,
471 int buflen
472);
473
483 SWMM_Engine engine,
484 const char* key,
485 const char* value
486);
487
496SWMM_ENGINE_API int swmm_get_crs(SWMM_Engine engine, char* buf, int buflen);
497
498/* =========================================================================
499 * Typed time-control accessors
500 *
501 * Date values are SWMM OADate doubles: the integer part is days since
502 * 1899-12-30 and the fractional part is the time-of-day fraction.
503 * ========================================================================= */
504
512
520
527SWMM_ENGINE_API int swmm_options_get_end_date(SWMM_Engine engine, double* value);
528
536
544
552
553/* =========================================================================
554 * User flags
555 *
556 * Flag names are case-insensitive: they are stored uppercase, matching the
557 * [USER_FLAGS] INP handler.
558 * ========================================================================= */
559
567SWMM_ENGINE_API int swmm_userflag_get_bool(SWMM_Engine engine, const char* name, int* value);
568
576SWMM_ENGINE_API int swmm_userflag_get_int (SWMM_Engine engine, const char* name, int* value);
577
585SWMM_ENGINE_API int swmm_userflag_get_real(SWMM_Engine engine, const char* name, double* value);
586
588SWMM_ENGINE_API int swmm_userflag_set_bool(SWMM_Engine engine, const char* name, int value);
589
591SWMM_ENGINE_API int swmm_userflag_set_int (SWMM_Engine engine, const char* name, int value);
592
594SWMM_ENGINE_API int swmm_userflag_set_real(SWMM_Engine engine, const char* name, double value);
595
596/* -------------------------------------------------------------------------
597 * User flag schema definitions ([USER_FLAGS]) and per-object values
598 * ([USER_FLAG_VALUES]).
599 *
600 * Flag types (matching openswmm::UserFlagType):
601 * 0 = BOOLEAN, 1 = INTEGER, 2 = REAL, 3 = STRING.
602 *
603 * Per-object values use string form symmetric with the INP encoding:
604 * BOOLEAN as YES/NO, INTEGER as %d, REAL as %g, STRING verbatim (no quotes).
605 * Object types and flag names are case-insensitive (stored uppercase);
606 * object names are case-preserved.
607 * ------------------------------------------------------------------------- */
608
616
629 SWMM_Engine engine,
630 int index,
631 char* name_buf,
632 int name_buflen,
633 int* type,
634 char* desc_buf,
635 int desc_buflen
636);
637
649 SWMM_Engine engine,
650 const char* name,
651 int type,
652 const char* description
653);
654
661SWMM_ENGINE_API int swmm_userflag_undefine(SWMM_Engine engine, const char* name);
662
675 SWMM_Engine engine,
676 const char* obj_type,
677 const char* obj_name,
678 const char* flag_name,
679 char* buf,
680 int buflen,
681 int* found
682);
683
698 SWMM_Engine engine,
699 const char* obj_type,
700 const char* obj_name,
701 const char* flag_name,
702 const char* value
703);
704
715 SWMM_Engine engine,
716 const char* obj_type,
717 const char* obj_name,
718 const char* flag_name
719);
720
721#ifdef __cplusplus
722} /* extern "C" */
723#endif
724
725#endif /* OPENSWMM_MODEL_H */
#define SWMM_ENGINE_API
Definition openswmm_2d.h:37
void * SWMM_Engine
Opaque handle to an OpenSWMM Engine instance.
Definition openswmm_callbacks.h:35
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:183
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:1464
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:1260
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:1275
SWMM_ENGINE_API int swmm_userflag_def_count(SWMM_Engine engine, int *count)
Number of user-flag schema definitions.
Definition openswmm_model_impl.cpp:1386
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:1300
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:607
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:103
SWMM_ENGINE_API int swmm_finalize_model(SWMM_Engine engine)
Finalise a programmatically-built model.
Definition openswmm_model_impl.cpp:147
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:1290
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:231
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:254
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:1194
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:1157
SWMM_ENGINE_API int swmm_title_clear(SWMM_Engine engine)
Remove all lines from the [TITLE] section.
Definition openswmm_model_impl.cpp:626
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:1358
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:1315
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:1369
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:1509
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:1421
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:872
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:1239
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:600
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:1283
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:446
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:294
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:330
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:1268
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:238
SWMM_ENGINE_API int swmm_validate_model(SWMM_Engine engine)
Validate model topology without changing state.
Definition openswmm_model_impl.cpp:113
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:1253
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:1394
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:1330
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:189
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:1409
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:278
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:587
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:580
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:1345
SWMM_FilePathRole
Identifies a single external-file slot on the model.
Definition openswmm_model.h:297
@ SWMM_FILE_RAINGAGE_DATA
Definition openswmm_model.h:310
@ SWMM_FILE_INFLOWS
Definition openswmm_model.h:302
@ SWMM_FILE_HOTSTART_USE
Definition openswmm_model.h:304
@ SWMM_FILE_TIMESERIES_DATA
Definition openswmm_model.h:312
@ SWMM_FILE_RAINFALL
Definition openswmm_model.h:299
@ SWMM_FILE_OUTFLOWS
Definition openswmm_model.h:303
@ SWMM_FILE_RDII
Definition openswmm_model.h:301
@ SWMM_FILE_RUNOFF
Definition openswmm_model.h:300
@ SWMM_FILE_CLIMATE_TEMP
Definition openswmm_model.h:305
@ SWMM_FILE_HOTSTART_SAVE
Definition openswmm_model.h:308
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:1428
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:466
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:636