Skip to content

Commit

Permalink
#84 Use InvolvementHierarchyGraph rather than custom
Browse files Browse the repository at this point in the history
InvolvementHierarchyGraph2

Change-Id: Ib38b117ac8d7c1edc9b65aea4f1c38caa23c3df4
Signed-off-by: Philippe DUL <philippe.dul@thalesgroup.com>
  • Loading branch information
pdulth authored and arnauddieumegard committed Jun 16, 2022
1 parent a196946 commit 25a5228
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 182 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
import org.polarsys.capella.core.data.fa.SequenceLink;
import org.polarsys.capella.core.model.helpers.BlockArchitectureExt;
import org.polarsys.capella.core.model.helpers.FunctionalChainExt;
import org.polarsys.capella.core.model.helpers.graph.InvolvementHierarchyGraph;
import org.polarsys.capella.core.model.helpers.graph.InvolvementHierarchyGraph.Edge;
import org.polarsys.capella.core.model.helpers.graph.InvolvementHierarchyGraph.Element;
import org.polarsys.capella.core.model.helpers.graph.InvolvementHierarchyGraph.Vertex;
import org.polarsys.capella.core.transition.common.constants.ITransitionConstants;
import org.polarsys.capella.core.transition.common.handlers.IHandler;
import org.polarsys.capella.core.transition.common.handlers.contextscope.ContextScopeHandlerHelper;
Expand All @@ -49,8 +53,6 @@
import org.polarsys.capella.core.transition.common.handlers.scope.ScopeHandlerHelper;
import org.polarsys.capella.core.transition.common.handlers.transformation.TransformationHandlerHelper;
import org.polarsys.capella.transition.system2subsystem.constants.ISubSystemConstants;
import org.polarsys.capella.transition.system2subsystem.handlers.attachment.InvolvementHierarchyGraph2.Element;
import org.polarsys.capella.transition.system2subsystem.handlers.attachment.InvolvementHierarchyGraph2.Vertex;
import org.polarsys.capella.transition.system2subsystem.handlers.scope.ExternalFunctionsScopeRetriever;
import org.polarsys.kitalpha.transposer.rules.handler.rules.api.IContext;

Expand Down Expand Up @@ -78,19 +80,19 @@ public static FunctionalChainAttachmentHelper getInstance(IContext context_p) {
return handler;
}

