diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DependencyModelingStage.java b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DependencyModelingStage.java index e6ce3d0..b55a78f 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DependencyModelingStage.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DependencyModelingStage.java @@ -13,6 +13,7 @@ import com.mxgraph.view.mxGraph; import generators.JavaCodeGenerator; import models.Edge; +import models.Node; import models.algebra.*; import models.controlFlowModel.*; import models.dataConstraintModel.Channel; @@ -68,7 +69,7 @@ ControlFlowGraph controlFlowGraph = ((ControlFlowDelegationStage) prevStage).getControlFlowGraph(); - dependencyFlowGraph = new DependencyFlowGraph(controlFlowGraph, model); + dependencyGraph = new DependencyGraph(controlFlowGraph, model); }*/ if (prevStage instanceof PushPullSelectionStage) { model = prevStage.getModel(); @@ -294,63 +295,63 @@ } private mxGraph insertDependencyEdges(final Map resNodeCells, final Map eventChNodeCells) { - mxCell root = (mxCell) graph.getDefaultParent(); - mxCell layerCell = (mxCell) root.getChildAt(DEPENDENCY_LAYER); + mxCell root = (mxCell) graph.getDefaultParent(); + mxCell layerCell = (mxCell) root.getChildAt(DEPENDENCY_LAYER); - for (Edge edge : dependencyGraph.getDataFlowGraph().getEdges()) { - DataFlowEdge dataFlowEdge = (DataFlowEdge) edge; - if (dataFlowEdge.isChannelToResource()) { - // output edge - DataTransferChannel channel = ((ChannelNode) dataFlowEdge.getSource()).getChannel(); - ResourcePath dstRes = ((ResourceNode) dataFlowEdge.getDestination()).getInSideResource(channel); - graph.insertEdge(layerCell, null, new Editor.SrcDstAttribute(channel, dstRes), eventChNodeCells.get(channel), resNodeCells.get((ResourceNode) dataFlowEdge.getDestination()), "strokeWidth=3;strokeColor=green;movable=false"); - } else { - // input edge - DataTransferChannel channel = ((ChannelNode) dataFlowEdge.getDestination()).getChannel(); - ResourcePath srcRes = ((ResourceNode) dataFlowEdge.getSource()).getOutSideResource(channel); - Set> toRes = getResourceDependencyForChannel(channel, dependencyGraph.getDataFlowGraph()); - for (Map.Entry RtoR : toRes) { - graph.insertEdge(layerCell, null, null, resNodeCells.get(RtoR.getValue()), resNodeCells.get(RtoR.getKey()), "strokeWidth=3;strokeColor=green;dashed=true;movable=false"); - } - graph.insertEdge(layerCell, null, new Editor.SrcDstAttribute(srcRes, channel), resNodeCells.get((ResourceNode) dataFlowEdge.getSource()), eventChNodeCells.get(channel), "strokeWidth=3;strokeColor=green;movable=false"); - } - } - - for (Channel ch : model.getChannels()) { - // reference edges - DataTransferChannel channel = (DataTransferChannel) ch; - for (ResourcePath refRes : channel.getReferenceResources()) { - graph.insertEdge(layerCell, null, null, resNodeCells.get(dependencyGraph.getDataFlowGraph().getResourceNode(refRes)), eventChNodeCells.get(channel), "strokeWidth=3;strokeColor=green;dashed=true;movable=false"); - } - } - - return graph; - } - - private Set> getResourceDependencyForChannel(DataTransferChannel ch, DataFlowGraph dataFlowGraph) { - Set> resourceDependency = new HashSet<>(); - if (!ch.getOutputChannelMembers().isEmpty()) { - try { - Map>> dependency = ch.fillOutsideResourcePaths(ch.getOutputChannelMembers().iterator().next(), JavaCodeGenerator.pullAccessor); - for (ChannelMember srcMem : dependency.keySet()) { - ResourceNode srcNode = dataFlowGraph.getResourceNode(srcMem.getResource()); - if (srcNode != null) { - for (ChannelMember dstMem : dependency.get(srcMem).getValue()) { - ResourceNode dstNode = dataFlowGraph.getResourceNode(dstMem.getResource()); - while (srcNode.getResourceHierarchy().getNumParameters() == 0 && srcNode.getParent() != null) { - srcNode = srcNode.getParent(); - } - resourceDependency.add(new AbstractMap.SimpleEntry<>(srcNode, dstNode)); - } + // DependencyGraphのエッジを使用(依存関係の視覚化) + for (CallEdge callEdge : dependencyGraph.getDependencyEdges()) { + Node srcNode = callEdge.getSource(); + Node dstNode = callEdge.getDestination(); + + mxCell srcCell = null; + mxCell dstCell = null; + + // Determine source cell (EventChannel or Resource) + DataTransferChannel srcEventChannel = dependencyGraph.getEventChannelFromObjectNode(srcNode); + if (srcEventChannel != null) { + // Source is an event channel + srcCell = eventChNodeCells.get(srcEventChannel); + } else { + // Source is a resource + ResourceNode srcResNode = dependencyGraph.getResourceNodeFromObjectNode(srcNode); + if (srcResNode != null) { + srcCell = resNodeCells.get(srcResNode); } } - } catch (ParameterizedIdentifierIsFutureWork | ResolvingMultipleDefinitionIsFutureWork | InvalidMessage | - UnificationFailed | ValueUndefined e) { - e.printStackTrace(); + + // Determine destination cell (EventChannel or Resource) + DataTransferChannel dstEventChannel = dependencyGraph.getEventChannelFromObjectNode(dstNode); + if (dstEventChannel != null) { + // Destination is an event channel + dstCell = eventChNodeCells.get(dstEventChannel); + } else { + // Destination is a resource + ResourceNode dstResNode = dependencyGraph.getResourceNodeFromObjectNode(dstNode); + if (dstResNode != null) { + dstCell = resNodeCells.get(dstResNode); + } + } + + // Insert edge if both cells are found + if (srcCell != null && dstCell != null) { + String style = "strokeWidth=3;strokeColor=green;movable=false"; + if (callEdge.getSelectedOption() == models.dataFlowModel.PushPullValue.PULL) { + style = "strokeWidth=3;strokeColor=green;dashed=true;movable=false"; + } + graph.insertEdge(layerCell, null, null, srcCell, dstCell, style); + } } + + for (Channel ch : model.getChannels()) { + // reference edges + DataTransferChannel channel = (DataTransferChannel) ch; + for (ResourcePath refRes : channel.getReferenceResources()) { + graph.insertEdge(layerCell, null, null, resNodeCells.get(dependencyGraph.getDataFlowGraph().getResourceNode(refRes)), eventChNodeCells.get(channel), "strokeWidth=3;strokeColor=green;dashed=true;movable=false"); + } + } + + return graph; } - return resourceDependency; - } public boolean isValid() { if (model == null) {