svn-gvsig-desktop / tags / v2_0_0_Build_2060 / extensions / extEditing / src / org / gvsig / editing / gui / cad / tools / CopyCADTool.java @ 39348
History | View | Annotate | Download (8.74 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.editing.gui.cad.tools; |
23 |
|
24 |
import java.awt.event.InputEvent; |
25 |
import java.awt.geom.Point2D; |
26 |
|
27 |
import org.gvsig.andami.PluginServices; |
28 |
import org.gvsig.andami.messages.NotificationManager; |
29 |
import org.gvsig.editing.CADExtension; |
30 |
import org.gvsig.editing.gui.cad.DefaultCADTool; |
31 |
import org.gvsig.editing.gui.cad.exception.CommandException; |
32 |
import org.gvsig.editing.gui.cad.tools.smc.CopyCADToolContext; |
33 |
import org.gvsig.editing.gui.cad.tools.smc.CopyCADToolContext.CopyCADToolState; |
34 |
import org.gvsig.editing.layers.VectorialLayerEdited; |
35 |
import org.gvsig.fmap.dal.exception.DataException; |
36 |
import org.gvsig.fmap.dal.exception.ReadException; |
37 |
import org.gvsig.fmap.dal.feature.Feature; |
38 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
39 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
40 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
41 |
import org.gvsig.fmap.geom.Geometry; |
42 |
import org.gvsig.fmap.geom.type.GeometryType; |
43 |
import org.gvsig.fmap.geom.util.UtilFunctions; |
44 |
import org.gvsig.fmap.mapcontrol.MapControlDrawer; |
45 |
import org.gvsig.tools.dispose.DisposableIterator; |
46 |
|
47 |
/**
|
48 |
* DOCUMENT ME!
|
49 |
*
|
50 |
* @author Vicente Caballero Navarro
|
51 |
*/
|
52 |
public class CopyCADTool extends DefaultCADTool { |
53 |
|
54 |
private CopyCADToolContext _fsm;
|
55 |
private Point2D firstPoint; |
56 |
private Point2D lastPoint; |
57 |
private GeometryType[] gTypes; |
58 |
|
59 |
/**
|
60 |
* M?todo de incio, para poner el c?digo de todo lo que se requiera de una
|
61 |
* carga previa a la utilizaci?n de la herramienta.
|
62 |
*/
|
63 |
public void init() { |
64 |
_fsm = new CopyCADToolContext(this); |
65 |
} |
66 |
|
67 |
/*
|
68 |
* (non-Javadoc)
|
69 |
*
|
70 |
* @see
|
71 |
* com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap
|
72 |
* .layers.FBitSet, double, double)
|
73 |
*/
|
74 |
public void transition(double x, double y, InputEvent event) { |
75 |
_fsm.addPoint(x, y, event); |
76 |
} |
77 |
|
78 |
/*
|
79 |
* (non-Javadoc)
|
80 |
*
|
81 |
* @see
|
82 |
* com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap
|
83 |
* .layers.FBitSet, double)
|
84 |
*/
|
85 |
public void transition(double d) { |
86 |
_fsm.addValue(d); |
87 |
} |
88 |
|
89 |
/*
|
90 |
* (non-Javadoc)
|
91 |
*
|
92 |
* @see
|
93 |
* com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap
|
94 |
* .layers.FBitSet, java.lang.String)
|
95 |
*/
|
96 |
public void transition(String s) throws CommandException { |
97 |
if (!super.changeCommand(s)) { |
98 |
_fsm.addOption(s); |
99 |
} |
100 |
} |
101 |
|
102 |
/**
|
103 |
* DOCUMENT ME!
|
104 |
*/
|
105 |
public void selection() { |
106 |
FeatureSet selection = null;
|
107 |
try {
|
108 |
selection = (FeatureSet) getVLE().getFeatureStore().getSelection(); |
109 |
|
110 |
if (selection.getSize() == 0 |
111 |
&& !CADExtension |
112 |
.getCADTool() |
113 |
.getClass() |
114 |
.getName() |
115 |
.equals("com.iver.cit.gvsig.gui.cad.tools.SelectionCADTool")) {
|
116 |
CADExtension.setCADTool("_selection", false); |
117 |
((SelectionCADTool) CADExtension.getCADTool()) |
118 |
.setNextTool("_copy");
|
119 |
} |
120 |
} catch (ReadException e) {
|
121 |
// TODO Auto-generated catch block
|
122 |
e.printStackTrace(); |
123 |
} catch (DataException e) {
|
124 |
// TODO Auto-generated catch block
|
125 |
e.printStackTrace(); |
126 |
} |
127 |
} |
128 |
|
129 |
/**
|
130 |
* Equivale al transition del prototipo pero sin pasarle como par?metro el
|
131 |
* editableFeatureSource que ya estar? creado.
|
132 |
*
|
133 |
* @param x
|
134 |
* par?metro x del punto que se pase en esta transici?n.
|
135 |
* @param y
|
136 |
* par?metro y del punto que se pase en esta transici?n.
|
137 |
*/
|
138 |
public void addPoint(double x, double y, InputEvent event) { |
139 |
CopyCADToolState actualState = |
140 |
(CopyCADToolState) _fsm.getPreviousState(); |
141 |
String status = actualState.getName();
|
142 |
VectorialLayerEdited vle = getVLE(); |
143 |
FeatureStore featureStore = null;
|
144 |
try {
|
145 |
featureStore = vle.getFeatureStore(); |
146 |
// FeatureSelection selection =
|
147 |
// featureStore.createFeatureSelection();
|
148 |
// selection.select((FeatureSet) featureStore.getSelection());
|
149 |
FeatureSelection selection = |
150 |
(FeatureSelection) featureStore.getSelection(); |
151 |
if (status.equals("Copy.FirstPointToMove")) { |
152 |
firstPoint = new Point2D.Double(x, y); |
153 |
} else
|
154 |
if (status.equals("Copy.SecondPointToMove")) { |
155 |
PluginServices.getMDIManager().setWaitCursor(); |
156 |
lastPoint = new Point2D.Double(x, y); |
157 |
featureStore.beginEditingGroup(getName()); |
158 |
|
159 |
FeatureSelection newSelection = |
160 |
featureStore.createFeatureSelection(); |
161 |
|
162 |
DisposableIterator iterator = null;
|
163 |
|
164 |
try {
|
165 |
iterator = selection.iterator(); |
166 |
|
167 |
featureStore.beginComplexNotification(); |
168 |
|
169 |
while (iterator.hasNext()) {
|
170 |
Feature feature = (Feature) iterator.next(); |
171 |
// Movemos la geometr?a
|
172 |
Geometry geometry = |
173 |
(feature.getDefaultGeometry()).cloneGeometry(); |
174 |
// EditableFeature
|
175 |
// eFeature=featureStore.createNewFeature(true);
|
176 |
geometry.move(lastPoint.getX() - firstPoint.getX(), |
177 |
lastPoint.getY() - firstPoint.getY()); |
178 |
|
179 |
// eFeature.setGeometry(featureStore.getDefaultFeatureType().getDefaultGeometryAttributeName(),geometry);
|
180 |
// featureStore.insert(eFeature);
|
181 |
newSelection.select(insertGeometry(geometry, |
182 |
feature)); |
183 |
} |
184 |
// clearSelection();
|
185 |
featureStore.endComplexNotification(); |
186 |
featureStore.setSelection(newSelection); |
187 |
featureStore.endEditingGroup(); |
188 |
PluginServices.getMDIManager().restoreCursor(); |
189 |
} catch (DataException e) {
|
190 |
featureStore.endComplexNotification(); |
191 |
throw e;
|
192 |
} finally {
|
193 |
if (iterator != null) { |
194 |
iterator.dispose(); |
195 |
} |
196 |
} |
197 |
|
198 |
} else {
|
199 |
} |
200 |
} catch (DataException e) {
|
201 |
NotificationManager.addError(e.getMessage(), e); |
202 |
} |
203 |
} |
204 |
|
205 |
/**
|
206 |
* M?todo para dibujar la lo necesario para el estado en el que nos
|
207 |
* encontremos.
|
208 |
*
|
209 |
* @param g
|
210 |
* Graphics sobre el que dibujar.
|
211 |
* @param x
|
212 |
* par?metro x del punto que se pase para dibujar.
|
213 |
* @param y
|
214 |
* par?metro x del punto que se pase para dibujar.
|
215 |
*/
|
216 |
public void drawOperation(MapControlDrawer renderer, double x, double y) { |
217 |
CopyCADToolState actualState = _fsm.getState(); |
218 |
String status = actualState.getName();
|
219 |
VectorialLayerEdited vle = getVLE(); |
220 |
if (status.equals("Copy.SecondPointToMove")) { |
221 |
drawSelectedGeometries(renderer, firstPoint, x, y); |
222 |
} |
223 |
} |
224 |
|
225 |
/**
|
226 |
* Add a diferent option.
|
227 |
*
|
228 |
* @param s
|
229 |
* Diferent option.
|
230 |
*/
|
231 |
public void addOption(String s) { |
232 |
} |
233 |
|
234 |
/*
|
235 |
* (non-Javadoc)
|
236 |
*
|
237 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
|
238 |
*/
|
239 |
public void addValue(double d) { |
240 |
} |
241 |
|
242 |
public String getName() { |
243 |
return PluginServices.getText(this, "copy_"); |
244 |
} |
245 |
|
246 |
public String toString() { |
247 |
return "_copy"; |
248 |
} |
249 |
|
250 |
@Override
|
251 |
public boolean isApplicable(GeometryType geometryType) { |
252 |
return true; |
253 |
} |
254 |
|
255 |
@Override
|
256 |
protected int[] getSupportedGeometryTypes() { |
257 |
return null; |
258 |
} |
259 |
} |