Below is an overview of Dprefers.pas, a Delphi unit from SWMM 5.2 that provides a dialog (TPreferencesForm) for setting various program preferences in the SWMM user interface. These preferences include:
- General UI behaviors (e.g., blinking map highlighters, confirming deletions, auto backups).
- Decimal precision for displayed subcatchment, node, and link results.
- Whether to display a start page on launch, how to handle auto-saving, and more.
- The application’s visual Style (Delphi VCL theme).
1. Purpose and Context
SWMM allows users to customize various preferences that affect the user interface and certain behaviors not directly related to model computations. The TPreferencesForm is a tabbed dialog that aggregates all these settings, letting the user adjust them in one place. Upon confirmation, these settings are saved to SWMM’s global variables and persist between sessions (e.g., stored in an .ini file or registry).
2. Main Form: TPreferencesForm
2.1 Tabs
TPageControl
organizes the preferences into two tabs:
- TabSheet1: General UI settings
- Blinking map highlighter, map flyovers, confirm on delete, automatic backup, tab-delimited project file, reporting time in elapsed format, auto-save results, showing the startup/welcome screen, clearing the recent projects list, etc.
- TabSheet2: Decimal precision / output display
- Allows the user to set how many decimals are shown for each subcatchment, node, and link output variable.
2.2 Controls
- Check Boxes (
CheckBox1..CheckBox9
) for general preferences like blinking map highlighter, confirm deletions, etc. - Combo Boxes for default variable selection (e.g.,
NodeVarBox
,LinkVarBox
,SubcatchVarBox
) and a numeric spin edit (TUpDnEditBox
) that determines the decimal precision of each variable. - StylesCombo: A drop-down listing available VCL Styles (
TStyleManager.StyleNames
), letting the user pick a different UI theme. - Buttons: OK, Cancel, Help.
3. Internal Data Management
Within TPreferencesForm, there are arrays storing the decimal digits to be displayed for each set of variables:
SubcatchDigits[]
: For subcatchment view variables (SUBCATCHOUTVAR1..SUBCATCHVIEWS
).NodeDigits[]
: For node variables (NODEOUTVAR1..NODEVIEWS
).LinkDigits[]
: For link variables (LINKOUTVAR1..LINKVIEWS
).
When the user changes the spin edit for, say, a subcatchment variable, it updates SubcatchDigits[SubcatchVarBox.ItemIndex]
. After hitting OK, these arrays get written back into SWMM’s global data structures:
SubcatchUnits[i].Digits := SubcatchDigits[...]
NodeUnits[i].Digits := NodeDigits[...]
LinkUnits[i].Digits := LinkDigits[...]
4. Event Flow
4.1 FormCreate
- Initializes the check box captions from
PrefersList[]
(like “Blinking Map Highlighter,” “Flyover Map Labeling,” etc.). - Sets each check box according to the existing global preference variables (
Uglobals.Blinking
,Uglobals.FlyOvers
, etc.). - Populates
StylesCombo
with all available VCL styles. Selects the current style’s name. - Fills the subcatch/node/link combo boxes (
SubcatchVarBox
, etc.) with the names of their output variables and copies the current decimal precision into local arrays (SubcatchDigits[]
, etc.).
4.2 (User Interaction)
- The user toggles check boxes for UI behavior.
- Chooses a subcatchment/node/link variable from the combo box and changes the spin edit to define the decimal places.
- Possibly picks a different theme from
StylesCombo
.
4.3 OKBtnClick
-
Calls
SetPreferences
, which updates Uglobals variables:Uglobals.Blinking := CheckBox1.Checked;
Uglobals.FlyOvers := CheckBox2.Checked;
- … etc.
-
If the user checks “Clear Recent Project List” (
CheckBox9
), it clearsUglobals.MRUList
. -
Writes new decimal digits for each output variable’s display.
-
Returns
mrOK
.
4.4 RetrieveStyleName
- Returns
StylesCombo.Text
so the main code can apply the chosen VCL style (e.g.,TStyleManager.SetStyle(...)
).
5. Summary
Dprefers.pas provides a straightforward way for SWMM users to customize how the software behaves and displays data, including:
- UI behaviors (blinking highlighter, confirm on delete, etc.).
- Project file formats (tab-delimited or normal).
- Decimal precision for each subcatchment/node/link result variable.
- The application’s VCL theme.
By saving these preferences to SWMM’s global variables, the user’s choices persist across sessions, ensuring a consistent, personalized experience.
No comments:
Post a Comment