svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / tools / MoveCADTool.java @ 23535
History | View | Annotate | Download (10.9 KB)
1 | 4434 | caballero | /* 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 | 23086 | vcaballero | import java.awt.Graphics2D; |
45 | 4637 | caballero | import java.awt.Image; |
46 | 4434 | caballero | import java.awt.event.InputEvent; |
47 | import java.awt.geom.Point2D; |
||
48 | 4458 | caballero | import java.util.ArrayList; |
49 | 23086 | vcaballero | import java.util.Iterator; |
50 | 4434 | caballero | |
51 | 12739 | caballero | import org.cresques.cts.ICoordTrans; |
52 | 23086 | vcaballero | import org.gvsig.fmap.data.DataException; |
53 | 21911 | jmvivo | import org.gvsig.fmap.data.ReadException; |
54 | 23086 | vcaballero | import org.gvsig.fmap.data.feature.Feature; |
55 | 22986 | vcaballero | import org.gvsig.fmap.data.feature.FeatureCollection; |
56 | 23086 | vcaballero | import org.gvsig.fmap.data.feature.FeatureStore; |
57 | import org.gvsig.fmap.data.feature.IsNotFeatureSettingException; |
||
58 | 21668 | vcaballero | import org.gvsig.fmap.geom.Geometry; |
59 | 23086 | vcaballero | import org.gvsig.fmap.geom.operation.Draw; |
60 | import org.gvsig.fmap.geom.operation.DrawOperationContext; |
||
61 | import org.gvsig.fmap.geom.operation.GeometryOperationException; |
||
62 | import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
||
63 | 21668 | vcaballero | import org.gvsig.fmap.geom.util.UtilFunctions; |
64 | import org.gvsig.fmap.mapcontext.ViewPort; |
||
65 | 12739 | caballero | |
66 | 4434 | caballero | import com.iver.andami.PluginServices; |
67 | 12739 | caballero | import com.iver.andami.messages.NotificationManager; |
68 | 4434 | caballero | import com.iver.cit.gvsig.CADExtension; |
69 | import com.iver.cit.gvsig.gui.cad.DefaultCADTool; |
||
70 | 5735 | caballero | import com.iver.cit.gvsig.gui.cad.exception.CommandException; |
71 | 4434 | caballero | import com.iver.cit.gvsig.gui.cad.tools.smc.MoveCADToolContext; |
72 | import com.iver.cit.gvsig.gui.cad.tools.smc.MoveCADToolContext.MoveCADToolState; |
||
73 | 4637 | caballero | import com.iver.cit.gvsig.layers.VectorialLayerEdited; |
74 | 4434 | caballero | |
75 | |||
76 | /**
|
||
77 | * DOCUMENT ME!
|
||
78 | *
|
||
79 | * @author Vicente Caballero Navarro
|
||
80 | */
|
||
81 | public class MoveCADTool extends DefaultCADTool { |
||
82 | 20894 | vcaballero | protected MoveCADToolContext _fsm;
|
83 | protected Point2D firstPoint; |
||
84 | protected Point2D lastPoint; |
||
85 | 4434 | caballero | |
86 | /**
|
||
87 | * Crea un nuevo PolylineCADTool.
|
||
88 | */
|
||
89 | public MoveCADTool() {
|
||
90 | } |
||
91 | |||
92 | /**
|
||
93 | * M?todo de incio, para poner el c?digo de todo lo que se requiera de una
|
||
94 | * carga previa a la utilizaci?n de la herramienta.
|
||
95 | */
|
||
96 | public void init() { |
||
97 | _fsm = new MoveCADToolContext(this); |
||
98 | } |
||
99 | |||
100 | /* (non-Javadoc)
|
||
101 | * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double, double)
|
||
102 | */
|
||
103 | public void transition(double x, double y, InputEvent event) { |
||
104 | _fsm.addPoint(x, y, event); |
||
105 | } |
||
106 | |||
107 | /* (non-Javadoc)
|
||
108 | * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double)
|
||
109 | */
|
||
110 | public void transition(double d) { |
||
111 | 5735 | caballero | _fsm.addValue(d); |
112 | 4434 | caballero | } |
113 | |||
114 | /* (non-Javadoc)
|
||
115 | * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, java.lang.String)
|
||
116 | */
|
||
117 | 5735 | caballero | public void transition(String s) throws CommandException { |
118 | 4892 | caballero | if (!super.changeCommand(s)){ |
119 | _fsm.addOption(s); |
||
120 | } |
||
121 | 4434 | caballero | } |
122 | |||
123 | /**
|
||
124 | * DOCUMENT ME!
|
||
125 | */
|
||
126 | public void selection() { |
||
127 | 22986 | vcaballero | FeatureCollection selection=null;
|
128 | try {
|
||
129 | selection = (FeatureCollection)getVLE().getFeatureStore().getSelection(); |
||
130 | } catch (ReadException e) {
|
||
131 | // TODO Auto-generated catch block
|
||
132 | e.printStackTrace(); |
||
133 | } |
||
134 | if (selection.size() == 0 && !CADExtension.getCADTool().getClass().getName().equals("com.iver.cit.gvsig.gui.cad.tools.SelectionCADTool")) { |
||
135 | 5071 | caballero | CADExtension.setCADTool("_selection",false); |
136 | 4584 | caballero | ((SelectionCADTool) CADExtension.getCADTool()).setNextTool( |
137 | 5071 | caballero | "_move");
|
138 | 4434 | caballero | } |
139 | } |
||
140 | |||
141 | /**
|
||
142 | * Equivale al transition del prototipo pero sin pasarle como par?metro el
|
||
143 | * editableFeatureSource que ya estar? creado.
|
||
144 | *
|
||
145 | * @param x par?metro x del punto que se pase en esta transici?n.
|
||
146 | * @param y par?metro y del punto que se pase en esta transici?n.
|
||
147 | */
|
||
148 | public void addPoint(double x, double y,InputEvent event) { |
||
149 | MoveCADToolState actualState = (MoveCADToolState) _fsm.getPreviousState(); |
||
150 | String status = actualState.getName();
|
||
151 | 4637 | caballero | VectorialLayerEdited vle=getVLE(); |
152 | 23086 | vcaballero | FeatureStore featureStore=null;
|
153 | try {
|
||
154 | featureStore = vle.getFeatureStore(); |
||
155 | } catch (ReadException e1) {
|
||
156 | // TODO Auto-generated catch block
|
||
157 | e1.printStackTrace(); |
||
158 | } |
||
159 | FeatureCollection selection=(FeatureCollection)featureStore.getSelection();//getSelectedRows();
|
||
160 | // ArrayList selectedRowAux=new ArrayList();
|
||
161 | 12739 | caballero | ICoordTrans ct=getVLE().getLayer().getCoordTrans(); |
162 | if (status.equals("Move.FirstPointToMove")) { |
||
163 | 4434 | caballero | firstPoint = new Point2D.Double(x, y); |
164 | } else if (status.equals("Move.SecondPointToMove")) { |
||
165 | PluginServices.getMDIManager().setWaitCursor(); |
||
166 | 4637 | caballero | lastPoint = new Point2D.Double(x, y); |
167 | 23086 | vcaballero | featureStore.getCommandsRecord().startComplex(); |
168 | 4434 | caballero | |
169 | try {
|
||
170 | 23086 | vcaballero | Iterator iterator=selection.iterator();
|
171 | while (iterator.hasNext()) {
|
||
172 | Feature feature = (Feature) iterator.next(); |
||
173 | |||
174 | // }
|
||
175 | // for (int i = 0; i < selection.size(); i++) {
|
||
176 | // IRowEdited edRow = (IRowEdited) selectedRow.get(i);
|
||
177 | // IFeature feat = (IFeature) edRow.getLinkedRow().cloneRow();
|
||
178 | Geometry ig = ((Geometry)feature.getDefaultGeometry()).cloneGeometry(); |
||
179 | feature.editing(); |
||
180 | 4458 | caballero | if (ig == null) |
181 | continue;
|
||
182 | 12739 | caballero | if (ct!=null) { |
183 | lastPoint=ct.getInverted().convert(lastPoint,null);
|
||
184 | firstPoint=ct.getInverted().convert(firstPoint,null);
|
||
185 | |||
186 | } |
||
187 | // if (ct!=null)
|
||
188 | // ig.reProject(ct);
|
||
189 | // Movemos la geometr?a
|
||
190 | 4458 | caballero | UtilFunctions.moveGeom(ig, lastPoint.getX() - |
191 | 4434 | caballero | firstPoint.getX(), lastPoint.getY() - firstPoint.getY()); |
192 | |||
193 | 12739 | caballero | // if (ct!=null)
|
194 | // ig.reProject(ct.getInverted());
|
||
195 | 23086 | vcaballero | feature.setGeometry(featureStore.getDefaultFeatureType().getDefaultGeometry(),ig); |
196 | featureStore.update(feature); |
||
197 | // vea.modifyRow(edRow.getIndex(),feat,getName(),EditionEvent.GRAPHIC);
|
||
198 | // selectedRowAux.add(new DefaultRowEdited(feat,IRowEdited.STATUS_MODIFIED,edRow.getIndex()));
|
||
199 | 4637 | caballero | } |
200 | 23086 | vcaballero | featureStore.getCommandsRecord().endComplex(getName()); |
201 | // vle.setSelectionCache(VectorialLayerEdited.NOTSAVEPREVIOUS, selectedRowAux);
|
||
202 | 5985 | caballero | //clearSelection();
|
203 | //selectedRow.addAll(selectedRowAux);
|
||
204 | 4584 | caballero | |
205 | 23086 | vcaballero | } catch (ReadException e) {
|
206 | 12739 | caballero | NotificationManager.addError(e.getMessage(),e); |
207 | 23086 | vcaballero | } catch (IsNotFeatureSettingException e) {
|
208 | 23535 | vcaballero | NotificationManager.addError(e.getMessage(),e); |
209 | 23086 | vcaballero | } catch (DataException e) {
|
210 | 23535 | vcaballero | NotificationManager.addError(e.getMessage(),e); |
211 | 20894 | vcaballero | } |
212 | 4434 | caballero | PluginServices.getMDIManager().restoreCursor(); |
213 | } |
||
214 | } |
||
215 | |||
216 | /**
|
||
217 | 23535 | vcaballero | * M?todo para dibujar lo necesario para el estado en el que nos
|
218 | 4434 | caballero | * encontremos.
|
219 | *
|
||
220 | * @param g Graphics sobre el que dibujar.
|
||
221 | * @param x par?metro x del punto que se pase para dibujar.
|
||
222 | * @param y par?metro x del punto que se pase para dibujar.
|
||
223 | */
|
||
224 | public void drawOperation(Graphics g, double x, double y) { |
||
225 | MoveCADToolState actualState = ((MoveCADToolContext) _fsm).getState(); |
||
226 | String status = actualState.getName();
|
||
227 | 4637 | caballero | VectorialLayerEdited vle=getVLE(); |
228 | //ArrayList selectedRow=getSelectedRows();
|
||
229 | /*drawHandlers(g, selectedRow,
|
||
230 | 4458 | caballero | getCadToolAdapter().getMapControl().getViewPort()
|
231 | .getAffineTransform());
|
||
232 | 4637 | caballero | */
|
233 | 4434 | caballero | if (status.equals("Move.SecondPointToMove")) { |
234 | 6881 | cesar | ViewPort vp=vle.getLayer().getMapContext().getViewPort(); |
235 | 4637 | caballero | int dx = vp.fromMapDistance(x - firstPoint.getX());
|
236 | int dy = -vp.fromMapDistance(y - firstPoint.getY());
|
||
237 | Image img = vle.getSelectionImage();
|
||
238 | g.drawImage(img, dx, dy, null);
|
||
239 | 23086 | vcaballero | // try {
|
240 | // Iterator iterator=vle.getFeatureStore().getSelection().iterator();
|
||
241 | // while (iterator.hasNext()) {
|
||
242 | // Feature feature = (Feature) iterator.next();
|
||
243 | // Geometry ig = ((Geometry)feature.getDefaultGeometry()).cloneGeometry();
|
||
244 | // if (ig == null)
|
||
245 | // continue;
|
||
246 | // // Movemos la geometr?a
|
||
247 | // UtilFunctions.moveGeom(ig, x - firstPoint.getX(), y - firstPoint.getY());
|
||
248 | //
|
||
249 | // DrawOperationContext doc=new DrawOperationContext();
|
||
250 | // doc.setGraphics((Graphics2D)g);
|
||
251 | // doc.setViewPort(vp);
|
||
252 | // doc.setSymbol(DefaultCADTool.geometrySelectSymbol);
|
||
253 | // try {
|
||
254 | // ig.invokeOperation(Draw.CODE,doc);
|
||
255 | // } catch (GeometryOperationNotSupportedException e) {
|
||
256 | // e.printStackTrace();
|
||
257 | // } catch (GeometryOperationException e) {
|
||
258 | // e.printStackTrace();
|
||
259 | // }
|
||
260 | // }
|
||
261 | // } catch (ReadException e) {
|
||
262 | // // TODO Auto-generated catch block
|
||
263 | // e.printStackTrace();
|
||
264 | // }
|
||
265 | /*for (int i = 0; i < selectedRow.size(); i++) {
|
||
266 | 4458 | caballero | IRowEdited edRow = (IRowEdited) selectedRow.get(i);
|
267 | IFeature feat = (IFeature) edRow.getLinkedRow();
|
||
268 | IGeometry ig = feat.getGeometry().cloneGeometry();
|
||
269 | if (ig == null)
|
||
270 | continue;
|
||
271 | // Movemos la geometr?a
|
||
272 | UtilFunctions.moveGeom(ig, x - firstPoint.getX(), y - firstPoint.getY());
|
||
273 | ig.draw((Graphics2D) g,
|
||
274 | getCadToolAdapter().getMapControl().getViewPort(),
|
||
275 | CADTool.drawingSymbol);
|
||
276 | 4637 | caballero | }*/
|
277 | }else{
|
||
278 | 7547 | caballero | if (!vle.getLayer().isVisible())
|
279 | return;
|
||
280 | 4637 | caballero | Image imgSel = vle.getSelectionImage();
|
281 | g.drawImage(imgSel, 0, 0, null); |
||
282 | Image imgHand = vle.getHandlersImage();
|
||
283 | g.drawImage(imgHand, 0, 0, null); |
||
284 | 4434 | caballero | } |
285 | } |
||
286 | |||
287 | /**
|
||
288 | * Add a diferent option.
|
||
289 | *
|
||
290 | * @param s Diferent option.
|
||
291 | */
|
||
292 | public void addOption(String s) { |
||
293 | } |
||
294 | |||
295 | /* (non-Javadoc)
|
||
296 | * @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
|
||
297 | */
|
||
298 | public void addValue(double d) { |
||
299 | } |
||
300 | |||
301 | public String getName() { |
||
302 | 4584 | caballero | return PluginServices.getText(this,"move_"); |
303 | 4434 | caballero | } |
304 | 4892 | caballero | |
305 | public String toString() { |
||
306 | return "_move"; |
||
307 | } |
||
308 | 5170 | caballero | |
309 | 4434 | caballero | } |