svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extEditing / src / com / iver / cit / gvsig / gui / cad / tools / MoveCADTool.java @ 24500
History | View | Annotate | Download (10.5 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 com.iver.cit.gvsig.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 |
import java.util.Iterator; |
48 |
|
49 |
import org.cresques.cts.ICoordTrans; |
50 |
import org.gvsig.fmap.dal.exception.DataException; |
51 |
import org.gvsig.fmap.dal.exception.ReadException; |
52 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
53 |
import org.gvsig.fmap.dal.feature.Feature; |
54 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
55 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
56 |
import org.gvsig.fmap.geom.Geometry; |
57 |
import org.gvsig.fmap.geom.util.UtilFunctions; |
58 |
import org.gvsig.fmap.mapcontext.ViewPort; |
59 |
|
60 |
import com.iver.andami.PluginServices; |
61 |
import com.iver.andami.messages.NotificationManager; |
62 |
import com.iver.cit.gvsig.CADExtension; |
63 |
import com.iver.cit.gvsig.gui.cad.DefaultCADTool; |
64 |
import com.iver.cit.gvsig.gui.cad.exception.CommandException; |
65 |
import com.iver.cit.gvsig.gui.cad.tools.smc.MoveCADToolContext; |
66 |
import com.iver.cit.gvsig.gui.cad.tools.smc.MoveCADToolContext.MoveCADToolState; |
67 |
import com.iver.cit.gvsig.layers.VectorialLayerEdited; |
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 |
try {
|
159 |
FeatureSet selection=(FeatureSet)featureStore.getSelection();//getSelectedRows();
|
160 |
// ArrayList selectedRowAux=new ArrayList();
|
161 |
ICoordTrans ct=getVLE().getLayer().getCoordTrans(); |
162 |
if (status.equals("Move.FirstPointToMove")) { |
163 |
firstPoint = new Point2D.Double(x, y); |
164 |
} else if (status.equals("Move.SecondPointToMove")) { |
165 |
PluginServices.getMDIManager().setWaitCursor(); |
166 |
lastPoint = new Point2D.Double(x, y); |
167 |
|
168 |
featureStore.beginEditingGroup(getName()); |
169 |
|
170 |
|
171 |
Iterator iterator=selection.iterator();
|
172 |
while (iterator.hasNext()) {
|
173 |
Feature feature = (Feature) iterator.next(); |
174 |
|
175 |
// }
|
176 |
// for (int i = 0; i < selection.size(); i++) {
|
177 |
// IRowEdited edRow = (IRowEdited) selectedRow.get(i);
|
178 |
// IFeature feat = (IFeature) edRow.getLinkedRow().cloneRow();
|
179 |
Geometry ig = ((Geometry)feature.getDefaultGeometry()).cloneGeometry(); |
180 |
EditableFeature eFeature=feature.getEditable(); |
181 |
if (ig == null) |
182 |
continue;
|
183 |
if (ct!=null) { |
184 |
lastPoint=ct.getInverted().convert(lastPoint,null);
|
185 |
firstPoint=ct.getInverted().convert(firstPoint,null);
|
186 |
|
187 |
} |
188 |
// if (ct!=null)
|
189 |
// ig.reProject(ct);
|
190 |
// Movemos la geometr?a
|
191 |
UtilFunctions.moveGeom(ig, lastPoint.getX() - |
192 |
firstPoint.getX(), lastPoint.getY() - firstPoint.getY()); |
193 |
|
194 |
// if (ct!=null)
|
195 |
// ig.reProject(ct.getInverted());
|
196 |
eFeature.setGeometry(featureStore.getDefaultFeatureType().getDefaultGeometryAttributeName(),ig); |
197 |
featureStore.update(eFeature); |
198 |
// vea.modifyRow(edRow.getIndex(),feat,getName(),EditionEvent.GRAPHIC);
|
199 |
// selectedRowAux.add(new DefaultRowEdited(feat,IRowEdited.STATUS_MODIFIED,edRow.getIndex()));
|
200 |
} |
201 |
featureStore.endEditingGroup(); |
202 |
// vle.setSelectionCache(VectorialLayerEdited.NOTSAVEPREVIOUS, selectedRowAux);
|
203 |
//clearSelection();
|
204 |
//selectedRow.addAll(selectedRowAux);
|
205 |
} |
206 |
} catch (ReadException e) {
|
207 |
NotificationManager.addError(e.getMessage(),e); |
208 |
} catch (DataException e) {
|
209 |
NotificationManager.addError(e.getMessage(),e); |
210 |
} |
211 |
PluginServices.getMDIManager().restoreCursor(); |
212 |
} |
213 |
|
214 |
/**
|
215 |
* M?todo para dibujar lo necesario para el estado en el que nos
|
216 |
* encontremos.
|
217 |
*
|
218 |
* @param g Graphics sobre el que dibujar.
|
219 |
* @param x par?metro x del punto que se pase para dibujar.
|
220 |
* @param y par?metro x del punto que se pase para dibujar.
|
221 |
*/
|
222 |
public void drawOperation(Graphics g, double x, double y) { |
223 |
MoveCADToolState actualState = ((MoveCADToolContext) _fsm).getState(); |
224 |
String status = actualState.getName();
|
225 |
VectorialLayerEdited vle=getVLE(); |
226 |
//ArrayList selectedRow=getSelectedRows();
|
227 |
/*drawHandlers(g, selectedRow,
|
228 |
getCadToolAdapter().getMapControl().getViewPort()
|
229 |
.getAffineTransform());
|
230 |
*/
|
231 |
if (status.equals("Move.SecondPointToMove")) { |
232 |
ViewPort vp=vle.getLayer().getMapContext().getViewPort(); |
233 |
int dx = vp.fromMapDistance(x - firstPoint.getX());
|
234 |
int dy = -vp.fromMapDistance(y - firstPoint.getY());
|
235 |
Image img = vle.getSelectionImage();
|
236 |
g.drawImage(img, dx, dy, null);
|
237 |
// try {
|
238 |
// Iterator iterator=vle.getFeatureStore().getSelection().iterator();
|
239 |
// while (iterator.hasNext()) {
|
240 |
// Feature feature = (Feature) iterator.next();
|
241 |
// Geometry ig = ((Geometry)feature.getDefaultGeometry()).cloneGeometry();
|
242 |
// if (ig == null)
|
243 |
// continue;
|
244 |
// // Movemos la geometr?a
|
245 |
// UtilFunctions.moveGeom(ig, x - firstPoint.getX(), y - firstPoint.getY());
|
246 |
//
|
247 |
// DrawOperationContext doc=new DrawOperationContext();
|
248 |
// doc.setGraphics((Graphics2D)g);
|
249 |
// doc.setViewPort(vp);
|
250 |
// doc.setSymbol(DefaultCADTool.geometrySelectSymbol);
|
251 |
// try {
|
252 |
// ig.invokeOperation(Draw.CODE,doc);
|
253 |
// } catch (GeometryOperationNotSupportedException e) {
|
254 |
// e.printStackTrace();
|
255 |
// } catch (GeometryOperationException e) {
|
256 |
// e.printStackTrace();
|
257 |
// }
|
258 |
// }
|
259 |
// } catch (ReadException e) {
|
260 |
// // TODO Auto-generated catch block
|
261 |
// e.printStackTrace();
|
262 |
// }
|
263 |
/*for (int i = 0; i < selectedRow.size(); i++) {
|
264 |
IRowEdited edRow = (IRowEdited) selectedRow.get(i);
|
265 |
IFeature feat = (IFeature) edRow.getLinkedRow();
|
266 |
IGeometry ig = feat.getGeometry().cloneGeometry();
|
267 |
if (ig == null)
|
268 |
continue;
|
269 |
// Movemos la geometr?a
|
270 |
UtilFunctions.moveGeom(ig, x - firstPoint.getX(), y - firstPoint.getY());
|
271 |
ig.draw((Graphics2D) g,
|
272 |
getCadToolAdapter().getMapControl().getViewPort(),
|
273 |
CADTool.drawingSymbol);
|
274 |
}*/
|
275 |
}else{
|
276 |
if (!vle.getLayer().isVisible())
|
277 |
return;
|
278 |
Image imgSel = vle.getSelectionImage();
|
279 |
g.drawImage(imgSel, 0, 0, null); |
280 |
Image imgHand = vle.getHandlersImage();
|
281 |
g.drawImage(imgHand, 0, 0, null); |
282 |
} |
283 |
} |
284 |
|
285 |
/**
|
286 |
* Add a diferent option.
|
287 |
*
|
288 |
* @param s Diferent option.
|
289 |
*/
|
290 |
public void addOption(String s) { |
291 |
} |
292 |
|
293 |
/* (non-Javadoc)
|
294 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
|
295 |
*/
|
296 |
public void addValue(double d) { |
297 |
} |
298 |
|
299 |
public String getName() { |
300 |
return PluginServices.getText(this,"move_"); |
301 |
} |
302 |
|
303 |
public String toString() { |
304 |
return "_move"; |
305 |
} |
306 |
|
307 |
} |