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);
}
}
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());
}
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);
}
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);
}
}
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);
}
}
}
Aggregations