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;
}
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;
}
Aggregations