diff --git a/AlgebraicDataflowArchitectureModel/src/application/SimulatorWindow.java b/AlgebraicDataflowArchitectureModel/src/application/SimulatorWindow.java index 37aeefe..509eaa6 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/SimulatorWindow.java +++ b/AlgebraicDataflowArchitectureModel/src/application/SimulatorWindow.java @@ -12,6 +12,7 @@ import javax.swing.JFrame; +import application.editor.SimulationLayout; import com.mxgraph.model.mxCell; import com.mxgraph.model.mxGeometry; import com.mxgraph.model.mxGraphModel; @@ -126,20 +127,73 @@ setVisible(true); simulator = new Simulator(this.editor.getModel()); - constructSimulateGraph(simulator.getCurState().getRootResources(), this.editor.getModel(),this.editor.getDataFlowGraph()); + 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()); + + 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; + } + 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); + 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 + } + } public mxGraph constructSimulateGraph(Set simulateRes, DataTransferModel model, DataFlowGraph dataFlowGraph) { bReflectingArchitectureModel = true; ((mxGraphModel) graph.getModel()).clear(); Object parent = graph.getDefaultParent(); graph.getModel().beginUpdate(); - + try { Map resources = new HashMap<>(); - + // create resource vertices for (Resource resNode: simulateRes) { int w = 80; @@ -152,11 +206,11 @@ createChildSimulateResourceVerticies(resource, resNode, resources, w, h); x+=80; } - + } finally { graph.getModel().endUpdate(); } - + bReflectingArchitectureModel = false; return graph; }