function handleSimulationCompleted(obj)
%HANDLESIMULATIONCOMPLETED Perform the post-simulation data, timer, and UI actions.

%   Copyright 2024 The MathWorks, Inc.

  enableMenusForInactiveSimulation = @()(setSimulationInactiveControls(obj,'on'));
  
  app = obj.App;
  
  stop(app.refreshTimer);
  obj.debugTrace('After sim');
  
  app.modelData.simOut = app.Simulation.SimulationOutput;
  % Process the simulation results
  obj.processSimOut();
  % Make sure the bottom panels are visible
  obj.showPanels(["signals", "plots"]);
  % This delay allows the pane to fully expand before plotting to ensure
  % proper axes dimensions.
  pause(app.Helper.AddedDelayForPaneTransition);
  % Update plots
  obj.updateSigsAndAxesGL();
  
  app.StatusLabel.Text = '';
  app.SimTimeLabel.Text = '';
  
  % reset UI control
  app.RunPauseResumeButton.Icon = fullfile(app.AssetsFolder, 'images', 'icon_run.png');
  
  obj.setUIControlState('on');
  % simulation has finished, Simulation status will be Inactive. Re-enable Save/Load/Reset menu
  % for Session and Parameters/Inputs
  enableMenusForInactiveSimulation();
  
  app.StopButton.Enable = 'off';
  drawnow limitrate;
end
