Search in sources :

Example 1 with MarkerCache

use of au.gov.asd.tac.constellation.views.mapview.utilities.MarkerCache in project constellation by constellation-app.

the class ToolsOverlay method overlay.

@Override
public void overlay() {
    boolean leftMousePressed = renderer.mouseButton == PConstants.LEFT;
    // draw tool overlay
    renderer.noStroke();
    renderer.fill(BACKGROUND_COLOUR);
    renderer.rect(x, y, width, height);
    float yOffset = y + MARGIN;
    // update measure tool state
    final float measureToolX = x + 60;
    final float measureToolWidth = VALUE_BOX_MEDIUM_WIDTH + VALUE_BOX_SHORT_WIDTH;
    final float measureSystemX = x + 60 + VALUE_BOX_MEDIUM_WIDTH + VALUE_BOX_SHORT_WIDTH + (PADDING * 2);
    final float measureSystemWidth = VALUE_BOX_SHORT_WIDTH;
    if (renderer.mouseX > measureToolX && renderer.mouseX < measureToolX + measureToolWidth && renderer.mouseY > yOffset && renderer.mouseY < yOffset + VALUE_BOX_HEIGHT) {
        if (leftMousePressed && mouseLeftMeasureToolRegion && !drawActive) {
            measureActive = !measureActive;
            mouseLeftMeasureToolRegion = false;
        }
    } else {
        mouseLeftMeasureToolRegion = true;
    }
    if (!measureActive && renderer.mouseX > measureSystemX && renderer.mouseX < measureSystemX + measureSystemWidth && renderer.mouseY > yOffset && renderer.mouseY < yOffset + VALUE_BOX_HEIGHT) {
        if (leftMousePressed && mouseLeftMeasureSystemRegion) {
            final MeasurementSystem[] measurementSystems = MeasurementSystem.values();
            measureSystem = measurementSystems[(measureSystem.ordinal() + 1) % measurementSystems.length];
            mouseLeftMeasureSystemRegion = false;
        }
    } else {
        mouseLeftMeasureSystemRegion = true;
    }
    // draw measure tool
    drawLabel("Measure", x + 60, yOffset);
    drawValue(measureSystem.getDisplayText(), measureSystemX, yOffset, measureSystemWidth, false, false);
    if (drawActive) {
        final Location start = getDrawToolStart();
        final Location end = getDrawToolEnd();
        if (start != null && end != null) {
            final float distance = measureSystem.getMeasureFunction().apply(start, end).floatValue();
            drawValue(String.format("%s", PApplet.nf(distance, 1, 3)), measureToolX, yOffset, measureToolWidth, false, false);
        } else {
            drawValue(DISABLED, measureToolX, yOffset, measureToolWidth, false, false);
        }
    } else if (measureActive) {
        final Location start = getMeasureToolStart();
        final Location end = getMeasureToolEnd();
        if (start != null && end != null) {
            float distance = measureSystem.getMeasureFunction().apply(start, end).floatValue();
            if (measurePath) {
                for (int i = 1; i < measureVertices.size(); i++) {
                    final Location startVertex = measureVertices.get(i - 1);
                    final Location endVertex = measureVertices.get(i);
                    distance += measureSystem.getMeasureFunction().apply(startVertex, endVertex).floatValue();
                }
            }
            drawValue(String.format("%s", PApplet.nf(distance, 1, 3)), measureToolX, yOffset, measureToolWidth, false, true);
        } else {
            drawValue("Enabled", measureToolX, yOffset, measureToolWidth, false, true);
        }
    } else {
        drawValue(DISABLED, measureToolX, yOffset, measureToolWidth, false, false);
    }
    // update map based on measure tool state
    if (mouseLeftMeasureToolRegion && measureActive) {
        final int measureToolColor = renderer.color(255, 0, 0, 127);
        renderer.stroke(measureToolColor);
        if (measurePath && measureVertices.size() > 1) {
            for (int i = 1; i < measureVertices.size(); i++) {
                final ScreenPosition previousVertex = map.getScreenPosition(measureVertices.get(i - 1));
                final ScreenPosition currentVertex = map.getScreenPosition(measureVertices.get(i));
                renderer.strokeWeight(5);
                renderer.point(previousVertex.x, previousVertex.y);
                renderer.point(currentVertex.x, currentVertex.y);
                renderer.strokeWeight(2);
                renderer.line(previousVertex.x, previousVertex.y, currentVertex.x, currentVertex.y);
            }
        } else {
            renderer.strokeWeight(5);
            renderer.point(measureOriginX, measureOriginY);
        }
        if (measureOriginX != -1 && measureOriginY != -1 && measureDeltaX != -1 && measureDeltaY != -1) {
            renderer.strokeWeight(5);
            renderer.point(measureDeltaX, measureDeltaY);
            renderer.strokeWeight(2);
            renderer.line(measureOriginX, measureOriginY, measureDeltaX, measureDeltaY);
            if (measureCircle) {
                final float radius = (float) Math.sqrt(Math.pow((measureDeltaX - measureOriginX), 2) + Math.pow((measureDeltaY - measureOriginY), 2));
                renderer.noFill();
                renderer.strokeWeight(2);
                renderer.ellipseMode(PConstants.RADIUS);
                renderer.ellipse(measureOriginX, measureOriginY, radius, radius);
            }
        }
    }
    // draw separator
    yOffset += VALUE_BOX_HEIGHT + PADDING * 2;
    drawSeparator(yOffset);
    yOffset += PADDING * 2;
    // update draw tool state
    final float drawToolX = x + 60;
    final float drawToolWidth = VALUE_BOX_MEDIUM_WIDTH + VALUE_BOX_SHORT_WIDTH;
    final float addToGraphX = x + 60 + VALUE_BOX_MEDIUM_WIDTH + VALUE_BOX_SHORT_WIDTH + (PADDING * 2);
    final float addToGraphWidth = VALUE_BOX_SHORT_WIDTH;
    if (renderer.mouseX > drawToolX && renderer.mouseX < drawToolX + drawToolWidth && renderer.mouseY > yOffset && renderer.mouseY < yOffset + VALUE_BOX_HEIGHT) {
        if (leftMousePressed && mouseLeftDrawToolRegion && !measureActive) {
            drawActive = !drawActive;
            mouseLeftDrawToolRegion = false;
        }
    } else {
        mouseLeftDrawToolRegion = true;
    }
    if (!drawActive && renderer.mouseX > addToGraphX && renderer.mouseX < addToGraphX + addToGraphWidth && renderer.mouseY > yOffset && renderer.mouseY < yOffset + VALUE_BOX_HEIGHT) {
        if (leftMousePressed && mouseLeftAddToGraphRegion) {
            try {
                final Graph currentGraph = GraphManager.getDefault().getActiveGraph();
                PluginExecution.withPlugin(MapViewPluginRegistry.COPY_CUSTOM_MARKERS_TO_GRAPH).executeNow(currentGraph);
                final MarkerCache markerCache = renderer.getMarkerCache();
                markerCache.getCustomMarkers().forEach(marker -> {
                    markerCache.get(marker).remove(GraphElement.NON_ELEMENT);
                    marker.setCustom(false);
                });
                renderer.updateMarkers(currentGraph, renderer.getMarkerState());
            } catch (final PluginException ex) {
                LOGGER.log(Level.SEVERE, "Error copying custom markers to graph", ex);
            } catch (final InterruptedException ex) {
                LOGGER.log(Level.SEVERE, "Error copying custom markers to graph", ex);
                Thread.currentThread().interrupt();
            }
            mouseLeftAddToGraphRegion = false;
        }
    } else {
        mouseLeftAddToGraphRegion = true;
    }
    // draw draw tool
    drawLabel("Draw", x + 60, yOffset);
    drawValue("+", addToGraphX, yOffset, addToGraphWidth, false, false);
    if (drawActive) {
        drawValue("Enabled", drawToolX, yOffset, drawToolWidth, false, true);
        yOffset += VALUE_BOX_HEIGHT + (PADDING * 4);
        final float drawDescriptionHeight = (VALUE_BOX_HEIGHT * 16) + (PADDING * 2) + 1;
        renderer.noStroke();
        renderer.fill(BACKGROUND_COLOUR);
        renderer.rect(x, yOffset - 1, width, drawDescriptionHeight);
        final String drawDescription = " > Click on the map to draw a point marker.\n" + " > Click on the map while holding shift to begin drawing a circle" + "  marker, click again with or without shift to complete it.\n" + " > Click on the map while holding control to begin drawing a polygon" + "  marker, continue clicking while holding control to draw edges," + "  then release control and click once more to complete it.\n" + " > Click on a drawn marker to remove it.";
        drawInfo(drawDescription, yOffset - (PADDING * 2), width - (MARGIN * 2) - (PADDING * 2), true);
    } else {
        drawValue(DISABLED, drawToolX, yOffset, drawToolWidth, false, false);
    }
    // update map based on draw tool state
    if (mouseLeftDrawToolRegion && drawActive) {
        final int polygonColor = renderer.color(0, 0, 0, 127);
        renderer.stroke(polygonColor);
        renderer.strokeJoin(PConstants.ROUND);
        renderer.strokeCap(PConstants.ROUND);
        if (drawPolygon && drawVertices.size() > 1) {
            for (int i = 1; i < drawVertices.size(); i++) {
                final ScreenPosition previousVertex = map.getScreenPosition(drawVertices.get(i - 1));
                final ScreenPosition currentVertex = map.getScreenPosition(drawVertices.get(i));
                renderer.strokeWeight(5);
                renderer.point(previousVertex.x, previousVertex.y);
                renderer.point(currentVertex.x, currentVertex.y);
                renderer.strokeWeight(2);
                renderer.line(previousVertex.x, previousVertex.y, currentVertex.x, currentVertex.y);
            }
        } else {
            renderer.strokeWeight(5);
            renderer.point(drawOriginX, drawOriginY);
        }
        if (drawOriginX != -1 && drawOriginY != -1 && drawDeltaX != -1 && drawDeltaY != -1) {
            renderer.strokeWeight(5);
            renderer.point(drawDeltaX, drawDeltaY);
            renderer.strokeWeight(2);
            renderer.line(drawOriginX, drawOriginY, drawDeltaX, drawDeltaY);
            if (drawCircle) {
                final float radius = (float) Math.sqrt(Math.pow((drawDeltaX - drawOriginX), 2) + Math.pow((drawDeltaY - drawOriginY), 2));
                renderer.noFill();
                renderer.strokeWeight(2);
                renderer.ellipseMode(PConstants.RADIUS);
                renderer.ellipse(drawOriginX, drawOriginY, radius, radius);
            }
        }
    }
    active = measureActive || drawActive;
}
Also used : Graph(au.gov.asd.tac.constellation.graph.Graph) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) MarkerCache(au.gov.asd.tac.constellation.views.mapview.utilities.MarkerCache) ScreenPosition(de.fhpotsdam.unfolding.utils.ScreenPosition) Location(de.fhpotsdam.unfolding.geo.Location)

