Skip to content

Commit

Permalink
#2699 Physical link cannot be created on PC Behavior or on LC inside (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mchoubby committed Aug 24, 2023
1 parent 7acb25d commit 5dfdd58
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2683,7 +2683,7 @@
<firstModelOperations xsi:type="tool:ChangeContext" browseExpression="aql:source.createABDelegation(sourceView,targetView)"/>
</initialOperation>
</tools>
<tools xsi:type="tool_1:EdgeCreationDescription" documentation="Creates a new Physical Link between the source and target Logicall Components or Actors." name="physical.link" label="%la.lab.physical.link" precondition="aql:preSourceView.target.isValidCreationPhysicalLink(preTargetView.target)" elementsToSelect="var:result" edgeMappings="//@ownedViewpoints[name='Logical%20Architecture']/@ownedRepresentations[name='Logical%20Architecture%20Blank']/@defaultLayer/@edgeMappings[name='LAB_PhysicalLink']" extraSourceMappings="//@ownedViewpoints[name='Logical%20Architecture']/@ownedRepresentations[name='Logical%20Architecture%20Blank']/@defaultLayer/@containerMappings[name='LAB%20Logical%20Component']" extraTargetMappings="//@ownedViewpoints[name='Logical%20Architecture']/@ownedRepresentations[name='Logical%20Architecture%20Blank']/@defaultLayer/@containerMappings[name='LAB%20Logical%20Component']">
<tools xsi:type="tool_1:EdgeCreationDescription" documentation="Creates a new Physical Link between the source and target Logicall Components or Actors." name="physical.link" label="%la.lab.physical.link" precondition="aql:preSourceView.target.isValidCreationPhysicalLink(preTargetView.target)" elementsToSelect="var:result" edgeMappings="//@ownedViewpoints[name='Logical%20Architecture']/@ownedRepresentations[name='Logical%20Architecture%20Blank']/@defaultLayer/@edgeMappings[name='LAB_PhysicalLink']" extraSourceMappings="//@ownedViewpoints[name='Logical%20Architecture']/@ownedRepresentations[name='Logical%20Architecture%20Blank']/@defaultLayer/@containerMappings[name='LAB%20Logical%20Component']" extraTargetMappings="//@ownedViewpoints[name='Logical%20Architecture']/@ownedRepresentations[name='Logical%20Architecture%20Blank']/@defaultLayer/@containerMappings[name='LAB%20Logical%20Component']" connectionStartPrecondition="aql:preSourceView.target.canBeInvolvedInPhysicalLink()">
<sourceVariable name="source"/>
<targetVariable name="target"/>
<sourceViewVariable name="sourceView"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2772,7 +2772,7 @@
</initialOperation>
</tools>
</ownedTools>
<ownedTools xsi:type="tool_1:EdgeCreationDescription" documentation="Creates a new Physical Link between the source and target Node Physical Components or Actors." name="physical.link" label="%pa.pab.physical.link" precondition="aql:self.isValidCreationABPhysicalLink(preSourceView,preTargetView)" elementsToSelect="var:result" edgeMappings="//@ownedViewpoints[name='Physical%20Architecture']/@ownedRepresentations[name='Physical%20Architecture%20Blank']/@defaultLayer/@edgeMappings[name='PAB_PhysicalLink']" extraSourceMappings="//@ownedViewpoints[name='Physical%20Architecture']/@ownedRepresentations[name='Physical%20Architecture%20Blank']/@defaultLayer/@containerMappings[name='PAB_PC'] //@ownedViewpoints[name='Physical%20Architecture']/@ownedRepresentations[name='Physical%20Architecture%20Blank']/@defaultLayer/@containerMappings[name='PAB_Deployment']" extraTargetMappings="//@ownedViewpoints[name='Physical%20Architecture']/@ownedRepresentations[name='Physical%20Architecture%20Blank']/@defaultLayer/@containerMappings[name='PAB_PC'] //@ownedViewpoints[name='Physical%20Architecture']/@ownedRepresentations[name='Physical%20Architecture%20Blank']/@defaultLayer/@containerMappings[name='PAB_Deployment']">
<ownedTools xsi:type="tool_1:EdgeCreationDescription" documentation="Creates a new Physical Link between the source and target Node Physical Components or Actors." name="physical.link" label="%pa.pab.physical.link" precondition="aql:self.isValidCreationABPhysicalLink(preSourceView,preTargetView)" elementsToSelect="var:result" edgeMappings="//@ownedViewpoints[name='Physical%20Architecture']/@ownedRepresentations[name='Physical%20Architecture%20Blank']/@defaultLayer/@edgeMappings[name='PAB_PhysicalLink']" extraSourceMappings="//@ownedViewpoints[name='Physical%20Architecture']/@ownedRepresentations[name='Physical%20Architecture%20Blank']/@defaultLayer/@containerMappings[name='PAB_PC'] //@ownedViewpoints[name='Physical%20Architecture']/@ownedRepresentations[name='Physical%20Architecture%20Blank']/@defaultLayer/@containerMappings[name='PAB_Deployment']" extraTargetMappings="//@ownedViewpoints[name='Physical%20Architecture']/@ownedRepresentations[name='Physical%20Architecture%20Blank']/@defaultLayer/@containerMappings[name='PAB_PC'] //@ownedViewpoints[name='Physical%20Architecture']/@ownedRepresentations[name='Physical%20Architecture%20Blank']/@defaultLayer/@containerMappings[name='PAB_Deployment']" connectionStartPrecondition="aql:self.isValidCreationPhysicalLink()">
<sourceVariable name="source"/>
<targetVariable name="target"/>
<sourceViewVariable name="sourceView"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2476,6 +2476,14 @@ public boolean isValidCreationPABDelegationExchange(EObject container, DSemantic
return (source != target) && isAbstractActorOrNotNodeComponent(source) && isAbstractActorOrNotNodeComponent(target);
}

