diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowModelingStage.java b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowModelingStage.java index 1ff1884..2b87cfd 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowModelingStage.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowModelingStage.java @@ -15,7 +15,6 @@ import models.Node; import models.controlFlowModel.*; import models.dataConstraintModel.ResourcePath; -import models.dataFlowModel.ChannelNode; import models.dataFlowModel.DataFlowGraph; import models.dataFlowModel.DataTransferChannel; import models.dataFlowModel.ResourceNode; @@ -191,7 +190,7 @@ mxCell insertedCell = (mxCell) graph.insertVertex(layerCell, null, name, 20, 20, width, height, style); // insert a resource as a vertex resourceNodeCells.put(resourceNode, insertedCell); - createChildResourceNodeCell(graph, insertedCell, resourceNode, resourceNodeCells, (int) (width * getScale(resourceNode.getChildren().size())), (int) (height * getScale(resourceNode.getChildren().size())), callGraph); + createChildResourceNodeCell(graph, insertedCell, resourceNode, resourceNodeCells, (int) (width * getScale(resourceNode.getChildren().size())), (int) (height * getScale(resourceNode.getChildren().size()))); } return resourceNodeCells; } @@ -244,9 +243,8 @@ * @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, final CallGraph callGraph) { + private void createChildResourceNodeCell(final mxGraph graph, final mxCell parentCell, final ResourceNode parentNode, final Map resourceNodeCells, int width, int height) { int i = 0; int n = parentNode.getChildren().size(); for (ResourceNode childNode : parentNode.getChildren()) { @@ -276,7 +274,7 @@ mxCell insertedCell = (mxCell) graph.insertVertex(parentCell, null, name, x, y, width, height, style); // insert a resource as a vertex resourceNodeCells.put(childNode, insertedCell); - createChildResourceNodeCell(graph, insertedCell, childNode, resourceNodeCells, (int) (width * getScale(childNode.getChildren().size())), (int) (height * getScale(childNode.getChildren().size())), callGraph); + createChildResourceNodeCell(graph, insertedCell, childNode, resourceNodeCells, (int) (width * getScale(childNode.getChildren().size())), (int) (height * getScale(childNode.getChildren().size()))); i++; } } @@ -308,7 +306,6 @@ continue; } final EventChannelObjectNode rootEventChannelNode = (EventChannelObjectNode) rootNode; - createEventChannelNodeCell(graph, layerCell, rootEventChannelNode, eventChannelNodeCells, outputEventChannelNodeCells, MIN_EVENT_CHANNEL_NODE_WIDTH, MIN_EVENT_CHANNEL_NODE_HEIGHT); } return eventChannelNodeCells; @@ -319,9 +316,9 @@ * * @param graph {@link mxGraph} instance to be modified. * @param parentCell Parent cell of the new cell. - * @param eventChannelNode {@link ChannelNode} instance to be registered. - * @param eventChannelNodeCells {@link ChannelNode} and its corresponding cell. - * @param outputEventChannelNodeCells {@link ChannelNode} and its corresponding output port cell. + * @param eventChannelNode {@link EventChannelObjectNode} instance to be registered. + * @param eventChannelNodeCells {@link EventChannelObjectNode} and its corresponding cell. + * @param outputEventChannelNodeCells {@link EventChannelObjectNode} and its corresponding output port cell. * @param cellWidth The width of a new cell. * @param cellHeight The height of a new cell. */ @@ -371,46 +368,47 @@ if (!(edge instanceof CallEdge)) { continue; } + CallEdge callEdge = (CallEdge) edge; + if (callEdge.getSource() == null || callEdge.getDestination() == null) { // Skip if the edge is not placed between 2 cells + continue; + } + if (!(callEdge.getSource() instanceof StatefulObjectNode) && !(callEdge.getSource() instanceof EventChannelObjectNode)) { // The source object of the edge isn't valid. + continue; + } - // エッジがノードと接続しているか? - if (callEdge.getSource() == null || callEdge.getDestination() == null) continue; - - Node srcResNode = null; - ResourceNode dstResNode = ((StatefulObjectNode) callEdge.getDestination()).getResource(); - - mxCell srcNodeCell = null; - mxCell srcOutPortCell = null; - mxCell dstNodeCell = resourceNodeCells.get(dstResNode); - + ObjectNode sourceNode = null; // Source node must be either StatefulObjectNode or EventChannelObejctNode + mxCell sourceNodeCell = null; + mxCell srcOutputPortCell = null; if (callEdge.getSource() instanceof StatefulObjectNode) { - srcResNode = ((StatefulObjectNode) callEdge.getSource()).getResource(); - srcNodeCell = resourceNodeCells.get(srcResNode); + sourceNode = (StatefulObjectNode) callEdge.getSource(); + sourceNodeCell = resourceNodeCells.get(((StatefulObjectNode) sourceNode).getResource()); } else if (callEdge.getSource() instanceof EventChannelObjectNode) { - srcResNode = callEdge.getSource(); - EventChannelObjectNode eventChNode = (EventChannelObjectNode) srcResNode; - DataTransferChannel channel = eventChNode.getIOChannel(); - // TODO: Suspicous call for getChannelNode() - ChannelNode channelNode = controlFlowGraph.getDataFlowGraph().getChannelNode(channel); - - if (eventChannelNodeCells == null) continue; - srcNodeCell = eventChannelNodeCells.get(channelNode); - if (srcNodeCell == null) continue; - srcOutPortCell = (mxCell) srcNodeCell.getChildAt(0); - } else continue; + sourceNode = (EventChannelObjectNode) (callEdge.getSource()); + sourceNodeCell = eventChannelNodeCells.get(sourceNode); + if (sourceNodeCell == null) { + continue; + } + srcOutputPortCell = (mxCell) sourceNodeCell.getChildAt(0); + } - if (srcNodeCell == null || dstNodeCell == null) continue; + StatefulObjectNode destinationNode = ((StatefulObjectNode) callEdge.getDestination()); // Destination node might be the StatefulObjectNode + mxCell destinationNodeCell = resourceNodeCells.get(destinationNode.getResource()); // TODO: Change the type of resourceNodeCells map - CallEdgeAttribute callEdgeAttr = new CallEdgeAttribute(callEdge, (ObjectNode) callEdge.getSource(), srcNodeCell, dstNodeCell); + if (sourceNode == null || sourceNodeCell == null || destinationNodeCell == null) { + continue; + } - mxCell parent = getLCA(srcNodeCell, dstNodeCell); - if (parent == null || parent == graph.getDefaultParent()) parent = layerCell; + mxCell parent = getLCA(sourceNodeCell, destinationNodeCell); + if (parent == null || parent == graph.getDefaultParent()) { + parent = layerCell; + } - if (srcResNode instanceof ResourceNode) { - graph.insertEdge(parent, null, callEdgeAttr, srcNodeCell, dstNodeCell, "movable=false;"); - } else if (srcResNode != null) { - // イベントチャンネルは出力ポートのセルの座標を参照 - graph.insertEdge(parent, null, callEdgeAttr, srcOutPortCell, dstNodeCell, "movable=false;"); + CallEdgeAttribute callEdgeAttr = new CallEdgeAttribute(callEdge, (ObjectNode) callEdge.getSource(), sourceNodeCell, destinationNodeCell); + if (sourceNode instanceof StatefulObjectNode) { + graph.insertEdge(parent, null, callEdgeAttr, sourceNodeCell, destinationNodeCell, "movable=false;"); + } else { + graph.insertEdge(parent, null, callEdgeAttr, srcOutputPortCell, destinationNodeCell, "movable=false;"); } } return graph;