Search in sources :

Example 1 with EvaluationContext

use of org.osate.aadl2.properties.EvaluationContext 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;
}
Also used : SimulationUIService(edu.uah.rsesc.aadlsimulator.ui.services.SimulationUIService) InstanceObject(org.osate.aadl2.instance.InstanceObject) FeatureInstance(org.osate.aadl2.instance.FeatureInstance) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) InstanceObject(org.osate.aadl2.instance.InstanceObject) BusinessObjectContext(org.osate.ge.BusinessObjectContext) URI(org.eclipse.emf.common.util.URI)

Example 2 with EvaluationContext

use of org.osate.aadl2.properties.EvaluationContext in project osate2 by osate.

the class OpenAssociatedDiagramHandler method setEnabled.

@Override
public void setEnabled(final Object evaluationContext) {
    boolean enabled = false;
    final List<BusinessObjectContext> selectedBusinessObjectContexts = AgeHandlerUtil.getSelectedBusinessObjectContexts();
    if (selectedBusinessObjectContexts.size() == 1) {
        final BusinessObjectContext selectedBusinessObjectContext = selectedBusinessObjectContexts.get(0);
        final Object bo = selectedBusinessObjectContext.getBusinessObject();
        enabled = (bo instanceof AadlPackage || bo instanceof Classifier || (bo instanceof Subcomponent && AadlSubcomponentUtil.getComponentClassifier(selectedBusinessObjectContext, (Subcomponent) bo) != null)) && ProjectUtil.getProjectForBo(bo).isPresent();
    }
    setBaseEnabled(enabled);
}
Also used : AadlPackage(org.osate.aadl2.AadlPackage) Subcomponent(org.osate.aadl2.Subcomponent) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier) BusinessObjectContext(org.osate.ge.BusinessObjectContext)

Example 3 with EvaluationContext

use of org.osate.aadl2.properties.EvaluationContext in project osate2 by osate.

the class ExecuteResoluteUtil method executeResoluteFunctionOnce.

/**
 * invokes Resolute claim function on targetComponent or targetElement if not null.
 * instanceroot is used to initialize the Resolute evaluation context.
 * targetComponent is the evaluation context
 * targetElement is the model element within the component instance or null.
 * parameterObjects is a list of additional parameters of types RealLiteral, IntegerLiteral, StringLiteral, BooleanLiteral
 * parameterObjects can be null or an empty list.
 * The return value is an Issue object with subissues for the list of issues returned in the Resolute ClaimResult.
 * If the proof fails then the top Issue is set to FAIL, if successful it is set to SUCCESS
 */
public Diagnostic executeResoluteFunctionOnce(EObject fundef, final SystemInstance instanceroot, final ComponentInstance targetComponent, final InstanceObject targetElement, List<PropertyExpression> parameterObjects) {
    FunctionDefinition fd = (FunctionDefinition) fundef;
    initializeResoluteContext(instanceroot);
    EvaluationContext context = new EvaluationContext(targetComponent, sets, featToConnsMap);
    // check for claim function
    FnCallExpr fcncall = createWrapperFunctionCall(fd, targetComponent, targetElement, parameterObjects);
    if (fcncall != null) {
        // using com.rockwellcollins.atc.resolute.analysis.results.ClaimResult
        ResoluteProver prover = new ResoluteProver(context) {

            @Override
            protected ResoluteEvaluator createResoluteEvaluator() {
                return new ResoluteEvaluator(context, varStack.peek()) {

                    @Override
                    public ResoluteValue caseThisExpr(ThisExpr object) {
                        NamedElement curr = context.getThisInstance();
                        if (object.getSub() != null) {
                            curr = object.getSub().getBase();
                        }
                        return new NamedElementValue(curr);
                    }
                };
            }
        };
        ResoluteResult res = prover.doSwitch(fcncall);
        return doResoluteResults(res);
    } else {
        return ResultUtil.createErrorDiagnostic("Could not find Resolute Function " + fd.getName(), fd);
    }
}
Also used : ResoluteEvaluator(com.rockwellcollins.atc.resolute.analysis.execution.ResoluteEvaluator) ResoluteResult(com.rockwellcollins.atc.resolute.analysis.results.ResoluteResult) NamedElementValue(com.rockwellcollins.atc.resolute.analysis.values.NamedElementValue) FunctionDefinition(com.rockwellcollins.atc.resolute.resolute.FunctionDefinition) EvaluationContext(com.rockwellcollins.atc.resolute.analysis.execution.EvaluationContext) FnCallExpr(com.rockwellcollins.atc.resolute.resolute.FnCallExpr) NamedElement(org.osate.aadl2.NamedElement) ResoluteProver(com.rockwellcollins.atc.resolute.analysis.execution.ResoluteProver) ThisExpr(com.rockwellcollins.atc.resolute.resolute.ThisExpr)

Example 4 with EvaluationContext

use of org.osate.aadl2.properties.EvaluationContext in project osate2 by osate.

the class PropertyImpl method evaluate.

