Below is an overview of Dmapexp.pas, a Delphi unit from SWMM 5.2 that provides a dialog (TMapExportForm) to export the current study area map into one of three file formats:
- MAP (a plain text format containing map coordinates)
- EMF (Enhanced Metafile, a vector-based image format)
- DXF (Drawing Exchange Format, often used by CAD applications)
1. Purpose and Context
When a user wants to save or share the spatial layout of a SWMM model’s map (as opposed to the entire SWMM input file), TMapExportForm provides a convenient interface to choose the export format and file location. The user can then:
- Generate a MAP file, which is an internal SWMM text-based format containing only the graphical layout (node/link coordinates, etc.).
- Produce an EMF file (vector image) for high-quality printing or embedding in documents.
- Create a DXF file for importing the geometry into CAD or GIS software.
2. Main Form: TMapExportForm
2.1 Controls
-
Radio Buttons (1) MAP, (2) EMF, (3) DXF:
Let the user pick which file format to export. -
RadioGroup1:
Visible only if DXF is chosen. Provides additional drawing choices (e.g., “Circle” vs. “Square” for node symbols) for how junctions appear in the DXF file. -
Buttons:
- OK (
Button1
): Executes the export. - Cancel (
Button2
): Closes the dialog with no export. - Help (
Button3
): Opens the help topic for exporting.
- OK (
-
SaveDialog1:
A standard Windows save-file dialog, controlled at runtime.
2.2 Variables and Constants
const
MAP_FILE = 0;
EMF_FILE = 1;
DXF_FILE = 2;
FilterTxt: array[MAP_FILE..DXF_FILE] of PChar =
('Map files (*.MAP)|*.MAP|All files|*.*',
'EMF files (*.EMF)|*.EMF|All files|*.*',
'DXF files (*.DXF)|*.DXF|All files|*.*');
ExtensionTxt: array[MAP_FILE..DXF_FILE] of PChar =
('map','emf','dxf');
TXT_SAVE_MAP_TITLE = 'Save Map As';
- These definitions let the code manage SaveDialog1’s filter text and file extension automatically, based on which format is selected.
3. Workflow
-
User Chooses Format
By default, RadioButton1 (MAP) is checked. The user can switch to EMF or DXF. -
(Optional) Adjust DXF Node Style
If RadioButton3 (DXF) is checked, RadioGroup1 is revealed, letting the user pick how junctions will be drawn in the DXF. -
OK Button
- The form is hidden.
- SaveDialog1 is configured with the relevant filter and extension.
- If the user picks a file name and clicks Save, the form processes the file in the chosen format:
- MAP => calls
ExportMapFile
- EMF => calls
MapForm.CopyToMetaFile
- DXF => calls
Udxf.DXFexport
, passing the chosen “junction style” index fromRadioGroup1.ItemIndex
.
- MAP => calls
-
ExportMapFile
- For a MAP format, the code calls
Uexport.ExportMap(S)
to retrieve a text representation of the map’s layout in a TStringList (S
). - Then
S.SaveToFile(Fname)
writes it out.
- For a MAP format, the code calls
-
Help Button
- Invokes the help topic for exporting the map (
HELP_CONTEXT, 211850
).
- Invokes the help topic for exporting the map (
-
FormKeyDown
- If F1 is pressed, calls the Help routine.
4. Key Routines
4.1 ExportMapFile
procedure TMapExportForm.ExportMapFile(const Fname: String);
var
S: TStringlist;
begin
S := TStringlist.Create;
try
Uexport.ExportMap(S);
S.SaveToFile(Fname);
finally
S.Free;
end;
end;
- Leverages the function in Uexport.pas that builds a text-based representation of map coordinates and object placements.
- This text is saved in a
.MAP
file, which can be re-imported by SWMM as a partial reference for the map layout.
4.2 MapForm.CopyToMetaFile
- When exporting to EMF,
MapForm.CopyToMetaFile(Filename)
captures a vector “screenshot” of the model map. - The user can place this
.emf
into other applications with no loss of resolution.
4.3 Udxf.DXFexport
- If the user chooses DXF,
Udxf.DXFexport(Filename, JuncStyle)
writes a standard 2D CAD format file. JuncStyle
typically controls how nodes are drawn (circles, squares, etc.) in the resulting DXF.
5. Summary
Dmapexp.pas is a concise unit enabling SWMM to export the model’s map as:
- MAP: SWMM’s text layout format (doesn’t include data on subcatchment polygons beyond their vertices, nor does it store hydraulic/hydrologic parameters—only geometry).
- EMF: A Windows Enhanced Metafile (vector image).
- DXF: A universal CAD format for geometry-based outlines of subcatchments, links, nodes, etc.
By allowing multiple formats, SWMM provides flexibility for both graphical presentation and for transferring geometry to other software tools.
No comments:
Post a Comment