svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / gui / cad / tools / CopyCADTool.java @ 30335
History | View | Annotate | Download (8.26 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* 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
|
40 |
*/
|
41 |
package org.gvsig.editing.gui.cad.tools; |
42 |
|
43 |
import java.awt.Image; |
44 |
import java.awt.event.InputEvent; |
45 |
import java.awt.geom.Point2D; |
46 |
|
47 |
import org.gvsig.andami.PluginServices; |
48 |
import org.gvsig.andami.messages.NotificationManager; |
49 |
import org.gvsig.editing.CADExtension; |
50 |
import org.gvsig.editing.gui.cad.DefaultCADTool; |
51 |
import org.gvsig.editing.gui.cad.exception.CommandException; |
52 |
import org.gvsig.editing.gui.cad.tools.smc.CopyCADToolContext; |
53 |
import org.gvsig.editing.gui.cad.tools.smc.CopyCADToolContext.CopyCADToolState; |
54 |
import org.gvsig.editing.layers.VectorialLayerEdited; |
55 |
import org.gvsig.fmap.dal.exception.DataException; |
56 |
import org.gvsig.fmap.dal.exception.ReadException; |
57 |
import org.gvsig.fmap.dal.feature.DisposableIterator; |
58 |
import org.gvsig.fmap.dal.feature.Feature; |
59 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
60 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
61 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
62 |
import org.gvsig.fmap.geom.Geometry; |
63 |
import org.gvsig.fmap.geom.util.UtilFunctions; |
64 |
import org.gvsig.fmap.mapcontext.ViewPort; |
65 |
import org.gvsig.fmap.mapcontrol.MapControlDrawer; |
66 |
|
67 |
|
68 |
|
69 |
/**
|
70 |
* DOCUMENT ME!
|
71 |
*
|
72 |
* @author Vicente Caballero Navarro
|
73 |
*/
|
74 |
public class CopyCADTool extends DefaultCADTool { |
75 |
private CopyCADToolContext _fsm;
|
76 |
private Point2D firstPoint; |
77 |
private Point2D lastPoint; |
78 |
|
79 |
/**
|
80 |
* Crea un nuevo PolylineCADTool.
|
81 |
*/
|
82 |
public CopyCADTool() {
|
83 |
} |
84 |
|
85 |
/**
|
86 |
* M?todo de incio, para poner el c?digo de todo lo que se requiera de una
|
87 |
* carga previa a la utilizaci?n de la herramienta.
|
88 |
*/
|
89 |
public void init() { |
90 |
_fsm = new CopyCADToolContext(this); |
91 |
} |
92 |
|
93 |
/* (non-Javadoc)
|
94 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double, double)
|
95 |
*/
|
96 |
public void transition(double x, double y, InputEvent event) { |
97 |
_fsm.addPoint(x, y, event); |
98 |
} |
99 |
|
100 |
/* (non-Javadoc)
|
101 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double)
|
102 |
*/
|
103 |
public void transition(double d) { |
104 |
_fsm.addValue(d); |
105 |
} |
106 |
|
107 |
/* (non-Javadoc)
|
108 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, java.lang.String)
|
109 |
*/
|
110 |
public void transition(String s) throws CommandException { |
111 |
if (!super.changeCommand(s)){ |
112 |
_fsm.addOption(s); |
113 |
} |
114 |
} |
115 |
|
116 |
/**
|
117 |
* DOCUMENT ME!
|
118 |
*/
|
119 |
public void selection() { |
120 |
FeatureSet selection=null;
|
121 |
try {
|
122 |
selection = (FeatureSet)getVLE().getFeatureStore().getSelection(); |
123 |
|
124 |
if (selection.getSize() == 0 && !CADExtension.getCADTool().getClass().getName().equals("com.iver.cit.gvsig.gui.cad.tools.SelectionCADTool")) { |
125 |
CADExtension.setCADTool("_selection",false); |
126 |
((SelectionCADTool) CADExtension.getCADTool()).setNextTool( |
127 |
"_copy");
|
128 |
} |
129 |
} catch (ReadException e) {
|
130 |
// TODO Auto-generated catch block
|
131 |
e.printStackTrace(); |
132 |
} catch (DataException e) {
|
133 |
// TODO Auto-generated catch block
|
134 |
e.printStackTrace(); |
135 |
} |
136 |
} |
137 |
|
138 |
/**
|
139 |
* Equivale al transition del prototipo pero sin pasarle como par?metro el
|
140 |
* editableFeatureSource que ya estar? creado.
|
141 |
*
|
142 |
* @param x par?metro x del punto que se pase en esta transici?n.
|
143 |
* @param y par?metro y del punto que se pase en esta transici?n.
|
144 |
*/
|
145 |
public void addPoint(double x, double y,InputEvent event) { |
146 |
CopyCADToolState actualState = (CopyCADToolState) _fsm.getPreviousState(); |
147 |
String status = actualState.getName();
|
148 |
VectorialLayerEdited vle=getVLE(); |
149 |
FeatureStore featureStore=null;
|
150 |
try {
|
151 |
featureStore = vle.getFeatureStore(); |
152 |
// FeatureSelection selection = featureStore.createFeatureSelection();
|
153 |
// selection.select((FeatureSet) featureStore.getSelection());
|
154 |
FeatureSelection selection = (FeatureSelection) featureStore |
155 |
.getSelection(); |
156 |
if (status.equals("Copy.FirstPointToMove")) { |
157 |
firstPoint = new Point2D.Double(x, y); |
158 |
} else if (status.equals("Copy.SecondPointToMove")) { |
159 |
PluginServices.getMDIManager().setWaitCursor(); |
160 |
lastPoint = new Point2D.Double(x, y); |
161 |
featureStore.beginEditingGroup(getName()); |
162 |
|
163 |
FeatureSelection newSelection = featureStore |
164 |
.createFeatureSelection(); |
165 |
|
166 |
DisposableIterator iterator = null;
|
167 |
|
168 |
try{
|
169 |
iterator = selection.iterator(); |
170 |
|
171 |
featureStore.beginComplexNotification(); |
172 |
|
173 |
while (iterator.hasNext()) {
|
174 |
Feature feature = (Feature) iterator.next(); |
175 |
// Movemos la geometr?a
|
176 |
Geometry geometry=(feature.getDefaultGeometry()).cloneGeometry(); |
177 |
// EditableFeature eFeature=featureStore.createNewFeature(true);
|
178 |
UtilFunctions.moveGeom(geometry, lastPoint.getX() - |
179 |
firstPoint.getX(), lastPoint.getY() - firstPoint.getY()); |
180 |
// eFeature.setGeometry(featureStore.getDefaultFeatureType().getDefaultGeometryAttributeName(),geometry);
|
181 |
// featureStore.insert(eFeature);
|
182 |
newSelection.select(insertGeometry(geometry, feature)); |
183 |
} |
184 |
// clearSelection();
|
185 |
featureStore.endComplexNotification(); |
186 |
featureStore.setSelection(newSelection); |
187 |
featureStore.endEditingGroup(); |
188 |
PluginServices.getMDIManager().restoreCursor(); |
189 |
} catch (DataException e) {
|
190 |
featureStore.endComplexNotification(); |
191 |
throw e;
|
192 |
} finally{
|
193 |
if (iterator != null){ |
194 |
iterator.dispose(); |
195 |
} |
196 |
} |
197 |
|
198 |
} else {
|
199 |
} |
200 |
} catch (DataException e) {
|
201 |
NotificationManager.addError(e.getMessage(),e); |
202 |
} |
203 |
} |
204 |
|
205 |
/**
|
206 |
* M?todo para dibujar la lo necesario para el estado en el que nos
|
207 |
* encontremos.
|
208 |
*
|
209 |
* @param g Graphics sobre el que dibujar.
|
210 |
* @param x par?metro x del punto que se pase para dibujar.
|
211 |
* @param y par?metro x del punto que se pase para dibujar.
|
212 |
*/
|
213 |
public void drawOperation(MapControlDrawer renderer, double x, double y) { |
214 |
CopyCADToolState actualState = _fsm.getState(); |
215 |
String status = actualState.getName();
|
216 |
VectorialLayerEdited vle=getVLE(); |
217 |
if (status.equals("Copy.SecondPointToMove")) { |
218 |
ViewPort vp=vle.getLayer().getMapContext().getViewPort(); |
219 |
int dx = vp.fromMapDistance(x - firstPoint.getX());
|
220 |
int dy = -vp.fromMapDistance(y - firstPoint.getY());
|
221 |
Image img = vle.getSelectionImage();
|
222 |
renderer.drawImage(img, dx, dy); |
223 |
}else{
|
224 |
if (!vle.getLayer().isVisible()) {
|
225 |
return;
|
226 |
} |
227 |
Image imgSel = vle.getSelectionImage();
|
228 |
renderer.drawImage(imgSel, 0, 0); |
229 |
|
230 |
Image imgHand = vle.getHandlersImage();
|
231 |
renderer.drawImage(imgHand, 0, 0); |
232 |
} |
233 |
} |
234 |
|
235 |
/**
|
236 |
* Add a diferent option.
|
237 |
*
|
238 |
* @param s Diferent option.
|
239 |
*/
|
240 |
public void addOption(String s) { |
241 |
} |
242 |
|
243 |
/* (non-Javadoc)
|
244 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
|
245 |
*/
|
246 |
public void addValue(double d) { |
247 |
} |
248 |
|
249 |
public String getName() { |
250 |
return PluginServices.getText(this,"copy_"); |
251 |
} |
252 |
|
253 |
public String toString() { |
254 |
return "_copy"; |
255 |
} |
256 |
|
257 |
|
258 |
} |