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