use of cbit.gui.graph.EdgeShape 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 cbit.gui.graph.EdgeShape in project vcell by virtualcell.
the class ShapeGroupUtil method addEdgeBundleShapes.
public static void addEdgeBundleShapes(GraphModel graphModel, Shape groupShape, Shape groupParentShape) {
Map<Shape, Set<EdgeShape>> connections = ShapeUtil.getExternalConnections(graphModel, groupShape);
for (Map.Entry<Shape, Set<EdgeShape>> entry : connections.entrySet()) {
Shape externalShape = entry.getKey();
Set<EdgeShape> edgeShapes = entry.getValue();
EdgeBundleShape edgeBundleShape = new EdgeBundleShape(graphModel, groupShape, externalShape, "", edgeShapes);
groupParentShape.addChildShape(edgeBundleShape);
graphModel.addShape(edgeBundleShape);
}
}
use of cbit.gui.graph.EdgeShape in project vcell by virtualcell.
the class PathwayGraphModel method refreshParticipant.
private void refreshParticipant(BioPaxInteractionShape interactionShape, InteractionParticipant participant) {
BioPaxInteractionParticipantShape edgeShape = (BioPaxInteractionParticipantShape) getShapeFromModelObject(participant);
PhysicalEntity physicalEntity = participant.getPhysicalEntity();
BioPaxObject ancestorObject = pathwayModel.findTopLevelGroupAncestor(physicalEntity);
if (edgeShape == null) {
Shape shape = getShapeFromModelObject(physicalEntity);
if (shape instanceof BioPaxPhysicalEntityShape) {
BioPaxPhysicalEntityShape physicalEntityShape = (BioPaxPhysicalEntityShape) shape;
edgeShape = new BioPaxInteractionParticipantShape(participant, interactionShape, physicalEntityShape, this);
pathwayContainerShape.addChildShape(edgeShape);
addShape(edgeShape);
}
} else {
// edges without end objects will be removed
if (ancestorObject != physicalEntity) {
removeEdgeShape(edgeShape);
}
}
unwantedShapes.remove(refreshGroup(pathwayContainerShape, ancestorObject, interactionShape, participant));
unwantedShapes.remove(edgeShape);
}
use of cbit.gui.graph.EdgeShape in project vcell by virtualcell.
the class PathwayGraphModel method refreshGroupInteraction.
private void refreshGroupInteraction(GroupObject groupObject, InteractionParticipant participant) {
BioPaxGroupShape groupShape = (BioPaxGroupShape) getShapeFromModelObject(groupObject);
PhysicalEntity physicalEntity = participant.getPhysicalEntity();
GroupNeighbor groupNeighbor = new GroupNeighbor(groupObject, physicalEntity, participant.getType());
BioPaxGroupNeighborShape edgeShape = (BioPaxGroupNeighborShape) getShapeFromModelObject(groupNeighbor);
BioPaxObject ancestorObject = pathwayModel.findTopLevelGroupAncestor(physicalEntity);
if (edgeShape == null) {
Shape shape = getShapeFromModelObject(physicalEntity);
if (shape instanceof BioPaxPhysicalEntityShape) {
BioPaxPhysicalEntityShape physicalEntityShape = (BioPaxPhysicalEntityShape) shape;
edgeShape = new BioPaxGroupNeighborShape(groupNeighbor, groupShape, physicalEntityShape, this);
pathwayContainerShape.addChildShape(edgeShape);
addShape(edgeShape);
}
} else {
// edges without end objects will be removed
if (ancestorObject != physicalEntity) {
// for grouped objects
removeEdgeShape(edgeShape);
}
}
unwantedShapes.remove(refreshGroup(pathwayContainerShape, ancestorObject, groupShape, participant));
unwantedShapes.remove(edgeShape);
}
use of cbit.gui.graph.EdgeShape in project vcell by virtualcell.
the class ReactionContainerShape method randomize.
public void randomize() {
// then draw in the reactionParticipant edges
for (Shape child : childShapeList) {
if (child instanceof SpeciesContextShape || child instanceof ReactionStepShape || child instanceof ReactionRuleDiagramShape || child instanceof RuleParticipantSignatureDiagramShape) {
// position normally about the center
child.getSpaceManager().setRelPos(getRandomPosition());
}
}
// calculate locations and sizes of reactionParticipant edges
for (Shape child : childShapeList) {
if (child instanceof ReactionParticipantShape || child instanceof RuleParticipantEdgeDiagramShape) {
EdgeShape reactionParticipantShape = (EdgeShape) child;
reactionParticipantShape.refreshLayoutSelf();
}
}
// position label
int centerX = getSpaceManager().getSize().width / 2;
int currentY = labelSize.height;
labelPos.x = centerX - labelSize.width / 2;
labelPos.y = currentY;
currentY += labelSize.height;
}
Aggregations