diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java b/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java index 7eadb4b..da0e8bd 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java @@ -68,7 +68,7 @@ } public mxGraphComponent getGraphComponent() { - return this.graphComponent; + return graphComponent; } public DataTransferModel getModel() { @@ -188,7 +188,6 @@ if (extension.contains(".dtram")) { openDTRAM(file); } - setDAGLayout(); } private void openModel(File file) { @@ -200,17 +199,18 @@ // Update stage's model to new parsed one if (curStage instanceof DataFlowModelingStage) { - DataFlowModelingStage stage = (DataFlowModelingStage) curStage; - stage.setModel(model); + ((DataFlowModelingStage) curStage).setModel(model); } // Force to change PushPullSelectionStage to construct mxGraph - changeStage(STAGE_PUSH_PULL_SELECTION); - if (curStage instanceof PushPullSelectionStage) { - PushPullSelectionStage stage = (PushPullSelectionStage) curStage; - stage.constructGraph(); + boolean stageChanged = changeStage(STAGE_PUSH_PULL_SELECTION); + if (stageChanged && curStage instanceof PushPullSelectionStage) { + ((PushPullSelectionStage) curStage).constructGraph(); } + // Set layout + setDAGLayout(); + // Update current file info curFilePath = file.getAbsolutePath(); curFileName = file.getName(); @@ -235,20 +235,18 @@ // Update stage's model to new parsed one if (curStage instanceof DataFlowModelingStage) { - DataFlowModelingStage stage = (DataFlowModelingStage) curStage; - stage.setModel(model); + ((DataFlowModelingStage) curStage).setModel(model); } - // Parse Geometry - parser.doParseGeometry(graph); - // Force to change PushPullSelectionStage to construct mxGraph - changeStage(STAGE_PUSH_PULL_SELECTION); - if (curStage instanceof PushPullSelectionStage) { - PushPullSelectionStage stage = (PushPullSelectionStage) curStage; - stage.constructGraph(); + boolean stageChanged = changeStage(STAGE_PUSH_PULL_SELECTION); + if (stageChanged && curStage instanceof PushPullSelectionStage) { + ((PushPullSelectionStage) curStage).constructGraph(); } + // Restore the geometry + parser.doParseGeometry(graph); + // Update current file info curFilePath = file.getAbsolutePath(); curFileName = file.getName(); diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/PushPullSelectionStage.java b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/PushPullSelectionStage.java index 0dfe517..5f4ae42 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/PushPullSelectionStage.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/PushPullSelectionStage.java @@ -121,63 +121,68 @@ */ public void constructGraph() { ((mxGraphModel) graph.getModel()).clear(); - Object parent = graph.getDefaultParent(); + mxCell parent = (mxCell) graph.getDefaultParent(); graph.getModel().beginUpdate(); try { - mxGeometry geo1 = new mxGeometry(0, 0.5, PORT_DIAMETER, PORT_DIAMETER); - geo1.setOffset(new mxPoint(-PORT_RADIUS, -PORT_RADIUS)); - geo1.setRelative(true); - - mxGeometry geo2 = new mxGeometry(1.0, 0.5, PORT_DIAMETER, PORT_DIAMETER); - geo2.setOffset(new mxPoint(-PORT_RADIUS, -PORT_RADIUS)); - geo2.setRelative(true); - Map channelsIn = new HashMap<>(); Map channelsOut = new HashMap<>(); Map resources = new HashMap<>(); + mxGeometry geoPortIn = new mxGeometry(0, 0.5, PORT_DIAMETER, PORT_DIAMETER); + geoPortIn.setOffset(new mxPoint(-PORT_RADIUS, -PORT_RADIUS)); + geoPortIn.setRelative(true); + + mxGeometry geoPortOut = new mxGeometry(1.0, 0.5, PORT_DIAMETER, PORT_DIAMETER); + geoPortOut.setOffset(new mxPoint(-PORT_RADIUS, -PORT_RADIUS)); + geoPortOut.setRelative(true); + // create resource vertices - for (ResourceNode resNode : dataFlowGraph.getRootResourceNodes()) { + for (ResourceNode resourceNode : dataFlowGraph.getRootResourceNodes()) { int w = 80; int h = 30; - ResourcePath res = resNode.getPrimaryResourcePath(); - Object resource = graph.insertVertex(parent, null, res.getLeafResourceName(), 20, 20, w, h, "shape=ellipse;perimeter=ellipsePerimeter"); // insert a resource as a vertex - resources.put(resNode, resource); - createChildResourceVertices(resource, resNode, resources, w, h); + ResourcePath resourcePath = resourceNode.getPrimaryResourcePath(); + Object resource = graph.insertVertex(parent, null, resourcePath.getLeafResourceName(), 20, 20, w, h, "shape=ellipse;perimeter=ellipsePerimeter"); // insert a resource as a vertex + resources.put(resourceNode, resource); + createChildResourceVertices(resource, resourceNode, resources, w, h); } // create channel vertices - for (ChannelNode c : dataFlowGraph.getRootChannelNodes()) { - DataTransferChannel channel = (DataTransferChannel) c.getChannel(); + for (ChannelNode channelNode : dataFlowGraph.getRootChannelNodes()) { + DataTransferChannel channel = channelNode.getChannel(); if (!channel.getInputResources().isEmpty()) { // Normal channel if (channelsIn.get(channel) == null || channelsOut.get(channel) == null) { if (Objects.equals(channel.getSelectors().toString(), "[]")) { - Object chCell = graph.insertVertex(parent, null, channel.getChannelName(), 150, 20, 30, 30); // insert a channel as a vertex - mxCell port_in = new mxCell(null, geo1, "shape=ellipse;perimter=ellipsePerimeter"); - port_in.setVertex(true); - graph.addCell(port_in, chCell); // insert the input port of a channel - mxCell port_out = new mxCell(null, geo2, "shape=ellipse;perimter=ellipsePerimeter"); + Object channelCell = graph.insertVertex(parent, null, channel.getChannelName(), 150, 20, 30, 30); // insert a channel as a vertex + + mxCell portIn = new mxCell(null, geoPortIn, "shape=ellipse;perimter=ellipsePerimeter"); + portIn.setVertex(true); + graph.addCell(portIn, channelCell); // insert the input port of a channel + channelsIn.put(channel, portIn); + + mxCell port_out = new mxCell(null, geoPortOut, "shape=ellipse;perimter=ellipsePerimeter"); port_out.setVertex(true); - graph.addCell(port_out, chCell); // insert the output port of a channel - channelsIn.put(channel, port_in); + graph.addCell(port_out, channelCell); // insert the output port of a channel channelsOut.put(channel, port_out); } else { for (Selector s : channel.getSelectors()) { Expression exp = s.getExpression(); - String selName = exp.toString(); - String cName = channel.getChannelName(); - String channelName = cName + " (" + selName + ")"; - Object chCell = graph.insertVertex(parent, null, channelName, 150, 20, 60, 30); // insert a channel as a vertex - mxCell port_in = new mxCell(null, geo1, "shape=ellipse;perimter=ellipsePerimeter"); - port_in.setVertex(true); - graph.addCell(port_in, chCell); // insert the input port of a channel - mxCell port_out = new mxCell(null, geo2, "shape=ellipse;perimter=ellipsePerimeter"); - port_out.setVertex(true); - graph.addCell(port_out, chCell); // insert the output port of a channel - channelsIn.put(channel, port_in); - channelsOut.put(channel, port_out); + String selectorName = exp.toString(); + String channelName = channel.getChannelName(); + String cellName = channelName + " (" + selectorName + ")"; + + Object channelCell = graph.insertVertex(parent, null, cellName, 150, 20, 60, 30); // insert a channel as a vertex + + mxCell portIn = new mxCell(null, geoPortIn, "shape=ellipse;perimter=ellipsePerimeter"); + portIn.setVertex(true); + graph.addCell(portIn, channelCell); // insert the input port of a channel + channelsIn.put(channel, portIn); + + mxCell portOut = new mxCell(null, geoPortOut, "shape=ellipse;perimter=ellipsePerimeter"); + portOut.setVertex(true); + graph.addCell(portOut, channelCell); // insert the output port of a channel + channelsOut.put(channel, portOut); } } } @@ -186,10 +191,10 @@ if (channelsOut.get(channel) == null) { if (Objects.equals(channel.getSelectors().toString(), "[]")) { Object chCell = graph.insertVertex(parent, null, channel.getChannelName(), 150, 20, 30, 30); // insert a channel as a vertex - mxCell port_in = new mxCell(null, geo1, "shape=ellipse;perimter=ellipsePerimeter"); + mxCell port_in = new mxCell(null, geoPortIn, "shape=ellipse;perimter=ellipsePerimeter"); port_in.setVertex(true); graph.addCell(port_in, chCell); // insert the input port of a channel - mxCell port_out = new mxCell(null, geo2, "shape=ellipse;perimter=ellipsePerimeter"); + mxCell port_out = new mxCell(null, geoPortOut, "shape=ellipse;perimter=ellipsePerimeter"); port_out.setVertex(true); graph.addCell(port_out, chCell); // insert the output port of a channel channelsIn.put(channel, port_in); @@ -197,17 +202,19 @@ } else { for (Selector s : channel.getSelectors()) { Expression exp = s.getExpression(); - String selName = exp.toString(); - String cName = channel.getChannelName(); - String channelName = cName + " (" + selName + ")"; - Object chCell = graph.insertVertex(parent, null, channelName, 150, 20, 60, 30); // insert a channel as a vertex - mxCell port_in = new mxCell(null, geo1, "shape=ellipse;perimter=ellipsePerimeter"); + String selectorName = exp.toString(); + String channelName = channel.getChannelName(); + String cellName = channelName + " (" + selectorName + ")"; + Object chCell = graph.insertVertex(parent, null, cellName, 150, 20, 60, 30); // insert a channel as a vertex + + mxCell port_in = new mxCell(null, geoPortIn, "shape=ellipse;perimter=ellipsePerimeter"); port_in.setVertex(true); - graph.addCell(port_in, chCell); // insert the input port of a channel - mxCell port_out = new mxCell(null, geo2, "shape=ellipse;perimter=ellipsePerimeter"); - port_out.setVertex(true); - graph.addCell(port_out, chCell); // insert the output port of a channel + graph.addCell(port_in, chCell); // insert the input port of a channel channelsIn.put(channel, port_in); + + mxCell port_out = new mxCell(null, geoPortOut, "shape=ellipse;perimter=ellipsePerimeter"); + port_out.setVertex(true); + graph.addCell(port_out, chCell); // insert the output port of a channel channelsOut.put(channel, port_out); } } @@ -217,22 +224,22 @@ // add input, output and reference edges for (Edge edge : dataFlowGraph.getEdges()) { - DataFlowEdge dfEdge = (DataFlowEdge) edge; - if (dfEdge.isChannelToResource()) { + DataFlowEdge dataFlowEdge = (DataFlowEdge) edge; + if (dataFlowEdge.isChannelToResource()) { // output edge - DataTransferChannel channel = ((ChannelNode) dfEdge.getSource()).getChannel(); - ResourcePath dstRes = ((ResourceNode) dfEdge.getDestination()).getInSideResource(channel); - graph.insertEdge(parent, null, new Editor.SrcDstAttribute(channel, dstRes), channelsOut.get(channel), resources.get((ResourceNode) dfEdge.getDestination()), "movable=false"); + DataTransferChannel channel = ((ChannelNode) dataFlowEdge.getSource()).getChannel(); + ResourcePath dstRes = ((ResourceNode) dataFlowEdge.getDestination()).getInSideResource(channel); + graph.insertEdge(parent, null, new Editor.SrcDstAttribute(channel, dstRes), channelsOut.get(channel), resources.get((ResourceNode) dataFlowEdge.getDestination()), "movable=false"); } else { // input edge - DataTransferChannel channel = ((ChannelNode) dfEdge.getDestination()).getChannel(); - ResourcePath srcRes = ((ResourceNode) dfEdge.getSource()).getOutSideResource(channel); - Set> toRes = getResourceDependencyForChannel(channel, model, dataFlowGraph); + DataTransferChannel channel = ((ChannelNode) dataFlowEdge.getDestination()).getChannel(); + ResourcePath srcRes = ((ResourceNode) dataFlowEdge.getSource()).getOutSideResource(channel); + Set> toRes = getResourceDependencyForChannel(channel, dataFlowGraph); for (Map.Entry RtoR : toRes) { graph.insertEdge(parent, null, null, resources.get(RtoR.getValue()), resources.get(RtoR.getKey()), "dashed=true;movable=false"); } - graph.insertEdge(parent, null, new Editor.SrcDstAttribute(srcRes, channel), resources.get((ResourceNode) dfEdge.getSource()), channelsIn.get(channel), "movable=false"); + graph.insertEdge(parent, null, new Editor.SrcDstAttribute(srcRes, channel), resources.get((ResourceNode) dataFlowEdge.getSource()), channelsIn.get(channel), "movable=false"); } } @@ -257,7 +264,7 @@ } } - private Set> getResourceDependencyForChannel(DataTransferChannel ch, DataTransferModel model, DataFlowGraph dataFlowGraph) { + private Set> getResourceDependencyForChannel(DataTransferChannel ch, DataFlowGraph dataFlowGraph) { Set> resourceDependency = new HashSet<>(); if (!ch.getOutputChannelMembers().isEmpty()) { try {