root / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / gui / cad / tools / MoveCADTool.java @ 37328
History | View | Annotate | Download (9.71 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.cresques.cts.ICoordTrans; |
28 |
|
29 |
import org.gvsig.andami.PluginServices; |
30 |
import org.gvsig.andami.messages.NotificationManager; |
31 |
import org.gvsig.editing.CADExtension; |
32 |
import org.gvsig.editing.gui.cad.DefaultCADTool; |
33 |
import org.gvsig.editing.gui.cad.exception.CommandException; |
34 |
import org.gvsig.editing.gui.cad.tools.smc.MoveCADToolContext; |
35 |
import org.gvsig.editing.gui.cad.tools.smc.MoveCADToolContext.MoveCADToolState; |
36 |
import org.gvsig.editing.layers.VectorialLayerEdited; |
37 |
import org.gvsig.fmap.dal.exception.DataException; |
38 |
import org.gvsig.fmap.dal.exception.ReadException; |
39 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
40 |
import org.gvsig.fmap.dal.feature.Feature; |
41 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
42 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
43 |
import org.gvsig.fmap.geom.Geometry; |
44 |
import org.gvsig.fmap.geom.type.GeometryType; |
45 |
import org.gvsig.fmap.geom.util.UtilFunctions; |
46 |
import org.gvsig.fmap.mapcontrol.MapControlDrawer; |
47 |
import org.gvsig.tools.dispose.DisposableIterator; |
48 |
|
49 |
/**
|
50 |
* DOCUMENT ME!
|
51 |
*
|
52 |
* @author Vicente Caballero Navarro
|
53 |
*/
|
54 |
public class MoveCADTool extends DefaultCADTool { |
55 |
|
56 |
protected MoveCADToolContext _fsm;
|
57 |
protected Point2D firstPoint; |
58 |
protected Point2D lastPoint; |
59 |
|
60 |
/**
|
61 |
* M?todo de incio, para poner el c?digo de todo lo que se requiera de una
|
62 |
* carga previa a la utilizaci?n de la herramienta.
|
63 |
*/
|
64 |
public void init() { |
65 |
_fsm = new MoveCADToolContext(this); |
66 |
} |
67 |
|
68 |
/*
|
69 |
* (non-Javadoc)
|
70 |
*
|
71 |
* @see
|
72 |
* com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap
|
73 |
* .layers.FBitSet, double, double)
|
74 |
*/
|
75 |
public void transition(double x, double y, InputEvent event) { |
76 |
_fsm.addPoint(x, y, event); |
77 |
} |
78 |
|
79 |
/*
|
80 |
* (non-Javadoc)
|
81 |
*
|
82 |
* @see
|
83 |
* com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap
|
84 |
* .layers.FBitSet, double)
|
85 |
*/
|
86 |
public void transition(double d) { |
87 |
_fsm.addValue(d); |
88 |
} |
89 |
|
90 |
/*
|
91 |
* (non-Javadoc)
|
92 |
*
|
93 |
* @see
|
94 |
* com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap
|
95 |
* .layers.FBitSet, java.lang.String)
|
96 |
*/
|
97 |
public void transition(String s) throws CommandException { |
98 |
if (!super.changeCommand(s)) { |
99 |
_fsm.addOption(s); |
100 |
} |
101 |
} |
102 |
|
103 |
/**
|
104 |
* DOCUMENT ME!
|
105 |
*/
|
106 |
public void selection() { |
107 |
FeatureSet selection = null;
|
108 |
try {
|
109 |
selection = (FeatureSet) getVLE().getFeatureStore().getSelection(); |
110 |
|
111 |
if (selection.getSize() == 0 |
112 |
&& !CADExtension |
113 |
.getCADTool() |
114 |
.getClass() |
115 |
.getName() |
116 |
.equals("com.iver.cit.gvsig.gui.cad.tools.SelectionCADTool")) {
|
117 |
CADExtension.setCADTool("_selection", false); |
118 |
((SelectionCADTool) CADExtension.getCADTool()) |
119 |
.setNextTool("_move");
|
120 |
} |
121 |
} catch (ReadException e) {
|
122 |
// TODO Auto-generated catch block
|
123 |
e.printStackTrace(); |
124 |
} catch (DataException e) {
|
125 |
// TODO Auto-generated catch block
|
126 |
e.printStackTrace(); |
127 |
} |
128 |
} |
129 |
|
130 |
/**
|
131 |
* Equivale al transition del prototipo pero sin pasarle como par?metro el
|
132 |
* editableFeatureSource que ya estar? creado.
|
133 |
*
|
134 |
* @param x
|
135 |
* par?metro x del punto que se pase en esta transici?n.
|
136 |
* @param y
|
137 |
* par?metro y del punto que se pase en esta transici?n.
|
138 |
*/
|
139 |
public void addPoint(double x, double y, InputEvent event) { |
140 |
MoveCADToolState actualState = |
141 |
(MoveCADToolState) _fsm.getPreviousState(); |
142 |
String status = actualState.getName();
|
143 |
VectorialLayerEdited vle = getVLE(); |
144 |
FeatureStore featureStore = null;
|
145 |
try {
|
146 |
featureStore = vle.getFeatureStore(); |
147 |
} catch (ReadException e1) {
|
148 |
// TODO Auto-generated catch block
|
149 |
e1.printStackTrace(); |
150 |
} |
151 |
DisposableIterator iterator = null;
|
152 |
try {
|
153 |
FeatureSet selection = (FeatureSet) featureStore.getSelection();// getSelectedRows();
|
154 |
// ArrayList selectedRowAux=new ArrayList();
|
155 |
ICoordTrans ct = getVLE().getLayer().getCoordTrans(); |
156 |
if (status.equals("Move.FirstPointToMove")) { |
157 |
firstPoint = new Point2D.Double(x, y); |
158 |
} else
|
159 |
if (status.equals("Move.SecondPointToMove")) { |
160 |
PluginServices.getMDIManager().setWaitCursor(); |
161 |
lastPoint = new Point2D.Double(x, y); |
162 |
|
163 |
featureStore.beginEditingGroup(getName()); |
164 |
try {
|
165 |
|
166 |
iterator = selection.iterator(); |
167 |
while (iterator.hasNext()) {
|
168 |
Feature feature = (Feature) iterator.next(); |
169 |
|
170 |
// }
|
171 |
// for (int i = 0; i < selection.size(); i++) {
|
172 |
// IRowEdited edRow = (IRowEdited)
|
173 |
// selectedRow.get(i);
|
174 |
// IFeature feat = (IFeature)
|
175 |
// edRow.getLinkedRow().cloneRow();
|
176 |
Geometry ig = |
177 |
(feature.getDefaultGeometry()).cloneGeometry(); |
178 |
EditableFeature eFeature = feature.getEditable(); |
179 |
if (ig == null) { |
180 |
continue;
|
181 |
} |
182 |
if (ct != null) { |
183 |
lastPoint = |
184 |
ct.getInverted().convert(lastPoint, null);
|
185 |
firstPoint = |
186 |
ct.getInverted().convert(firstPoint, null);
|
187 |
|
188 |
} |
189 |
// if (ct!=null)
|
190 |
// ig.reProject(ct);
|
191 |
// Movemos la geometr?a
|
192 |
UtilFunctions.moveGeom(ig, lastPoint.getX() |
193 |
- firstPoint.getX(), lastPoint.getY() |
194 |
- firstPoint.getY()); |
195 |
|
196 |
// if (ct!=null)
|
197 |
// ig.reProject(ct.getInverted());
|
198 |
eFeature.setGeometry(featureStore |
199 |
.getDefaultFeatureType() |
200 |
.getDefaultGeometryAttributeName(), ig); |
201 |
featureStore.update(eFeature); |
202 |
// vea.modifyRow(edRow.getIndex(),feat,getName(),EditionEvent.GRAPHIC);
|
203 |
// selectedRowAux.add(new
|
204 |
// DefaultRowEdited(feat,IRowEdited.STATUS_MODIFIED,edRow.getIndex()));
|
205 |
} |
206 |
} finally {
|
207 |
featureStore.endEditingGroup(); |
208 |
} |
209 |
// vle.setSelectionCache(VectorialLayerEdited.NOTSAVEPREVIOUS,
|
210 |
// selectedRowAux);
|
211 |
// clearSelection();
|
212 |
// selectedRow.addAll(selectedRowAux);
|
213 |
} |
214 |
} catch (ReadException e) {
|
215 |
NotificationManager.addError(e.getMessage(), e); |
216 |
} catch (DataException e) {
|
217 |
NotificationManager.addError(e.getMessage(), e); |
218 |
} finally {
|
219 |
if (iterator != null) { |
220 |
iterator.dispose(); |
221 |
} |
222 |
} |
223 |
PluginServices.getMDIManager().restoreCursor(); |
224 |
} |
225 |
|
226 |
/**
|
227 |
* M?todo para dibujar lo necesario para el estado en el que nos
|
228 |
* encontremos.
|
229 |
*
|
230 |
* @param g
|
231 |
* Graphics sobre el que dibujar.
|
232 |
* @param x
|
233 |
* par?metro x del punto que se pase para dibujar.
|
234 |
* @param y
|
235 |
* par?metro x del punto que se pase para dibujar.
|
236 |
*/
|
237 |
public void drawOperation(MapControlDrawer renderer, double x, double y) { |
238 |
MoveCADToolState actualState = (_fsm).getState(); |
239 |
String status = actualState.getName();
|
240 |
VectorialLayerEdited vle = getVLE(); |
241 |
|
242 |
if (status.equals("Move.SecondPointToMove")) { |
243 |
drawSelectedGeometries(renderer, firstPoint, x, y); |
244 |
} |
245 |
} |
246 |
|
247 |
/**
|
248 |
* Add a diferent option.
|
249 |
*
|
250 |
* @param s
|
251 |
* Diferent option.
|
252 |
*/
|
253 |
public void addOption(String s) { |
254 |
} |
255 |
|
256 |
/*
|
257 |
* (non-Javadoc)
|
258 |
*
|
259 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
|
260 |
*/
|
261 |
public void addValue(double d) { |
262 |
} |
263 |
|
264 |
public String getName() { |
265 |
return PluginServices.getText(this, "move_"); |
266 |
} |
267 |
|
268 |
public String toString() { |
269 |
return "_move"; |
270 |
} |
271 |
|
272 |
@Override
|
273 |
public boolean isApplicable(GeometryType geometryType) { |
274 |
return true; |
275 |
} |
276 |
|
277 |
@Override
|
278 |
protected int[] getSupportedGeometryTypes() { |
279 |
return null; |
280 |
} |
281 |
|
282 |
} |