Search in sources :

Example 56 with ConnectionInstanceEnd

use of org.osate.aadl2.instance.ConnectionInstanceEnd in project osate2 by osate.

the class ShowConnectedElementsHandler method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final InternalDiagramEditor editor = getDiagramEditor(event);
    final List<BusinessObjectContext> selectedElements = AgeHandlerUtil.getSelectedBusinessObjectContexts().stream().filter(boc -> isSubcomponentOrConnectionEnd(boc)).collect(Collectors.toList());
    referenceService = Objects.requireNonNull(Adapters.adapt(editor, ProjectReferenceService.class), "Unable to retrieve reference service");
    final BusinessObjectTreeUpdater treeUpdater = editor.getBoTreeUpdater();
    final BusinessObjectNode boTree = getBoTree(editor, treeUpdater);
    for (final BusinessObjectContext selectedElement : selectedElements) {
        final BusinessObjectNode selectedNode = getSelectedNode(boTree, selectedElement);
        final Object selectedBo = selectedNode.getBusinessObject();
        if (selectedBo instanceof ConnectionEnd) {
            final SimpleEntry<Optional<ComponentClassifier>, BusinessObjectNode> classifierToConnectionEnd = getClassifierToConnectionEnd(selectedNode);
            final Optional<ComponentClassifier> compImplOpt = classifierToConnectionEnd.getKey();
            final BusinessObjectNode conEndNode = classifierToConnectionEnd.getValue();
            // Determine component implementation of selected node
            final BusinessObjectNode compNode = selectedBo instanceof Subcomponent && conEndNode == selectedNode ? selectedNode : conEndNode.getParent();
            // Internal Connections to Connection End
            compImplOpt.ifPresent(ci -> {
                if (ci instanceof ComponentImplementation) {
                    enableInternalConnections((ComponentImplementation) ci, conEndNode.getBusinessObject(), selectedBo, compNode);
                }
            });
            // Parent Connections to Connection End
            AadlClassifierUtil.getComponentImplementation(compNode.getParent()).ifPresent(ci -> {
                enableParentConnections(ci, conEndNode.getBusinessObject(), selectedBo, compNode);
            });
        }
        if (selectedBo instanceof Subcomponent) {
            final BusinessObjectNode parent = selectedNode.getParent();
            // Parent Connections to Subcomponent
            AadlClassifierUtil.getComponentImplementation(parent).ifPresent(compImpl -> enableComponentImplementationConnections(compImpl, parent, selectedNode));
            // Internal Connections to Subcomponent
            AadlClassifierUtil.getComponentImplementation(selectedBo).ifPresent(compImpl -> enableSelectedElementConnections(compImpl, selectedNode));
        } else if (selectedBo instanceof InstanceObject) {
            if (selectedBo instanceof ComponentInstance) {
                final ComponentInstance compInstance = (ComponentInstance) selectedBo;
                enableComponentInstanceConnections(compInstance, boTree);
            }
            if (selectedBo instanceof ConnectionInstanceEnd) {
                final InstanceObject selectedConnectionEnd = (InstanceObject) selectedBo;
                enableInstanceEndConnections(selectedConnectionEnd, boTree);
            }
        }
    }
    final AgeDiagram diagram = editor.getDiagram();
    final DiagramUpdater diagramUpdater = editor.getDiagramUpdater();
    final LayoutInfoProvider layoutInfoProvider = Objects.requireNonNull(Adapters.adapt(editor, LayoutInfoProvider.class), "Unable to retrieve layout info provider");
    // Update the diagram
    editor.getActionExecutor().execute("Show Connected Elements", ExecutionMode.NORMAL, () -> {
        // Update the diagram
        diagramUpdater.updateDiagram(diagram, boTree);
        // Update layout
        diagram.modify("Layout Incrementally", m -> DiagramElementLayoutUtil.layoutIncrementally(diagram, m, layoutInfoProvider));
        return null;
    });
    return null;
}
Also used : ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) DiagramToBusinessObjectTreeConverter(org.osate.ge.internal.diagram.runtime.updating.DiagramToBusinessObjectTreeConverter) Element(org.osate.aadl2.Element) ProjectReferenceService(org.osate.ge.internal.services.ProjectReferenceService) ComponentImplementation(org.osate.aadl2.ComponentImplementation) HashMap(java.util.HashMap) DiagramElementLayoutUtil(org.osate.ge.internal.diagram.runtime.layout.DiagramElementLayoutUtil) ConnectionInstanceEnd(org.osate.aadl2.instance.ConnectionInstanceEnd) BusinessObjectNode(org.osate.ge.internal.diagram.runtime.updating.BusinessObjectNode) ArrayList(java.util.ArrayList) HandlerUtil(org.eclipse.ui.handlers.HandlerUtil) ComponentClassifier(org.osate.aadl2.ComponentClassifier) InternalDiagramEditor(org.osate.ge.internal.ui.editor.InternalDiagramEditor) BusinessObjectContext(org.osate.ge.BusinessObjectContext) Map(java.util.Map) LinkedList(java.util.LinkedList) Subcomponent(org.osate.aadl2.Subcomponent) RelativeBusinessObjectReference(org.osate.ge.RelativeBusinessObjectReference) Completeness(org.osate.ge.internal.diagram.runtime.updating.Completeness) SimpleEntry(java.util.AbstractMap.SimpleEntry) IEditorPart(org.eclipse.ui.IEditorPart) ConnectionEnd(org.osate.aadl2.ConnectionEnd) BusinessObjectTreeUpdater(org.osate.ge.internal.diagram.runtime.updating.BusinessObjectTreeUpdater) Context(org.osate.aadl2.Context) DiagramUpdater(org.osate.ge.internal.diagram.runtime.updating.DiagramUpdater) AadlClassifierUtil(org.osate.ge.aadl2.internal.util.AadlClassifierUtil) Connection(org.osate.aadl2.Connection) UUID(java.util.UUID) ExecutionException(org.eclipse.core.commands.ExecutionException) Collectors(java.util.stream.Collectors) ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) Objects(java.util.Objects) Adapters(org.eclipse.core.runtime.Adapters) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) AbstractMap(java.util.AbstractMap) List(java.util.List) ConnectionReference(org.osate.aadl2.instance.ConnectionReference) Stream(java.util.stream.Stream) ExecutionMode(org.osate.ge.internal.services.ActionExecutor.ExecutionMode) AgeHandlerUtil(org.osate.ge.internal.ui.handlers.AgeHandlerUtil) Optional(java.util.Optional) Queue(java.util.Queue) AbstractHandler(org.eclipse.core.commands.AbstractHandler) LayoutInfoProvider(org.osate.ge.internal.diagram.runtime.layout.LayoutInfoProvider) Collections(java.util.Collections) ConnectedElement(org.osate.aadl2.ConnectedElement) InstanceObject(org.osate.aadl2.instance.InstanceObject) ComponentImplementation(org.osate.aadl2.ComponentImplementation) BusinessObjectTreeUpdater(org.osate.ge.internal.diagram.runtime.updating.BusinessObjectTreeUpdater) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Optional(java.util.Optional) ConnectionInstanceEnd(org.osate.aadl2.instance.ConnectionInstanceEnd) DiagramUpdater(org.osate.ge.internal.diagram.runtime.updating.DiagramUpdater) InternalDiagramEditor(org.osate.ge.internal.ui.editor.InternalDiagramEditor) BusinessObjectNode(org.osate.ge.internal.diagram.runtime.updating.BusinessObjectNode) InstanceObject(org.osate.aadl2.instance.InstanceObject) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) Subcomponent(org.osate.aadl2.Subcomponent) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) InstanceObject(org.osate.aadl2.instance.InstanceObject) ConnectionEnd(org.osate.aadl2.ConnectionEnd) BusinessObjectContext(org.osate.ge.BusinessObjectContext) LayoutInfoProvider(org.osate.ge.internal.diagram.runtime.layout.LayoutInfoProvider)

