Below is a high-level summary of the Uproject.pas unit, which defines the TProject class representing the entire SWMM project data and numerous related objects (subcatchments, nodes, links, pollutant data, etc.).
1. Purpose and Responsibilities
This unit is responsible for:
- Storing and organizing all data for a SWMM project, including:
- Subcatchments (with infiltration, groundwater, LID units, etc.)
- Nodes (junctions, outfalls, dividers, storage units)
- Links (conduits, pumps, orifices, weirs, outlets)
- Gages, pollutants, landuses, time series, curves, climate data, and so on.
- Maintaining the next available ID (label) for each type of object (auto ID creation).
- Providing lookup methods to find an object’s index given its string ID.
- Defining the default properties for each object type and storing object data.
- Support for copying/cutting/pasting objects to an internal clipboard structure.
- Handling map coordinates and polygon/vertex data for subcatchment and storage shapes.
The TProject class interacts heavily with:
Uglobalsto track global settings and references (current subcatch/node/link, flags, etc.).Uutilsfor numeric/string conversions and utility methods.Umap, which uses these objects’ data for rendering on the map.Ulid,Uinlet, etc., which handle specialized LID or inlet data references.
2. Major Classes Defined
-
TProjectA top-level container of all SWMM data. Its key members:
Lists[ObjType]: An array ofTStringList, each list storing the object ID strings and references.DefProp[ObjType]: Default property values for each object category.NextID[ObjType]andIDPrefix[ObjType]: Used to generate new IDs.HasItems[ObjType],CurrentItem[ObjType]: Track usage and the currently selected item.- Specialized lists like
ProfileNames,PollutNames,ControlRules, etc. Clipboard: An internal project clipboard.
Key methods:
ClearandClearList(ObjType)remove objects or entire categories.DeleteItem(ObjType, Index)deletes a single object (including references from other objects).GetNextID(ObjType)returns a new unique ID for a given object type.FindNode/FindLink/FindSubcatch/FindCurvesearch for an object’s index by its ID.IsNode/IsLink/IsSubcatch/IsCurveetc. help identify object categories.GetNode,GetLink,GetSubcatchand others fetch typed object references.
-
TSubcatchRepresents a subcatchment. Stores:
X, Y: Centroid coords.Vlist: Polygon vertices for the subcatch outline.InfilData: infiltration parameters.LandUses,Loadings,LIDs,Groundwaterdata.
-
TNodeCommon node base class for junctions, outfalls, dividers, storage:
X, Y: CoordinatesData[]: Properties (inverts, depths, etc.).DWInflow,DXInflow,IIInflow: Inflow definitions.Treatment: Node treatment expressions.Vlist: Vertex list for storage polygons.
-
TLinkCommon link base class for conduit, pump, orifice, etc.:
Node1, Node2: Upstream/Downstream nodes.Vlist: If the link is drawn with vertices.Inlet: Reference if a specialized inlet is used.
-
TRaingage,TPollutant,TLanduse,TAquifer,TClimatologySpecialized classes for rainfall definitions, pollutants, land-use definitions, aquifer definitions, climate data.
-
TMapLabelFor user-defined map labels: text, font, anchor node, etc.
-
TProjectClipboardA custom clipboard used for copying/cutting/pasting blocks of objects internally.
-
TNonpointSource,TTimeseries,TCurve,TStreet,TTransect,THydrograph,TSnowpack,TPatternAdditional classes for smaller-scale data elements (buildup/washoff, time series, rating curves, etc.).
3. Key Data Structures
3.1 Lists[ObjType]
- An array of
TStringListobjects. Each string is the object’s ID, andObjects[]points to the actual object instance (likeTSubcatch,TNode,TLink, etc.).
3.2 Default Property Arrays
DefProp[ObjType]: For each SWMM object category, there’s a set of default property values that new objects can copy upon creation.
3.3 Inheritance and Polymorphism
- Because Delphi doesn’t have generics in older versions, each category references a base class but often is cast to the correct specialized type (e.g.,
TLink,TNode).
4. Notable Methods
-
Finding Objects
FindNode(S, Ntype, Index),FindLink(S, Ltype, Index),FindSubcatch(S, Atype, Index)
These search the objectLists[]by ID string.
-
Adding or Deleting Objects
DeleteItem(ObjType, Index)frees the associated object, removes its references, and updates that object list.ClearList(ObjType)removes all objects of one category.
-
ID Management
GetNextID(ObjType)ensures a unique ID by incrementing and checking for duplicates.DupID(ID, ObjType, Index)checks if a newly entered ID duplicates an existing object’s ID.
-
Working with Coordinates
- Subcatchments or storage nodes have
Vlist: TVertexListto store polygon or polyline vertex data. SetCentroidorSetMaxDepthcompute geometric properties (centroid or depth from the coordinate data).
- Subcatchments or storage nodes have
-
Clipboard
- The
TProjectClipboardclass organizes multiple string lists plus aTFontto handle a block of objects that can be pasted later.
- The
5. Typical Usage Flow
-
Initialization
- A
TProjectis created at program start. - Lists are initialized (empty).
- A
-
Importing or Creating Objects
- On reading an INP file, the parser calls routines to create subcatchments, nodes, etc.
- Each object is stored in
Lists[ObjType].AddObject(ID, <objectInstance>).
-
Editing
- The user or code changes properties (e.g., infiltration data for a subcatchment).
- The property values are stored in arrays like
Data[]on each object.
-
Retrieving
- The user wants the ID or property of an object: the code uses
GetSubcatch(ObjType, Index).Data[...]. - Or calls
GetID(ObjType, Index)to get the ID string.
- The user wants the ID or property of an object: the code uses
-
Deleting
- The user deletes an object.
DeleteItem(ObjType, Index)is invoked, which also removes references from other objects (like subcatch -> outNode references).
- The user deletes an object.
6. Interaction with Other Units
Umap.pas: UsesXandYofTNode,TSubcatchpolygons, etc. for display.Uinlet.pas: Manages inlets assigned toTLink.Inlet.Uoutput.pas: May reference each object’sOutFileIndexto map simulation results back to these objects.Ulid.pas: Reads/writes LID definitions stored inTSubcatch.LIDs.Uglobals.pas: Holds global enumerations, labels, map color info, etc.
7. Key Points and Constraints
- Each object category’s
Data[]array can have a different meaning (e.g.,Data[0..MAXSUBCATCHPROPS]for subcatchments). - Some object categories (like subcatchments) also store infiltration or LID data in separate arrays/lists.
- Memory Management: Each object’s destructor must free any sub-lists or sub-objects (like
Vlist,LIDsin a subcatch). - The unit includes a wide variety of property codes, enumerations, and default definitions.
8. Conclusion
Uproject.pas serves as the central data model for an EPA SWMM project. It defines how SWMM objects (subcatchments, nodes, links, etc.):
- Are created, stored, identified by ID
- Manage their geometry (vertex lists) and specialized data (inflows, infiltration, etc.)
- Are added or removed from the project database
All higher-level modules (map display, results, file I/O) rely on TProject to retrieve and manipulate the project’s object data.
No comments:
Post a Comment