Search in sources :

Example 6 with SimulationUIService

use of edu.uah.rsesc.aadlsimulator.ui.services.SimulationUIService in project AGREE by loonwerks.

the class ShowInSimulationVariablesViewHandler method calculateEnabled.

private boolean calculateEnabled(final Object evaluationContext) {
    final SimulationUIService simulationUiService = EclipseContextFactory.getServiceContext(FrameworkUtil.getBundle(getClass()).getBundleContext()).get(SimulationUIService.class);
    if (simulationUiService == null) {
        return false;
    }
    final List<BusinessObjectContext> selectedBocs = getSelectedDiagramElementsFromContext(evaluationContext);
    if (simulationUiService.getCurrentState().getEngineState() == null || selectedBocs.size() != 1) {
        return false;
    }
    final Object bo = selectedBocs.get(0).getBusinessObject();
    // Make the command available if there is only one business object selected and it is not the root System instance
    if ((bo instanceof FeatureInstance || bo instanceof ComponentInstance) && bo != ((InstanceObject) bo).getSystemInstance()) {
        final InstanceObject io = (InstanceObject) bo;
        // Compare the references from the diagram and simulation system instances. Only show the command if they match
        final URI diagramSystemInstanceUri = EcoreUtil.getURI(io.getSystemInstance());
        final URI simulationSystemInstanceUri = EcoreUtil.getURI(simulationUiService.getCurrentState().getSimulationEngine().getSystemInstance());
        return diagramSystemInstanceUri != null && diagramSystemInstanceUri.equals(simulationSystemInstanceUri);
    }
    return false;
}
Also used : SimulationUIService(edu.uah.rsesc.aadlsimulator.ui.services.SimulationUIService) InstanceObject(org.osate.aadl2.instance.InstanceObject) FeatureInstance(org.osate.aadl2.instance.FeatureInstance) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) InstanceObject(org.osate.aadl2.instance.InstanceObject) BusinessObjectContext(org.osate.ge.BusinessObjectContext) URI(org.eclipse.emf.common.util.URI)

Example 7 with SimulationUIService

use of edu.uah.rsesc.aadlsimulator.ui.services.SimulationUIService 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)

Example 8 with SimulationUIService

use of edu.uah.rsesc.aadlsimulator.ui.services.SimulationUIService in project AGREE by loonwerks.

the class SaveLustreHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    final SimulationUIService simulationUIService = Objects.requireNonNull((SimulationUIService) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getService(SimulationUIService.class), "Unable to retrieve simulation UI service");
    final SimulationEngineState engineState = simulationUIService.getCurrentState().getEngineState();
    if (engineState instanceof LustreProgramProvider) {
        LustreProgramSaver.handleSave((LustreProgramProvider) engineState);
    }
    return null;
}
Also used : SimulationUIService(edu.uah.rsesc.aadlsimulator.ui.services.SimulationUIService) SimulationEngineState(edu.uah.rsesc.aadlsimulator.SimulationEngineState) LustreProgramProvider(edu.uah.rsesc.aadlsimulator.agree.LustreProgramProvider)

Example 9 with SimulationUIService

use of edu.uah.rsesc.aadlsimulator.ui.services.SimulationUIService in project AGREE by loonwerks.

the class ExportAction method buildExportArguments.

private ExportArguments buildExportArguments() {
    final SimulationUIService simUiService = (SimulationUIService) Objects.requireNonNull(PlatformUI.getWorkbench().getService(SimulationUIService.class), "Unable to retrieve Simulation UI Service");
    final SimulatorState simulatorState = simUiService.getCurrentState();
    if (!(simulatorState.getEngineState() instanceof AGREESimulationState)) {
        throw new RuntimeException("Simulation engine state must be an AGREESimulationState");
    }
    if (!(simulatorState.getSimulationEngine() instanceof AGREESimulationEngine)) {
        throw new RuntimeException("Simulation engine must be an AGREESimulationEngine");
    }
    final AGREESimulationState agreeSimState = (AGREESimulationState) simulatorState.getEngineState();
    final AGREESimulationEngine engine = (AGREESimulationEngine) simulatorState.getSimulationEngine();
    final ComponentImplementation componentImplementation = engine.getSystemInstance().getComponentImplementation();
    final Counterexample cex = buildCounterexample(agreeSimState);
    final Renaming renaming = engine.getSimulationProgram().getAgreeRenaming();
    return new ExportArguments() {

        @Override
        public ComponentImplementation getComponentImplementation() {
            return componentImplementation;
        }

        @Override
        public Counterexample getCounterexample() {
            return cex;
        }

        @Override
        public Renaming getAgreeRenaming() {
            return renaming;
        }
    };
}
Also used : SimulationUIService(edu.uah.rsesc.aadlsimulator.ui.services.SimulationUIService) ComponentImplementation(org.osate.aadl2.ComponentImplementation) AGREESimulationState(edu.uah.rsesc.aadlsimulator.agree.engine.AGREESimulationState) ExportArguments(edu.uah.rsesc.aadlsimulator.agree.ext.AGREESimulationExporter.ExportArguments) AGREESimulationEngine(edu.uah.rsesc.aadlsimulator.agree.engine.AGREESimulationEngine) SimulatorState(edu.uah.rsesc.aadlsimulator.ui.services.SimulatorState) Counterexample(jkind.results.Counterexample) Renaming(jkind.api.results.Renaming)

Example 10 with SimulationUIService

use of edu.uah.rsesc.aadlsimulator.ui.services.SimulationUIService in project AGREE by loonwerks.

the class SimulatePossibilitiesHandler method execute.

