Below is an overview of Dproselect.pas, a Delphi unit from SWMM 5.2 that provides a profile selection dialog (TProfileSelectForm). This dialog lets users build or retrieve a profile plot path for SWMM—i.e., a series of links (and intermediate nodes) that define a longitudinal section of the drainage network. Once defined, this path can be used to create a profile plot that shows water levels over time or design geometry for those links.
1. Purpose and Context
In SWMM, a profile is a path of links (and nodes) through the network. The user may want to see a cross-sectional water level profile along that path under certain hydraulic conditions. TProfileSelectForm helps:
- Manually build a list of links for a profile (adding links one-by-one).
- Automatically find a path between two specified nodes (using a minimum-links path).
- Load a previously saved profile from the project.
- Save the newly defined profile path (giving it a name) for future use.
- Finally, OK triggers the creation of the actual profile plot, handled by SWMM’s plotting routine.
2. Main Form: TProfileSelectForm
2.1 Key Controls
- StartNodeEdit / EndNodeEdit (TEdit): Name of the first/last node in the profile.
- StartNodeBtn / EndNodeBtn:
- Buttons that set
StartNodeEdit
orEndNodeEdit
to whatever node is currently selected in SWMM’s data browser.
- Buttons that set
- LinksListBox: Lists all the link IDs the user has placed in the profile path, in order.
- FindPathBtn: Finds a minimal-link path from StartNode to EndNode (if one exists) automatically.
- UseProfileBtn: Opens another form to pick from a saved profile in the project, which is then loaded into
LinksListBox
. - SaveProfileBtn: Saves the current
LinksListBox
to the project’s ProfileNames and ProfileLinks lists, under a user-entered name. - OK / Cancel: Confirms or cancels.
- ProfileLinksBox: A group box around the
LinksListBox
; its caption can display either “Links in Profile” or the profile’s name if one is loaded/saved.
3. SWMM Data Interactions
- Project.ProfileNames: A
TStringList
storing names of saved profiles. - Project.ProfileLinks: A parallel
TStringList
storing the link sequences (each line being a newline-separated list of link IDs) for each profile inProfileNames
. - For each new profile, the user supplies a name that is appended to
ProfileNames
and the path (link IDs) is appended toProfileLinks
.
4. Event Handlers and Key Routines
4.1 FormCreate
- Positions the form near the main form’s client area, sets up glyphs for the buttons, and enables/disables certain controls based on if there are any existing saved profiles.
4.2 StartEndNodeBtnClick
- Transfers the currently selected node from SWMM’s data model to the StartNodeEdit or EndNodeEdit.
4.3 BtnAddLinkClick
- Adds the currently selected link in SWMM’s data model to
LinksListBox
at the current index + 1, effectively inserting it right after the user’s currently highlighted link in the list.
4.4 FindPathBtnClick
- Reads
StartNodeEdit
/EndNodeEdit
, ensures those nodes exist. - Builds adjacency lists (via CreateAdjLists) so each node references all links to its neighbors.
- Calls GetMinPath to find a minimal link path between the two nodes.
- Stores the resulting link path in
LinksListBox
.
4.5 GetMinPath(StartNode, EndNode, NodeStack, LinkStack)
- Uses a BFS-like approach with
TQueue
/TStack
to find a path with the fewest links from StartNode to EndNode. - Marks and updates each node’s “PathLen.” If the end node can’t be reached, returns empty.
- If found, unwinds the path from EndNode backward to StartNode and populates
LinkStack
.
4.6 SaveProfileBtnClick
- Prompts the user for a name (via
InputBox
). - Checks if that name is already in
Project.ProfileNames
; if so, error. - Otherwise, appends the name to
ProfileNames
, and the link IDs fromLinksListBox
toProfileLinks
(as one multi-line string). - Sets
Uglobals.HasChanged := True
.
4.7 UseProfileBtnClick
- Opens TProfileSelectionForm (Dprofile.pas), letting the user pick from the existing saved profiles.
- On success, loads that profile’s link list into
LinksListBox
.
4.8 BtnOKClick
- Checks if at least one link is in the list.
- Calls
CheckProfile
to ensure each consecutive link is physically connected to the next. - If valid, calls CreatePlot which sets up
TReportSelection
and requests SWMM to create a profile plot. - Closes the form.
4.9 CheckProfile
- For each consecutive pair of links in
LinksListBox
, ensures they share a node. Also checks if the link actually exists in the project. - If any mismatch, returns the index of the invalid link. If all good, returns -1.
4.10 CreatePlot
- Builds a
TReportSelection
record specifying aPROFILEPLOT
type with the link IDs fromLinksListBox
. - Calls
MainForm.CreateReport(ReportSelection)
, generating the actual profile plot in SWMM.
5. Summary
Dproselect.pas provides a user-friendly “Stay-on-top” form, enabling:
- Manual or automatic path building for a SWMM profile plot.
- Saving the path under a name for re-use.
- Checking and ensuring the path is physically contiguous.
- Ultimately creating a profile plot in SWMM after the user hits OK.
This tool is essential for custom or ad-hoc path creation, allowing the user to quickly define or re-use a sequence of links and visualize water level profiles across that selection.
No comments:
Post a Comment