Search in sources :

Example 11 with SimulationUIService

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

the class StepForwardHandler method execute.

public Object execute(final ExecutionEvent event) throws ExecutionException {
    try {
        final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        final SimulationUIService simulationUIService = Objects.requireNonNull((SimulationUIService) window.getService(SimulationUIService.class), "Unable to retrieve simulation UI service");
        if (simulationUIService.canStepForward()) {
            simulationUIService.stepForward();
        }
    } 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 : SimulationUIService(edu.uah.rsesc.aadlsimulator.ui.services.SimulationUIService) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 12 with SimulationUIService

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

the class StepForwardMultipleTimesHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    try {
        final SimulationUIService simulationUIService = (SimulationUIService) Objects.requireNonNull(PlatformUI.getWorkbench().getService(SimulationUIService.class), "Unable to get simulation UI service");
        final SimulationService simulationService = Objects.requireNonNull((SimulationService) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getService(SimulationService.class), "Unable to retrieve simulation service");
        final SimulationEngine simulationEngine = simulationUIService.getCurrentState().getSimulationEngine();
        // Notify the UI service to prepare to step forward. This will validate input constraints which are being edited
        try {
            simulationUIService.prepareToStepForward();
        } 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;
        }
        final SelectStepsDialog dlg = new SelectStepsDialog(new Shell(Display.getDefault(), SWT.NONE));
        final int returnCode = dlg.open();
        final Object simControlLock = new Object();
        if (returnCode == 0 && dlg.getSteps() != null) {
            simulationUIService.lockUserInterface();
            new Job("Simulating") {

                @Override
                protected IStatus run(IProgressMonitor monitor) {
                    final SimulatorStateListener canceledListener = new SimulatorStateListener() {

                        @Override
                        public void onSimulatorStateChanged(SimulatorState simulatorState) {
                            // Check if canceled
                            if (simulatorState.getEngineState() == null) {
                                // notify to exit job
                                synchronized (simControlLock) {
                                    simControlLock.notify();
                                }
                            }
                        }
                    };
                    simulationUIService.addStateChangeListener(canceledListener);
                    try {
                        monitor.beginTask("Simulate Steps", dlg.getSteps());
                        runSimulation(monitor, simControlLock, simulationUIService, simulationService, simulationEngine, dlg);
                        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);
                        simulationEngine.clearPendingCommands();
                    }
                }
            }.schedule();
        }
    } 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 : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IStatus(org.eclipse.core.runtime.IStatus) SelectStepsDialog(edu.uah.rsesc.aadlsimulator.ui.dialogs.SelectStepsDialog) StepForwardCanceledException(edu.uah.rsesc.aadlsimulator.ui.services.StepForwardCanceledException) SimulatorStateListener(edu.uah.rsesc.aadlsimulator.ui.services.SimulatorStateListener) 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) SimulationService(edu.uah.rsesc.aadlsimulator.services.SimulationService)

Example 13 with SimulationUIService

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

the class OpenVariablesChartHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    try {
        final SimulationUIService simulationUIService = (SimulationUIService) Objects.requireNonNull(PlatformUI.getWorkbench().getService(SimulationUIService.class), "unable to get simulation UI service");
        // Open Value Visualization Chart
        simulationUIService.getCurrentState().getSimulationEngine().queueNotification(new NotificationHandler() {

            @Override
            public void handleNotification(final SimulationEngineNotification notification) {
                Display.getDefault().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        if (simulationUIService.getCurrentState().getEngineState().getNumberOfFrames() != 0) {
                            simulationUIService.lockUserInterface();
                            final Shell shell = new Shell(Display.getDefault().getActiveShell(), SWT.SHELL_TRIM & ~SWT.MIN);
                            // Listening for cancellation
                            final SimulatorStateListener simCanceledListener = new SimulatorStateListener() {

                                @Override
                                public void onSimulatorStateChanged(SimulatorState simulatorState) {
                                    if (simulationUIService.getCurrentState().getEngineState() == null) {
                                        if (shell != null && !shell.isDisposed()) {
                                            // Close view on cancel
                                            shell.close();
                                        }
                                    }
                                }
                            };
                            simulationUIService.addStateChangeListener(simCanceledListener);
                            try {
                                new VariablesChartDialog(shell, simulationUIService);
                            } finally {
                                simulationUIService.removeStateChangeListener(simCanceledListener);
                                simulationUIService.unlockUserInterface();
                            }
                        }
                    }
                });
            }
        });
    } 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 : SimulationUIService(edu.uah.rsesc.aadlsimulator.ui.services.SimulationUIService) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) Shell(org.eclipse.swt.widgets.Shell) VariablesChartDialog(edu.uah.rsesc.aadlsimulator.ui.dialogs.VariablesChartDialog) SimulatorStateListener(edu.uah.rsesc.aadlsimulator.ui.services.SimulatorStateListener) NotificationHandler(edu.uah.rsesc.aadlsimulator.NotificationHandler) SimulatorState(edu.uah.rsesc.aadlsimulator.ui.services.SimulatorState) SimulationEngineNotification(edu.uah.rsesc.aadlsimulator.SimulationEngineNotification) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 14 with SimulationUIService

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

the class ResetInputConstraintsHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    try {
        final SimulationUIService simulationUIService = (SimulationUIService) Objects.requireNonNull(PlatformUI.getWorkbench().getService(SimulationUIService.class), "unable to get simulation UI service");
        simulationUIService.getCurrentState().getSimulationEngine().resetInputConstraints();
    } 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 : SimulationUIService(edu.uah.rsesc.aadlsimulator.ui.services.SimulationUIService) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 15 with SimulationUIService

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

the class ShowInSimulationVariablesViewHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final SimulationUIService simulationUiService = EclipseContextFactory.getServiceContext(FrameworkUtil.getBundle(getClass()).getBundleContext()).get(SimulationUIService.class);
    final List<BusinessObjectContext> selectedBocs = getBusinessObjectContexts(HandlerUtil.getCurrentSelection(event));
    try {
        final SimulationEngineState engineState = simulationUiService.getCurrentState().getEngineState();
        Objects.requireNonNull(engineState, "engineState must not be null");
        final Object stateElement = Objects.requireNonNull(engineState.findElement((InstanceObject) selectedBocs.get(0).getBusinessObject()), "unable to retrieve state element");
        // Ensure variables view is visible
        final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
        final IViewPart variablesViewPart = page.showView(UIConstants.VARIABLES_VIEW_ID);
        if (variablesViewPart instanceof VariablesViewPart) {
            // Scroll to and select the state element
            final VariablesViewPart variablesView = (VariablesViewPart) variablesViewPart;
            variablesView.scrollToAndSelectStateElement(stateElement);
        }
    } catch (final PartInitException e) {
        throw new RuntimeException(e);
    }
    return null;
}
Also used : SimulationUIService(edu.uah.rsesc.aadlsimulator.ui.services.SimulationUIService) InstanceObject(org.osate.aadl2.instance.InstanceObject) IViewPart(org.eclipse.ui.IViewPart) VariablesViewPart(edu.uah.rsesc.aadlsimulator.ui.views.VariablesViewPart) SimulationEngineState(edu.uah.rsesc.aadlsimulator.SimulationEngineState) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) InstanceObject(org.osate.aadl2.instance.InstanceObject) PartInitException(org.eclipse.ui.PartInitException) BusinessObjectContext(org.osate.ge.BusinessObjectContext)

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