Search in sources :

Example 6 with NodeModel

use of org.gephi.visualization.model.node.NodeModel in project gephi by gephi.

the class CompatibilityEngine method mouseClick.

@Override
public void mouseClick() {
    if (vizConfig.isSelectionEnable() && rectangleSelection && !customSelection) {
        Rectangle rectangle = (Rectangle) currentSelectionArea;
        //rectangle.setBlocking(false);
        resetEdgesSelection();
        //Select with click
        boolean someSelection = false;
        for (Iterator<NodeModel> itr = octree.getSelectableNodeIterator(); itr.hasNext(); ) {
            NodeModel obj = (NodeModel) itr.next();
            if (isUnderMouse(obj)) {
                if (!obj.isSelected()) {
                    //New selected
                    obj.setSelected(true);
                }
                someSelection = true;
            } else if (obj.isSelected()) {
                someSelection = true;
            }
        }
        if (!(rectangle.isCtrl() && someSelection)) {
            for (NodeModel nm : getSelectedNodes()) {
                nm.setSelected(false);
            }
            someSelection = false;
        }
        rectangle.setBlocking(someSelection);
        if (vizController.getVizModel().isLightenNonSelectedAuto()) {
            if (vizConfig.isLightenNonSelectedAnimation()) {
                if (!anySelected && someSelection) {
                    //Start animation
                    lightenAnimationDelta = 0.07f;
                } else if (anySelected && !someSelection) {
                    //Stop animation
                    lightenAnimationDelta = -0.07f;
                }
                vizConfig.setLightenNonSelected(someSelection || lightenAnimationDelta != 0);
            } else {
                vizConfig.setLightenNonSelected(someSelection);
            }
        }
        anySelected = someSelection;
        scheduler.requireUpdateSelection();
    }
}
Also used : NodeModel(org.gephi.visualization.model.node.NodeModel) Rectangle(org.gephi.visualization.selection.Rectangle)

Example 7 with NodeModel

use of org.gephi.visualization.model.node.NodeModel in project gephi by gephi.

the class Octant method trimNodes.

private void trimNodes() {
    if (nodesLength >= TRIM_THRESHOLD && ((float) nodeCount) / nodesLength < TRIM_RATIO) {
        NodeModel[] t = new NodeModel[nodeCount];
        if (nodeCount > 0) {
            int c = 0;
            for (int i = 0; i < nodes.length; i++) {
                NodeModel n = nodes[i];
                if (n != null) {
                    n.setOctantId(c);
                    t[c++] = n;
                }
            }
        }
        nodesLength = t.length;
        nodes = t;
        nodesGarbage = null;
        nodesGarbageLength = 0;
    }
}
Also used : NodeModel(org.gephi.visualization.model.node.NodeModel)

Example 8 with NodeModel

use of org.gephi.visualization.model.node.NodeModel in project gephi by gephi.

the class Octree method repositionNodes.

public boolean repositionNodes() {
    List<NodeModel> movedNodes = new ArrayList<>();
    for (int i = 0; i < length; i++) {
        Octant leaf = leaves[i];
        if (leaf != null) {
            int l = leaf.nodesLength;
            NodeModel[] nodes = leaf.nodes;
            for (int j = 0; j < l; j++) {
                NodeModel node = nodes[j];
                if (node != null) {
                    if (!node.isInOctreeLeaf(leaf)) {
                        removeNode(node);
                        movedNodes.add(node);
                    }
                }
            }
        }
    }
    if (!movedNodes.isEmpty()) {
        for (NodeModel node : movedNodes) {
            addNode(node);
        }
        return true;
    }
    return false;
}
Also used : NodeModel(org.gephi.visualization.model.node.NodeModel) ArrayList(java.util.ArrayList)

Example 9 with NodeModel

use of org.gephi.visualization.model.node.NodeModel in project gephi by gephi.

the class GraphContextMenu method getMenu.

public JPopupMenu getMenu() {
    GraphContextMenuItem[] items = getGraphContextMenuItems();
    final List<NodeModel> selectedNodeModels = engine.getSelectedNodes();
    Node[] selectedNodes = new Node[selectedNodeModels.size()];
    int i = 0;
    for (NodeModel nm : selectedNodeModels) {
        selectedNodes[i++] = nm.getNode();
    }
    final Graph graph = dataBridge.getGraph();
    JPopupMenu contextMenu = new JPopupMenu();
    //Add items ordered:
    Integer lastItemType = null;
    for (GraphContextMenuItem item : items) {
        item.setup(graph, selectedNodes);
        if (lastItemType == null) {
            lastItemType = item.getType();
        }
        if (lastItemType != item.getType()) {
            contextMenu.addSeparator();
        }
        lastItemType = item.getType();
        if (item.isAvailable()) {
            contextMenu.add(createMenuItemFromGraphContextMenuItem(item, graph, selectedNodes));
        }
    }
    return contextMenu;
}
Also used : GraphContextMenuItem(org.gephi.visualization.spi.GraphContextMenuItem) NodeModel(org.gephi.visualization.model.node.NodeModel) Graph(org.gephi.graph.api.Graph) Node(org.gephi.graph.api.Node) JPopupMenu(javax.swing.JPopupMenu)

Example 10 with NodeModel

use of org.gephi.visualization.model.node.NodeModel in project gephi by gephi.

the class DataBridge method updateWorld.

