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++; diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/SimulationLayout.java b/AlgebraicDataflowArchitectureModel/src/application/editor/SimulationLayout.java new file mode 100644 index 0000000..c53aba7 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/SimulationLayout.java @@ -0,0 +1,55 @@ +package application.editor; + +import simulator.Resource; +import simulator.Simulator; + +import java.util.HashMap; +import java.util.Set; + +public class SimulationLayout { + //リソース毎の分割度を保持する + HashMap divisionLevelMap = new HashMap<>(); + //リソース毎の拡大倍率を保持する + HashMap resourceScaleMap = new HashMap<>(); + int maxDivisionLevel = 1; + public final double BASE_WIDTH = 100; + public final double BASE_HEIGHT = BASE_WIDTH/2; + public SimulationLayout(Set resources){ + //全リソースの分割度を計算 + for (Resource res:resources) { + setDivisionLevel(divisionLevelMap, res, 1); + } + //リソース毎の表示倍率を決定 + for (Resource res:divisionLevelMap.keySet()) { + double scale = (double) maxDivisionLevel / divisionLevelMap.get(res); + resourceScaleMap.put(res, scale); + } + } + public double getScale(Resource resource){ + return resourceScaleMap.get(resource); + } + public double getDivision(Resource resource){ + return divisionLevelMap.get(resource); + } + + public HashMap getResourceScaleMap() { + return resourceScaleMap; + } + + private void setDivisionLevel(HashMap resourceSet, Resource resource, int childCount){ + int divisionLevel; + if(resourceSet.get(resource.getParent()) == null){ + divisionLevel = 1; + }else{ + divisionLevel = resourceSet.get(resource.getParent()) * childCount; + } + if (divisionLevel > maxDivisionLevel)maxDivisionLevel = divisionLevel; + resourceSet.put(resource,divisionLevel); + if(resource.getChildren()!=null){ + for(Resource child:resource.getChildren()){ + setDivisionLevel(resourceSet, child, resource.getChildren().size()); + } + } + } + +}