diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DependencyModelingStage.java b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DependencyModelingStage.java index 5e1d44d..ee88089 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DependencyModelingStage.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DependencyModelingStage.java @@ -20,10 +20,8 @@ import models.dataConstraintModel.Channel; import models.dataConstraintModel.ResourcePath; import models.dataFlowModel.*; -import models.dependencyModel.DependencyGraph; -import models.dependencyModel.InterfaceNode; -import models.dependencyModel.mxInterfacePerimeter; -import models.dependencyModel.mxInterfaceShape; +import models.dependencyModel.*; +import simulator.states.State; import java.awt.event.MouseListener; import java.util.*; @@ -143,6 +141,9 @@ Map dependencyEventNodeCells = createEventChannelCells(); graph = insertDependencyEdges(dependencyResNodeCells, dependencyEventNodeCells); + + dependencyGraph.getEdges().forEach(e -> + System.out.println(e.getSource() + " -> " + e.getDestination())); } finally { graph.getModel().endUpdate(); } @@ -173,28 +174,35 @@ */ private mxCell cloneResourceCellHierarchy(mxCell oldCell, mxCell newParent, Map resNodeCells) { mxGeometry geo = (mxGeometry) oldCell.getGeometry().clone(); - double x = geo.getX(); - double y = geo.getY(); - double w = geo.getWidth(); - double h = geo.getHeight(); String label = (String) oldCell.getValue(); String newStyle = "shape=ellipse;perimeter=ellipsePerimeter;verticalAlign=top;opacity=" + 0; - mxCell newCell = (mxCell) graph.insertVertex(newParent,null, label, x, y, w, h, newStyle); + mxCell newCell = (mxCell) graph.insertVertex(newParent,null, label, + geo.getX(), geo.getY(), geo.getWidth(), geo.getHeight(), newStyle); - ResourceNode node = findResourceNodeByCell(oldCell); - if (node != null) { - resNodeCells.put(node, newCell); + + ResourceNode currentNode = findResourceNodeByCell(oldCell); + if (currentNode != null) { + resNodeCells.put(currentNode, newCell); } - // Recursively copy child cells int childCount = oldCell.getChildCount(); for (int i = 0; i < childCount; i++) { - mxCell oldChild = (mxCell) oldCell.getChildAt(i); - mxCell newChild = cloneResourceCellHierarchy(oldChild, newCell, resNodeCells); - InsertDependencyEdgeResourceCellHierarchy(newParent, newCell, newChild, i); + mxCell oldChild = (mxCell) oldCell.getChildAt(i); + mxCell newChild = cloneResourceCellHierarchy(oldChild, newCell, resNodeCells); + + ResourceNode parentNode = currentNode; + ResourceNode childNode = findResourceNodeByCell(oldChild); + + if (parentNode != null && childNode != null) { + + ObjectNode parentObj = new StatefulObjectNode(parentNode); + ObjectNode childObj = new StatefulObjectNode(childNode); + + addDependencyGraph(parentObj, childObj); + } } return newCell; @@ -213,32 +221,8 @@ return null; } - private void InsertDependencyEdgeResourceCellHierarchy(mxCell parentLayer, mxCell outerCell, mxCell innerCell, int index) { - mxGeometry gOuter = outerCell.getGeometry(); - mxGeometry gInner = innerCell.getGeometry(); - if (gOuter == null || gInner == null) return; - - String exitDir; - String entryDir; - - if (index == 0) { - exitDir = "exitX=0.7;exitY=0;"; - entryDir = "entryX=0.5;entryY=0;"; - } - else { - exitDir = "exitX=1;exitY=0;"; - entryDir = "entryX=1;entryY=0;"; - } - - mxCell edge = (mxCell) graph.insertEdge( - parentLayer, null, null, - outerCell, innerCell, - dependencyEdgeStyle + ";" + exitDir + entryDir - ); - - mxGeometry eGeo = new mxGeometry(); - eGeo.setRelative(true); - edge.setGeometry(eGeo); + private void addDependencyGraph(ObjectNode parentNode, ObjectNode childNode){ + dependencyGraph.addEdge(new DependencyEdge(parentNode, childNode)); } private Map createEventChannelCells() { @@ -320,60 +304,90 @@ return style.contains("ellipse") || style.contains("perimeter=ellipsePerimeter"); } - private mxGraph insertDependencyEdges(final Map resNodeCells, final Map eventChNodeCells) { - mxCell root = (mxCell) graph.getDefaultParent(); - mxCell layerCell = (mxCell) root.getChildAt(DEPENDENCY_LAYER); + private mxGraph insertDependencyEdges( + final Map resNodeCells, + final Map eventChNodeCells + ) { + mxCell root = (mxCell) graph.getDefaultParent(); + mxCell layerCell = (mxCell) root.getChildAt(DEPENDENCY_LAYER); - for (Edge callEdge : dependencyGraph.getEdges()) { - 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); + for (Edge callEdge : dependencyGraph.getEdges()) { + + Node srcNode = callEdge.getSource(); + Node dstNode = callEdge.getDestination(); + + mxCell srcCell = null; + mxCell dstCell = null; + + // Determine if the source is an EventChannel or a Resource + DataTransferChannel srcEvent = dependencyGraph.getEventChannelFromObjectNode(srcNode); + if (srcEvent != null) { + srcCell = eventChNodeCells.get(srcEvent); + } else { + ResourceNode srcRes = dependencyGraph.getResourceNodeFromObjectNode(srcNode); + if (srcRes != null) srcCell = resNodeCells.get(srcRes); + } + + // Determine if the destination is an EventChannel or a Resource + DataTransferChannel dstEvent = dependencyGraph.getEventChannelFromObjectNode(dstNode); + if (dstEvent != null) { + dstCell = eventChNodeCells.get(dstEvent); + } else { + ResourceNode dstRes = dependencyGraph.getResourceNodeFromObjectNode(dstNode); + if (dstRes != null) dstCell = resNodeCells.get(dstRes); + } + + // Skip if either side cannot be resolved to a cell + if (srcCell == null || dstCell == null) continue; + + + // Resource → Resource edges (for layout consistency) + boolean srcIsRes = dependencyGraph.getEventChannelFromObjectNode(srcNode) == null; + boolean dstIsRes = dependencyGraph.getEventChannelFromObjectNode(dstNode) == null; + + String style = dependencyEdgeStyle; + + if (srcIsRes && dstIsRes) { + // Compute child index to determine styling direction + int childIndex = getChildIndex(srcCell, dstCell); + + if (childIndex == 0) { + style += ";exitX=0.7;exitY=0;entryX=0.5;entryY=0;"; } else { - // Source is a resource - ResourceNode srcResNode = dependencyGraph.getResourceNodeFromObjectNode(srcNode); - if (srcResNode != null) { - srcCell = resNodeCells.get(srcResNode); - } - } - - // 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) { - graph.insertEdge(layerCell, null, null, srcCell, dstCell, dependencyEdgeStyle); + style += ";exitX=1;exitY=0;entryX=1;entryY=0;"; } } - 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; + graph.insertEdge(layerCell, null, null, srcCell, dstCell, style); } + // Insert reference edges (Resource → EventChannel) + for (Channel ch : model.getChannels()) { + DataTransferChannel channel = (DataTransferChannel) ch; + for (ResourcePath refRes : channel.getReferenceResources()) { + ResourceNode resNode = dependencyGraph.getDataFlowGraph().getResourceNode(refRes); + + graph.insertEdge( + layerCell, null, null, + resNodeCells.get(resNode), + eventChNodeCells.get(channel), + "strokeWidth=3;strokeColor=green;dashed=true;movable=false" + ); + } + } + + return graph; + } + + + private int getChildIndex(mxCell parent, mxCell child) { + int count = parent.getChildCount(); + for (int i = 0; i < count; i++) { + if (parent.getChildAt(i) == child) return i; + } + return -1; // 見つからない場合 + } + public boolean isValid() { if (model == null) { return false;