svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.editing.app / org.gvsig.editing.app.mainplugin / src / main / java / org / gvsig / editing / gui / cad / tools / MoveCADTool.java @ 40557
History | View | Annotate | Download (9.78 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* 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 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* 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 |
*
|
16 |
* 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 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.editing.gui.cad.tools; |
25 |
|
26 |
import java.awt.event.InputEvent; |
27 |
import java.awt.geom.Point2D; |
28 |
|
29 |
import org.cresques.cts.ICoordTrans; |
30 |
|
31 |
import org.gvsig.andami.PluginServices; |
32 |
import org.gvsig.andami.messages.NotificationManager; |
33 |
import org.gvsig.editing.CADExtension; |
34 |
import org.gvsig.editing.gui.cad.DefaultCADTool; |
35 |
import org.gvsig.editing.gui.cad.exception.CommandException; |
36 |
import org.gvsig.editing.gui.cad.tools.smc.MoveCADToolContext; |
37 |
import org.gvsig.editing.gui.cad.tools.smc.MoveCADToolContext.MoveCADToolState; |
38 |
import org.gvsig.editing.layers.VectorialLayerEdited; |
39 |
import org.gvsig.fmap.dal.exception.DataException; |
40 |
import org.gvsig.fmap.dal.exception.ReadException; |
41 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
42 |
import org.gvsig.fmap.dal.feature.Feature; |
43 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
44 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
45 |
import org.gvsig.fmap.geom.Geometry; |
46 |
import org.gvsig.fmap.geom.type.GeometryType; |
47 |
import org.gvsig.fmap.geom.util.UtilFunctions; |
48 |
import org.gvsig.fmap.mapcontrol.MapControlDrawer; |
49 |
import org.gvsig.tools.dispose.DisposableIterator; |
50 |
|
51 |
/**
|
52 |
* DOCUMENT ME!
|
53 |
*
|
54 |
* @author Vicente Caballero Navarro
|
55 |
*/
|
56 |
public class MoveCADTool extends DefaultCADTool { |
57 |
|
58 |
protected MoveCADToolContext _fsm;
|
59 |
protected Point2D firstPoint; |
60 |
protected Point2D lastPoint; |
61 |
|
62 |
/**
|
63 |
* M?todo de incio, para poner el c?digo de todo lo que se requiera de una
|
64 |
* carga previa a la utilizaci?n de la herramienta.
|
65 |
*/
|
66 |
public void init() { |
67 |
_fsm = new MoveCADToolContext(this); |
68 |
} |
69 |
|
70 |
/*
|
71 |
* (non-Javadoc)
|
72 |
*
|
73 |
* @see
|
74 |
* com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap
|
75 |
* .layers.FBitSet, double, double)
|
76 |
*/
|
77 |
public void transition(double x, double y, InputEvent event) { |
78 |
_fsm.addPoint(x, y, event); |
79 |
} |
80 |
|
81 |
/*
|
82 |
* (non-Javadoc)
|
83 |
*
|
84 |
* @see
|
85 |
* com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap
|
86 |
* .layers.FBitSet, double)
|
87 |
*/
|
88 |
public void transition(double d) { |
89 |
_fsm.addValue(d); |
90 |
} |
91 |
|
92 |
/*
|
93 |
* (non-Javadoc)
|
94 |
*
|
95 |
* @see
|
96 |
* com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap
|
97 |
* .layers.FBitSet, java.lang.String)
|
98 |
*/
|
99 |
public void transition(String s) throws CommandException { |
100 |
if (!super.changeCommand(s)) { |
101 |
_fsm.addOption(s); |
102 |
} |
103 |
} |
104 |
|
105 |
/**
|
106 |
* DOCUMENT ME!
|
107 |
*/
|
108 |
public void selection() { |
109 |
FeatureSet selection = null;
|
110 |
try {
|
111 |
selection = (FeatureSet) getVLE().getFeatureStore().getSelection(); |
112 |
|
113 |
if (selection.getSize() == 0 |
114 |
&& !SelectionCADTool.isInstance(CADExtension.getCADTool(), true)) {
|
115 |
CADExtension.setCADTool("_selection", false); |
116 |
((SelectionCADTool) CADExtension.getCADTool()) |
117 |
.setNextTool("_move");
|
118 |
} |
119 |
} catch (ReadException e) {
|
120 |
// TODO Auto-generated catch block
|
121 |
e.printStackTrace(); |
122 |
} catch (DataException e) {
|
123 |
// TODO Auto-generated catch block
|
124 |
e.printStackTrace(); |
125 |
} |
126 |
} |
127 |
|
128 |
/**
|
129 |
* Equivale al transition del prototipo pero sin pasarle como par?metro el
|
130 |
* editableFeatureSource que ya estar? creado.
|
131 |
*
|
132 |
* @param x
|
133 |
* par?metro x del punto que se pase en esta transici?n.
|
134 |
* @param y
|
135 |
* par?metro y del punto que se pase en esta transici?n.
|
136 |
*/
|
137 |
public void addPoint(double x, double y, InputEvent event) { |
138 |
MoveCADToolState actualState = |
139 |
(MoveCADToolState) _fsm.getPreviousState(); |
140 |
String status = actualState.getName();
|
141 |
VectorialLayerEdited vle = getVLE(); |
142 |
FeatureStore featureStore = null;
|
143 |
try {
|
144 |
featureStore = vle.getFeatureStore(); |
145 |
} catch (ReadException e1) {
|
146 |
// TODO Auto-generated catch block
|
147 |
e1.printStackTrace(); |
148 |
} |
149 |
DisposableIterator iterator = null;
|
150 |
try {
|
151 |
FeatureSet selection = (FeatureSet) featureStore.getSelection();// getSelectedRows();
|
152 |
// ArrayList selectedRowAux=new ArrayList();
|
153 |
ICoordTrans ct = getVLE().getLayer().getCoordTrans(); |
154 |
if (status.equals("Move.FirstPointToMove")) { |
155 |
firstPoint = new Point2D.Double(x, y); |
156 |
} else
|
157 |
if (status.equals("Move.SecondPointToMove")) { |
158 |
PluginServices.getMDIManager().setWaitCursor(); |
159 |
lastPoint = new Point2D.Double(x, y); |
160 |
|
161 |
featureStore.beginEditingGroup(getName()); |
162 |
try {
|
163 |
|
164 |
iterator = selection.iterator(); |
165 |
while (iterator.hasNext()) {
|
166 |
Feature feature = (Feature) iterator.next(); |
167 |
|
168 |
// }
|
169 |
// for (int i = 0; i < selection.size(); i++) {
|
170 |
// IRowEdited edRow = (IRowEdited)
|
171 |
// selectedRow.get(i);
|
172 |
// IFeature feat = (IFeature)
|
173 |
// edRow.getLinkedRow().cloneRow();
|
174 |
Geometry ig = |
175 |
(feature.getDefaultGeometry()).cloneGeometry(); |
176 |
if (ig == null) { |
177 |
continue;
|
178 |
} |
179 |
if (ct != null) { |
180 |
lastPoint = |
181 |
ct.getInverted().convert(lastPoint, null);
|
182 |
firstPoint = |
183 |
ct.getInverted().convert(firstPoint, null);
|
184 |
|
185 |
} |
186 |
// if (ct!=null)
|
187 |
// ig.reProject(ct);
|
188 |
// Movemos la geometr?a
|
189 |
ig.move(lastPoint.getX() - firstPoint.getX(), |
190 |
lastPoint.getY() - firstPoint.getY()); |
191 |
|
192 |
// if (ct!=null)
|
193 |
// ig.reProject(ct.getInverted());
|
194 |
|
195 |
super.updateGeometry(featureStore, feature, ig);
|
196 |
//
|
197 |
// EditableFeature eFeature = feature.getEditable();
|
198 |
// eFeature.setGeometry(featureStore
|
199 |
// .getDefaultFeatureType()
|
200 |
// .getDefaultGeometryAttributeName(), ig);
|
201 |
// featureStore.update(eFeature);
|
202 |
//
|
203 |
|
204 |
// vea.modifyRow(edRow.getIndex(),feat,getName(),EditionEvent.GRAPHIC);
|
205 |
// selectedRowAux.add(new
|
206 |
// DefaultRowEdited(feat,IRowEdited.STATUS_MODIFIED,edRow.getIndex()));
|
207 |
} |
208 |
} finally {
|
209 |
featureStore.endEditingGroup(); |
210 |
} |
211 |
// vle.setSelectionCache(VectorialLayerEdited.NOTSAVEPREVIOUS,
|
212 |
// selectedRowAux);
|
213 |
// clearSelection();
|
214 |
// selectedRow.addAll(selectedRowAux);
|
215 |
} |
216 |
} catch (ReadException e) {
|
217 |
NotificationManager.addError(e.getMessage(), e); |
218 |
} catch (DataException e) {
|
219 |
NotificationManager.addError(e.getMessage(), e); |
220 |
} finally {
|
221 |
if (iterator != null) { |
222 |
iterator.dispose(); |
223 |
} |
224 |
} |
225 |
PluginServices.getMDIManager().restoreCursor(); |
226 |
} |
227 |
|
228 |
/**
|
229 |
* M?todo para dibujar lo necesario para el estado en el que nos
|
230 |
* encontremos.
|
231 |
*
|
232 |
* @param g
|
233 |
* Graphics sobre el que dibujar.
|
234 |
* @param x
|
235 |
* par?metro x del punto que se pase para dibujar.
|
236 |
* @param y
|
237 |
* par?metro x del punto que se pase para dibujar.
|
238 |
*/
|
239 |
public void drawOperation(MapControlDrawer renderer, double x, double y) { |
240 |
MoveCADToolState actualState = (_fsm).getState(); |
241 |
String status = actualState.getName();
|
242 |
VectorialLayerEdited vle = getVLE(); |
243 |
|
244 |
if (status.equals("Move.SecondPointToMove")) { |
245 |
drawSelectedGeometries(renderer, firstPoint, x, y); |
246 |
} |
247 |
} |
248 |
|
249 |
/**
|
250 |
* Add a diferent option.
|
251 |
*
|
252 |
* @param s
|
253 |
* Diferent option.
|
254 |
*/
|
255 |
public void addOption(String s) { |
256 |
} |
257 |
|
258 |
/*
|
259 |
* (non-Javadoc)
|
260 |
*
|
261 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
|
262 |
*/
|
263 |
public void addValue(double d) { |
264 |
} |
265 |
|
266 |
public String getName() { |
267 |
return PluginServices.getText(this, "move_"); |
268 |
} |
269 |
|
270 |
public String toString() { |
271 |
return "_move"; |
272 |
} |
273 |
|
274 |
@Override
|
275 |
public boolean isApplicable(GeometryType geometryType) { |
276 |
return true; |
277 |
} |
278 |
|
279 |
@Override
|
280 |
protected int[] getSupportedGeometryTypes() { |
281 |
return null; |
282 |
} |
283 |
|
284 |
} |