Search in sources :

Example 26 with Feature

use of com.google.cloud.vision.v1p3beta1.Feature in project osate2 by osate.

the class InstantiateModel method instantiateFlowSpecs.

/**
 * same method but with different name exists in createEndToEndFlowSwitch.
 * It adds the flow instances on demand when ETEF is created
 * @param ci
 */
private void instantiateFlowSpecs(ComponentInstance ci) throws InterruptedException {
    for (FlowSpecification spec : getComponentType(ci).getAllFlowSpecifications()) {
        if (monitor.isCanceled()) {
            throw new InterruptedException();
        }
        FlowSpecificationInstance speci = ci.createFlowSpecification();
        speci.setName(spec.getName());
        speci.setFlowSpecification(spec);
        FlowEnd inend = spec.getAllInEnd();
        if (inend != null) {
            Feature srcfp = inend.getFeature();
            Context srcpg = inend.getContext();
            if (srcpg == null) {
                FeatureInstance fi = ci.findFeatureInstance(srcfp);
                if (fi != null) {
                    speci.setSource(fi);
                }
            } else if (srcpg instanceof FeatureGroup) {
                FeatureInstance pgi = ci.findFeatureInstance((FeatureGroup) srcpg);
                if (pgi != null) {
                    FeatureInstance fi = pgi.findFeatureInstance(srcfp);
                    if (fi != null) {
                        speci.setSource(fi);
                    }
                }
            }
        }
        FlowEnd outend = spec.getAllOutEnd();
        if (outend != null) {
            Feature dstfp = outend.getFeature();
            Context dstpg = outend.getContext();
            if (dstpg == null) {
                FeatureInstance fi = ci.findFeatureInstance(dstfp);
                if (fi != null) {
                    speci.setDestination(fi);
                }
            } else if (dstpg instanceof FeatureGroup) {
                FeatureInstance pgi = ci.findFeatureInstance((FeatureGroup) dstpg);
                if (pgi != null) {
                    FeatureInstance fi = pgi.findFeatureInstance(dstfp);
                    if (fi != null) {
                        speci.setDestination(fi);
                    }
                }
            }
        }
        for (Mode mode : spec.getAllInModes()) {
            if (monitor.isCanceled()) {
                throw new InterruptedException();
            }
            ModeInstance mi = ci.findModeInstance(mode);
            if (mi != null) {
                speci.getInModes().add(mi);
            }
        }
        for (ModeTransition mt : spec.getInModeTransitions()) {
            if (monitor.isCanceled()) {
                throw new InterruptedException();
            }
            ModeTransitionInstance ti = ci.findModeTransitionInstance(mt);
            if (ti != null) {
                speci.getInModeTransitions().add(ti);
            }
        }
    }
}
Also used : Context(org.osate.aadl2.Context) IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext) ModeInstance(org.osate.aadl2.instance.ModeInstance) FeatureGroup(org.osate.aadl2.FeatureGroup) FlowSpecification(org.osate.aadl2.FlowSpecification) FeatureInstance(org.osate.aadl2.instance.FeatureInstance) Mode(org.osate.aadl2.Mode) SystemOperationMode(org.osate.aadl2.instance.SystemOperationMode) ModeTransition(org.osate.aadl2.ModeTransition) ModeTransitionInstance(org.osate.aadl2.instance.ModeTransitionInstance) FlowSpecificationInstance(org.osate.aadl2.instance.FlowSpecificationInstance) Feature(org.osate.aadl2.Feature) DirectedFeature(org.osate.aadl2.DirectedFeature) FlowEnd(org.osate.aadl2.FlowEnd)

Example 27 with Feature

use of com.google.cloud.vision.v1p3beta1.Feature in project osate2 by osate.

the class InstantiateModel method instantiateFeatures.

/*
	 * Add feature instances to component instance
	 */
