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 | 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 | 39573 | jldominguez | && !SelectionCADTool.isInstance(CADExtension.getCADTool(), true)) {
|
113 | 37138 | cordinyana | 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 | 4434 | caballero | |
126 | 37138 | cordinyana | /**
|
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 | 24429 | vcaballero | |
159 | 37138 | cordinyana | featureStore.beginEditingGroup(getName()); |
160 | try {
|
||
161 | 24429 | vcaballero | |
162 | 37138 | cordinyana | iterator = selection.iterator(); |
163 | while (iterator.hasNext()) {
|
||
164 | Feature feature = (Feature) iterator.next(); |
||
165 | 23086 | vcaballero | |
166 | 37138 | cordinyana | // }
|
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 | 12739 | caballero | |
183 | 37138 | cordinyana | } |
184 | // if (ct!=null)
|
||
185 | // ig.reProject(ct);
|
||
186 | // Movemos la geometr?a
|
||
187 | 39048 | jldominguez | ig.move(lastPoint.getX() - firstPoint.getX(), |
188 | lastPoint.getY() - firstPoint.getY()); |
||
189 | 4434 | caballero | |
190 | 37138 | cordinyana | // if (ct!=null)
|
191 | // ig.reProject(ct.getInverted());
|
||
192 | 39578 | jjdelcerro | |
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 | 37138 | cordinyana | // 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 | 4434 | caballero | |
226 | 37138 | cordinyana | /**
|
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 | 4434 | caballero | |
242 | 37138 | cordinyana | if (status.equals("Move.SecondPointToMove")) { |
243 | drawSelectedGeometries(renderer, firstPoint, x, y); |
||
244 | } |
||
245 | } |
||
246 | 4434 | caballero | |
247 | 37138 | cordinyana | /**
|
248 | * Add a diferent option.
|
||
249 | *
|
||
250 | * @param s
|
||
251 | * Diferent option.
|
||
252 | */
|
||
253 | public void addOption(String s) { |
||
254 | } |
||
255 | 30788 | jpiera | |
256 | 37138 | cordinyana | /*
|
257 | * (non-Javadoc)
|
||
258 | *
|
||
259 | * @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
|
||
260 | */
|
||
261 | public void addValue(double d) { |
||
262 | } |
||
263 | 4892 | caballero | |
264 | 37138 | cordinyana | public String getName() { |
265 | return PluginServices.getText(this, "move_"); |
||
266 | } |
||
267 | 5170 | caballero | |
268 | 37138 | cordinyana | public String toString() { |
269 | return "_move"; |
||
270 | } |
||
271 | |||
272 | 37328 | cordinyana | @Override
|
273 | public boolean isApplicable(GeometryType geometryType) { |
||
274 | return true; |
||
275 | } |
||
276 | |||
277 | @Override
|
||
278 | protected int[] getSupportedGeometryTypes() { |
||
279 | return null; |
||
280 | } |
||
281 | |||
282 | 4434 | caballero | } |