Below is a high-level overview of Fgraph.pas, a Delphi unit from SWMM 5.2 that defines a form (TGraphForm) for displaying simulation results as either a time series plot or a scatter plot.
1. Purpose and Context
SWMM can display simulation results in various plot types. Fgraph.pas implements the TGraphForm (an MDI child form) that renders these plots (time series or scatter plots) using Delphi’s TeeChart library. It relies on routines in Ugraph.pas to handle the details of chart creation, styling, and data retrieval from SWMM’s binary output file.
2. The TGraphForm Class
2.1 Key Fields
-
Chart1 (
TChart
):- The main TeeChart component.
- Houses a set of data series used for plotting.
-
Graph (
TReportSelection
record):- Stores selections (like object/variable, time range, plot type, etc.).
-
TimeFactor, StartDate, EndDate:
- Used for time series plots, to manage whether times appear in elapsed hours, days, or actual date/time format.
-
OptionPage:
- Determines which tab of a graph options dialog will initially show.
-
XvarIndex, YvarIndex:
- Indices in SWMM’s binary output data for the chosen variables (X and Y in a scatter plot).
-
StartPeriod, EndPeriod, TotalPeriods:
- Determine which range of simulation time steps to display.
2.2 Main Features
-
Time Series Plot
- Each object/variable combination is displayed as a separate series on Chart1.
- X-axis can be actual dates/times or elapsed time.
- The user can optionally show observed/calibration data if only one object is being plotted.
-
Scatter Plot
- Plots one variable vs. another for a single range of time steps.
- A single data series is created, containing points of (Xvariable, Yvariable) for each time period.
-
Creation and Refresh
- CreateGraph is called once to set up the chart based on selected items:
- For time series: creates multiple line or area series, one per object.
- For scatter plot: creates a single point series.
- RefreshGraph is called to retrieve new data after e.g. a re-run of the simulation.
- Data are fetched from the SWMM binary output via
Uoutput
routines (likeGetValue
).
- CreateGraph is called once to set up the chart based on selected items:
-
Graph Options
- Right-clicking on the chart calls
SetGraphOptions
, opening a Graph Options dialog (in Ugraph.pas) to change display styles. - Standard functionality for copying to clipboard or file, or printing, is available via
CopyTo
andPrint
.
- Right-clicking on the chart calls
-
Mouse/Keyboard Interactions
- Pressing Shift + left mouse button zooms in. Right-click triggers graph options.
- Pressing Esc or close button frees the form.
- A “lock” button toggles whether the plot auto-refreshes data after a new simulation.
2.3 Key Methods
-
CreateGraph (Main entry point):
- Takes a
TReportSelection
describing what to plot. - Decides if it’s a time series or scatter plot.
- Builds the chart’s data series accordingly.
- Takes a
-
RefreshGraph:
- Re-fetches data from the simulation results if not locked.
- For time series: calls
RefreshTimeSeriesPlot
. - For scatter: calls
RefreshScatterPlot
.
-
RefreshTimeSeriesPlot:
- Clears each data series, then loops over time periods from start to end, calling
GetValue
for each. - Optionally adds calibration data for observed vs. computed comparisons.
- Clears each data series, then loops over time periods from start to end, calling
-
RefreshScatterPlot:
- Clears the single scatter series, again fetching X and Y values over time from the binary output.
-
SetGraphOptions:
- Launches a Graph Options dialog, letting the user change colors, grid style, fonts, axis scaling, etc.
-
CopyTo and Print:
- Provide ways to save or print the chart.
3. Summary
In Fgraph.pas, the TGraphForm is the specialized form for showing SWMM’s results as a time series or scatter plot. It integrates with SWMM’s output file reading, receives user’s plot selections from a TReportSelection
, and displays the resulting chart with help from Ugraph.pas. By calling CreateGraph
, RefreshGraph
, SetGraphOptions
, CopyTo
, or Print
, the rest of SWMM’s GUI manages how and when a chart is built, updated, exported, or printed.
No comments:
Post a Comment