Sunday, December 29, 2024

SWMM5 Delphi GUI Dmap.pas Summary

 Below is an overview of Dmap.pas, a Delphi unit from SWMM 5.2 that defines a dialog (TMapOptionsForm) for configuring map display options in the SWMM user interface. This dialog allows the user to customize how subcatchments, nodes, links, labels, arrows, and other map elements are rendered.


1. Purpose and Context

When viewing a SWMM model, users may want to change how the map looks—for example, adjusting node sizes, link widths, subcatchment fill style, or label transparency. The TMapOptionsForm provides these customization options, which SWMM later uses when drawing the main project map.


2. Main Form: TMapOptionsForm

2.1 Key Visual Components

  1. ListBox1 on the left:

    • Lists different categories of map display options (e.g., Subcatchments, Nodes, Links, Labels, etc.).
    • When the user selects an item from this list, the corresponding page in Notebook1 is shown.
  2. Notebook1 (with multiple pages):

    • Each page corresponds to a category of map display options:
      • Page 0: Subcatchment appearance (e.g., fill style, line style).
      • Page 1: Node appearance (node size, border, shape).
      • Page 2: Link appearance (link width, border).
      • Page 3: Label/notation settings (font size, transparency).
      • Page 4: Arrow appearance.
      • … and so on.
    • Contains various controls (checkboxes, radio groups, up-down numeric edits, etc.) for adjusting each display option.
  3. ColorListBox1:

    • Lets the user pick a background color for the map from a custom list of colors.
  4. Button Panel:

    • OK, Cancel, Help.

3. Map Settings in TMapOptions

A TMapOptions record (from Umap.pas) typically holds many boolean and integer fields that control how the map is drawn. For example:

  • ShowSubcatchLinks: Whether lines from subcatchment centroids to nodes are shown.
  • SubcatchFillStyle: Brush style (solid, clear, diagonal, etc.) for subcatchments.
  • SubcatchSize and SubcatchLineSize: The size of subcatchment symbols and boundary lines.
  • NodeSize: Node symbol size.
  • ShowNodesBySize / ShowNodeBorder: Whether node sizes and borders are displayed.
  • LinkSize: Link line width, etc.
  • LabelsTranspar: Whether labels have a transparent background.
  • NotationSize: Font size for object labels (IDs/values).
  • ColorIndex: An index for the background color choice.

The form reads and writes these fields through SetOptions and GetOptions.


4. Event Handlers and Workflow

4.1 FormCreate

  • Initializes the left-side ListBox1 so each item (option category) displays at an appropriate height.
  • Sets ListBox1.ItemIndex := 0 and calls ListBox1Click to show the first page in Notebook1.

4.2 SetOptions(Options: TMapOptions)

  • Called by the main application to load the current map settings into the form’s controls.
  • For example:
    • SubcatchLink.Checked := Options.ShowSubcatchLinks;
    • SubcatchSymbol.Spinner.Position := Options.SubcatchSize;
    • NodeSpin.Spinner.Position := Options.NodeSize;
    • NodesBySize.Checked := Options.ShowNodesBySize;
    • … etc. …
  • Finally, calls routines to resize sample shapes (ResizeNodeShape, ResizeLinkShape) and sets HasChanged := False.

4.3 User Adjustments

  • The user selects categories from ListBox1.
  • They toggle checkboxes (e.g., NodeBorder), use spin boxes for sizes (NodeSpin, LinkSpin), or pick fill styles from a TRadioGroup (SubcatchFill).
  • The form draws a small preview shape (NodeShape or LinkShape) scaled according to the user’s input.

4.4 NodeSpinChange / ResizeNodeShape

  • When the user changes node size, the code updates the shape (NodeShape) to reflect the new dimension. This is purely a preview—final changes are only applied to the SWMM map once the user clicks OK.

4.5 GetOptions(Options: TMapOptions)

  • Called after the user presses OK:
    1. Reads each control’s value back into the corresponding Options field.
    2. Compares with old values to set HasChanged := True if something changed.
    3. Example: Options.NodeSize := NodeSpin.Spinner.Position; Options.ShowNodeSymbols := NodeSymbols.Checked; etc.

4.6 BtnHelpClick

  • Displays context-sensitive help, with different Help IDs for each Notebook1 page.

5. Notable Details

  1. ColorListBox1GetColors:

    • A specialized event populating ColorListBox1 with a custom set of colors (White, Yellow, Blue, Panel, Black, etc.).
    • The user’s selection sets Options.ColorIndex.
  2. NodeBorder / NodeSymbols

    • Checkboxes that toggle whether node shapes have a border or if node symbols are shown at all.
    • The shape’s pen color changes dynamically (red for no border, black for border).
  3. Zoom Fields (e.g., ZoomForLabels, ZoomForSymbols):

    • Control at what zoom level these elements become visible.
    • For instance, if LabelZoom is 10, then labels only appear if the map is zoomed in beyond a certain threshold.
  4. ListBox1DrawItem:

    • An override that custom-draws each item in the category list, centering the text vertically.

6. Summary

Dmap.pas provides a multi-tabbed Map Options dialog, letting users customize subcatchment fill, node/link size, color, labeling transparency, arrows, background color, and more. Through SetOptions and GetOptions, it synchronizes these choices with the global TMapOptions structure, which the SWMM UI then uses to redraw the map with the user’s preferred appearance.

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