Search in sources :

Example 1 with LongEnumerator

use of org.cytoscape.util.intr.LongEnumerator in project cytoscape-impl by cytoscape.

the class InnerCanvas method toggleSelectedEdge.

private int toggleSelectedEdge(long chosenEdge, MouseEvent e) {
    int chosenEdgeSelected = 0;
    final boolean wasSelected = m_view.getDEdgeView(chosenEdge).isSelected();
    // Linux users should use Ctrl-Alt since many window managers capture Alt-drag to move windows
    if ((e.isAltDown()) && ((m_lastRenderDetail & GraphRenderer.LOD_EDGE_ANCHORS) != 0)) {
        m_view.m_selectedAnchors.empty();
        m_ptBuff[0] = m_lastXMousePos;
        m_ptBuff[1] = m_lastYMousePos;
        m_view.xformComponentToNodeCoords(m_ptBuff);
        // Store current handle list
        m_undoable_edit = new ViewChangeEdit(m_view, ViewChangeEdit.SavedObjs.SELECTED_EDGES, "Add Edge Handle", serviceRegistrar);
        final Point2D newHandlePoint = new Point2D.Float((float) m_ptBuff[0], (float) m_ptBuff[1]);
        DEdgeView edgeView = m_view.getDEdgeView(chosenEdge);
        Bend defaultBend = edgeView.getDefaultValue(BasicVisualLexicon.EDGE_BEND);
        if (edgeView.getVisualProperty(BasicVisualLexicon.EDGE_BEND) == defaultBend) {
            if (defaultBend instanceof BendImpl)
                edgeView.setLockedValue(BasicVisualLexicon.EDGE_BEND, new BendImpl((BendImpl) defaultBend));
            else
                edgeView.setLockedValue(BasicVisualLexicon.EDGE_BEND, new BendImpl());
        }
        DEdgeView ev = m_view.getDEdgeView(chosenEdge);
        final int chosenInx = ev.addHandlePoint(newHandlePoint);
        m_view.m_selectedAnchors.insert(((chosenEdge) << 6) | chosenInx);
    }
    // Ignore Ctrl if Alt is down so that Ctrl-Alt can be used for edge bends without side effects
    if (wasSelected && (e.isShiftDown() || (isControlOrMetaDown(e) && !e.isAltDown()))) {
        // ((DEdgeView) m_view.getDEdgeView(chosenEdge)).unselectInternal();
        chosenEdgeSelected = -1;
    } else if (!wasSelected) {
        // ((DEdgeView) m_view.getDEdgeView(chosenEdge)).selectInternal(false);
        chosenEdgeSelected = 1;
        if ((m_lastRenderDetail & GraphRenderer.LOD_EDGE_ANCHORS) != 0) {
            m_ptBuff[0] = m_lastXMousePos;
            m_ptBuff[1] = m_lastYMousePos;
            m_view.xformComponentToNodeCoords(m_ptBuff);
            final LongEnumerator hits = m_view.m_spacialA.queryOverlap((float) m_ptBuff[0], (float) m_ptBuff[1], (float) m_ptBuff[0], (float) m_ptBuff[1], null, 0, false);
            if (hits.numRemaining() > 0) {
                final long hit = hits.nextLong();
                if (m_view.m_selectedAnchors.count(hit) == 0)
                    m_view.m_selectedAnchors.insert(hit);
            }
        }
    }
    m_button1NodeDrag = true;
    m_view.setContentChanged();
    return chosenEdgeSelected;
}
Also used : ViewChangeEdit(org.cytoscape.ding.ViewChangeEdit) LongEnumerator(org.cytoscape.util.intr.LongEnumerator) Point2D(java.awt.geom.Point2D) Bend(org.cytoscape.view.presentation.property.values.Bend) Point(java.awt.Point)

Example 2 with LongEnumerator

use of org.cytoscape.util.intr.LongEnumerator in project cytoscape-impl by cytoscape.

the class InnerCanvas method setSelectedEdges.

