Search in sources :

Example 1 with ConstellationPolygonMarker

use of au.gov.asd.tac.constellation.views.mapview.markers.ConstellationPolygonMarker in project constellation by constellation-app.

the class MarkerCache method styleMarkers.

public void styleMarkers(final Graph graph, final MarkerState markerState) {
    assert !SwingUtilities.isEventDispatchThread();
    // update style based on graph attributes
    if (graph != null) {
        final ReadableGraph readableGraph = graph.getReadableGraph();
        try {
            final int elementMixColorAttributeId = VisualConcept.GraphAttribute.MIX_COLOR.get(readableGraph);
            final ConstellationColor mixColor = elementMixColorAttributeId != Graph.NOT_FOUND ? readableGraph.getObjectValue(elementMixColorAttributeId, 0) : null;
            synchronized (lock) {
                forEach((marker, elementList) -> {
                    if (marker != null) {
                        final Set<String> labels = new HashSet<>();
                        final Set<ConstellationColor> colors = new HashSet<>();
                        boolean selected = false;
                        boolean dimmed = false;
                        boolean hidden = false;
                        // get relevent attribute ids
                        int elementVisibilityAttributeId;
                        int elementDimmedAttributeId;
                        int elementSelectedAttributeId;
                        int elementLabelAttributeId;
                        int elementColorAttributeId;
                        for (final GraphElement element : elementList) {
                            switch(element.getType()) {
                                case VERTEX:
                                    if (markerState.getLabel() == null) {
                                        elementLabelAttributeId = GraphConstants.NOT_FOUND;
                                    } else {
                                        elementLabelAttributeId = markerState.getLabel().getVertexAttribute() == null ? GraphConstants.NOT_FOUND : markerState.getLabel().getVertexAttribute().get(readableGraph);
                                    }
                                    if (markerState.getColorScheme() == null) {
                                        elementColorAttributeId = GraphConstants.NOT_FOUND;
                                    } else {
                                        elementColorAttributeId = markerState.getColorScheme().getVertexAttribute() == null ? GraphConstants.NOT_FOUND : markerState.getColorScheme().getVertexAttribute().get(readableGraph);
                                    }
                                    elementSelectedAttributeId = VisualConcept.VertexAttribute.SELECTED.get(readableGraph);
                                    elementDimmedAttributeId = VisualConcept.VertexAttribute.DIMMED.get(readableGraph);
                                    elementVisibilityAttributeId = VisualConcept.VertexAttribute.VISIBILITY.get(readableGraph);
                                    break;
                                case TRANSACTION:
                                    if (markerState.getLabel() == null) {
                                        elementLabelAttributeId = GraphConstants.NOT_FOUND;
                                    } else {
                                        elementLabelAttributeId = markerState.getLabel().getTransactionAttribute() == null ? GraphConstants.NOT_FOUND : markerState.getLabel().getTransactionAttribute().get(readableGraph);
                                    }
                                    if (markerState.getColorScheme() == null) {
                                        elementColorAttributeId = GraphConstants.NOT_FOUND;
                                    } else {
                                        elementColorAttributeId = markerState.getColorScheme().getTransactionAttribute() == null ? GraphConstants.NOT_FOUND : markerState.getColorScheme().getTransactionAttribute().get(readableGraph);
                                    }
                                    elementSelectedAttributeId = VisualConcept.TransactionAttribute.SELECTED.get(readableGraph);
                                    elementDimmedAttributeId = VisualConcept.TransactionAttribute.DIMMED.get(readableGraph);
                                    elementVisibilityAttributeId = VisualConcept.TransactionAttribute.VISIBILITY.get(readableGraph);
                                    break;
                                default:
                                    if (marker.isCustom()) {
                                        colors.add(MarkerUtilities.value(MarkerUtilities.DEFAULT_CUSTOM_COLOR));
                                        selected |= marker.isSelected();
                                        dimmed |= marker.isDimmed();
                                    }
                                    continue;
                            }
                            final int elementId = element.getId();
                            // get label
                            if (elementLabelAttributeId != GraphConstants.NOT_FOUND) {
                                labels.add(readableGraph.getStringValue(elementLabelAttributeId, elementId));
                            }
                            // get color
                            if (elementColorAttributeId != GraphConstants.NOT_FOUND) {
                                switch(markerState.getColorScheme()) {
                                    case COLOR:
                                    case OVERLAY:
                                        colors.add(readableGraph.getObjectValue(elementColorAttributeId, elementId));
                                        break;
                                    case BLAZE:
                                        // give the blazes a color and default to the color scheme for non blazed nodes
                                        if (readableGraph.getObjectValue(elementColorAttributeId, elementId) != null) {
                                            colors.add(((Blaze) readableGraph.getObjectValue(elementColorAttributeId, elementId)).getColor());
                                        }
                                        break;
                                    default:
                                        break;
                                }
                            }
                            // get selected
                            if (elementSelectedAttributeId != GraphConstants.NOT_FOUND && readableGraph.getBooleanValue(elementSelectedAttributeId, elementId)) {
                                selected |= true;
                            }
                            // get dimming
                            if (elementDimmedAttributeId != GraphConstants.NOT_FOUND && readableGraph.getBooleanValue(elementDimmedAttributeId, elementId)) {
                                dimmed |= true;
                            }
                            // get visibility
                            if (elementVisibilityAttributeId != GraphConstants.NOT_FOUND && readableGraph.getFloatValue(elementVisibilityAttributeId, elementId) <= 0) {
                                hidden |= true;
                            }
                        }
                        // update label
                        if (labels.isEmpty()) {
                            marker.setId(null);
                        } else if (labels.size() == 1) {
                            marker.setId(labels.iterator().next());
                        } else {
                            marker.setId(MULTIPLE_VALUES);
                        }
                        // update color
                        if (colors.isEmpty()) {
                            marker.setColor(MarkerUtilities.DEFAULT_COLOR);
                        } else if (colors.size() == 1) {
                            marker.setColor(MarkerUtilities.color(colors.iterator().next()));
                        } else {
                            marker.setColor(MarkerUtilities.color(mixColor));
                        }
                        // update selection
                        marker.setSelected(selected);
                        // update dimming
                        marker.setDimmed(dimmed);
                        // update visibility
                        if ((markerState.isShowSelectedOnly() && !marker.isSelected()) || (!markerState.isShowPointMarkers() && marker instanceof ConstellationPointMarker) || (!markerState.isShowLineMarkers() && marker instanceof ConstellationLineMarker) || (!markerState.isShowPolygonMarkers() && marker instanceof ConstellationPolygonMarker) || (!markerState.isShowMultiMarkers() && marker instanceof ConstellationMultiMarker) || (!markerState.isShowClusterMarkers() && marker instanceof ConstellationClusterMarker)) {
                            marker.setHidden(true);
                        } else {
                            marker.setHidden(hidden);
                        }
                    }
                });
            }
        } finally {
            readableGraph.release();
        }
    }
}
Also used : ConstellationColor(au.gov.asd.tac.constellation.utilities.color.ConstellationColor) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) ConstellationMultiMarker(au.gov.asd.tac.constellation.views.mapview.markers.ConstellationMultiMarker) ConstellationLineMarker(au.gov.asd.tac.constellation.views.mapview.markers.ConstellationLineMarker) DoublePoint(org.apache.commons.math3.ml.clustering.DoublePoint) ConstellationClusterMarker(au.gov.asd.tac.constellation.views.mapview.markers.ConstellationClusterMarker) ConstellationPolygonMarker(au.gov.asd.tac.constellation.views.mapview.markers.ConstellationPolygonMarker) ConstellationPointMarker(au.gov.asd.tac.constellation.views.mapview.markers.ConstellationPointMarker) HashSet(java.util.HashSet)

