Below is an overview of Dwelcome.pas, a Delphi unit from SWMM 5.2 that implements a TWelcomeForm, which is a custom "Welcome" or "Start Page" dialog that can appear when SWMM first launches. This form allows users to quickly access recent projects, sample projects, or documentation resources, and to start new or open existing SWMM files.
1. Purpose and Context
Many applications provide a "Welcome Screen" at startup, presenting options such as:
- Creating a new project
- Opening a recent project
- Accessing sample models
- Viewing documentation or tutorials
In SWMM, the TWelcomeForm does exactly this. It gathers a variety of resources (recently opened SWMM input files, sample project files) and presents them in a user-friendly interface, letting the user quickly select an option (like opening an existing file, starting a new project, or exploring examples).
Once the user makes a selection, the form returns a code to the main program, indicating what action SWMM should take (e.g., "Load recent file #3," "No action," "Open a sample model," etc.).
2. Main Form: TWelcomeForm
2.1 Visual Components
- Panel1 / Panel2: Container panels for layout and styling.
- CloseButton (
TSpeedButton
): A button labeled “Close,” which simply closes the welcome screen with “no action.” - ShowStartPageCB (
TCheckBox
): If checked, indicates the user wants to see this welcome form every time SWMM starts. Otherwise, once unchecked, SWMM might store a user preference not to show the welcome screen at startup. - GetStartedListView, DevelopListView, SamplesListView, ProjectsListView (all
TListView
):- Each list view contains clickable items with icons, letting the user pick an action (tutorial, user’s guide, create new project, open project, load sample file, or load recent project).
- For example:
- GetStartedListView might contain items like “Open the Tutorial” or “View the User’s Guide.”
- DevelopListView might have “New Project” or “Open Project.”
- SamplesListView shows sample project entries in the local “Documents\EPA SWMM Projects\Samples” folder, plus an item pointing to an external website with further examples.
- ProjectsListView displays the list of most recently used (MRU) projects from SWMM’s
MRUList
.
- ClearProjectsLinkLabel (
TLinkLabel
):- A link that clears the "recent projects" list.
2.2 Internal Data
- The form tracks two main arrays:
RecentFileNames[0..7]
: the actual file paths for up to 8 MRU items, displayed in ProjectsListView.SampleFileNames[0..6]
: the actual file paths for up to 7 sample models, displayed in SamplesListView.
2.3 Key Methods
-
FormCreate
- Calls
LoadRecentProjects
to populate ProjectsListView fromMRUList
. - Calls
LoadSampleProjects
to populate SamplesListView from known sample files in the user’s Documents folder. - Adjusts visibility of "Clear recent projects" link or a label stating "No recent projects."
- Calls
-
LoadRecentProjects
- Reads SWMM’s global
MRUList
, checks each file for existence, and if found, adds it to ProjectsListView, storing the path inRecentFileNames[...]
. - Hides the list and shows a label if no projects exist.
- Reads SWMM’s global
-
LoadSampleProjects
- Defines several example files (like “Detention_Pond_Model.inp”) plus their descriptive captions.
- Looks in
Documents\EPA SWMM Projects\Samples
for these files. - If found, adds them to SamplesListView, storing the path in
SampleFileNames[...]
. - Also adds an item “OpenSwmm.org Examples” that opens a web link if selected.
-
GetStartedListViewSelectItem / DevelopListViewSelectItem / SamplesListViewSelectItem / ProjectsListViewSelectItem
- Each ListView’s OnSelectItem event. When a user clicks an item, the form sets its
ModalResult
to a special integer code (like “saLoadSample” or “saLoadRecent”) or opens a web link for further examples. The main program sees the modal result and decides how to proceed.
- Each ListView’s OnSelectItem event. When a user clicks an item, the form sets its
-
ClearProjectsLinkLabelLinkClick
- Clears the
MRUList
and the ProjectsListView, updating the UI to reflect no recent projects.
- Clears the
-
CloseButtonClick
- Closes the form with “no action” result.
3. Interaction Flow
- SWMM starts up and sees the "Show welcome form at startup" preference is true.
- TWelcomeForm is shown, listing:
- GetStarted items (open tutorial, user guide),
- Samples items (example projects),
- Develop items (create new project, open existing project),
- Recent items (list of up to 8 last opened projects).
- The user clicks a relevant item, e.g., a recent project. The form sets
ModalResult := saLoadRecent
, plus setsSelectedFile
to the path. Then the form closes. - SWMM sees that result, loads the specified file or performs the indicated action.
4. Summary
Dwelcome.pas provides a “Welcome Screen” that SWMM displays at startup, letting the user quickly open recent or sample projects or navigate to tutorials and user guides. The design includes:
- ListViews for “Get Started,” “Develop,” “Samples,” and “Recent Projects,” each returning a code that the main application interprets to take an action,
- A checkbox controlling if this welcome screen should appear on subsequent launches,
- A link to clear the recent project history.
Thus, it helps new and returning users rapidly get started with SWMM or jump into a recent or sample project.
No comments:
Post a Comment