Search in sources :

Example 1 with ConnectionMode

use of au.gov.asd.tac.constellation.graph.schema.visual.attribute.objects.ConnectionMode in project constellation by constellation-app.

the class PointSelectionPlugin method edit.

@Override
public void edit(final GraphWriteMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException {
    final int maxTransactionsAttribute = VisualConcept.GraphAttribute.MAX_TRANSACTIONS.get(graph);
    final int vertexSelectedAttribute = VisualConcept.VertexAttribute.SELECTED.get(graph);
    final int transactionSelectedAttribute = VisualConcept.TransactionAttribute.SELECTED.get(graph);
    final int connectionModeAttrId = VisualConcept.GraphAttribute.CONNECTION_MODE.get(graph);
    final ConnectionMode connectionMode = connectionModeAttrId != Graph.NOT_FOUND ? graph.getObjectValue(connectionModeAttrId, 0) : ConnectionMode.EDGE;
    final int maxTransactionsDrawn = maxTransactionsAttribute != Graph.NOT_FOUND ? graph.getIntValue(maxTransactionsAttribute, 0) : VisualGraphDefaults.DEFAULT_MAX_TRANSACTION_TO_DRAW;
    // Deselect all vertices and transactions.
    if (clearSelection) {
        if (vertexSelectedAttribute != Graph.NOT_FOUND) {
            for (int position = 0; position < graph.getVertexCount(); position++) {
                final int vertexId = graph.getVertex(position);
                if (graph.getBooleanValue(vertexSelectedAttribute, vertexId)) {
                    graph.setBooleanValue(vertexSelectedAttribute, vertexId, false);
                }
            }
        }
        if (transactionSelectedAttribute != Graph.NOT_FOUND) {
            for (int position = 0; position < graph.getTransactionCount(); position++) {
                final int transactionId = graph.getTransaction(position);
                if (graph.getBooleanValue(transactionSelectedAttribute, transactionId)) {
                    graph.setBooleanValue(transactionSelectedAttribute, transactionId, false);
                }
            }
        }
    }
    if (vertexSelectedAttribute != Graph.NOT_FOUND) {
        vertexIds.forEach(vertexId -> {
            final boolean select = !isToggle || !graph.getBooleanValue(vertexSelectedAttribute, vertexId);
            graph.setBooleanValue(vertexSelectedAttribute, vertexId, select);
        });
    }
    if (transactionSelectedAttribute != Graph.NOT_FOUND) {
        transactionIds.forEach(transactionId -> {
            final boolean select = !isToggle || !graph.getBooleanValue(transactionSelectedAttribute, transactionId);
            // We also have to take into account that the renderer draws transactions as edges if there are more than maxTxDrawn transactions between two vertices.
            if (connectionMode == ConnectionMode.LINK) {
                final int linkId = graph.getTransactionLink(transactionId);
                final int txCount = graph.getLinkTransactionCount(linkId);
                for (int position = 0; position < txCount; position++) {
                    final int tx = graph.getLinkTransaction(linkId, position);
                    graph.setBooleanValue(transactionSelectedAttribute, tx, select);
                }
            } else {
                final int edgeId = graph.getTransactionEdge(transactionId);
                final int edgeTxCount = graph.getEdgeTransactionCount(edgeId);
                final int linkId = graph.getTransactionLink(transactionId);
                final int linkTxCount = graph.getLinkTransactionCount(linkId);
                if (connectionMode == ConnectionMode.EDGE || linkTxCount > maxTransactionsDrawn) {
                    for (int position = 0; position < edgeTxCount; position++) {
                        final int tx = graph.getEdgeTransaction(edgeId, position);
                        graph.setBooleanValue(transactionSelectedAttribute, tx, select);
                    }
                } else {
                    graph.setBooleanValue(transactionSelectedAttribute, transactionId, select);
                }
            }
        });
    }
}
Also used : ConnectionMode(au.gov.asd.tac.constellation.graph.schema.visual.attribute.objects.ConnectionMode)

Example 2 with ConnectionMode

use of au.gov.asd.tac.constellation.graph.schema.visual.attribute.objects.ConnectionMode in project constellation by constellation-app.

the class SetConnectionModePlugin method edit.

@Override
protected void edit(final GraphWriteMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
    final ConnectionMode mode = (ConnectionMode) parameters.getObjectValue(CONNECTION_MODE_PARAMETER_ID);
    final int connectionModeAttrId = VisualConcept.GraphAttribute.CONNECTION_MODE.get(graph);
    if (connectionModeAttrId != Graph.NOT_FOUND) {
        graph.setObjectValue(VisualConcept.GraphAttribute.CONNECTION_MODE.get(graph), 0, mode);
    }
}
Also used : ConnectionMode(au.gov.asd.tac.constellation.graph.schema.visual.attribute.objects.ConnectionMode)

Example 3 with ConnectionMode

use of au.gov.asd.tac.constellation.graph.schema.visual.attribute.objects.ConnectionMode in project constellation by constellation-app.

the class VisualGraphTopComponent method visualUpdate.

private void visualUpdate() {
    final ReadableGraph rg = graph.getReadableGraph();
    try {
        final int drawFlagsAttribute = VisualConcept.GraphAttribute.DRAW_FLAGS.get(rg);
        final int visibleAboveThresholdAttribute = VisualConcept.GraphAttribute.VISIBLE_ABOVE_THRESHOLD.get(rg);
        final int displayModeIs3DAttribute = VisualConcept.GraphAttribute.DISPLAY_MODE_3D.get(rg);
        final int drawingModeAttribute = VisualConcept.GraphAttribute.DRAWING_MODE.get(rg);
        final int drawDirectedAttribute = VisualConcept.GraphAttribute.DRAW_DIRECTED_TRANSACTIONS.get(rg);
        final int connectionModeAttribute = VisualConcept.GraphAttribute.CONNECTION_MODE.get(rg);
        // Read relevant visual attributes from the graph and update the sidebar.
        final DrawFlags drawFlags;
        final ConnectionMode connectionMode;
        final boolean visibleAboveThreshold;
        final boolean isDisplay3D;
        final boolean isDrawingMode;
        final boolean isDrawingDirectedTransactions;
        drawFlags = drawFlagsAttribute != Graph.NOT_FOUND ? rg.getObjectValue(drawFlagsAttribute, 0) : VisualGraphDefaults.DEFAULT_DRAW_FLAGS;
        visibleAboveThreshold = visibleAboveThresholdAttribute != Graph.NOT_FOUND ? rg.getBooleanValue(visibleAboveThresholdAttribute, 0) : VisualGraphDefaults.DEFAULT_GRAPH_VISIBILITY;
        isDisplay3D = displayModeIs3DAttribute != Graph.NOT_FOUND ? rg.getBooleanValue(displayModeIs3DAttribute, 0) : VisualGraphDefaults.DEFAULT_DISPLAY_MODE_3D;
        isDrawingMode = drawingModeAttribute != Graph.NOT_FOUND ? rg.getBooleanValue(drawingModeAttribute, 0) : VisualGraphDefaults.DEFAULT_DRAWING_MODE;
        isDrawingDirectedTransactions = drawDirectedAttribute != Graph.NOT_FOUND ? rg.getBooleanValue(drawDirectedAttribute, 0) : VisualGraphDefaults.DEFAULT_DRAWING_DIRECTED_TRANSACTIONS;
        connectionMode = connectionModeAttribute != Graph.NOT_FOUND ? rg.getObjectValue(connectionModeAttribute, 0) : VisualGraphDefaults.DEFAULT_CONNECTION_MODE;
        drawNodesAction.putValue(Action.SELECTED_KEY, drawFlags.drawNodes());
        drawConnectionsAction.putValue(Action.SELECTED_KEY, drawFlags.drawConnections());
        drawNodeLabelsAction.putValue(Action.SELECTED_KEY, drawFlags.drawNodeLabels());
        drawNodeLabelsAction.putValue(Action.SHORT_DESCRIPTION, drawFlags.drawNodeLabels() ? HIDE_NODE_LABELS_SHORT_DESCRIPTION : SHOW_NODE_LABELS_SHORT_DESCRIPTION);
        drawConnectionLabelsAction.putValue(Action.SELECTED_KEY, drawFlags.drawConnectionLabels());
        drawConnectionLabelsAction.putValue(Action.SHORT_DESCRIPTION, drawFlags.drawConnectionLabels() ? HIDE_CONNECTION_LABELS_SHORT_DESCRIPTION : SHOW_CONNECTION_LABELS_SHORT_DESCRIPTION);
        drawBlazesAction.putValue(Action.SELECTED_KEY, drawFlags.drawBlazes());
        drawBlazesAction.putValue(Action.SHORT_DESCRIPTION, drawFlags.drawBlazes() ? HIDE_BLAZES_SHORT_DESCRIPTION : SHOW_BLAZES_SHORT_DESCRIPTION);
        display3dAction.putValue(Action.SELECTED_KEY, isDisplay3D);
        display3dAction.putValue(Action.SMALL_ICON, isDisplay3D ? MODE_3D_ICON : MODE_2D_ICON);
        display3dAction.putValue(Action.SHORT_DESCRIPTION, isDisplay3D ? MODE_3D_SHORT_DESCRIPTION : MODE_2D_SHORT_DESCRIPTION);
        toggleGraphVisibilityAction.putValue(Action.SELECTED_KEY, visibleAboveThreshold);
        toggleGraphVisibilityAction.putValue(Action.SMALL_ICON, visibleAboveThreshold ? VISIBLE_ICON : HIDDEN_ICON);
        toggleGraphVisibilityAction.putValue(Action.SHORT_DESCRIPTION, visibleAboveThreshold ? DISABLE_GRAPH_VISIBILITY_THRESHOLD_LABELS_SHORT_DESCRIPTION : ENABLE_GRAPH_VISIBILITY_THRESHOLD_LABELS_SHORT_DESCRIPTION);
        toggleSelectModeAction.putValue(Action.SELECTED_KEY, isDrawingMode);
        toggleSelectModeAction.putValue(Action.SMALL_ICON, isDrawingMode ? DRAWING_MODE_ICON : SELECT_MODE_ICON);
        toggleSelectModeAction.putValue(Action.SHORT_DESCRIPTION, isDrawingMode ? DRAWING_MODE_SHORT_DESCRIPTION : SELECTION_MODE_SHORT_DESCRIPTION);
        toggleDrawDirectedAction.putValue(Action.SELECTED_KEY, isDrawingDirectedTransactions);
        toggleDrawDirectedAction.putValue(Action.SMALL_ICON, isDrawingDirectedTransactions ? DIRECTED_ICON : UNDIRECTED_ICON);
        toggleDrawDirectedAction.putValue(Action.SHORT_DESCRIPTION, isDrawingDirectedTransactions ? DIRECTED_SHORT_DESCRIPTION : UNDIRECTED_SHORT_DESCRIPTION);
        toggleDrawDirectedAction.setEnabled(isDrawingMode);
        switch(connectionMode) {
            case LINK:
                drawLinksAction.putValue(Action.SELECTED_KEY, true);
                break;
            case EDGE:
                drawEdgesAction.putValue(Action.SELECTED_KEY, true);
                break;
            case TRANSACTION:
                drawTransactionsAction.putValue(Action.SELECTED_KEY, true);
                break;
            default:
                throw new IllegalStateException("Unknown ConnectionMode: " + connectionMode);
        }
    } finally {
        rg.release();
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) ConnectionMode(au.gov.asd.tac.constellation.graph.schema.visual.attribute.objects.ConnectionMode) DrawFlags(au.gov.asd.tac.constellation.utilities.visual.DrawFlags)

Aggregations

ConnectionMode (au.gov.asd.tac.constellation.graph.schema.visual.attribute.objects.ConnectionMode)3 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)1 DrawFlags (au.gov.asd.tac.constellation.utilities.visual.DrawFlags)1