Below is an overview of Dmapdim.pas, a Delphi unit from SWMM 5.2 that provides a dialog (TMapDimensionsForm) used to set (or revise) the dimensions of the project’s study area map. This ensures that all map objects (subcatchments, nodes, links, backdrop images, etc.) appear within a specified coordinate range at the correct scale.
1. Purpose and Context
SWMM maintains coordinate extents (min/max and ) for the study area map. These coordinates:
- Determine how the map is displayed in the user interface (how zoomed in/out it appears initially).
- Provide a basis for calculating scaled distances or areas, particularly if the user chooses map units of feet/meters or degrees.
The TMapDimensionsForm dialog lets users:
- Manually enter the map’s lower-left and upper-right corners .
- Automatically compute them by scanning all existing model objects plus any backdrop image extents.
- Choose whether the map is in length units (feet/meters) or geographic units (degrees).
2. Key Form Elements
-
GroupBoxes
- One for entering or automatically setting the coordinate extents (the lower-left and upper-right points).
- Another for choosing the MapUnits radio group (feet/meters vs. degrees).
-
Edit Controls:
- LLXEdit, LLYEdit: Lower-left and .
- URXEdit, URYEdit: Upper-right and .
Each is a TNumEdit control, ensuring numeric input.
-
RadioGroup (MapUnits):
- muFeet, muMeters, or muDegrees.
- Adjusting it changes how SWMM interprets the map coordinate scale.
-
AutoLengths CheckBox:
- If checked, triggers an update of stored element lengths (e.g., conduit lengths) after changing the map’s scale.
-
Buttons
- OK: Validates the user’s input.
- Cancel: Closes the dialog without changes.
- Help: Opens context-sensitive help.
- Auto: Retrieves the minimum bounding rectangle from all model objects and the backdrop image, if present.
3. Typical Workflow
- User opens the Map Dimensions dialog.
- SetData(Dimensions: TMapDimensions) is called to load the current coordinate extents into the form controls:
- If the user has a previous scale, that data is displayed.
- The user can either:
- Type in new LLX/LLY/URX/URY values, or
- Click Auto to let SWMM compute bounding coordinates from the map’s existing objects (subcatchments, nodes, links, backdrop).
- The user optionally checks AutoLengths if they want conduit and subcatchment area calculations automatically updated in light of the new coordinates.
- On OK, the form calls:
- GetData(Dimensions) to store user changes back into a
TMapDimensions
record. - Validates that no blank or equal min/max values exist. If invalid, an error message appears.
- If valid, the map is re-scaled accordingly.
- GetData(Dimensions) to store user changes back into a
4. Implementation Details
4.1 SetData(Dimensions: TMapDimensions)
- Copies the four numeric fields (LLX, LLY, URX, URY) into the TNumEdits.
- Sets the MapUnits radio group from
Dimensions.Units
. AutoLengths.Visible
is set based onDimensions.AutoLength
. (In SWMM 5.2, this might relate to whether the user wants SWMM to re-compute lengths or not.)
4.2 GetData(Dimensions: TMapDimensions)
- Reads back the user’s numeric entries into
Dimensions.LowerLeft.X
,.Y
, andDimensions.UpperRight.X
,.Y
. - Updates
Dimensions.Units
from theMapUnits.ItemIndex
. - If
AutoLengths.Checked
, calls a function to update all length calculations (viaUupdate.UpdateAllLengths
).
4.3 BtnAutoClick
- Calls
Ucoords.GetCoordExtents(...)
to find the bounding rectangle of all model objects. - Also merges in any backdrop image’s bounding rectangle.
- If the resulting rectangle is valid, populates the TNumEdits. Otherwise, reverts to default dimensions from
DefMapDimensions
.
4.4 BtnOKClick
- Ensures the numeric fields aren’t empty and that and .
- If checks pass, sets
ModalResult := mrOK
.
5. Summary
Dmapdim.pas provides a simple but essential dialog to define or adjust the coordinate system bounding box for a SWMM project’s map. By specifying the lower-left and upper-right corners—and optionally the map units (feet, meters, or degrees)—the user ensures the project’s geometry is scaled properly for:
- Visual display in the SWMM user interface.
- Correct length/area computations for subcatchments and links.
Additionally, the Auto feature quickly sets the bounding box to encompass all existing objects on the map plus any loaded backdrop image, saving users the effort of manually setting map extents.
No comments:
Post a Comment