svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / gui / cad / tools / MoveCADTool.java @ 39578
History | View | Annotate | Download (9.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.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 |
&& !SelectionCADTool.isInstance(CADExtension.getCADTool(), true)) {
|
113 |
CADExtension.setCADTool("_selection", false); |
114 |
((SelectionCADTool) CADExtension.getCADTool()) |
115 |
.setNextTool("_move");
|
116 |
} |
117 |
} catch (ReadException e) {
|
118 |
// TODO Auto-generated catch block
|
119 |
e.printStackTrace(); |
120 |
} catch (DataException e) {
|
121 |
// TODO Auto-generated catch block
|
122 |
e.printStackTrace(); |
123 |
} |
124 |
} |
125 |
|
126 |
/**
|
127 |
* Equivale al transition del prototipo pero sin pasarle como par?metro el
|
128 |
* editableFeatureSource que ya estar? creado.
|
129 |
*
|
130 |
* @param x
|
131 |
* par?metro x del punto que se pase en esta transici?n.
|
132 |
* @param y
|
133 |
* par?metro y del punto que se pase en esta transici?n.
|
134 |
*/
|
135 |
public void addPoint(double x, double y, InputEvent event) { |
136 |
MoveCADToolState actualState = |
137 |
(MoveCADToolState) _fsm.getPreviousState(); |
138 |
String status = actualState.getName();
|
139 |
VectorialLayerEdited vle = getVLE(); |
140 |
FeatureStore featureStore = null;
|
141 |
try {
|
142 |
featureStore = vle.getFeatureStore(); |
143 |
} catch (ReadException e1) {
|
144 |
// TODO Auto-generated catch block
|
145 |
e1.printStackTrace(); |
146 |
} |
147 |
DisposableIterator iterator = null;
|
148 |
try {
|
149 |
FeatureSet selection = (FeatureSet) featureStore.getSelection();// getSelectedRows();
|
150 |
// ArrayList selectedRowAux=new ArrayList();
|
151 |
ICoordTrans ct = getVLE().getLayer().getCoordTrans(); |
152 |
if (status.equals("Move.FirstPointToMove")) { |
153 |
firstPoint = new Point2D.Double(x, y); |
154 |
} else
|
155 |
if (status.equals("Move.SecondPointToMove")) { |
156 |
PluginServices.getMDIManager().setWaitCursor(); |
157 |
lastPoint = new Point2D.Double(x, y); |
158 |
|
159 |
featureStore.beginEditingGroup(getName()); |
160 |
try {
|
161 |
|
162 |
iterator = selection.iterator(); |
163 |
while (iterator.hasNext()) {
|
164 |
Feature feature = (Feature) iterator.next(); |
165 |
|
166 |
// }
|
167 |
// for (int i = 0; i < selection.size(); i++) {
|
168 |
// IRowEdited edRow = (IRowEdited)
|
169 |
// selectedRow.get(i);
|
170 |
// IFeature feat = (IFeature)
|
171 |
// edRow.getLinkedRow().cloneRow();
|
172 |
Geometry ig = |
173 |
(feature.getDefaultGeometry()).cloneGeometry(); |
174 |
if (ig == null) { |
175 |
continue;
|
176 |
} |
177 |
if (ct != null) { |
178 |
lastPoint = |
179 |
ct.getInverted().convert(lastPoint, null);
|
180 |
firstPoint = |
181 |
ct.getInverted().convert(firstPoint, null);
|
182 |
|
183 |
} |
184 |
// if (ct!=null)
|
185 |
// ig.reProject(ct);
|
186 |
// Movemos la geometr?a
|
187 |
ig.move(lastPoint.getX() - firstPoint.getX(), |
188 |
lastPoint.getY() - firstPoint.getY()); |
189 |
|
190 |
// if (ct!=null)
|
191 |
// ig.reProject(ct.getInverted());
|
192 |
|
193 |
super.updateGeometry(featureStore, feature, ig);
|
194 |
//
|
195 |
// EditableFeature eFeature = feature.getEditable();
|
196 |
// eFeature.setGeometry(featureStore
|
197 |
// .getDefaultFeatureType()
|
198 |
// .getDefaultGeometryAttributeName(), ig);
|
199 |
// featureStore.update(eFeature);
|
200 |
//
|
201 |
|
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 |
} |