use of edu.rpi.graphdrawing.Blackboard in project vcell by virtualcell.
the class WorkflowCartoonTool method layout.
public void layout(String layoutName) throws Exception {
Blackboard bb = new Blackboard();
HashMap<String, Shape> nodeShapeMap = new HashMap<String, Shape>();
// add nodes
boolean bHasSelections = getGraphModel().getSelectedShape() != null;
ArrayList<Shape> vcellShapeList = new ArrayList<Shape>();
for (Shape shape : getGraphModel().getShapes()) {
vcellShapeList.add(shape);
edu.rpi.graphdrawing.Node newNode = null;
if (ShapeUtil.isMovable(shape)) {
if (!bHasSelections || shape.isSelected()) {
String shapeIndexStr = "node" + Integer.toString(vcellShapeList.indexOf(shape));
newNode = bb.addNode(shapeIndexStr);
}
}
// initialize node location to current absolute position
if (newNode != null) {
newNode.XY(shape.getSpaceManager().getAbsLoc().x, shape.getSpaceManager().getAbsLoc().y);
nodeShapeMap.put(newNode.label(), shape);
}
}
for (Shape shape : getGraphModel().getShapes()) {
if (shape instanceof EdgeShape) {
EdgeShape eShape = (EdgeShape) shape;
Shape node1Shape = eShape.getStartShape();
Shape node2Shape = eShape.getEndShape();
if (!bHasSelections || (node1Shape.isSelected() && node2Shape.isSelected())) {
String node1IndexStr = "node" + Integer.toString(vcellShapeList.indexOf(node1Shape));
String node2IndexStr = "node" + Integer.toString(vcellShapeList.indexOf(node2Shape));
bb.addEdge(node1IndexStr, node2IndexStr);
}
}
}
bb.setArea(0, 0, getGraphPane().getWidth(), getGraphPane().getHeight());
bb.globals.D(20);
bb.addEmbedder(GraphLayoutManager.OldLayouts.ANNEALER, new Annealer(bb));
bb.addEmbedder(GraphLayoutManager.OldLayouts.CIRCULARIZER, new Circularizer(bb));
bb.addEmbedder(GraphLayoutManager.OldLayouts.CYCLEIZER, new Cycleizer(bb));
bb.addEmbedder(GraphLayoutManager.OldLayouts.FORCEDIRECT, new ForceDirect(bb));
bb.addEmbedder(GraphLayoutManager.OldLayouts.LEVELLER, new Leveller(bb));
bb.addEmbedder(GraphLayoutManager.OldLayouts.RANDOMIZER, new Randomizer(bb));
bb.addEmbedder(GraphLayoutManager.OldLayouts.RELAXER, new Relaxer(bb));
bb.addEmbedder(GraphLayoutManager.OldLayouts.STABILIZER, new Stabilizer(bb));
bb.setEmbedding(layoutName);
@SuppressWarnings("unchecked") List<Node> nodeList = bb.nodes();
for (int i = 0; i < nodeList.size(); i++) {
Node node = nodeList.get(i);
System.out.println("Node " + node.label() + " @ (" + node.x() + "," + node.y() + ")");
}
bb.PreprocessNodes();
Embedder embedder = bb.embedder();
embedder.Init();
for (int i = 0; i < 1000; i++) {
embedder.Embed();
}
bb.removeDummies();
@SuppressWarnings("unchecked") Vector<Node> nodes = bb.nodes();
nodeList = nodes;
//
// calculate offset and scaling so that resulting graph fits on canvas
//
double lowX = 100000;
double highX = -100000;
double lowY = 100000;
double highY = -100000;
for (int i = 0; i < nodeList.size(); i++) {
Node node = nodeList.get(i);
lowX = Math.min(lowX, node.x());
highX = Math.max(highX, node.x());
lowY = Math.min(lowY, node.y());
highY = Math.max(highY, node.y());
}
double scaleX = getGraphPane().getWidth() / (1.5 * (highX - lowX));
double scaleY = getGraphPane().getHeight() / (1.5 * (highY - lowY));
int offsetX = getGraphPane().getWidth() / 6;
int offsetY = getGraphPane().getHeight() / 6;
for (int i = 0; i < nodeList.size(); i++) {
Node node = nodeList.get(i);
Shape shape = nodeShapeMap.get(node.label());
Point parentLoc = shape.getParent().getSpaceManager().getAbsLoc();
shape.getSpaceManager().setAbsLoc(new Point((int) (scaleX * (node.x() - lowX)) + offsetX + parentLoc.x, (int) ((scaleY * (node.y() - lowY)) + offsetY + parentLoc.y)));
System.out.println("Shape " + shape.getLabel() + " @ " + shape.getSpaceManager().getAbsLoc());
}
getGraphPane().repaint();
}
use of edu.rpi.graphdrawing.Blackboard in project vcell by virtualcell.
the class GraphLayoutManager method layoutRPI.
public void layoutRPI(Client client) throws Exception {
Blackboard bb = new Blackboard();
HashMap<String, Shape> nodeShapeMap = new HashMap<String, Shape>();
for (Shape shape : client.getGraphModel().getShapes()) {
Node newNode = null;
if (ShapeUtil.isMovable(shape)) {
newNode = bb.addNode(shape.getLabel());
}
// initialize node location to current absolute position
if (newNode != null) {
newNode.XY(shape.getSpaceManager().getAbsLoc().x, shape.getSpaceManager().getAbsLoc().y);
nodeShapeMap.put(newNode.label(), shape);
}
}
for (Shape shape : client.getGraphModel().getShapes()) {
if (shape instanceof EdgeShape) {
EdgeShape edgeShape = (EdgeShape) shape;
Shape startShape = edgeShape.getStartShape();
Shape endShape = edgeShape.getEndShape();
if (edgeShape.isDirectedForward()) {
bb.addEdge(startShape.getLabel(), endShape.getLabel());
} else {
bb.addEdge(endShape.getLabel(), startShape.getLabel());
}
}
}
bb.setArea(0, 0, client.getWidth(), client.getHeight());
bb.globals.D(20);
bb.addEmbedder(GraphLayoutManager.OldLayouts.ANNEALER, new Annealer(bb));
bb.addEmbedder(GraphLayoutManager.OldLayouts.CIRCULARIZER, new Circularizer(bb));
bb.addEmbedder(GraphLayoutManager.OldLayouts.CYCLEIZER, new Cycleizer(bb));
bb.addEmbedder(GraphLayoutManager.OldLayouts.FORCEDIRECT, new ForceDirect(bb));
bb.addEmbedder(GraphLayoutManager.OldLayouts.LEVELLER, new Leveller(bb));
bb.addEmbedder(GraphLayoutManager.OldLayouts.RANDOMIZER, new Randomizer(bb));
bb.addEmbedder(GraphLayoutManager.OldLayouts.RELAXER, new Relaxer(bb));
bb.addEmbedder(GraphLayoutManager.OldLayouts.STABILIZER, new Stabilizer(bb));
bb.setEmbedding(client.getLayoutName());
@SuppressWarnings("unchecked") List<Node> nodeList = bb.nodes();
bb.PreprocessNodes();
Embedder embedder = bb.embedder();
embedder.Init();
for (int i = 0; i < 1000; i++) {
embedder.Embed();
}
bb.removeDummies();
@SuppressWarnings("unchecked") List<Node> nodesRaw = bb.nodes();
nodeList = nodesRaw;
for (int i = 0; i < nodeList.size(); i++) {
Node node = nodeList.get(i);
Shape shape = nodeShapeMap.get(node.label());
if (shape != null) {
shape.setAbsPos((int) node.x(), (int) node.y());
}
}
new StretchToBoundaryLayouter().layout(client);
}
Aggregations