public HashMap<FunctionalChain, InvolvementHierarchyGraph2> getGraphs(IContext context_p) {
HashMap<FunctionalChain, InvolvementHierarchyGraph2> graphs = (HashMap) context_p.get(GRAPH_MAPS);
public HashMap<FunctionalChain, InvolvementHierarchyGraph> getGraphs(IContext context_p) {
HashMap<FunctionalChain, InvolvementHierarchyGraph> graphs = (HashMap) context_p.get(GRAPH_MAPS);
if (graphs == null) {
graphs = new HashMap<FunctionalChain, InvolvementHierarchyGraph2>();
graphs = new HashMap<FunctionalChain, InvolvementHierarchyGraph>();
context_p.put(GRAPH_MAPS, graphs);
}
return graphs;
}

public InvolvementHierarchyGraph2 getGraph(FunctionalChain chain, IContext context_p) {
HashMap<FunctionalChain, InvolvementHierarchyGraph2> graphs = getGraphs(context_p);
public InvolvementHierarchyGraph getGraph(FunctionalChain chain, IContext context_p) {
HashMap<FunctionalChain, InvolvementHierarchyGraph> graphs = getGraphs(context_p);
if (!graphs.containsKey(chain)) {
graphs.put(chain, new InvolvementHierarchyGraph2(chain));
graphs.put(chain, new InvolvementHierarchyGraph(chain));
}
return graphs.get(chain);
}
Expand Down Expand Up @@ -304,7 +306,7 @@ public static Collection<LinkedList<FunctionalChainInvolvement>> toFCI(Collectio
* For a list of graph elements, we retrieve the FCI behinds.
*/
public static LinkedList<FunctionalChainInvolvement> toFCI(LinkedList<Element> elements) {
return elements.stream().map(d -> d.getElement()).collect(Collectors.toCollection(LinkedList::new));
return elements.stream().map(GraphHelper::getInvolvment).collect(Collectors.toCollection(LinkedList::new));
}

/**
Expand All @@ -319,11 +321,11 @@ public Collection<LinkedList<FunctionalChainInvolvement>> getNextPathsTowards(Fu
computeChains((FunctionalChain) fci.eContainer(), context);
// For all chains using this fci, we retrieve the paths towards the next valid fcis
Collection<LinkedList<FunctionalChainInvolvement>> allPaths = new ArrayList<LinkedList<FunctionalChainInvolvement>>();
for (InvolvementHierarchyGraph2 g : getGraphs(context).values()) {
for (Vertex v : g.getVertexs(fci)) { // (returns empty if the fci is not used) (we could have retrieve graphs of
for (InvolvementHierarchyGraph g : getGraphs(context).values()) {
for (Vertex v : GraphHelper.getVertices(g, fci)) { // (returns empty if the fci is not used) (we could have retrieve graphs of
// owning and all referencing chains)
allPaths.addAll(
toFCI(GraphHelper.getPathsTowards(v, n -> isTheOne(n, expected, context), context, n -> n.getNexts())));
toFCI(GraphHelper.getPathsTowards(v, n -> isTheOne(n, expected, context), context, GraphHelper::getNexts)));
}
}
return allPaths;
Expand All @@ -341,19 +343,20 @@ public Collection<LinkedList<FunctionalChainInvolvement>> getPreviousPathsToward
computeChains((FunctionalChain) fci.eContainer(), context);
// For all chains using this fci, we retrieve the paths towards the previous valid fcis
Collection<LinkedList<FunctionalChainInvolvement>> allPaths = new ArrayList<LinkedList<FunctionalChainInvolvement>>();
for (InvolvementHierarchyGraph2 g : getGraphs(context).values()) {
for (Vertex v : g.getVertexs(fci)) { // (returns empty if the fci is not used) (we could have retrieve graphs of
for (InvolvementHierarchyGraph g : getGraphs(context).values()) {
for (Vertex v : GraphHelper.getVertices(g, fci)) { // (returns empty if the fci is not used) (we could have retrieve graphs of
// owning and all referencing chains)
allPaths.addAll(
toFCI(GraphHelper.getPathsTowards(v, n -> isTheOne(n, expected, context), context, n -> n.getPrevious())));
toFCI(GraphHelper.getPathsTowards(v, n -> isTheOne(n, expected, context), context, GraphHelper::getPrevious)));
}
}
return allPaths;
}

public boolean isTheOne(Element current, FunctionalChainInvolvement expected, IContext context) {
return (expected == null && isValidElement(((Element) current).getElement(), context))
|| current.getElement().equals(expected);
FunctionalChainInvolvement element = GraphHelper.getInvolvment(current);
return (expected == null && isValidElement(element, context))
|| element.equals(expected);
}

public void merge(FunctionalChainInvolvementFunction tSrc, FunctionalChainInvolvementFunction tTgt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,18 @@
package org.polarsys.capella.transition.system2subsystem.handlers.attachment;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedList;
import java.util.function.Function;
import java.util.stream.Collectors;

import org.polarsys.capella.core.data.fa.FunctionalChainInvolvement;
import org.polarsys.capella.core.model.helpers.graph.InvolvementHierarchyGraph;
import org.polarsys.capella.core.model.helpers.graph.InvolvementHierarchyGraph.Edge;
import org.polarsys.capella.core.model.helpers.graph.InvolvementHierarchyGraph.Element;
import org.polarsys.capella.core.model.helpers.graph.InvolvementHierarchyGraph.Vertex;
import org.polarsys.capella.core.model.helpers.graph.InvolvementHierarchyGraph.VertexKey;
import org.polarsys.kitalpha.transposer.rules.handler.rules.api.IContext;

public class GraphHelper {
Expand Down Expand Up @@ -66,4 +74,32 @@ protected static <T> Collection<LinkedList<T>> getPathsTowards(T fci, Function<T
return result;
}


public static FunctionalChainInvolvement getInvolvment(Element e) {
if (e instanceof Edge) {
return ((Edge) e).getLink();
}
return ((Vertex) e).getFunction();
}

public static Collection<Element> getPrevious(Element e) {
if (e instanceof Edge) {
return Arrays.asList((Element)((Edge)e).getSource());
}
return (Collection)((Vertex)e).getIncomingEdges();
}

public static Collection<Element> getNexts(Element e) {
if (e instanceof Edge) {
return Arrays.asList((Element)((Edge)e).getTarget());
}
return (Collection)((Vertex)e).getOutgoingEdges();
}

public static Collection<Vertex> getVertices(InvolvementHierarchyGraph graph, FunctionalChainInvolvement fci) {
return (Collection) graph.getVertices().keySet().stream().filter(v -> ((VertexKey) v).getFunction() == fci)
.map(v -> graph.getVertices().get(v)).collect(Collectors.toList());
}


}

This file was deleted.

0 comments on commit 25a5228

Please sign in to comment.