diff --git a/AlgebraicDataflowArchitectureModel/src/application/actions/NewResourceAction.java b/AlgebraicDataflowArchitectureModel/src/application/actions/NewResourceAction.java index fd51111..3fb3f38 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/actions/NewResourceAction.java +++ b/AlgebraicDataflowArchitectureModel/src/application/actions/NewResourceAction.java @@ -2,6 +2,7 @@ import application.editor.Editor; import models.dataConstraintModel.ResourcePath; +import models.dataFlowModel.ResourceNode; import javax.swing.*; import java.awt.event.ActionEvent; @@ -17,25 +18,25 @@ @Override public void actionPerformed(ActionEvent e) { - List selectedResPaths = editor.getSelectedResourcePaths(); + List selectedResNodes = editor.getSelectedResourceNodes(); String initialName = ""; - if (selectedResPaths != null && selectedResPaths.size() == 1) { - initialName = selectedResPaths.get(0).toString(); + if (selectedResNodes != null && selectedResNodes.size() == 1) { + initialName = selectedResNodes.get(0).getPrimaryResourcePath().toString(); } String resName = JOptionPane.showInputDialog("Resource Name:", initialName); if (resName == null) { return; } - if (selectedResPaths == null || selectedResPaths.size() == 0) { - editor.addResourcePath(null, resName); - } else if (selectedResPaths.size() == 1) { + if (selectedResNodes == null || selectedResNodes.size() == 0) { + editor.addResourceNode(null, resName); + } else if (selectedResNodes.size() == 1) { if (initialName.length() > 0 && resName.startsWith(initialName)) { resName = resName.substring(initialName.length()); if (resName.startsWith(".")) { resName = resName.substring(1); } } - editor.addResourcePath(selectedResPaths.get(0), resName); + editor.addResourceNode(selectedResNodes.get(0), resName); } } } diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java b/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java index 034cbb6..e2dc634 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java @@ -22,6 +22,7 @@ import models.dataFlowModel.DataFlowGraph; import models.dataFlowModel.DataTransferChannel; import models.dataFlowModel.DataTransferModel; +import models.dataFlowModel.ResourceNode; import models.visualModel.FormulaChannel; import parser.Parser; import parser.ParserDTRAM; @@ -359,19 +360,21 @@ } } - public List getSelectedResourcePaths() { + public List getSelectedResourceNodes() { Object[] sels = graph.getSelectionCells(); - List resPaths = new ArrayList<>(); - for (Object sel: sels) { - if (sel instanceof mxCell && ((mxCell) sel).isVertex()) { - mxCell cell = ((mxCell) sel); - ResourcePath resPath = model.getResourcePath((String) cell.getValue()); - if (resPath != null) { - resPaths.add(resPath); - } - } + List resNodes = new ArrayList<>(); + if (curStage instanceof DataFlowModelingStage) { + for (Object sel: sels) { + if (sel instanceof mxCell && ((mxCell) sel).isVertex()) { + mxCell cell = ((mxCell) sel); + ResourceNode resNode = ((DataFlowModelingStage) curStage).getResourceNode(cell); + if (resNode != null) { + resNodes.add(resNode); + } + } + } } - return resPaths; + return resNodes; } public List getSelectedChannels() { @@ -402,13 +405,13 @@ ((DataFlowModelingStage) curStage).delete(); } - public void addResourcePath(ResourcePath parentPath, String resName) { + public void addResourceNode(ResourceNode parentNode, String resName) { // Force to change to data-flow modeling stage boolean stageChanged = changeStage(STAGE_DATA_FLOW_MODELING); if (!stageChanged) { return; } - ((DataFlowModelingStage) curStage).addResourcePath(parentPath, resName); + ((DataFlowModelingStage) curStage).addResourceNode(parentNode, resName); model = curStage.getModel(); } diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DataFlowModelingStage.java b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DataFlowModelingStage.java index 4722df8..6c97196 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DataFlowModelingStage.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DataFlowModelingStage.java @@ -16,8 +16,10 @@ import models.dataConstraintModel.ChannelMember; import models.dataConstraintModel.ResourcePath; import models.dataConstraintModel.Selector; +import models.dataFlowModel.DataFlowGraph; import models.dataFlowModel.DataTransferChannel; import models.dataFlowModel.DataTransferModel; +import models.dataFlowModel.ResourceNode; import models.visualModel.FormulaChannel; import parser.Parser; import parser.exceptions.*; @@ -28,10 +30,10 @@ import java.util.List; public class DataFlowModelingStage extends Stage { - private HashMap resPathToCell = new HashMap<>(); - private HashMap channelToCell = new HashMap<>(); - private HashMap cellToResPath = new HashMap<>(); - private HashMap cellToChannel = new HashMap<>(); + private HashMap resNodeToCell = new HashMap<>(); + private HashMap channelToCell = new HashMap<>(); + private HashMap cellToResNode = new HashMap<>(); + private HashMap cellToChannel = new HashMap<>(); public DataFlowModelingStage(mxGraphComponent graphComponent) { super(graphComponent); @@ -39,6 +41,20 @@ @Override public void init(Stage prevStage) { + if (prevStage instanceof PushPullSelectionStage) { + if (((PushPullSelectionStage) prevStage).getResNodeToCell() != null) { + resNodeToCell = ((PushPullSelectionStage) prevStage).getResNodeToCell(); + } + if (((PushPullSelectionStage) prevStage).getChannelToCell() != null) { + channelToCell = ((PushPullSelectionStage) prevStage).getChannelToCell(); + } + for (ResourceNode resNode: resNodeToCell.keySet()) { + cellToResNode.put(resNodeToCell.get(resNode), resNode); + } + for (DataTransferChannel ch: channelToCell.keySet()) { + cellToChannel.put(channelToCell.get(ch), ch); + } + } } @Override @@ -105,20 +121,23 @@ return Validation.checkUpdateConflict(model); } - public ResourcePath getResourcePath(mxCell cell) { - return cellToResPath.get(cell); + public ResourceNode getResourceNode(mxCell cell) { + return cellToResNode.get(cell); } public Channel getChannel(mxCell cell) { return cellToChannel.get(cell); } - public void addResourcePath(ResourcePath parentPath, String resName) { - ResourcePath resourcePath = null; - if (parentPath == null) { - resourcePath = new ResourcePath(resName); + public void addResourceNode(ResourceNode parentNode, String resName) { + ResourceNode resourceNode = null; + ResourcePath resourcePath = null; + if (parentNode == null) { + resourcePath = new ResourcePath(resName); + resourceNode = new ResourceNode(null, resourcePath); getModel().addResourcePath(resourcePath); } else { + ResourcePath parentPath = parentNode.getPrimaryResourcePath(); if (resName.startsWith(Parser.LEFT_CURLY_BRACKET) && resName.endsWith(Parser.RIGHT_CURLY_BRACKET)) { Parser.TokenStream stream = new Parser.TokenStream(); Parser parser = new Parser(stream); @@ -126,12 +145,14 @@ try { Expression exp = parser.parseTerm(stream, getModel()); resourcePath = new ResourcePath(parentPath, exp); + resourceNode = new ResourceNode(parentNode, resourcePath); getModel().addResourcePath(resourcePath); } catch (ExpectedRightBracket | WrongJsonExpression | ExpectedColon | ExpectedDoubleQuotation e) { e.printStackTrace(); } } else { resourcePath = new ResourcePath(parentPath, resName); + resourceNode = new ResourceNode(parentNode, resourcePath); getModel().addResourcePath(resourcePath); } } @@ -139,17 +160,17 @@ graph.getModel().beginUpdate(); mxCell root = (mxCell) graph.getDefaultParent(); try { - if (parentPath == null) { - mxCell resCell = (mxCell) graph.insertVertex(root, null, resourcePath.getName(), 20, 20, 80, 30, "shape=ellipse;perimeter=ellipsePerimeter;verticalAlign=top"); // insert a resource as a vertex - resPathToCell.put(resourcePath, resCell); - cellToResPath.put(resCell, resourcePath); + if (parentNode == null) { + mxCell resCell = (mxCell) graph.insertVertex(root, null, resourceNode.getPrimaryResourcePath().getName(), 20, 20, 80, 30, "shape=ellipse;perimeter=ellipsePerimeter;verticalAlign=top"); // insert a resource as a vertex + resNodeToCell.put(resourceNode, resCell); + cellToResNode.put(resCell, resourceNode); } else { - mxCell parentCell = resPathToCell.get(parentPath); + mxCell parentCell = resNodeToCell.get(parentNode); double pw = parentCell.getGeometry().getWidth(); double ph = parentCell.getGeometry().getHeight(); - mxCell resCell = (mxCell) graph.insertVertex(parentCell, null, resourcePath.getName(), 20, 20, pw * 0.8, ph * 0.8, "shape=ellipse;perimeter=ellipsePerimeter;verticalAlign=top"); // insert a resource as a vertex - resPathToCell.put(resourcePath, resCell); - cellToResPath.put(resCell, resourcePath); + mxCell resCell = (mxCell) graph.insertVertex(parentCell, null, resourceNode.getPrimaryResourcePath().getName(), 20, 20, pw * 0.8, ph * 0.8, "shape=ellipse;perimeter=ellipsePerimeter;verticalAlign=top"); // insert a resource as a vertex + resNodeToCell.put(resourceNode, resCell); + cellToResNode.put(resCell, resourceNode); } } finally { graph.getModel().endUpdate(); @@ -275,26 +296,40 @@ } public boolean connectEdge(mxCell edge, mxCell src, mxCell dst) { - Channel srcCh = cellToChannel.get(src); + DataTransferChannel srcCh = cellToChannel.get(src); if (srcCh == null) { - ResourcePath srcRes = cellToResPath.get(src); - Channel dstCh = cellToChannel.get(dst); - if (srcRes == null || dstCh == null) { + ResourceNode srcResNode = cellToResNode.get(src); + DataTransferChannel dstCh = cellToChannel.get(dst); + if (srcResNode == null || dstCh == null) { return false; } // resource to channel edge + ResourcePath srcRes = srcResNode.getPrimaryResourcePath(); + if (srcResNode.getIndegree() + srcResNode.getOutdegree() == 0) { + srcResNode.addOutSideResource(dstCh, srcRes); + } else { + srcRes = new ResourcePath(srcRes.getName(), srcRes.getResourceHierarchy()); + model.addResourcePath(srcRes); + } ChannelMember srcCm = new ChannelMember(srcRes); - ((DataTransferChannel) dstCh).addChannelMemberAsInput(srcCm); + dstCh.addChannelMemberAsInput(srcCm); edge.setValue(new Editor.SrcDstAttribute(srcRes, dstCh)); return true; } - ResourcePath dstRes = cellToResPath.get(dst); - if (dstRes == null) { + ResourceNode dstResNode = cellToResNode.get(dst); + if (dstResNode == null) { return false; } // channel to resource edge + ResourcePath dstRes = dstResNode.getPrimaryResourcePath(); + if (dstResNode.getIndegree() + dstResNode.getOutdegree() == 0) { + dstResNode.addInSideResource(srcCh, dstRes); + } else { + dstRes = new ResourcePath(dstRes.getName(), dstRes.getResourceHierarchy()); + model.addResourcePath(dstRes); + } ChannelMember dstCm = new ChannelMember(dstRes); - ((DataTransferChannel) srcCh).addChannelMemberAsOutput(dstCm); + srcCh.addChannelMemberAsOutput(dstCm); edge.setValue(new Editor.SrcDstAttribute(srcCh, dstRes)); return true; } @@ -303,28 +338,32 @@ for (Object obj : graph.getSelectionCells()) { mxCell cell = (mxCell) obj; if (cell.isEdge()) { - String srcName = (String) cell.getSource().getValue(); - String dstName = (String) cell.getTarget().getValue(); - if (model.getResourcePath(srcName) != null) { + mxCell srcCell = (mxCell) cell.getSource(); + mxCell dstCell = (mxCell) cell.getTarget(); + if (cellToResNode.get(srcCell) != null) { // resource to channel edge - Channel ch = model.getChannel(dstName); - ch.removeChannelMember(model.getResourcePath(srcName)); - } else if (model.getResourcePath(dstName) != null) { + DataTransferChannel ch = cellToChannel.get(dstCell); + ch.removeChannelMember(cellToResNode.get(srcCell).getOutSideResource(ch)); + } else if (cellToResNode.get(dstCell) != null) { // channel to resource edge - Channel ch = model.getChannel(srcName); - if (ch == null) { - ch = model.getInputChannel(srcName); - } - ch.removeChannelMember(model.getResourcePath(dstName)); + DataTransferChannel ch = cellToChannel.get(srcCell); + ch.removeChannelMember(cellToResNode.get(dstCell).getInSideResource(ch)); } } else if (cell.isVertex()) { - String name = (String) cell.getValue(); - if (model.getChannel(name) != null) { - model.removeChannel(name); - } else if (model.getInputChannel(name) != null) { - model.removeInputChannel(name); - } else if (model.getResourcePath(name) != null) { - model.removeResourcePath(name); + if (cellToChannel.get(cell) != null) { + DataTransferChannel ch = cellToChannel.get(cell); + if (ch.getInputChannelMembers().size() == 0) { + model.removeInputChannel(cellToChannel.get(cell).getChannelName()); + } else { + model.removeChannel(cellToChannel.get(cell).getChannelName()); + } + } else if (cellToResNode.get(cell) != null) { + for (ResourcePath resPath: cellToResNode.get(cell).getInSideResources()) { + model.removeResourcePath(resPath); + } + for (ResourcePath resPath: cellToResNode.get(cell).getOutSideResources()) { + model.removeResourcePath(resPath); + } } } } diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/PushPullSelectionStage.java b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/PushPullSelectionStage.java index eeb814c..06b5b47 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/PushPullSelectionStage.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/PushPullSelectionStage.java @@ -25,6 +25,8 @@ public class PushPullSelectionStage extends Stage { private DataFlowGraph dataFlowGraph = null; + private HashMap resNodeToCell; + private HashMap channelToCell; public PushPullSelectionStage(mxGraphComponent graphComponent) { super(graphComponent); @@ -125,9 +127,10 @@ graph.getModel().beginUpdate(); try { - Map channelsIn = new HashMap<>(); - Map channelsOut = new HashMap<>(); - Map resources = new HashMap<>(); + Map channelInToCell = new HashMap<>(); + Map channelOutToCell = new HashMap<>(); + channelToCell = new HashMap<>(); + resNodeToCell = new HashMap<>(); mxGeometry geoPortIn = new mxGeometry(0, 0.5, PORT_DIAMETER, PORT_DIAMETER); geoPortIn.setOffset(new mxPoint(-PORT_RADIUS, -PORT_RADIUS)); @@ -142,9 +145,9 @@ int w = 80; int h = 30; ResourcePath resourcePath = resourceNode.getPrimaryResourcePath(); - Object resourceCell = graph.insertVertex(parent, null, resourcePath.getLeafResourceName(), 20, 20, w, h, "shape=ellipse;perimeter=ellipsePerimeter;verticalAlign=top"); // insert a resource as a vertex - resources.put(resourceNode, resourceCell); - createChildResourceVertices(resourceCell, resourceNode, resources, w, h); + mxCell resourceCell = (mxCell) graph.insertVertex(parent, null, resourcePath.getLeafResourceName(), 20, 20, w, h, "shape=ellipse;perimeter=ellipsePerimeter;verticalAlign=top"); // insert a resource as a vertex + resNodeToCell.put(resourceNode, resourceCell); + createChildResourceVertices(resourceCell, resourceNode, w, h); } // create channel vertices @@ -152,7 +155,7 @@ DataTransferChannel channel = channelNode.getChannel(); if (!channel.getInputResources().isEmpty()) { // Normal channel - if (channelsIn.get(channel) == null || channelsOut.get(channel) == null) { + if (channelInToCell.get(channel) == null || channelOutToCell.get(channel) == null) { String channelName = channel.getChannelName(); if (channel.getSelectors().size() > 0) { channelName += "("; @@ -171,22 +174,23 @@ w *= 2; h *= 2; } - Object channelCell = graph.insertVertex(parent, null, channelName, 150, 20, w, h, "verticalAlign=top"); // insert a channel as a vertex + mxCell channelCell = (mxCell) graph.insertVertex(parent, null, channelName, 150, 20, w, h, "verticalAlign=top"); // insert a channel as a vertex + channelToCell.put(channel, channelCell); 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); + channelInToCell.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, h); + channelOutToCell.put(channel, portOut); + createChildChannelVertices(channelCell, channelNode, channelInToCell, channelOutToCell, geoPortIn, geoPortOut, w, h); } } else { // Event channel - if (channelsOut.get(channel) == null) { + if (channelOutToCell.get(channel) == null) { String channelName = channel.getChannelName(); if (channel.getSelectors().size() > 0) { channelName += "("; @@ -205,13 +209,14 @@ w *= 2; h *= 2; } - Object channelCell = graph.insertVertex(parent, null, channelName, 150, 20, w, h, "verticalAlign=top"); // insert a channel as a vertex + mxCell channelCell = (mxCell) graph.insertVertex(parent, null, channelName, 150, 20, w, h, "verticalAlign=top"); // insert a channel as a vertex + channelToCell.put(channel, channelCell); 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); + channelOutToCell.put(channel, portOut); + createChildChannelVertices(channelCell, channelNode, channelInToCell, channelOutToCell, geoPortIn, geoPortOut, w, h); } } } @@ -223,17 +228,17 @@ // output edge 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"); + graph.insertEdge(parent, null, new Editor.SrcDstAttribute(channel, dstRes), channelOutToCell.get(channel), resNodeToCell.get((ResourceNode) dataFlowEdge.getDestination()), "movable=false"); } else { // input edge 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, null, resNodeToCell.get(RtoR.getValue()), resNodeToCell.get(RtoR.getKey()), "dashed=true;movable=false"); } - graph.insertEdge(parent, null, new Editor.SrcDstAttribute(srcRes, channel), resources.get((ResourceNode) dataFlowEdge.getSource()), channelsIn.get(channel), "movable=false"); + graph.insertEdge(parent, null, new Editor.SrcDstAttribute(srcRes, channel), resNodeToCell.get((ResourceNode) dataFlowEdge.getSource()), channelInToCell.get(channel), "movable=false"); } } @@ -241,7 +246,7 @@ // reference edges DataTransferChannel channel = (DataTransferChannel) ch; for (ResourcePath refRes : channel.getReferenceResources()) { - graph.insertEdge(parent, null, null, resources.get(dataFlowGraph.getResourceNode(refRes)), channelsIn.get(channel), "dashed=true;movable=false"); + graph.insertEdge(parent, null, null, resNodeToCell.get(dataFlowGraph.getResourceNode(refRes)), channelInToCell.get(channel), "dashed=true;movable=false"); } } } finally { @@ -249,21 +254,22 @@ } } - private void createChildResourceVertices(Object parentCell, ResourceNode parentResNode, Map resources, int w, int h) { + private void createChildResourceVertices(mxCell parentCell, ResourceNode parentResNode, 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;verticalAlign=top"); // insert a resource as a vertex - resources.put(resNode, resourceCell); - createChildResourceVertices(resourceCell, resNode, resources, w, h); + mxCell resourceCell = (mxCell) graph.insertVertex(parentCell, null, resPath.getName(), 0, 0, w, h, "shape=ellipse;perimeter=ellipsePerimeter;verticalAlign=top"); // insert a resource as a vertex + resNodeToCell.put(resNode, resourceCell); + createChildResourceVertices(resourceCell, resNode, w, h); } } - private void createChildChannelVertices(Object parentCell, ChannelNode parentChannelNode, Map channelsIn, Map channelsOut, mxGeometry geoPortIn, mxGeometry geoPortOut, int w, int h) { + private void createChildChannelVertices(mxCell parentCell, ChannelNode parentChannelNode, + Map channelInToCell, Map channelOutToCell, 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) { + if (channelInToCell.get(channel) == null || channelOutToCell.get(channel) == null) { String channelName = channel.getChannelName(); if (channel.getSelectors().size() > 0) { channelName += "("; @@ -276,22 +282,23 @@ } 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 channelCell = (mxCell) graph.insertVertex(parentCell, null, channelName, w / 4, h / 4, w / 2, h / 2, "verticalAlign=top"); // insert a channel as a vertex + channelToCell.put(channel, channelCell); 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); + channelInToCell.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); + channelOutToCell.put(channel, portOut); + createChildChannelVertices(channelCell, channelNode, channelInToCell, channelOutToCell, geoPortIn, geoPortOut, w / 2, h / 2); } } else { // Event channel - if (channelsOut.get(channel) == null) { + if (channelOutToCell.get(channel) == null) { String channelName = channel.getChannelName(); if (channel.getSelectors().size() > 0) { channelName += "("; @@ -304,13 +311,14 @@ } 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 channelCell = (mxCell) graph.insertVertex(parentCell, null, channelName, w / 4, h / 4, w / 2, h / 2, "verticalAlign=top"); // insert a channel as a vertex + channelToCell.put(channel, channelCell); 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); + channelOutToCell.put(channel, portOut); + createChildChannelVertices(channelCell, channelNode, channelInToCell, channelOutToCell, geoPortIn, geoPortOut, w / 2, h / 2); } } } @@ -344,4 +352,12 @@ public DataFlowGraph getDataFlowGraph() { return dataFlowGraph; } + + public HashMap getResNodeToCell() { + return resNodeToCell; + } + + public HashMap getChannelToCell() { + return channelToCell; + } } diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java index 858ecb4..6ce02cd 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java @@ -1114,6 +1114,10 @@ ResourcePath resourcePath = getResourcePath(path); if (resourcePath == null) return; resourcePaths.remove(resourcePath); + removeResourcePath(resourcePath); + } + + public void removeResourcePath(ResourcePath resourcePath) { for (Channel ch: channels.values()) { ch.removeChannelMember(resourcePath); } diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/ResourceNode.java b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/ResourceNode.java index 8dea216..6c56bcb 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/ResourceNode.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/ResourceNode.java @@ -21,13 +21,26 @@ protected ResourceNode parent = null; protected Set children = null; protected ResourceHierarchy resourceHierarchy = null; + protected ResourcePath primaryResourcePath = null; // for temporal use at the modeling stage protected Map inSide = null; protected Map outSide = null; protected List selectors = null; + + public ResourceNode(ResourceNode parent, ResourcePath primaryResourcePath) { + this.parent = parent; + this.children = new HashSet<>(); + this.inSide = new HashMap<>(); + this.outSide = new HashMap<>(); + this.resourceHierarchy = primaryResourcePath.getResourceHierarchy(); + this.primaryResourcePath = primaryResourcePath; + this.selectors = new ArrayList<>(); + if (resourceHierarchy.getNumParameters() > 0) { + List pathParams = primaryResourcePath.getPathParams(); + selectors.add(new Selector(pathParams.get(pathParams.size() - 1))); + } + } - public ResourceNode(ResourceNode parent, - ResourcePath outSideResource, - DataTransferChannel outSideChannel) { + public ResourceNode(ResourceNode parent, ResourcePath outSideResource, DataTransferChannel outSideChannel) { this.parent = parent; this.children = new HashSet<>(); this.inSide = new HashMap<>(); @@ -45,9 +58,7 @@ } } - public ResourceNode(ResourceNode parent, - ResourcePath resource, - DataTransferChannel channel, boolean isInside) { + public ResourceNode(ResourceNode parent, ResourcePath resource, DataTransferChannel channel, boolean isInside) { this.parent = parent; this.children = new HashSet<>(); this.inSide = new HashMap<>(); @@ -69,9 +80,7 @@ } } - public ResourceNode(ResourceNode parent, - Map outSide, - Map inSide) { + public ResourceNode(ResourceNode parent, Map outSide, Map inSide) { this.parent = parent; this.children = new HashSet<>(); this.inSide = inSide; @@ -124,6 +133,7 @@ } public ResourcePath getPrimaryResourcePath() { + if (primaryResourcePath != null) return primaryResourcePath; if (outSide.size() > 0) return outSide.values().iterator().next(); return inSide.values().iterator().next(); } @@ -153,10 +163,12 @@ } public void addInSideResource(DataTransferChannel channel, ResourcePath inResource) { + primaryResourcePath = null; inSide.put(channel, inResource); } public void addOutSideResource(DataTransferChannel channel, ResourcePath outResource) { + primaryResourcePath = null; outSide.put(channel, outResource); }