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;
}
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);
}
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);
}
}
});
}
}
}
}
Aggregations