diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/InputEventCellEditor.java b/AlgebraicDataflowArchitectureModel/src/application/editor/InputEventCellEditor.java index 57ab5d2..e0ab458 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/InputEventCellEditor.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/InputEventCellEditor.java @@ -203,8 +203,7 @@ } } } - final double BASE_WIDTH = 200; - final double BASE_HEIGHT = BASE_WIDTH/2; + private mxGraph constructNextSimulateGraph(Set simulateRes, DataTransferModel model,DataFlowGraph dataFlowGraph, mxGraph nextGraph) { bReflectingArchitectureModel = true; ((mxGraphModel) nextGraph.getModel()).clear(); @@ -243,21 +242,21 @@ nextGraph.getModel().beginUpdate(); - SimulationLayout simulationLayout = new SimulationLayout(simulator.getCurState().getRootResources()); + 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); + double scale = simulationLayout.getScale(resNode.getResourceIdentifier()); double maxDiv = simulationLayout.maxDivisionLevel; - double w = BASE_WIDTH * scale /maxDiv; - double h = BASE_HEIGHT * scale /maxDiv; + double w = simulationLayout.BASE_WIDTH * scale /maxDiv; + double h = simulationLayout.BASE_HEIGHT * scale /maxDiv; - double division = simulationLayout.getDivision(resNode); - double w1 = 2*BASE_WIDTH/division; - double h1 = 2*BASE_HEIGHT/division; + 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 ; @@ -278,30 +277,18 @@ bReflectingArchitectureModel = false; return nextGraph; } - private void createNextChildSimulateResourceVerticies(Object resource, Resource resNode, Map resources, SimulationLayout layout) { //sample + 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) { - double width, height, maxDiv; - ResourcePath childRes ; - maxDiv = layout.maxDivisionLevel; - if(!layout.isExistResource(childNode)){ - width = layout.getScale(resNode) * BASE_WIDTH / maxDiv; - height = layout.getScale(resNode) * BASE_HEIGHT/ maxDiv; - childRes = childNode.getResourceIdentifier(); - }else{ - width = layout.getScale(childNode) * BASE_WIDTH / maxDiv; - height = layout.getScale(childNode) * BASE_HEIGHT/ maxDiv; - childRes = childNode.getResourceIdentifier(); - } + 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 +// 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); @@ -309,7 +296,7 @@ } } if (children == null || children.size() == 0) { - Object state = graph.insertVertex(resource, null, + 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 } } diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/SimulationLayout.java b/AlgebraicDataflowArchitectureModel/src/application/editor/SimulationLayout.java index 39c2255..c876581 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/SimulationLayout.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/SimulationLayout.java @@ -1,42 +1,48 @@ package application.editor; +import com.mxgraph.view.mxGraph; +import models.dataConstraintModel.ResourcePath; import simulator.Resource; import simulator.ResourceIdentifier; import simulator.Simulator; +import simulator.SystemState; import java.util.HashMap; +import java.util.List; import java.util.Set; public class SimulationLayout { //リソース毎の分割度を保持する - HashMap divisionLevelMap = new HashMap<>(); + HashMap divisionLevelMap = new HashMap<>(); //リソース毎の拡大倍率を保持する - HashMap resourceScaleMap = new HashMap<>(); + HashMap resourceScaleMap = new HashMap<>(); int maxDivisionLevel = 1; - public final double BASE_WIDTH = 100; + public final double BASE_WIDTH = 400; public final double BASE_HEIGHT = BASE_WIDTH/2; - public SimulationLayout(Set resources){ + SystemState systemState; + public SimulationLayout(SystemState systemState){ + this.systemState = systemState; //全リソースの分割度を計算 - for (Resource res:resources) { - setDivisionLevel(divisionLevelMap, res, 1); + for (Resource res:systemState.getRootResources()) { + setDivisionLevel(divisionLevelMap, res.getResourceIdentifier(), 1); } //リソース毎の表示倍率を決定 - for (Resource res:divisionLevelMap.keySet()) { + for (ResourceIdentifier res:divisionLevelMap.keySet()) { double scale = (double) maxDivisionLevel / divisionLevelMap.get(res); resourceScaleMap.put(res, scale); } } - public double getScale(Resource resource){ + public double getScale(ResourceIdentifier resource){ return resourceScaleMap.get(resource); } - public double getDivision(Resource resource){ + public double getDivision(ResourceIdentifier resource){ return divisionLevelMap.get(resource); } - public boolean isExistResource(Resource resource){ - return divisionLevelMap.containsKey(resource); + public boolean isExistResource(ResourceIdentifier resourceIdentifier){ + return divisionLevelMap.containsKey(resourceIdentifier); } - private void setDivisionLevel(HashMap resourceSet, Resource resource, int childCount){ + private void setDivisionLevel(HashMap resourceSet, ResourceIdentifier resource, int childCount){ int divisionLevel; if(resourceSet.get(resource.getParent()) == null){ divisionLevel = 1; @@ -45,11 +51,39 @@ } if (divisionLevel > maxDivisionLevel)maxDivisionLevel = divisionLevel; resourceSet.put(resource,divisionLevel); - if(resource.getChildren()!=null){ - for(Resource child:resource.getChildren()){ - setDivisionLevel(resourceSet, child, resource.getChildren().size()); + + List identifiers = systemState.getResource(resource).getChildren(); + if(identifiers!=null){ + for(Resource child:identifiers){ + setDivisionLevel(resourceSet, child.getResourceIdentifier(), identifiers.size()); } } } + public Object setLayout(mxGraph graph,Object parent, ResourceIdentifier resourceIdentifier,double index, double length){ + double width, height, maxDiv,x,y; + ResourceIdentifier parentIdentifier = ResourceIdentifier.createFrom(resourceIdentifier.getParent()); + maxDiv = maxDivisionLevel; + + + width = getScale(resourceIdentifier) * BASE_WIDTH / maxDiv; + height = getScale(resourceIdentifier) * BASE_HEIGHT/ maxDiv; + //x = width * (index - 1 - (length-1) / 2.0)*length; + + x = width * ((index-1)/length)*length; + + //if((int)getDivision(resourceIdentifier)==(int)getDivision(parentIdentifier)){ + if((int)length==1){ + y=20; + }else{ + y = (getScale(parentIdentifier)*BASE_HEIGHT/maxDiv)/2 - height/length; + // y = height/length; + } + + Object result = graph.insertVertex(parent, null, + resourceIdentifier.toString(), x, y, width, height, + "shape=ellipse;perimeter=ellipsePerimeter;verticalAlign=top;"); + System.out.println(result); + return result; + } }