Sunday, December 29, 2024

SWMM5 Delphi GUI Dproject.pas Summary

 Below is an overview of Dproject.pas, a Delphi unit from SWMM 5.2 that provides a form (TProjectForm) for viewing the project’s input file content in a structured way. Specifically, the form displays all sections of the SWMM input data (e.g., 

TITLETITLE, RAINGAGESRAINGAGES, SUBCATCHMENTSSUBCATCHMENTS, etc.) in a list box, and shows the lines belonging to the currently selected section in a string grid.


1. Purpose and Context

In SWMM, a project is typically stored as a text-based .inp file with various sections. Each section (TITLETITLE, OPTIONSOPTIONS, SUBCATCHMENTSSUBCATCHMENTS, etc.) contains parameters describing parts of the model. The TProjectForm in Dproject.pas:

  1. Exports the project’s data to a text representation (using Uexport.ExportProject).
  2. Organizes these text lines by section.
  3. Lets the user browse each section’s lines in a read-only format:
    • A ListBox for picking the section name.
    • A StringGrid that displays the lines for that section.

This is mostly a convenience or debugging feature—showing the user exactly how SWMM’s data is structured internally.


2. Main Form: TProjectForm

2.1 Components

  1. ListBox1: On the left side, listing the names of the input file sections (e.g., “[TITLE]”, “[OPTIONS]”, “[RAINGAGES]”, etc.).
  2. StringGrid1: On the right side, showing the lines of whichever section is selected in ListBox1.
  3. Panel1 / Panel2 / Panel3: Layout panels.
  4. Splitter1: A vertical splitter between the section list (ListBox1) and the lines (StringGrid1).
  5. Edit1: An invisible text box used to measure or set consistent row heights, ensuring correct DPI scaling.

2.2 Internal Variables

  • S (TStringList): A temporary string list that holds the entire exported text of the project.
  • Section (integer): The currently selected section index in ListBox1.

3. Data Flow

3.1 FormCreate

  • Creates S := TStringList.Create, to store the entire .inp file text.
  • Sets StringGrid1.DefaultRowHeight and ListBox1.ItemHeight to match Edit1.Height (ensuring consistent text layout across DPI settings).
  • Positions the form to fill the same area as MainForm.ClientHandle.

3.2 FormShow

  • Calls Uexport.ExportProject(S, Uglobals.ProjectDir), which writes a textual representation of the entire SWMM project into string list S.
  • Iterates over S to find lines that begin with [, i.e. the section headers, and adds them to ListBox1.Items.
  • Initializes Section := -1.
  • Selects the first item in ListBox1 and triggers ListBox1Click.

3.3 ListBox1Click

  • When a user picks a section from ListBox1, we find that section’s header line in S by matching S[J].
  • Then, from that line onward, we collect lines until hitting another section header ([).
  • We skip lines that are blank or have only ;; (comment lines for a project header).
  • The resulting lines are placed in StringGrid1, each line in a separate row.

3.4 RefreshGrid

  • Clears the grid.
  • Finds the selected section’s text lines.
  • Resizes StringGrid1.RowCount accordingly.
  • Fills each row (Cells[0, row]) with one line from the input.

3.5 Closing and Freed Resources

  • On FormClose, S.Free is called to release the memory used by the string list.

4. UI Behavior

  1. StringGrid is read-only. The user can’t edit lines—this is purely a view.
  2. Panel1Resize sets StringGrid1.DefaultColWidth := Panel1.Width, ensuring the single column spans the full panel width.
  3. StringGrid1DrawCell: By default, if a TStringGrid row is selected while it does not have focus, it might draw the selection with highlight color. This handler overrides that, drawing the line with a standard background color if the grid is not the active control, so it doesn’t show a highlight selection.

5. Summary

Dproject.pas implements a form that:

  • Exports the entire SWMM project to a textual .inp format.
  • Lists each input section in a left-side ListBox.
  • Shows each line of that section in a right-side StringGrid.

This allows users to inspect the complete project data as it would appear in the input file, all within SWMM’s interface, without manually opening the .inp file in an external text editor. By presenting a per-section view, the user can easily jump to different parts of the input structure.

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...