Search in sources :

Example 1 with SimulationService

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

the class StopHandler method execute.

public void execute() {
    try {
        final SimulationService simulationService = Objects.requireNonNull((SimulationService) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getService(SimulationService.class), "Unable to retrieve simulation service");
        final SimulationUIService simulationUIService = Objects.requireNonNull((SimulationUIService) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getService(SimulationUIService.class), "Unable to retrieve simulation UI service");
        final SimulatorState simulatorState = simulationUIService.getCurrentState();
        final SimulationEngine engine = simulatorState.getSimulationEngine();
        if (engine != null) {
            simulationService.dispose(engine);
        }
    } 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);
    }
}
Also used : SimulationUIService(edu.uah.rsesc.aadlsimulator.ui.services.SimulationUIService) SimulationEngine(edu.uah.rsesc.aadlsimulator.SimulationEngine) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) SimulatorState(edu.uah.rsesc.aadlsimulator.ui.services.SimulatorState) SimulationService(edu.uah.rsesc.aadlsimulator.services.SimulationService) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 2 with SimulationService

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

the class SimulationLaunchShortcut method launch.

public ILaunch launch(final ComponentImplementation componentImplementation, String engineTypeId, final String mode) throws CoreException {
    if (engineTypeId == null) {
        final SimulationService simulationService = Objects.requireNonNull(PlatformUI.getWorkbench().getService(SimulationService.class), "Unable to retrieve simulation service");
        final EngineType engineType = simulationService.getCompatibleEngineType(componentImplementation);
        if (engineType == null) {
            StatusManager.getManager().handle(new Status(IStatus.ERROR, FrameworkUtil.getBundle(getClass()).getSymbolicName(), "Unable to find compatible simulation engine for " + componentImplementation.getQualifiedName()), StatusManager.BLOCK);
            return null;
        }
        engineTypeId = engineType.getId();
    }
    // Stop the current simulation
    new StopHandler().execute();
    final ILaunchConfigurationType configType = getLaunchConfigurationType();
    // Search for an existing launch configuration
    final List<ILaunchConfiguration> launchConfigs = getLaunchConfigurations(configType, componentImplementation, engineTypeId);
    ILaunchConfiguration launchConfig = launchConfigs.size() > 0 ? launchConfigs.get(0) : null;
    if (launchConfig == null) {
        final ILaunchConfigurationWorkingCopy wcLaunchConf = configType.newInstance(null, DebugPlugin.getDefault().getLaunchManager().generateLaunchConfigurationName(componentImplementation.getQualifiedName()));
        // Set attributes, etc for the launch configuration
        wcLaunchConf.setAttribute(SimulationLaunchConfigurationAttributes.COMPONENT_IMPLEMENTATION_NAME, componentImplementation.getQualifiedName());
        wcLaunchConf.setAttribute(SimulationLaunchConfigurationAttributes.PROJECT_NAME, getProjectName(componentImplementation.eResource()));
        if (engineTypeId != null) {
            wcLaunchConf.setAttribute(SimulationLaunchConfigurationAttributes.ENGINE_TYPE_ID, engineTypeId);
        }
        launchConfig = wcLaunchConf;
    }
    // Launch the launch configuration
    return DebugUITools.buildAndLaunch(launchConfig, mode, new NullProgressMonitor());
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) StopHandler(edu.uah.rsesc.aadlsimulator.ui.handlers.StopHandler) EngineType(edu.uah.rsesc.aadlsimulator.services.EngineType) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) SimulationService(edu.uah.rsesc.aadlsimulator.services.SimulationService)

Example 3 with SimulationService

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

the class SimulationTabGroup method createTabs.

@Override
public void createTabs(final ILaunchConfigurationDialog dialog, final String mode) {
    Objects.requireNonNull(dialog, "dialog must not be null");
    Objects.requireNonNull(dialog, "mode must not be null");
    // Get the simulation service
    final SimulationService simulationService = (SimulationService) PlatformUI.getWorkbench().getService(SimulationService.class);
    Objects.requireNonNull(simulationService, "Unable to retrieve SimulationService");
    final ILaunchConfigurationTab[] tabs = new ILaunchConfigurationTab[] { new SimulationTab(simulationService) };
    setTabs(tabs);
}
Also used : SimulationService(edu.uah.rsesc.aadlsimulator.services.SimulationService) ILaunchConfigurationTab(org.eclipse.debug.ui.ILaunchConfigurationTab)

Example 4 with SimulationService

use of edu.uah.rsesc.aadlsimulator.services.SimulationService 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 5 with SimulationService

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

the class SimulationLaunchConfigurationDelegate method launch.

