Search in sources :

Example 1 with ExecutionContext

use of org.yakindu.sct.model.sruntime.ExecutionContext in project statecharts by Yakindu.

the class ExecutionContextVisualizer method highlightSuspendedElements.

protected void highlightSuspendedElements(final Notification notification) {
    highlight(notification, DefaultDynamicNotationHandler.SUSPENDED_PARAMS);
    List<IHighlightingSupport.Action> actions = new ArrayList<IHighlightingSupport.Action>();
    // This is required to set active state highlighting after resuming from
    // terminated local reaction breakpoint
    ExecutionContext context = getExecutionContext(notification);
    List<EObject> newValues = toList(notification.getNewValue());
    List<EObject> oldValues = toList(notification.getOldValue());
    oldValues.removeAll(newValues);
    for (EObject eObject : oldValues) {
        if (context.getActiveStates().contains(eObject)) {
            actions.add(new IHighlightingSupport.Highlight(eObject, DefaultDynamicNotationHandler.STATE_HIGHLIGHT_PARAMS));
        }
    }
    getHighlightingSupport().executeAsync(actions);
}
Also used : IHighlightingSupport(org.yakindu.base.gmf.runtime.highlighting.IHighlightingSupport) ExecutionContext(org.yakindu.sct.model.sruntime.ExecutionContext) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList)

Example 2 with ExecutionContext

use of org.yakindu.sct.model.sruntime.ExecutionContext in project statecharts by Yakindu.

the class FeatureParameterValueImpl method getExecutionContext.

/**
 * <!-- begin-user-doc --> <!-- end-user-doc -->
 *
 * @generated NOT
 */
protected ExecutionContext getExecutionContext() {
    if (!(EcoreUtil.getRootContainer(this) instanceof GeneratorModel)) {
        return new ExecutionContextImpl();
    }
    ExecutionContext context = new ExecutionContextImpl();
    GeneratorModel generatorModel = (GeneratorModel) EcoreUtil.getRootContainer(this);
    EList<PropertyDefinition> properties = generatorModel.getProperties();
    for (PropertyDefinition propertyDefinition : properties) {
        ExecutionVariable variable = SRuntimeFactory.eINSTANCE.createExecutionVariable();
        variable.setName(propertyDefinition.getName());
        variable.setFqName(propertyDefinition.getName());
        variable.setType(propertyDefinition.getType());
        variable.setValue(interpreter.evaluate(propertyDefinition.getInitialValue(), context));
        context.getSlots().add(variable);
    }
    return context;
}
Also used : ExecutionContext(org.yakindu.sct.model.sruntime.ExecutionContext) ExecutionContextImpl(org.yakindu.sct.model.sruntime.impl.ExecutionContextImpl) GeneratorModel(org.yakindu.sct.model.sgen.GeneratorModel) PropertyDefinition(org.yakindu.sct.model.sgen.PropertyDefinition) ExecutionVariable(org.yakindu.sct.model.sruntime.ExecutionVariable)

Example 3 with ExecutionContext

use of org.yakindu.sct.model.sruntime.ExecutionContext in project statecharts by Yakindu.

the class DefaultSimulationEngineFactory method restore.

protected ExecutionContext restore(String context, Statechart statechart) {
    try {
        ResourceSet set = new ResourceSetImpl();
        Resource resource = set.createResource(URI.createURI("snapshot.xmi"));
        if (resource == null)
            return null;
        set.getResources().add(resource);
        resource.load(new URIConverter.ReadableInputStream(context, "UTF_8"), Collections.emptyMap());
        IDomain domain = DomainRegistry.getDomain(statechart);
        Injector injector = domain.getInjector(IDomain.FEATURE_SIMULATION);
        ITypeSystem typeSystem = injector.getInstance(ITypeSystem.class);
        if (typeSystem instanceof AbstractTypeSystem) {
            set.getResources().add(((AbstractTypeSystem) typeSystem).getResource());
        }
        EcoreUtil.resolveAll(resource);
        ExecutionContext result = (ExecutionContext) resource.getContents().get(0);
        result.setSnapshot(true);
        return result;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : ITypeSystem(org.yakindu.base.types.typesystem.ITypeSystem) IDomain(org.yakindu.sct.domain.extension.IDomain) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) ExecutionContext(org.yakindu.sct.model.sruntime.ExecutionContext) Injector(com.google.inject.Injector) AbstractTypeSystem(org.yakindu.base.types.typesystem.AbstractTypeSystem) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) URIConverter(org.eclipse.emf.ecore.resource.URIConverter) CoreException(org.eclipse.core.runtime.CoreException)

Example 4 with ExecutionContext

use of org.yakindu.sct.model.sruntime.ExecutionContext in project statecharts by Yakindu.

the class DefaultSimulationEngineFactory method createExecutionContainer.

public ISimulationEngine createExecutionContainer(Statechart statechart, ILaunch launch) throws CoreException {
    ISimulationEngine controller = createController(statechart);
    injector.injectMembers(controller);
    // For restoring execution context
    String attribute = launch.getLaunchConfiguration().getAttribute(ISCTLaunchParameters.EXECUTION_CONTEXT, "");
    if (attribute != null && attribute.trim().length() > 0) {
        ExecutionContext context = restore(attribute, statechart);
        controller.setExecutionContext(context);
    }
    return controller;
}
Also used : ExecutionContext(org.yakindu.sct.model.sruntime.ExecutionContext) ISimulationEngine(org.yakindu.sct.simulation.core.engine.ISimulationEngine)

Aggregations

ExecutionContext (org.yakindu.sct.model.sruntime.ExecutionContext)4 Injector (com.google.inject.Injector)1 ArrayList (java.util.ArrayList)1 CoreException (org.eclipse.core.runtime.CoreException)1 EObject (org.eclipse.emf.ecore.EObject)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1 URIConverter (org.eclipse.emf.ecore.resource.URIConverter)1 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)1 IHighlightingSupport (org.yakindu.base.gmf.runtime.highlighting.IHighlightingSupport)1 AbstractTypeSystem (org.yakindu.base.types.typesystem.AbstractTypeSystem)1 ITypeSystem (org.yakindu.base.types.typesystem.ITypeSystem)1 IDomain (org.yakindu.sct.domain.extension.IDomain)1 GeneratorModel (org.yakindu.sct.model.sgen.GeneratorModel)1 PropertyDefinition (org.yakindu.sct.model.sgen.PropertyDefinition)1 ExecutionVariable (org.yakindu.sct.model.sruntime.ExecutionVariable)1 ExecutionContextImpl (org.yakindu.sct.model.sruntime.impl.ExecutionContextImpl)1 ISimulationEngine (org.yakindu.sct.simulation.core.engine.ISimulationEngine)1