Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ This removes Rollup warnings about missing global names for externalized peer de
- [cleanup] Use only one border node description provider for all item border nodes.
- https://github.com/eclipse-syson/syson/issues/2452[#2352] [diagram] Decouple SysON tools from Sirius Web's DefaultToolsFactory: SysON now defines its own `DiagramDefaultToolsFactory` providing show/hide tools.
- https://github.com/eclipse-syson/syson/issues/2453[#2453] [diagrams] Add the Show/Hide section and associated tools to the group palette.
- https://github.com/eclipse-syson/syson/issues/2441[#2441] [services] Refactor `DiagramMutationElementService#createAllocateEdge` to extract semantic creation from diagram service.

=== New features

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -751,17 +751,12 @@ public IncludeUseCaseUsage createIncludeUseCaseUsage(UseCaseUsage source, UseCas
* the current editing context
* @param diagramService
* the current diagram service
* @return the given source element
* @return the created {@link AllocationUsage}
*/
public Element createAllocateEdge(Element source, Element target, Node sourceNode, IEditingContext editingContext, IDiagramService diagramService) {
var owner = source.getOwner();
var ownerMembership = SysmlFactory.eINSTANCE.createOwningMembership();
owner.getOwnedRelationship().add(ownerMembership);
var allocation = SysmlFactory.eINSTANCE.createAllocationUsage();
ownerMembership.getOwnedRelatedElement().add(allocation);
this.addEndToAllocateEdge(allocation, source);
this.addEndToAllocateEdge(allocation, target);
return source;
public AllocationUsage createAllocateEdge(Element source, Element target, Node sourceNode, IEditingContext editingContext, IDiagramService diagramService) {
var allocateEdge = this.metamodelMutationElementService.createAllocateEdge(source, target);
this.metamodelMutationElementService.initialize(allocateEdge);
return allocateEdge;
}

/**
Expand Down Expand Up @@ -838,18 +833,6 @@ public Element reconnectSourceAllocateEdge(AllocationUsage allocationUsage, Elem
return allocationUsage;
}

private void addEndToAllocateEdge(AllocationUsage edge, Element end) {
if (end instanceof Usage usage) {
var featureMembership = SysmlFactory.eINSTANCE.createEndFeatureMembership();
edge.getOwnedRelationship().add(featureMembership);
var feature = SysmlFactory.eINSTANCE.createFeature();
featureMembership.getOwnedRelatedElement().add(feature);
var reference = SysmlFactory.eINSTANCE.createReferenceSubsetting();
feature.getOwnedRelationship().add(reference);
reference.setReferencedFeature(usage);
}
}

/**
* Reconnects the target of an allocate edge.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.syson.sysml.AllocationUsage;
import org.eclipse.syson.sysml.BindingConnectorAsUsage;
import org.eclipse.syson.sysml.ConnectionUsage;
import org.eclipse.syson.sysml.Connector;
Expand Down Expand Up @@ -48,6 +49,7 @@
import org.eclipse.syson.sysml.SysmlFactory;
import org.eclipse.syson.sysml.SysmlPackage;
import org.eclipse.syson.sysml.Type;
import org.eclipse.syson.sysml.Usage;

/**
* Element-related services doing mutations. This class should not depend on sirius-web services or other spring
Expand Down Expand Up @@ -386,6 +388,36 @@ public Documentation createObjectiveDocumentation(Element element, String refere
return null;
}

/**
* Creates an allocate edge between the given source and target.
*
* @param source the source of the allocate edge
* @param target the target of the allocate edge
* @return the created {@link AllocationUsage}
*/
public AllocationUsage createAllocateEdge(Element source, Element target) {
var owner = source.getOwner();
var ownerMembership = SysmlFactory.eINSTANCE.createOwningMembership();
owner.getOwnedRelationship().add(ownerMembership);
var allocation = SysmlFactory.eINSTANCE.createAllocationUsage();
ownerMembership.getOwnedRelatedElement().add(allocation);
this.addEndToAllocateEdge(allocation, source);
this.addEndToAllocateEdge(allocation, target);
return allocation;
}

private void addEndToAllocateEdge(AllocationUsage edge, Element end) {
if (end instanceof Usage usage) {
var featureMembership = SysmlFactory.eINSTANCE.createEndFeatureMembership();
edge.getOwnedRelationship().add(featureMembership);
var feature = SysmlFactory.eINSTANCE.createFeature();
featureMembership.getOwnedRelatedElement().add(feature);
var reference = SysmlFactory.eINSTANCE.createReferenceSubsetting();
feature.getOwnedRelationship().add(reference);
reference.setReferencedFeature(usage);
}
}

private Feature addConnectorEnd(Connector connector, Feature end, Element endContainer, Element connectorContainer, FeatureDirectionKind defaultDirection) {
List<Feature> sourceFeaturePath = List.of();
// This code will not work to connect inherited non redefined feature.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.List;
import java.util.Objects;

import org.eclipse.syson.sysml.AllocationUsage;
import org.eclipse.syson.sysml.ConnectionUsage;
import org.eclipse.syson.sysml.Element;
import org.eclipse.syson.sysml.FeatureDirectionKind;
Expand All @@ -26,6 +27,7 @@
import org.eclipse.syson.sysml.MetadataUsage;
import org.eclipse.syson.sysml.OwningMembership;
import org.eclipse.syson.sysml.Package;
import org.eclipse.syson.sysml.PartUsage;
import org.eclipse.syson.sysml.ReferenceUsage;
import org.eclipse.syson.sysml.RequirementUsage;
import org.eclipse.syson.sysml.SysmlFactory;
Expand Down Expand Up @@ -188,6 +190,22 @@ public void createFlowUsageBetweenFeatureWithoutDirection() {
assertThat(targetFlow).isEqualTo(target);
}

@Test
@DisplayName("GIVEN two PartUsage, WHEN creating an allocate edge, then an AllocationUsage is created with the correct ends")
public void createAllocateEdge() {
Package parentPackage = SysmlFactory.eINSTANCE.createPackage();
PartUsage partUsage1 = SysmlFactory.eINSTANCE.createPartUsage();
this.mutationService.addChildInParent(parentPackage, partUsage1);
PartUsage partUsage2 = SysmlFactory.eINSTANCE.createPartUsage();
this.mutationService.addChildInParent(parentPackage, partUsage2);
AllocationUsage allocationUsage = this.mutationService.createAllocateEdge(partUsage1, partUsage2);
assertThat(allocationUsage).isNotNull();
assertThat(allocationUsage.getFeature())
.hasSize(2)
.anySatisfy(feature -> assertThat(feature.getOwnedReferenceSubsetting().getReferencedFeature()).isEqualTo(partUsage1))
.anySatisfy(feature -> assertThat(feature.getOwnedReferenceSubsetting().getReferencedFeature()).isEqualTo(partUsage2));
}

private RequirementUsage createRequirement(String name) {
RequirementUsage requirement = SysmlFactory.eINSTANCE.createRequirementUsage();
requirement.setDeclaredName(name);
Expand Down
Loading