Below is an overview and walkthrough of the Dinfil.pas unit (from SWMM 5.2) highlighting the purpose of each section of the code and how it manages infiltration (or exfiltration) parameters:
1. Purpose and Context
This unit defines a Delphi Form class TInfilForm that is used to edit infiltration (for subcatchments) or exfiltration (for storage units) parameters in SWMM 5.2. The form supports several infiltration models:
- Horton (or Modified Horton)
- Green-Ampt (or Modified Green-Ampt)
- SCS Curve Number
Additionally, it can be used to edit seepage parameters for a storage node (exfiltration).
2. Key Components
2.1 Delphi Form Elements
- TInfilForm: The main form class containing:
- A TComboBox (
ComboBox1) for selecting the infiltration model. - A TGridEditFrame (
GridEdit) for displaying/editing parameter names and values. - OK, Cancel, and Help buttons.
- A label (
HintLabel) that shows hints or descriptions for each parameter row. - Several
TPanelcontrols for layout.
- A TComboBox (
2.2 Arrays Storing Parameter Values
- HortonInfil: array of strings holding Horton infiltration parameters.
- GreenAmptInfil: array of strings holding Green-Ampt infiltration parameters.
- CurveNumInfil: array of strings holding Curve Number infiltration parameters.
Note: Each infiltration model uses a set of up to
MAXINFILPROPS + 1parameters.
2.3 Properties and Hints
Constant arrays define:
- HortonProps: labels for Horton infiltration parameters.
- GreenAmptProps: labels for Green-Ampt infiltration parameters.
- CurveNumProps: labels for Curve Number infiltration parameters.
Likewise, there are arrays of hint text (e.g., HortonHint, GreenAmptHint, CurveNumHint, StorageInfilHint) that describe each parameter to the user.
2.4 Model Selection
SWMM infiltration model constants are typically something like:
HORTON_INFILGREEN_AMPT_INFILCURVE_NUMBER_INFILMOD_HORTON_INFILMOD_GREEN_AMPT_INFIL
The ComboBox1 is populated with textual options (see InfilOptions[]) corresponding to these constants.
3. Form Lifecycle and Event Handlers
3.1 FormCreate
- Initializes the
ComboBox1with the infiltration model names (fromInfilOptions). - Sets default infiltration parameter arrays for each model to
DefHortonInfil,DefGreenAmptInfil, andDefCurveNumInfil. - Initializes the columns in
GridEdit.Grid(property vs. value).
3.2 FormShow
- Calls
SetInfilProperties, which populates the grid with parameter labels and current values for the currently selected infiltration model.
3.3 ComboBox1Change
When the user selects a different infiltration model from the combo box:
- Saves the currently displayed grid values into the old model’s string array (
HortonInfil,GreenAmptInfil, orCurveNumInfil) so changes aren’t lost. - Updates
NewInfilModelto the user’s new selection. - Calls
SetInfilPropertiesagain to refresh the grid with the new model’s parameters.
3.4 SetInfilModel
- Called externally to specify which infiltration model is currently in use (by name).
- If the string
Sis empty, that indicates storage exfiltration parameters rather than subcatchment infiltration. - Otherwise, it matches
Sagainst the known infiltration model strings and setsOldInfilModel(andNewInfilModel) accordingly.
3.5 SetInfilProperties
- Populates the grid (
GridEdit.Grid) with row labels and values for the currently selected infiltration model. - If it’s storage seepage, the caption changes, and the
ComboBoxis hidden.
3.6 SetData / GetData
- SetData: Load a set of infiltration parameters (
InfilData) into the form’s string arrays, then callSetInfilPropertiesto display them. - GetData: Retrieve the current infiltration parameter values from the grid and store them in the passed-in array.
- Also sets
HasChangedif anything was edited or if the user changed infiltration models.
- Also sets
3.7 GetInfilModelName
- Returns the name (text) of the current infiltration model selection in the combo box.
3.8 OKBtnClick
- Validates the user’s input:
- Converts the grid’s values from strings to floating-point numbers.
- Checks for invalid relationships, e.g.:
- Minimum infiltration rate > maximum infiltration rate for Horton.
- Green-Ampt initial deficit > 1, etc.
- If invalid data is found, shows an error message, otherwise closes the form with
ModalResult := mrOK.
3.9 HelpBtnClick
- Uses
Application.HelpCommandto open the appropriate Help topic based on the currently selected infiltration model.
3.10 FormKeyDown
- If the user presses F1, it behaves as though the Help button was clicked.
4. Flow of Usage
When the form is used to edit infiltration properties:
-
Initialization
The form is created. Default infiltration parameters are loaded. The infiltration model is set viaSetInfilModel. -
Presentation
The form displays the infiltration parameter grid according toNewInfilModel. Hints for each parameter appear inHintLabel. -
User Edits
- The user can change parameter values directly in the grid cells.
- The user can switch infiltration models in the
ComboBox. The form saves the old model’s data before switching to the new model’s data.
-
Validation / Confirmation
- On OK, numeric conversions and validations occur.
- If something is invalid, an error message is shown, and the user must correct it.
- If valid, the form returns with
mrOK.
-
Retrieval
- Caller uses
GetDatato read infiltration parameters from the form. - Caller also uses
GetInfilModelNameto see which infiltration model the user chose.
- Caller uses
5. Summary
- Dinfil.pas defines a dialog for editing infiltration parameters in SWMM 5.2.
- It handles multiple infiltration methods (Horton, Green-Ampt, SCS Curve Number) plus a special mode for storage exfiltration.
- The form’s UI elements (combo box + grid) allow the user to switch among models, edit parameter values, see hints, validate inputs, and request context-sensitive help.
- The arrays (
HortonInfil,GreenAmptInfil,CurveNumInfil) store each model’s parameters in string form, which get updated whenever the user switches models or confirms changes. - This design encapsulates infiltration editing in a single form, simplifying data entry and validation logic.
Overall, TInfilForm provides a cohesive, user-friendly way for SWMM (or any Delphi application using these routines) to manage infiltration or exfiltration input parameters with built-in validation, help integration, and multiple model support.
No comments:
Post a Comment