protected void instantiateFeatures(final ComponentInstance ci) throws InterruptedException {
    for (final Feature feature : getInstantiatedClassifier(ci).getClassifier().getAllFeatures()) {
        if (monitor.isCanceled()) {
            throw new InterruptedException();
        }
        final EList<ArrayDimension> dims = feature.getArrayDimensions();
        if (dims.isEmpty()) {
            fillFeatureInstance(ci, feature, false, 0);
        } else {
            // feature dimension should always be one
            class ArrayInstantiator {

                void process(int dim) {
                    ArraySize arraySize = dims.get(dim).getSize();
                    long count = getElementCount(arraySize, ci);
                    for (int i = 1; i <= count; i++) {
                        fillFeatureInstance(ci, feature, false, i);
                    }
                }
            }
            new ArrayInstantiator().process(0);
        }
    }
}
Also used : ArraySize(org.osate.aadl2.ArraySize) Feature(org.osate.aadl2.Feature) DirectedFeature(org.osate.aadl2.DirectedFeature) ArrayDimension(org.osate.aadl2.ArrayDimension)

Example 28 with Feature

use of com.google.cloud.vision.v1p3beta1.Feature in project osate2 by osate.

the class CacheContainedPropertyAssociationsSwitch method processContainedPropertyAssociations.

protected void processContainedPropertyAssociations(final FeatureInstance fi, final EList<PropertyAssociation> propertyAssociations) {
    for (PropertyAssociation pa : propertyAssociations) {
        Property prop = pa.getProperty();
        if (Aadl2Util.isNull(prop) || Aadl2Util.isNull(prop.getType())) {
            // PA is missing the prop def, skip to the next one
            continue;
        }
        for (ContainedNamedElement cne : pa.getAppliesTos()) {
            final EList<ContainmentPathElement> cpes = cne.getContainmentPathElements();
            if (cpes != null && !cpes.isEmpty()) {
                final Collection<FeatureInstance> ios = fi.findFeatureInstances(cpes);
                if (!ios.isEmpty()) {
                    for (InstanceObject io : ios) {
                        PropertyAssociationInstance newPA = InstanceFactory.eINSTANCE.createPropertyAssociationInstance();
                        newPA.setProperty(prop);
                        newPA.setPropertyAssociation(pa);
                        newPA.getOwnedValues().addAll(EcoreUtil.copyAll(pa.getOwnedValues()));
                        // replace reference values in the context of the contained PA's owner
                        for (Iterator<Element> content = EcoreUtil.getAllProperContents(newPA, false); content.hasNext(); ) {
                            Element elem = content.next();
                            if (elem instanceof ReferenceValue) {
                                PropertyExpression irv = ((ReferenceValue) elem).instantiate(fi);
                                if (irv != null) {
                                    EcoreUtil.replace(elem, irv);
                                }
                            }
                        }
                        final PropertyAssociation existingPA = io.getPropertyValue(prop, false).first();
                        if (existingPA != null && isConstant(existingPA)) {
                            /*
								 * Cannot put the error on the property association that is affected because it might
								 * be a declarative model element at this point. Need to report the error on the
								 * instance object itself.
								 */
                            final String classifierName = pa.getContainingClassifier().getQualifiedName();
                            final Element owner = pa.getOwner();
                            final String featureName = (owner instanceof Feature) ? ("." + ((Feature) owner).getName()) : "";
                            getErrorManager().error(io, "Property association for \"" + prop.getQualifiedName() + "\" is constant.  A contained property association in classifier \"" + classifierName + featureName + "\" tries to replace it.");
                        } else {
                            io.removePropertyAssociations(prop);
                            io.getOwnedPropertyAssociations().add(newPA);
                        }
                    }
                }
            }
        }
        checkIfCancelled();
        if (cancelled()) {
            break;
        }
    }
}
Also used : FeatureInstance(org.osate.aadl2.instance.FeatureInstance) PropertyAssociation(org.osate.aadl2.PropertyAssociation) ReferenceValue(org.osate.aadl2.ReferenceValue) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement) Element(org.osate.aadl2.Element) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) NamedElement(org.osate.aadl2.NamedElement) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement) Feature(org.osate.aadl2.Feature) InstanceObject(org.osate.aadl2.instance.InstanceObject) PropertyAssociationInstance(org.osate.aadl2.instance.PropertyAssociationInstance) PropertyExpression(org.osate.aadl2.PropertyExpression) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) Property(org.osate.aadl2.Property)

