root / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / gui / cad / tools / MoveCADTool.java @ 29616
History | View | Annotate | Download (10.6 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program 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
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package org.gvsig.editing.gui.cad.tools; |
42 |
|
43 |
import java.awt.Graphics; |
44 |
import java.awt.Image; |
45 |
import java.awt.event.InputEvent; |
46 |
import java.awt.geom.Point2D; |
47 |
|
48 |
import org.cresques.cts.ICoordTrans; |
49 |
import org.gvsig.andami.PluginServices; |
50 |
import org.gvsig.andami.messages.NotificationManager; |
51 |
import org.gvsig.editing.CADExtension; |
52 |
import org.gvsig.editing.gui.cad.DefaultCADTool; |
53 |
import org.gvsig.editing.gui.cad.exception.CommandException; |
54 |
import org.gvsig.editing.gui.cad.tools.smc.MoveCADToolContext; |
55 |
import org.gvsig.editing.gui.cad.tools.smc.MoveCADToolContext.MoveCADToolState; |
56 |
import org.gvsig.editing.layers.VectorialLayerEdited; |
57 |
import org.gvsig.fmap.dal.exception.DataException; |
58 |
import org.gvsig.fmap.dal.exception.ReadException; |
59 |
import org.gvsig.fmap.dal.feature.DisposableIterator; |
60 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
61 |
import org.gvsig.fmap.dal.feature.Feature; |
62 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
63 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
64 |
import org.gvsig.fmap.geom.Geometry; |
65 |
import org.gvsig.fmap.geom.util.UtilFunctions; |
66 |
import org.gvsig.fmap.mapcontext.ViewPort; |
67 |
|
68 |
|
69 |
|
70 |
/**
|
71 |
* DOCUMENT ME!
|
72 |
*
|
73 |
* @author Vicente Caballero Navarro
|
74 |
*/
|
75 |
public class MoveCADTool extends DefaultCADTool { |
76 |
protected MoveCADToolContext _fsm;
|
77 |
protected Point2D firstPoint; |
78 |
protected Point2D lastPoint; |
79 |
|
80 |
/**
|
81 |
* Crea un nuevo PolylineCADTool.
|
82 |
*/
|
83 |
public MoveCADTool() {
|
84 |
} |
85 |
|
86 |
/**
|
87 |
* M?todo de incio, para poner el c?digo de todo lo que se requiera de una
|
88 |
* carga previa a la utilizaci?n de la herramienta.
|
89 |
*/
|
90 |
public void init() { |
91 |
_fsm = new MoveCADToolContext(this); |
92 |
} |
93 |
|
94 |
/* (non-Javadoc)
|
95 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double, double)
|
96 |
*/
|
97 |
public void transition(double x, double y, InputEvent event) { |
98 |
_fsm.addPoint(x, y, event); |
99 |
} |
100 |
|
101 |
/* (non-Javadoc)
|
102 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double)
|
103 |
*/
|
104 |
public void transition(double d) { |
105 |
_fsm.addValue(d); |
106 |
} |
107 |
|
108 |
/* (non-Javadoc)
|
109 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, java.lang.String)
|
110 |
*/
|
111 |
public void transition(String s) throws CommandException { |
112 |
if (!super.changeCommand(s)){ |
113 |
_fsm.addOption(s); |
114 |
} |
115 |
} |
116 |
|
117 |
/**
|
118 |
* DOCUMENT ME!
|
119 |
*/
|
120 |
public void selection() { |
121 |
FeatureSet selection=null;
|
122 |
try {
|
123 |
selection = (FeatureSet)getVLE().getFeatureStore().getSelection(); |
124 |
|
125 |
if (selection.getSize() == 0 && !CADExtension.getCADTool().getClass().getName().equals("com.iver.cit.gvsig.gui.cad.tools.SelectionCADTool")) { |
126 |
CADExtension.setCADTool("_selection",false); |
127 |
((SelectionCADTool) CADExtension.getCADTool()).setNextTool( |
128 |
"_move");
|
129 |
} |
130 |
} catch (ReadException e) {
|
131 |
// TODO Auto-generated catch block
|
132 |
e.printStackTrace(); |
133 |
} catch (DataException e) {
|
134 |
// TODO Auto-generated catch block
|
135 |
e.printStackTrace(); |
136 |
} |
137 |
} |
138 |
|
139 |
/**
|
140 |
* Equivale al transition del prototipo pero sin pasarle como par?metro el
|
141 |
* editableFeatureSource que ya estar? creado.
|
142 |
*
|
143 |
* @param x par?metro x del punto que se pase en esta transici?n.
|
144 |
* @param y par?metro y del punto que se pase en esta transici?n.
|
145 |
*/
|
146 |
public void addPoint(double x, double y,InputEvent event) { |
147 |
MoveCADToolState actualState = (MoveCADToolState) _fsm |
148 |
.getPreviousState(); |
149 |
String status = actualState.getName();
|
150 |
VectorialLayerEdited vle=getVLE(); |
151 |
FeatureStore featureStore=null;
|
152 |
try {
|
153 |
featureStore = vle.getFeatureStore(); |
154 |
} catch (ReadException e1) {
|
155 |
// TODO Auto-generated catch block
|
156 |
e1.printStackTrace(); |
157 |
} |
158 |
DisposableIterator iterator = null;
|
159 |
try {
|
160 |
FeatureSet selection = (FeatureSet) featureStore.getSelection();// getSelectedRows();
|
161 |
// ArrayList selectedRowAux=new ArrayList();
|
162 |
ICoordTrans ct = getVLE().getLayer().getCoordTrans(); |
163 |
if (status.equals("Move.FirstPointToMove")) { |
164 |
firstPoint = new Point2D.Double(x, y); |
165 |
} else if (status.equals("Move.SecondPointToMove")) { |
166 |
PluginServices.getMDIManager().setWaitCursor(); |
167 |
lastPoint = new Point2D.Double(x, y); |
168 |
|
169 |
featureStore.beginEditingGroup(getName()); |
170 |
try {
|
171 |
|
172 |
iterator = selection.iterator(); |
173 |
while (iterator.hasNext()) {
|
174 |
Feature feature = (Feature) iterator.next(); |
175 |
|
176 |
// }
|
177 |
// for (int i = 0; i < selection.size(); i++) {
|
178 |
// IRowEdited edRow = (IRowEdited) selectedRow.get(i);
|
179 |
// IFeature feat = (IFeature)
|
180 |
// edRow.getLinkedRow().cloneRow();
|
181 |
Geometry ig = (feature.getDefaultGeometry()) |
182 |
.cloneGeometry(); |
183 |
EditableFeature eFeature = feature.getEditable(); |
184 |
if (ig == null) { |
185 |
continue;
|
186 |
} |
187 |
if (ct != null) { |
188 |
lastPoint = ct.getInverted().convert(lastPoint, |
189 |
null);
|
190 |
firstPoint = ct.getInverted().convert(firstPoint, |
191 |
null);
|
192 |
|
193 |
} |
194 |
// if (ct!=null)
|
195 |
// ig.reProject(ct);
|
196 |
// Movemos la geometr?a
|
197 |
UtilFunctions.moveGeom(ig, lastPoint.getX() |
198 |
- firstPoint.getX(), lastPoint.getY() |
199 |
- firstPoint.getY()); |
200 |
|
201 |
// if (ct!=null)
|
202 |
// ig.reProject(ct.getInverted());
|
203 |
eFeature.setGeometry(featureStore |
204 |
.getDefaultFeatureType() |
205 |
.getDefaultGeometryAttributeName(), ig); |
206 |
featureStore.update(eFeature); |
207 |
// vea.modifyRow(edRow.getIndex(),feat,getName(),EditionEvent.GRAPHIC);
|
208 |
// selectedRowAux.add(new
|
209 |
// DefaultRowEdited(feat,IRowEdited.STATUS_MODIFIED,edRow.getIndex()));
|
210 |
} |
211 |
} finally {
|
212 |
featureStore.endEditingGroup(); |
213 |
} |
214 |
// vle.setSelectionCache(VectorialLayerEdited.NOTSAVEPREVIOUS,
|
215 |
// selectedRowAux);
|
216 |
// clearSelection();
|
217 |
// selectedRow.addAll(selectedRowAux);
|
218 |
} |
219 |
} catch (ReadException e) {
|
220 |
NotificationManager.addError(e.getMessage(), e); |
221 |
} catch (DataException e) {
|
222 |
NotificationManager.addError(e.getMessage(), e); |
223 |
} finally {
|
224 |
if (iterator != null) { |
225 |
iterator.dispose(); |
226 |
} |
227 |
} |
228 |
PluginServices.getMDIManager().restoreCursor(); |
229 |
} |
230 |
|
231 |
/**
|
232 |
* M?todo para dibujar lo necesario para el estado en el que nos
|
233 |
* encontremos.
|
234 |
*
|
235 |
* @param g Graphics sobre el que dibujar.
|
236 |
* @param x par?metro x del punto que se pase para dibujar.
|
237 |
* @param y par?metro x del punto que se pase para dibujar.
|
238 |
*/
|
239 |
public void drawOperation(Graphics g, double x, double y) { |
240 |
MoveCADToolState actualState = (_fsm).getState(); |
241 |
String status = actualState.getName();
|
242 |
VectorialLayerEdited vle=getVLE(); |
243 |
//ArrayList selectedRow=getSelectedRows();
|
244 |
/*drawHandlers(g, selectedRow,
|
245 |
getCadToolAdapter().getMapControl().getViewPort()
|
246 |
.getAffineTransform());
|
247 |
*/
|
248 |
if (status.equals("Move.SecondPointToMove")) { |
249 |
ViewPort vp=vle.getLayer().getMapContext().getViewPort(); |
250 |
int dx = vp.fromMapDistance(x - firstPoint.getX());
|
251 |
int dy = -vp.fromMapDistance(y - firstPoint.getY());
|
252 |
Image img = vle.getSelectionImage();
|
253 |
g.drawImage(img, dx, dy, null);
|
254 |
// try {
|
255 |
// Iterator iterator=vle.getFeatureStore().getSelection().iterator();
|
256 |
// while (iterator.hasNext()) {
|
257 |
// Feature feature = (Feature) iterator.next();
|
258 |
// Geometry ig = ((Geometry)feature.getDefaultGeometry()).cloneGeometry();
|
259 |
// if (ig == null)
|
260 |
// continue;
|
261 |
// // Movemos la geometr?a
|
262 |
// UtilFunctions.moveGeom(ig, x - firstPoint.getX(), y - firstPoint.getY());
|
263 |
//
|
264 |
// DrawOperationContext doc=new DrawOperationContext();
|
265 |
// doc.setGraphics((Graphics2D)g);
|
266 |
// doc.setViewPort(vp);
|
267 |
// doc.setSymbol(DefaultCADTool.geometrySelectSymbol);
|
268 |
// try {
|
269 |
// ig.invokeOperation(Draw.CODE,doc);
|
270 |
// } catch (GeometryOperationNotSupportedException e) {
|
271 |
// e.printStackTrace();
|
272 |
// } catch (GeometryOperationException e) {
|
273 |
// e.printStackTrace();
|
274 |
// }
|
275 |
// }
|
276 |
// } catch (ReadException e) {
|
277 |
// // TODO Auto-generated catch block
|
278 |
// e.printStackTrace();
|
279 |
// }
|
280 |
/*for (int i = 0; i < selectedRow.size(); i++) {
|
281 |
IRowEdited edRow = (IRowEdited) selectedRow.get(i);
|
282 |
IFeature feat = (IFeature) edRow.getLinkedRow();
|
283 |
IGeometry ig = feat.getGeometry().cloneGeometry();
|
284 |
if (ig == null)
|
285 |
continue;
|
286 |
// Movemos la geometr?a
|
287 |
UtilFunctions.moveGeom(ig, x - firstPoint.getX(), y - firstPoint.getY());
|
288 |
ig.draw((Graphics2D) g,
|
289 |
getCadToolAdapter().getMapControl().getViewPort(),
|
290 |
CADTool.drawingSymbol);
|
291 |
}*/
|
292 |
}else{
|
293 |
if (!vle.getLayer().isVisible()) {
|
294 |
return;
|
295 |
} |
296 |
try{
|
297 |
Image imgSel = vle.getSelectionImage();
|
298 |
if (imgSel!=null) { |
299 |
g.drawImage(imgSel, 0, 0, null); |
300 |
} |
301 |
Image imgHand = vle.getHandlersImage();
|
302 |
if (imgHand!=null) { |
303 |
g.drawImage(imgHand, 0, 0, null); |
304 |
} |
305 |
}catch (Exception e) { |
306 |
} |
307 |
} |
308 |
} |
309 |
|
310 |
/**
|
311 |
* Add a diferent option.
|
312 |
*
|
313 |
* @param s Diferent option.
|
314 |
*/
|
315 |
public void addOption(String s) { |
316 |
} |
317 |
|
318 |
/* (non-Javadoc)
|
319 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
|
320 |
*/
|
321 |
public void addValue(double d) { |
322 |
} |
323 |
|
324 |
public String getName() { |
325 |
return PluginServices.getText(this,"move_"); |
326 |
} |
327 |
|
328 |
public String toString() { |
329 |
return "_move"; |
330 |
} |
331 |
|
332 |
} |