svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / gui / cad / tools / MoveCADTool.java @ 39127
History | View | Annotate | Download (9.66 KB)
1 | 37138 | cordinyana | /* gvSIG. Geographic Information System of the Valencian Government
|
---|---|---|---|
2 | 4434 | caballero | *
|
3 | 37138 | cordinyana | * Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 | * of the Valencian Government (CIT)
|
||
5 | *
|
||
6 | 4434 | caballero | * 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 | 37138 | cordinyana | *
|
11 | 4434 | caballero | * 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 | 37138 | cordinyana | *
|
16 | 4434 | caballero | * 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 | 37138 | cordinyana | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 | * MA 02110-1301, USA.
|
||
20 | *
|
||
21 | 4434 | caballero | */
|
22 | 29616 | jpiera | package org.gvsig.editing.gui.cad.tools; |
23 | 4434 | caballero | |
24 | import java.awt.event.InputEvent; |
||
25 | import java.awt.geom.Point2D; |
||
26 | |||
27 | 12739 | caballero | import org.cresques.cts.ICoordTrans; |
28 | 37138 | cordinyana | |
29 | 29616 | jpiera | 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 | 24500 | jmvivo | import org.gvsig.fmap.dal.exception.DataException; |
38 | import org.gvsig.fmap.dal.exception.ReadException; |
||
39 | 24490 | jmvivo | 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 | 21668 | vcaballero | import org.gvsig.fmap.geom.Geometry; |
44 | 37328 | cordinyana | import org.gvsig.fmap.geom.type.GeometryType; |
45 | 21668 | vcaballero | import org.gvsig.fmap.geom.util.UtilFunctions; |
46 | 30335 | jpiera | import org.gvsig.fmap.mapcontrol.MapControlDrawer; |
47 | 37138 | cordinyana | import org.gvsig.tools.dispose.DisposableIterator; |
48 | 12739 | caballero | |
49 | 4434 | caballero | /**
|
50 | * DOCUMENT ME!
|
||
51 | 37138 | cordinyana | *
|
52 | 4434 | caballero | * @author Vicente Caballero Navarro
|
53 | */
|
||
54 | public class MoveCADTool extends DefaultCADTool { |
||
55 | |||
56 | 37138 | cordinyana | protected MoveCADToolContext _fsm;
|
57 | protected Point2D firstPoint; |
||
58 | protected Point2D lastPoint; |
||
59 | 4434 | caballero | |
60 | 37138 | cordinyana | /**
|
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 | 4434 | caballero | |
68 | 37138 | cordinyana | /*
|
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 | 4434 | caballero | |
79 | 37138 | cordinyana | /*
|
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 | 4434 | caballero | |
90 | 37138 | cordinyana | /*
|
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 | 24263 | vcaballero | |
103 | 37138 | cordinyana | /**
|
104 | * DOCUMENT ME!
|
||
105 | */
|
||
106 | public void selection() { |
||
107 | FeatureSet selection = null;
|
||
108 | try {
|
||
109 | selection = (FeatureSet) getVLE().getFeatureStore().getSelection(); |
||
110 | 4434 | caballero | |
111 | 37138 | cordinyana | 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 | 4434 | caballero | |
130 | 37138 | cordinyana | /**
|
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 | 24429 | vcaballero | |
163 | 37138 | cordinyana | featureStore.beginEditingGroup(getName()); |
164 | try {
|
||
165 | 24429 | vcaballero | |
166 | 37138 | cordinyana | iterator = selection.iterator(); |
167 | while (iterator.hasNext()) {
|
||
168 | Feature feature = (Feature) iterator.next(); |
||
169 | 23086 | vcaballero | |
170 | 37138 | cordinyana | // }
|
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 | 12739 | caballero | |
188 | 37138 | cordinyana | } |
189 | // if (ct!=null)
|
||
190 | // ig.reProject(ct);
|
||
191 | // Movemos la geometr?a
|
||
192 | 39048 | jldominguez | ig.move(lastPoint.getX() - firstPoint.getX(), |
193 | lastPoint.getY() - firstPoint.getY()); |
||
194 | 4434 | caballero | |
195 | 37138 | cordinyana | // if (ct!=null)
|
196 | // ig.reProject(ct.getInverted());
|
||
197 | eFeature.setGeometry(featureStore |
||
198 | .getDefaultFeatureType() |
||
199 | .getDefaultGeometryAttributeName(), ig); |
||
200 | featureStore.update(eFeature); |
||
201 | // vea.modifyRow(edRow.getIndex(),feat,getName(),EditionEvent.GRAPHIC);
|
||
202 | // selectedRowAux.add(new
|
||
203 | // DefaultRowEdited(feat,IRowEdited.STATUS_MODIFIED,edRow.getIndex()));
|
||
204 | } |
||
205 | } finally {
|
||
206 | featureStore.endEditingGroup(); |
||
207 | } |
||
208 | // vle.setSelectionCache(VectorialLayerEdited.NOTSAVEPREVIOUS,
|
||
209 | // selectedRowAux);
|
||
210 | // clearSelection();
|
||
211 | // selectedRow.addAll(selectedRowAux);
|
||
212 | } |
||
213 | } catch (ReadException e) {
|
||
214 | NotificationManager.addError(e.getMessage(), e); |
||
215 | } catch (DataException e) {
|
||
216 | NotificationManager.addError(e.getMessage(), e); |
||
217 | } finally {
|
||
218 | if (iterator != null) { |
||
219 | iterator.dispose(); |
||
220 | } |
||
221 | } |
||
222 | PluginServices.getMDIManager().restoreCursor(); |
||
223 | } |
||
224 | 4434 | caballero | |
225 | 37138 | cordinyana | /**
|
226 | * M?todo para dibujar lo necesario para el estado en el que nos
|
||
227 | * encontremos.
|
||
228 | *
|
||
229 | * @param g
|
||
230 | * Graphics sobre el que dibujar.
|
||
231 | * @param x
|
||
232 | * par?metro x del punto que se pase para dibujar.
|
||
233 | * @param y
|
||
234 | * par?metro x del punto que se pase para dibujar.
|
||
235 | */
|
||
236 | public void drawOperation(MapControlDrawer renderer, double x, double y) { |
||
237 | MoveCADToolState actualState = (_fsm).getState(); |
||
238 | String status = actualState.getName();
|
||
239 | VectorialLayerEdited vle = getVLE(); |
||
240 | 4434 | caballero | |
241 | 37138 | cordinyana | if (status.equals("Move.SecondPointToMove")) { |
242 | drawSelectedGeometries(renderer, firstPoint, x, y); |
||
243 | } |
||
244 | } |
||
245 | 4434 | caballero | |
246 | 37138 | cordinyana | /**
|
247 | * Add a diferent option.
|
||
248 | *
|
||
249 | * @param s
|
||
250 | * Diferent option.
|
||
251 | */
|
||
252 | public void addOption(String s) { |
||
253 | } |
||
254 | 30788 | jpiera | |
255 | 37138 | cordinyana | /*
|
256 | * (non-Javadoc)
|
||
257 | *
|
||
258 | * @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
|
||
259 | */
|
||
260 | public void addValue(double d) { |
||
261 | } |
||
262 | 4892 | caballero | |
263 | 37138 | cordinyana | public String getName() { |
264 | return PluginServices.getText(this, "move_"); |
||
265 | } |
||
266 | 5170 | caballero | |
267 | 37138 | cordinyana | public String toString() { |
268 | return "_move"; |
||
269 | } |
||
270 | |||
271 | 37328 | cordinyana | @Override
|
272 | public boolean isApplicable(GeometryType geometryType) { |
||
273 | return true; |
||
274 | } |
||
275 | |||
276 | @Override
|
||
277 | protected int[] getSupportedGeometryTypes() { |
||
278 | return null; |
||
279 | } |
||
280 | |||
281 | 4434 | caballero | } |