public PropertyEvaluationResult evaluate(EvaluationContext ctx, int depth) {
    List<PropertyAssociation> pas = getPropertyValue(ctx).getAssociations();
    List<EvaluatedProperty> vals = new LinkedList<EvaluatedProperty>();
    for (PropertyAssociation pa : pas) {
        vals.add(pa.evaluate(ctx, depth));
        if (!pa.isAppend()) {
            break;
        }
    }
    /*
		 * NB. Do not fix Issue 2387 here! Doing so caused a different problem. Namely,
		 * if a property with a default value is explicit associated with a value in one place
		 * in the model, it's going to force model instantiation to create explicit property
		 * associations in the instance model that bind the default value to the property AT
		 * ALL OTHER PLACES THE PROPERTY IS APPLICABLE. This is undesirable.
		 */
    return new PropertyEvaluationResult(pas.isEmpty() ? null : pas.get(0), vals);
}
Also used : PropertyEvaluationResult(org.osate.aadl2.properties.PropertyEvaluationResult) PropertyAssociation(org.osate.aadl2.PropertyAssociation) EvaluatedProperty(org.osate.aadl2.properties.EvaluatedProperty) LinkedList(java.util.LinkedList)

Example 5 with EvaluationContext

use of org.osate.aadl2.properties.EvaluationContext in project osate2 by osate.

the class CachePropertyAssociationsSwitch method cachePropertyAssociations.

protected void cachePropertyAssociations(InstanceObject io) {
    try {
        for (Property property : propertyFilter) {
            if (io.acceptsProperty(property)) {
                /*
					 * Just look up the property. The property doesn't yet have a
					 * local association, so lookup will get the value from the
					 * declarative model. Property lookup process now corrects
					 * reference values to instance reference values.
					 */
                PropertyEvaluationResult result = property.evaluate(new EvaluationContext(io, classifierCache), 0);
                List<EvaluatedProperty> evaluated = result.getEvaluated();
                if (!evaluated.isEmpty()) {
                    // OsateDebug.osateDebug ("[CachePropertyAssociation] io=" + io + ";property=" + property + ";value=" + value);
                    PropertyAssociationInstance newPA = InstanceFactory.eINSTANCE.createPropertyAssociationInstance();
                    io.removePropertyAssociations(property);
                    newPA.setProperty(property);
                    newPA.setPropertyAssociation(getDeclarativePA(result.getPa()));
                    fillPropertyValue(io, newPA, evaluated);
                    if (!newPA.getOwnedValues().isEmpty()) {
                        io.getOwnedPropertyAssociations().add(newPA);
                    }
                }
            }
            checkIfCancelled();
            if (cancelled()) {
                break;
            }
        }
    } catch (IllegalStateException e) {
        // circular dependency
        // xxx: this is a misleading place to put the marker
        OsateDebug.osateDebug("IllegalStateException raised in cachePropertyAssociations");
        error(io, e.getMessage());
        return;
    } catch (InvalidModelException e) {
        OsateDebug.osateDebug("InvalidModelException raised in cachePropertyAssociations");
        error(e.getElement(), e.getMessage());
        return;
    }
}
Also used : InvalidModelException(org.osate.aadl2.properties.InvalidModelException) PropertyEvaluationResult(org.osate.aadl2.properties.PropertyEvaluationResult) PropertyAssociationInstance(org.osate.aadl2.instance.PropertyAssociationInstance) EvaluatedProperty(org.osate.aadl2.properties.EvaluatedProperty) EvaluationContext(org.osate.aadl2.properties.EvaluationContext) EvaluatedProperty(org.osate.aadl2.properties.EvaluatedProperty) Property(org.osate.aadl2.Property)

Aggregations

EvaluatedProperty (org.osate.aadl2.properties.EvaluatedProperty)8 InvalidModelException (org.osate.aadl2.properties.InvalidModelException)7 PropertyExpression (org.osate.aadl2.PropertyExpression)5 InstanceObject (org.osate.aadl2.instance.InstanceObject)4 NamedElement (org.osate.aadl2.NamedElement)3 Property (org.osate.aadl2.Property)3 EvaluationContext (org.osate.aadl2.properties.EvaluationContext)3 PropertyEvaluationResult (org.osate.aadl2.properties.PropertyEvaluationResult)3 EvaluationContext (com.rockwellcollins.atc.resolute.analysis.execution.EvaluationContext)2 ResoluteEvaluator (com.rockwellcollins.atc.resolute.analysis.execution.ResoluteEvaluator)2 ResoluteProver (com.rockwellcollins.atc.resolute.analysis.execution.ResoluteProver)2 ResoluteResult (com.rockwellcollins.atc.resolute.analysis.results.ResoluteResult)2 NamedElementValue (com.rockwellcollins.atc.resolute.analysis.values.NamedElementValue)2 FnCallExpr (com.rockwellcollins.atc.resolute.resolute.FnCallExpr)2 FunctionDefinition (com.rockwellcollins.atc.resolute.resolute.FunctionDefinition)2 ThisExpr (com.rockwellcollins.atc.resolute.resolute.ThisExpr)2 AadlPackage (org.osate.aadl2.AadlPackage)2 Classifier (org.osate.aadl2.Classifier)2 ListValue (org.osate.aadl2.ListValue)2 NumberValue (org.osate.aadl2.NumberValue)2