Search in sources :

Example 1 with GeometryEditor

use of com.revolsys.geometry.model.editor.GeometryEditor in project com.revolsys.open by revolsys.

the class EditRecordGeometryOverlay method keyReleased.

@Override
public void keyReleased(final KeyEvent e) {
    final int keyCode = e.getKeyCode();
    if (keyCode == KeyEvent.VK_ALT) {
        if (!this.dragged) {
            if (isOverlayAction(ACTION_MOVE_GEOMETRY)) {
                if (clearOverlayAction(ACTION_MOVE_GEOMETRY)) {
                    if (this.addLayer != null) {
                        modeAddGeometryMove(null);
                    } else {
                        updateMouseOverLocations();
                    }
                }
            } else {
                if (this.addLayer == null) {
                    updateMouseOverLocations();
                } else {
                    modeAddGeometryMove(null);
                }
            }
        }
    } else if (keyCode == KeyEvent.VK_BACK_SPACE || keyCode == KeyEvent.VK_DELETE) {
        if (hasMouseOverLocation()) {
            final MultipleUndo edit = new MultipleUndo();
            for (final CloseLocation location : getMouseOverLocations()) {
                final Geometry geometry = location.getGeometry();
                final int[] vertexId = location.getVertexId();
                if (vertexId != null) {
                    try {
                        if (this.addGeometryEditor == null) {
                            final GeometryEditor<?> geometryEditor = geometry.newGeometryEditor();
                            geometryEditor.deleteVertex(vertexId);
                            if (geometryEditor.isModified()) {
                                final Geometry newGeometry = geometryEditor.newGeometry();
                                if (newGeometry.isEmpty()) {
                                    Toolkit.getDefaultToolkit().beep();
                                } else {
                                    final UndoableEdit geometryEdit = setGeometry(location, newGeometry);
                                    edit.addEdit(geometryEdit);
                                }
                            }
                        } else {
                            edit.addEdit(new DeleteVertexUndoEdit(this.addGeometryEditor, vertexId));
                        }
                    } catch (final Exception t) {
                        Toolkit.getDefaultToolkit().beep();
                    }
                }
            }
            if (!edit.isEmpty()) {
                edit.addEdit(new ClearXorUndoEdit());
                addUndo(edit);
            }
            clearMouseOverLocations();
        }
    } else if (keyCode == KeyEvent.VK_F2 || keyCode == KeyEvent.VK_F) {
        clearMouseOverLocations();
        modeMoveGeometryClear();
        if (this.addCompleteAction != null) {
            final Geometry addGeometry = this.addGeometryEditor.newGeometry();
            this.addCompleteAction.addComplete(this, addGeometry);
        }
        modeAddGeometryClear();
    } else if (splitLineKeyPress(e)) {
    }
}
Also used : CloseLocation(com.revolsys.swing.map.overlay.CloseLocation) Geometry(com.revolsys.geometry.model.Geometry) DeleteVertexUndoEdit(com.revolsys.swing.map.overlay.record.geometryeditor.DeleteVertexUndoEdit) UndoableEdit(javax.swing.undo.UndoableEdit) AbstractUndoableEdit(com.revolsys.swing.undo.AbstractUndoableEdit) Point(com.revolsys.geometry.model.Point) MultipleUndo(com.revolsys.swing.undo.MultipleUndo) GeometryEditor(com.revolsys.geometry.model.editor.GeometryEditor)

Example 2 with GeometryEditor

use of com.revolsys.geometry.model.editor.GeometryEditor in project com.revolsys.open by revolsys.

the class EditRecordGeometryOverlay method modeMoveGeometryFinish.

protected boolean modeMoveGeometryFinish(final MouseEvent event) {
    if (event.getButton() == MouseEvent.BUTTON1) {
        if (clearOverlayAction(ACTION_MOVE_GEOMETRY)) {
            clearOverlayAction(ACTION_ADD_GEOMETRY_EDIT_VERTICES);
            clearOverlayAction(ACTION_EDIT_GEOMETRY_VERTICES);
            final MultipleUndo edit = new MultipleUndo();
            for (final CloseLocation location : this.moveGeometryLocations) {
                final GeometryFactory geometryFactory = location.getGeometryFactory();
                final Point from = this.moveGeometryStart.convertGeometry(geometryFactory);
                final Point to = this.moveGeometryEnd.convertGeometry(geometryFactory);
                final double deltaX = to.getX() - from.getX();
                final double deltaY = to.getY() - from.getY();
                if (deltaX != 0 || deltaY != 0) {
                    final Geometry geometry = location.getGeometry();
                    if (geometry instanceof GeometryEditor<?>) {
                        final GeometryEditor<?> geometryEditor = (GeometryEditor<?>) geometry;
                        edit.addEdit(new MoveGeometryUndoEdit(geometryEditor, deltaX, deltaY));
                    } else {
                        final Geometry newGeometry = geometry.edit(editor -> {
                            editor.move(deltaX, deltaY);
                            for (final Vertex vertex : editor.vertices()) {
                                final double z = getElevation(vertex);
                                if (Double.isFinite(z)) {
                                    vertex.setZ(z);
                                }
                            }
                            return editor;
                        });
                        final UndoableEdit geometryEdit = setGeometry(location, newGeometry);
                        edit.addEdit(geometryEdit);
                    }
                }
            }
            if (!edit.isEmpty()) {
                edit.addEdit(new ClearXorUndoEdit());
                addUndo(edit);
            }
            modeMoveGeometryClear();
            repaint();
            return true;
        }
    }
    return false;
}
Also used : CloseLocation(com.revolsys.swing.map.overlay.CloseLocation) Geometry(com.revolsys.geometry.model.Geometry) MoveGeometryUndoEdit(com.revolsys.swing.map.overlay.record.geometryeditor.MoveGeometryUndoEdit) Vertex(com.revolsys.geometry.model.vertex.Vertex) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) UndoableEdit(javax.swing.undo.UndoableEdit) AbstractUndoableEdit(com.revolsys.swing.undo.AbstractUndoableEdit) Point(com.revolsys.geometry.model.Point) MultipleUndo(com.revolsys.swing.undo.MultipleUndo) GeometryEditor(com.revolsys.geometry.model.editor.GeometryEditor)

