Extended and Expanded Summary of Uclipbrd.pas
This Delphi unit, Uclipbrd.pas, manages the copy and paste operations involving objects in an EPA SWMM project (the project’s internal data structures) to and from an internal clipboard. It is not the same as the Windows system clipboard (although it parallels that usage), but rather a custom data container stored in Project.Clipboard.
The code provides procedures to:
- Copy the data of a particular object type (e.g. subcatchment, node, link, label, rain gage) from the project's database into the internal clipboard.
- Paste the data from the internal clipboard back onto a target object (replacing the target’s properties).
1. Objects and Their Data
SWMM organizes objects by type (e.g., Subcatch, Node, Link, Gage, Label). Each object type has a set of string fields or properties stored in arrays or lists:
- For subcatchments: infiltration parameters, land uses, etc.
- For nodes: invert elevation, inflows, etc.
- For links: geometry parameters, cross-section, etc.
- For rain gages: data format, time-series name, etc.
- For map labels: font name, size, style, etc.
These fields are typically stored in the Data[] arrays of the objects (e.g., TSubcatch.Data[i], TNode.Data[i], etc.).
2. Internal Clipboard: Project.Clipboard
There is a single Project.Clipboard object with these main properties:
ObjType: an integer storing the SWMM object type code (likeSUBCATCH,JUNCTION, etc.).Data: a string list. Each line holds one property value for the object that was copied.List1,List2: optional additional string lists for objects with more complex data (like infiltration data, or inflows).Font: used only for label objects, storing the TFont attributes.
When a user chooses "Copy" from the GUI for a subcatchment, the code collects the subcatchment data (like indexes [SUBCATCH_RAINGAGE_INDEX .. SUBCATCH_CURBLENGTH_INDEX]) into the Data list, infiltration data into List1, and land uses into List2. The code then marks ObjType := SUBCATCH.
When "Paste" is requested, the code reads these lists from Project.Clipboard and applies them to a given subcatchment’s data arrays.
3. Procedures Overview
A. Copy Routines
-
CopyGage(Index)
Copies a rain gage object’s relevant data (e.g.Data[GAGE_DATA_FORMAT..GAGE_RAIN_UNITS]) intoProject.Clipboard.ObjType := RAINGAGE;
-
CopySubcatch(Index)
Copies a subcatchment object’s data fromData[SUBCATCH_RAINGAGE_INDEX..SUBCATCH_CURBLENGTH_INDEX], infiltration data, and land uses into the clipboard’sData,List1, andList2.ObjType := SUBCATCH;
-
CopyNode(Ntype, Index)
For a node object (junction, outfall, divider, storage), it determines which data indexes to copy (usingGetDataIndexes). Then it copies those fields plus any inflow lists.ObjType := Ntype;
Node inflows appear inDWInfloworDXInflowlists, which get placed inList1andList2.
-
CopyLink(Ltype, Index)
For a link (conduit, pump, orifice, weir, outlet), usesGetDataIndexesto know which data fields to copy, then places them into theDatalist.ObjType := Ltype;
-
CopyLabel(Index)
Copies a map label object’s font properties (font name, size, bold, italic) into the clipboard’sFontobject.ObjType := MAPLABEL;
B. Paste Routines
-
PasteGage(Index)
Pastes the data from theClipboard.Data[]fields back into a rain gage’s data array[GAGE_DATA_FORMAT..GAGE_RAIN_UNITS]. -
PasteSubcatch(Index)
Pastes subcatchment properties, infiltration data (List1), and land uses (List2). If the subcatchment’sOutletIDchanges, the code callsUupdate.UpdateSubcatchOutlet. -
PasteNode(Ntype, Index)
Pastes the node’s data from theDataarray plus any dry-weather and pattern-based inflows from theList1andList2.
Then callsUedit.UpdateEditor(...)to refresh the property editor and color updates if needed. -
PasteLink(Ltype, Index)
Pastes link data. E.g. for a conduit, it might copy shape, offsets, etc. fromData. -
PasteLabel(Index)
Pastes the label’s stored TFont info. Then re-draws it on the map.
4. Shared Helper Routines
GetDataIndexes(ObjType, var First, Last) -> Boolean
- Each node or link object type uses a certain range of integer indexes to store relevant data.
- For example, a junction might store data from
NODE_INVERT_INDEXup toJUNCTION_PONDED_AREA_INDEX. - This routine maps the object type (like
JUNCTION,OUTFALL,CONDUIT, etc.) to the correctFirstandLastindexes in theDataarray. - Returns False if not recognized.
Copy/Paste Mechanism
When the user calls Copy on an object:
- Determine the range of indexes (
GetDataIndexesfor some types). - Place each string-based property into
Clipboard.Data[...]. - For more complex objects, place infiltration/inflow arrays in
Clipboard.List1, .List2. - Set
Clipboard.ObjTypeto that object’s type.
When the user calls Paste onto an object:
- Confirm that
Clipboard.ObjTypematches the target object type. - Copy the strings from
Clipboard.Data, .List1, .List2into the object’s data arrays or infiltration/inflow lists. - Possibly call
Uupdate.Update...to handle post-processing changes (like subcatch outlets, node color, or link geometry).
5. Uutils and Uupdate Interaction
Uutils.CopyStringList(...)is used to clone lists from objects to the clipboard and vice versa.Uupdate.UpdateSubcatchOutlet(...)is used if a subcatchment’s outlet changes.Uedit.UpdateEditor(...)is used to refresh the property editor form if the object is currently open for editing.MapForm.EraseLabel(...)andMapForm.DrawObject(...)are used to handle re-drawing the map label after a paste.
6. Key Points
- The unit deals only with internal in-application copy/paste, not the OS clipboard.
- Each object type has a distinct structure for how many data fields exist and how they’re stored.
- For node or link objects, we rely on a helper function
GetDataIndexesto identify the relevant data fields (like from “CONDUIT_SHAPE_INDEX” to “CONDUIT_TSECT_INDEX”). - Subcatchments, nodes, and links often carry extra list-based data: infiltration data, land uses, or inflows. These require special handling in
Clipboard.List1andClipboard.List2. - Labels store only font name, size, bold, italic in the TFont of
Clipboard.Font. - After the paste, changes are flagged as “modified” so that the application can track unsaved changes and re-run the model if needed.
Hence, Uclipbrd.pas is an internal utility for copying/pasting SWMM’s object data to the program’s ephemeral data structure, letting the user replicate or reassign the properties from one object to another quickly.
No comments:
Post a Comment