private long[] setSelectedEdges() {
    long[] selectedEdges = null;
    if ((m_lastRenderDetail & GraphRenderer.LOD_EDGE_ANCHORS) != 0) {
        m_ptBuff[0] = m_selectionRect.x;
        m_ptBuff[1] = m_selectionRect.y;
        m_view.xformComponentToNodeCoords(m_ptBuff);
        final double xMin = m_ptBuff[0];
        final double yMin = m_ptBuff[1];
        m_ptBuff[0] = m_selectionRect.x + m_selectionRect.width;
        m_ptBuff[1] = m_selectionRect.y + m_selectionRect.height;
        m_view.xformComponentToNodeCoords(m_ptBuff);
        final double xMax = m_ptBuff[0];
        final double yMax = m_ptBuff[1];
        final LongEnumerator hits = m_view.m_spacialA.queryOverlap((float) xMin, (float) yMin, (float) xMax, (float) yMax, null, 0, false);
        if (hits.numRemaining() > 0)
            m_view.setContentChanged();
        while (hits.numRemaining() > 0) {
            final long hit = hits.nextLong();
            if (m_view.m_selectedAnchors.count(hit) == 0)
                m_view.m_selectedAnchors.insert(hit);
        }
    }
    computeEdgesIntersecting(m_selectionRect.x, m_selectionRect.y, m_selectionRect.x + m_selectionRect.width, m_selectionRect.y + m_selectionRect.height, m_stack2);
    m_stack.empty();
    final LongEnumerator edgesXSect = m_stack2.elements();
    while (edgesXSect.numRemaining() > 0) {
        final long edgeXSect = edgesXSect.nextLong();
        if (m_view.m_selectedEdges.count(edgeXSect) == 0)
            m_stack.push(edgeXSect);
    }
    selectedEdges = new long[m_stack.size()];
    final LongEnumerator edges = m_stack.elements();
    for (int i = 0; i < selectedEdges.length; i++) selectedEdges[i] = edges.nextLong();
    if (selectedEdges.length > 0)
        m_view.setContentChanged();
    return selectedEdges;
}
Also used : LongEnumerator(org.cytoscape.util.intr.LongEnumerator) Point(java.awt.Point)

Example 3 with LongEnumerator

use of org.cytoscape.util.intr.LongEnumerator in project cytoscape-impl by cytoscape.

the class InnerCanvas method computeEdgesIntersecting.

