diff --git a/AlgebraicDataflowArchitectureModel/src/application/SimulatorWindow.java b/AlgebraicDataflowArchitectureModel/src/application/SimulatorWindow.java index 509eaa6..0d2add1 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/SimulatorWindow.java +++ b/AlgebraicDataflowArchitectureModel/src/application/SimulatorWindow.java @@ -127,44 +127,10 @@ setVisible(true); simulator = new Simulator(this.editor.getModel()); - constructSimulateGraph(simulator); - graphComponent.setCellEditor(new InputEventCellEditor(graphComponent, simulator, this.editor, graph)); - } - mxGraph constructSimulateGraph(Simulator simulator){ - bReflectingArchitectureModel = true; - ((mxGraphModel) graph.getModel()).clear(); - Object parent = graph.getDefaultParent(); - graph.getModel().beginUpdate(); - SimulationLayout simulationLayout = new SimulationLayout(simulator.getCurState()); + SimulationLayout layout = new SimulationLayout(simulator.getCurState()); + layout.constructSimulateGraph(graph, simulator); - try { - Map resources = new HashMap<>(); - int i = 0; - // create resource vertices - for (Resource resNode: simulator.getCurState().getRootResources()) { - double scale = simulationLayout.getScale(resNode.getResourceIdentifier()); - double maxDiv = simulationLayout.getMaxDivisionLevel(); - double w = simulationLayout.BASE_WIDTH * scale /maxDiv; - double h = simulationLayout.BASE_HEIGHT * scale /maxDiv; - int childCount = simulator.getCurState().getRootResources().size(); - double x = w * (1 + i - childCount / 2.0); - double y = 20 ; - ResourcePath res = resNode.getResourceIdentifier(); - Object resource = graph.insertVertex(parent, null, - res.toString(), x, y, w, h, - "shape=ellipse;perimeter=ellipsePerimeter;verticalAlign=top;"); // insert a resource as a vertex - resources.put(resNode, resource); - i++; - createNextChildSimulateResourceVerticies(resource, resNode, resources, simulationLayout); - - } - - } finally { - graph.getModel().endUpdate(); - } - - bReflectingArchitectureModel = false; - return graph; + graphComponent.setCellEditor(new InputEventCellEditor(graphComponent, simulator, this.editor, graph)); } private void createNextChildSimulateResourceVerticies(Object parent, Resource resNode, Map resources, SimulationLayout layout) { //sample List children = resNode.getChildren(); diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/InputEventCellEditor.java b/AlgebraicDataflowArchitectureModel/src/application/editor/InputEventCellEditor.java index 9c9c048..1acd819 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/InputEventCellEditor.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/InputEventCellEditor.java @@ -169,9 +169,10 @@ Event newEvent = new Event(eventChs.get(eventNum), eventMessage, eventResPath, simulator.getCurState().getResource(resId)); simulator.transition(newEvent); - - constructNextSimulateGraph(simulator, simulator.getModel(),simulator.getModel().getDataFlowGraph(), graph); - //constructNextSimulateGraph(simulator.getCurState().getRootResources(), simulator.getModel(),simulator.getModel().getDataFlowGraph(), graph); + + SimulationLayout layout = new SimulationLayout(simulator.getCurState()); + layout.constructSimulateGraph(graph, simulator); + graphComponent.setCellEditor(new InputEventCellEditor(graphComponent, simulator, this.editor, graph)); } catch (ParameterizedIdentifierIsFutureWork | ResolvingMultipleDefinitionIsFutureWork @@ -235,71 +236,6 @@ 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()); - - try { - Map resources = new HashMap<>(); - int i = 0; - // create resource vertices - for (Resource resNode:simulator.getCurState().getRootResources()) { - double scale = simulationLayout.getScale(resNode.getResourceIdentifier()); - double maxDiv = simulationLayout.maxDivisionLevel; - double w = simulationLayout.BASE_WIDTH * scale /maxDiv; - double h = simulationLayout.BASE_HEIGHT * scale /maxDiv; - - double division = simulationLayout.getDivision(resNode.getResourceIdentifier()); - double w1 = 2*simulationLayout.BASE_WIDTH/division; - double h1 = 2*simulationLayout.BASE_HEIGHT/division; - int childCount = simulator.getCurState().getRootResources().size(); - double x = w * (1 + i - childCount / 2.0); - double y = 20 ; - ResourcePath res = resNode.getResourceIdentifier(); - Object resource = nextGraph.insertVertex(parent, null, - res.toString(), x, y, w, h, - "shape=ellipse;perimeter=ellipsePerimeter;verticalAlign=top;"); // insert a resource as a vertex - resources.put(resNode, resource); - i++; - createNextChildSimulateResourceVerticies(resource, resNode, resources, simulationLayout); - - } - - } finally { - nextGraph.getModel().endUpdate(); - } - - bReflectingArchitectureModel = false; - return nextGraph; - } - private void createNextChildSimulateResourceVerticies(Object parent, Resource resNode, Map resources, SimulationLayout layout) { //sample - List children = resNode.getChildren(); - if(children != null) { - //List children = resNode.getChildren(); - double i = 1; - double childCount = children.size(); - for (Resource childNode: children) { - Object childResource = layout.setLayout(graph, parent, childNode.getResourceIdentifier(), i, childCount); - -// Object childResource = graph.insertVertex(resource, null, -// childRes.toString(), width * (i - 1 - (childCount-1) / 2)*childCount, height/2, width, height, -// "shape=ellipse;perimeter=ellipsePerimeter;verticalAlign=top;"); // insert a resource as a vertex - resources.put(childNode, childResource); - i++; - createNextChildSimulateResourceVerticies(childResource, childNode, resources,layout); - - } - } - if (children == null || children.size() == 0) { - Object state = graph.insertVertex(parent, 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) { diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/SimulationLayout.java b/AlgebraicDataflowArchitectureModel/src/application/editor/SimulationLayout.java index a6e6502..d84c6a1 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/SimulationLayout.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/SimulationLayout.java @@ -1,5 +1,6 @@ package application.editor; +import com.mxgraph.model.mxGraphModel; import com.mxgraph.view.mxGraph; import models.dataConstraintModel.ResourcePath; import simulator.Resource; @@ -9,6 +10,7 @@ import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Set; public class SimulationLayout { @@ -86,4 +88,56 @@ return result; } + public mxGraph constructSimulateGraph(mxGraph graph, Simulator simulator){ + ((mxGraphModel) graph.getModel()).clear(); + Object parent = graph.getDefaultParent(); + graph.getModel().beginUpdate(); + + try { + Map resources = new HashMap<>(); + int i = 0; + // create resource vertices + for (Resource resNode: simulator.getCurState().getRootResources()) { + double scale = this.getScale(resNode.getResourceIdentifier()); + double maxDiv = this.getMaxDivisionLevel(); + double w = this.BASE_WIDTH * scale /maxDiv; + double h = this.BASE_HEIGHT * scale /maxDiv; + int childCount = simulator.getCurState().getRootResources().size(); + double x = w * (1 + i - childCount / 2.0); + double y = 20 ; + ResourcePath res = resNode.getResourceIdentifier(); + Object resource = graph.insertVertex(parent, null, + res.toString(), x, y, w, h, + "shape=ellipse;perimeter=ellipsePerimeter;verticalAlign=top;"); // insert a resource as a vertex + resources.put(resNode, resource); + i++; + createNextChildSimulateResourceVerticies(graph, resource, resNode, resources); + + } + + } finally { + graph.getModel().endUpdate(); + } + + return graph; + } + private void createNextChildSimulateResourceVerticies(mxGraph graph, Object parent, Resource resNode, Map resources) { //sample + List children = resNode.getChildren(); + if(children != null) { + //List children = resNode.getChildren(); + double i = 1; + double childCount = children.size(); + for (Resource childNode: children) { + Object childResource = setLayout(graph, parent, childNode.getResourceIdentifier(), i, childCount); + resources.put(childNode, childResource); + i++; + createNextChildSimulateResourceVerticies(graph, childResource, childNode, resources); + + } + } + if (children == null || children.size() == 0) { + Object state = graph.insertVertex(parent, 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 + } + } }