Extended and Expanded Summary of the Umap.pas Unit
This unit, Umap.pas, forms a central part of EPA SWMM’s map-drawing architecture. It manages drawing the Study Area Map on a memory bitmap and handles details like re-scaling, positioning, labeling, and optionally rendering a backdrop image.
Below is a thorough guide to:
- Purpose and Scope
- Core Data Structures
- Key Constants & Defaults
- Principal Routines
- Workflow
- Integration With Other Units
1. Purpose and Scope
The Umap.pas unit covers:
- Rendering (drawing) the SWMM project’s elements onto an in-memory bitmap, then onto the main display canvas.
- Backdrops, including reading an image from a file, placing it behind the foreground objects, and optionally modifying it (watermark, grayscale).
- Re-scaling and zooming the map, ensuring that the coordinate transformations (World ↔ Screen) are correct.
- Legendary map operations:
- Identifying bounding rectangles for objects.
- Drawing objects (subcatchments, nodes, links, and labels) at the correct size and color.
- Handling shape-specific symbols (outfalls, dividers, inlets, etc.).
- Coordinate conversion methods, allowing SWMM’s internal world coordinates to map onto device (pixel) coordinates.
2. Core Data Structures
2.1 TMap Class
TMap = class(TObject)
Canvas : TCanvas;
Bitmap : TBitmap;
BackBM : TBitmap;
GageBM : TBitmap;
InletBM : TBitmap;
Window : TMapWindow;
Dimensions: TMapDimensions;
Options : TMapOptions;
Backdrop : TMapBackdrop;
Sfactor : Extended;
ZoomState : array [0..10] of TMapZoomState;
ZoomIndex : Integer;
ZoomRatio : Integer;
...
end;
The TMap class encapsulates all map-centric data:
Canvas: The main TCanvas used for drawing.Bitmap,BackBM: TBitmap objects for the overall map and the backdrop.GageBM,InletBM: Bitmaps for specialized symbols (raingages, inlets).Window: ATMapWindowrecord describing the mapping from world to pixel coordinates.Dimensions: ATMapDimensionsrecord with physical extents, unit conversions, etc.Options: ATMapOptionsrecord (e.g., whether to show node IDs, subcatchment fill style, arrow sizes, etc.).Backdrop: ATMapBackdroprecord with backdrop image info (filename, source, corners, etc.).Sfactor: A factor for adjusting scale at zero-zoom.ZoomState[]: Up to 10 zoom states can be stored, each with a center and zoom factor.
2.2 Supporting Records
TMapDimensions: Contains the real-world bounding box, length/area conversion factors, map units, etc.TMapWindow: Captures the pixel-based map rectangle, world→pixel offset, and scaling ratio.TMapBackdrop: For controlling the source/visibility of the backdrop image.TMapOptions: For toggling visibility of subcatchments, nodes, etc., plus annotation styles and coloring.
3. Key Constants & Defaults
MAX_INT_COORD= 32767 (the maximum pixel coordinate for safe GDI operations).MAX_POINTS= 1000 (the max vertices in a polygon array).- Default
TMapDimensions(DefMapDimensions) with 0..10000 bounding box, 3 decimal digits, conversion factors, etc. - Default
TMapBackdrop(DefMapBackdrop) with none source, empty file, etc. - Default
TMapOptions(DefMapOptions) with things like show subcatchments, node IDs off, link IDs off, etc.
4. Principal Routines
4.1 Map Construction and Lifecycle
-
constructor TMap.Create- Allocates memory bitmaps (
Bitmap,BackBM,GageBM,InletBM) and sets them to 24-bit color. - Applies default map/backdrop options and zero-level zoom state.
- Allocates memory bitmaps (
-
destructor TMap.Destroy- Frees the TBitmap objects.
4.2 Drawing Methods
-
DrawMap- Clears map background, optionally draws the backdrop, then calls
DrawForeground.
- Clears map background, optionally draws the backdrop, then calls
-
DrawForeground- Sets pen & brush colors, draws subcatchments, links, nodes, gages, and labels.
-
Object-Specific:
DrawSubcatchments,DrawSubcatch(Index):- Retrieves vertex points, sets a color from the subcatch’s color index, draws the polygon, subcatch centroid marker, etc.
DrawNodes, plus subroutines for each node type (DrawOutfall,DrawDivider,DrawStorage, etc.).DrawLinks,DrawLink(...):- Draws polylines for each link, possibly with an arrow or pump/valve symbol.
DrawLabels:- Draws map labels (
TMapLabel) with user-defined fonts.
- Draws map labels (
-
Symbol Drawing:
DrawArrowHead(...): for link flow direction.DrawPumpSymbol(...): for pumps.DrawInletSymbol(...): for inlets.
4.3 Backdrop Handling
-
DrawBackdrop(...)- Loads a TPicture from file, calculates a rectangle, then stretches the image onto the
BackBMcanvas. - Handles grayscale or watermark transformations if set.
- Loads a TPicture from file, calculates a rectangle, then stretches the image onto the
-
RedrawBackdrop- Convenience method that calls
DrawBackdropif backdrop is visible.
- Convenience method that calls
4.4 Rescaling, Zooming, Coordinate Conversions
-
Rescale- Recomputes the current window scale (
WperP) based on the main bounding rectangle and the currentZoomIndex.
- Recomputes the current window scale (
-
Pixel ↔ World:
GetXpix,GetYpixconvert from world to pixel.GetX,GetYconvert from pixel back to world.
-
ZoomState[]array keeps track of center coordinates and scale factors at different zoom levels.
4.5 Utility Methods
-
GetBoundingRect(...)- Returns the bounding rectangle in pixel space for a given SWMM object (subcatch, node, link, or label).
-
GetNodeRect(...),GetLinkRect(...),GetSubcatchRect(...)- Specialized bounding rectangle logic for each category.
-
SnapSubcatch(...)- Example of snapping subcatchment vertices if user drags them close to another polygon.
-
GetSubcatchAreaStr(...),GetLinkLengthStr(...)- For computing lengths in consistent project units.
5. Workflow
-
Initialization
- A
TMapinstance is created, bitmaps are allocated, default dimension and options are assigned. - The “full extents” of the map are determined from the project bounding box (see
Rescalelogic).
- A
-
Backdrop
- If the user sets a backdrop file,
RedrawBackdropis called. DrawBackdroploads the file into a TPicture, positions it, and draws it ontoBackBM.
- If the user sets a backdrop file,
-
Drawing the Foreground
DrawMapis invoked, which erases the background, then copies the backdrop image (if visible) onto the mainBitmap.- Then
DrawForegroundsystematically draws subcatchments, links, nodes, rain gages, labels, etc. - SWMM color-coded styling is determined via calls to
SetNodeColor,SetSubcatchColor, etc.
-
Zooming
- The user might choose Zoom In/Out in the UI.
- SWMM updates
ZoomIndexor modifiesZoomState[ZoomIndex]. Rescaleis called, thenDrawMapre-renders at the new scale.
-
Coordinate Tools
- Clicking on the map or retrieving an object’s bounding rectangle uses the coordinate transformations in
GetXpix,GetYpix, etc.
- Clicking on the map or retrieving an object’s bounding rectangle uses the coordinate transformations in
6. Integration With Other Units
-
Uglobals.pas- Defines
CurrentNodeVar,CurrentLinkVar, etc., plus color arrays likeMapSubcatchColor,MapNodeColor,MapLinkColor.
- Defines
-
Uproject.pas- Houses the main
Projectobject with subcatchments, nodes, links, etc. Umapfrequently queriesProjectto get coordinates, color indexes, etc.
- Houses the main
-
Uoutput.pas- Provides
Uoutput.GetNodeValStr,Uoutput.GetSubcatchValStr, etc. used for labeling.
- Provides
-
Uinlet.pas- Some specialized logic for drawing inlets on conduits (
DrawInletSymbol).
- Some specialized logic for drawing inlets on conduits (
-
Jpeg- The code references loading
TJPegImageif the user’s backdrop is a JPEG.
- The code references loading
-
System.UITypes- For color and coordinate definitions in newer Delphi versions.
Concluding Remarks
In summary:
Umap.pasorchestrates the entire graphic representation of SWMM objects.- It does so by layering a backdrop image behind user-defined and computed shapes.
- It manages the correlation between real-world coordinates (including lat-long if the user chooses) and the screen’s pixel coordinates.
- It uses custom coloring, line widths, symbol drawing, text labels, and handling of user options to produce a clear, zoomable map representation.
No comments:
Post a Comment