root / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / gui / cad / tools / RotateCADTool.java @ 38539
History | View | Annotate | Download (12 KB)
1 | 37138 | cordinyana | /* gvSIG. Geographic Information System of the Valencian Government
|
---|---|---|---|
2 | 3883 | caballero | *
|
3 | 37138 | cordinyana | * Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 | * of the Valencian Government (CIT)
|
||
5 | *
|
||
6 | 3883 | 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 | 3883 | 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 | 3883 | 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 | 3883 | caballero | */
|
22 | 29616 | jpiera | package org.gvsig.editing.gui.cad.tools; |
23 | 3883 | caballero | |
24 | 4313 | fjp | import java.awt.event.InputEvent; |
25 | 3883 | caballero | import java.awt.geom.AffineTransform; |
26 | import java.awt.geom.Point2D; |
||
27 | 4458 | caballero | import java.util.ArrayList; |
28 | 3883 | caballero | |
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.RotateCADToolContext; |
||
35 | import org.gvsig.editing.gui.cad.tools.smc.RotateCADToolContext.RotateCADToolState; |
||
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 | 23086 | 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 | 21668 | vcaballero | |
49 | 3883 | caballero | /**
|
50 | * DOCUMENT ME!
|
||
51 | 37138 | cordinyana | *
|
52 | 3883 | caballero | * @author Vicente Caballero Navarro
|
53 | */
|
||
54 | public class RotateCADTool extends DefaultCADTool { |
||
55 | |||
56 | 37138 | cordinyana | private RotateCADToolContext _fsm;
|
57 | private Point2D firstPoint; |
||
58 | private Point2D lastPoint; |
||
59 | 3883 | 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 RotateCADToolContext(this); |
||
66 | } |
||
67 | 3883 | 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,
|
||
74 | * double, double)
|
||
75 | */
|
||
76 | public void transition(double x, double y, InputEvent event) { |
||
77 | _fsm.addPoint(x, y, event); |
||
78 | } |
||
79 | 3883 | caballero | |
80 | 37138 | cordinyana | /*
|
81 | * (non-Javadoc)
|
||
82 | *
|
||
83 | * @see
|
||
84 | * com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap
|
||
85 | * .layers.FBitSet,
|
||
86 | * double)
|
||
87 | */
|
||
88 | public void transition(double d) { |
||
89 | _fsm.addValue(d); |
||
90 | } |
||
91 | 3883 | caballero | |
92 | 37138 | cordinyana | /*
|
93 | * (non-Javadoc)
|
||
94 | *
|
||
95 | * @see
|
||
96 | * com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap
|
||
97 | * .layers.FBitSet,
|
||
98 | * java.lang.String)
|
||
99 | */
|
||
100 | public void transition(String s) throws CommandException { |
||
101 | if (!super.changeCommand(s)) { |
||
102 | _fsm.addOption(s); |
||
103 | } |
||
104 | } |
||
105 | 24263 | vcaballero | |
106 | 37138 | cordinyana | /**
|
107 | * DOCUMENT ME!
|
||
108 | */
|
||
109 | public void selection() { |
||
110 | FeatureSet selection = null;
|
||
111 | try {
|
||
112 | selection = (FeatureSet) getVLE().getFeatureStore().getSelection(); |
||
113 | 3883 | caballero | |
114 | 37138 | cordinyana | if (selection.getSize() == 0 |
115 | && !CADExtension |
||
116 | .getCADTool() |
||
117 | .getClass() |
||
118 | .getName() |
||
119 | .equals("com.iver.cit.gvsig.gui.cad.tools.SelectionCADTool")) {
|
||
120 | CADExtension.setCADTool("_selection", false); |
||
121 | ((SelectionCADTool) CADExtension.getCADTool()) |
||
122 | .setNextTool("_rotate");
|
||
123 | } |
||
124 | } catch (ReadException e) {
|
||
125 | // TODO Auto-generated catch block
|
||
126 | e.printStackTrace(); |
||
127 | } catch (DataException e) {
|
||
128 | // TODO Auto-generated catch block
|
||
129 | e.printStackTrace(); |
||
130 | } |
||
131 | } |
||
132 | 23086 | vcaballero | |
133 | 37138 | cordinyana | /**
|
134 | * Equivale al transition del prototipo pero sin pasarle como par?metro el
|
||
135 | * editableFeatureSource que ya estar? creado.
|
||
136 | *
|
||
137 | * @param x
|
||
138 | * par?metro x del punto que se pase en esta transici?n.
|
||
139 | * @param y
|
||
140 | * par?metro y del punto que se pase en esta transici?n.
|
||
141 | */
|
||
142 | public void addPoint(double x, double y, InputEvent event) { |
||
143 | RotateCADToolState actualState = |
||
144 | (RotateCADToolState) _fsm.getPreviousState(); |
||
145 | String status = actualState.getName();
|
||
146 | VectorialLayerEdited vle = getVLE(); |
||
147 | FeatureStore featureStore = null;
|
||
148 | try {
|
||
149 | featureStore = vle.getFeatureStore(); |
||
150 | } catch (ReadException e1) {
|
||
151 | // TODO Auto-generated catch block
|
||
152 | e1.printStackTrace(); |
||
153 | } |
||
154 | DisposableIterator iterator = null;
|
||
155 | try {
|
||
156 | FeatureSet selection = (FeatureSet) featureStore.getSelection();// getSelectedRows();
|
||
157 | ArrayList selectedRowAux = new ArrayList(); |
||
158 | 3883 | caballero | |
159 | 37138 | cordinyana | if (status.equals("Rotate.PointMain")) { |
160 | firstPoint = new Point2D.Double(x, y); |
||
161 | } else
|
||
162 | if (status.equals("Rotate.AngleOrPoint")) { |
||
163 | PluginServices.getMDIManager().setWaitCursor(); |
||
164 | lastPoint = new Point2D.Double(x, y); |
||
165 | 3883 | caballero | |
166 | 37138 | cordinyana | double w;
|
167 | double h;
|
||
168 | w = lastPoint.getX() - firstPoint.getX(); |
||
169 | h = lastPoint.getY() - firstPoint.getY(); |
||
170 | 23086 | vcaballero | |
171 | 37138 | cordinyana | featureStore.beginEditingGroup(getName()); |
172 | try {
|
||
173 | iterator = selection.iterator(); |
||
174 | while (iterator.hasNext()) {
|
||
175 | Feature feature = (Feature) iterator.next(); |
||
176 | 27525 | jmvivo | |
177 | 37138 | cordinyana | // }
|
178 | // for (int i = 0; i < selectedRow.size(); i++) {
|
||
179 | // DefaultRowEdited row=(DefaultRowEdited)
|
||
180 | // selectedRow.get(i);
|
||
181 | // DefaultFeature fea = (DefaultFeature)
|
||
182 | // row.getLinkedRow().cloneRow();
|
||
183 | // Rotamos la geometry
|
||
184 | Geometry geometry = |
||
185 | (feature.getDefaultGeometry()).cloneGeometry(); |
||
186 | EditableFeature eFeature = feature.getEditable(); |
||
187 | UtilFunctions.rotateGeom(geometry, |
||
188 | -Math.atan2(w, h) + (Math.PI / 2), |
||
189 | firstPoint.getX(), firstPoint.getY()); |
||
190 | eFeature.setGeometry(featureStore |
||
191 | .getDefaultFeatureType() |
||
192 | .getDefaultGeometryAttributeName(), geometry); |
||
193 | featureStore.update(eFeature); |
||
194 | // vea.modifyRow(row.getIndex(), fea,
|
||
195 | // getName(),EditionEvent.GRAPHIC);
|
||
196 | // selectedRowAux.add(new
|
||
197 | // DefaultRowEdited(fea,IRowEdited.STATUS_MODIFIED,row.getIndex()));
|
||
198 | } |
||
199 | } finally {
|
||
200 | 24429 | vcaballero | |
201 | 37138 | cordinyana | featureStore.endEditingGroup(); |
202 | } |
||
203 | // vle.setSelectionCache(VectorialLayerEdited.NOTSAVEPREVIOUS,
|
||
204 | // selectedRowAux);
|
||
205 | // clearSelection();
|
||
206 | // selectedRow.addAll(selectedRowAux);
|
||
207 | 3883 | caballero | |
208 | 37138 | cordinyana | PluginServices.getMDIManager().restoreCursor(); |
209 | } |
||
210 | } catch (DataException e) {
|
||
211 | NotificationManager.addError(e.getMessage(), e); |
||
212 | } finally {
|
||
213 | if (iterator != null) { |
||
214 | iterator.dispose(); |
||
215 | } |
||
216 | } |
||
217 | } |
||
218 | 3883 | caballero | |
219 | 37138 | cordinyana | /**
|
220 | * M?todo para dibujar la lo necesario para el estado en el que nos
|
||
221 | * encontremos.
|
||
222 | *
|
||
223 | * @param g
|
||
224 | * Graphics sobre el que dibujar.
|
||
225 | * @param x
|
||
226 | * par?metro x del punto que se pase para dibujar.
|
||
227 | * @param y
|
||
228 | * par?metro x del punto que se pase para dibujar.
|
||
229 | */
|
||
230 | public void drawOperation(MapControlDrawer renderer, double x, double y) { |
||
231 | RotateCADToolState actualState = _fsm.getState(); |
||
232 | String status = actualState.getName();
|
||
233 | 3883 | caballero | |
234 | 37138 | cordinyana | if (status.equals("Rotate.AngleOrPoint")) { |
235 | drawAndRotateSelectedGeometries(renderer, firstPoint, x, y); |
||
236 | renderer.drawLine(firstPoint, new Point2D.Double(x, y), |
||
237 | mapControlManager.getAxisReferenceSymbol()); |
||
238 | } |
||
239 | } |
||
240 | 3883 | caballero | |
241 | 37138 | cordinyana | /**
|
242 | * Add a diferent option.
|
||
243 | *
|
||
244 | * @param s
|
||
245 | * Diferent option.
|
||
246 | */
|
||
247 | public void addOption(String s) { |
||
248 | } |
||
249 | 23086 | vcaballero | |
250 | 37138 | cordinyana | /*
|
251 | * (non-Javadoc)
|
||
252 | *
|
||
253 | * @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
|
||
254 | */
|
||
255 | public void addValue(double d) { |
||
256 | RotateCADToolState actualState = |
||
257 | (RotateCADToolState) _fsm.getPreviousState(); |
||
258 | String status = actualState.getName();
|
||
259 | VectorialLayerEdited vle = getVLE(); |
||
260 | FeatureStore featureStore = null;
|
||
261 | try {
|
||
262 | featureStore = vle.getFeatureStore(); |
||
263 | } catch (ReadException e1) {
|
||
264 | // TODO Auto-generated catch block
|
||
265 | e1.printStackTrace(); |
||
266 | } |
||
267 | DisposableIterator iterator = null;
|
||
268 | try {
|
||
269 | FeatureSet selection = (FeatureSet) featureStore.getSelection();// getSelectedRows();
|
||
270 | 4637 | caballero | |
271 | 37138 | cordinyana | if (status.equals("Rotate.AngleOrPoint")) { |
272 | 23086 | vcaballero | |
273 | 37138 | cordinyana | featureStore.beginEditingGroup(getName()); |
274 | try {
|
||
275 | // /ArrayList selectedRowAux=new ArrayList();
|
||
276 | iterator = selection.iterator(); |
||
277 | while (iterator.hasNext()) {
|
||
278 | Feature feature = (Feature) iterator.next(); |
||
279 | 24429 | vcaballero | |
280 | 37138 | cordinyana | // }
|
281 | // for (int i = 0; i < selectedRow.size(); i++) {
|
||
282 | // DefaultRowEdited row=(DefaultRowEdited)
|
||
283 | // selectedRow.get(i);
|
||
284 | // DefaultFeature fea = (DefaultFeature)
|
||
285 | // row.getLinkedRow().cloneRow();
|
||
286 | // Rotamos la geometry
|
||
287 | AffineTransform at = new AffineTransform(); |
||
288 | at.rotate(Math.toRadians(d), firstPoint.getX(),
|
||
289 | firstPoint.getY()); |
||
290 | Geometry geometry = |
||
291 | (feature.getDefaultGeometry()).cloneGeometry(); |
||
292 | EditableFeature eFeature = feature.getEditable(); |
||
293 | geometry.transform(at); |
||
294 | eFeature.setGeometry(featureStore |
||
295 | .getDefaultFeatureType() |
||
296 | .getDefaultGeometryAttributeName(), geometry); |
||
297 | featureStore.update(eFeature); |
||
298 | // vea.modifyRow(row.getIndex(),
|
||
299 | // fea,getName(),EditionEvent.GRAPHIC);
|
||
300 | // /selectedRowAux.add(new
|
||
301 | // DefaultRowEdited(fea,IRowEdited.STATUS_MODIFIED,index));
|
||
302 | } |
||
303 | } finally {
|
||
304 | featureStore.endEditingGroup(); |
||
305 | } |
||
306 | clearSelection(); |
||
307 | // /selectedRow=selectedRowAux;
|
||
308 | 4118 | caballero | |
309 | 37138 | cordinyana | } |
310 | } catch (DataException e) {
|
||
311 | NotificationManager.addError(e.getMessage(), e); |
||
312 | } finally {
|
||
313 | if (iterator != null) { |
||
314 | iterator.dispose(); |
||
315 | } |
||
316 | } |
||
317 | } |
||
318 | 4892 | caballero | |
319 | 37138 | cordinyana | public String getName() { |
320 | return PluginServices.getText(this, "rotate_"); |
||
321 | } |
||
322 | 5170 | caballero | |
323 | 37138 | cordinyana | public String toString() { |
324 | return "_rotate"; |
||
325 | } |
||
326 | |||
327 | 37328 | cordinyana | @Override
|
328 | public boolean isApplicable(GeometryType geometryType) { |
||
329 | return true; |
||
330 | } |
||
331 | |||
332 | @Override
|
||
333 | protected int[] getSupportedGeometryTypes() { |
||
334 | return null; |
||
335 | } |
||
336 | 3883 | caballero | } |