Search in sources :

Example 1 with MpvProxy

use of org.osate.aadl2.properties.EvaluatedProperty.MpvProxy in project osate2 by osate.

the class PropertiesValidator method checkInRange.

private void checkInRange(NumberType type, NumberValue value) {
    NumericRange range = type.getRange();
    if (range != null) {
        PropertyExpression lowerExpression;
        try {
            MpvProxy modalProxy = range.getLowerBound().evaluate(null, 0).first();
            lowerExpression = modalProxy == null ? null : modalProxy.getValue();
        } catch (InvalidModelException e) {
            lowerExpression = null;
        }
        PropertyExpression upperExpression;
        try {
            MpvProxy modalProxy = range.getUpperBound().evaluate(null, 0).first();
            upperExpression = modalProxy == null ? null : modalProxy.getValue();
        } catch (InvalidModelException e) {
            upperExpression = null;
        }
        if (lowerExpression instanceof NumberValue && upperExpression instanceof NumberValue) {
            NumberValue lower = (NumberValue) lowerExpression;
            NumberValue upper = (NumberValue) upperExpression;
            double valueScaled = value.getScaledValue();
            if (valueScaled < lower.getScaledValue() || valueScaled > upper.getScaledValue()) {
                error(value, "Value must be between " + lower + " and " + upper);
            }
        }
    }
}
Also used : NumericRange(org.osate.aadl2.NumericRange) InvalidModelException(org.osate.aadl2.properties.InvalidModelException) NumberValue(org.osate.aadl2.NumberValue) MpvProxy(org.osate.aadl2.properties.EvaluatedProperty.MpvProxy) PropertyExpression(org.osate.aadl2.PropertyExpression)

Example 2 with MpvProxy

use of org.osate.aadl2.properties.EvaluatedProperty.MpvProxy in project osate2 by osate.

the class CachePropertyAssociationsSwitch method fillPropertyValue.

private void fillPropertyValue(InstanceObject io, PropertyAssociation pa, List<EvaluatedProperty> values) {
    PropertyExpression lexp;
    List<PropertyExpression> elems;
    final Iterator<EvaluatedProperty> valueIter = values.iterator();
    final EvaluatedProperty value = valueIter.next();
    final List<MpvProxy> proxies = value.getProxies();
    for (MpvProxy proxy : proxies) {
        ModalPropertyValue newVal = Aadl2Factory.eINSTANCE.createModalPropertyValue();
        List<SystemOperationMode> inSOMs = new ArrayList<SystemOperationMode>();
        newVal.setOwnedValue(EcoreUtil.copy(proxy.getValue()));
        // process list appends
        while (valueIter.hasNext()) {
            MpvProxy prx = valueIter.next().getProxies().get(0);
            if (prx.isModal()) {
                throw new InvalidModelException(pa, "Trying to append to a modal list value");
            }
            lexp = EcoreUtil.copy(prx.getValue());
            elems = ((ListValue) lexp).getOwnedListElements();
            ((ListValue) newVal.getOwnedValue()).getOwnedListElements().addAll(0, elems);
        }
        boolean valueIsUsed = false;
        if (!proxy.isModal()) {
            valueIsUsed = true;
            pa.getOwnedValues().add(newVal);
        } else {
            List<Mode> modes = proxy.getModes();
            for (Mode mode : modes) {
                if (mode instanceof SystemOperationMode) {
                    inSOMs.add((SystemOperationMode) mode);
                } else {
                    if (io instanceof ConnectionReference) {
                        List<SystemOperationMode> conniModes = ((ConnectionInstance) io.eContainer()).getInSystemOperationModes();
                        if (conniModes.isEmpty()) {
                            conniModes = io.getSystemInstance().getSystemOperationModes();
                        }
                        List<ModeInstance> holderModes = ((ConnectionReference) io).getContext().getModeInstances();
                        for (ModeInstance mi : holderModes) {
                            if (mi.getMode() == mode) {
                                for (SystemOperationMode som : conniModes) {
                                    if (som.getCurrentModes().contains(mi)) {
                                        inSOMs.add(som);
                                    }
                                }
                                break;
                            }
                        }
                    } else {
                        List<ModeInstance> holderModes = (io instanceof ComponentInstance) ? ((ComponentInstance) io).getModeInstances() : io.getContainingComponentInstance().getModeInstances();
                        for (ModeInstance mi : holderModes) {
                            if (mi.getMode() == mode) {
                                if (mode2som.containsKey(mi)) {
                                    inSOMs.addAll(mode2som.get(mi));
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            for (SystemOperationMode som : inSOMs) {
                if (io.isActive(som)) {
                    newVal.getInModes().add(som);
                }
            }
            if (!newVal.getInModes().isEmpty()) {
                valueIsUsed = true;
                pa.getOwnedValues().add(newVal);
            }
        }
        if (valueIsUsed) {
            // replace reference values in the context of the contained PA's owner
            for (Iterator<Element> content = EcoreUtil.getAllProperContents(newVal, false); content.hasNext(); ) {
                Element elem = content.next();
                if (elem instanceof ReferenceValue) {
                    try {
                        PropertyExpression irv = ((ReferenceValue) elem).instantiate(io);
                        if (irv != null) {
                            EcoreUtil.replace(elem, irv);
                        }
                    } catch (InvalidModelException e) {
                        error(io, e.getMessage());
                    }
                }
            }
        }
    }
}
Also used : ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) ModeInstance(org.osate.aadl2.instance.ModeInstance) ModalPropertyValue(org.osate.aadl2.ModalPropertyValue) ReferenceValue(org.osate.aadl2.ReferenceValue) Mode(org.osate.aadl2.Mode) SystemOperationMode(org.osate.aadl2.instance.SystemOperationMode) Element(org.osate.aadl2.Element) ArrayList(java.util.ArrayList) EvaluatedProperty(org.osate.aadl2.properties.EvaluatedProperty) SystemOperationMode(org.osate.aadl2.instance.SystemOperationMode) InvalidModelException(org.osate.aadl2.properties.InvalidModelException) MpvProxy(org.osate.aadl2.properties.EvaluatedProperty.MpvProxy) ConnectionReference(org.osate.aadl2.instance.ConnectionReference) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) PropertyExpression(org.osate.aadl2.PropertyExpression)

Aggregations

PropertyExpression (org.osate.aadl2.PropertyExpression)2 MpvProxy (org.osate.aadl2.properties.EvaluatedProperty.MpvProxy)2 InvalidModelException (org.osate.aadl2.properties.InvalidModelException)2 ArrayList (java.util.ArrayList)1 Element (org.osate.aadl2.Element)1 ModalPropertyValue (org.osate.aadl2.ModalPropertyValue)1 Mode (org.osate.aadl2.Mode)1 NumberValue (org.osate.aadl2.NumberValue)1 NumericRange (org.osate.aadl2.NumericRange)1 ReferenceValue (org.osate.aadl2.ReferenceValue)1 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)1 ConnectionInstance (org.osate.aadl2.instance.ConnectionInstance)1 ConnectionReference (org.osate.aadl2.instance.ConnectionReference)1 ModeInstance (org.osate.aadl2.instance.ModeInstance)1 SystemOperationMode (org.osate.aadl2.instance.SystemOperationMode)1 EvaluatedProperty (org.osate.aadl2.properties.EvaluatedProperty)1