public Object execute(ExecutionEvent execEvent) throws ExecutionException {
    try {
        final SimulationUIService simulationUIService = (SimulationUIService) Objects.requireNonNull(PlatformUI.getWorkbench().getService(SimulationUIService.class), "unable to get simulation UI service");
        final Shell shell = new Shell(Display.getDefault().getActiveShell(), SWT.SHELL_TRIM & ~SWT.MIN);
        // Notify the UI service to prepare to step forward. This will validate input constraints which are being edited
        simulationUIService.prepareToStepForward();
        final List<SimulationEngineState> simulationEngineStates = new ArrayList<>();
        final SelectStepsDialog dlg = new SelectStepsDialog(new Shell(Display.getDefault(), SWT.NONE));
        final int returnCode = dlg.open();
        // Object to control when job is done/canceled
        final Object simControlLock = new Object();
        if (returnCode == 0 && dlg.getSteps() != null) {
            simulationUIService.lockUserInterface();
            new Job("Simulate Possibilities") {

                @Override
                protected IStatus run(IProgressMonitor monitor) {
                    final SimulationEngine simulationEngine = simulationUIService.getCurrentState().getSimulationEngine().fork();
                    try {
                        final SimulationEngineState initialState = simulationEngine.getCurrentState();
                        final SimulatorStateListener canceledListener = new SimulatorStateListener() {

                            @Override
                            public void onSimulatorStateChanged(SimulatorState simulatorState) {
                                // Check if canceled
                                if (simulationUIService.getCurrentState().getEngineState() == null) {
                                    // notify to exit job
                                    synchronized (simControlLock) {
                                        simControlLock.notify();
                                    }
                                }
                            }
                        };
                        simulationUIService.addStateChangeListener(canceledListener);
                        try {
                            monitor.beginTask("Simulate", dlg.getSteps());
                            runSimulation(monitor, simControlLock, simulationUIService, simulationEngine, simulationEngineStates, dlg);
                            openChart(monitor, shell, simControlLock, simulationUIService, simulationEngine, simulationEngineStates, initialState);
                            synchronized (simControlLock) {
                                simControlLock.wait();
                            }
                            return monitor.isCanceled() ? Status.CANCEL_STATUS : Status.OK_STATUS;
                        } catch (final InterruptedException e) {
                            Thread.currentThread().interrupt();
                            throw new RuntimeException(e);
                        } catch (final Exception e) {
                            throw e;
                        } finally {
                            simulationUIService.unlockUserInterface();
                            simulationUIService.removeStateChangeListener(canceledListener);
                        }
                    } finally {
                        simulationEngine.dispose();
                    }
                }
            }.schedule();
        }
    } catch (StepForwardCanceledException ex) {
        final Status status = new Status(IStatus.ERROR, FrameworkUtil.getBundle(getClass()).getSymbolicName(), "Error preparing to step forward", ex);
        StatusManager.getManager().handle(status, StatusManager.SHOW);
        return null;
    } catch (final Exception ex) {
        final Status status = new Status(IStatus.ERROR, FrameworkUtil.getBundle(getClass()).getSymbolicName(), "Error", ex);
        StatusManager.getManager().handle(status, StatusManager.SHOW | StatusManager.LOG);
    }
    return null;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) SelectStepsDialog(edu.uah.rsesc.aadlsimulator.ui.dialogs.SelectStepsDialog) SimulationEngineState(edu.uah.rsesc.aadlsimulator.SimulationEngineState) SimulatorStateListener(edu.uah.rsesc.aadlsimulator.ui.services.SimulatorStateListener) StepForwardCanceledException(edu.uah.rsesc.aadlsimulator.ui.services.StepForwardCanceledException) ArrayList(java.util.ArrayList) SimulatorState(edu.uah.rsesc.aadlsimulator.ui.services.SimulatorState) ExecutionException(org.eclipse.core.commands.ExecutionException) StepForwardCanceledException(edu.uah.rsesc.aadlsimulator.ui.services.StepForwardCanceledException) SimulationUIService(edu.uah.rsesc.aadlsimulator.ui.services.SimulationUIService) SimulationEngine(edu.uah.rsesc.aadlsimulator.SimulationEngine) Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Job(org.eclipse.core.runtime.jobs.Job)

Aggregations

SimulationUIService (edu.uah.rsesc.aadlsimulator.ui.services.SimulationUIService)16 IStatus (org.eclipse.core.runtime.IStatus)9 Status (org.eclipse.core.runtime.Status)9 SimulatorState (edu.uah.rsesc.aadlsimulator.ui.services.SimulatorState)8 ExecutionException (org.eclipse.core.commands.ExecutionException)8 SimulationEngine (edu.uah.rsesc.aadlsimulator.SimulationEngine)6 SimulationEngineState (edu.uah.rsesc.aadlsimulator.SimulationEngineState)4 AGREESimulationEngine (edu.uah.rsesc.aadlsimulator.agree.engine.AGREESimulationEngine)3 SimulationService (edu.uah.rsesc.aadlsimulator.services.SimulationService)3 SimulatorStateListener (edu.uah.rsesc.aadlsimulator.ui.services.SimulatorStateListener)3 Shell (org.eclipse.swt.widgets.Shell)3 InstanceObject (org.osate.aadl2.instance.InstanceObject)3 SelectStepsDialog (edu.uah.rsesc.aadlsimulator.ui.dialogs.SelectStepsDialog)2 SimulationLaunchShortcut (edu.uah.rsesc.aadlsimulator.ui.launch.SimulationLaunchShortcut)2 StepForwardCanceledException (edu.uah.rsesc.aadlsimulator.ui.services.StepForwardCanceledException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 Job (org.eclipse.core.runtime.jobs.Job)2 URI (org.eclipse.emf.common.util.URI)2 PartInitException (org.eclipse.ui.PartInitException)2 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)2