diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowModelingStage.java b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowModelingStage.java index ed2e6ef..82376c9 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowModelingStage.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowModelingStage.java @@ -576,8 +576,19 @@ mxCell root = (mxCell) graph.getDefaultParent(); mxCell layerCell = (mxCell) root.getChildAt(layer); final Map resourceNodeCells = new HashMap<>(); - + + CallGraph callGraph = null; + if (layer == PUSH_FLOW_LAYER) { + callGraph = controlFlowGraph.getPushCallGraph(); + } else if (layer == PULL_FLOW_LAYER) { + callGraph = controlFlowGraph.getPullCallGraph(); + } + for (ResourceNode rootNode : controlFlowGraph.getDataFlowGraph().getRootResourceNodes()) { + if (callGraph != null && !isResourceOrDescendantsInCallGraph(rootNode, callGraph)) { + continue; + } + ResourcePath rootResourcePath = rootNode.getPrimaryResourcePath(); int width = 320; int height = 160; @@ -585,7 +596,7 @@ mxCell insertedCell = (mxCell) graph.insertVertex(layerCell, null, rootResourcePath.getLeafResourceName(), 20, 20, width, height, "shape=ellipse;perimeter=ellipsePerimeter;verticalAlign=top"); // insert a resource as a vertex resourceNodeCells.put(rootNode, insertedCell); - createChildResourceNodeCell(graph, insertedCell, rootNode, resourceNodeCells, width / 2, height / 2); + createChildResourceNodeCell(graph, insertedCell, rootNode, resourceNodeCells, width / 2, height / 2, callGraph); } return resourceNodeCells; } @@ -597,9 +608,14 @@ * @param parentCell Parent cell of the new cell. * @param parentNode {@link ResourceNode} instance to be registered. * @param resourceNodeCells The map of {@link ResourceNode} and its corresponding cell. + * @param callGraph The call graph to check for node existence. */ - private void createChildResourceNodeCell(final mxGraph graph, final mxCell parentCell, final ResourceNode parentNode, final Map resourceNodeCells, int width, int height) { + private void createChildResourceNodeCell(final mxGraph graph, final mxCell parentCell, final ResourceNode parentNode, final Map resourceNodeCells, int width, int height, final CallGraph callGraph) { for (ResourceNode childNode : parentNode.getChildren()) { + if (callGraph != null && !isResourceOrDescendantsInCallGraph(childNode, callGraph)) { + continue; + } + ResourcePath resourcePath = childNode.getPrimaryResourcePath(); mxGeometry parentGeo = parentCell.getGeometry(); @@ -613,9 +629,24 @@ mxCell insertedCell = (mxCell) graph.insertVertex(parentCell, null, resourcePath.getName(), x, y, width, height, "shape=ellipse;perimeter=ellipsePerimeter;verticalAlign=top"); // insert a resource as a vertex resourceNodeCells.put(childNode, insertedCell); - createChildResourceNodeCell(graph, insertedCell, childNode, resourceNodeCells, width / 2, height / 2); + createChildResourceNodeCell(graph, insertedCell, childNode, resourceNodeCells, width / 2, height / 2, callGraph); } } + + /** + * Check if the resource node or any of its descendants are in the call graph. + * + * @param node The resource node to check. + * @param callGraph The call graph. + * @return true if the node or any descendant is in the call graph. + */ + private boolean isResourceOrDescendantsInCallGraph(ResourceNode node, CallGraph callGraph) { + if (callGraph.getStatefulObjectNode(node) != null) return true; + for (ResourceNode child : node.getChildren()) { + if (isResourceOrDescendantsInCallGraph(child, callGraph)) return true; + } + return false; + } /** * Create and register a new graph cell for event channel nodes.