Example 2 with ConstellationPolygonMarker

use of au.gov.asd.tac.constellation.views.mapview.markers.ConstellationPolygonMarker in project constellation by constellation-app.

the class CopyCustomMarkersToGraphPlugin method edit.

@Override
protected void edit(final GraphWriteMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
    final int vertexIdentifierAttributeId = VisualConcept.VertexAttribute.IDENTIFIER.ensure(graph);
    final int vertexTypeAttributeId = AnalyticConcept.VertexAttribute.TYPE.ensure(graph);
    final int vertexLatitudeAttributeId = SpatialConcept.VertexAttribute.LATITUDE.ensure(graph);
    final int vertexLongitudeAttributeId = SpatialConcept.VertexAttribute.LONGITUDE.ensure(graph);
    final int vertexPrecisionAttributeId = SpatialConcept.VertexAttribute.PRECISION.ensure(graph);
    final int vertexShapeAttributeId = SpatialConcept.VertexAttribute.SHAPE.ensure(graph);
    final MarkerCache markerCache = MarkerCache.getDefault();
    for (final ConstellationAbstractMarker marker : markerCache.getCustomMarkers()) {
        final String markerId = marker.getId() == null ? marker.toString() : marker.getId();
        final int vertexId = graph.addVertex();
        graph.setStringValue(vertexIdentifierAttributeId, vertexId, markerId);
        graph.setObjectValue(vertexTypeAttributeId, vertexId, AnalyticConcept.VertexType.LOCATION);
        graph.setFloatValue(vertexLatitudeAttributeId, vertexId, marker.getLocation().getLat());
        graph.setFloatValue(vertexLongitudeAttributeId, vertexId, marker.getLocation().getLon());
        graph.setFloatValue(vertexPrecisionAttributeId, vertexId, (float) marker.getRadius());
        try {
            final Shape.GeometryType geometryType;
            if (marker instanceof ConstellationMultiMarker) {
                geometryType = Shape.GeometryType.MULTI_POLYGON;
            } else if (marker instanceof ConstellationPolygonMarker) {
                geometryType = Shape.GeometryType.POLYGON;
            } else if (marker instanceof ConstellationLineMarker) {
                geometryType = Shape.GeometryType.LINE;
            } else {
                geometryType = Shape.GeometryType.POINT;
            }
            final List<Tuple<Double, Double>> coordinates = marker.getLocations().stream().map(location -> Tuple.create((double) location.getLon(), (double) location.getLat())).collect(Collectors.toList());
            final String shape = Shape.generateShape(markerId, geometryType, coordinates);
            graph.setStringValue(vertexShapeAttributeId, vertexId, shape);
        } catch (final IOException ex) {
            throw new PluginException(PluginNotificationLevel.ERROR, ex);
        }
    }
    PluginExecution.withPlugin(VisualSchemaPluginRegistry.COMPLETE_SCHEMA).executeNow(graph);
    PluginExecution.withPlugin(InteractiveGraphPluginRegistry.RESET_VIEW).executeNow(graph);
}
Also used : ConstellationAbstractMarker(au.gov.asd.tac.constellation.views.mapview.markers.ConstellationAbstractMarker) GraphWriteMethods(au.gov.asd.tac.constellation.graph.GraphWriteMethods) Tuple(au.gov.asd.tac.constellation.utilities.datastructure.Tuple) SimpleEditPlugin(au.gov.asd.tac.constellation.plugins.templates.SimpleEditPlugin) SpatialConcept(au.gov.asd.tac.constellation.graph.schema.analytic.concept.SpatialConcept) VisualConcept(au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept) MarkerCache(au.gov.asd.tac.constellation.views.mapview.utilities.MarkerCache) ConstellationLineMarker(au.gov.asd.tac.constellation.views.mapview.markers.ConstellationLineMarker) Plugin(au.gov.asd.tac.constellation.plugins.Plugin) PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) Shape(au.gov.asd.tac.constellation.utilities.geospatial.Shape) ServiceProvider(org.openide.util.lookup.ServiceProvider) PluginTags(au.gov.asd.tac.constellation.plugins.templates.PluginTags) PluginExecution(au.gov.asd.tac.constellation.plugins.PluginExecution) ConstellationPolygonMarker(au.gov.asd.tac.constellation.views.mapview.markers.ConstellationPolygonMarker) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) InteractiveGraphPluginRegistry(au.gov.asd.tac.constellation.graph.interaction.InteractiveGraphPluginRegistry) IOException(java.io.IOException) ConstellationAbstractMarker(au.gov.asd.tac.constellation.views.mapview.markers.ConstellationAbstractMarker) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) Collectors(java.util.stream.Collectors) PluginNotificationLevel(au.gov.asd.tac.constellation.plugins.PluginNotificationLevel) PluginInfo(au.gov.asd.tac.constellation.plugins.PluginInfo) List(java.util.List) AnalyticConcept(au.gov.asd.tac.constellation.graph.schema.analytic.concept.AnalyticConcept) ConstellationMultiMarker(au.gov.asd.tac.constellation.views.mapview.markers.ConstellationMultiMarker) VisualSchemaPluginRegistry(au.gov.asd.tac.constellation.graph.schema.visual.VisualSchemaPluginRegistry) NbBundle(org.openide.util.NbBundle) Shape(au.gov.asd.tac.constellation.utilities.geospatial.Shape) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) ConstellationMultiMarker(au.gov.asd.tac.constellation.views.mapview.markers.ConstellationMultiMarker) IOException(java.io.IOException) ConstellationLineMarker(au.gov.asd.tac.constellation.views.mapview.markers.ConstellationLineMarker) ConstellationPolygonMarker(au.gov.asd.tac.constellation.views.mapview.markers.ConstellationPolygonMarker) MarkerCache(au.gov.asd.tac.constellation.views.mapview.utilities.MarkerCache) Tuple(au.gov.asd.tac.constellation.utilities.datastructure.Tuple)

