diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/InputEventCellEditor.java b/AlgebraicDataflowArchitectureModel/src/application/editor/InputEventCellEditor.java index e21a902..c59fec4 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/InputEventCellEditor.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/InputEventCellEditor.java @@ -170,7 +170,8 @@ Event newEvent = new Event(eventChs.get(eventNum), eventMessage, eventResPath, simulator.getCurState().getResource(resId)); simulator.transition(newEvent); - constructNextSimulateGraph(simulator.getCurState().getRootResources(), simulator.getModel(),simulator.getModel().getDataFlowGraph(), graph); + constructNextSimulateGraph(simulator, simulator.getModel(),simulator.getModel().getDataFlowGraph(), graph); + //constructNextSimulateGraph(simulator.getCurState().getRootResources(), simulator.getModel(),simulator.getModel().getDataFlowGraph(), graph); graphComponent.setCellEditor(new InputEventCellEditor(graphComponent, simulator, this.editor, graph)); } catch (ParameterizedIdentifierIsFutureWork | ResolvingMultipleDefinitionIsFutureWork @@ -202,16 +203,17 @@ } } } - + final double BASE_WIDTH = 100; + final double BASE_HEIGHT = BASE_WIDTH/2; private mxGraph constructNextSimulateGraph(Set simulateRes, DataTransferModel model,DataFlowGraph dataFlowGraph, mxGraph nextGraph) { bReflectingArchitectureModel = true; ((mxGraphModel) nextGraph.getModel()).clear(); Object parent = nextGraph.getDefaultParent(); nextGraph.getModel().beginUpdate(); - + try { Map resources = new HashMap<>(); - + // create resource vertices for (Resource resNode: simulateRes) { int w = 400; @@ -221,19 +223,88 @@ res.toString(), x, y, w, h, "shape=ellipse;perimeter=ellipsePerimeter;verticalAlign=top;"); // insert a resource as a vertex resources.put(resNode, resource); - + createNextChildSimulateResourceVerticies(resource, resNode, resources, w, h); x+=400; } - + } finally { nextGraph.getModel().endUpdate(); } - + bReflectingArchitectureModel = false; return nextGraph; } + private mxGraph constructNextSimulateGraph(Simulator simulator, DataTransferModel model,DataFlowGraph dataFlowGraph, mxGraph nextGraph) { + bReflectingArchitectureModel = true; + ((mxGraphModel) nextGraph.getModel()).clear(); + Object parent = nextGraph.getDefaultParent(); + nextGraph.getModel().beginUpdate(); + + + SimulationLayout simulationLayout = new SimulationLayout(simulator.getCurState().getRootResources()); + + try { + Map resources = new HashMap<>(); + int i = 0; + // create resource vertices + for (Resource resNode:simulator.getCurState().getRootResources()) { + double scale = simulationLayout.getScale(resNode); + double w = BASE_WIDTH * scale; + double h = BASE_HEIGHT * scale; + + double division = simulationLayout.getDivision(resNode); + double w1 = 2*BASE_WIDTH/division; + double h1 = 2*BASE_HEIGHT/division; + double x = 40 + i * w; + double y = 20 ; + ResourcePath res = resNode.getResourceIdentifier(); + Object resource = nextGraph.insertVertex(parent, null, + res.toString(), x, y, w1, h1, + "shape=ellipse;perimeter=ellipsePerimeter;verticalAlign=top;"); // insert a resource as a vertex + resources.put(resNode, resource); + + createNextChildSimulateResourceVerticies(resource, resNode, resources, simulationLayout); + + } + + } finally { + nextGraph.getModel().endUpdate(); + } + + bReflectingArchitectureModel = false; + return nextGraph; + } + private void createNextChildSimulateResourceVerticies(Object resource, Resource resNode, Map resources, SimulationLayout layout) { //sample + + if(resNode.getChildren() != null) { + List children = resNode.getChildren(); + int i = 1; + int childCount = children.size(); + for (Resource childNode: children) { + + ResourcePath childRes = childNode.getResourceIdentifier(); + double width = layout.getScale(childNode) * BASE_WIDTH ; + double height = layout.getScale(childNode) * BASE_HEIGHT; + + double division = layout.getDivision(childNode); + double w1 = 2*BASE_WIDTH/division; + double h1 = 2*BASE_HEIGHT/division; + + Object childResource = graph.insertVertex(resource, null, + childRes.toString(), w1 * i - (w1 * childCount / 2.0), h1/2, w1, h1, + "shape=ellipse;perimeter=ellipsePerimeter;verticalAlign=top;"); // insert a resource as a vertex + resources.put(childNode, childResource); + i++; + createNextChildSimulateResourceVerticies(childResource, childNode, resources,layout); + } + } + if (resNode.getChildren() == null || resNode.getChildren().size() == 0) { + Object state = graph.insertVertex(resource, null, + resNode.getState().getValue().toString(), 0.5, 0.5, 0.25, 0.25, "opacity=0;verticalAlign=down;", true); // insert a state label as a vertex + } + } private void createNextChildSimulateResourceVerticies(Object resource, Resource resNode, Map resources, int w, int h) { //sample if(resNode.getChildren() != null) { @@ -241,7 +312,7 @@ int i = 1; ResourcePath childRes = childNode.getResourceIdentifier(); Object childResource = graph.insertVertex(resource, null, - childRes.toString(), x/i, y, w/(i+1), h/(i+2), + childRes.toString(), x/i, 0, w/(i+1), h/(i+2), "shape=ellipse;perimeter=ellipsePerimeter;verticalAlign=top;"); // insert a resource as a vertex resources.put(childNode, childResource); i++;