Example 2 with MarkerCache

use of au.gov.asd.tac.constellation.views.mapview.utilities.MarkerCache 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)

Example 3 with MarkerCache

use of au.gov.asd.tac.constellation.views.mapview.utilities.MarkerCache in project constellation by constellation-app.

the class ToolsOverlay method mouseClicked.

@Override
public void mouseClicked(final MouseEvent event) {
    if (event.getButton() == PConstants.LEFT) {
        // draw measure line
        if (mouseLeftMeasureToolRegion && measureActive) {
            if (measureOriginX == -1 && measureOriginY == -1) {
                if (event.isControlDown()) {
                    measurePath = true;
                    measureVertices.add(map.getLocation(event.getX(), event.getY()));
                } else if (event.isShiftDown()) {
                    measureCircle = true;
                } else {
                // Do nothing
                }
                measureFinished = false;
                measureOriginX = event.getX();
                measureOriginY = event.getY();
            } else {
                if (event.isControlDown()) {
                    measureVertices.add(map.getLocation(event.getX(), event.getY()));
                    measureOriginX = event.getX();
                    measureOriginY = event.getY();
                } else {
                    measureFinished = true;
                    measurePath = false;
                    measureVertices.clear();
                    measureCircle = false;
                    measureOriginX = -1;
                    measureOriginY = -1;
                    measureDeltaX = -1;
                    measureDeltaY = -1;
                }
            }
        }
        // draw markers
        final List<ConstellationAbstractMarker> hitMarkers;
        synchronized (LOCK) {
            hitMarkers = map.getHitMarkers(event.getX(), event.getY()).stream().map(ConstellationAbstractMarker.class::cast).collect(Collectors.toList());
        }
        if (mouseLeftDrawToolRegion && drawActive) {
            final MarkerCache markerCache = renderer.getMarkerCache();
            final Location clickLocation = map.getLocation(event.getX(), event.getY());
            if (hitMarkers.isEmpty()) {
                if (event.isControlDown()) {
                    drawPolygon = true;
                    drawVertices.add(clickLocation);
                    drawOriginX = event.getX();
                    drawOriginY = event.getY();
                } else if (event.isShiftDown() && !drawCircle) {
                    drawCircle = true;
                    drawOriginX = event.getX();
                    drawOriginY = event.getY();
                } else {
                    if (drawPolygon) {
                        final ConstellationShapeFeature clickFeature;
                        if (drawVertices.size() > 2) {
                            clickFeature = new ConstellationShapeFeature(ConstellationFeatureType.POLYGON);
                        } else if (drawVertices.size() == 2) {
                            clickFeature = new ConstellationShapeFeature(ConstellationFeatureType.LINE);
                        } else {
                            return;
                        }
                        drawVertices.forEach(clickFeature::addLocation);
                        renderer.addCustomMarker(clickFeature);
                        drawPolygon = false;
                        drawVertices.clear();
                        drawOriginX = -1;
                        drawOriginY = -1;
                        drawDeltaX = -1;
                        drawDeltaY = -1;
                    } else if (drawCircle) {
                        drawVertices.addAll(MarkerUtilities.generateCircle(map.getLocation(drawOriginX, drawOriginY), map.getLocation(drawDeltaX, drawDeltaY)));
                        final ConstellationShapeFeature clickFeature = new ConstellationShapeFeature(ConstellationFeatureType.POLYGON);
                        drawVertices.forEach(clickFeature::addLocation);
                        renderer.addCustomMarker(clickFeature);
                        drawCircle = false;
                        drawVertices.clear();
                        drawOriginX = -1;
                        drawOriginY = -1;
                        drawDeltaX = -1;
                        drawDeltaY = -1;
                    } else {
                        final ConstellationPointFeature clickFeature = new ConstellationPointFeature(clickLocation);
                        renderer.addCustomMarker(clickFeature);
                    }
                }
            } else {
                hitMarkers.forEach(hitMarker -> {
                    if (hitMarker.isCustom()) {
                        markerCache.get(hitMarker).remove(GraphElement.NON_ELEMENT);
                        if (markerCache.get(hitMarker).isEmpty()) {
                            map.getMarkers().remove(hitMarker);
                            markerCache.remove(hitMarker);
                        } else {
                            hitMarker.setCustom(false);
                        }
                    }
                });
            }
        }
    }
}
Also used : ConstellationAbstractMarker(au.gov.asd.tac.constellation.views.mapview.markers.ConstellationAbstractMarker) ConstellationShapeFeature(au.gov.asd.tac.constellation.views.mapview.features.ConstellationShapeFeature) ConstellationPointFeature(au.gov.asd.tac.constellation.views.mapview.features.ConstellationPointFeature) MarkerCache(au.gov.asd.tac.constellation.views.mapview.utilities.MarkerCache) Location(de.fhpotsdam.unfolding.geo.Location)

Aggregations

MarkerCache (au.gov.asd.tac.constellation.views.mapview.utilities.MarkerCache)3 PluginException (au.gov.asd.tac.constellation.plugins.PluginException)2 ConstellationAbstractMarker (au.gov.asd.tac.constellation.views.mapview.markers.ConstellationAbstractMarker)2 Location (de.fhpotsdam.unfolding.geo.Location)2 Graph (au.gov.asd.tac.constellation.graph.Graph)1 GraphWriteMethods (au.gov.asd.tac.constellation.graph.GraphWriteMethods)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 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 Tuple (au.gov.asd.tac.constellation.utilities.datastructure.Tuple)1