Expanded Summary of Udxf.pas
This Delphi Pascal unit Udxf.pas
is responsible for exporting the SWMM study area map to a DXF (Drawing Exchange Format) file. It uses various drawing primitives (lines, circles, polylines, text, etc.) to represent nodes, links, subcatchments, and labels from an EPA SWMM model in a DXF file that can be opened in a CAD application.
1. Purpose & Usage
-
Main Entry Point:
procedure DXFexport(const fname: String; const Jstyle: Integer);
This is the procedure that the rest of the SWMM code calls to export all visual elements of the model (e.g., subcatchments, nodes, links, labels) into a DXF file named
fname
. The parameterJstyle
indicates how junction nodes will be drawn (e.g., as circles, crosses, squares, etc.). -
DXF Format:
The code writes plain-text lines in the correct order and structure to a.dxf
file. The content is broken up into:- Header (map extents).
- Tables (line types, layers, etc.).
- Entities (actual geometry).
2. DXF Data Structures & Outline
-
Header
- The procedure
AddHeader(...)
writes out$EXTMIN
and$EXTMAX
to define the bounding box extents in the DXF file.
- The procedure
-
Layer Table
StartTables(Nlayers)
writes the starting lines of the DXFTABLES
section with N layers.AddLayer(LayerName, ColorIndex)
is called for each separate layer (e.g., “Subcatchments,” “Links,” “Nodes,” “Arrows,” “Labels”).EndTables
closes the layer table and begins theSECTION ENTITIES
block.
-
Entities
- Various geometry elements are added:
- Circle (for nodes, if style is set to circles).
- Polyline (for subcatchment polygons, link polylines).
- Line or Solid (for arrowheads or node shapes).
- Text (for labels).
- Various geometry elements are added:
-
Ending the File
EndDXF
writes theENDSEC
andEOF
lines required at the end of the DXF.
3. Key Procedures
3.1. DXFexport(const fname: String; const Jstyle: Integer)
-
Input:
fname
: name of the resulting DXF file on disk.Jstyle
: node-drawing style (e.g., circle, cross, etc.).
-
Actions:
- Open a text file for writing (DXFfile).
- Retrieve information from SWMM:
- The “Map” instance (with subcatchments, nodes, etc.).
- Various map styling options (line sizes, arrow sizes, etc.).
- Compute or look up color indexes for subcatchments, links, and nodes. (DXF color is integer-based, so the code finds the “closest” integer color index from a set.)
- Write the DXF “header” with bounding box extents.
- Create table data: layers for subcatchments, links, nodes, arrows, labels.
- Iterate over each object in the SWMM model:
- Subcatchments: add them as polylines.
- Links: add polylines plus optional arrowheads.
- Nodes: add circles or squares or crosses, depending on
Jstyle
. - Labels: add text items.
- Finish by writing end-of-file markers.
3.2. AddHeader(xmin, ymin, xmax, ymax: Single)
- Writes out the minimal bounding rectangle that the CAD program can use for
$EXTMIN
and$EXTMAX
in the DXF file.
3.3. AddLayer(layer: String; color: Integer)
- Within the “layer table,” create a new layer with the given color index.
3.4. AddCircle(x, y, radius, color, layer)
- Writes the DXF statements for a circle entity at
(x, y)
withradius
, assigned to some color and layer.
3.5. AddSubcatchPolyLine(aSubcatch, thickness, bulge, color, layer)
- Polylines the subcatchment’s polygon boundary. The code writes a “POLYLINE ... VERTEX ... SEQEND” block. The subcatchment’s polygon is accessed from
aSubcatch.Vlist
.
3.6. AddLinkPolyLine(aLink, thickness, bulge, color, layer)
- Similar to
AddSubcatchPolyLine
but for a link’s polyline (viaaLink.Vlist
plus the from/to node coords).
3.7. AddArrow(...)
- Renders the arrowhead for a link, by writing two line segments forming a “V” shape. The geometry is computed from start/end angles and arrow size.
3.8. AddText(x, y, ht, rot, txt, layer)
- Writes a text entity. Used for map labels.
4. Data & Variables
-
Global/Module-level:
DXFfile
: aTextFile
handle for writing the DXF lines.JuncStyle
: integer controlling how junctions are drawn (0=circles, 1=cross, 2=filled squares).SubcatchSize
,LinkSize
,NodeSize
,LabelSize
,ArrowSize
: floating “scaling factors” from SWMM’s map to DXF.PixPerMapExt
: ratio to convert from map coordinates to screen or other dimension units, used for scaling.DXFLinkColor, DXFNodeColor, DXFSubcatchColor
: arrays for color indexes for different objects, matching SWMM’s color legend intervals.
-
Units: The code transforms local map units (from the SWMM map display) into raw DXF coordinates, effectively in the same coordinate system but scaled to represent line thickness, arrow sizes, etc.
5. Flow of DXFexport
Below is a step-by-step outline of what DXFexport(...)
does:
- Open the output file at
fname
. - Initialize local variables with dimension and style settings from the SWMM map object.
- Write:
AddHeader(...)
with bounding box.StartTables(...)
,AddLayer(...)
calls, andEndTables
.
- Loop over subcatchments if they are shown; calls
AddSubcatch(...)
for each. - Loop over each link type (
I in [CONDUIT, PUMP, ...]
), callsAddLink(...)
. - Loop over each node type (
I in [JUNCTION, OUTFALL, ...]
), callsAddNode(...)
. - AddLabels if they are shown.
- Close the DXF with
EndDXF
. - Close the file handle.
That’s how the entire map is rendered into lines, polylines, circles, etc.
6. Practical Notes
- Colors: The code looks up the SWMM color (RGB) in
DXFColors = (clRed, clYellow, ...)
, matching it to the “closest” index. This might be a limited approach but is standard for older DXF color indexes. - Arrows: Only drawn if
MapOptions.ArrowStyle
is notasNone
. The code calculates arrow geometry withSinCos(arctan2(...))
calls. - Units: The SWMM coordinates are used directly, no special unit conversion is done. The user’s SWMM map coordinates are in some length unit that the DXF will interpret.
- File: The resulting
.dxf
is “AutoCAD Release 12 style” or older ASCII format, which is widely recognized.
7. Conclusion
Udxf.pas
provides a straightforward, if somewhat “low-level,” approach to generating a standard ASCII DXF file from an EPA SWMM map. It enumerates each item of interest (subcatchments, nodes, links, labels), converts them to the necessary DXF geometry calls (POLYLINE, CIRCLE, SOLID, TEXT), and organizes them into layers. This allows the SWMM map layout to be examined or edited in any CAD application supporting DXF.
No comments:
Post a Comment