Below is an overview of Dpattern.pas, a Delphi unit from SWMM 5.2 that provides a dialog (TPatternForm) to create or edit time patterns in SWMM. These time patterns (monthly, daily, or hourly) are typically used to modify inflow or pollutant concentrations on a varying schedule.
1. Purpose and Context
SWMM supports time patterns to represent how certain parameters (e.g., DWF inflow, treatment removal efficiencies, etc.) vary over months, days, or hours. The TPatternForm dialog lets users enter the name and type of a pattern and specify its multiplier values in a grid. These multipliers scale a base value by a time-dependent factor.
A time pattern has:
-
Pattern Type:
- Monthly (12 multipliers, one per month)
- Daily (7 multipliers, one per day of week)
- Hourly (24 multipliers, one per hour of the day)
-
Name: A unique identifier for the pattern.
-
Comment: An optional description (e.g., “Summer irrigation pattern”).
2. Main Form: TPatternForm
2.1 Visual Components
- NameEdit (
TNumEdit
): A field to set or edit the pattern's ID/name. - CommentEdit (
TEdit
): A single-line text field for an optional comment/description. - PatternTypeCombo (
TComboBox
): A dropdown to pick the pattern type (Monthly, Daily, Hourly). - GridEdit1 (
TGridEditFrame
):- Houses a
TStringGrid
to display two columns:- Label column (month names, day names, or hour labels).
- Multiplier column (where the user enters numeric multipliers).
- Houses a
- OK/Cancel/Help Buttons.
- EditBtn (
TBitBtn
): Launches a more comprehensive text editor for the comment if desired (viaUedit.EditComment
).
2.2 Variables and Constants
- PatternIndex: The index of the pattern in SWMM’s project data (or -1 if new).
- MonthlyLabels, DailyLabels, HourlyLabels: Arrays of strings used to label the grid's first column.
- AM, PM: Additional strings for labeling hours in 12-hour format.
3. Data Flow
3.1 SetData
- Takes an
Index
(the pattern’s position inProject.Lists[PATTERN]
) and a TPattern object (aPattern
). - If the index >= 0, loads the pattern's name from
Project.Lists[PATTERN].Strings[Index]
intoNameEdit
. - Sets
PatternTypeCombo.ItemIndex := aPattern.PatternType
, which triggersPatternTypeComboClick
. - Copies the comment (
aPattern.Comment
) intoCommentEdit
. - Copies the multipliers from
aPattern.Data[]
into the second column ofGridEdit1.Grid
.
3.2 PatternTypeComboClick
- Adjusts the
GridEdit1.Grid.RowCount
and the first column’s labels depending on the selected pattern type:- 12 rows for Monthly (Jan…Dec).
- 7 rows for Daily (Sun…Sat).
- 24 rows for Hourly (12 AM…11 PM).
- Ensures any empty multiplier cells are set to
"1.0"
.
3.3 GetData
- Outputs the pattern's Name (
NameEdit.Text
) to the calling variableS
. - Writes
PatternTypeCombo.ItemIndex
toaPattern.PatternType
. - Writes
CommentEdit.Text
toaPattern.Comment
. - Reads each row of
GridEdit1.Grid.Cells[1, row]
intoaPattern.Data[row]
.
3.4 OKBtnClick and ValidateData
- ValidateData checks:
- If
NameEdit.Text
is non-empty. - If the name is unique (i.e., not used by another pattern).
- If all multiplier cells parse as valid floats.
- If
- If valid,
ModalResult := mrOK
, otherwise an error message is shown.
4. Additional Details
- NameEditKeyPress: Blocks
[
from being the first character. - EditBtnClick: Opens a comment editor for multiline/extended text.
- HelpBtnClick: Launches the SWMM help topic for patterns.
- The grid uses two columns: The first for a descriptive label (not editable), and the second for the multiplier.
5. Typical Usage
- The user picks an existing pattern from a SWMM interface and chooses Edit (or Add for a new one).
- SetData populates
TPatternForm
with the pattern’s type, name, comment, and multipliers. - The user modifies the type or modifies the multipliers in
GridEdit1
. - On OK,
ValidateData
ensures the pattern is valid. - GetData finalizes changes back into SWMM’s
Project.Lists[PATTERN][Index]
.
This approach seamlessly manages the variety of pattern types (monthly, daily, hourly) and ensures the user has a convenient, tabular way to enter multipliers while giving them a textual comment field for extra context.
No comments:
Post a Comment