Example 29 with Feature

use of com.google.cloud.vision.v1p3beta1.Feature in project osate2 by osate.

the class CreateConnectionsSwitch method doModeTransitionConnections.

/**
 * As we are following connection declarations we need to check whether the
 * destination of the connection is named in one of the mode transitions of
 * the component instance that is the destination of the connection being
 * added
 *
 * @param parentci
 *            The component that is the context in which the connections are
 *            declared
 * @param pci
 *            PortConnectionInstance that is being created
 * @param conn
 *            connection being added to the ConnectionInstance
 * @return true if we created a ModetransitionInstance
 */
private boolean doModeTransitionConnections(final ComponentInstance parentci, ConnectionInfo connInfo, Connection conn) {
    boolean didTransition = false;
    if (!(conn instanceof PortConnection || conn instanceof FeatureGroupConnection)) {
        return false;
    }
    ComponentInstance parent = null;
    Context fc = conn.getAllDestinationContext();
    Element connContext = null;
    if (fc instanceof ComponentImplementation || fc instanceof FeatureGroup) {
        // we
        // have
        // an
        // outgoing
        // connection
        parent = (ComponentInstance) parentci.eContainer();
        connContext = parentci.getSubcomponent();
    } else if (fc instanceof Subcomponent) {
        parent = parentci.findSubcomponentInstance((Subcomponent) fc);
        connContext = ((Subcomponent) fc).getAllClassifier();
    }
    if (parent == null) {
        return false;
    }
    EList<ModeTransitionInstance> mtl = parent.getModeTransitionInstances();
    Feature f = (Feature) conn.getAllDestination();
    for (ModeTransitionInstance mti : mtl) {
        ModeTransition mt = mti.getModeTransition();
        Context co = null;
        for (ModeTransitionTrigger trigger : mt.getOwnedTriggers()) {
            TriggerPort tp = trigger.getTriggerPort();
            if (tp instanceof Port) {
                Port o = (Port) tp;
                co = trigger.getContext();
                NamedElement context = co;
                if (context instanceof FeatureGroup) {
                    context = parent.getSubcomponent().getAllClassifier();
                }
                if (f == o && context == connContext) {
                    final ConnectionInstance mtci = addConnectionInstance(parentci.getSystemInstance(), connInfo.convertToModeTransition(), mti);
                    fillInModes(mtci);
                    fillInModeTransitions(mtci);
                    didTransition = true;
                }
            } else {
            // TODO-LW: what if it's a processor port or internal event?
            }
        }
    }
    return didTransition;
}
Also used : Context(org.osate.aadl2.Context) ComponentImplementation(org.osate.aadl2.ComponentImplementation) ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) FeatureGroup(org.osate.aadl2.FeatureGroup) Element(org.osate.aadl2.Element) NamedElement(org.osate.aadl2.NamedElement) ConnectedElement(org.osate.aadl2.ConnectedElement) Port(org.osate.aadl2.Port) TriggerPort(org.osate.aadl2.TriggerPort) TriggerPort(org.osate.aadl2.TriggerPort) ModeTransition(org.osate.aadl2.ModeTransition) ModeTransitionInstance(org.osate.aadl2.instance.ModeTransitionInstance) InternalFeature(org.osate.aadl2.InternalFeature) ProcessorFeature(org.osate.aadl2.ProcessorFeature) Feature(org.osate.aadl2.Feature) PortConnection(org.osate.aadl2.PortConnection) FeatureGroupConnection(org.osate.aadl2.FeatureGroupConnection) SubprogramSubcomponent(org.osate.aadl2.SubprogramSubcomponent) DataSubcomponent(org.osate.aadl2.DataSubcomponent) Subcomponent(org.osate.aadl2.Subcomponent) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) NamedElement(org.osate.aadl2.NamedElement) ModeTransitionTrigger(org.osate.aadl2.ModeTransitionTrigger)