// Puts [last drawn] edges intersecting onto stack; as RootGraph indices.
// Depends on the state of several member variables, such as m_hash.
// Clobbers m_stack and m_ptBuff.
// The rectangle extents are in component coordinate space.
// IMPORTANT: Code that calls this method should be holding m_lock.
final void computeEdgesIntersecting(final int xMini, final int yMini, final int xMaxi, final int yMaxi, final LongStack stack) {
    m_ptBuff[0] = xMini;
    m_ptBuff[1] = yMini;
    m_view.xformComponentToNodeCoords(m_ptBuff);
    final double xMin = m_ptBuff[0];
    final double yMin = m_ptBuff[1];
    m_ptBuff[0] = xMaxi;
    m_ptBuff[1] = yMaxi;
    m_view.xformComponentToNodeCoords(m_ptBuff);
    final double xMax = m_ptBuff[0];
    final double yMax = m_ptBuff[1];
    // Positive.
    LongEnumerator edgeNodesEnum = m_hash.elements();
    m_stack.empty();
    final int edgeNodesCount = edgeNodesEnum.numRemaining();
    for (int i = 0; i < edgeNodesCount; i++) m_stack.push(edgeNodesEnum.nextLong());
    m_hash.empty();
    edgeNodesEnum = m_stack.elements();
    stack.empty();
    final CyNetwork graph = m_view.m_drawPersp;
    if ((m_lastRenderDetail & GraphRenderer.LOD_HIGH_DETAIL) == 0) {
        // We won't need to look up arrows and their sizes.
        for (int i = 0; i < edgeNodesCount; i++) {
            // Positive.
            final long node = edgeNodesEnum.nextLong();
            final CyNode nodeObj = graph.getNode(node);
            if (!m_view.m_spacial.exists(node, m_view.m_extentsBuff, 0))
                // Will happen if e.g. node was removed.
                continue;
            final float nodeX = (m_view.m_extentsBuff[0] + m_view.m_extentsBuff[2]) / 2;
            final float nodeY = (m_view.m_extentsBuff[1] + m_view.m_extentsBuff[3]) / 2;
            final Iterable<CyEdge> touchingEdges = graph.getAdjacentEdgeIterable(nodeObj, CyEdge.Type.ANY);
            for (CyEdge e : touchingEdges) {
                final long edge = e.getSUID();
                final long otherNode = node ^ e.getSource().getSUID().longValue() ^ e.getTarget().getSUID().longValue();
                if (m_hash.get(otherNode) < 0) {
                    m_view.m_spacial.exists(otherNode, m_view.m_extentsBuff, 0);
                    final float otherNodeX = (m_view.m_extentsBuff[0] + m_view.m_extentsBuff[2]) / 2;
                    final float otherNodeY = (m_view.m_extentsBuff[1] + m_view.m_extentsBuff[3]) / 2;
                    m_line.setLine(nodeX, nodeY, otherNodeX, otherNodeY);
                    if (m_line.intersects(xMin, yMin, xMax - xMin, yMax - yMin))
                        stack.push(edge);
                }
            }
            m_hash.put(node);
        }
    } else {
        // Last render high detail.
        for (int i = 0; i < edgeNodesCount; i++) {
            // Positive.
            final long node = edgeNodesEnum.nextLong();
            final CyNode nodeObj = graph.getNode(node);
            if (!m_view.m_spacial.exists(node, m_view.m_extentsBuff, 0))
                continue;
            /* Will happen if e.g. node was removed. */
            final byte nodeShape = m_view.m_nodeDetails.getShape(nodeObj);
            final Iterable<CyEdge> touchingEdges = graph.getAdjacentEdgeIterable(nodeObj, CyEdge.Type.ANY);
            for (CyEdge edge : touchingEdges) {
                // final int edge = e.getIndex(); // Positive.
                final double segThicknessDiv2 = m_view.m_edgeDetails.getWidth(edge) / 2.0d;
                final long otherNode = node ^ edge.getSource().getSUID().longValue() ^ edge.getTarget().getSUID().longValue();
                final CyNode otherNodeObj = graph.getNode(otherNode);
                if (m_hash.get(otherNode) < 0) {
                    m_view.m_spacial.exists(otherNode, m_extentsBuff2, 0);
                    final byte otherNodeShape = m_view.m_nodeDetails.getShape(otherNodeObj);
                    final byte srcShape;
                    final byte trgShape;
                    final float[] srcExtents;
                    final float[] trgExtents;
                    if (node == edge.getSource().getSUID().longValue()) {
                        srcShape = nodeShape;
                        trgShape = otherNodeShape;
                        srcExtents = m_view.m_extentsBuff;
                        trgExtents = m_extentsBuff2;
                    } else {
                        // node == graph.edgeTarget(edge).
                        srcShape = otherNodeShape;
                        trgShape = nodeShape;
                        srcExtents = m_extentsBuff2;
                        trgExtents = m_view.m_extentsBuff;
                    }
                    final ArrowShape srcArrow;
                    final ArrowShape trgArrow;
                    final float srcArrowSize;
                    final float trgArrowSize;
                    if ((m_lastRenderDetail & GraphRenderer.LOD_EDGE_ARROWS) == 0) {
                        srcArrow = trgArrow = ArrowShapeVisualProperty.NONE;
                        srcArrowSize = trgArrowSize = 0.0f;
                    } else {
                        srcArrow = m_view.m_edgeDetails.getSourceArrowShape(edge);
                        trgArrow = m_view.m_edgeDetails.getTargetArrowShape(edge);
                        srcArrowSize = ((srcArrow == ArrowShapeVisualProperty.NONE) ? 0.0f : m_view.m_edgeDetails.getSourceArrowSize(edge));
                        trgArrowSize = ((trgArrow == ArrowShapeVisualProperty.NONE) ? 0.0f : m_view.m_edgeDetails.getTargetArrowSize(edge));
                    }
                    final EdgeAnchors anchors = (((m_lastRenderDetail & GraphRenderer.LOD_EDGE_ANCHORS) == 0) ? null : m_view.m_edgeDetails.getAnchors(edge));
                    if (!GraphRenderer.computeEdgeEndpoints(m_grafx, srcExtents, srcShape, srcArrow, srcArrowSize, anchors, trgExtents, trgShape, trgArrow, trgArrowSize, m_floatBuff1, m_floatBuff2))
                        continue;
                    m_grafx.getEdgePath(srcArrow, srcArrowSize, trgArrow, trgArrowSize, m_floatBuff1[0], m_floatBuff1[1], anchors, m_floatBuff2[0], m_floatBuff2[1], m_path);
                    GraphRenderer.computeClosedPath(m_path.getPathIterator(null), m_path2);
                    if (m_path2.intersects(xMin - segThicknessDiv2, yMin - segThicknessDiv2, (xMax - xMin) + (segThicknessDiv2 * 2), (yMax - yMin) + (segThicknessDiv2 * 2)))
                        stack.push(edge.getSUID().longValue());
                }
            }
            m_hash.put(node);
        }
    }
}
Also used : EdgeAnchors(org.cytoscape.graph.render.immed.EdgeAnchors) CyNetwork(org.cytoscape.model.CyNetwork) CyEdge(org.cytoscape.model.CyEdge) Point(java.awt.Point) LongEnumerator(org.cytoscape.util.intr.LongEnumerator) ArrowShape(org.cytoscape.view.presentation.property.values.ArrowShape) CyNode(org.cytoscape.model.CyNode)

