Search in sources :

Example 1 with SimulationLaunchShortcut

use of edu.uah.rsesc.aadlsimulator.ui.launch.SimulationLaunchShortcut in project AGREE by loonwerks.

the class SimulatorHandlerHelper method startSimulator.

public static Object startSimulator(final ExecutionEvent event, final String engineTypeId) {
    try {
        final SimulationUIService simulationUiService = Objects.requireNonNull(EclipseContextFactory.getServiceContext(FrameworkUtil.getBundle(SimulatorHandlerHelper.class).getBundleContext()).get(SimulationUIService.class), "unable to get simulation UI service");
        if (simulationUiService.getCurrentState().getSimulationEngine() != null) {
            final MessageBox messageBox = new MessageBox(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO);
            messageBox.setMessage("A simulation is already active. Do you want to stop the current simulation?");
            messageBox.setText("Stop Current Simulation");
            if (messageBox.open() == SWT.NO) {
                return null;
            }
        }
        if (event.getApplicationContext() instanceof IEvaluationContext) {
            final IEvaluationContext appContext = (IEvaluationContext) event.getApplicationContext();
            final ISelection selection = (ISelection) appContext.getVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME);
            final SimulationLaunchShortcut launchShortcut = new SimulationLaunchShortcut();
            launchShortcut.launch(selection, engineTypeId, ILaunchManager.RUN_MODE);
        }
    } catch (final Exception ex) {
        final Status status = new Status(IStatus.ERROR, FrameworkUtil.getBundle(SimulatorHandlerHelper.class).getSymbolicName(), "Error", ex);
        StatusManager.getManager().handle(status, StatusManager.SHOW | StatusManager.LOG);
    }
    return null;
}
Also used : SimulationUIService(edu.uah.rsesc.aadlsimulator.ui.services.SimulationUIService) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) ISelection(org.eclipse.jface.viewers.ISelection) SimulationLaunchShortcut(edu.uah.rsesc.aadlsimulator.ui.launch.SimulationLaunchShortcut) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 2 with SimulationLaunchShortcut

use of edu.uah.rsesc.aadlsimulator.ui.launch.SimulationLaunchShortcut in project AGREE by loonwerks.

the class CounterexampleLoaderHelper method receiveCex.

public void receiveCex(final ComponentImplementation compImpl, Property property, EObject agreeProperty, final Counterexample cex, final Map<String, EObject> refMap, final Mode mode) {
    // Launch the simulation
    final SimulationService simulationService = Objects.requireNonNull(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getService(SimulationService.class), "Unable to retrieve simulation service");
    final SimulationLaunchShortcut launchShortcut = new SimulationLaunchShortcut();
    try {
        final boolean isInductiveCex = property instanceof UnknownProperty;
        final ILaunch launch = launchShortcut.launch(compImpl, (isInductiveCex ? mode.inductiveEngineTypeId : mode.engineTypeId), ILaunchManager.RUN_MODE);
        // Get the simulation engine
        final SimulationEngine simulationEngine = getSimulationEngine(launch);
        if (simulationEngine instanceof AGREESimulationEngine) {
            final AGREESimulationEngine agreeSimulationEngine = (AGREESimulationEngine) simulationEngine;
            final SimulationUIService simulationUIService = Objects.requireNonNull(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getService(SimulationUIService.class), "Unable to retrieve simulation UI service");
            final Map<String, Object> signalNameToSimStateElementMap = buildAgreeNameToSimulationStateElementMap(agreeSimulationEngine);
            simulateCounterexample(cex, 0, signalNameToSimStateElementMap, agreeSimulationEngine, simulationService, simulationUIService);
        }
    } catch (final Exception e) {
        simulationService.getExceptionHandler().handleException(e);
    }
}
Also used : AGREESimulationEngine(edu.uah.rsesc.aadlsimulator.agree.engine.AGREESimulationEngine) SimulationEngine(edu.uah.rsesc.aadlsimulator.SimulationEngine) SimulationUIService(edu.uah.rsesc.aadlsimulator.ui.services.SimulationUIService) UnknownProperty(jkind.results.UnknownProperty) AGREESimulationEngine(edu.uah.rsesc.aadlsimulator.agree.engine.AGREESimulationEngine) ILaunch(org.eclipse.debug.core.ILaunch) EObject(org.eclipse.emf.ecore.EObject) SimulationLaunchShortcut(edu.uah.rsesc.aadlsimulator.ui.launch.SimulationLaunchShortcut) SimulationService(edu.uah.rsesc.aadlsimulator.services.SimulationService) PartInitException(org.eclipse.ui.PartInitException)

Aggregations

SimulationLaunchShortcut (edu.uah.rsesc.aadlsimulator.ui.launch.SimulationLaunchShortcut)2 SimulationUIService (edu.uah.rsesc.aadlsimulator.ui.services.SimulationUIService)2 SimulationEngine (edu.uah.rsesc.aadlsimulator.SimulationEngine)1 AGREESimulationEngine (edu.uah.rsesc.aadlsimulator.agree.engine.AGREESimulationEngine)1 SimulationService (edu.uah.rsesc.aadlsimulator.services.SimulationService)1 UnknownProperty (jkind.results.UnknownProperty)1 IEvaluationContext (org.eclipse.core.expressions.IEvaluationContext)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 ILaunch (org.eclipse.debug.core.ILaunch)1 EObject (org.eclipse.emf.ecore.EObject)1 ISelection (org.eclipse.jface.viewers.ISelection)1 MessageBox (org.eclipse.swt.widgets.MessageBox)1 PartInitException (org.eclipse.ui.PartInitException)1