diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java b/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java index ed5bfa9..48c7484 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java @@ -172,7 +172,7 @@ // Force to change PushPullSelectionStage to construct mxGraph boolean stageChanged = changeStage(STAGE_PUSH_PULL_SELECTION); if (stageChanged && curStage instanceof PushPullSelectionStage) { - ((PushPullSelectionStage) curStage).constructGraph(); + ((PushPullSelectionStage) curStage).constructGraph(); // Construction of data-flow graph } // Set layout @@ -208,7 +208,7 @@ // Force to change PushPullSelectionStage to construct mxGraph boolean stageChanged = changeStage(STAGE_PUSH_PULL_SELECTION); if (stageChanged && curStage instanceof PushPullSelectionStage) { - ((PushPullSelectionStage) curStage).constructGraph(); + ((PushPullSelectionStage) curStage).constructGraph(); // Construction of data-flow graph } // Restore the geometry diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/PushPullSelectionStage.java b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/PushPullSelectionStage.java index 5f4ae42..6423df6 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/PushPullSelectionStage.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/PushPullSelectionStage.java @@ -142,9 +142,9 @@ int w = 80; int h = 30; 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); + Object resourceCell = graph.insertVertex(parent, null, resourcePath.getLeafResourceName(), 20, 20, w, h, "shape=ellipse;perimeter=ellipsePerimeter"); // insert a resource as a vertex + resources.put(resourceNode, resourceCell); + createChildResourceVertices(resourceCell, resourceNode, resources, w, h); } // create channel vertices @@ -153,71 +153,65 @@ if (!channel.getInputResources().isEmpty()) { // Normal channel if (channelsIn.get(channel) == null || channelsOut.get(channel) == null) { - if (Objects.equals(channel.getSelectors().toString(), "[]")) { - Object channelCell = graph.insertVertex(parent, null, channel.getChannelName(), 150, 20, 30, 30); // insert a channel as a vertex + String channelName = channel.getChannelName(); + if (channel.getSelectors().size() > 0) { + channelName += "("; + String delimiter = ""; + for (Selector s: channel.getSelectors()) { + Expression exp = s.getExpression(); + String selectorName = exp.toString(); + channelName += delimiter + selectorName; + delimiter = ", "; + } + channelName += ")"; + } + int w = 60; + int h = 30; + if (channelNode.getChildren().size() > 0) { + w *= 2; + h *= 2; + } + Object channelCell = graph.insertVertex(parent, null, channelName, 150, 20, w, h, "verticalAlign=top"); // 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 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, channelCell); // insert the output port of a channel - channelsOut.put(channel, port_out); - } else { - for (Selector s : channel.getSelectors()) { - Expression exp = s.getExpression(); - 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); - } - } + 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); + createChildChannelVertices(channelCell, channelNode, channelsIn, channelsOut, geoPortIn, geoPortOut, w, h); } } else { - // I/O channel + // Event channel 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, 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, 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); - channelsOut.put(channel, port_out); - } else { - for (Selector s : channel.getSelectors()) { - Expression exp = s.getExpression(); - 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 - 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); - } - } + String channelName = channel.getChannelName(); + if (channel.getSelectors().size() > 0) { + channelName += "("; + String delimiter = ""; + for (Selector s: channel.getSelectors()) { + Expression exp = s.getExpression(); + String selectorName = exp.toString(); + channelName += delimiter + selectorName; + delimiter = ", "; + } + channelName += ")"; + } + int w = 40; + int h = 30; + if (channelNode.getChildren().size() > 0) { + w *= 2; + h *= 2; + } + Object channelCell = graph.insertVertex(parent, null, channelName, 150, 20, w, h, "verticalAlign=top"); // insert a channel as a vertex + + 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); + createChildChannelVertices(channelCell, channelNode, channelsIn, channelsOut, geoPortIn, geoPortOut, w, h); } } } @@ -255,14 +249,72 @@ } } - private void createChildResourceVertices(Object resource, ResourceNode resNode, Map resources, int w, int h) { - for (ResourceNode childNode : resNode.getChildren()) { - ResourcePath childRes = childNode.getPrimaryResourcePath(); - Object childResource = graph.insertVertex(resource, null, childRes.getName(), 0, 0, w, h, "shape=ellipse;perimeter=ellipsePerimeter"); // insert a resource as a vertex - resources.put(childNode, childResource); - createChildResourceVertices(childResource, childNode, resources, w, h); + private void createChildResourceVertices(Object parentCell, ResourceNode parentResNode, Map resources, int w, int h) { + for (ResourceNode resNode: parentResNode.getChildren()) { + ResourcePath resPath = resNode.getPrimaryResourcePath(); + Object resourceCell = graph.insertVertex(parentCell, null, resPath.getName(), 0, 0, w, h, "shape=ellipse;perimeter=ellipsePerimeter"); // insert a resource as a vertex + resources.put(resNode, resourceCell); + createChildResourceVertices(resourceCell, resNode, resources, w, h); } } + + private void createChildChannelVertices(Object parentCell, ChannelNode parentChannelNode, Map channelsIn, Map channelsOut, mxGeometry geoPortIn, mxGeometry geoPortOut, int w, int h) { + for (ChannelNode channelNode: parentChannelNode.getChildren()) { + DataTransferChannel channel = channelNode.getChannel(); + if (!channel.getInputResources().isEmpty()) { + // Normal channel + if (channelsIn.get(channel) == null || channelsOut.get(channel) == null) { + String channelName = channel.getChannelName(); + if (channel.getSelectors().size() > 0) { + channelName += "("; + String delimiter = ""; + for (Selector s: channel.getSelectors()) { + Expression exp = s.getExpression(); + String selectorName = exp.toString(); + channelName += delimiter + selectorName; + delimiter = ", "; + } + channelName += ")"; + } + Object channelCell = graph.insertVertex(parentCell, null, channelName, w / 4, h / 4, w / 2, h / 2, "verticalAlign=top"); // 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); + createChildChannelVertices(channelCell, channelNode, channelsIn, channelsOut, geoPortIn, geoPortOut, w / 2, h / 2); + } + } else { + // Event channel + if (channelsOut.get(channel) == null) { + String channelName = channel.getChannelName(); + if (channel.getSelectors().size() > 0) { + channelName += "("; + String delimiter = ""; + for (Selector s: channel.getSelectors()) { + Expression exp = s.getExpression(); + String selectorName = exp.toString(); + channelName += delimiter + selectorName; + delimiter = ", "; + } + channelName += ")"; + } + Object channelCell = graph.insertVertex(parentCell, null, channelName, w / 4, h / 4, w / 2, h / 2, "verticalAlign=top"); // insert a channel as a vertex + + 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); + createChildChannelVertices(channelCell, channelNode, channelsIn, channelsOut, geoPortIn, geoPortOut, w / 2, h / 2); + } + } + } + } private Set> getResourceDependencyForChannel(DataTransferChannel ch, DataFlowGraph dataFlowGraph) { Set> resourceDependency = new HashSet<>();