Below is an overview of Dtools1.pas, a Delphi unit from SWMM 5.2 that provides a TToolOptionsForm dialog for managing add-on tools in SWMM. These custom tools are user-specified external programs or commands that can be launched directly from SWMM’s main menu under “Tools.”
1. Purpose and Context
SWMM allows users to integrate third-party or custom external tools (e.g., text editors, GIS software, or specialized analysis programs) into the interface. The TToolOptionsForm presents a list of these tools, letting the user add, edit, delete, or reorder them. The final list of tools is stored in Utools.ToolList, which SWMM references to populate the Tools menu in the main form.
2. Main Form: TToolOptionsForm
2.1 Visual Components
- ToolsListBox: A list displaying the names of the currently configured tools.
- AddBtn, DeleteBtn, EditBtn: Buttons for adding a new tool, removing the selected tool, or editing the properties of the selected tool.
- MoveUpBtn / MoveDownBtn: TBitButtons that reorder the list by moving the selected tool up or down.
- CloseBtn, HelpBtn: Standard close and help actions.
2.2 Internal Logic
-
FormCreate:
- Populates
ToolsListBox.Items
fromUtools.ToolList
. - Sets the currently selected item (if any) to index 0.
- Loads up/down arrow glyphs for the move buttons from the main form’s image list.
- Calls
EnableBtns
to adjust button states (Edit, Delete, MoveUp, MoveDown) depending on whether any items exist.
- Populates
-
EnableBtns:
- Disables or enables the Edit, Delete, MoveUp, MoveDown buttons if
ToolsListBox.Items.Count = 0
or not.
- Disables or enables the Edit, Delete, MoveUp, MoveDown buttons if
-
AddBtnClick:
- Creates a TToolPropertiesForm (from
Dtools2.pas
presumably) to let the user define a new tool. - Calls
LoadTool(-1)
meaning it loads a “new” blank tool. - If the dialog returns OK, it calls
GetToolName
from that form and adds it toToolsListBox
(and presumablyUtools.ToolList
).
- Creates a TToolPropertiesForm (from
-
DeleteBtnClick:
- Gets the selected index, calls
Utools.DeleteTool(I)
, and removes the tool fromToolsListBox
. - Adjusts the selected index and calls
EnableBtns
.
- Gets the selected index, calls
-
EditBtnClick:
- Gets the selected index in
ToolsListBox
. - Creates a TToolPropertiesForm, calls
LoadTool(I)
to load that tool’s properties, and if the user saves changes, updates that entry inToolsListBox
to the new name returned byGetToolName
.
- Gets the selected index in
-
MoveUpBtnClick / MoveDownBtnClick:
- Exchanges tools in
Utools.ToolList
viaUtools.ExchangeTools(I, I-1)
orUtools.ExchangeTools(I, I+1)
. - Refreshes
ToolsListBox
from the updatedUtools.ToolList
and sets the selected item to the new position.
- Exchanges tools in
-
HelpBtnClick:
- Displays a help topic (HELP_CONTEXT, 213160).
3. Relationship to Other Units
-
Utools:
- Maintains the global
ToolList
of external tools, each presumably with fields for name, command line, optional arguments, etc. - Exposes methods like
DeleteTool(I)
orExchangeTools(I, J)
to manipulate the list.
- Maintains the global
-
DTools2:
- Contains TToolPropertiesForm, the dialog for defining or editing a single tool’s properties (name, command path, arguments, etc.).
-
Fmain:
- The main form that references the tools in ToolList to populate the “Tools” menu dynamically.
4. Summary
Dtools1.pas is a straightforward form providing a user-friendly interface to manage additional external tools in SWMM. Each tool is represented by a name (and presumably a command line). The form supports:
- Addition of a new tool (launching a separate form to gather the tool’s properties).
- Deletion of an existing tool.
- Editing the properties of a selected tool.
- Reordering the list of tools (up/down).
Ultimately, this helps build the Tools menu in SWMM’s main form, so that the user can quickly launch external tools from within SWMM.
No comments:
Post a Comment