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 | 3883 | caballero | /* 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 | 29616 | jpiera | package org.gvsig.editing.gui.cad.tools; |
42 | 3883 | caballero | |
43 | 4637 | caballero | import java.awt.Image; |
44 | 4313 | fjp | import java.awt.event.InputEvent; |
45 | 3978 | caballero | import java.awt.geom.Point2D; |
46 | 3883 | caballero | |
47 | 29616 | jpiera | 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 | 24500 | jmvivo | import org.gvsig.fmap.dal.exception.DataException; |
56 | import org.gvsig.fmap.dal.exception.ReadException; |
||
57 | 27525 | jmvivo | import org.gvsig.fmap.dal.feature.DisposableIterator; |
58 | 24490 | jmvivo | import org.gvsig.fmap.dal.feature.Feature; |
59 | 27269 | jmvivo | import org.gvsig.fmap.dal.feature.FeatureSelection; |
60 | 24490 | jmvivo | import org.gvsig.fmap.dal.feature.FeatureSet; |
61 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
62 | 23086 | vcaballero | import org.gvsig.fmap.geom.Geometry; |
63 | 21668 | vcaballero | import org.gvsig.fmap.geom.util.UtilFunctions; |
64 | import org.gvsig.fmap.mapcontext.ViewPort; |
||
65 | 30335 | jpiera | import org.gvsig.fmap.mapcontrol.MapControlDrawer; |
66 | 21668 | vcaballero | |
67 | 3883 | caballero | |
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 | 4313 | fjp | public void transition(double x, double y, InputEvent event) { |
97 | 4324 | caballero | _fsm.addPoint(x, y, event); |
98 | 3883 | caballero | } |
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 | 5735 | caballero | _fsm.addValue(d); |
105 | 3883 | caballero | } |
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 | 5735 | caballero | public void transition(String s) throws CommandException { |
111 | 4892 | caballero | if (!super.changeCommand(s)){ |
112 | _fsm.addOption(s); |
||
113 | } |
||
114 | 3883 | caballero | } |
115 | |||
116 | /**
|
||
117 | * DOCUMENT ME!
|
||
118 | */
|
||
119 | public void selection() { |
||
120 | 23842 | jjdelcerro | FeatureSet selection=null;
|
121 | 24263 | vcaballero | 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 | 3883 | caballero | } |
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 | 4365 | caballero | public void addPoint(double x, double y,InputEvent event) { |
146 | 24263 | vcaballero | 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 | 27525 | jmvivo | // FeatureSelection selection = featureStore.createFeatureSelection();
|
153 | // selection.select((FeatureSet) featureStore.getSelection());
|
||
154 | FeatureSelection selection = (FeatureSelection) featureStore |
||
155 | .getSelection(); |
||
156 | 24263 | vcaballero | 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 | 3883 | caballero | |
163 | 27269 | jmvivo | FeatureSelection newSelection = featureStore |
164 | 27525 | jmvivo | .createFeatureSelection(); |
165 | 27269 | jmvivo | |
166 | 27525 | jmvivo | DisposableIterator iterator = null;
|
167 | 27269 | jmvivo | |
168 | 27525 | jmvivo | try{
|
169 | iterator = selection.iterator(); |
||
170 | 27269 | jmvivo | |
171 | 27525 | jmvivo | 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 | 24263 | vcaballero | } |
197 | 27525 | jmvivo | |
198 | } else {
|
||
199 | } |
||
200 | } catch (DataException e) {
|
||
201 | NotificationManager.addError(e.getMessage(),e); |
||
202 | 24263 | vcaballero | } |
203 | } |
||
204 | 3883 | caballero | |
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 | 30335 | jpiera | public void drawOperation(MapControlDrawer renderer, double x, double y) { |
214 | 9121 | caballero | CopyCADToolState actualState = _fsm.getState(); |
215 | 3883 | caballero | String status = actualState.getName();
|
216 | 4637 | caballero | VectorialLayerEdited vle=getVLE(); |
217 | 3978 | caballero | if (status.equals("Copy.SecondPointToMove")) { |
218 | 6881 | cesar | ViewPort vp=vle.getLayer().getMapContext().getViewPort(); |
219 | 4637 | caballero | int dx = vp.fromMapDistance(x - firstPoint.getX());
|
220 | int dy = -vp.fromMapDistance(y - firstPoint.getY());
|
||
221 | Image img = vle.getSelectionImage();
|
||
222 | 30335 | jpiera | renderer.drawImage(img, dx, dy); |
223 | 4637 | caballero | }else{
|
224 | 27269 | jmvivo | if (!vle.getLayer().isVisible()) {
|
225 | 7547 | caballero | return;
|
226 | 27269 | jmvivo | } |
227 | 4637 | caballero | Image imgSel = vle.getSelectionImage();
|
228 | 30335 | jpiera | renderer.drawImage(imgSel, 0, 0); |
229 | |||
230 | 4637 | caballero | Image imgHand = vle.getHandlersImage();
|
231 | 30335 | jpiera | renderer.drawImage(imgHand, 0, 0); |
232 | 3883 | caballero | } |
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 | 4118 | caballero | |
249 | public String getName() { |
||
250 | 4584 | caballero | return PluginServices.getText(this,"copy_"); |
251 | 4118 | caballero | } |
252 | 4892 | caballero | |
253 | public String toString() { |
||
254 | return "_copy"; |
||
255 | } |
||
256 | 5170 | caballero | |
257 | |||
258 | 3883 | caballero | } |