Example 3 with GeometryEditor

use of com.revolsys.geometry.model.editor.GeometryEditor in project com.revolsys.open by revolsys.

the class MeasureOverlay method deleteVertex.

private Geometry deleteVertex() {
    final Geometry geometry = getMeasureGeometry();
    for (final CloseLocation location : getMouseOverLocations()) {
        final int[] vertexId = location.getVertexId();
        if (vertexId != null) {
            if (geometry instanceof Point) {
                return null;
            } else if (geometry instanceof LineString) {
                final LineString line = (LineString) geometry;
                if (line.getVertexCount() == 2) {
                    if (vertexId.length == 1) {
                        if (vertexId[0] == 0) {
                            return line.getPoint(1);
                        } else {
                            return line.getPoint(0);
                        }
                    }
                }
            } else if (geometry instanceof Polygon) {
                final Polygon polygon = (Polygon) geometry;
                final LinearRing ring = polygon.getRing(0);
                if (ring.getVertexCount() == 4) {
                    if (vertexId.length == 2) {
                        final GeometryFactory geometryFactory = geometry.getGeometryFactory();
                        final Vertex point0 = ring.getVertex(0);
                        final Vertex point1 = ring.getVertex(1);
                        final Vertex point2 = ring.getVertex(2);
                        switch(vertexId[1]) {
                            case 0:
                                return geometryFactory.lineString(point1, point2);
                            case 1:
                                return geometryFactory.lineString(point2, point0);
                            default:
                                return geometryFactory.lineString(point0, point1);
                        }
                    }
                }
            }
            try {
                final GeometryEditor geometryEditor = geometry.newGeometryEditor();
                geometryEditor.deleteVertex(vertexId);
                if (geometryEditor.isModified()) {
                    return geometryEditor.newGeometry();
                }
            } catch (final Exception e) {
                Toolkit.getDefaultToolkit().beep();
                return geometry;
            }
        }
    }
    return geometry;
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) Vertex(com.revolsys.geometry.model.vertex.Vertex) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) LineString(com.revolsys.geometry.model.LineString) Point(com.revolsys.geometry.model.Point) Polygon(com.revolsys.geometry.model.Polygon) LinearRing(com.revolsys.geometry.model.LinearRing) GeometryEditor(com.revolsys.geometry.model.editor.GeometryEditor)

Example 4 with GeometryEditor

use of com.revolsys.geometry.model.editor.GeometryEditor in project com.revolsys.open by revolsys.

the class EditRecordGeometryOverlay method addRecord.

/**
 * Set the addLayer that a new feature is to be added to.
 *
 * @param addLayer
 */
@SuppressWarnings("unchecked")
public void addRecord(final AbstractRecordLayer layer, final AddGeometryCompleteAction addCompleteAction) {
    if (layer != null) {
        final RecordDefinition recordDefinition = layer.getRecordDefinition();
        final FieldDefinition geometryField = recordDefinition.getGeometryField();
        if (geometryField != null) {
            this.addLayer = layer;
            this.addCompleteAction = addCompleteAction;
            final GeometryFactory geometryFactory = recordDefinition.getGeometryFactory();
            this.setGeometryFactory(geometryFactory);
            clearUndoHistory();
            setOverlayAction(ACTION_ADD_GEOMETRY);
            final GeometryDataType<Geometry, GeometryEditor<?>> geometryDataType = (GeometryDataType<Geometry, GeometryEditor<?>>) geometryField.getDataType();
            setAddGeometryDataType(geometryDataType, geometryFactory);
            setMapCursor(CURSOR_NODE_ADD);
        }
    }
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) FieldDefinition(com.revolsys.record.schema.FieldDefinition) GeometryDataType(com.revolsys.geometry.model.GeometryDataType) RecordDefinition(com.revolsys.record.schema.RecordDefinition) GeometryEditor(com.revolsys.geometry.model.editor.GeometryEditor)

Aggregations

Geometry (com.revolsys.geometry.model.Geometry)4 GeometryEditor (com.revolsys.geometry.model.editor.GeometryEditor)4 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)3 Point (com.revolsys.geometry.model.Point)3 Vertex (com.revolsys.geometry.model.vertex.Vertex)2 CloseLocation (com.revolsys.swing.map.overlay.CloseLocation)2 AbstractUndoableEdit (com.revolsys.swing.undo.AbstractUndoableEdit)2 MultipleUndo (com.revolsys.swing.undo.MultipleUndo)2 UndoableEdit (javax.swing.undo.UndoableEdit)2 GeometryDataType (com.revolsys.geometry.model.GeometryDataType)1 LineString (com.revolsys.geometry.model.LineString)1 LinearRing (com.revolsys.geometry.model.LinearRing)1 Polygon (com.revolsys.geometry.model.Polygon)1 FieldDefinition (com.revolsys.record.schema.FieldDefinition)1 RecordDefinition (com.revolsys.record.schema.RecordDefinition)1 DeleteVertexUndoEdit (com.revolsys.swing.map.overlay.record.geometryeditor.DeleteVertexUndoEdit)1 MoveGeometryUndoEdit (com.revolsys.swing.map.overlay.record.geometryeditor.MoveGeometryUndoEdit)1