@Override
public void launch(final ILaunchConfiguration configuration, final String mode, final ILaunch launch, final IProgressMonitor monitor) throws CoreException {
    SimulationService simulationService = null;
    try {
        simulationService = EclipseContextFactory.getServiceContext(FrameworkUtil.getBundle(getClass()).getBundleContext()).get(SimulationService.class);
        Objects.requireNonNull(configuration, "configuration must not be null");
        // Find the component implementation
        final String componentImplementationName = configuration.getAttribute(SimulationLaunchConfigurationAttributes.COMPONENT_IMPLEMENTATION_NAME, (String) null);
        final String projectName = configuration.getAttribute(SimulationLaunchConfigurationAttributes.PROJECT_NAME, (String) null);
        final IProject project = projectName == null ? null : findProject(projectName);
        final EObject obj = componentImplementationName == null ? null : findComponentImplementation(project, componentImplementationName);
        if (obj instanceof ComponentImplementation) {
            // Refresh the component implementation
            final ComponentImplementation ci = refreshComponentImplementation((ComponentImplementation) obj);
            // (Re)instantiate the model
            final SystemInstance systemInstance = InstantiateModel.buildInstanceModelFile(ci);
            // Get the selected simulation engine type.
            final String selectedEngineTypeId = Objects.requireNonNull(configuration.getAttribute(SimulationLaunchConfigurationAttributes.ENGINE_TYPE_ID, (String) null), "Simulation Engine must be specified");
            final EngineType engineType = Objects.requireNonNull(simulationService.getEngineTypeById(selectedEngineTypeId), "Unable to find specified simulation engine");
            final SimulationEngine newEngine = simulationService.createEngine(engineType, systemInstance);
            final SimulationService simService = simulationService;
            simulationService.addSimulationEngineChangeListener(new SimulationEngineChangeListener() {

                @Override
                public void onSimulationEngineCreated(final SimulationEngine engine) {
                }

                @Override
                public void onSimulationEngineDisposed(final SimulationEngine engine) {
                    if (engine == newEngine) {
                        DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch);
                        simService.removeSimulationEngineChangeListener(this);
                    }
                }
            });
            if (launch instanceof SimulationLaunch) {
                ((SimulationLaunch) launch).setSimulationEngine(newEngine);
            }
        } else {
            simulationService.getExceptionHandler().handleException(new CoreException(new Status(IStatus.ERROR, FrameworkUtil.getBundle(getClass()).getSymbolicName(), "Unable to find Component Implementation.")));
        }
    } catch (final Exception e) {
        DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch);
        if (simulationService == null) {
            throw new RuntimeException(e);
        } else {
            simulationService.getExceptionHandler().handleException(e);
        }
    }
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) SimulationEngine(edu.uah.rsesc.aadlsimulator.SimulationEngine) CoreException(org.eclipse.core.runtime.CoreException) SystemInstance(org.osate.aadl2.instance.SystemInstance) EObject(org.eclipse.emf.ecore.EObject) SimulationEngineChangeListener(edu.uah.rsesc.aadlsimulator.services.SimulationEngineChangeListener) EngineType(edu.uah.rsesc.aadlsimulator.services.EngineType) SimulationService(edu.uah.rsesc.aadlsimulator.services.SimulationService)

Aggregations

SimulationService (edu.uah.rsesc.aadlsimulator.services.SimulationService)6 SimulationEngine (edu.uah.rsesc.aadlsimulator.SimulationEngine)4 IStatus (org.eclipse.core.runtime.IStatus)4 Status (org.eclipse.core.runtime.Status)4 SimulationUIService (edu.uah.rsesc.aadlsimulator.ui.services.SimulationUIService)3 EngineType (edu.uah.rsesc.aadlsimulator.services.EngineType)2 SimulatorState (edu.uah.rsesc.aadlsimulator.ui.services.SimulatorState)2 ExecutionException (org.eclipse.core.commands.ExecutionException)2 EObject (org.eclipse.emf.ecore.EObject)2 AGREESimulationEngine (edu.uah.rsesc.aadlsimulator.agree.engine.AGREESimulationEngine)1 SimulationEngineChangeListener (edu.uah.rsesc.aadlsimulator.services.SimulationEngineChangeListener)1 SelectStepsDialog (edu.uah.rsesc.aadlsimulator.ui.dialogs.SelectStepsDialog)1 StopHandler (edu.uah.rsesc.aadlsimulator.ui.handlers.StopHandler)1 SimulationLaunchShortcut (edu.uah.rsesc.aadlsimulator.ui.launch.SimulationLaunchShortcut)1 SimulatorStateListener (edu.uah.rsesc.aadlsimulator.ui.services.SimulatorStateListener)1 StepForwardCanceledException (edu.uah.rsesc.aadlsimulator.ui.services.StepForwardCanceledException)1 UnknownProperty (jkind.results.UnknownProperty)1 IProject (org.eclipse.core.resources.IProject)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1