Search in sources :

Example 96 with CyNetwork

use of org.cytoscape.model.CyNetwork in project cytoscape-impl by cytoscape.

the class StringToModelImpl method getTable.

@Override
public CyTable getTable(String strTable) {
    if (strTable == null || strTable.length() == 0 || strTable.equalsIgnoreCase(CURRENT))
        return serviceRegistrar.getService(CyApplicationManager.class).getCurrentTable();
    // Look for any special prefix
    CyNetwork network;
    String[] splitString = strTable.split(":");
    if (splitString.length > 1) {
        if (splitString[0].equalsIgnoreCase("node")) {
            network = getNetwork(splitString[1]);
            if (network != null)
                return network.getDefaultNodeTable();
        }
        if (splitString[0].equalsIgnoreCase("edge")) {
            network = getNetwork(splitString[1]);
            if (network != null)
                return network.getDefaultEdgeTable();
        }
        if (splitString[0].equalsIgnoreCase("network")) {
            network = getNetwork(splitString[1]);
            if (network != null)
                return network.getDefaultNetworkTable();
        }
    } else {
        final CyTableManager tableMgr = serviceRegistrar.getService(CyTableManager.class);
        for (CyTable tab : tableMgr.getGlobalTables()) {
            if (tab.getTitle().contains(strTable))
                return tab;
        }
    }
    return null;
}
Also used : CyTable(org.cytoscape.model.CyTable) CyTableManager(org.cytoscape.model.CyTableManager) CyNetwork(org.cytoscape.model.CyNetwork)

Example 97 with CyNetwork

use of org.cytoscape.model.CyNetwork 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 98 with CyNetwork

use of org.cytoscape.model.CyNetwork in project cytoscape-impl by cytoscape.

the class ThumbnailView method handleEvent.

@Override
public void handleEvent(RowsSetEvent e) {
    if (!e.containsColumn(CyNetwork.SELECTED))
        return;
    CyTable source = e.getSource();
    CyNetwork model = viewModel.getModel();
    if (!viewModel.getComponent().isShowing() && (source == model.getDefaultNodeTable() || source == model.getDefaultEdgeTable())) {
        forceRender = true;
        repaint();
    }
}
Also used : CyTable(org.cytoscape.model.CyTable) CyNetwork(org.cytoscape.model.CyNetwork)

Example 99 with CyNetwork

use of org.cytoscape.model.CyNetwork 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 100 with CyNetwork

use of org.cytoscape.model.CyNetwork in project cytoscape-impl by cytoscape.

the class DingVisualStyleRenderingEngineFactory method createRenderingEngine.

@Override
public RenderingEngine<CyNetwork> createRenderingEngine(Object presentationContainer, View<CyNetwork> view) {
    RenderingEngine<CyNetwork> engine = super.createRenderingEngine(presentationContainer, view);
    Container component = (Container) presentationContainer;
    // Remove unnecessary mouse listeners.
    final int compCount = component.getComponentCount();
    for (int i = 0; i < compCount; i++) {
        final Component comp = component.getComponent(i);
        final MouseListener[] listeners = comp.getMouseListeners();
        for (MouseListener ml : listeners) comp.removeMouseListener(ml);
    }
    return engine;
}
Also used : Container(java.awt.Container) MouseListener(java.awt.event.MouseListener) CyNetwork(org.cytoscape.model.CyNetwork) Component(java.awt.Component)

Aggregations

CyNetwork (org.cytoscape.model.CyNetwork)517 CyNode (org.cytoscape.model.CyNode)183 CyNetworkView (org.cytoscape.view.model.CyNetworkView)129 CyEdge (org.cytoscape.model.CyEdge)108 Test (org.junit.Test)107 ArrayList (java.util.ArrayList)87 CyTable (org.cytoscape.model.CyTable)75 CyApplicationManager (org.cytoscape.application.CyApplicationManager)70 CyIdentifiable (org.cytoscape.model.CyIdentifiable)57 CyRow (org.cytoscape.model.CyRow)48 HashSet (java.util.HashSet)45 CyNetworkManager (org.cytoscape.model.CyNetworkManager)40 HashMap (java.util.HashMap)35 CyRootNetwork (org.cytoscape.model.subnetwork.CyRootNetwork)35 CySubNetwork (org.cytoscape.model.subnetwork.CySubNetwork)32 CyNetworkViewManager (org.cytoscape.view.model.CyNetworkViewManager)31 VisualStyle (org.cytoscape.view.vizmap.VisualStyle)30 AbstractNetworkReaderTest (org.cytoscape.io.internal.read.AbstractNetworkReaderTest)27 TaskIterator (org.cytoscape.work.TaskIterator)27 List (java.util.List)26