8
8
9
9
from trame .widgets import html , vuetify
10
10
11
+ from ..Analyze .plotsMain import available_plot_options , load_dataTable_data , update_plot
11
12
from ..Input .generalFunctions import generalFunctions
13
+ from ..Run .controls import execute_impactx_sim
12
14
from ..trame_setup import setup_server
13
15
from .exportTemplate import input_file
14
16
from .importParser import DashboardParser
22
24
state .importing_file = False
23
25
24
26
25
- # -----------------------------------------------------------------------------
26
- # Triggers/Controllers
27
- # -----------------------------------------------------------------------------
28
- def reset_importing_states ():
29
- state .import_file_error = None
30
- state .import_file_details = None
31
- state .import_file = None
32
- state .importing_file = False
33
-
34
-
35
- @ctrl .add ("reset_all" )
36
- def reset_all ():
37
- reset_importing_states ()
38
- generalFunctions .reset_inputs ("all" )
39
-
40
-
41
- @ctrl .trigger ("export" )
42
- def on_export_click ():
43
- return input_file ()
44
-
45
-
46
- @state .change ("import_file" )
47
- def on_import_file_change (import_file , ** kwargs ):
48
- if import_file :
49
- try :
50
- state .importing_file = True
51
- DashboardParser .file_details (import_file )
52
- DashboardParser .populate_impactx_simulation_file_to_ui (import_file )
53
- except Exception :
54
- state .import_file_error = True
55
- state .import_file_error_message = "Unable to parse"
56
- finally :
57
- state .importing_file = False
27
+ class ToolbarImport :
28
+ @state .change ("import_file" )
29
+ def on_import_file_change (import_file , ** kwargs ):
30
+ if import_file :
31
+ try :
32
+ state .importing_file = True
33
+ DashboardParser .file_details (import_file )
34
+ DashboardParser .populate_impactx_simulation_file_to_ui (import_file )
35
+ except Exception :
36
+ state .import_file_error = True
37
+ state .import_file_error_message = "Unable to parse"
38
+ finally :
39
+ state .importing_file = False
58
40
41
+ @staticmethod
42
+ def reset_importing_states ():
43
+ """
44
+ Resets import related states to default.
45
+ """
59
46
60
- # -----------------------------------------------------------------------------
61
- # Common toolbar elements
62
- # -----------------------------------------------------------------------------
47
+ state .import_file_error = None
48
+ state .import_file_details = None
49
+ state .import_file = None
50
+ state .importing_file = False
63
51
64
52
65
- class ToolbarElements :
53
+ class InputToolbar :
66
54
"""
67
- Helper functions to create
68
- Vuetify UI elements for toolbar.
55
+ Contains toolbar elements for the Input page.
69
56
"""
70
57
58
+ @ctrl .trigger ("export" )
59
+ def on_export_click ():
60
+ return input_file ()
61
+
62
+ @ctrl .add ("reset_all" )
63
+ def reset_all ():
64
+ ToolbarImport .reset_importing_states ()
65
+ generalFunctions .reset_inputs ("all" )
66
+
71
67
@staticmethod
72
- def export_button ():
68
+ def export_button () -> vuetify .VBtn :
69
+ """
70
+ Creates an export button to download a .py file
71
+ containing the user's current input values.
72
+ """
73
+
73
74
with vuetify .VBtn (
74
75
click = "utils.download('impactx_simulation.py', trigger('export'), 'text/plain')" ,
75
76
outlined = True ,
@@ -81,28 +82,12 @@ def export_button():
81
82
html .Span ("Export" )
82
83
83
84
@staticmethod
84
- def plot_options ():
85
- vuetify .VSelect (
86
- v_model = ("active_plot" , "1D plots over s" ),
87
- items = ("plot_options" ,),
88
- label = "Select plot to view" ,
89
- hide_details = True ,
90
- dense = True ,
91
- style = "max-width: 250px" ,
92
- disabled = ("disableRunSimulationButton" , True ),
93
- )
94
-
95
- @staticmethod
96
- def run_simulation_button ():
97
- vuetify .VBtn (
98
- "Run Simulation" ,
99
- style = "background-color: #00313C; color: white; margin: 0 20px;" ,
100
- click = ctrl .run_simulation ,
101
- disabled = ("disableRunSimulationButton" , True ),
102
- )
85
+ def import_button () -> None :
86
+ """
87
+ Displays the 'import' button on the input section
88
+ of the dashboard.
89
+ """
103
90
104
- @staticmethod
105
- def import_button ():
106
91
vuetify .VFileInput (
107
92
v_model = ("import_file" ,),
108
93
accept = ".py" ,
@@ -146,7 +131,12 @@ def import_button():
146
131
)
147
132
148
133
@staticmethod
149
- def reset_inputs_button ():
134
+ def reset_inputs_button () -> vuetify .VBtn :
135
+ """
136
+ Creates a button to reset all input fields to
137
+ default values.
138
+ """
139
+
150
140
with vuetify .VBtn (
151
141
click = ctrl .reset_all ,
152
142
outlined = True ,
@@ -155,43 +145,103 @@ def reset_inputs_button():
155
145
vuetify .VIcon ("mdi-refresh" , left = True )
156
146
html .Span ("Reset" )
157
147
148
+
149
+ class RunToolbar :
150
+ """
151
+ Contains toolbar elements for the Run page.
152
+ """
153
+
154
+ @ctrl .add ("begin_sim" )
155
+ def run ():
156
+ state .plot_options = available_plot_options (simulationClicked = True )
157
+ execute_impactx_sim ()
158
+ update_plot ()
159
+ load_dataTable_data ()
160
+
158
161
@staticmethod
159
- def dashboard_info () :
162
+ def run_simulation_button () -> vuetify . VBtn :
160
163
"""
161
- Creates an alert box with dashboard information.
164
+ Creates a button to run an ImpactX simulation
165
+ with the current user-provided inputs.
162
166
"""
163
167
164
- vuetify .VAlert (
165
- "ImpactX Dashboard is provided as a preview and continues to be developed. "
166
- "Thus, it may not yet include all the features available in ImpactX." ,
167
- type = "info" ,
168
+ return vuetify .VBtn (
169
+ "Run Simulation" ,
170
+ style = "background-color: #00313C; color: white; margin: 0 20px;" ,
171
+ click = ctrl .begin_sim ,
172
+ disabled = ("disableRunSimulationButton" , True ),
173
+ )
174
+
175
+
176
+ class AnalyzeToolbar :
177
+ """
178
+ Contains toolbar elements for the Analyze page.
179
+ """
180
+
181
+ @staticmethod
182
+ def plot_options () -> vuetify .VSelect :
183
+ """
184
+ Creates a dropdown menu for selecting a plot
185
+ to visualize simulation results.
186
+ """
187
+
188
+ return vuetify .VSelect (
189
+ v_model = ("active_plot" , "1D plots over s" ),
190
+ items = ("plot_options" ,),
191
+ label = "Select plot to view" ,
192
+ hide_details = True ,
168
193
dense = True ,
169
- dismissible = True ,
170
- v_model = ("show_dashboard_alert" , True ),
171
- classes = "mt-4" ,
194
+ style = "max-width: 250px" ,
195
+ disabled = ("disableRunSimulationButton" , True ),
172
196
)
173
197
174
198
175
- class Toolbars :
199
+ class GeneralToolbar :
176
200
"""
177
- Builds toolbar for dashboard .
201
+ General tolbar elements .
178
202
"""
179
203
180
204
@staticmethod
181
205
def dashboard_toolbar (toolbar_name : str ) -> None :
206
+ """
207
+ Builds and displays the appropriate toolbar
208
+ based on the selected dashboard section.
209
+
210
+ :param toolbar_name: The name of the dashboard section
211
+ for which the toolbar is needed.
212
+ """
213
+
182
214
toolbar_name = toolbar_name .lower ()
183
215
if toolbar_name == "input" :
184
- (ToolbarElements .dashboard_info (),)
216
+ (GeneralToolbar .dashboard_info (),)
185
217
vuetify .VSpacer ()
186
- ToolbarElements .import_button ()
187
- ToolbarElements .export_button ()
188
- ToolbarElements .reset_inputs_button ()
189
-
218
+ InputToolbar .import_button ()
219
+ InputToolbar .export_button ()
220
+ InputToolbar .reset_inputs_button ()
190
221
elif toolbar_name == "run" :
191
- (ToolbarElements .dashboard_info (),)
222
+ (GeneralToolbar .dashboard_info (),)
192
223
(vuetify .VSpacer (),)
193
- (ToolbarElements .run_simulation_button (),)
224
+ (RunToolbar .run_simulation_button (),)
194
225
elif toolbar_name == "analyze" :
195
- (ToolbarElements .dashboard_info (),)
226
+ (GeneralToolbar .dashboard_info (),)
196
227
vuetify .VSpacer ()
197
- ToolbarElements .plot_options ()
228
+ AnalyzeToolbar .plot_options ()
229
+
230
+ @staticmethod
231
+ def dashboard_info () -> vuetify .VAlert :
232
+ """
233
+ Creates an informational alert box for the dashboard to
234
+ notify users that the ImpactX dashboard is still in development.
235
+
236
+ :return: A Vuetify alert component displaying the dashboard notice.
237
+ """
238
+
239
+ return vuetify .VAlert (
240
+ "ImpactX Dashboard is provided as a preview and continues to be developed. "
241
+ "Thus, it may not yet include all the features available in ImpactX." ,
242
+ type = "info" ,
243
+ dense = True ,
244
+ dismissible = True ,
245
+ v_model = ("show_dashboard_alert" , True ),
246
+ classes = "mt-4" ,
247
+ )
0 commit comments