Search in sources :

Example 1 with EdgeShape

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();
}
Also used : Randomizer(edu.rpi.graphdrawing.Randomizer) RubberBandRectShape(cbit.gui.graph.RubberBandRectShape) NodeShape(cbit.gui.graph.NodeShape) EdgeShape(cbit.gui.graph.EdgeShape) ContainerShape(cbit.gui.graph.ContainerShape) Shape(cbit.gui.graph.Shape) HashMap(java.util.HashMap) Node(edu.rpi.graphdrawing.Node) ArrayList(java.util.ArrayList) Cycleizer(edu.rpi.graphdrawing.Cycleizer) Embedder(edu.rpi.graphdrawing.Embedder) Annealer(edu.rpi.graphdrawing.Annealer) ForceDirect(edu.rpi.graphdrawing.ForceDirect) EdgeShape(cbit.gui.graph.EdgeShape) Circularizer(edu.rpi.graphdrawing.Circularizer) Relaxer(edu.rpi.graphdrawing.Relaxer) Node(edu.rpi.graphdrawing.Node) Point(java.awt.Point) Point(java.awt.Point) Stabilizer(edu.rpi.graphdrawing.Stabilizer) Leveller(edu.rpi.graphdrawing.Leveller) Blackboard(edu.rpi.graphdrawing.Blackboard)

Example 2 with EdgeShape

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);
    }
}
Also used : EdgeShape(cbit.gui.graph.EdgeShape) EdgeShape(cbit.gui.graph.EdgeShape) Shape(cbit.gui.graph.Shape) Set(java.util.Set) HashSet(java.util.HashSet) Map(java.util.Map)

Example 3 with EdgeShape

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);
}
Also used : PhysicalEntity(org.vcell.pathway.PhysicalEntity) EdgeShape(cbit.gui.graph.EdgeShape) Shape(cbit.gui.graph.Shape) BioPaxObject(org.vcell.pathway.BioPaxObject)

Example 4 with 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);
}
Also used : PhysicalEntity(org.vcell.pathway.PhysicalEntity) EdgeShape(cbit.gui.graph.EdgeShape) Shape(cbit.gui.graph.Shape) GroupNeighbor(org.vcell.pathway.GroupNeighbor) BioPaxObject(org.vcell.pathway.BioPaxObject)

Example 5 with 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;
}
Also used : EdgeShape(cbit.gui.graph.EdgeShape) EdgeShape(cbit.gui.graph.EdgeShape) ContainerShape(cbit.gui.graph.ContainerShape) Shape(cbit.gui.graph.Shape) Point(java.awt.Point)

Aggregations

EdgeShape (cbit.gui.graph.EdgeShape)5 Shape (cbit.gui.graph.Shape)5 ContainerShape (cbit.gui.graph.ContainerShape)2 Point (java.awt.Point)2 BioPaxObject (org.vcell.pathway.BioPaxObject)2 PhysicalEntity (org.vcell.pathway.PhysicalEntity)2 NodeShape (cbit.gui.graph.NodeShape)1 RubberBandRectShape (cbit.gui.graph.RubberBandRectShape)1 Annealer (edu.rpi.graphdrawing.Annealer)1 Blackboard (edu.rpi.graphdrawing.Blackboard)1 Circularizer (edu.rpi.graphdrawing.Circularizer)1 Cycleizer (edu.rpi.graphdrawing.Cycleizer)1 Embedder (edu.rpi.graphdrawing.Embedder)1 ForceDirect (edu.rpi.graphdrawing.ForceDirect)1 Leveller (edu.rpi.graphdrawing.Leveller)1 Node (edu.rpi.graphdrawing.Node)1 Randomizer (edu.rpi.graphdrawing.Randomizer)1 Relaxer (edu.rpi.graphdrawing.Relaxer)1 Stabilizer (edu.rpi.graphdrawing.Stabilizer)1 ArrayList (java.util.ArrayList)1