Example 4 with LongEnumerator

use of org.cytoscape.util.intr.LongEnumerator in project cytoscape-impl by cytoscape.

the class DEdgeDetails method getAnchors.

@Override
public EdgeAnchors getAnchors(final CyEdge edge) {
    final DEdgeView edgeView = (DEdgeView) dGraphView.getDEdgeView(edge);
    if (edgeView == null)
        return null;
    final EdgeAnchors returnThis = edgeView;
    if (returnThis.numAnchors() > 0)
        return returnThis;
    final CyNetwork graph = dGraphView.m_drawPersp;
    final long srcNodeIndex = edgeView.getModel().getSource().getSUID();
    final long trgNodeIndex = edgeView.getModel().getTarget().getSUID();
    // Calculate anchors necessary for self edges.
    if (srcNodeIndex == trgNodeIndex) {
        dGraphView.m_spacial.exists(srcNodeIndex, m_extentsBuff, 0);
        final double w = ((double) m_extentsBuff[2]) - m_extentsBuff[0];
        final double h = ((double) m_extentsBuff[3]) - m_extentsBuff[1];
        final double x = (((double) m_extentsBuff[0]) + m_extentsBuff[2]) / 2.0d;
        final double y = (((double) m_extentsBuff[1]) + m_extentsBuff[3]) / 2.0d;
        final double nodeSize = Math.max(w, h);
        int i = 0;
        final List<CyEdge> selfEdgeList = graph.getConnectingEdgeList(edgeView.getModel().getSource(), edgeView.getModel().getSource(), CyEdge.Type.ANY);
        for (final CyEdge selfEdge : selfEdgeList) {
            // while (selfEdges.hasNext())
            // final int e2 = selfEdges.nextInt();
            final long e2 = selfEdge.getSUID();
            if (e2 == edge.getSUID())
                break;
            if (((EdgeAnchors) dGraphView.getDEdgeView(e2)).numAnchors() == 0)
                i++;
        }
        final int inx = i;
        return new EdgeAnchors() {

            @Override
            public int numAnchors() {
                return 2;
            }

            @Override
            public void getAnchor(int anchorInx, float[] anchorArr, int offset) {
                if (anchorInx == 0) {
                    anchorArr[offset] = (float) (x - (((inx + 3) * nodeSize) / 2.0d));
                    anchorArr[offset + 1] = (float) y;
                } else if (anchorInx == 1) {
                    anchorArr[offset] = (float) x;
                    anchorArr[offset + 1] = (float) (y - (((inx + 3) * nodeSize) / 2.0d));
                }
            }
        };
    }
    // exist between two nodes. This has no effect if user specified anchors exist on the edge.
    while (true) {
        // By consistently ordering the source and target nodes, dx and dy
        // will always
        // be calculated according to the same orientation. This allows the
        // offset
        // calculation to toggle the edges from side to side without any
        // overlap.
        final long tmpSrcIndex = Math.min(srcNodeIndex, trgNodeIndex);
        final long tmpTrgIndex = Math.max(srcNodeIndex, trgNodeIndex);
        // Sort the connecting edges.
        final CyNode tmpSrc = graph.getNode(tmpSrcIndex);
        final CyNode tmpTrg = graph.getNode(tmpTrgIndex);
        final List<CyEdge> conEdgeList = graph.getConnectingEdgeList(tmpSrc, tmpTrg, CyEdge.Type.ANY);
        // final IntIterator conEdges = graph.edgesConnecting(tmpSrc,
        // tmpTrg,
        // true, true, true);
        m_heap.empty();
        for (final CyEdge conEdge : conEdgeList) {
            // while (conEdges.hasNext())
            // m_heap.toss(conEdges.nextInt());
            m_heap.toss(conEdge.getSUID());
        }
        final LongEnumerator otherEdges = m_heap.orderedElements(false);
        long otherEdge = otherEdges.nextLong();
        // (i.e. we're at the end of the list?).
        if (otherEdge == edge.getSUID())
            break;
        // So we don't count the other edge twice?
        DEdgeView otherEdgeView = dGraphView.getDEdgeView(otherEdge);
        if (otherEdgeView == null)
            continue;
        int i = (((EdgeAnchors) otherEdgeView).numAnchors() == 0) ? 1 : 0;
        // Count the number of other edges.
        while (true) {
            if (edge.getSUID() == (otherEdge = otherEdges.nextLong()) || otherEdge == -1)
                break;
            if (((EdgeAnchors) otherEdgeView).numAnchors() == 0)
                i++;
        }
        final int inx = i;
        // Get source node size and position.
        dGraphView.m_spacial.exists(tmpSrcIndex, m_extentsBuff, 0);
        final double srcW = ((double) m_extentsBuff[2]) - m_extentsBuff[0];
        final double srcH = ((double) m_extentsBuff[3]) - m_extentsBuff[1];
        final double srcX = (((double) m_extentsBuff[0]) + m_extentsBuff[2]) / 2.0d;
        final double srcY = (((double) m_extentsBuff[1]) + m_extentsBuff[3]) / 2.0d;
        // Get target node size and position.
        dGraphView.m_spacial.exists(tmpTrgIndex, m_extentsBuff, 0);
        final double trgW = ((double) m_extentsBuff[2]) - m_extentsBuff[0];
        final double trgH = ((double) m_extentsBuff[3]) - m_extentsBuff[1];
        final double trgX = (((double) m_extentsBuff[0]) + m_extentsBuff[2]) / 2.0d;
        final double trgY = (((double) m_extentsBuff[1]) + m_extentsBuff[3]) / 2.0d;
        // Used for determining the space between the edges.
        final double nodeSize = Math.max(Math.max(Math.max(srcW, srcH), trgW), trgH);
        // Midpoint between nodes.
        final double midX = (srcX + trgX) / 2;
        final double midY = (srcY + trgY) / 2;
        // Distance in X and Y dimensions.
        // Note that dx and dy may be negative. This is OK, because this will ensure
        // that the handle is always correctly placed offset from the midpoint of,
        // and perpendicular to, the original edge.
        final double dx = trgX - srcX;
        final double dy = trgY - srcY;
        // Distance or length between nodes.
        final double len = Math.sqrt((dx * dx) + (dy * dy));
        if (((float) len) == 0.0f)
            break;
        // This determines which side of the first edge and how far from the first
        // edge the other edge should be placed.
        // - Divide by 2 puts consecutive edges at the same distance from the center because of integer math.
        // - Modulo puts consecutive edges on opposite sides.
        // - Node size is for consistent scaling.
        final double offset = ((inx + 1) / 2) * (inx % 2 == 0 ? 1 : -1) * nodeSize;
        // Depending on orientation sine or cosine. This adjusts the length
        // of the offset according the appropriate X and Y dimensions.
        final double normX = dx / len;
        final double normY = dy / len;
        // Calculate the anchor points.
        final double anchorX = midX + (offset * normY);
        final double anchorY = midY - (offset * normX);
        return new EdgeAnchors() {

            public int numAnchors() {
                return 1;
            }

            public void getAnchor(int inx, float[] arr, int off) {
                arr[off] = (float) anchorX;
                arr[off + 1] = (float) anchorY;
            }
        };
    }
    return returnThis;
}
Also used : EdgeAnchors(org.cytoscape.graph.render.immed.EdgeAnchors) LongEnumerator(org.cytoscape.util.intr.LongEnumerator) CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) CyEdge(org.cytoscape.model.CyEdge) Paint(java.awt.Paint)

