function stopButtonPushed(obj, ~)
%STOPBUTTONPUSHED Callback for the stop simulation button.
%   Re-enable disabled controls, update simulation status label, stop
%   the simulation, and the refresh timer.

%   Copyright 2021-2024 The MathWorks, Inc.

    app = obj.App;

    if ~isfield(app.modelData, "simInp")
      return;
    end

    simIn = app.modelData.simInp;

    if ~isa(simIn, "Simulink.SimulationInput")
      return;
    end

    stop(app.refreshTimer);
    app.Helper.setUIControlState('off');
    arrayfun(@(menuItem)(set(app.(menuItem),'Enable','off')),obj.SimulationInactiveControls);
    drawnow limitrate;
    
    obj.debugTrace('Before stop');
    stop(app.Simulation);
    obj.debugTrace('After stop');
end
