@@ -143,6 +143,8 @@ function delete(App)
143143 App.SelectorUI.ModelFileFullPath = modelfile_fullpath ;
144144 % Block path in the drop down uses " / " as the subsystem separator.
145145 App.SelectorUI.BlockPathDropDownUI.Value = replace(App .BlockPath , " /" , " / " );
146+
147+ App .SelectorUI .GetParametersFromBlockCallback()
146148 end % if
147149
148150 Show(App .Window )
@@ -185,26 +187,71 @@ function delete(App)
185187
186188 function getParametersFromVehicleBlock(App )
187189 %%
190+ % This function collects parameters from the block in the model specified by
191+ % the block selector.
192+ % If a block parameter is a workspace variable, it must have been loaded
193+ % in the base workspace. If it's not loaded, the physical value UI component
194+ % shows an inline error.
188195
189196 App.ModelName = App .SelectorUI .ModelName ;
190197 App.BlockPath = App .SelectorUI .BlockPath ;
191198
192- previous_parameters = App .Parameters ;
193- App.Parameters = setup_all_data(App );
199+ % Before updating UI components, turn off the plot auto-update because
200+ % all UI components whose value changes call auto-update,
201+ % which is unecessary and noticeably slows down the update.
202+ previous_auto_update_value = App .AutoUpdateUI .Value ;
203+ App.AutoUpdateUI.Value = false ;
194204
195- if not(App .BlockIsReady )
196- % There was an issue in getting parameters from the block.
197- % Recover the previous state.
198- App.Parameters = previous_parameters ;
199- App.BlockPath = " " ;
205+ % Full enum name is returned, e.g., "sdl.enum.VehicleParameterizationType.Regular".
206+ full_enum_name = get_param(App .BlockPath , " vehParamType" );
207+ % Get the last part, which is the enum element name, e.g. "Regular".
208+ enum_element_name = extractAfter(full_enum_name , asManyOfPattern(wildcardPattern + " ." ));
200209
201- return
210+ if enum_element_name ~= " Regular"
211+ id = App .errorID + " :InvalidBlockParameter" ;
212+ msg = LiteApp5 .Utility .i18n(" Only "" Regular"" Parameterization type for Longitudinal Vehicle block is supported." );
213+
214+ throw(MException(id , msg ))
202215
203216 end % if
204217
205- setParametersToUIComponents(App )
206- auto_update_plot(App )
218+ App.VehicleMassUI.ValueEditFieldUI.Value = get_param(App .BlockPath , " M_vehicle" );
219+ App.VehicleMassUI.UnitDropDownUI.MainDropDown.Value = get_param(App .BlockPath , " M_vehicle_unit" );
220+
221+ % R_tireroll (tire rolling radius) is skipped because it is not used in the app.
222+
223+ App.TireRollingCoefficientUI.Value = get_param(App .BlockPath , " C_tireroll" );
224+
225+ App.AirDragCoefficientUI.Value = get_param(App .BlockPath , " C_airdrag" );
226+
227+ App.FrontalAreaUI.Value = get_param(App .BlockPath , " A_front" );
228+ App.FrontalAreaUI.Unit = get_param(App .BlockPath , " A_front_unit" );
229+
230+ App.GravitationalAccelerationUI.Value = get_param(App .BlockPath , " g" );
231+ App.GravitationalAccelerationUI.Unit = get_param(App .BlockPath , " g_unit" );
232+
233+ % !todo: Air density should be public in Longitudinal Vehicle block.
234+ % App.AirDensityUI.Value = get_param(App.BlockPath, "air_density");
235+ % App.AirDensityUI.Unit = get_param(App.BlockPath, "air_density_unit");
236+
237+ % Deselect the preset because parameters are read from the specified block.
238+ App.PresetUI.MainListBox.Value = {};
239+
240+ % -----------------------------------------------------------------------
241+
242+ % Synchronize the Parameters property based on the updated UI components
243+ % and update other UI components for the derived parameters.
244+ getParametersFromUIComponents(App )
245+ App.Parameters = update_states(App .Parameters );
246+ App.RoadLoadAUI.SimscapeValue = App .Parameters .RoadLoadA ;
247+ App.RoadLoadCUI.SimscapeValue = App .Parameters .RoadLoadC ;
248+ App.MaximumForceUI.SimscapeValue = App .Parameters .MaximumForce ;
249+ App.MaximumClimbPowerUI.SimscapeValue = App .Parameters .MaximumClimbPower ;
207250
251+ % Recover the previous auto-update state for the plot button.
252+ App.AutoUpdateUI.Value = previous_auto_update_value ;
253+
254+ auto_update_plot(App )
208255 end % function
209256
210257 function setParametersToVehicleBlock(App )
@@ -264,14 +311,6 @@ function performancePlot(App, NameValuePair)
264311 function getParametersFromUIComponents(App )
265312 %%
266313
267- if App .UseGUI
268- id = App .errorID + " AppNotVisible" ;
269- msg = " App must be visible before calling getParametersFromUIComponents" ;
270- % When this assertion fails, the app is not visible yet.
271- % Thus, show the error message in the Command Window.
272- assert(App .Window .MainFigure .Visible == " on" , id , msg )
273- end % if
274-
275314 % Vehicle ---------------------------------------------------------------
276315
277316 App.Parameters.VehicleMass = App .VehicleMassUI .SimscapeValue ;
@@ -771,31 +810,6 @@ function callback_AutoUpdate(App)
771810 App.UpdateButtonUI.MainButton.Enable = " on" ;
772811 end % if
773812 end % function
774-
775- %{
776- function callback_LoadParametersFromBlock(App)
777- %%
778- [App.Parameters, error_message] = getParametersFromBlock(App.Parameters, App.BlockPath);
779- if error_message ~= ""
780- % Do not issue an error and return from here.
781- % Fallback data are loaded in case of an error.
782- % if App.UseGUI && isprop(App, "Window") && isprop(App.Window, "MainFigure") && App.Window.MainFigure.Visible
783- uialert(App.Window.MainFigure, error_message, "Alert")
784- % else
785- % % App is not visible.
786- % warning("Vehicle1DPerformanceDesignAppMain:ErrorInGetParametersFromBlock", error_message);
787- % end % if, App UI or Command Window
788- end % if, error
789-
790- App.Parameters = update_states(App.Parameters);
791-
792- setParametersToComponents(App)
793-
794- if App.AutoUpdateUI.Value
795- performancePlot(App, ParentAxes=App.ParentAxes)
796- end % if, propagation
797- end % function
798- %}
799813
800814 function setParametersToUIComponents(App , NameValuePairs )
801815 %%
0 commit comments