Search in sources :

Example 16 with Subcomponent

use of org.osate.aadl2.Subcomponent in project osate2 by osate.

the class CreateAadlConnectionPaletteCommand method buildCreateOperation.

public Operation buildCreateOperation(final BusinessObjectContext ownerBoc, final BusinessObjectContext srcBoc, final BusinessObjectContext dstBoc) {
    return Operation.createWithBuilder(createOp -> {
        // Create the subcomponent
        getClassifierOpBuilder().buildOperation(createOp, ownerBoc.getBusinessObject()).modifyPreviousResult(owner -> {
            // Create the appropriate type of connection object
            final org.osate.aadl2.Connection newAadlConnection = AadlConnectionUtil.createConnection(owner, connectionType);
            if (newAadlConnection == null) {
                return null;
            }
            // Reset the no connections flag
            owner.setNoConnections(false);
            // Set the source and destination
            final ConnectedElement src = getConnectedElementForBusinessObjectContext(srcBoc, connectionType, false, ownerBoc);
            newAadlConnection.setSource(src);
            final ConnectedElement dst = getConnectedElementForBusinessObjectContext(dstBoc, connectionType, !(src.getContext() instanceof Subcomponent), ownerBoc);
            newAadlConnection.setDestination(dst);
            // Determine the name for the new connection
            final String newConnectionName = AadlNamingUtil.buildUniqueIdentifier(owner, "new_connection");
            newAadlConnection.setName(newConnectionName);
            // Set type of access connection
            if (newAadlConnection instanceof AccessConnection) {
                final AccessConnection ac = (AccessConnection) newAadlConnection;
                if (src.getConnectionEnd() instanceof SubprogramAccess || dst.getConnectionEnd() instanceof SubprogramAccess) {
                    ac.setAccessCategory(AccessCategory.SUBPROGRAM);
                } else if (src.getConnectionEnd() instanceof SubprogramGroupAccess || dst.getConnectionEnd() instanceof SubprogramGroupAccess) {
                    ac.setAccessCategory(AccessCategory.SUBPROGRAM_GROUP);
                } else if (src.getConnectionEnd() instanceof BusAccess || dst.getConnectionEnd() instanceof BusAccess) {
                    ac.setAccessCategory(AccessCategory.BUS);
                } else if (src.getConnectionEnd() instanceof DataAccess || dst.getConnectionEnd() instanceof DataAccess) {
                    ac.setAccessCategory(AccessCategory.DATA);
                }
            }
            return StepResultBuilder.create().showNewBusinessObject(ownerBoc, newAadlConnection).build();
        });
    });
}
Also used : BusAccess(org.osate.aadl2.BusAccess) SubprogramAccess(org.osate.aadl2.SubprogramAccess) SubprogramSubcomponent(org.osate.aadl2.SubprogramSubcomponent) Subcomponent(org.osate.aadl2.Subcomponent) ConnectedElement(org.osate.aadl2.ConnectedElement) AccessConnection(org.osate.aadl2.AccessConnection) SubprogramGroupAccess(org.osate.aadl2.SubprogramGroupAccess) DataAccess(org.osate.aadl2.DataAccess)

Example 17 with Subcomponent

use of org.osate.aadl2.Subcomponent in project osate2 by osate.

the class CreateAadlConnectionPaletteCommand method getOwnerBoc.

private static BusinessObjectContext getOwnerBoc(final BusinessObjectContext srcBoc, final BusinessObjectContext dstBoc) {
    // Search for an appropriate owner. To be appropriate the owner BOC must be a component implementation or a subcomponent which is reachable from both
    // the source and destination BOC.
    int subcomponentsChecked1 = 0;
    BusinessObjectContext temp1 = srcBoc.getParent();
    while (temp1 != null) {
        final Object bo1 = temp1.getBusinessObject();
        if (bo1 instanceof Subcomponent || bo1 instanceof ComponentImplementation) {
            BusinessObjectContext temp2 = dstBoc.getParent();
            int subcomponentsChecked2 = 0;
            while (temp2 != null) {
                final Object bo2 = temp2.getBusinessObject();
                if (bo2 instanceof Subcomponent || bo2 instanceof ComponentImplementation) {
                    if (temp1 == temp2) {
                        return temp1;
                    }
                    if (bo2 instanceof Subcomponent) {
                        subcomponentsChecked2++;
                        // Stop checking at second subcomponent
                        if (subcomponentsChecked2 >= 2) {
                            break;
                        }
                    } else if (bo2 instanceof ComponentImplementation) {
                        // Stop checking at component implementations
                        break;
                    }
                }
                temp2 = temp2.getParent();
            }
            if (temp1.getBusinessObject() instanceof Subcomponent) {
                subcomponentsChecked1++;
                // Stop checking at second subcomponent
                if (subcomponentsChecked1 >= 2) {
                    break;
                }
            } else if (bo1 instanceof ComponentImplementation) {
                // Stop checking at component implementations
                break;
            }
        }
        temp1 = temp1.getParent();
    }
    return null;
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) SubprogramSubcomponent(org.osate.aadl2.SubprogramSubcomponent) Subcomponent(org.osate.aadl2.Subcomponent) BusinessObjectContext(org.osate.ge.BusinessObjectContext)

