diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationStage.java b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationStage.java index a35a852..0483b83 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationStage.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationStage.java @@ -7,8 +7,8 @@ import com.mxgraph.model.mxCell; import com.mxgraph.model.mxGeometry; import com.mxgraph.swing.mxGraphComponent; -import com.mxgraph.util.mxPoint; import com.mxgraph.util.mxEventSource.mxIEventListener; +import com.mxgraph.util.mxPoint; import com.mxgraph.view.mxGraph; import application.editor.Editor; @@ -25,7 +25,6 @@ import models.controlFlowModel.ObjectNode; import models.controlFlowModel.ObjectNodeAttribute; import models.controlFlowModel.StatefulObjectNode; -import models.dataConstraintModel.ChannelGenerator; import models.dataFlowModel.DataFlowGraph; import models.dataFlowModel.PushPullValue; import models.dataFlowModel.ResourceNode; @@ -212,8 +211,7 @@ ObjectNode insertObjNode = new ObjectNode(insertObjName); ObjectNodeAttribute objNodeAttr = new ObjectNodeAttribute(insertObjNode); - - mxPoint srcPoint = new mxPoint(callEdgeAttr.getSourceCell().getGeometry().getX(), callEdgeAttr.getSourceCell().getGeometry().getY()); + mxPoint srcPoint = new mxPoint(callEdgeAttr.getSourceCell().getGeometry().getX(), callEdgeAttr.getSourceCell().getGeometry().getY()); mxPoint dstPoint = new mxPoint(callEdgeAttr.getDestinationCell().getGeometry().getX(), callEdgeAttr.getDestinationCell().getGeometry().getY()); mxPoint insertPoint = new mxPoint( (srcPoint.getX() + dstPoint.getX())/2, @@ -224,7 +222,6 @@ /* coordinate*/ insertPoint.getX(), insertPoint.getY(), /* scale */ 40, 40, objNodeAttr.getDefaultStyle()); - insertObjNodeCell.setValue(objNodeAttr); addObjectNodeToCallGraphl(insertObjNode, callEdgeAttr.getSelectedOption()); @@ -237,15 +234,20 @@ // Connecting I/O Edges to the insert object. CallEdge srcToInsertEdge = callEdgeAttr.getCallEdge(); - CallEdge insertToDstEdge = new CallEdge(insertObjNode, dstObjNode, callEdgeAttr.getSelectedOption()); + CallEdge insertToDstEdge = new CallEdge(insertObjNode, dstObjNode, callEdgeAttr.getSelectedOption()); + if(srcToInsertEdge == null || insertToDstEdge == null) throw new NullPointerException(); + + // Remove the destination edge of the object node. + // After add the "srcToInsertEdge" to the destination object node. + dstObjNode.removeInEdge(srcToInsertEdge); + dstObjNode.addInEdge(insertToDstEdge); srcToInsertEdge.setDestination(insertObjNode); // changing the out of edge of the sourceObjectNode - if(srcToInsertEdge == null || insertToDstEdge == null) throw new NullPointerException(); - insertObjNode.addInEdge(srcToInsertEdge); - insertObjNode.addOutEdge(insertToDstEdge); + insertObjNode.addOutEdge(insertToDstEdge); + // Update the cell of the graph. for(int i =0; i < controlLayerCell.getChildCount(); i++) { mxCell nodeCell = (mxCell)controlLayerCell.getChildAt(i); if( !nodeCell.isVertex()) continue; @@ -263,9 +265,14 @@ // then it removes from mxGraphModel. if(graph.getModel().getValue(targetEdge) != null) graph.getModel().remove(targetEdge); - - graph.insertEdge(controlLayerCell, null, newInEdgeAttr, srcNodeCell, insertObjNodeCell, "movable=false;"); + mxCell outPortCell = (mxCell)srcNodeCell.getChildAt(0); + if(outPortCell != null) { + graph.insertEdge(controlLayerCell, null, newInEdgeAttr, outPortCell, insertObjNodeCell, "movable=false;"); + } + else { + graph.insertEdge(controlLayerCell, null, newInEdgeAttr, srcNodeCell, insertObjNodeCell, "movable=false;"); + } continue; } // Is "nodeCell" the same as the destination cell of the call edge? @@ -306,7 +313,7 @@ // Creating Entry-Point Object Map controlFlowEntryNodeCells = createCellsOfInputChannel(graph, CONTROL_FLOW_LAYER, controlFlowGraph, controlFlowNodeCells); - Map pushFlowEntryNodeCells = createCellsOfInputChannel(graph, CONTROL_FLOW_LAYER, controlFlowGraph, controlFlowNodeCells); + Map pushFlowEntryNodeCells = createCellsOfInputChannel(graph, PUSH_FLOW_LAYER, controlFlowGraph, controlFlowNodeCells); // Inserting edges of each transfer graph = insertControlFlowEdges(graph, PUSH_FLOW_LAYER, controlFlowGraph.getPushCallGraph(), pushResNodeCells, pushFlowEntryNodeCells); @@ -444,8 +451,9 @@ mxCell channel = (mxCell)graph.insertVertex(layerCell, null, entryObjAttr, 150, 20, 30, 30); mxCell port_out = new mxCell(null, outPortGeometry, "shape=ellipse;perimter=ellipsePerimeter"); port_out.setVertex(true); + graph.addCell(port_out, channel); // insert the output port of a channel - ioChannelCells.put(entryPointObjNode, port_out); + ioChannelCells.put(entryPointObjNode, channel); } } finally { @@ -473,8 +481,9 @@ ResourceNode dstResNode = ((StatefulObjectNode)callEdge.getDestination()).getResource(); mxCell srcNodeCell =null; + mxCell srcOutPortCell = null; mxCell dstNodeCell = resNodeCells.get(dstResNode); - + if(callEdge.getSource() instanceof StatefulObjectNode) { srcResNode = ((StatefulObjectNode)callEdge.getSource()).getResource(); srcNodeCell =resNodeCells.get(srcResNode); @@ -482,13 +491,23 @@ else if (callEdge.getSource() instanceof EntryPointObjectNode) { srcResNode = (EntryPointObjectNode)callEdge.getSource(); srcNodeCell = entryNodeCells.get(srcResNode); + srcOutPortCell = (mxCell)srcNodeCell.getChildAt(0); } else continue; if(srcNodeCell == null || dstNodeCell == null) continue; - + CallEdgeAttribute callEdgeAttr = new CallEdgeAttribute(callEdge, srcNodeCell, dstNodeCell); - graph.insertEdge(layerCell, null, callEdgeAttr, srcNodeCell, dstNodeCell, "movable=false;"); + + // If "srcResNode" types of "EntryPointObjectNode" (= channel) + // then parameter references to geometry of "outPort". + if(srcResNode instanceof ResourceNode) { + graph.insertEdge(layerCell, null, callEdgeAttr, srcNodeCell, dstNodeCell, "movable=false;"); + } + else if(srcResNode instanceof EntryPointObjectNode) { + graph.insertEdge(layerCell, null, callEdgeAttr, srcOutPortCell, dstNodeCell, "movable=false;"); + } + } return graph; }