root / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / gui / cad / tools / StretchCADTool.java @ 37328
History | View | Annotate | Download (14.6 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
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 2
|
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 |
*/
|
22 |
package org.gvsig.editing.gui.cad.tools; |
23 |
|
24 |
import java.awt.event.InputEvent; |
25 |
import java.awt.geom.Point2D; |
26 |
import java.awt.geom.Rectangle2D; |
27 |
|
28 |
import org.gvsig.andami.PluginServices; |
29 |
import org.gvsig.andami.messages.NotificationManager; |
30 |
import org.gvsig.editing.CADExtension; |
31 |
import org.gvsig.editing.gui.cad.DefaultCADTool; |
32 |
import org.gvsig.editing.gui.cad.exception.CommandException; |
33 |
import org.gvsig.editing.gui.cad.tools.smc.StretchCADToolContext; |
34 |
import org.gvsig.editing.gui.cad.tools.smc.StretchCADToolContext.StretchCADToolState; |
35 |
import org.gvsig.editing.layers.VectorialLayerEdited; |
36 |
import org.gvsig.fmap.dal.exception.DataException; |
37 |
import org.gvsig.fmap.dal.exception.ReadException; |
38 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
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.handler.Handler; |
45 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
46 |
import org.gvsig.fmap.mapcontrol.MapControlDrawer; |
47 |
import org.gvsig.tools.dispose.DisposableIterator; |
48 |
|
49 |
/**
|
50 |
* Herramienta para estirar los handlers que seleccionemos previamente.
|
51 |
*
|
52 |
* @author Vicente Caballero Navarro
|
53 |
*/
|
54 |
public class StretchCADTool extends DefaultCADTool { |
55 |
|
56 |
protected StretchCADToolContext _fsm;
|
57 |
protected Point2D selfirstPoint; |
58 |
protected Point2D sellastPoint; |
59 |
protected Point2D movefirstPoint; |
60 |
protected Point2D movelastPoint; |
61 |
protected Rectangle2D rect = null; |
62 |
|
63 |
/**
|
64 |
* M?todo de incio, para poner el c?digo de todo lo que se requiera de una
|
65 |
* carga previa a la utilizaci?n de la herramienta.
|
66 |
*/
|
67 |
public void init() { |
68 |
_fsm = new StretchCADToolContext(this); |
69 |
} |
70 |
|
71 |
/*
|
72 |
* (non-Javadoc)
|
73 |
*
|
74 |
* @see
|
75 |
* com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap
|
76 |
* .layers.FBitSet,
|
77 |
* double, double)
|
78 |
*/
|
79 |
public void transition(double x, double y, InputEvent event) { |
80 |
_fsm.addPoint(x, y, event); |
81 |
} |
82 |
|
83 |
/*
|
84 |
* (non-Javadoc)
|
85 |
*
|
86 |
* @see
|
87 |
* com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap
|
88 |
* .layers.FBitSet,
|
89 |
* double)
|
90 |
*/
|
91 |
public void transition(double d) { |
92 |
_fsm.addValue(d); |
93 |
} |
94 |
|
95 |
/*
|
96 |
* (non-Javadoc)
|
97 |
*
|
98 |
* @see
|
99 |
* com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap
|
100 |
* .layers.FBitSet,
|
101 |
* java.lang.String)
|
102 |
*/
|
103 |
public void transition(String s) throws CommandException { |
104 |
if (!super.changeCommand(s)) { |
105 |
_fsm.addOption(s); |
106 |
} |
107 |
} |
108 |
|
109 |
/**
|
110 |
* DOCUMENT ME!
|
111 |
*/
|
112 |
public void selection() { |
113 |
FeatureSet selection = null;
|
114 |
try {
|
115 |
selection = (FeatureSet) getVLE().getFeatureStore().getSelection(); |
116 |
|
117 |
if (selection.getSize() == 0 |
118 |
&& !CADExtension |
119 |
.getCADTool() |
120 |
.getClass() |
121 |
.getName() |
122 |
.equals("com.iver.cit.gvsig.gui.cad.tools.SelectionCADTool")) {
|
123 |
CADExtension.setCADTool("_selection", false); |
124 |
((SelectionCADTool) CADExtension.getCADTool()) |
125 |
.setNextTool("_stretch");
|
126 |
} |
127 |
} catch (ReadException e) {
|
128 |
// TODO Auto-generated catch block
|
129 |
e.printStackTrace(); |
130 |
} catch (DataException e) {
|
131 |
// TODO Auto-generated catch block
|
132 |
e.printStackTrace(); |
133 |
} |
134 |
} |
135 |
|
136 |
/**
|
137 |
* Equivale al transition del prototipo pero sin pasarle como par?metro el
|
138 |
* editableFeatureSource que ya estar? creado.
|
139 |
*
|
140 |
* @param x
|
141 |
* par?metro x del punto que se pase en esta transici?n.
|
142 |
* @param y
|
143 |
* par?metro y del punto que se pase en esta transici?n.
|
144 |
*/
|
145 |
public void addPoint(double x, double y, InputEvent event) { |
146 |
StretchCADToolState actualState = |
147 |
(StretchCADToolState) _fsm.getPreviousState(); |
148 |
String status = actualState.getName();
|
149 |
|
150 |
if (status.equals("Stretch.SelFirstPoint")) { |
151 |
selfirstPoint = new Point2D.Double(x, y); |
152 |
} else
|
153 |
if (status.equals("Stretch.SelLastPoint")) { |
154 |
sellastPoint = new Point2D.Double(x, y); |
155 |
|
156 |
double x1;
|
157 |
double y1;
|
158 |
double w1;
|
159 |
double h1;
|
160 |
|
161 |
if (selfirstPoint.getX() < sellastPoint.getX()) {
|
162 |
x1 = selfirstPoint.getX(); |
163 |
w1 = sellastPoint.getX() - selfirstPoint.getX(); |
164 |
} else {
|
165 |
x1 = sellastPoint.getX(); |
166 |
w1 = selfirstPoint.getX() - sellastPoint.getX(); |
167 |
} |
168 |
|
169 |
if (selfirstPoint.getY() < sellastPoint.getY()) {
|
170 |
y1 = selfirstPoint.getY(); |
171 |
h1 = sellastPoint.getY() - selfirstPoint.getY(); |
172 |
} else {
|
173 |
y1 = sellastPoint.getY(); |
174 |
h1 = selfirstPoint.getY() - sellastPoint.getY(); |
175 |
} |
176 |
|
177 |
rect = new Rectangle2D.Double(x1, y1, w1, h1); |
178 |
} else
|
179 |
if (status.equals("Stretch.MoveFirstPoint")) { |
180 |
movefirstPoint = new Point2D.Double(x, y); |
181 |
} else
|
182 |
if (status.equals("Stretch.MoveLastPoint")) { |
183 |
VectorialLayerEdited vle = getVLE(); |
184 |
FeatureStore featureStore = null;
|
185 |
DisposableIterator iterator = null;
|
186 |
try {
|
187 |
featureStore = vle.getFeatureStore(); |
188 |
|
189 |
// VectorialEditableAdapter vea=vle.getVEA();
|
190 |
featureStore.beginEditingGroup(getName()); |
191 |
// ArrayList selectedRow=getSelectedRows();
|
192 |
// ArrayList selectedRowAux = new ArrayList();
|
193 |
// PluginServices.getMDIManager().setWaitCursor();
|
194 |
movelastPoint = new Point2D.Double(x, y); |
195 |
|
196 |
Handler[] handlers = null; |
197 |
|
198 |
// for (int i = selectedGeometries.nextSetBit(0); i
|
199 |
// >= 0;
|
200 |
// i = selectedGeometries.nextSetBit(i + 1)) {
|
201 |
iterator = |
202 |
((FeatureSelection) featureStore.getSelection()) |
203 |
.iterator(); |
204 |
while (iterator.hasNext()) {
|
205 |
Feature feature = (Feature) iterator.next(); |
206 |
|
207 |
// }
|
208 |
// for (int i =0;i<selectedRow.size(); i++) {
|
209 |
// IRowEdited edRow = (IRowEdited)
|
210 |
// selectedRow.get(i);
|
211 |
// DefaultFeature fea = (DefaultFeature)
|
212 |
// edRow.getLinkedRow().cloneRow();
|
213 |
Geometry geometry = null;
|
214 |
geometry = |
215 |
(feature.getDefaultGeometry()) |
216 |
.cloneGeometry(); |
217 |
|
218 |
handlers = |
219 |
geometry |
220 |
.getHandlers(Geometry.STRETCHINGHANDLER); |
221 |
|
222 |
for (int j = 0; j < handlers.length; j++) { |
223 |
if (rect.contains(handlers[j].getPoint())) {
|
224 |
handlers[j].move(movelastPoint.getX() |
225 |
- movefirstPoint.getX(), |
226 |
movelastPoint.getY() |
227 |
- movefirstPoint.getY()); |
228 |
} |
229 |
} |
230 |
EditableFeature eFeature = |
231 |
feature.getEditable(); |
232 |
eFeature.setGeometry(featureStore |
233 |
.getDefaultFeatureType() |
234 |
.getDefaultGeometryAttributeName(), |
235 |
geometry); |
236 |
// vea.modifyRow(edRow.getIndex(),fea,getName(),EditionEvent.GRAPHIC);
|
237 |
featureStore.update(eFeature); |
238 |
// selectedRowAux.add(feature);
|
239 |
} |
240 |
featureStore.endEditingGroup(); |
241 |
// vle.setSelectionCache(VectorialLayerEdited.NOTSAVEPREVIOUS,
|
242 |
// selectedRowAux);
|
243 |
|
244 |
// PluginServices.getMDIManager().restoreCursor();
|
245 |
} catch (DataException e) {
|
246 |
NotificationManager.addError(e.getMessage(), e); |
247 |
} finally {
|
248 |
if (iterator != null) { |
249 |
iterator.dispose(); |
250 |
} |
251 |
} |
252 |
} |
253 |
} |
254 |
|
255 |
/**
|
256 |
* M?todo para dibujar la lo necesario para el estado en el que nos
|
257 |
* encontremos.
|
258 |
*
|
259 |
* @param g
|
260 |
* Graphics sobre el que dibujar.
|
261 |
* @param x
|
262 |
* par?metro x del punto que se pase para dibujar.
|
263 |
* @param y
|
264 |
* par?metro x del punto que se pase para dibujar.
|
265 |
*/
|
266 |
public void drawOperation(MapControlDrawer renderer, double x, double y) { |
267 |
StretchCADToolState actualState = (_fsm).getState(); |
268 |
String status = actualState.getName();
|
269 |
|
270 |
// ArrayList selectedRow = getSelectedRows();
|
271 |
DisposableIterator iterator = null;
|
272 |
try {
|
273 |
iterator = |
274 |
((FeatureSelection) getVLE().getFeatureStore().getSelection()) |
275 |
.iterator(); |
276 |
if (status.equals("Stretch.SelLastPoint")) { |
277 |
GeneralPathX elShape = |
278 |
new GeneralPathX(GeneralPathX.WIND_EVEN_ODD, 4); |
279 |
elShape.moveTo(selfirstPoint.getX(), selfirstPoint.getY()); |
280 |
elShape.lineTo(x, selfirstPoint.getY()); |
281 |
elShape.lineTo(x, y); |
282 |
elShape.lineTo(selfirstPoint.getX(), y); |
283 |
elShape.lineTo(selfirstPoint.getX(), selfirstPoint.getY()); |
284 |
|
285 |
renderer.draw(createCurve(elShape), |
286 |
mapControlManager.getAxisReferenceSymbol()); |
287 |
} else
|
288 |
if (status.equals("Stretch.MoveFirstPoint")) { |
289 |
|
290 |
Handler[] handlers = null; |
291 |
while (iterator.hasNext()) {
|
292 |
Feature feature = (Feature) iterator.next(); |
293 |
|
294 |
Geometry geometry = null;
|
295 |
geometry = |
296 |
(feature.getDefaultGeometry()).cloneGeometry(); |
297 |
|
298 |
handlers = |
299 |
geometry.getHandlers(Geometry.STRETCHINGHANDLER); |
300 |
|
301 |
for (int j = 0; j < handlers.length; j++) { |
302 |
if (rect.contains(handlers[j].getPoint())) {
|
303 |
renderer.drawHandlers(handlers, |
304 |
getCadToolAdapter().getMapControl() |
305 |
.getViewPort().getAffineTransform(), |
306 |
mapControlManager.getHandlerSymbol()); |
307 |
} |
308 |
} |
309 |
} |
310 |
} else
|
311 |
if (status.equals("Stretch.MoveLastPoint")) { |
312 |
Handler[] handlers = null; |
313 |
while (iterator.hasNext()) {
|
314 |
Feature feature = (Feature) iterator.next(); |
315 |
// for (int i = 0;i<selectedRow.size();i++) {
|
316 |
// IRowEdited edRow = (IRowEdited)
|
317 |
// selectedRow.get(i);
|
318 |
// DefaultFeature fea = (DefaultFeature)
|
319 |
// edRow.getLinkedRow().cloneRow();
|
320 |
Geometry geometry = null;
|
321 |
geometry = |
322 |
(feature.getDefaultGeometry()).cloneGeometry(); |
323 |
|
324 |
handlers = |
325 |
geometry |
326 |
.getHandlers(Geometry.STRETCHINGHANDLER); |
327 |
|
328 |
for (int j = 0; j < handlers.length; j++) { |
329 |
if (rect.contains(handlers[j].getPoint())) {
|
330 |
handlers[j].move(x - movefirstPoint.getX(), |
331 |
y - movefirstPoint.getY()); |
332 |
} |
333 |
} |
334 |
renderer.draw(geometry, |
335 |
mapControlManager.getAxisReferenceSymbol()); |
336 |
} |
337 |
} |
338 |
} catch (DataException e) {
|
339 |
// TODO Auto-generated catch block
|
340 |
e.printStackTrace(); |
341 |
} finally {
|
342 |
if (iterator != null) { |
343 |
iterator.dispose(); |
344 |
} |
345 |
} |
346 |
|
347 |
} |
348 |
|
349 |
/**
|
350 |
* Add a diferent option.
|
351 |
*
|
352 |
* @param s
|
353 |
* Diferent option.
|
354 |
*/
|
355 |
public void addOption(String s) { |
356 |
} |
357 |
|
358 |
/*
|
359 |
* (non-Javadoc)
|
360 |
*
|
361 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
|
362 |
*/
|
363 |
public void addValue(double d) { |
364 |
} |
365 |
|
366 |
public String getName() { |
367 |
return PluginServices.getText(this, "stretch_"); |
368 |
} |
369 |
|
370 |
public String toString() { |
371 |
return "_stretch"; |
372 |
} |
373 |
|
374 |
@Override
|
375 |
protected int[] getSupportedGeometryTypes() { |
376 |
return new int[] { CURVE, SURFACE, AGGREGATE, MULTICURVE, |
377 |
MULTISURFACE, CIRCLE, ARC, ELLIPSE, SPLINE, ELLIPTICARC }; |
378 |
} |
379 |
} |