/**
* Returns whether the source is valid for the creation of a physical link in the PAB diagram
*/
public boolean isValidCreationPhysicalLink(EObject container) {
EObject source = getComponentType(container);
return isNodeComponent(source);
}

/**
* Returns whether the source and target elements are both source/target for a physical link in the PAB diagram
*/
Expand Down Expand Up @@ -3238,31 +3246,27 @@ public Collection<CapellaElement> getComponentExchangeByGroupOrientedSemanticElt

Collection<CapellaElement> componentExchanges = getComponentExchangeByGroupSemantics(source, sourceView,
targetView);
Predicate<EObject> isPartSourceForCE = new Predicate<EObject>() {

@Override
public boolean apply(EObject eObj) {
if (eObj instanceof ComponentExchange) {
ComponentExchange ce = (ComponentExchange) eObj;
// TODO: check this
Part sourcePart = (Part) source;
Predicate<EObject> isPartSourceForCE = eObj -> {
if (eObj instanceof ComponentExchange) {
ComponentExchange ce = (ComponentExchange) eObj;
// TODO: check this
Part sourcePart = (Part) source;

ComponentPort cpSource = ComponentExchangeExt.getAttachingPort(sourcePart, ce);
ComponentPort cpTarget = (ComponentPort) ComponentExchangeExt.getOppositePort(ce, cpSource);
ComponentPort cpSource = ComponentExchangeExt.getAttachingPort(sourcePart, ce);
ComponentPort cpTarget = (ComponentPort) ComponentExchangeExt.getOppositePort(ce, cpSource);

if (!((cpTarget instanceof ComponentPort) && (cpSource instanceof ComponentPort))) {
return false;
}
if (!((cpTarget instanceof ComponentPort) && (cpSource instanceof ComponentPort))) {
return false;
}

if (PortExt.isInStrict(cpSource)) {
return false;
}
if (PortExt.isOutStrict(cpTarget)) {
return false;
}
if (PortExt.isInStrict(cpSource)) {
return false;
}
if (PortExt.isOutStrict(cpTarget)) {
return false;
}
return true;
}
return true;
};

return Lists.newArrayList(Iterables.filter(componentExchanges, isPartSourceForCE));
Expand Down Expand Up @@ -4460,9 +4464,7 @@ public Collection<? extends EObject> getComponentExchangeByDelegationSemantics(E
// retrains with related parts (for multipart mode)
Collection<EObject> a = new ArrayList<>();

Iterator<? extends EObject> it = target.iterator();
while (it.hasNext()) {
EObject ce = it.next();
for (EObject ce : target) {
if (ce instanceof ComponentExchange) {
ComponentExchange cee = (ComponentExchange) ce;
Part sourcePart = getSourcePart(cee);
Expand Down Expand Up @@ -4661,25 +4663,22 @@ public EObject getPhysicalLinkTarget(PhysicalLink connection) {
}

public Comparator<CapellaElement> getComparator() {
return new Comparator<CapellaElement>() {
@Override
public int compare(CapellaElement o1, CapellaElement o2) {
if ((o1 == null) && (o2 == null)) {
return 0;
} else if ((o1 == null) || (o1.getId() == null)) {
return -1;
} else if ((o2 == null) || (o2.getId() == null)) {
return 1;
}
if ((o1 instanceof AbstractNamedElement) && (o2 instanceof AbstractNamedElement)) {
AbstractNamedElement a1 = (AbstractNamedElement) o1;
AbstractNamedElement a2 = (AbstractNamedElement) o2;
if ((a1.getName() != null) && (a2.getName() != null)) {
return a1.getName().compareTo(a2.getName());
}
}
return o1.getId().compareTo(o2.getId());
}
return (o1, o2) -> {
if ((o1 == null) && (o2 == null)) {
return 0;
} else if ((o1 == null) || (o1.getId() == null)) {
return -1;
} else if ((o2 == null) || (o2.getId() == null)) {
return 1;
}
if ((o1 instanceof AbstractNamedElement) && (o2 instanceof AbstractNamedElement)) {
AbstractNamedElement a1 = (AbstractNamedElement) o1;
AbstractNamedElement a2 = (AbstractNamedElement) o2;
if ((a1.getName() != null) && (a2.getName() != null)) {
return a1.getName().compareTo(a2.getName());
}
}
return o1.getId().compareTo(o2.getId());
};
}

Expand Down Expand Up @@ -6192,7 +6191,7 @@ public List<EObject> targeFinderExpressionForConstraint(Constraint context) {
if (result.contains(object)) {
continue;
}
result.add(object);
result.add(object);

if (object instanceof PartDeploymentLink) {
PartDeploymentLink link = (PartDeploymentLink) object;
Expand Down Expand Up @@ -6790,17 +6789,13 @@ private boolean isValidComputedLink(EObject communication, Port sourcePort, Port
}

private boolean isInnerPort(AbstractDNode node, Port port) {
Iterator<DNode> ownedBorderedNodes = node.getOwnedBorderedNodes().iterator();
while (ownedBorderedNodes.hasNext()) {
DDiagramElement diagramElement = ownedBorderedNodes.next();
for (DDiagramElement diagramElement : node.getOwnedBorderedNodes()) {
if (diagramElement.getTarget() == port && diagramElement.isVisible()) {
return true;
}
}
if (node instanceof DNodeContainer) {
Iterator<DDiagramElement> ownedDiagramElements = ((DNodeContainer) node).getOwnedDiagramElements().iterator();
while (ownedDiagramElements.hasNext()) {
DDiagramElement next = ownedDiagramElements.next();
for (DDiagramElement next : ((DNodeContainer) node).getOwnedDiagramElements()) {
if (next instanceof AbstractDNode && isInnerPort((AbstractDNode) next, port)) {
return true;
}
Expand Down Expand Up @@ -6884,9 +6879,7 @@ private boolean isChildView(DDiagram diagram, Part mainPart, DeploymentTarget el

private void addRelevantParts(DDiagram diagram, Part mainPart, List<DeploymentTarget> toHandle) {
if (mainPart.eContainer() instanceof Component) {
Iterator<Part> parts = getCache(ComponentExt::getRepresentingParts, (Component) mainPart.eContainer()).iterator();
while (parts.hasNext()) {
Part parentPart = parts.next();
for (Part parentPart : getCache(ComponentExt::getRepresentingParts, (Component) mainPart.eContainer())) {
Collection<DSemanticDecorator> diagramElements = DiagramServices.getDiagramServices()
.getDiagramElements(diagram, parentPart);
int foundCount = 0;
Expand All @@ -6908,9 +6901,7 @@ private void addRelevantParts(DDiagram diagram, Part mainPart, List<DeploymentTa
}

private EObject getFirstVisibleAncestor(DDiagram diagram, Collection<Part> relevantParts) {
Iterator<Part> iterator = relevantParts.iterator();
while (iterator.hasNext()) {
Part part = iterator.next();
for (Part part : relevantParts) {
DDiagramElement diagramElement = DiagramServices.getDiagramServices().getDiagramElement(diagram, part);
if (diagramElement != null && diagramElement.isVisible()) {
return part;
Expand Down Expand Up @@ -6956,7 +6947,7 @@ else if (target instanceof FunctionalChainInvolvementFunction) {
public boolean isActor(EObject context) {
return ComponentExt.isActor(context);
}

public Object getConstraintLocation(EObject context, EObject target) {
if (null == context) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,10 @@ public void cannotCreatePhysicalLink(String idSource, String idTarget, String id
new CreateDEdgeTool(this, IToolNameConstants.TOOL_XAB_CREATE_PHYSICAL_LINK, idSource, idTarget, id).cannotRun();
}

public void creationPhysicalLinkFail(String idSource, String idTarget) {
new CreateDEdgeTool(this, IToolNameConstants.TOOL_XAB_CREATE_PHYSICAL_LINK, idSource, idTarget).shouldFail();
}

public String getToolNameReconnectPhysicalLink(BlockArchitectureExt.LinkDirection direction) {
String name = null;
if (direction == LinkDirection.SOURCE) {
Expand Down Expand Up @@ -581,7 +585,7 @@ public Collection<EObject> adaptTool(AbstractToolStep<?> tool, Map<String, Objec

// If tool show component in wizard but display parts in diagrams, or the opposite, we switch between them
EObject scopeElement = scope.iterator().next();
Collection<EObject> result = new ArrayList<EObject>();
Collection<EObject> result = new ArrayList<>();
for (EObject element : semanticElements) {
if ((element instanceof Part) && (scopeElement instanceof Component)) {
result.add(((Part) element).getAbstractType());
Expand Down Expand Up @@ -637,8 +641,7 @@ public void cannotReconnectFunctionalExchange(String id, String oldTargetId, Str
}

public PhysicalPath createPhysicalPath(final String path, final String... links) {
List<DSemanticDecorator> decorators = Arrays.stream(links).map(string -> getView(string))
.collect(Collectors.toList());
List<DSemanticDecorator> decorators = Arrays.stream(links).map(this::getView).collect(Collectors.toList());
List<EditPart> correspondingEditPart = decorators.stream()
.map(decorator -> DiagramServices.getDiagramServices().getEditPart((DDiagramElement) decorator))
.collect(Collectors.toList());
Expand Down Expand Up @@ -672,8 +675,7 @@ public void removePhysicalPath(String... path) {
}

public void createFunctionalChain(String path, String... links) {
List<DSemanticDecorator> decorators = Arrays.stream(links).map(string -> getView(string))
.collect(Collectors.toList());
List<DSemanticDecorator> decorators = Arrays.stream(links).map(this::getView).collect(Collectors.toList());
List<EditPart> correspondingEditPart = decorators.stream()
.map(decorator -> DiagramServices.getDiagramServices().getEditPart((DDiagramElement) decorator))
.collect(Collectors.toList());
Expand All @@ -692,7 +694,7 @@ protected IStructuredSelection getSelection() {
} catch (ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
putView(path, (DDiagramElement) result);
getSessionContext().putSemanticElement(path, ((DDiagramElement) result).getTarget());
}
Expand Down Expand Up @@ -817,7 +819,7 @@ public void deleteControlNodes(String... ids) {
}

public void deleteSequenceLinks(String... ids) {
List<DSemanticDecorator> decorators = Arrays.stream(ids).map(id -> getView(id)).collect(Collectors.toList());
List<DSemanticDecorator> decorators = Arrays.stream(ids).map(this::getView).collect(Collectors.toList());
DeleteHookHelper helper = new DeleteHookHelper(decorators);
assertTrue(helper.checkDeleteHook());
}
Expand Down
Loading

0 comments on commit 5dfdd58

Please sign in to comment.