Example 5 with LongEnumerator

use of org.cytoscape.util.intr.LongEnumerator in project cytoscape-impl by cytoscape.

the class DGraphView method getSelectedEdgeIndices.

/**
 * Returns an array of selected edge indices.
 *
 * @return An array of selected edge indices.
 */
@Override
public long[] getSelectedEdgeIndices() {
    synchronized (m_lock) {
        final LongEnumerator elms = m_selectedEdges.searchRange(Integer.MIN_VALUE, Integer.MAX_VALUE, false);
        final long[] returnThis = new long[elms.numRemaining()];
        for (int i = 0; i < returnThis.length; i++) returnThis[i] = elms.nextLong();
        return returnThis;
    }
}
Also used : LongEnumerator(org.cytoscape.util.intr.LongEnumerator) Paint(java.awt.Paint) TexturePaint(java.awt.TexturePaint)

Aggregations

LongEnumerator (org.cytoscape.util.intr.LongEnumerator)19 Point (java.awt.Point)5 CyEdge (org.cytoscape.model.CyEdge)4 CyNode (org.cytoscape.model.CyNode)4 Paint (java.awt.Paint)3 TexturePaint (java.awt.TexturePaint)2 Point2D (java.awt.geom.Point2D)2 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 EdgeAnchors (org.cytoscape.graph.render.immed.EdgeAnchors)2 CyNetwork (org.cytoscape.model.CyNetwork)2 LongObjHash (org.cytoscape.util.intr.LongObjHash)2 Bend (org.cytoscape.view.presentation.property.values.Bend)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 ViewChangeEdit (org.cytoscape.ding.ViewChangeEdit)1