Search in sources :

Example 6 with Node

use of org.vcell.util.graphlayout.ContainedGraph.Node in project vcell by virtualcell.

the class VCellGraphToContainedGraphMapper method updateContainedGraphFromVCellGraph.

public void updateContainedGraphFromVCellGraph() {
    containedGraph.clear();
    for (Shape shape : vcellGraph.getShapes()) {
        GraphContainerLayout containerLayout = vcellGraph.getContainerLayout();
        if (containerLayout.isContainerForAutomaticLayout(shape)) {
            Rectangle boundary = containerLayout.getBoundaryForAutomaticLayout(shape);
            Container container = containedGraph.addContainer(shape, boundary.getX(), boundary.getY(), boundary.getWidth(), boundary.getHeight());
            for (Shape child : shape.getChildren()) {
                if (containerLayout.isNodeForAutomaticLayout(child)) {
                    Point absLoc = child.getSpaceManager().getAbsLoc();
                    Dimension size = child.getSpaceManager().getSize();
                    containedGraph.addNode(child, container, absLoc.getX(), absLoc.getY(), size.getWidth(), size.getHeight());
                }
            }
        }
    }
    for (Shape shape : vcellGraph.getShapes()) {
        if (shape instanceof EdgeShape) {
            EdgeShape edgeShape = (EdgeShape) shape;
            Node nodeStart = containedGraph.getNode(edgeShape.getStartShape());
            Node nodeEnd = containedGraph.getNode(edgeShape.getEndShape());
            if (nodeStart != null && nodeEnd != null) {
                containedGraph.addEdge(edgeShape, nodeStart, nodeEnd);
            }
        }
    }
}
Also used : Container(org.vcell.util.graphlayout.ContainedGraph.Container) Node(org.vcell.util.graphlayout.ContainedGraph.Node) Rectangle(java.awt.Rectangle) Point(java.awt.Point) Dimension(java.awt.Dimension)

Example 7 with Node

use of org.vcell.util.graphlayout.ContainedGraph.Node in project vcell by virtualcell.

the class VCellGraphToContainedGraphMapper method updateVCellGraphFromContainedGraph.

public void updateVCellGraphFromContainedGraph() {
    for (Node node : containedGraph.getNodes()) {
        Object object = node.getObject();
        if (object instanceof Shape) {
            Shape shape = (Shape) object;
            shape.getSpaceManager().setAbsLoc((int) node.getX(), (int) node.getY());
        }
    }
}
Also used : Node(org.vcell.util.graphlayout.ContainedGraph.Node)

Example 8 with Node

use of org.vcell.util.graphlayout.ContainedGraph.Node in project vcell by virtualcell.

the class StretchToBoundaryLayouter method layout.

public void layout(ContainedGraph graph, Container container) {
    Collection<? extends Node> containerNodes = graph.getContainerNodes(container);
    if (!containerNodes.isEmpty()) {
        Iterator<? extends Node> nodeIter = containerNodes.iterator();
        Node firstNode = nodeIter.next();
        double xMin = firstNode.getX();
        double yMin = firstNode.getY();
        double xMax = firstNode.getX() + firstNode.getWidth();
        double yMax = firstNode.getY() + firstNode.getHeight();
        if (containerNodes.size() > 2) {
            while (nodeIter.hasNext()) {
                Node node = nodeIter.next();
                double xMinNode = node.getX();
                double yMinNode = node.getY();
                double xMaxNode = node.getX() + node.getWidth();
                double yMaxNode = node.getY() + node.getHeight();
                if (xMinNode < xMin) {
                    xMin = xMinNode;
                }
                if (yMinNode < yMin) {
                    yMin = yMinNode;
                }
                if (xMaxNode > xMax) {
                    xMax = xMaxNode;
                }
                if (yMaxNode > yMax) {
                    yMax = yMaxNode;
                }
            }
            double xRange = xMax - xMin;
            if (xRange > 0) {
                for (Node node : containerNodes) {
                    double spaceNew = container.getWidth() - node.getWidth();
                    double spaceOld = xRange - node.getWidth();
                    if (spaceNew >= 0) {
                        node.setX(container.getX() + ((node.getX() - xMin) * spaceNew) / spaceOld);
                    }
                }
            }
            double yRange = yMax - yMin;
            if (yRange > 0) {
                for (Node node : containerNodes) {
                    double spaceNew = container.getHeight() - node.getHeight();
                    double spaceOld = yRange - node.getHeight();
                    if (spaceNew >= 0) {
                        node.setY(container.getY() + (int) (((node.getY() - yMin) * spaceNew) / spaceOld));
                    }
                }
            }
        } else {
            for (Node node : containerNodes) {
                if (node.getX() < container.getX()) {
                    node.setX(container.getX());
                } else {
                    double xMaxNode = container.getNodeMaxX(node);
                    if (node.getX() > xMaxNode) {
                        node.setX(xMaxNode);
                    }
                }
                if (node.getY() < container.getY()) {
                    node.setY(container.getY());
                } else {
                    double yMaxNode = container.getNodeMaxY(node);
                    if (node.getY() > yMaxNode) {
                        node.setY(yMaxNode);
                    }
                }
            }
        }
    }
}
Also used : Node(org.vcell.util.graphlayout.ContainedGraph.Node)

