01: /* uDig - User Friendly Desktop Internet GIS client
02: * http://udig.refractions.net
03: * (C) 2004, Refractions Research Inc.
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation;
08: * version 2.1 of the License.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: */
15: package net.refractions.udig.tools.edit.commands;
16:
17: import net.refractions.udig.project.command.AbstractCommand;
18: import net.refractions.udig.project.command.UndoableMapCommand;
19: import net.refractions.udig.tools.edit.EditToolHandler;
20: import net.refractions.udig.tools.edit.support.EditBlackboard;
21: import net.refractions.udig.tools.edit.support.EditGeom;
22: import net.refractions.udig.tools.edit.support.Point;
23: import net.refractions.udig.tools.edit.support.PrimitiveShape;
24:
25: import org.eclipse.core.runtime.IProgressMonitor;
26:
27: /**
28: * Removes all vertices from EditGeom's shell.
29: *
30: * @author Jesse
31: * @since 1.1.0
32: */
33: public class RemoveAllVerticesCommand extends AbstractCommand implements
34: UndoableMapCommand {
35:
36: private EditToolHandler handler;
37: private EditGeom oldGeom;
38:
39: public RemoveAllVerticesCommand(EditToolHandler handler) {
40: this .handler = handler;
41: }
42:
43: public void run(IProgressMonitor monitor) throws Exception {
44: EditGeom geom = handler.getCurrentGeom();
45:
46: oldGeom = new EditGeom(geom);
47: for (Point point : geom.getShell()) {
48: geom.getEditBlackboard().removeCoords(point.getX(),
49: point.getY(), geom.getShell());
50: }
51: }
52:
53: public String getName() {
54: return "RemoveAllVerticesCommand"; //$NON-NLS-1$
55: }
56:
57: public void rollback(IProgressMonitor monitor) throws Exception {
58: EditBlackboard bb = oldGeom.getEditBlackboard();
59: EditGeom geom = bb.newGeom(oldGeom.getFeatureIDRef().get(),
60: oldGeom.getShapeType());
61: for (Point p : oldGeom.getShell()) {
62: bb.addPoint(p.getX(), p.getY(), geom.getShell());
63: }
64:
65: for (PrimitiveShape shape : oldGeom.getHoles()) {
66: PrimitiveShape hole = geom.newHole();
67: for (Point p : shape) {
68: bb.addPoint(p.getX(), p.getY(), hole);
69: }
70: }
71:
72: }
73:
74: }
|