Below is an overview of Dprofile.pas, a Delphi unit from SWMM 5.2 that provides a form (TProfileSelectionForm) for selecting and managing saved profile plots in a SWMM project. A “profile” in SWMM typically refers to a longitudinal section (i.e., a series of connected nodes and links) that the user wants to plot over time.
1. Purpose and Context
In SWMM, you can create profile plots showing how water level (hydraulic grade line) changes along a series of nodes and links. The application allows you to save these node/link sequences under a name (a “Profile Name”) for easy re-use.
The TProfileSelectionForm dialog is where users:
- See a list of previously saved profile names.
- Can rename an existing profile.
- Can remove a profile from the project.
- Finally, can select one profile to work with, returning that selection to the calling code.
2. Main Form: TProfileSelectionForm
2.1 Components
- ProfilesListBox: A
TListBox
that lists the names of all saved profiles in the project. - RenameBtn: Lets the user rename the selected profile.
- RemoveBtn: Removes the selected profile from the list.
- OKBtn / CancelBtn: Confirm or dismiss the selection.
- A hidden TmpProfiles (
TStringList
) that stores the actual link sequences for each profile, paralleling the names inProfilesListBox.Items
.
2.2 Key Variables
- HasChanged (boolean): Tracks whether any changes (rename or remove) have been made.
- SelectedProfile (integer): The index of the profile that the user ultimately selected (or
-1
if none).
2.3 Interaction with SWMM’s Project Data
Project.ProfileNames
: ATStringList
in SWMM’sUproject
global data structure that stores the user-friendly names of each profile.Project.ProfileLinks
: AnotherTStringList
that stores the link sequences (one line per profile) in parallel withProject.ProfileNames
.
When this form is opened, it:
- Copies
Project.ProfileNames
intoProfilesListBox.Items
. - Copies
Project.ProfileLinks
intoTmpProfiles
.
When the user clicks OK:
- The form writes any updated
ProfilesListBox.Items
back intoProject.ProfileNames
. - Writes the updated
TmpProfiles
back intoProject.ProfileLinks
. - Sets
SelectedProfile = ProfilesListBox.ItemIndex
. - If anything changed (
HasChanged
), setsUglobals.HasChanged := True;
so the project knows it’s modified.
3. Workflow
- FormCreate: Initializes
TmpProfiles
as a newTStringList
and setsHasChanged := False
. - FormShow:
- Copies
Project.ProfileNames
intoProfilesListBox.Items
. - Copies
Project.ProfileLinks
intoTmpProfiles
. - Ensures the list box has item 0 selected (if available).
- Copies
- Renaming a Profile:
- The user selects a profile in
ProfilesListBox
. - Clicking RenameBtn prompts the user for a new name (
InputBox
). - If the new name is unique (or the same as the old name), the profile name is updated in
ProfilesListBox.Items
. - Sets
HasChanged := True
.
- The user selects a profile in
- Removing a Profile:
- The user selects a profile in
ProfilesListBox
. - Clicking RemoveBtn deletes it from both
ProfilesListBox
andTmpProfiles
(keeping the indices aligned). - Adjusts
ItemIndex
to a valid index, if any remain. - Sets
HasChanged := True
.
- The user selects a profile in
- OKBtnClick:
- Copies the edited
ProfilesListBox.Items
back intoProject.ProfileNames
. - Copies
TmpProfiles
back intoProject.ProfileLinks
. SelectedProfile := ProfilesListBox.ItemIndex
.- If
HasChanged
, setsUglobals.HasChanged := True
. - Closes with
ModalResult := mrOK
.
- Copies the edited
4. Summary
Dprofile.pas manages the ProfileSelectionForm where users can manage multiple saved profile views in SWMM. This dialog:
- Displays existing profiles in a list.
- Allows rename or remove of a profile.
- Finally returns the selected profile index to the caller.
- Updates SWMM’s global data (
Project.ProfileNames
,Project.ProfileLinks
) accordingly, so that the project’s set of saved profiles is kept in sync with the user’s changes.
By offering straightforward name-based management, TProfileSelectionForm ensures users can easily re-use or modify the “profile” node sequences for repeated hydraulic profile plots in SWMM.
No comments:
Post a Comment