Example 9 with Node

use of org.vcell.util.graphlayout.ContainedGraph.Node in project vcell by virtualcell.

the class GenericLogicGraphLayouter method getOrAddEdge.

protected static void getOrAddEdge(ContainerContext context, Edge edge) {
    Node node1 = edge.getNode1();
    Node node2 = edge.getNode2();
    Container container = context.getContainer();
    if (container.equals(node1.getContainer()) && container.equals(node2.getContainer())) {
        GlgGraphEdge glgEdge = context.getEdgeMap().get(edge);
        if (glgEdge == null) {
            GlgGraphNode glgNode1 = getOrAddInternalNode(context, node1);
            GlgGraphNode glgNode2 = getOrAddInternalNode(context, node2);
            if (!context.getGlgGraph().NodesConnected(glgNode1, glgNode2)) {
                glgEdge = context.getGlgGraph().AddEdge(glgNode1, glgNode2, edge);
                context.getEdgeMap().put(edge, glgEdge);
            }
        }
    } else if (container.equals(node1.getContainer())) {
        GlgGraphEdge glgEdge = context.getEdgeMap().get(edge);
        if (glgEdge == null) {
            GlgGraphNode glgNode1 = getOrAddInternalNode(context, node1);
            GlgGraphNode glgNodeExternal2 = getOrAddExternalNode(context, node2, node1);
            if (!context.getGlgGraph().NodesConnected(glgNode1, glgNodeExternal2)) {
                glgEdge = context.getGlgGraph().AddEdge(glgNode1, glgNodeExternal2, edge);
                context.getEdgeMap().put(edge, glgEdge);
            }
        }
    } else if (container.equals(node2.getContainer())) {
        GlgGraphEdge glgEdge = context.getEdgeMap().get(edge);
        if (glgEdge == null) {
            GlgGraphNode glgNodeExternal1 = getOrAddExternalNode(context, node1, node2);
            GlgGraphNode glgNode2 = getOrAddInternalNode(context, node2);
            if (!context.getGlgGraph().NodesConnected(glgNodeExternal1, glgNode2)) {
                glgEdge = context.getGlgGraph().AddEdge(glgNode2, glgNodeExternal1, edge);
                context.getEdgeMap().put(edge, glgEdge);
            }
        }
    }
}
Also used : Container(org.vcell.util.graphlayout.ContainedGraph.Container) Node(org.vcell.util.graphlayout.ContainedGraph.Node)

Example 10 with Node

use of org.vcell.util.graphlayout.ContainedGraph.Node in project vcell by virtualcell.

the class ShootAndCutMinimizer method minimize.

public void minimize(EnergySum energySum) {
    ContainedGraph graph = energySum.getGraph();
    for (Node node : graph.getNodes()) {
        double shiftX = ContainedGraphUtil.getRandomShiftX(node, random);
        double shiftY = ContainedGraphUtil.getRandomShiftY(node, random);
        while (Math.abs(shiftX) + Math.abs(shiftY) > 0.3) {
            NodesShift nodesShift = new NodesShift.SingleNode(graph, node, shiftX, shiftY);
            if (energySum.getDifference(nodesShift) < 0) {
                nodesShift.apply();
                break;
            }
            shiftX = (1 - cut) * shiftX;
            shiftY = (1 - cut) * shiftY;
        }
    }
}
Also used : NodesShift(org.vcell.util.graphlayout.NodesShift) Node(org.vcell.util.graphlayout.ContainedGraph.Node) ContainedGraph(org.vcell.util.graphlayout.ContainedGraph)

Aggregations

Node (org.vcell.util.graphlayout.ContainedGraph.Node)11 Container (org.vcell.util.graphlayout.ContainedGraph.Container)5 ContainedGraph (org.vcell.util.graphlayout.ContainedGraph)2 Edge (org.vcell.util.graphlayout.ContainedGraph.Edge)2 NodesShift (org.vcell.util.graphlayout.NodesShift)2 ReactionRuleDiagramShape (cbit.vcell.graph.ReactionRuleDiagramShape)1 ReactionStepShape (cbit.vcell.graph.ReactionStepShape)1 RuleParticipantSignatureDiagramShape (cbit.vcell.graph.RuleParticipantSignatureDiagramShape)1 SpeciesContextShape (cbit.vcell.graph.SpeciesContextShape)1 Dimension (java.awt.Dimension)1 Point (java.awt.Point)1 Rectangle (java.awt.Rectangle)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 SetOfTwo (org.sbpax.util.sets.SetOfTwo)1 ListOfTwo (org.vcell.sybil.util.lists.ListOfTwo)1 Vector2D (org.vcell.util.geometry2d.Vector2D)1 EnergyTerm (org.vcell.util.graphlayout.energybased.EnergySum.EnergyTerm)1