root / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / gui / cad / tools / ComplexSelectionCADTool.java @ 30788
History | View | Annotate | Download (21.3 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.Color; |
44 |
import java.awt.Graphics2D; |
45 |
import java.awt.Image; |
46 |
import java.awt.event.InputEvent; |
47 |
import java.awt.event.MouseEvent; |
48 |
import java.awt.geom.Point2D; |
49 |
import java.util.ArrayList; |
50 |
import java.util.List; |
51 |
|
52 |
import org.gvsig.andami.PluginServices; |
53 |
import org.gvsig.andami.messages.NotificationManager; |
54 |
import org.gvsig.app.project.documents.table.gui.FeatureTableDocumentPanel; |
55 |
import org.gvsig.editing.CADExtension; |
56 |
import org.gvsig.editing.gui.cad.DefaultCADTool; |
57 |
import org.gvsig.editing.gui.cad.exception.CommandException; |
58 |
import org.gvsig.editing.gui.cad.tools.smc.ComplexSelectionCADToolContext; |
59 |
import org.gvsig.editing.gui.cad.tools.smc.ComplexSelectionCADToolContext.ComplexSelectionCADToolState; |
60 |
import org.gvsig.editing.layers.VectorialLayerEdited; |
61 |
import org.gvsig.fmap.dal.exception.DataException; |
62 |
import org.gvsig.fmap.dal.exception.InitializeException; |
63 |
import org.gvsig.fmap.dal.exception.ReadException; |
64 |
import org.gvsig.fmap.dal.feature.DisposableIterator; |
65 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
66 |
import org.gvsig.fmap.dal.feature.Feature; |
67 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
68 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
69 |
import org.gvsig.fmap.dal.feature.FeatureType; |
70 |
import org.gvsig.fmap.geom.Geometry; |
71 |
import org.gvsig.fmap.geom.handler.Handler; |
72 |
import org.gvsig.fmap.geom.operation.Draw; |
73 |
import org.gvsig.fmap.geom.operation.DrawOperationContext; |
74 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
75 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
76 |
import org.gvsig.fmap.geom.primitive.Curve; |
77 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
78 |
import org.gvsig.fmap.mapcontext.ViewPort; |
79 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
80 |
import org.gvsig.fmap.mapcontrol.MapControl; |
81 |
import org.gvsig.fmap.mapcontrol.MapControlDrawer; |
82 |
|
83 |
|
84 |
/**
|
85 |
* DOCUMENT ME!
|
86 |
*
|
87 |
* @author Vicente Caballero Navarro
|
88 |
*/
|
89 |
public class ComplexSelectionCADTool extends SelectionCADTool { |
90 |
protected ComplexSelectionCADToolContext _fsm;
|
91 |
protected List pointsPolygon = new ArrayList(); |
92 |
|
93 |
/**
|
94 |
* Crea un nuevo ComplexSelectionCADTool.
|
95 |
*/
|
96 |
public ComplexSelectionCADTool() {
|
97 |
type = PluginServices.getText(this, "inside_circle"); |
98 |
} |
99 |
|
100 |
/**
|
101 |
* M?todo de incio, para poner el c?digo de todo lo que se requiera de una
|
102 |
* carga previa a la utilizaci?n de la herramienta.
|
103 |
*/
|
104 |
public void init() { |
105 |
_fsm = new ComplexSelectionCADToolContext(this); |
106 |
setNextTool("complex_selection");
|
107 |
|
108 |
setType(PluginServices.getText(this, "inside_circle")); |
109 |
} |
110 |
|
111 |
/**
|
112 |
* Equivale al transition del prototipo pero sin pasarle como par? metro el
|
113 |
* editableFeatureSource que ya estar? creado.
|
114 |
*
|
115 |
* @param selection
|
116 |
* Bitset con las geometr?as que est?n seleccionadas.
|
117 |
* @param x
|
118 |
* par?metro x del punto que se pase en esta transici?n.
|
119 |
* @param y
|
120 |
* par?metro y del punto que se pase en esta transici?n.
|
121 |
*/
|
122 |
public void addPoint(double x, double y, InputEvent event) { |
123 |
if (event != null && ((MouseEvent) event).getClickCount() == 2) { |
124 |
try {
|
125 |
pointDoubleClick(((MapControl) event.getComponent()) |
126 |
.getMapContext()); |
127 |
} catch (ReadException e) {
|
128 |
NotificationManager.addError(e.getMessage(), e); |
129 |
} |
130 |
return;
|
131 |
} |
132 |
ComplexSelectionCADToolState actualState = (ComplexSelectionCADToolState) _fsm |
133 |
.getPreviousState(); |
134 |
String status = actualState.getName();
|
135 |
System.out.println("PREVIOUSSTATE =" + status); // + "ESTADO ACTUAL: " + |
136 |
// _fsm.getState());
|
137 |
VectorialLayerEdited vle = getVLE(); |
138 |
FeatureStore featureStore = null;
|
139 |
try {
|
140 |
featureStore = vle.getFeatureStore(); |
141 |
} catch (ReadException e) {
|
142 |
// TODO Auto-generated catch block
|
143 |
e.printStackTrace(); |
144 |
} |
145 |
ArrayList selectedHandler = vle.getSelectedHandler();
|
146 |
System.out.println("STATUS ACTUAL = " + _fsm.getTransition()); |
147 |
if (status.equals("Selection.FirstPoint")) { |
148 |
firstPoint = new Point2D.Double(x, y); |
149 |
pointsPolygon.add(firstPoint); |
150 |
} else if (status.equals("Selection.SecondPoint")) { |
151 |
} else if (status.equals("Selection.WithFeatures")) { |
152 |
} else if (status.equals("Selection.WithHandlers")) { |
153 |
String description = PluginServices.getText(this, "move_handlers"); |
154 |
DisposableIterator iterator = null;
|
155 |
try {
|
156 |
featureStore.beginEditingGroup(description); |
157 |
ArrayList selectedRowsAux = new ArrayList(); |
158 |
|
159 |
iterator = ((FeatureSelection) featureStore.getSelection()) |
160 |
.iterator(); |
161 |
|
162 |
while (iterator.hasNext()) {
|
163 |
Feature feature = (Feature) iterator.next(); |
164 |
|
165 |
// }
|
166 |
Geometry ig = (feature.getDefaultGeometry()) |
167 |
.cloneGeometry(); |
168 |
// Movemos los handlers que hemos seleccionado
|
169 |
// previamente dentro del m?todo select()
|
170 |
Handler[] handlers = ig.getHandlers(Geometry.SELECTHANDLER); |
171 |
for (int k = 0; k < selectedHandler.size(); k++) { |
172 |
Handler h = (Handler) selectedHandler.get(k); |
173 |
for (int j = 0; j < handlers.length; j++) { |
174 |
if (h.getPoint().equals(handlers[j].getPoint())) {
|
175 |
handlers[j].set(x, y); |
176 |
} |
177 |
} |
178 |
} |
179 |
EditableFeature eFeature = feature.getEditable(); |
180 |
eFeature.setGeometry(featureStore.getDefaultFeatureType() |
181 |
.getDefaultGeometryAttributeName(), ig); |
182 |
featureStore.update(eFeature); |
183 |
selectedRowsAux.add(eFeature); |
184 |
} |
185 |
|
186 |
firstPoint = new Point2D.Double(x, y); |
187 |
// vle.setSelectionCache(VectorialLayerEdited.SAVEPREVIOUS,
|
188 |
// selectedRowsAux);
|
189 |
|
190 |
featureStore.endEditingGroup(); |
191 |
} catch (DataException e1) {
|
192 |
// TODO Auto-generated catch block
|
193 |
e1.printStackTrace(); |
194 |
} finally {
|
195 |
if (iterator != null) { |
196 |
iterator.dispose(); |
197 |
} |
198 |
} |
199 |
|
200 |
} else if (status.equals("Selection.NextPointPolygon")) { |
201 |
pointsPolygon.add(new Point2D.Double(x, y)); |
202 |
} |
203 |
} |
204 |
|
205 |
/**
|
206 |
* Receives second point
|
207 |
*
|
208 |
* @param x
|
209 |
* @param y
|
210 |
* @return numFeatures selected
|
211 |
*/
|
212 |
public long selectWithSecondPointOutRectangle(double x, double y, |
213 |
InputEvent event) {
|
214 |
Point2D lastPoint = new Point2D.Double(x, y); |
215 |
GeneralPathX gpx = new GeneralPathX();
|
216 |
gpx.moveTo(firstPoint.getX(), firstPoint.getY()); |
217 |
gpx.lineTo(lastPoint.getX(), firstPoint.getY()); |
218 |
gpx.lineTo(lastPoint.getX(), lastPoint.getY()); |
219 |
gpx.lineTo(firstPoint.getX(), lastPoint.getY()); |
220 |
gpx.closePath(); |
221 |
Geometry rectangle = createSurface(gpx); |
222 |
return selectWithPolygon(rectangle);
|
223 |
} |
224 |
|
225 |
/**
|
226 |
* Receives second point
|
227 |
*
|
228 |
* @param x
|
229 |
* @param y
|
230 |
* @return numFeatures selected
|
231 |
*/
|
232 |
public long selectWithCircle(double x, double y, InputEvent event) { |
233 |
Geometry circle = createCircle(firstPoint, |
234 |
new Point2D.Double(x, y)); |
235 |
return selectWithPolygon(circle);
|
236 |
} |
237 |
|
238 |
public long selectWithPolygon(Geometry polygon) { |
239 |
VectorialLayerEdited vle = getVLE(); |
240 |
PluginServices.getMDIManager().setWaitCursor(); |
241 |
|
242 |
if (getType().equals(PluginServices.getText(this, "inside_circle")) |
243 |
|| getType().equals( |
244 |
PluginServices.getText(this, "inside_polygon"))) { |
245 |
vle.selectInsidePolygon(polygon); |
246 |
} else if (getType().equals( |
247 |
PluginServices.getText(this, "cross_circle")) |
248 |
|| getType().equals( |
249 |
PluginServices.getText(this, "cross_polygon"))) { |
250 |
vle.selectCrossPolygon(polygon); |
251 |
} else if (getType().equals(PluginServices.getText(this, "out_circle")) |
252 |
|| getType() |
253 |
.equals(PluginServices.getText(this, "out_polygon")) |
254 |
|| getType().equals( |
255 |
PluginServices.getText(this, "out_rectangle"))) { |
256 |
vle.selectOutPolygon(polygon); |
257 |
} |
258 |
long countSelection = 0; |
259 |
try {
|
260 |
countSelection = ((FeatureSelection) vle.getFeatureStore() |
261 |
.getSelection()).getSize(); |
262 |
} catch (ReadException e) {
|
263 |
// TODO Auto-generated catch block
|
264 |
e.printStackTrace(); |
265 |
} catch (DataException e) {
|
266 |
// TODO Auto-generated catch block
|
267 |
e.printStackTrace(); |
268 |
} |
269 |
PluginServices.getMDIManager().restoreCursor(); |
270 |
if (countSelection > 0) { |
271 |
nextState = "Selection.WithSelectedFeatures";
|
272 |
end(); |
273 |
} else {
|
274 |
nextState = "Selection.FirstPoint";
|
275 |
} |
276 |
return countSelection;
|
277 |
} |
278 |
|
279 |
/**
|
280 |
* M?todo para dibujar la lo necesario para el estado en el que nos
|
281 |
* encontremos.
|
282 |
*
|
283 |
* @param g
|
284 |
* Graphics sobre el que dibujar.
|
285 |
* @param selectedGeometries
|
286 |
* BitSet con las geometr?as seleccionadas.
|
287 |
* @param x
|
288 |
* par?metro x del punto que se pase para dibujar.
|
289 |
* @param y
|
290 |
* par?metro x del punto que se pase para dibujar.
|
291 |
*/
|
292 |
public void drawOperation(MapControlDrawer renderer, double x, double y) { |
293 |
ComplexSelectionCADToolState actualState = _fsm.getState(); |
294 |
String status = actualState.getName();
|
295 |
VectorialLayerEdited vle = getVLE(); |
296 |
ArrayList selectedHandler = vle.getSelectedHandler();
|
297 |
ViewPort vp = vle.getLayer().getMapContext().getViewPort(); |
298 |
if (status.equals("Selection.SecondPoint") |
299 |
|| status.equals("Selection.SecondPointOutRectangle")) {
|
300 |
// Dibuja el rect?ngulo de selecci?n
|
301 |
GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD,
|
302 |
4);
|
303 |
elShape.moveTo(firstPoint.getX(), firstPoint.getY()); |
304 |
elShape.lineTo(x, firstPoint.getY()); |
305 |
elShape.lineTo(x, y); |
306 |
elShape.lineTo(firstPoint.getX(), y); |
307 |
elShape.lineTo(firstPoint.getX(), firstPoint.getY()); |
308 |
|
309 |
renderer.draw(createCurve(elShape), mapControlManager.getGeometrySelectionSymbol()); |
310 |
|
311 |
return;
|
312 |
} |
313 |
if (status.equals("Selection.SecondPointCircle")) { |
314 |
Geometry circle = createCircle(firstPoint, |
315 |
new Point2D.Double(x, y)); |
316 |
GeneralPathX gpx = new GeneralPathX();
|
317 |
gpx.append(circle.getInternalShape().getPathIterator(null), true); |
318 |
Geometry circleSel = createCurve(gpx); |
319 |
// Dibuja el c?rculo de selecci?n
|
320 |
renderer.draw(circleSel, mapControlManager.getGeometrySelectionSymbol()); |
321 |
|
322 |
return;
|
323 |
} else if (status.equals("Selection.NextPointPolygon")) { |
324 |
// Dibuja el pol?gono de selecci?n
|
325 |
Geometry polygon = getGeometryPolygon(new Point2D.Double(x, y)); |
326 |
renderer.draw(polygon, mapControlManager.getGeometrySelectionSymbol()); |
327 |
|
328 |
return;
|
329 |
} else if (status.equals("Selection.WithHandlers")) { |
330 |
// Movemos los handlers que hemos seleccionado
|
331 |
// previamente dentro del m?todo select()
|
332 |
double xPrev = 0; |
333 |
double yPrev = 0; |
334 |
for (int k = 0; k < selectedHandler.size(); k++) { |
335 |
Handler h = (Handler) selectedHandler.get(k); |
336 |
xPrev = h.getPoint().getX(); |
337 |
yPrev = h.getPoint().getY(); |
338 |
h.set(x, y); |
339 |
} |
340 |
// Y una vez movidos los v?rtices (handles)
|
341 |
// redibujamos la nueva geometr?a.
|
342 |
for (int i = 0; i < rowselectedHandlers.size(); i++) { |
343 |
Feature rowEd = (Feature) rowselectedHandlers.get(i); |
344 |
Geometry geom = (rowEd.getDefaultGeometry()) |
345 |
.cloneGeometry(); |
346 |
renderer.setColor(Color.gray);
|
347 |
renderer.draw(geom, mapControlManager.getAxisReferenceSymbol()); |
348 |
} |
349 |
for (int k = 0; k < selectedHandler.size(); k++) { |
350 |
Handler h = (Handler) selectedHandler.get(k); |
351 |
h.set(xPrev, yPrev); |
352 |
} |
353 |
return;
|
354 |
} |
355 |
} |
356 |
|
357 |
/**
|
358 |
* Add a diferent option.
|
359 |
*
|
360 |
* @param sel
|
361 |
* DOCUMENT ME!
|
362 |
* @param s
|
363 |
* Diferent option.
|
364 |
*/
|
365 |
public void addOption(String s) { |
366 |
ComplexSelectionCADToolState actualState = (ComplexSelectionCADToolState) _fsm |
367 |
.getPreviousState(); |
368 |
String status = actualState.getName();
|
369 |
System.out.println("PREVIOUSSTATE =" + status); // + "ESTADO ACTUAL: " + |
370 |
// _fsm.getState());
|
371 |
System.out.println("STATUS ACTUAL = " + _fsm.getTransition()); |
372 |
if (s.equals(PluginServices.getText(this, "cancel"))) { |
373 |
init(); |
374 |
return;
|
375 |
} else if (s.equals(PluginServices.getText(this, "select_all"))) { |
376 |
selectAll(); |
377 |
init(); |
378 |
return;
|
379 |
} |
380 |
if (status.equals("Selection.FirstPoint")) { |
381 |
setType(s); |
382 |
return;
|
383 |
} else if (status.equals("Selection.NextPointPolygon")) { |
384 |
if (s.equals(PluginServices.getText(this, "end_polygon")) |
385 |
|| s.equalsIgnoreCase(PluginServices.getText(this,
|
386 |
"ComplexSelectionCADTool.end"))) {
|
387 |
Geometry polygon = getGeometryPolygon(null);
|
388 |
GeneralPathX gpx = new GeneralPathX();
|
389 |
gpx.append(polygon.getPathIterator(null), true); |
390 |
if (gpx.isCCW()) {
|
391 |
gpx.flip(); |
392 |
polygon = createSurface(gpx); |
393 |
} |
394 |
selectWithPolygon(polygon); |
395 |
pointsPolygon.clear(); |
396 |
setType(PluginServices.getText(this, "inside_circle")); |
397 |
return;
|
398 |
} |
399 |
} |
400 |
init(); |
401 |
} |
402 |
|
403 |
private long selectAll() { |
404 |
VectorialLayerEdited vle = getVLE(); |
405 |
PluginServices.getMDIManager().setWaitCursor(); |
406 |
vle.selectAll(); |
407 |
long countSelection = 0; |
408 |
try {
|
409 |
countSelection = ((FeatureSelection) vle.getFeatureStore() |
410 |
.getSelection()).getSize(); |
411 |
} catch (ReadException e) {
|
412 |
// TODO Auto-generated catch block
|
413 |
e.printStackTrace(); |
414 |
} catch (DataException e) {
|
415 |
// TODO Auto-generated catch block
|
416 |
e.printStackTrace(); |
417 |
} |
418 |
PluginServices.getMDIManager().restoreCursor(); |
419 |
if (countSelection > 0) { |
420 |
nextState = "Selection.WithSelectedFeatures";
|
421 |
} else {
|
422 |
nextState = "Selection.FirstPoint";
|
423 |
} |
424 |
end(); |
425 |
return countSelection;
|
426 |
} |
427 |
|
428 |
private Geometry getGeometryPolygon(Point2D p) { |
429 |
Point2D[] points = (Point2D[]) pointsPolygon.toArray(new Point2D[0]); |
430 |
GeneralPathX gpx = new GeneralPathX();
|
431 |
for (int i = 0; i < points.length; i++) { |
432 |
if (i == 0) { |
433 |
gpx.moveTo(points[i].getX(), points[i].getY()); |
434 |
} else {
|
435 |
gpx.lineTo(points[i].getX(), points[i].getY()); |
436 |
} |
437 |
} |
438 |
if (p != null) { |
439 |
gpx.lineTo(p.getX(), p.getY()); |
440 |
gpx.closePath(); |
441 |
Geometry polyline = createCurve(gpx); |
442 |
return polyline;
|
443 |
} |
444 |
gpx.closePath(); |
445 |
Geometry polygon = createSurface(gpx); |
446 |
return polygon;
|
447 |
} |
448 |
|
449 |
/*
|
450 |
* (non-Javadoc)
|
451 |
*
|
452 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
|
453 |
*/
|
454 |
public void addValue(double d) { |
455 |
} |
456 |
|
457 |
public void end() { |
458 |
if (!getNextTool().equals("complex_selection")) { |
459 |
CADExtension.setCADTool(getNextTool(), false);
|
460 |
} |
461 |
} |
462 |
|
463 |
public String getName() { |
464 |
return PluginServices.getText(this, "complex_selection_"); |
465 |
} |
466 |
|
467 |
public boolean selectFeatures(double x, double y, InputEvent event) { |
468 |
ComplexSelectionCADToolState actualState = _fsm.getState(); |
469 |
|
470 |
String status = actualState.getName();
|
471 |
VectorialLayerEdited vle = getVLE(); |
472 |
|
473 |
if ((status.equals("Selection.FirstPoint")) |
474 |
|| (status.equals("Selection.WithSelectedFeatures"))) {
|
475 |
PluginServices.getMDIManager().setWaitCursor(); |
476 |
firstPoint = new Point2D.Double(x, y); |
477 |
vle.selectWithPoint(x, y, multipleSelection); |
478 |
PluginServices.getMDIManager().restoreCursor(); |
479 |
} |
480 |
long countSelection = 0; |
481 |
try {
|
482 |
countSelection = ((FeatureSelection) vle.getFeatureStore() |
483 |
.getSelection()).getSize(); |
484 |
} catch (ReadException e) {
|
485 |
// TODO Auto-generated catch block
|
486 |
e.printStackTrace(); |
487 |
} catch (DataException e) {
|
488 |
// TODO Auto-generated catch block
|
489 |
e.printStackTrace(); |
490 |
} |
491 |
if (countSelection > 0) { |
492 |
nextState = "Selection.WithSelectedFeatures";
|
493 |
return true; |
494 |
} else {
|
495 |
{ |
496 |
nextState = "Selection.SecondPoint";
|
497 |
return true; |
498 |
} |
499 |
} |
500 |
} |
501 |
|
502 |
public int selectHandlers(double x, double y, InputEvent event) { |
503 |
Point2D auxPoint = new Point2D.Double(x, y); |
504 |
|
505 |
VectorialLayerEdited vle = getVLE(); |
506 |
ArrayList selectedHandler = vle.getSelectedHandler();
|
507 |
selectedHandler.clear(); |
508 |
|
509 |
// Se comprueba si se pincha en una gemometr?a
|
510 |
PluginServices.getMDIManager().setWaitCursor(); |
511 |
|
512 |
double tam = getCadToolAdapter().getMapControl().getViewPort()
|
513 |
.toMapDistance(mapControlManager.getTolerance()); |
514 |
|
515 |
Handler[] handlers = null; |
516 |
rowselectedHandlers.clear(); |
517 |
FeatureStore featureStore = null;
|
518 |
try {
|
519 |
featureStore = vle.getFeatureStore(); |
520 |
} catch (ReadException e) {
|
521 |
// TODO Auto-generated catch block
|
522 |
e.printStackTrace(); |
523 |
} |
524 |
DisposableIterator iterator = null;
|
525 |
try {
|
526 |
iterator = ((FeatureSelection) featureStore.getSelection()) |
527 |
.iterator(); |
528 |
while (iterator.hasNext()) {
|
529 |
Feature feature = (Feature) iterator.next(); |
530 |
|
531 |
Geometry geom = (feature.getDefaultGeometry()).cloneGeometry(); |
532 |
handlers = geom.getHandlers(Geometry.SELECTHANDLER); |
533 |
// y miramos los handlers de cada entidad seleccionada
|
534 |
double min = tam;
|
535 |
|
536 |
for (int j = 0; j < handlers.length; j++) { |
537 |
Point2D handlerPoint = handlers[j].getPoint();
|
538 |
double distance = auxPoint.distance(handlerPoint);
|
539 |
if (distance <= min) {
|
540 |
min = distance; |
541 |
selectedHandler.add(handlers[j]); |
542 |
EditableFeature eFeature; |
543 |
try {
|
544 |
eFeature = featureStore.createNewFeature(false);
|
545 |
FeatureType featureType = featureStore |
546 |
.getDefaultFeatureType(); |
547 |
for (int i = 0; i < featureType.size(); i++) { |
548 |
eFeature.set(i, feature.get(i)); |
549 |
} |
550 |
eFeature.setGeometry(featureType |
551 |
.getDefaultGeometryAttributeName(), geom); |
552 |
} catch (InitializeException e) {
|
553 |
// TODO Auto-generated catch block
|
554 |
e.printStackTrace(); |
555 |
} catch (DataException e) {
|
556 |
// TODO Auto-generated catch block
|
557 |
e.printStackTrace(); |
558 |
} |
559 |
rowselectedHandlers.add(feature); |
560 |
} |
561 |
} |
562 |
} |
563 |
} catch (DataException e1) {
|
564 |
// TODO Auto-generated catch block
|
565 |
e1.printStackTrace(); |
566 |
} finally {
|
567 |
if (iterator != null) { |
568 |
iterator.dispose(); |
569 |
} |
570 |
} |
571 |
|
572 |
PluginServices.getMDIManager().restoreCursor(); |
573 |
|
574 |
int numHandlesSelected = selectedHandler.size();
|
575 |
|
576 |
/*
|
577 |
* if (numHandlesSelected == 0) selectFeatures(x,y);
|
578 |
*/
|
579 |
|
580 |
return numHandlesSelected;
|
581 |
} |
582 |
|
583 |
public String getType() { |
584 |
return type;
|
585 |
} |
586 |
|
587 |
public void setType(String type) { |
588 |
if (type.equalsIgnoreCase(PluginServices.getText(this, |
589 |
"ComplexSelectionCADTool.outrectangle"))) {
|
590 |
this.type = PluginServices.getText(this, "out_rectangle"); |
591 |
} else if (type.equalsIgnoreCase(PluginServices.getText(this, |
592 |
"ComplexSelectionCADTool.intropolygon"))) {
|
593 |
this.type = PluginServices.getText(this, "inside_polygon"); |
594 |
} else if (type.equalsIgnoreCase(PluginServices.getText(this, |
595 |
"ComplexSelectionCADTool.crosspolygon"))) {
|
596 |
this.type = PluginServices.getText(this, "cross_polygon"); |
597 |
} else if (type.equalsIgnoreCase(PluginServices.getText(this, |
598 |
"ComplexSelectionCADTool.outpolygon"))) {
|
599 |
this.type = PluginServices.getText(this, "out_polygon"); |
600 |
} else if (type.equalsIgnoreCase(PluginServices.getText(this, |
601 |
"ComplexSelectionCADTool.introcircle"))) {
|
602 |
this.type = PluginServices.getText(this, "inside_circle"); |
603 |
} else if (type.equalsIgnoreCase(PluginServices.getText(this, |
604 |
"ComplexSelectionCADTool.crosscircle"))) {
|
605 |
this.type = PluginServices.getText(this, "cross_circle"); |
606 |
} else if (type.equalsIgnoreCase(PluginServices.getText(this, |
607 |
"ComplexSelectionCADTool.outcircle"))) {
|
608 |
this.type = PluginServices.getText(this, "out_circle"); |
609 |
} else if (type.equals(PluginServices.getText(this, "select_all"))) { |
610 |
selectAll(); |
611 |
init(); |
612 |
} else {
|
613 |
this.type = type;
|
614 |
} |
615 |
pointsPolygon.clear(); |
616 |
} |
617 |
|
618 |
/*
|
619 |
* (non-Javadoc)
|
620 |
*
|
621 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet,
|
622 |
* double, double)
|
623 |
*/
|
624 |
public void transition(double x, double y, InputEvent event) { |
625 |
System.out.println("TRANSICION DESDE ESTADO " + _fsm.getState() |
626 |
+ " x= " + x + " y=" + y); |
627 |
try {
|
628 |
_fsm.addPoint(x, y, event); |
629 |
} catch (Exception e) { |
630 |
init(); |
631 |
} |
632 |
System.out.println("ESTADO ACTUAL: " + getStatus()); |
633 |
|
634 |
FLyrVect lv = (FLyrVect) ((VectorialLayerEdited) CADExtension |
635 |
.getEditionManager().getActiveLayerEdited()).getLayer(); |
636 |
org.gvsig.andami.ui.mdiManager.IWindow[] views = PluginServices
|
637 |
.getMDIManager().getAllWindows(); |
638 |
|
639 |
for (int i = 0; i < views.length; i++) { |
640 |
if (views[i] instanceof FeatureTableDocumentPanel) { |
641 |
FeatureTableDocumentPanel table = (FeatureTableDocumentPanel) views[i]; |
642 |
if (table.getModel().getAssociatedLayer() != null |
643 |
&& table.getModel().getAssociatedLayer().equals(lv)) { |
644 |
table.updateSelection(); |
645 |
} |
646 |
} |
647 |
} |
648 |
} |
649 |
|
650 |
public String getStatus() { |
651 |
try {
|
652 |
ComplexSelectionCADToolState actualState = (ComplexSelectionCADToolState) _fsm |
653 |
.getPreviousState(); |
654 |
String status = actualState.getName();
|
655 |
|
656 |
return status;
|
657 |
} catch (NullPointerException e) { |
658 |
return "Selection.FirstPoint"; |
659 |
} |
660 |
} |
661 |
|
662 |
/*
|
663 |
* (non-Javadoc)
|
664 |
*
|
665 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet,
|
666 |
* java.lang.String)
|
667 |
*/
|
668 |
public void transition(String s) throws CommandException { |
669 |
if (!super.changeCommand(s)) { |
670 |
|
671 |
_fsm.addOption(s); |
672 |
|
673 |
} |
674 |
} |
675 |
|
676 |
/*
|
677 |
* (non-Javadoc)
|
678 |
*
|
679 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet,
|
680 |
* double)
|
681 |
*/
|
682 |
public void transition(double d) { |
683 |
_fsm.addValue(d); |
684 |
} |
685 |
|
686 |
public String toString() { |
687 |
return "_complex_selection"; |
688 |
} |
689 |
|
690 |
public String getNextState() { |
691 |
return nextState;
|
692 |
} |
693 |
|
694 |
} |