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