Extended and Expanded Summary of the Ulegend.pas
Unit
The Ulegend.pas
unit in EPA SWMM manages the creation, display, and editing of color legends for various variables shown on the study area map. It also includes functionality to draw a legend for elapsed or actual simulation time (the “time legend”). Below is a thorough overview of the unit’s functionality, data parameters, and key routines.
1. Purpose and Scope
The Ulegend.pas
unit is responsible for:
- Drawing the legend that shows how colors map to ranges (intervals) of subcatchment, node, or link variables (e.g., pollutant concentration, water depth, velocity, etc.).
- Displaying and editing legend intervals and colors through a user interface (the Legend Editor dialog).
- Drawing a separate time legend on the map that displays the current simulation time period being viewed.
2. Key Data Types and Fields
2.1 TMapLegend
Record
A TMapLegend
is defined globally in Uglobals.pas
and referenced here. It holds:
- Intervals: an array of floating-point breakpoints for the color intervals.
- Nintervals: the number of these intervals actually used (1 to
MAXINTERVALS
). - Ltype: the object type for this legend (e.g.,
SUBCATCHMENTS
,NODES
, orLINKS
). - ViewVar: the index of the particular variable (e.g., flow, depth, pollutant concentration) being displayed.
2.2 Supporting Variables
MapColor[]
orColors[]
: arrays ofTColor
used to assign colors to each legend interval.Digits
: integer specifying how many decimal places to display for legend intervals.Framed
: boolean that determines if the legend is drawn with a bounding rectangle.
3. Main Functions and Procedures
3.1 DrawLegend(...)
procedure DrawLegend(
const R: TRect;
const C: TCanvas;
const BackColor: TColor;
const Framed: Boolean;
const Legend: TMapLegend;
const VarIndex: Integer;
const Digits: Integer;
const MapColor: array of TColor);
-
Purpose
Draws a color-coded legend for a specified variable on a map canvas. -
Parameters
- R: The rectangle on which the legend is drawn.
- C: The
TCanvas
where the legend is rendered. - BackColor: Background color for the legend area.
- Framed: Whether or not to draw a rectangle frame around the legend.
- Legend: The
TMapLegend
record containing intervals and the number of intervals. - VarIndex: Identifies which variable’s legend is drawn (e.g., flow, depth).
- Digits: Number of decimal digits to display on interval labels.
- MapColor: Array of colors associated with each legend interval.
-
Logic
- Retrieves the name and units of the variable from
GetObjVarNames
(inUglobals.pas
). - Clears the rectangle
R
with the background color. - Draws optional framing if
Framed
is True. - Renders a title with object type (“Node”, “Link”, or “Subcatch”) and the variable name (e.g., “Depth”, “Concentration”).
- For each interval in the legend, draws a small color box and a textual label with the numeric breakpoint (formatted with
Digits
decimals). - Optionally shows the variable’s measurement units (e.g.,
MGD
,CFS
, etc.).
- Retrieves the name and units of the variable from
3.2 DrawTimeLegend(...)
procedure DrawTimeLegend(
R: TRect;
C: TCanvas;
const BackColor: TColor;
const S: String);
-
Purpose
Draws the textual “time legend” (the current date/time or elapsed time of the simulation) in a specified rectangle. -
Parameters
- R: The rectangle bounding the legend.
- C: The map canvas on which to draw.
- BackColor: Background color.
- S: The time string to display (e.g., “4/25/2024 12:00:00 AM”).
-
Logic
- Fills the background with
BackColor
. - Chooses a font (Arial, Bold, size=8).
- Writes the string
S
centered in the rectangleR
. - The text and pen color is set to contrast with the background (e.g., if the background is black, the text is white).
- Fills the background with
3.3 EditLegend(...)
function EditLegend(
var Legend: TMapLegend;
const VarIndex: Integer;
const Digits: Integer;
const TimePeriod: Integer;
var Colors: array of TColor;
var Framed: Boolean): Boolean;
-
Purpose
Opens a Legend Editor dialog box (TLegendForm
) to let the user modify legend intervals, colors, or whether the legend is framed. -
Parameters
- Legend: Reference to the current legend’s intervals, number of intervals, etc.
- VarIndex: The variable being depicted.
- Digits: Decimal places for numeric intervals.
- TimePeriod: The current simulation time period (for possibly adjusting scale).
- Colors: The color array for each legend break.
- Framed: Whether the user wants a framed bounding rectangle around the legend.
-
Logic
- Retrieves the object class and variable name/units via
GetObjVarNames
. - Instantiates
TLegendForm
(declared inDlegend.pas
), passing in legend data. - If the user clicks OK, the updated intervals, colors, and
Framed
flag are retrieved. - If user cancels, returns
False
(no changes applied).
- Retrieves the object class and variable name/units via
4. Integration with Other Units
Dlegend.pas
: The actual Legend Editor form used byEditLegend
.Uglobals.pas
:- Contains the
TMapLegend
record, constants likeSUBCATCHMENTS
,NODES
, etc. - Provides
GetObjVarNames(...)
which returns object category name, variable name, and units.
- Contains the
Uutils.pas
:- Offers string formatting and numeric conversion utilities (
FloatToStrF
, etc.).
- Offers string formatting and numeric conversion utilities (
Fmain.pas
orFmap.pas
**:- The location where these legends are drawn or updated on the map.
System.UITypes
:- Provides definitions for color, coordinate rectangles, and possibly other UI-related types.
5. Typical Usage Flow
-
Drawing the Legend
- The SWMM main map display calls
DrawLegend(...)
whenever it needs to refresh or redraw the color-coded legend. - The legend’s intervals and colors come from the
SubcatchLegend[]
,NodeLegend[]
, orLinkLegend[]
arrays inUglobals
.
- The SWMM main map display calls
-
User Editing
- The user right-clicks or otherwise chooses to “Edit Legend.”
EditLegend(...)
is invoked, which displaysTLegendForm
.- The user adjusts the color scale, intervals, number of intervals, etc.
- On closing with OK, the updated properties store back into the
Legend
andColors
arrays.
-
Time Legend
- In an animation loop or when stepping through simulation time periods,
DrawTimeLegend(...)
is called to update the displayed date/time in a small region of the map.
- In an animation loop or when stepping through simulation time periods,
6. Conclusions
The Ulegend.pas
unit provides the fundamental drawing routines and an editing hook for legends in SWMM’s map display. Key highlights include:
- It can display both variable legends (with multiple color intervals) and a time legend.
- Legend intervals are typically read from or saved to
Uglobals
data structures, ensuring consistency across SWMM. - A separate form (
Dlegend.pas
) is used for interactive editing of the color intervals, numeric ranges, and legend styles.
This approach separates the concerns of:
- Storing legend data (
TMapLegend
inUglobals
), - Drawing it on the map (
Ulegend.pas
), and - Letting the user edit intervals (
Dlegend.pas
).
No comments:
Post a Comment