Sunday, December 29, 2024

SWMM5 Delphi GUI Dproselect.pas Summary

 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:

  1. Manually build a list of links for a profile (adding links one-by-one).
  2. Automatically find a path between two specified nodes (using a minimum-links path).
  3. Load a previously saved profile from the project.
  4. Save the newly defined profile path (giving it a name) for future use.
  5. Finally, OK triggers the creation of the actual profile plot, handled by SWMM’s plotting routine.

2. Main Form: TProfileSelectForm

2.1 Key Controls

  1. StartNodeEdit / EndNodeEdit (TEdit): Name of the first/last node in the profile.
  2. StartNodeBtn / EndNodeBtn:
    • Buttons that set StartNodeEdit or EndNodeEdit to whatever node is currently selected in SWMM’s data browser.
  3. LinksListBox: Lists all the link IDs the user has placed in the profile path, in order.
  4. FindPathBtn: Finds a minimal-link path from StartNode to EndNode (if one exists) automatically.
  5. UseProfileBtn: Opens another form to pick from a saved profile in the project, which is then loaded into LinksListBox.
  6. SaveProfileBtn: Saves the current LinksListBox to the project’s ProfileNames and ProfileLinks lists, under a user-entered name.
  7. OK / Cancel: Confirms or cancels.
  8. 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 in ProfileNames.
  • For each new profile, the user supplies a name that is appended to ProfileNames and the path (link IDs) is appended to ProfileLinks.

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

  1. Reads StartNodeEdit/EndNodeEdit, ensures those nodes exist.
  2. Builds adjacency lists (via CreateAdjLists) so each node references all links to its neighbors.
  3. Calls GetMinPath to find a minimal link path between the two nodes.
  4. 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

  1. Prompts the user for a name (via InputBox).
  2. Checks if that name is already in Project.ProfileNames; if so, error.
  3. Otherwise, appends the name to ProfileNames, and the link IDs from LinksListBox to ProfileLinks (as one multi-line string).
  4. 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

  1. Checks if at least one link is in the list.
  2. Calls CheckProfile to ensure each consecutive link is physically connected to the next.
  3. If valid, calls CreatePlot which sets up TReportSelection and requests SWMM to create a profile plot.
  4. 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 a PROFILEPLOT type with the link IDs from LinksListBox.
  • Calls MainForm.CreateReport(ReportSelection), generating the actual profile plot in SWMM.

5. Summary

Dproselect.pas provides a user-friendly “Stay-on-top” form, enabling:

  1. Manual or automatic path building for a SWMM profile plot.
  2. Saving the path under a name for re-use.
  3. Checking and ensuring the path is physically contiguous.
  4. 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:

A comprehensive explanation of how minimum travel distance relates to link length in InfoSewer

In hydraulic modeling of sewer networks, the minimum travel distance is a fundamental parameter that affects how accurately the model can si...