Example 18 with Subcomponent

use of org.osate.aadl2.Subcomponent 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 19 with Subcomponent

use of org.osate.aadl2.Subcomponent in project osate2 by osate.

the class DefaultSelectSubprogramDialogModel method getSubprograms.

@Override
public List<Object> getSubprograms(final Object context) {
    // Build a list of subprograms
    final List<Object> subprograms = new ArrayList<Object>();
    // Data/Subprogram Group/Abstract Type
    if (context instanceof IEObjectDescription) {
        final IEObjectDescription desc = (IEObjectDescription) context;
        final Classifier contextClassifier = (Classifier) (desc.getEObjectOrProxy().eIsProxy() ? (Classifier) EcoreUtil.resolve(desc.getEObjectOrProxy(), bi.eResource()) : desc.getEObjectOrProxy());
        if (!contextClassifier.eIsProxy()) {
            for (final Feature tmpFeature : contextClassifier.getAllFeatures()) {
                if (tmpFeature instanceof SubprogramAccess) {
                    // Provides Subprogram Access
                    if (((SubprogramAccess) tmpFeature).getKind() == AccessType.PROVIDES) {
                        subprograms.add(tmpFeature);
                    }
                }
            }
        }
    } else if (context instanceof SubprogramGroupAccess) {
        // Requires Subprogram Group Access
        // Only subprogram group accesses with kind = Requires and which has a subprogram group classifier should be in the context list
        // Provides Subprogram Access
        final SubprogramGroupClassifier spgClassifier = (SubprogramGroupClassifier) ((SubprogramGroupAccess) context).getAllClassifier();
        addProvidesSubprogramAccessesForComponentClassifier(spgClassifier, subprograms);
    } else if (context instanceof FeatureGroup) {
        // Feature Group
        final FeatureGroup fg = (FeatureGroup) context;
        // Requires subprogram Access if not inverse and Provides subprogram access if is inverse
        final boolean inverted = fg.isInverse();
        for (final Feature tmpFeature : AadlFeatureUtil.getAllFeatures(fg.getAllFeatureGroupType())) {
            if (tmpFeature instanceof SubprogramAccess) {
                final AccessType accessKind = ((SubprogramAccess) tmpFeature).getKind();
                if ((!inverted && accessKind == AccessType.REQUIRES) || (inverted && accessKind == AccessType.PROVIDES)) {
                    subprograms.add(tmpFeature);
                }
            }
        }
    } else if (context instanceof SubprogramGroupSubcomponent) {
        // Subprogram Group Subcomponent
        // Provides Subprogram
        addProvidesSubprogramAccessesForComponentClassifier(((SubprogramGroupSubcomponent) context).getAllClassifier(), subprograms);
    } else if (context == processorContext) {
        // Subprogram Proxy
        for (final ProcessorFeature processorFeature : AgeAadlUtil.getAllProcessorFeatures(bi)) {
            if (processorFeature instanceof SubprogramProxy) {
                subprograms.add(processorFeature);
            }
        }
    } else if (context == nullContext) {
        // Null Context
        // Subprogram classifier reference
        final Aadl2Package aadl2Package = Aadl2Package.eINSTANCE;
        for (final IEObjectDescription desc : AadlModelAccessUtil.getAllEObjectsByType(bi.eResource(), aadl2Package.getComponentClassifier())) {
            // Add objects that have care either types or implementations of the same category as the classifier type
            final EClass classifierEClass = desc.getEClass();
            if (aadl2Package.getSubprogramClassifier().isSuperTypeOf(classifierEClass)) {
                subprograms.add(desc);
            }
        }
        // Requires Subprogram Access
        for (final Feature tmpFeature : bi.getAllFeatures()) {
            if (tmpFeature instanceof SubprogramAccess && ((SubprogramAccess) tmpFeature).getKind() == AccessType.REQUIRES) {
                subprograms.add(tmpFeature);
            }
        }
        // Subprogram Subcomponent
        for (final Subcomponent tmpSc : bi.getAllSubcomponents()) {
            if (tmpSc instanceof SubprogramSubcomponent) {
                subprograms.add(tmpSc);
            }
        }
        // Subprogram Prototype
        for (final Prototype prototype : bi.getAllPrototypes()) {
            if (prototype instanceof SubprogramPrototype) {
                subprograms.add(prototype);
            }
        }
    }
    return Collections.unmodifiableList(subprograms);
}
Also used : FeatureGroup(org.osate.aadl2.FeatureGroup) SubprogramSubcomponent(org.osate.aadl2.SubprogramSubcomponent) SubprogramPrototype(org.osate.aadl2.SubprogramPrototype) Prototype(org.osate.aadl2.Prototype) SubprogramGroupClassifier(org.osate.aadl2.SubprogramGroupClassifier) ArrayList(java.util.ArrayList) SubprogramGroupSubcomponent(org.osate.aadl2.SubprogramGroupSubcomponent) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier) SubprogramGroupClassifier(org.osate.aadl2.SubprogramGroupClassifier) Feature(org.osate.aadl2.Feature) ProcessorFeature(org.osate.aadl2.ProcessorFeature) SubprogramGroupAccess(org.osate.aadl2.SubprogramGroupAccess) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) EClass(org.eclipse.emf.ecore.EClass) SubprogramProxy(org.osate.aadl2.SubprogramProxy) SubprogramAccess(org.osate.aadl2.SubprogramAccess) Aadl2Package(org.osate.aadl2.Aadl2Package) SubprogramSubcomponent(org.osate.aadl2.SubprogramSubcomponent) Subcomponent(org.osate.aadl2.Subcomponent) SubprogramGroupSubcomponent(org.osate.aadl2.SubprogramGroupSubcomponent) ProcessorFeature(org.osate.aadl2.ProcessorFeature) SubprogramPrototype(org.osate.aadl2.SubprogramPrototype) AccessType(org.osate.aadl2.AccessType)