Example 57 with ConnectionInstanceEnd

use of org.osate.aadl2.instance.ConnectionInstanceEnd in project AGREE by loonwerks.

the class AgreeASTBuilder method getConnectionsFromInstances.

private List<AgreeAADLConnection> getConnectionsFromInstances(EList<ConnectionInstance> connectionInstances, ComponentInstance compInst, List<AgreeNode> subnodes, boolean latched) {
    List<AgreeAADLConnection> result = new ArrayList<>();
    for (ConnectionInstance connectionInstance : connectionInstances) {
        boolean isDelayed = isDelayed(connectionInstance, compInst);
        for (ConnectionReference connectionReference : connectionInstance.getConnectionReferences()) {
            ConnectionInstanceEnd sourceEndInstance = connectionReference.getSource();
            ConnectionInstanceEnd destinationEndInstance = connectionReference.getDestination();
            ComponentInstance sourceComponentInstance = sourceEndInstance.getComponentInstance();
            ComponentInstance destinationComponentInstance = destinationEndInstance.getComponentInstance();
            if (!compInst.equals(sourceComponentInstance) && !compInst.getComponentInstances().contains(sourceComponentInstance)) {
                // This connection reference connects to component instances not germane to this level of hierarchy
                continue;
            }
            if (!compInst.equals(destinationComponentInstance) && !compInst.getComponentInstances().contains(destinationComponentInstance)) {
                // This connection reference connects to component instances not germane to this level of hierarchy
                continue;
            }
            // make connections only to subcomponents that have annexes
            if (!compInst.equals(sourceComponentInstance) && compInst.getAllComponentInstances().contains(sourceComponentInstance)) {
                if (!AgreeUtils.containsTransitiveAgreeAnnex(sourceComponentInstance, isMonolithic)) {
                    continue;
                }
            }
            if (!compInst.equals(destinationComponentInstance) && compInst.getAllComponentInstances().contains(destinationComponentInstance)) {
                if (!AgreeUtils.containsTransitiveAgreeAnnex(destinationComponentInstance, isMonolithic)) {
                    continue;
                }
            }
            AgreeNode sourceNode = agreeNodeFromNamedEl(subnodes, sourceComponentInstance);
            AgreeNode destinationNode = agreeNodeFromNamedEl(subnodes, destinationComponentInstance);
            ConnectionEnd sourceConnectionEnd;
            if (sourceEndInstance instanceof FeatureInstance) {
                sourceConnectionEnd = ((FeatureInstance) sourceEndInstance).getFeature();
            } else {
                AgreeLogger.logWarning("unable to reason about connection '" + connectionInstance.getQualifiedName() + "' because it connects from a " + sourceEndInstance.getClass().getName());
                continue;
            }
            ConnectionEnd destinationConnectionEnd;
            if (destinationEndInstance instanceof FeatureInstance) {
                destinationConnectionEnd = ((FeatureInstance) destinationEndInstance).getFeature();
            } else {
                AgreeLogger.logWarning("unable to reason about connection '" + connectionInstance.getQualifiedName() + "' because it connects to a " + destinationEndInstance.getClass().getName());
                continue;
            }
            // TODO: Paranoia? Is this redundant with the previous lines?
            if (sourceConnectionEnd instanceof DataSubcomponent || destinationConnectionEnd instanceof DataSubcomponent) {
                AgreeLogger.logWarning("unable to reason about connection '" + connectionInstance.getQualifiedName() + "' because it connects to a data subcomponent");
                continue;
            }
            // Handle prefixing elements of feature groups
            String sourcePrefix = null;
            if (sourceConnectionEnd instanceof FeatureGroup) {
                sourcePrefix = sourceConnectionEnd.getName();
            }
            String destinationPrefix = null;
            if (destinationConnectionEnd instanceof FeatureGroup) {
                destinationPrefix = destinationConnectionEnd.getName();
            }
            List<AgreeVar> sourceVars = getAgreePortNames(sourceConnectionEnd, sourcePrefix, sourceNode == null ? null : sourceNode.compInst);
            List<AgreeVar> destinationVars = getAgreePortNames(destinationConnectionEnd, destinationPrefix, destinationNode == null ? null : destinationNode.compInst);
            if (sourceVars.size() != destinationVars.size()) {
                throw new AgreeException("The number of AGREE variables differ for connection '" + connectionInstance.getQualifiedName() + "'. Do the types of the source and destination differ? Perhaps one is an implementation and the other is a type?");
            }
            for (int i = 0; i < sourceVars.size(); i++) {
                AgreeVar sourceVar = sourceVars.get(i);
                AgreeVar destinationVar = destinationVars.get(i);
                if (!matches((ConnectionEnd) sourceVar.reference, (ConnectionEnd) destinationVar.reference)) {
                    AgreeLogger.logWarning("Connection '" + connectionInstance.getQualifiedName() + "' has ports '" + sourceVar.id.replace(dotChar, ".") + "' and '" + destinationVar.id.replace(dotChar, ".") + "' of differing type");
                    continue;
                }
                if (!sourceVar.type.equals(destinationVar.type)) {
                    throw new AgreeException("Type mismatch during connection generation");
                }
                ConnectionType connType;
                if (sourceVar.id.endsWith(eventSuffix)) {
                    connType = ConnectionType.EVENT;
                } else {
                    connType = ConnectionType.DATA;
                }
                AgreeAADLConnection agreeConnection = new AgreeAADLConnection(sourceNode, destinationNode, sourceVar, destinationVar, connType, latched, isDelayed, connectionReference.getConnection());
                result.add(agreeConnection);
            }
        }
    }
    return result;
}
Also used : ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) FeatureGroup(org.osate.aadl2.FeatureGroup) ConnectionType(com.rockwellcollins.atc.agree.analysis.ast.AgreeAADLConnection.ConnectionType) FeatureInstance(org.osate.aadl2.instance.FeatureInstance) ConnectionInstanceEnd(org.osate.aadl2.instance.ConnectionInstanceEnd) ArrayList(java.util.ArrayList) DataSubcomponent(org.osate.aadl2.DataSubcomponent) ConnectionReference(org.osate.aadl2.instance.ConnectionReference) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) ConnectionEnd(org.osate.aadl2.ConnectionEnd) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException)

Aggregations

ConnectionInstanceEnd (org.osate.aadl2.instance.ConnectionInstanceEnd)45 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)32 FeatureInstance (org.osate.aadl2.instance.FeatureInstance)30 ConnectionInstance (org.osate.aadl2.instance.ConnectionInstance)21 ConnectionReference (org.osate.aadl2.instance.ConnectionReference)16 ArrayList (java.util.ArrayList)11 Connection (org.osate.aadl2.Connection)8 BasicEList (org.eclipse.emf.common.util.BasicEList)7 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)7 Feature (org.osate.aadl2.Feature)7 InstanceObject (org.osate.aadl2.instance.InstanceObject)7 ConnectionEnd (org.osate.aadl2.ConnectionEnd)6 Subcomponent (org.osate.aadl2.Subcomponent)6 Element (org.osate.aadl2.Element)5 HashMap (java.util.HashMap)4 LinkedList (java.util.LinkedList)4 List (java.util.List)4 SystemInstance (org.osate.aadl2.instance.SystemInstance)4 InstantiatedClassifier (org.osate.aadl2.instance.util.InstanceUtil.InstantiatedClassifier)4 Collections (java.util.Collections)3