Revision 37138 branches/v2_0_0_prep/extensions/extEditing/src/org/gvsig/editing/gui/cad/tools/MoveCADTool.java
MoveCADTool.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
|
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
|
2 | 2 |
* |
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
5 | 6 |
* This program is free software; you can redistribute it and/or |
6 | 7 |
* modify it under the terms of the GNU General Public License |
7 | 8 |
* as published by the Free Software Foundation; either version 2 |
8 | 9 |
* of the License, or (at your option) any later version. |
9 |
* |
|
10 |
*
|
|
10 | 11 |
* This program is distributed in the hope that it will be useful, |
11 | 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | 14 |
* GNU General Public License for more details. |
14 |
* |
|
15 |
*
|
|
15 | 16 |
* You should have received a copy of the GNU General Public License |
16 | 17 |
* 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 |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
40 | 21 |
*/ |
41 | 22 |
package org.gvsig.editing.gui.cad.tools; |
42 | 23 |
|
43 |
import java.awt.Image; |
|
44 | 24 |
import java.awt.event.InputEvent; |
45 | 25 |
import java.awt.geom.Point2D; |
46 | 26 |
|
47 | 27 |
import org.cresques.cts.ICoordTrans; |
28 |
|
|
48 | 29 |
import org.gvsig.andami.PluginServices; |
49 | 30 |
import org.gvsig.andami.messages.NotificationManager; |
50 | 31 |
import org.gvsig.editing.CADExtension; |
... | ... | |
55 | 36 |
import org.gvsig.editing.layers.VectorialLayerEdited; |
56 | 37 |
import org.gvsig.fmap.dal.exception.DataException; |
57 | 38 |
import org.gvsig.fmap.dal.exception.ReadException; |
58 |
import org.gvsig.tools.dispose.DisposableIterator; |
|
59 | 39 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
60 | 40 |
import org.gvsig.fmap.dal.feature.Feature; |
61 | 41 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
62 | 42 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
63 | 43 |
import org.gvsig.fmap.geom.Geometry; |
64 | 44 |
import org.gvsig.fmap.geom.util.UtilFunctions; |
65 |
import org.gvsig.fmap.mapcontext.ViewPort; |
|
66 | 45 |
import org.gvsig.fmap.mapcontrol.MapControlDrawer; |
46 |
import org.gvsig.tools.dispose.DisposableIterator; |
|
67 | 47 |
|
68 |
|
|
69 |
|
|
70 | 48 |
/** |
71 | 49 |
* DOCUMENT ME! |
72 |
* |
|
50 |
*
|
|
73 | 51 |
* @author Vicente Caballero Navarro |
74 | 52 |
*/ |
75 | 53 |
public class MoveCADTool extends DefaultCADTool { |
76 |
protected MoveCADToolContext _fsm; |
|
77 |
protected Point2D firstPoint; |
|
78 |
protected Point2D lastPoint; |
|
79 | 54 |
|
80 |
/** |
|
81 |
* Crea un nuevo PolylineCADTool. |
|
82 |
*/ |
|
83 |
public MoveCADTool() { |
|
84 |
} |
|
55 |
protected MoveCADToolContext _fsm; |
|
56 |
protected Point2D firstPoint; |
|
57 |
protected Point2D lastPoint; |
|
85 | 58 |
|
86 |
/** |
|
87 |
* M?todo de incio, para poner el c?digo de todo lo que se requiera de una |
|
88 |
* carga previa a la utilizaci?n de la herramienta. |
|
89 |
*/ |
|
90 |
public void init() { |
|
91 |
_fsm = new MoveCADToolContext(this); |
|
92 |
} |
|
59 |
/** |
|
60 |
* Crea un nuevo PolylineCADTool. |
|
61 |
*/ |
|
62 |
public MoveCADTool() { |
|
63 |
} |
|
93 | 64 |
|
94 |
/* (non-Javadoc) |
|
95 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double, double) |
|
96 |
*/ |
|
97 |
public void transition(double x, double y, InputEvent event) { |
|
98 |
_fsm.addPoint(x, y, event); |
|
99 |
} |
|
65 |
/** |
|
66 |
* M?todo de incio, para poner el c?digo de todo lo que se requiera de una |
|
67 |
* carga previa a la utilizaci?n de la herramienta. |
|
68 |
*/ |
|
69 |
public void init() { |
|
70 |
_fsm = new MoveCADToolContext(this); |
|
71 |
} |
|
100 | 72 |
|
101 |
/* (non-Javadoc) |
|
102 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double) |
|
103 |
*/ |
|
104 |
public void transition(double d) { |
|
105 |
_fsm.addValue(d); |
|
106 |
} |
|
73 |
/* |
|
74 |
* (non-Javadoc) |
|
75 |
* |
|
76 |
* @see |
|
77 |
* com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap |
|
78 |
* .layers.FBitSet, double, double) |
|
79 |
*/ |
|
80 |
public void transition(double x, double y, InputEvent event) { |
|
81 |
_fsm.addPoint(x, y, event); |
|
82 |
} |
|
107 | 83 |
|
108 |
/* (non-Javadoc) |
|
109 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, java.lang.String) |
|
110 |
*/ |
|
111 |
public void transition(String s) throws CommandException { |
|
112 |
if (!super.changeCommand(s)){ |
|
113 |
_fsm.addOption(s); |
|
114 |
} |
|
115 |
} |
|
84 |
/* |
|
85 |
* (non-Javadoc) |
|
86 |
* |
|
87 |
* @see |
|
88 |
* com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap |
|
89 |
* .layers.FBitSet, double) |
|
90 |
*/ |
|
91 |
public void transition(double d) { |
|
92 |
_fsm.addValue(d); |
|
93 |
} |
|
116 | 94 |
|
117 |
/** |
|
118 |
* DOCUMENT ME! |
|
119 |
*/ |
|
120 |
public void selection() { |
|
121 |
FeatureSet selection=null; |
|
122 |
try { |
|
123 |
selection = (FeatureSet)getVLE().getFeatureStore().getSelection(); |
|
95 |
/* |
|
96 |
* (non-Javadoc) |
|
97 |
* |
|
98 |
* @see |
|
99 |
* com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap |
|
100 |
* .layers.FBitSet, java.lang.String) |
|
101 |
*/ |
|
102 |
public void transition(String s) throws CommandException { |
|
103 |
if (!super.changeCommand(s)) { |
|
104 |
_fsm.addOption(s); |
|
105 |
} |
|
106 |
} |
|
124 | 107 |
|
125 |
if (selection.getSize() == 0 && !CADExtension.getCADTool().getClass().getName().equals("com.iver.cit.gvsig.gui.cad.tools.SelectionCADTool")) { |
|
126 |
CADExtension.setCADTool("_selection",false); |
|
127 |
((SelectionCADTool) CADExtension.getCADTool()).setNextTool( |
|
128 |
"_move"); |
|
129 |
} |
|
130 |
} catch (ReadException e) { |
|
131 |
// TODO Auto-generated catch block |
|
132 |
e.printStackTrace(); |
|
133 |
} catch (DataException e) { |
|
134 |
// TODO Auto-generated catch block |
|
135 |
e.printStackTrace(); |
|
136 |
} |
|
137 |
} |
|
108 |
/** |
|
109 |
* DOCUMENT ME! |
|
110 |
*/ |
|
111 |
public void selection() { |
|
112 |
FeatureSet selection = null; |
|
113 |
try { |
|
114 |
selection = (FeatureSet) getVLE().getFeatureStore().getSelection(); |
|
138 | 115 |
|
139 |
/** |
|
140 |
* Equivale al transition del prototipo pero sin pasarle como par?metro el |
|
141 |
* editableFeatureSource que ya estar? creado. |
|
142 |
* |
|
143 |
* @param x par?metro x del punto que se pase en esta transici?n. |
|
144 |
* @param y par?metro y del punto que se pase en esta transici?n. |
|
145 |
*/ |
|
146 |
public void addPoint(double x, double y,InputEvent event) { |
|
147 |
MoveCADToolState actualState = (MoveCADToolState) _fsm |
|
148 |
.getPreviousState(); |
|
149 |
String status = actualState.getName(); |
|
150 |
VectorialLayerEdited vle=getVLE(); |
|
151 |
FeatureStore featureStore=null; |
|
152 |
try { |
|
153 |
featureStore = vle.getFeatureStore(); |
|
154 |
} catch (ReadException e1) { |
|
155 |
// TODO Auto-generated catch block |
|
156 |
e1.printStackTrace(); |
|
157 |
} |
|
158 |
DisposableIterator iterator = null; |
|
159 |
try { |
|
160 |
FeatureSet selection = (FeatureSet) featureStore.getSelection();// getSelectedRows(); |
|
161 |
// ArrayList selectedRowAux=new ArrayList(); |
|
162 |
ICoordTrans ct = getVLE().getLayer().getCoordTrans(); |
|
163 |
if (status.equals("Move.FirstPointToMove")) { |
|
164 |
firstPoint = new Point2D.Double(x, y); |
|
165 |
} else if (status.equals("Move.SecondPointToMove")) { |
|
166 |
PluginServices.getMDIManager().setWaitCursor(); |
|
167 |
lastPoint = new Point2D.Double(x, y); |
|
116 |
if (selection.getSize() == 0 |
|
117 |
&& !CADExtension |
|
118 |
.getCADTool() |
|
119 |
.getClass() |
|
120 |
.getName() |
|
121 |
.equals("com.iver.cit.gvsig.gui.cad.tools.SelectionCADTool")) { |
|
122 |
CADExtension.setCADTool("_selection", false); |
|
123 |
((SelectionCADTool) CADExtension.getCADTool()) |
|
124 |
.setNextTool("_move"); |
|
125 |
} |
|
126 |
} catch (ReadException e) { |
|
127 |
// TODO Auto-generated catch block |
|
128 |
e.printStackTrace(); |
|
129 |
} catch (DataException e) { |
|
130 |
// TODO Auto-generated catch block |
|
131 |
e.printStackTrace(); |
|
132 |
} |
|
133 |
} |
|
168 | 134 |
|
169 |
featureStore.beginEditingGroup(getName()); |
|
170 |
try { |
|
135 |
/** |
|
136 |
* Equivale al transition del prototipo pero sin pasarle como par?metro el |
|
137 |
* editableFeatureSource que ya estar? creado. |
|
138 |
* |
|
139 |
* @param x |
|
140 |
* par?metro x del punto que se pase en esta transici?n. |
|
141 |
* @param y |
|
142 |
* par?metro y del punto que se pase en esta transici?n. |
|
143 |
*/ |
|
144 |
public void addPoint(double x, double y, InputEvent event) { |
|
145 |
MoveCADToolState actualState = |
|
146 |
(MoveCADToolState) _fsm.getPreviousState(); |
|
147 |
String status = actualState.getName(); |
|
148 |
VectorialLayerEdited vle = getVLE(); |
|
149 |
FeatureStore featureStore = null; |
|
150 |
try { |
|
151 |
featureStore = vle.getFeatureStore(); |
|
152 |
} catch (ReadException e1) { |
|
153 |
// TODO Auto-generated catch block |
|
154 |
e1.printStackTrace(); |
|
155 |
} |
|
156 |
DisposableIterator iterator = null; |
|
157 |
try { |
|
158 |
FeatureSet selection = (FeatureSet) featureStore.getSelection();// getSelectedRows(); |
|
159 |
// ArrayList selectedRowAux=new ArrayList(); |
|
160 |
ICoordTrans ct = getVLE().getLayer().getCoordTrans(); |
|
161 |
if (status.equals("Move.FirstPointToMove")) { |
|
162 |
firstPoint = new Point2D.Double(x, y); |
|
163 |
} else |
|
164 |
if (status.equals("Move.SecondPointToMove")) { |
|
165 |
PluginServices.getMDIManager().setWaitCursor(); |
|
166 |
lastPoint = new Point2D.Double(x, y); |
|
171 | 167 |
|
172 |
iterator = selection.iterator(); |
|
173 |
while (iterator.hasNext()) { |
|
174 |
Feature feature = (Feature) iterator.next(); |
|
168 |
featureStore.beginEditingGroup(getName()); |
|
169 |
try { |
|
175 | 170 |
|
176 |
// } |
|
177 |
// for (int i = 0; i < selection.size(); i++) { |
|
178 |
// IRowEdited edRow = (IRowEdited) selectedRow.get(i); |
|
179 |
// IFeature feat = (IFeature) |
|
180 |
// edRow.getLinkedRow().cloneRow(); |
|
181 |
Geometry ig = (feature.getDefaultGeometry()) |
|
182 |
.cloneGeometry(); |
|
183 |
EditableFeature eFeature = feature.getEditable(); |
|
184 |
if (ig == null) { |
|
185 |
continue; |
|
186 |
} |
|
187 |
if (ct != null) { |
|
188 |
lastPoint = ct.getInverted().convert(lastPoint, |
|
189 |
null); |
|
190 |
firstPoint = ct.getInverted().convert(firstPoint, |
|
191 |
null); |
|
171 |
iterator = selection.iterator(); |
|
172 |
while (iterator.hasNext()) { |
|
173 |
Feature feature = (Feature) iterator.next(); |
|
192 | 174 |
|
193 |
} |
|
194 |
// if (ct!=null) |
|
195 |
// ig.reProject(ct); |
|
196 |
// Movemos la geometr?a |
|
197 |
UtilFunctions.moveGeom(ig, lastPoint.getX() |
|
198 |
- firstPoint.getX(), lastPoint.getY() |
|
199 |
- firstPoint.getY()); |
|
175 |
// } |
|
176 |
// for (int i = 0; i < selection.size(); i++) { |
|
177 |
// IRowEdited edRow = (IRowEdited) |
|
178 |
// selectedRow.get(i); |
|
179 |
// IFeature feat = (IFeature) |
|
180 |
// edRow.getLinkedRow().cloneRow(); |
|
181 |
Geometry ig = |
|
182 |
(feature.getDefaultGeometry()).cloneGeometry(); |
|
183 |
EditableFeature eFeature = feature.getEditable(); |
|
184 |
if (ig == null) { |
|
185 |
continue; |
|
186 |
} |
|
187 |
if (ct != null) { |
|
188 |
lastPoint = |
|
189 |
ct.getInverted().convert(lastPoint, null); |
|
190 |
firstPoint = |
|
191 |
ct.getInverted().convert(firstPoint, null); |
|
200 | 192 |
|
201 |
// if (ct!=null) |
|
202 |
// ig.reProject(ct.getInverted()); |
|
203 |
eFeature.setGeometry(featureStore |
|
204 |
.getDefaultFeatureType() |
|
205 |
.getDefaultGeometryAttributeName(), ig); |
|
206 |
featureStore.update(eFeature); |
|
207 |
// vea.modifyRow(edRow.getIndex(),feat,getName(),EditionEvent.GRAPHIC); |
|
208 |
// selectedRowAux.add(new |
|
209 |
// DefaultRowEdited(feat,IRowEdited.STATUS_MODIFIED,edRow.getIndex())); |
|
210 |
} |
|
211 |
} finally { |
|
212 |
featureStore.endEditingGroup(); |
|
213 |
} |
|
214 |
// vle.setSelectionCache(VectorialLayerEdited.NOTSAVEPREVIOUS, |
|
215 |
// selectedRowAux); |
|
216 |
// clearSelection(); |
|
217 |
// selectedRow.addAll(selectedRowAux); |
|
218 |
} |
|
219 |
} catch (ReadException e) { |
|
220 |
NotificationManager.addError(e.getMessage(), e); |
|
221 |
} catch (DataException e) { |
|
222 |
NotificationManager.addError(e.getMessage(), e); |
|
223 |
} finally { |
|
224 |
if (iterator != null) { |
|
225 |
iterator.dispose(); |
|
226 |
} |
|
227 |
} |
|
228 |
PluginServices.getMDIManager().restoreCursor(); |
|
229 |
} |
|
193 |
} |
|
194 |
// if (ct!=null) |
|
195 |
// ig.reProject(ct); |
|
196 |
// Movemos la geometr?a |
|
197 |
UtilFunctions.moveGeom(ig, lastPoint.getX() |
|
198 |
- firstPoint.getX(), lastPoint.getY() |
|
199 |
- firstPoint.getY()); |
|
230 | 200 |
|
231 |
/** |
|
232 |
* M?todo para dibujar lo necesario para el estado en el que nos |
|
233 |
* encontremos. |
|
234 |
* |
|
235 |
* @param g Graphics sobre el que dibujar. |
|
236 |
* @param x par?metro x del punto que se pase para dibujar. |
|
237 |
* @param y 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(); |
|
201 |
// if (ct!=null) |
|
202 |
// ig.reProject(ct.getInverted()); |
|
203 |
eFeature.setGeometry(featureStore |
|
204 |
.getDefaultFeatureType() |
|
205 |
.getDefaultGeometryAttributeName(), ig); |
|
206 |
featureStore.update(eFeature); |
|
207 |
// vea.modifyRow(edRow.getIndex(),feat,getName(),EditionEvent.GRAPHIC); |
|
208 |
// selectedRowAux.add(new |
|
209 |
// DefaultRowEdited(feat,IRowEdited.STATUS_MODIFIED,edRow.getIndex())); |
|
210 |
} |
|
211 |
} finally { |
|
212 |
featureStore.endEditingGroup(); |
|
213 |
} |
|
214 |
// vle.setSelectionCache(VectorialLayerEdited.NOTSAVEPREVIOUS, |
|
215 |
// selectedRowAux); |
|
216 |
// clearSelection(); |
|
217 |
// selectedRow.addAll(selectedRowAux); |
|
218 |
} |
|
219 |
} catch (ReadException e) { |
|
220 |
NotificationManager.addError(e.getMessage(), e); |
|
221 |
} catch (DataException e) { |
|
222 |
NotificationManager.addError(e.getMessage(), e); |
|
223 |
} finally { |
|
224 |
if (iterator != null) { |
|
225 |
iterator.dispose(); |
|
226 |
} |
|
227 |
} |
|
228 |
PluginServices.getMDIManager().restoreCursor(); |
|
229 |
} |
|
243 | 230 |
|
244 |
if (status.equals("Move.SecondPointToMove")) { |
|
245 |
drawSelectedGeometries(renderer, firstPoint, x, y); |
|
246 |
} |
|
247 |
} |
|
231 |
/** |
|
232 |
* M?todo para dibujar lo necesario para el estado en el que nos |
|
233 |
* encontremos. |
|
234 |
* |
|
235 |
* @param g |
|
236 |
* Graphics sobre el que dibujar. |
|
237 |
* @param x |
|
238 |
* par?metro x del punto que se pase para dibujar. |
|
239 |
* @param y |
|
240 |
* par?metro x del punto que se pase para dibujar. |
|
241 |
*/ |
|
242 |
public void drawOperation(MapControlDrawer renderer, double x, double y) { |
|
243 |
MoveCADToolState actualState = (_fsm).getState(); |
|
244 |
String status = actualState.getName(); |
|
245 |
VectorialLayerEdited vle = getVLE(); |
|
248 | 246 |
|
249 |
/** |
|
250 |
* Add a diferent option. |
|
251 |
* |
|
252 |
* @param s Diferent option. |
|
253 |
*/ |
|
254 |
public void addOption(String s) { |
|
255 |
} |
|
247 |
if (status.equals("Move.SecondPointToMove")) { |
|
248 |
drawSelectedGeometries(renderer, firstPoint, x, y); |
|
249 |
} |
|
250 |
} |
|
256 | 251 |
|
257 |
/* (non-Javadoc) |
|
258 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double) |
|
259 |
*/ |
|
260 |
public void addValue(double d) { |
|
261 |
} |
|
252 |
/** |
|
253 |
* Add a diferent option. |
|
254 |
* |
|
255 |
* @param s |
|
256 |
* Diferent option. |
|
257 |
*/ |
|
258 |
public void addOption(String s) { |
|
259 |
} |
|
262 | 260 |
|
263 |
public String getName() { |
|
264 |
return PluginServices.getText(this,"move_"); |
|
265 |
} |
|
261 |
/* |
|
262 |
* (non-Javadoc) |
|
263 |
* |
|
264 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double) |
|
265 |
*/ |
|
266 |
public void addValue(double d) { |
|
267 |
} |
|
266 | 268 |
|
267 |
public String toString() {
|
|
268 |
return "_move";
|
|
269 |
}
|
|
269 |
public String getName() {
|
|
270 |
return PluginServices.getText(this, "move_");
|
|
271 |
}
|
|
270 | 272 |
|
273 |
public String toString() { |
|
274 |
return "_move"; |
|
275 |
} |
|
276 |
|
|
271 | 277 |
} |
Also available in: Unified diff