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 / CopyCADTool.java @ 40557
History | View | Annotate | Download (8.66 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.gvsig.andami.PluginServices; |
30 |
import org.gvsig.andami.messages.NotificationManager; |
31 |
import org.gvsig.editing.CADExtension; |
32 |
import org.gvsig.editing.gui.cad.DefaultCADTool; |
33 |
import org.gvsig.editing.gui.cad.exception.CommandException; |
34 |
import org.gvsig.editing.gui.cad.tools.smc.CopyCADToolContext; |
35 |
import org.gvsig.editing.gui.cad.tools.smc.CopyCADToolContext.CopyCADToolState; |
36 |
import org.gvsig.editing.layers.VectorialLayerEdited; |
37 |
import org.gvsig.fmap.dal.exception.DataException; |
38 |
import org.gvsig.fmap.dal.exception.ReadException; |
39 |
import org.gvsig.fmap.dal.feature.Feature; |
40 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
41 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
42 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
43 |
import org.gvsig.fmap.geom.Geometry; |
44 |
import org.gvsig.fmap.geom.type.GeometryType; |
45 |
import org.gvsig.fmap.geom.util.UtilFunctions; |
46 |
import org.gvsig.fmap.mapcontrol.MapControlDrawer; |
47 |
import org.gvsig.tools.dispose.DisposableIterator; |
48 |
|
49 |
/**
|
50 |
* DOCUMENT ME!
|
51 |
*
|
52 |
* @author Vicente Caballero Navarro
|
53 |
*/
|
54 |
public class CopyCADTool extends DefaultCADTool { |
55 |
|
56 |
private CopyCADToolContext _fsm;
|
57 |
private Point2D firstPoint; |
58 |
private Point2D lastPoint; |
59 |
private GeometryType[] gTypes; |
60 |
|
61 |
/**
|
62 |
* M?todo de incio, para poner el c?digo de todo lo que se requiera de una
|
63 |
* carga previa a la utilizaci?n de la herramienta.
|
64 |
*/
|
65 |
public void init() { |
66 |
_fsm = new CopyCADToolContext(this); |
67 |
} |
68 |
|
69 |
/*
|
70 |
* (non-Javadoc)
|
71 |
*
|
72 |
* @see
|
73 |
* com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap
|
74 |
* .layers.FBitSet, double, double)
|
75 |
*/
|
76 |
public void transition(double x, double y, InputEvent event) { |
77 |
_fsm.addPoint(x, y, event); |
78 |
} |
79 |
|
80 |
/*
|
81 |
* (non-Javadoc)
|
82 |
*
|
83 |
* @see
|
84 |
* com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap
|
85 |
* .layers.FBitSet, double)
|
86 |
*/
|
87 |
public void transition(double d) { |
88 |
_fsm.addValue(d); |
89 |
} |
90 |
|
91 |
/*
|
92 |
* (non-Javadoc)
|
93 |
*
|
94 |
* @see
|
95 |
* com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap
|
96 |
* .layers.FBitSet, java.lang.String)
|
97 |
*/
|
98 |
public void transition(String s) throws CommandException { |
99 |
if (!super.changeCommand(s)) { |
100 |
_fsm.addOption(s); |
101 |
} |
102 |
} |
103 |
|
104 |
/**
|
105 |
* DOCUMENT ME!
|
106 |
*/
|
107 |
public void selection() { |
108 |
FeatureSet selection = null;
|
109 |
try {
|
110 |
selection = (FeatureSet) getVLE().getFeatureStore().getSelection(); |
111 |
|
112 |
if (selection.getSize() == 0 |
113 |
&& !SelectionCADTool.isInstance(CADExtension.getCADTool(), true)) {
|
114 |
CADExtension.setCADTool("_selection", false); |
115 |
((SelectionCADTool) CADExtension.getCADTool()) |
116 |
.setNextTool("_copy");
|
117 |
} |
118 |
} catch (ReadException e) {
|
119 |
// TODO Auto-generated catch block
|
120 |
e.printStackTrace(); |
121 |
} catch (DataException e) {
|
122 |
// TODO Auto-generated catch block
|
123 |
e.printStackTrace(); |
124 |
} |
125 |
} |
126 |
|
127 |
/**
|
128 |
* Equivale al transition del prototipo pero sin pasarle como par?metro el
|
129 |
* editableFeatureSource que ya estar? creado.
|
130 |
*
|
131 |
* @param x
|
132 |
* par?metro x del punto que se pase en esta transici?n.
|
133 |
* @param y
|
134 |
* par?metro y del punto que se pase en esta transici?n.
|
135 |
*/
|
136 |
public void addPoint(double x, double y, InputEvent event) { |
137 |
CopyCADToolState actualState = |
138 |
(CopyCADToolState) _fsm.getPreviousState(); |
139 |
String status = actualState.getName();
|
140 |
VectorialLayerEdited vle = getVLE(); |
141 |
FeatureStore featureStore = null;
|
142 |
try {
|
143 |
featureStore = vle.getFeatureStore(); |
144 |
// FeatureSelection selection =
|
145 |
// featureStore.createFeatureSelection();
|
146 |
// selection.select((FeatureSet) featureStore.getSelection());
|
147 |
FeatureSelection selection = |
148 |
(FeatureSelection) featureStore.getSelection(); |
149 |
if (status.equals("Copy.FirstPointToMove")) { |
150 |
firstPoint = new Point2D.Double(x, y); |
151 |
} else
|
152 |
if (status.equals("Copy.SecondPointToMove")) { |
153 |
PluginServices.getMDIManager().setWaitCursor(); |
154 |
lastPoint = new Point2D.Double(x, y); |
155 |
featureStore.beginEditingGroup(getName()); |
156 |
|
157 |
FeatureSelection newSelection = |
158 |
featureStore.createFeatureSelection(); |
159 |
|
160 |
DisposableIterator iterator = null;
|
161 |
|
162 |
try {
|
163 |
iterator = selection.iterator(); |
164 |
|
165 |
featureStore.beginComplexNotification(); |
166 |
|
167 |
while (iterator.hasNext()) {
|
168 |
Feature feature = (Feature) iterator.next(); |
169 |
// Movemos la geometr?a
|
170 |
Geometry geometry = |
171 |
(feature.getDefaultGeometry()).cloneGeometry(); |
172 |
// EditableFeature
|
173 |
// eFeature=featureStore.createNewFeature(true);
|
174 |
geometry.move(lastPoint.getX() - firstPoint.getX(), |
175 |
lastPoint.getY() - firstPoint.getY()); |
176 |
|
177 |
// eFeature.setGeometry(featureStore.getDefaultFeatureType().getDefaultGeometryAttributeName(),geometry);
|
178 |
// featureStore.insert(eFeature);
|
179 |
newSelection.select(insertGeometry(geometry, |
180 |
feature)); |
181 |
} |
182 |
// clearSelection();
|
183 |
featureStore.endComplexNotification(); |
184 |
featureStore.setSelection(newSelection); |
185 |
featureStore.endEditingGroup(); |
186 |
PluginServices.getMDIManager().restoreCursor(); |
187 |
} catch (DataException e) {
|
188 |
featureStore.endComplexNotification(); |
189 |
throw e;
|
190 |
} finally {
|
191 |
if (iterator != null) { |
192 |
iterator.dispose(); |
193 |
} |
194 |
} |
195 |
|
196 |
} else {
|
197 |
} |
198 |
} catch (DataException e) {
|
199 |
NotificationManager.addError(e.getMessage(), e); |
200 |
} |
201 |
} |
202 |
|
203 |
/**
|
204 |
* M?todo para dibujar la lo necesario para el estado en el que nos
|
205 |
* encontremos.
|
206 |
*
|
207 |
* @param g
|
208 |
* Graphics sobre el que dibujar.
|
209 |
* @param x
|
210 |
* par?metro x del punto que se pase para dibujar.
|
211 |
* @param y
|
212 |
* par?metro x del punto que se pase para dibujar.
|
213 |
*/
|
214 |
public void drawOperation(MapControlDrawer renderer, double x, double y) { |
215 |
CopyCADToolState actualState = _fsm.getState(); |
216 |
String status = actualState.getName();
|
217 |
VectorialLayerEdited vle = getVLE(); |
218 |
if (status.equals("Copy.SecondPointToMove")) { |
219 |
drawSelectedGeometries(renderer, firstPoint, x, y); |
220 |
} |
221 |
} |
222 |
|
223 |
/**
|
224 |
* Add a diferent option.
|
225 |
*
|
226 |
* @param s
|
227 |
* Diferent option.
|
228 |
*/
|
229 |
public void addOption(String s) { |
230 |
} |
231 |
|
232 |
/*
|
233 |
* (non-Javadoc)
|
234 |
*
|
235 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
|
236 |
*/
|
237 |
public void addValue(double d) { |
238 |
} |
239 |
|
240 |
public String getName() { |
241 |
return PluginServices.getText(this, "copy_"); |
242 |
} |
243 |
|
244 |
public String toString() { |
245 |
return "_copy"; |
246 |
} |
247 |
|
248 |
@Override
|
249 |
public boolean isApplicable(GeometryType geometryType) { |
250 |
return true; |
251 |
} |
252 |
|
253 |
@Override
|
254 |
protected int[] getSupportedGeometryTypes() { |
255 |
return null; |
256 |
} |
257 |
} |