public synchronized boolean updateWorld() {
    boolean force = false;
    if (graphModel != null) {
        graphModel.getGraph().writeLock();
    }
    try {
        if ((observer != null && observer.isDestroyed()) || (graphModel != null && graph.getView() != graphModel.getVisibleView())) {
            if (observer != null && !observer.isDestroyed()) {
                observer.destroy();
            }
            observer = null;
            if (graphModel != null) {
                graph = graphModel.getGraphVisible();
                observer = graphModel.createGraphObserver(graph, false);
                force = true;
            }
        }
    } finally {
        if (graphModel != null) {
            graphModel.getGraph().readUnlockAll();
            graphModel.getGraph().writeUnlock();
        }
    }
    if (force || (observer != null && (observer.isNew() || observer.hasGraphChanged())) || hasColumnsChanged()) {
        if (observer.isNew()) {
            observer.hasGraphChanged();
        }
        NodeModeler nodeModeler = engine.getNodeModeler();
        EdgeModeler edgeModeler = engine.getEdgeModeler();
        Octree octree = engine.getOctree();
        //Stats
        int removedNodes = 0;
        int addedNodes = 0;
        int removedEdges = 0;
        int addedEdges = 0;
        graph.readLock();
        try {
            boolean isView = !graph.getView().isMainView();
            for (int i = 0; i < nodes.length; i++) {
                NodeModel node = nodes[i];
                if (node != null && (node.getNode().getStoreId() == -1 || (isView && !graph.contains(node.getNode())))) {
                    //Removed
                    octree.removeNode(node);
                    nodes[i] = null;
                    removedNodes++;
                }
            }
            for (Node node : graph.getNodes()) {
                int id = node.getStoreId();
                NodeModel model;
                if (id >= nodes.length || nodes[id] == null) {
                    growNodes(id);
                    model = nodeModeler.initModel(node);
                    octree.addNode(model);
                    nodes[id] = model;
                    addedNodes++;
                } else {
                    model = nodes[id];
                }
                textManager.refreshNode(graph, model, textModel);
            }
            for (int i = 0; i < edges.length; i++) {
                EdgeModel edge = edges[i];
                if (edge != null && (edge.getEdge().getStoreId() == -1 || (isView && !graph.contains(edge.getEdge())))) {
                    //Removed
                    int sourceId = edge.getEdge().getSource().getStoreId();
                    int targetId = edge.getEdge().getTarget().getStoreId();
                    NodeModel sourceModel = sourceId == -1 ? null : nodes[sourceId];
                    NodeModel targetModel = targetId == -1 ? null : nodes[targetId];
                    if (sourceModel != null) {
                        sourceModel.removeEdge(edge);
                    }
                    if (targetModel != null && sourceModel != targetModel) {
                        targetModel.removeEdge(edge);
                    }
                    edges[i] = null;
                    removedEdges++;
                }
            }
            float minWeight = Float.MAX_VALUE;
            float maxWeight = Float.MIN_VALUE;
            for (Edge edge : graph.getEdges()) {
                int id = edge.getStoreId();
                EdgeModel model;
                if (id >= edges.length || edges[id] == null) {
                    growEdges(id);
                    NodeModel sourceModel = nodes[edge.getSource().getStoreId()];
                    NodeModel targetModel = nodes[edge.getTarget().getStoreId()];
                    model = edgeModeler.initModel(edge, sourceModel, targetModel);
                    sourceModel.addEdge(model);
                    if (targetModel != sourceModel) {
                        targetModel.addEdge(model);
                    }
                    edges[id] = model;
                    addedEdges++;
                } else {
                    model = edges[id];
                }
                float w = (float) edge.getWeight(graph.getView());
                model.setWeight(w);
                minWeight = Math.min(w, minWeight);
                maxWeight = Math.max(w, maxWeight);
                textManager.refreshEdge(graph, model, textModel);
            }
            if (!isView) {
                limits.setMaxWeight(maxWeight);
                limits.setMinWeight(minWeight);
            }
        } finally {
            graph.readUnlockAll();
        }
        return true;
    } else if (observer == null) {
        Octree octree = engine.getOctree();
        if (!octree.isEmpty()) {
            octree.clear();
        }
    }
    return false;
}
Also used : NodeModel(org.gephi.visualization.model.node.NodeModel) NodeModeler(org.gephi.visualization.model.node.NodeModeler) EdgeModeler(org.gephi.visualization.model.edge.EdgeModeler) Node(org.gephi.graph.api.Node) Octree(org.gephi.visualization.octree.Octree) Edge(org.gephi.graph.api.Edge) EdgeModel(org.gephi.visualization.model.edge.EdgeModel)

Aggregations

NodeModel (org.gephi.visualization.model.node.NodeModel)10 Node (org.gephi.graph.api.Node)2 EdgeModel (org.gephi.visualization.model.edge.EdgeModel)2 Rectangle (org.gephi.visualization.selection.Rectangle)2 ArrayList (java.util.ArrayList)1 JPopupMenu (javax.swing.JPopupMenu)1 Edge (org.gephi.graph.api.Edge)1 Graph (org.gephi.graph.api.Graph)1 VizModel (org.gephi.visualization.VizModel)1 EdgeModeler (org.gephi.visualization.model.edge.EdgeModeler)1 NodeModeler (org.gephi.visualization.model.node.NodeModeler)1 Octree (org.gephi.visualization.octree.Octree)1 GraphContextMenuItem (org.gephi.visualization.spi.GraphContextMenuItem)1