Example 20 with Subcomponent

use of org.osate.aadl2.Subcomponent in project osate2 by osate.

the class OpenAssociatedDiagramHandler method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
    if (!(activeEditor instanceof InternalDiagramEditor)) {
        throw new RuntimeException("Unexpected editor: " + activeEditor);
    }
    // Get diagram and selected BOCs
    final List<BusinessObjectContext> selectedBusinessObjectContexts = AgeHandlerUtil.getSelectedBusinessObjectContexts();
    if (selectedBusinessObjectContexts.size() == 0) {
        throw new RuntimeException("No element selected");
    }
    final BusinessObjectContext selectedBusinessObjectContext = selectedBusinessObjectContexts.get(0);
    final Object bo = selectedBusinessObjectContext.getBusinessObject();
    final DiagramService diagramService = Objects.requireNonNull(Adapters.adapt(activeEditor, DiagramService.class), "Unable to retrieve diagram service");
    if (bo instanceof AadlPackage || bo instanceof Classifier) {
        diagramService.openOrCreateDiagramForBusinessObject(bo);
    } else if (bo instanceof Subcomponent) {
        final ComponentClassifier cc = AadlSubcomponentUtil.getComponentClassifier(selectedBusinessObjectContext, (Subcomponent) bo);
        if (cc != null) {
            diagramService.openOrCreateDiagramForBusinessObject(cc);
        }
    }
    return null;
}
Also used : InternalDiagramEditor(org.osate.ge.internal.ui.editor.InternalDiagramEditor) ComponentClassifier(org.osate.aadl2.ComponentClassifier) AadlPackage(org.osate.aadl2.AadlPackage) Subcomponent(org.osate.aadl2.Subcomponent) IEditorPart(org.eclipse.ui.IEditorPart) DiagramService(org.osate.ge.internal.services.DiagramService) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier) BusinessObjectContext(org.osate.ge.BusinessObjectContext)

Aggregations

Subcomponent (org.osate.aadl2.Subcomponent)118 ComponentClassifier (org.osate.aadl2.ComponentClassifier)53 Classifier (org.osate.aadl2.Classifier)46 ComponentImplementation (org.osate.aadl2.ComponentImplementation)40 NamedElement (org.osate.aadl2.NamedElement)40 Feature (org.osate.aadl2.Feature)37 DataSubcomponent (org.osate.aadl2.DataSubcomponent)33 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)33 ArrayList (java.util.ArrayList)31 EObject (org.eclipse.emf.ecore.EObject)25 Connection (org.osate.aadl2.Connection)24 FeatureGroup (org.osate.aadl2.FeatureGroup)21 SubprogramSubcomponent (org.osate.aadl2.SubprogramSubcomponent)21 Property (org.osate.aadl2.Property)20 FeatureInstance (org.osate.aadl2.instance.FeatureInstance)19 ContainmentPathElement (org.osate.aadl2.ContainmentPathElement)17 FeatureGroupType (org.osate.aadl2.FeatureGroupType)17 Element (org.osate.aadl2.Element)16 List (java.util.List)15 AadlPackage (org.osate.aadl2.AadlPackage)15