svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / gui / cad / tools / CopyCADTool.java @ 36749
History | View | Annotate | Download (7.79 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 | 30788 | jpiera | import org.cresques.cts.ICoordTrans; |
48 | 29616 | jpiera | import org.gvsig.andami.PluginServices; |
49 | import org.gvsig.andami.messages.NotificationManager; |
||
50 | import org.gvsig.editing.CADExtension; |
||
51 | import org.gvsig.editing.gui.cad.DefaultCADTool; |
||
52 | import org.gvsig.editing.gui.cad.exception.CommandException; |
||
53 | import org.gvsig.editing.gui.cad.tools.smc.CopyCADToolContext; |
||
54 | import org.gvsig.editing.gui.cad.tools.smc.CopyCADToolContext.CopyCADToolState; |
||
55 | import org.gvsig.editing.layers.VectorialLayerEdited; |
||
56 | 24500 | jmvivo | import org.gvsig.fmap.dal.exception.DataException; |
57 | import org.gvsig.fmap.dal.exception.ReadException; |
||
58 | 33205 | cordinyana | import org.gvsig.tools.dispose.DisposableIterator; |
59 | 24490 | jmvivo | import org.gvsig.fmap.dal.feature.Feature; |
60 | 27269 | jmvivo | import org.gvsig.fmap.dal.feature.FeatureSelection; |
61 | 24490 | jmvivo | import org.gvsig.fmap.dal.feature.FeatureSet; |
62 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
63 | 23086 | vcaballero | import org.gvsig.fmap.geom.Geometry; |
64 | 21668 | vcaballero | import org.gvsig.fmap.geom.util.UtilFunctions; |
65 | import org.gvsig.fmap.mapcontext.ViewPort; |
||
66 | 30335 | jpiera | import org.gvsig.fmap.mapcontrol.MapControlDrawer; |
67 | 21668 | vcaballero | |
68 | 3883 | caballero | |
69 | |||
70 | /**
|
||
71 | * DOCUMENT ME!
|
||
72 | *
|
||
73 | * @author Vicente Caballero Navarro
|
||
74 | */
|
||
75 | public class CopyCADTool extends DefaultCADTool { |
||
76 | private CopyCADToolContext _fsm;
|
||
77 | private Point2D firstPoint; |
||
78 | private Point2D lastPoint; |
||
79 | |||
80 | /**
|
||
81 | * Crea un nuevo PolylineCADTool.
|
||
82 | */
|
||
83 | public CopyCADTool() {
|
||
84 | } |
||
85 | |||
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 CopyCADToolContext(this); |
||
92 | } |
||
93 | |||
94 | /* (non-Javadoc)
|
||
95 | * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double, double)
|
||
96 | */
|
||
97 | 4313 | fjp | public void transition(double x, double y, InputEvent event) { |
98 | 4324 | caballero | _fsm.addPoint(x, y, event); |
99 | 3883 | caballero | } |
100 | |||
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 | 5735 | caballero | _fsm.addValue(d); |
106 | 3883 | caballero | } |
107 | |||
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 | 5735 | caballero | public void transition(String s) throws CommandException { |
112 | 4892 | caballero | if (!super.changeCommand(s)){ |
113 | _fsm.addOption(s); |
||
114 | } |
||
115 | 3883 | caballero | } |
116 | |||
117 | /**
|
||
118 | * DOCUMENT ME!
|
||
119 | */
|
||
120 | public void selection() { |
||
121 | 23842 | jjdelcerro | FeatureSet selection=null;
|
122 | 24263 | vcaballero | try {
|
123 | selection = (FeatureSet)getVLE().getFeatureStore().getSelection(); |
||
124 | |||
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 | "_copy");
|
||
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 | 3883 | caballero | } |
138 | |||
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 | 4365 | caballero | public void addPoint(double x, double y,InputEvent event) { |
147 | 24263 | vcaballero | CopyCADToolState actualState = (CopyCADToolState) _fsm.getPreviousState(); |
148 | String status = actualState.getName();
|
||
149 | VectorialLayerEdited vle=getVLE(); |
||
150 | FeatureStore featureStore=null;
|
||
151 | try {
|
||
152 | featureStore = vle.getFeatureStore(); |
||
153 | 27525 | jmvivo | // FeatureSelection selection = featureStore.createFeatureSelection();
|
154 | // selection.select((FeatureSet) featureStore.getSelection());
|
||
155 | FeatureSelection selection = (FeatureSelection) featureStore |
||
156 | .getSelection(); |
||
157 | 24263 | vcaballero | if (status.equals("Copy.FirstPointToMove")) { |
158 | firstPoint = new Point2D.Double(x, y); |
||
159 | } else if (status.equals("Copy.SecondPointToMove")) { |
||
160 | PluginServices.getMDIManager().setWaitCursor(); |
||
161 | lastPoint = new Point2D.Double(x, y); |
||
162 | featureStore.beginEditingGroup(getName()); |
||
163 | 3883 | caballero | |
164 | 27269 | jmvivo | FeatureSelection newSelection = featureStore |
165 | 27525 | jmvivo | .createFeatureSelection(); |
166 | 27269 | jmvivo | |
167 | 27525 | jmvivo | DisposableIterator iterator = null;
|
168 | 27269 | jmvivo | |
169 | 27525 | jmvivo | try{
|
170 | iterator = selection.iterator(); |
||
171 | 27269 | jmvivo | |
172 | 27525 | jmvivo | featureStore.beginComplexNotification(); |
173 | |||
174 | while (iterator.hasNext()) {
|
||
175 | Feature feature = (Feature) iterator.next(); |
||
176 | // Movemos la geometr?a
|
||
177 | Geometry geometry=(feature.getDefaultGeometry()).cloneGeometry(); |
||
178 | // EditableFeature eFeature=featureStore.createNewFeature(true);
|
||
179 | UtilFunctions.moveGeom(geometry, lastPoint.getX() - |
||
180 | firstPoint.getX(), lastPoint.getY() - firstPoint.getY()); |
||
181 | // eFeature.setGeometry(featureStore.getDefaultFeatureType().getDefaultGeometryAttributeName(),geometry);
|
||
182 | // featureStore.insert(eFeature);
|
||
183 | newSelection.select(insertGeometry(geometry, feature)); |
||
184 | } |
||
185 | // clearSelection();
|
||
186 | featureStore.endComplexNotification(); |
||
187 | featureStore.setSelection(newSelection); |
||
188 | featureStore.endEditingGroup(); |
||
189 | PluginServices.getMDIManager().restoreCursor(); |
||
190 | } catch (DataException e) {
|
||
191 | featureStore.endComplexNotification(); |
||
192 | throw e;
|
||
193 | } finally{
|
||
194 | if (iterator != null){ |
||
195 | iterator.dispose(); |
||
196 | } |
||
197 | 24263 | vcaballero | } |
198 | 27525 | jmvivo | |
199 | } else {
|
||
200 | } |
||
201 | } catch (DataException e) {
|
||
202 | NotificationManager.addError(e.getMessage(),e); |
||
203 | 24263 | vcaballero | } |
204 | } |
||
205 | 3883 | caballero | |
206 | /**
|
||
207 | * M?todo para dibujar la lo necesario para el estado en el que nos
|
||
208 | * encontremos.
|
||
209 | *
|
||
210 | * @param g Graphics sobre el que dibujar.
|
||
211 | * @param x par?metro x del punto que se pase para dibujar.
|
||
212 | * @param y par?metro x del punto que se pase para dibujar.
|
||
213 | */
|
||
214 | 30335 | jpiera | public void drawOperation(MapControlDrawer renderer, double x, double y) { |
215 | 9121 | caballero | CopyCADToolState actualState = _fsm.getState(); |
216 | 3883 | caballero | String status = actualState.getName();
|
217 | 4637 | caballero | VectorialLayerEdited vle=getVLE(); |
218 | 3978 | caballero | if (status.equals("Copy.SecondPointToMove")) { |
219 | 30788 | jpiera | drawSelectedGeometries(renderer, firstPoint, x, y); |
220 | 3883 | caballero | } |
221 | } |
||
222 | |||
223 | /**
|
||
224 | * Add a diferent option.
|
||
225 | *
|
||
226 | * @param s Diferent option.
|
||
227 | */
|
||
228 | public void addOption(String s) { |
||
229 | } |
||
230 | |||
231 | /* (non-Javadoc)
|
||
232 | * @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
|
||
233 | */
|
||
234 | public void addValue(double d) { |
||
235 | } |
||
236 | 4118 | caballero | |
237 | public String getName() { |
||
238 | 4584 | caballero | return PluginServices.getText(this,"copy_"); |
239 | 4118 | caballero | } |
240 | 4892 | caballero | |
241 | public String toString() { |
||
242 | return "_copy"; |
||
243 | } |
||
244 | 5170 | caballero | |
245 | |||
246 | 3883 | caballero | } |