Aggregations

ConstellationLineMarker (au.gov.asd.tac.constellation.views.mapview.markers.ConstellationLineMarker)2 ConstellationMultiMarker (au.gov.asd.tac.constellation.views.mapview.markers.ConstellationMultiMarker)2 ConstellationPolygonMarker (au.gov.asd.tac.constellation.views.mapview.markers.ConstellationPolygonMarker)2 GraphWriteMethods (au.gov.asd.tac.constellation.graph.GraphWriteMethods)1 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)1 InteractiveGraphPluginRegistry (au.gov.asd.tac.constellation.graph.interaction.InteractiveGraphPluginRegistry)1 AnalyticConcept (au.gov.asd.tac.constellation.graph.schema.analytic.concept.AnalyticConcept)1 SpatialConcept (au.gov.asd.tac.constellation.graph.schema.analytic.concept.SpatialConcept)1 VisualSchemaPluginRegistry (au.gov.asd.tac.constellation.graph.schema.visual.VisualSchemaPluginRegistry)1 VisualConcept (au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept)1 Plugin (au.gov.asd.tac.constellation.plugins.Plugin)1 PluginException (au.gov.asd.tac.constellation.plugins.PluginException)1 PluginExecution (au.gov.asd.tac.constellation.plugins.PluginExecution)1 PluginInfo (au.gov.asd.tac.constellation.plugins.PluginInfo)1 PluginInteraction (au.gov.asd.tac.constellation.plugins.PluginInteraction)1 PluginNotificationLevel (au.gov.asd.tac.constellation.plugins.PluginNotificationLevel)1 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)1 PluginTags (au.gov.asd.tac.constellation.plugins.templates.PluginTags)1 SimpleEditPlugin (au.gov.asd.tac.constellation.plugins.templates.SimpleEditPlugin)1 ConstellationColor (au.gov.asd.tac.constellation.utilities.color.ConstellationColor)1