Sunday, December 29, 2024

SWMM5 Delphi GUI Dquery.pas Summary

 Below is an overview of Dquery.pas, a Delphi unit from SWMM 5.2 that provides a stay-on-top form (TQueryForm) for performing a Map Query. A Map Query in SWMM allows users to highlight particular objects (subcatchments, nodes, or links) on the map that meet certain criteria (for example, nodes with flooding > 0, or subcatchments with a certain runoff depth, etc.). Additionally, it supports special queries for nodes having inflows and subcatchments with LID controls.


1. Purpose and Context

In SWMM’s user interface, a Map Query helps the user quickly find and highlight which elements of the network satisfy a specified condition—such as “subcatchment infiltration rate is above X,” or “node has an RDII inflow assigned,” or “link flow is below Y.”

The TQueryForm allows the user to define:

  1. Which type of element is being queried (subcatchment, node, link, LID subcatchment, or inflow node).
  2. For subcatchments/nodes/links, which variable to compare.
  3. The relation (e.g., “above,” “below,” or “equals”) to use in the comparison.
  4. A comparison value if needed.

Once the user performs the query, objects matching the condition are highlighted on the map, and the rest are grayed out. A readout at the bottom shows how many objects matched.


2. Main Form: TQueryForm

2.1 Key Controls

  1. ComboBox1: Selects which category to query (“Subcatchments,” “Nodes,” “Links,” “LID Subcatchments,” or “Inflow Nodes”).
  2. ComboBox2: If subcatchments/nodes/links are chosen, lists the specific view variables relevant to that object type (e.g., “Area,” “Runoff,” “Depth,” “Flooding,” etc.). If “LID Subcatchments” is chosen, lists different LID types (e.g., “Biocell,” “Rain Barrel,” etc.). If “Inflow Nodes” is chosen, lists different inflow types (Direct Inflow, DWF, RDII, Groundwater).
  3. ComboBox3: The comparison operator (above, below, equals). Only used if subcatchments/nodes/links are chosen.
  4. Edit1: The numeric or text value for the query comparison.
  5. Button1 (labeled Go or an icon): Executes the query.
  6. Panel1: Displays how many objects matched the query.
  7. The form is stay-on-top, ensuring it remains accessible while working with the map.

2.2 Internal Data / Global Variables

  • QueryFlag: A boolean indicating if a map query is currently active.
  • QueryRelation: The chosen relation (above, below, equals).
  • QueryValue: The numeric value typed in Edit1 for the comparison.
  • CurrentSubcatchVar, CurrentNodeVar, CurrentLinkVar: Indicate which variable is currently used to color subcatchments, nodes, or links on the map, respectively.
  • OldSubcatchVar, OldNodeVar, OldLinkVar: The previously displayed map variable (before the query).
  • OldShowSubcatchs, OldShowNodes, OldShowLinks: Whether subcatchments, nodes, or links were visible prior to the query.

3. Workflow

3.1 FormShow

  1. Backs up the current map display settings (OldSubcatchVar, etc.).
  2. Disables the main form’s subcatch/node/link view combos (so user can’t change the displayed variable while the query is active).
  3. Calls ComboBox1Change to re-populate the second combo box with the correct list of variables for the chosen object type.

3.2 ComboBox1Change / UpdateVariables

  • If user picks “Subcatchments,” the form loads subcatchment variables (rainfall, infiltration, etc.) from MainForm.SubcatchViewBox.Items.
  • If “Nodes,” it loads node variables from MainForm.NodeViewBox.Items.
  • If “Links,” it loads link variables from MainForm.LinkViewBox.Items.
  • If “LID Subcatchments,” it loads a list of LID types.
  • If “Inflow Nodes,” it loads inflow types (“Direct,” “DWF,” “RDII,” “GW”).

3.3 Button1Click (the “Go” button)

  • Checks if user’s Edit1 is valid if a numeric comparison is needed (subcatch/node/link).
  • If valid, sets QueryFlag := True; saves the user’s chosen comparison operator (QueryRelation) and numeric value (QueryValue).
  • Disables the main form’s view combos.
  • Depending on which object type was chosen (ComboBox1.ItemIndex):
    • If 0 = Subcatchments: sets CurrentSubcatchVar to the chosen subcatchment variable, calls Uoutput.SetSubcatchColors, etc.
    • If 1 = Nodes: sets CurrentNodeVar, calls Uoutput.SetNodeColors.
    • If 2 = Links: sets CurrentLinkVar, calls Uoutput.SetLinkColors.
    • If 3 = LID Subcatchments: calls SetLIDSubcatchColors to highlight subcatchments that have LID, possibly filtering by type.
    • If 4 = Inflow Nodes: calls SetInflowNodeColors to highlight nodes that have certain inflow types.
  • Calls UpdateQueryCaption to display how many objects matched the query.
  • Redraws the map and updates legends.

3.4 SetInflowNodeColors

  • Clears all node color indices.
  • If the user chose “Direct Inflow,” it sets ColorIndex = 1 for nodes that have direct external inflow.
  • If “DWF,” does so for nodes with Dry Weather Flow.
  • If “RDII,” for nodes with RDII inflow.
  • If “GW,” for subcatchments that have groundwater flow assigned to a node, colors that node.

3.5 SetLIDSubcatchColors

  • Clears all subcatchment color indices.
  • Sets CurrentSubcatchVar := LID_USAGE.
  • If user picks “Any LIDs,” any subcatchment with an LID gets ColorIndex=1.
  • Otherwise checks if it has the chosen LID type (like “Rain Garden”).
  • Objects with ColorIndex=1 are considered “matched.”

3.6 UpdateQueryCaption

  • Counts how many objects (subcatchments, nodes, or links) have ColorIndex>0.
  • Displays “N items found” in Panel1.

3.7 FormClose

  • If QueryFlag=True, resets the map to its old display variables (OldSubcatchVar, etc.).
  • Re-enables the main form’s subcatch/node/link combos.
  • Clears the query.

4. Summary

Dquery.pas defines a small, always-on-top form that queries subcatchments, nodes, or links for a condition and highlights those objects on the map. By:

  • Letting the user pick object type and variable or picking “LID subcatchments” / “inflow nodes” queries,
  • Selecting a comparison operator (above, below, equal),
  • Entering a numeric threshold (if needed),

the form then updates the map’s color coding so that only those objects meeting the condition appear highlighted. This interactive Map Query feature helps modelers quickly identify and visualize network elements that match specific criteria (e.g., nodes with flooding, subcatchments with certain infiltration, or elements with certain special properties like LIDs or inflows).

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