Example 30 with Feature

use of com.google.cloud.vision.v1p3beta1.Feature in project osate2 by osate.

the class CreateConnectionsSwitch method doModeTransitionConnections.

// ------------------------------------------------------------------------
// Methods related to mode transition connections
// ------------------------------------------------------------------------
/**
 * handles the situation that a mode transition may name an event port in a
 * thread (or other leaf component instance) and that port is not the
 * destination of a connection instance - it is the start of a connection
 * instance
 *
 * @param ci
 *            ComponentInstance
 * @param fi
 *            FeatureInstance
 * @return true if we created a ModetransitionInstance
 */
private boolean doModeTransitionConnections(ComponentInstance ci, FeatureInstance fi) {
    boolean didTransition = false;
    if (fi.getCategory() == FeatureCategory.EVENT_PORT) {
        Subcomponent sub = ci.getSubcomponent();
        Feature f = fi.getFeature();
        for (ModeTransitionInstance mti : ci.getContainingComponentInstance().getModeTransitionInstances()) {
            for (ModeTransitionTrigger trigger : mti.getModeTransition().getOwnedTriggers()) {
                TriggerPort tp = trigger.getTriggerPort();
                if (tp instanceof Port) {
                    Port p = (Port) tp;
                    Context c = trigger.getContext();
                    if (f == p && c == sub) {
                        addConnectionInstance(ci.getSystemInstance(), ConnectionInfo.newModeTransition(fi), mti);
                        didTransition = true;
                    }
                } else {
                // TODO-LW: what if it's a processor port or internal
                // event?
                }
            }
        }
    }
    return didTransition;
}
Also used : Context(org.osate.aadl2.Context) SubprogramSubcomponent(org.osate.aadl2.SubprogramSubcomponent) DataSubcomponent(org.osate.aadl2.DataSubcomponent) Subcomponent(org.osate.aadl2.Subcomponent) Port(org.osate.aadl2.Port) TriggerPort(org.osate.aadl2.TriggerPort) TriggerPort(org.osate.aadl2.TriggerPort) ModeTransitionInstance(org.osate.aadl2.instance.ModeTransitionInstance) InternalFeature(org.osate.aadl2.InternalFeature) ProcessorFeature(org.osate.aadl2.ProcessorFeature) Feature(org.osate.aadl2.Feature) ModeTransitionTrigger(org.osate.aadl2.ModeTransitionTrigger)

Aggregations

Feature (org.osate.aadl2.Feature)86 ArrayList (java.util.ArrayList)82 Feature (com.google.cloud.vision.v1.Feature)74 AnnotateImageRequest (com.google.cloud.vision.v1.AnnotateImageRequest)71 Image (com.google.cloud.vision.v1.Image)71 BatchAnnotateImagesResponse (com.google.cloud.vision.v1.BatchAnnotateImagesResponse)68 ImageAnnotatorClient (com.google.cloud.vision.v1.ImageAnnotatorClient)68 AnnotateImageResponse (com.google.cloud.vision.v1.AnnotateImageResponse)65 ByteString (com.google.protobuf.ByteString)48 ImageSource (com.google.cloud.vision.v1.ImageSource)39 Subcomponent (org.osate.aadl2.Subcomponent)31 FileInputStream (java.io.FileInputStream)30 Classifier (org.osate.aadl2.Classifier)29 EntityAnnotation (com.google.cloud.vision.v1.EntityAnnotation)28 WebImage (com.google.cloud.vision.v1.WebDetection.WebImage)26 NamedElement (org.osate.aadl2.NamedElement)24 ComponentClassifier (org.osate.aadl2.ComponentClassifier)22 FeatureGroup (org.osate.aadl2.FeatureGroup)20 FeatureGroupType (org.osate.aadl2.FeatureGroupType)19 FeatureInstance (org.osate.aadl2.instance.FeatureInstance)19