Below is a high-level summary of Uvalidate.pas
, a Delphi unit responsible for validating new or edited property values of EPA SWMM objects in the SWMM GUI.
1. Purpose & Overview
The Uvalidate.pas
unit’s central function is ValidateEditor
, which checks if new or modified property values (entered by a user in the Property Editor) are valid for the particular SWMM object (e.g., rain gage, subcatchment, node, link, or map label). It ensures that:
- Required fields are not blank,
- Numeric fields contain valid numbers,
- Key constraints (such as unique ID names or nonzero values) are honored,
- Geometric constraints (like not connecting a link’s start and end node to the same node) are satisfied.
When validation fails, an error message is displayed to the user.
2. Key Components
2.1 Main Validation Routine
ValidateEditor(I: Integer; var S: String; var E: String): Boolean
- The primary entry point from the Property Editor.
- Parameters:
I
= the index of the property being changed,S
= the new string value,E
= returned error message (if any).
- Determines the object type (e.g., RAINGAGE, SUBCATCH, etc.) from a global
EditorObject
variable and dispatches the validation to specialized routines.
2.2 Specialized Validation Subroutines
Each SWMM object type has its own function to check properties:
-
ValidateRaingage
- Checks for unique ID and validates numerical properties (coordinates, data frequency, etc.).
- Moves the gage on the map if X/Y is changed.
-
ValidateSubcatch
- Checks for unique subcatchment ID.
- Validates area, outlet node/subcatchment name, coordinate changes, and infiltration parameters.
-
ValidateNode
- Covers Junctions, Outfalls, Dividers, Storage nodes.
- Ensures unique ID, verifies numeric properties, and moves the node on the map if X/Y changed.
-
ValidateLink
- Covers Conduits, Pumps, Orifices, Weirs, Outlets.
- Ensures unique link ID, valid start and end nodes, and numeric property checks (e.g., zero lengths or offsets disallowed for some properties).
-
ValidateLabel
- For a map label: checks text changes, new anchor node references, and moves the label if X/Y changes.
2.3 Data Checking Helpers
-
ValidateData
- A generic function used to see if a property’s value is non-blank or nonzero, depending on rules for that property (e.g., area must be non-blank, roughness can’t be zero).
-
ReplaceID
- If a new name for an object is valid, updates that name in the project’s database and on the visual map.
2.4 Error Handling
- Uses
Errmsg
as a global string to hold the latest error message if a check fails. - Typical error messages:
MSG_DUPLICATE_ID
: “ID name is blank or already in use.”MSG_NO_DATA
: “This data field cannot be blank.”MSG_ZERO_VALUE
: “This property cannot be 0.”
2.5 Map Updates
-
On successful coordinate changes (X or Y), calls
MapForm.MoveGage
,MapForm.MoveSubcatch
,MapForm.MoveNode
, orMapForm
methods to visually redraw objects. -
On renaming an object, calls
ReplaceID
to:- Update the project’s internal list,
- Adjust references to that object’s old name,
- Refresh the map display if needed.
3. Typical Usage Flow
- User edits a property (ID, coordinate, or numeric setting) in the Property Editor.
- The editor calls
ValidateEditor
with that property’s index and the new value. ValidateEditor
identifies the object type from a global variable (EditorObject
) and delegates to the appropriate routine:ValidateRaingage
,ValidateSubcatch
,ValidateNode
,ValidateLink
, orValidateLabel
.
- The specialized routine checks the input:
- If invalid, sets
Errmsg
, returnsFalse
, and no changes are made. - If valid, updates the project data structure, calls map redraw if needed, and returns
True
.
- If invalid, sets
- If
False
, an error dialog is shown with the storedErrmsg
.
4. Summary
Uvalidate.pas
is dedicated to checking and enforcing correctness of edited SWMM object properties:
- Ensuring unique or non-empty IDs,
- Preventing invalid references (like a link’s node = itself),
- Maintaining numeric validity and constraints (e.g., area > 0),
- Redrawing the map whenever property changes affect the visual layout.
This module guarantees data consistency within SWMM’s GUI, so that changes made via the Property Editor do not compromise the project’s internal model data.
No comments:
Post a Comment