svn-gvsig-desktop / tags / v1_0_2_Build_900 / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / tools / ComplexSelectionCADTool.java @ 10562
History | View | Annotate | Download (18.3 KB)
1 | 5207 | 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 | package com.iver.cit.gvsig.gui.cad.tools; |
||
42 | |||
43 | import java.awt.Color; |
||
44 | import java.awt.Graphics; |
||
45 | import java.awt.Graphics2D; |
||
46 | import java.awt.Image; |
||
47 | import java.awt.event.InputEvent; |
||
48 | import java.awt.event.MouseEvent; |
||
49 | import java.awt.geom.Point2D; |
||
50 | import java.io.IOException; |
||
51 | import java.util.ArrayList; |
||
52 | |||
53 | import com.iver.andami.PluginServices; |
||
54 | import com.iver.cit.gvsig.CADExtension; |
||
55 | import com.iver.cit.gvsig.fmap.MapControl; |
||
56 | import com.iver.cit.gvsig.fmap.ViewPort; |
||
57 | import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
||
58 | import com.iver.cit.gvsig.fmap.core.Handler; |
||
59 | import com.iver.cit.gvsig.fmap.core.IFeature; |
||
60 | import com.iver.cit.gvsig.fmap.core.IGeometry; |
||
61 | import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
||
62 | import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
||
63 | 6474 | caballero | import com.iver.cit.gvsig.fmap.edition.DefaultRowEdited; |
64 | 5207 | caballero | import com.iver.cit.gvsig.fmap.edition.IRowEdited; |
65 | import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter; |
||
66 | 6474 | caballero | import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
67 | 5207 | caballero | import com.iver.cit.gvsig.gui.cad.CADTool; |
68 | 5735 | caballero | import com.iver.cit.gvsig.gui.cad.exception.CommandException; |
69 | 5207 | caballero | import com.iver.cit.gvsig.gui.cad.tools.smc.ComplexSelectionCADToolContext; |
70 | import com.iver.cit.gvsig.gui.cad.tools.smc.ComplexSelectionCADToolContext.ComplexSelectionCADToolState; |
||
71 | import com.iver.cit.gvsig.layers.VectorialLayerEdited; |
||
72 | 8765 | jjdelcerro | import com.iver.cit.gvsig.project.documents.table.gui.Table; |
73 | 5207 | caballero | |
74 | /**
|
||
75 | * DOCUMENT ME!
|
||
76 | *
|
||
77 | * @author Vicente Caballero Navarro
|
||
78 | */
|
||
79 | public class ComplexSelectionCADTool extends SelectionCADTool { |
||
80 | //public final static int tolerance = 4;
|
||
81 | |||
82 | private ComplexSelectionCADToolContext _fsm;
|
||
83 | |||
84 | //private Point2D firstPoint;
|
||
85 | |||
86 | //private Point2D lastPoint;
|
||
87 | |||
88 | |||
89 | |||
90 | //private String nextState;
|
||
91 | // Registros de los que se ha sleccionado alg?n handler.
|
||
92 | //private ArrayList rowselectedHandlers=new ArrayList();
|
||
93 | //private String type=PluginServices.getText(this,"inside_circle");
|
||
94 | //private ArrayList pointsPolygon=new ArrayList();
|
||
95 | /**
|
||
96 | * Crea un nuevo ComplexSelectionCADTool.
|
||
97 | */
|
||
98 | public ComplexSelectionCADTool() {
|
||
99 | type=PluginServices.getText(this,"inside_circle"); |
||
100 | } |
||
101 | |||
102 | /**
|
||
103 | * M?todo de incio, para poner el c?digo de todo lo que se requiera de una
|
||
104 | * carga previa a la utilizaci?n de la herramienta.
|
||
105 | */
|
||
106 | public void init() { |
||
107 | _fsm = new ComplexSelectionCADToolContext(this); |
||
108 | setNextTool("complex_selection");
|
||
109 | |||
110 | setType(PluginServices.getText(this,"inside_circle")); |
||
111 | } |
||
112 | |||
113 | /**
|
||
114 | * Equivale al transition del prototipo pero sin pasarle como par? metro el
|
||
115 | * editableFeatureSource que ya estar? creado.
|
||
116 | *
|
||
117 | * @param selection
|
||
118 | * Bitset con las geometr?as que est?n seleccionadas.
|
||
119 | * @param x
|
||
120 | * par?metro x del punto que se pase en esta transici?n.
|
||
121 | * @param y
|
||
122 | * par?metro y del punto que se pase en esta transici?n.
|
||
123 | */
|
||
124 | public void addPoint(double x, double y, InputEvent event) { |
||
125 | 5225 | caballero | if (event!=null && ((MouseEvent)event).getClickCount()==2){ |
126 | 5207 | caballero | pointDoubleClick((MapControl)event.getComponent()); |
127 | return;
|
||
128 | } |
||
129 | ComplexSelectionCADToolState actualState = (ComplexSelectionCADToolState) _fsm |
||
130 | .getPreviousState(); |
||
131 | String status = actualState.getName();
|
||
132 | System.out.println("PREVIOUSSTATE =" + status); // + "ESTADO ACTUAL: " + |
||
133 | // _fsm.getState());
|
||
134 | VectorialLayerEdited vle = getVLE(); |
||
135 | VectorialEditableAdapter vea=vle.getVEA(); |
||
136 | ArrayList selectedHandler = vle.getSelectedHandler();
|
||
137 | ArrayList selectedRow = vle.getSelectedRow();
|
||
138 | System.out.println("STATUS ACTUAL = " + _fsm.getTransition()); |
||
139 | if (status.equals("Selection.FirstPoint")) { |
||
140 | firstPoint=new Point2D.Double(x,y); |
||
141 | pointsPolygon.add(firstPoint); |
||
142 | } else if (status.equals("Selection.SecondPoint")) { |
||
143 | } else if (status.equals("Selection.WithFeatures")) { |
||
144 | } else if (status.equals("Selection.WithHandlers")) { |
||
145 | vea.startComplexRow(); |
||
146 | 6474 | caballero | ArrayList selectedRowsAux=new ArrayList(); |
147 | 5207 | caballero | for (int i = 0; i < selectedRow.size(); i++) { |
148 | IRowEdited row = (IRowEdited) selectedRow.get(i); |
||
149 | 6474 | caballero | IFeature feat = (IFeature) row.getLinkedRow().cloneRow(); |
150 | 5207 | caballero | // Movemos los handlers que hemos seleccionado
|
151 | // previamente dentro del m?todo select()
|
||
152 | for (int k = 0; k < selectedHandler.size(); k++) { |
||
153 | Handler h = (Handler) selectedHandler.get(k); |
||
154 | h.set(x, y); |
||
155 | } |
||
156 | |||
157 | 6474 | caballero | modifyFeature(row.getIndex(), feat); |
158 | selectedRowsAux.add(new DefaultRowEdited(feat,IRowEdited.STATUS_MODIFIED,row.getIndex()));
|
||
159 | 5207 | caballero | } |
160 | 6474 | caballero | firstPoint=new Point2D.Double(x,y); |
161 | vle.setSelectionCache(selectedRowsAux); |
||
162 | 5207 | caballero | try {
|
163 | 6071 | caballero | String description=PluginServices.getText(this,"move_handlers"); |
164 | vea.endComplexRow(description); |
||
165 | 5207 | caballero | } catch (IOException e) { |
166 | e.printStackTrace(); |
||
167 | } catch (DriverIOException e) {
|
||
168 | e.printStackTrace(); |
||
169 | } |
||
170 | }else if (status.equals("Selection.NextPointPolygon")) { |
||
171 | pointsPolygon.add(new Point2D.Double(x,y)); |
||
172 | } |
||
173 | } |
||
174 | |||
175 | /**
|
||
176 | * Receives second point
|
||
177 | * @param x
|
||
178 | * @param y
|
||
179 | * @return numFeatures selected
|
||
180 | */
|
||
181 | public int selectWithSecondPointOutRectangle(double x, double y, InputEvent event) { |
||
182 | Point2D lastPoint=new Point2D.Double(x,y); |
||
183 | GeneralPathX gpx=new GeneralPathX();
|
||
184 | gpx.moveTo(firstPoint.getX(),firstPoint.getY()); |
||
185 | gpx.lineTo(lastPoint.getX(),firstPoint.getY()); |
||
186 | gpx.lineTo(lastPoint.getX(),lastPoint.getY()); |
||
187 | gpx.lineTo(firstPoint.getX(),lastPoint.getY()); |
||
188 | gpx.closePath(); |
||
189 | IGeometry rectangle=ShapeFactory.createPolygon2D(gpx); |
||
190 | return selectWithPolygon(rectangle);
|
||
191 | } |
||
192 | /**
|
||
193 | * Receives second point
|
||
194 | * @param x
|
||
195 | * @param y
|
||
196 | * @return numFeatures selected
|
||
197 | */
|
||
198 | public int selectWithCircle(double x, double y, InputEvent event) { |
||
199 | IGeometry circle=ShapeFactory.createCircle(firstPoint,new Point2D.Double(x,y)); |
||
200 | return selectWithPolygon(circle);
|
||
201 | } |
||
202 | public int selectWithPolygon(IGeometry polygon) { |
||
203 | VectorialLayerEdited vle = getVLE(); |
||
204 | PluginServices.getMDIManager().setWaitCursor(); |
||
205 | |||
206 | if (getType().equals(PluginServices.getText(this,"inside_circle")) || getType().equals(PluginServices.getText(this,"inside_polygon"))) { |
||
207 | vle.selectInsidePolygon(polygon); |
||
208 | } else if (getType().equals(PluginServices.getText(this,"cross_circle")) || getType().equals(PluginServices.getText(this,"cross_polygon"))) { |
||
209 | vle.selectCrossPolygon(polygon); |
||
210 | } else if (getType().equals(PluginServices.getText(this,"out_circle")) || getType().equals(PluginServices.getText(this,"out_polygon")) || getType().equals(PluginServices.getText(this,"out_rectangle"))) { |
||
211 | vle.selectOutPolygon(polygon); |
||
212 | } |
||
213 | ArrayList selectedRow = vle.getSelectedRow();
|
||
214 | PluginServices.getMDIManager().restoreCursor(); |
||
215 | if (selectedRow.size() > 0) { |
||
216 | nextState = "Selection.WithSelectedFeatures";
|
||
217 | end(); |
||
218 | } else
|
||
219 | nextState = "Selection.FirstPoint";
|
||
220 | return selectedRow.size();
|
||
221 | } |
||
222 | |||
223 | /**
|
||
224 | * M?todo para dibujar la lo necesario para el estado en el que nos
|
||
225 | * encontremos.
|
||
226 | *
|
||
227 | * @param g
|
||
228 | * Graphics sobre el que dibujar.
|
||
229 | * @param selectedGeometries
|
||
230 | * BitSet con las geometr?as seleccionadas.
|
||
231 | * @param x
|
||
232 | * par?metro x del punto que se pase para dibujar.
|
||
233 | * @param y
|
||
234 | * par?metro x del punto que se pase para dibujar.
|
||
235 | */
|
||
236 | public void drawOperation(Graphics g, double x, double y) { |
||
237 | ComplexSelectionCADToolState actualState = _fsm.getState(); |
||
238 | String status = actualState.getName();
|
||
239 | VectorialLayerEdited vle = getVLE(); |
||
240 | ArrayList selectedHandler = vle.getSelectedHandler();
|
||
241 | 6881 | cesar | ViewPort vp=vle.getLayer().getMapContext().getViewPort(); |
242 | 5207 | caballero | if (status.equals("Selection.SecondPoint") || status.equals("Selection.SecondPointOutRectangle")) { |
243 | // Dibuja el rect?ngulo de selecci?n
|
||
244 | GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD,
|
||
245 | 4);
|
||
246 | elShape.moveTo(firstPoint.getX(), firstPoint.getY()); |
||
247 | elShape.lineTo(x, firstPoint.getY()); |
||
248 | elShape.lineTo(x, y); |
||
249 | elShape.lineTo(firstPoint.getX(), y); |
||
250 | elShape.lineTo(firstPoint.getX(), firstPoint.getY()); |
||
251 | ShapeFactory.createPolyline2D(elShape).draw((Graphics2D) g,
|
||
252 | vp, |
||
253 | CADTool.selectSymbol); |
||
254 | Image img = vle.getSelectionImage();
|
||
255 | g.drawImage(img, 0, 0, null); |
||
256 | return;
|
||
257 | }if (status.equals("Selection.SecondPointCircle")) { |
||
258 | 6193 | caballero | IGeometry circle=ShapeFactory.createCircle(firstPoint,new Point2D.Double(x,y)); |
259 | GeneralPathX gpx=new GeneralPathX();
|
||
260 | gpx.append(circle.getInternalShape(),true);
|
||
261 | IGeometry circleSel=ShapeFactory.createPolyline2D(gpx); |
||
262 | 5207 | caballero | // Dibuja el c?rculo de selecci?n
|
263 | 6193 | caballero | circleSel.draw((Graphics2D) g,
|
264 | 5207 | caballero | vp, |
265 | CADTool.selectSymbol); |
||
266 | Image img = vle.getSelectionImage();
|
||
267 | g.drawImage(img, 0, 0, null); |
||
268 | return;
|
||
269 | }else if (status.equals("Selection.NextPointPolygon")) { |
||
270 | // Dibuja el pol?gono de selecci?n
|
||
271 | IGeometry polygon=getGeometryPolygon(new Point2D.Double(x,y)); |
||
272 | polygon.draw((Graphics2D) g,
|
||
273 | vp, |
||
274 | CADTool.selectSymbol); |
||
275 | Image img = vle.getSelectionImage();
|
||
276 | g.drawImage(img, 0, 0, null); |
||
277 | return;
|
||
278 | }else if (status.equals("Selection.WithHandlers")) { |
||
279 | // Movemos los handlers que hemos seleccionado
|
||
280 | // previamente dentro del m?todo select()
|
||
281 | for (int k = 0; k < selectedHandler.size(); k++) { |
||
282 | Handler h = (Handler) selectedHandler.get(k); |
||
283 | h.set(x, y); |
||
284 | } |
||
285 | // Y una vez movidos los v?rtices (handles)
|
||
286 | // redibujamos la nueva geometr?a.
|
||
287 | for (int i = 0; i < rowselectedHandlers.size(); i++) { |
||
288 | IRowEdited rowEd = (IRowEdited) rowselectedHandlers.get(i); |
||
289 | IGeometry geom = ((IFeature) rowEd.getLinkedRow()) |
||
290 | .getGeometry().cloneGeometry(); |
||
291 | g.setColor(Color.gray);
|
||
292 | geom.draw((Graphics2D) g, vp, CADTool.modifySymbol);
|
||
293 | } |
||
294 | return;
|
||
295 | }else{
|
||
296 | 7541 | caballero | if (!vle.getLayer().isVisible())
|
297 | return;
|
||
298 | 5207 | caballero | try{
|
299 | Image imgSel = vle.getSelectionImage();
|
||
300 | if (imgSel!=null) |
||
301 | g.drawImage(imgSel, 0, 0, null); |
||
302 | Image imgHand = vle.getHandlersImage();
|
||
303 | if (imgHand!=null) |
||
304 | g.drawImage(imgHand, 0, 0, null); |
||
305 | }catch (Exception e) { |
||
306 | } |
||
307 | } |
||
308 | } |
||
309 | |||
310 | /**
|
||
311 | * Add a diferent option.
|
||
312 | *
|
||
313 | * @param sel
|
||
314 | * DOCUMENT ME!
|
||
315 | * @param s
|
||
316 | * Diferent option.
|
||
317 | */
|
||
318 | public void addOption(String s) { |
||
319 | ComplexSelectionCADToolState actualState = (ComplexSelectionCADToolState) _fsm |
||
320 | .getPreviousState(); |
||
321 | String status = actualState.getName();
|
||
322 | System.out.println("PREVIOUSSTATE =" + status); // + "ESTADO ACTUAL: " + |
||
323 | // _fsm.getState());
|
||
324 | System.out.println("STATUS ACTUAL = " + _fsm.getTransition()); |
||
325 | if (s.equals(PluginServices.getText(this,"cancel"))){ |
||
326 | init(); |
||
327 | return;
|
||
328 | }else if (s.equals(PluginServices.getText(this,"select_all"))){ |
||
329 | selectAll(); |
||
330 | init(); |
||
331 | return;
|
||
332 | } |
||
333 | if (status.equals("Selection.FirstPoint")) { |
||
334 | setType(s); |
||
335 | return;
|
||
336 | }else if (status.equals("Selection.NextPointPolygon")){ |
||
337 | if (s.equals(PluginServices.getText(this,"end_polygon")) || s.equals("E") || s.equals("e")) { |
||
338 | IGeometry polygon=getGeometryPolygon(null);
|
||
339 | 6160 | caballero | GeneralPathX gpx=new GeneralPathX();
|
340 | gpx.append(polygon,true);
|
||
341 | if (gpx.isCCW()) {
|
||
342 | gpx.flip(); |
||
343 | polygon=ShapeFactory.createPolygon2D(gpx); |
||
344 | } |
||
345 | 5207 | caballero | selectWithPolygon(polygon); |
346 | pointsPolygon.clear(); |
||
347 | setType(PluginServices.getText(this,"inside_circle")); |
||
348 | return;
|
||
349 | } |
||
350 | } |
||
351 | init(); |
||
352 | } |
||
353 | private int selectAll() { |
||
354 | VectorialLayerEdited vle = getVLE(); |
||
355 | PluginServices.getMDIManager().setWaitCursor(); |
||
356 | vle.selectAll(); |
||
357 | ArrayList selectedRow = vle.getSelectedRow();
|
||
358 | PluginServices.getMDIManager().restoreCursor(); |
||
359 | if (selectedRow.size() > 0) { |
||
360 | nextState = "Selection.WithSelectedFeatures";
|
||
361 | } else
|
||
362 | nextState = "Selection.FirstPoint";
|
||
363 | end(); |
||
364 | return selectedRow.size();
|
||
365 | } |
||
366 | |||
367 | private IGeometry getGeometryPolygon(Point2D p) { |
||
368 | Point2D[] points = (Point2D[]) pointsPolygon.toArray(new Point2D[0]); |
||
369 | GeneralPathX gpx = new GeneralPathX();
|
||
370 | for (int i = 0; i < points.length; i++) { |
||
371 | if (i == 0) { |
||
372 | gpx.moveTo(points[i].getX(), points[i].getY()); |
||
373 | } else {
|
||
374 | gpx.lineTo(points[i].getX(), points[i].getY()); |
||
375 | } |
||
376 | } |
||
377 | if (p!=null){ |
||
378 | gpx.lineTo(p.getX(),p.getY()); |
||
379 | gpx.closePath(); |
||
380 | IGeometry polyline = ShapeFactory.createPolyline2D(gpx); |
||
381 | return polyline;
|
||
382 | } |
||
383 | gpx.closePath(); |
||
384 | IGeometry polygon = ShapeFactory.createPolygon2D(gpx); |
||
385 | return polygon;
|
||
386 | } |
||
387 | |||
388 | /*
|
||
389 | * (non-Javadoc)
|
||
390 | *
|
||
391 | * @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
|
||
392 | */
|
||
393 | public void addValue(double d) { |
||
394 | } |
||
395 | |||
396 | public void end() { |
||
397 | if (!getNextTool().equals("complex_selection")) |
||
398 | CADExtension.setCADTool(getNextTool(),false);
|
||
399 | } |
||
400 | |||
401 | public String getName() { |
||
402 | return PluginServices.getText(this,"complex_selection_"); |
||
403 | } |
||
404 | |||
405 | public boolean selectFeatures(double x, double y, InputEvent event) { |
||
406 | ComplexSelectionCADToolState actualState = (ComplexSelectionCADToolState) _fsm |
||
407 | .getState(); |
||
408 | |||
409 | String status = actualState.getName();
|
||
410 | VectorialLayerEdited vle = getVLE(); |
||
411 | |||
412 | |||
413 | if ((status.equals("Selection.FirstPoint")) |
||
414 | || (status.equals("Selection.WithSelectedFeatures"))) {
|
||
415 | PluginServices.getMDIManager().setWaitCursor(); |
||
416 | firstPoint = new Point2D.Double(x, y); |
||
417 | 5908 | caballero | vle.selectWithPoint(x,y,multipleSelection); |
418 | 5207 | caballero | PluginServices.getMDIManager().restoreCursor(); |
419 | } |
||
420 | ArrayList selectedRow = vle.getSelectedRow();
|
||
421 | if (selectedRow.size() > 0) { |
||
422 | nextState = "Selection.WithSelectedFeatures";
|
||
423 | return true; |
||
424 | } else {
|
||
425 | { |
||
426 | nextState = "Selection.SecondPoint";
|
||
427 | return true; |
||
428 | } |
||
429 | } |
||
430 | } |
||
431 | |||
432 | public int selectHandlers(double x, double y, InputEvent event) { |
||
433 | Point2D auxPoint = new Point2D.Double(x, y); |
||
434 | |||
435 | VectorialLayerEdited vle = getVLE(); |
||
436 | ArrayList selectedHandler = vle.getSelectedHandler();
|
||
437 | ArrayList selectedRow = vle.getSelectedRow();
|
||
438 | System.out.println("DENTRO DE selectHandlers. selectedRow.size= " |
||
439 | + selectedRow.size()); |
||
440 | selectedHandler.clear(); |
||
441 | |||
442 | // Se comprueba si se pincha en una gemometr?a
|
||
443 | PluginServices.getMDIManager().setWaitCursor(); |
||
444 | |||
445 | double tam = getCadToolAdapter().getMapControl().getViewPort()
|
||
446 | .toMapDistance(tolerance); |
||
447 | |||
448 | Handler[] handlers = null; |
||
449 | rowselectedHandlers.clear(); |
||
450 | for (int i = 0; i < selectedRow.size(); i++) { |
||
451 | IRowEdited rowEd = (IRowEdited) selectedRow.get(i); |
||
452 | |||
453 | IFeature fea = (IFeature) rowEd.getLinkedRow(); |
||
454 | handlers = fea.getGeometry().getHandlers(IGeometry.SELECTHANDLER); |
||
455 | // y miramos los handlers de cada entidad seleccionada
|
||
456 | double min = tam;
|
||
457 | // int hSel = -1;
|
||
458 | |||
459 | for (int j = 0; j < handlers.length; j++) { |
||
460 | Point2D handlerPoint = handlers[j].getPoint();
|
||
461 | double distance = auxPoint.distance(handlerPoint);
|
||
462 | if (distance <= min) {
|
||
463 | min = distance; |
||
464 | // hSel = j;
|
||
465 | selectedHandler.add(handlers[j]); |
||
466 | rowselectedHandlers.add(rowEd); |
||
467 | } |
||
468 | } |
||
469 | } |
||
470 | PluginServices.getMDIManager().restoreCursor(); |
||
471 | |||
472 | int numHandlesSelected = selectedHandler.size();
|
||
473 | |||
474 | /*
|
||
475 | * if (numHandlesSelected == 0) selectFeatures(x,y);
|
||
476 | */
|
||
477 | |||
478 | return numHandlesSelected;
|
||
479 | } |
||
480 | |||
481 | public String getType() { |
||
482 | return type;
|
||
483 | } |
||
484 | |||
485 | public void setType(String type) { |
||
486 | if (type.equals("OR") || type.equals("or")){ |
||
487 | this.type=PluginServices.getText(this,"out_rectangle"); |
||
488 | }else if (type.equals("IP") || type.equals("ip")){ |
||
489 | this.type=PluginServices.getText(this,"inside_polygon"); |
||
490 | }else if (type.equals("CP") || type.equals("cp")){ |
||
491 | this.type=PluginServices.getText(this,"cross_polygon"); |
||
492 | }else if (type.equals("OP") || type.equals("op")){ |
||
493 | this.type=PluginServices.getText(this,"out_polygon"); |
||
494 | }else if (type.equals("IC") || type.equals("ic")){ |
||
495 | this.type=PluginServices.getText(this,"inside_circle"); |
||
496 | }else if (type.equals("CC") || type.equals("cc")){ |
||
497 | this.type=PluginServices.getText(this,"cross_circle"); |
||
498 | }else if (type.equals("OC") || type.equals("oc")){ |
||
499 | this.type=PluginServices.getText(this,"cross_circle"); |
||
500 | }else if (type.equals(PluginServices.getText(this,"select_all"))){ |
||
501 | selectAll(); |
||
502 | init(); |
||
503 | }else{
|
||
504 | this.type = type;
|
||
505 | } |
||
506 | pointsPolygon.clear(); |
||
507 | } |
||
508 | /*
|
||
509 | * (non-Javadoc)
|
||
510 | *
|
||
511 | * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet,
|
||
512 | * double, double)
|
||
513 | */
|
||
514 | public void transition(double x, double y, InputEvent event) { |
||
515 | System.out.println("TRANSICION DESDE ESTADO " + _fsm.getState() |
||
516 | + " x= " + x + " y=" + y); |
||
517 | try{
|
||
518 | _fsm.addPoint(x, y, event); |
||
519 | }catch (Exception e) { |
||
520 | init(); |
||
521 | } |
||
522 | System.out.println("ESTADO ACTUAL: " + getStatus()); |
||
523 | |||
524 | 6474 | caballero | FLyrVect lv=(FLyrVect)((VectorialLayerEdited)CADExtension.getEditionManager().getActiveLayerEdited()).getLayer(); |
525 | 6880 | cesar | com.iver.andami.ui.mdiManager.IWindow[] views = (com.iver.andami.ui.mdiManager.IWindow[]) PluginServices.getMDIManager().getAllWindows(); |
526 | 6474 | caballero | |
527 | for (int i=0 ; i<views.length ; i++){ |
||
528 | if (views[i] instanceof Table){ |
||
529 | Table table=(Table)views[i]; |
||
530 | if (table.getModel().getAssociatedTable()!=null && table.getModel().getAssociatedTable().equals(lv)) |
||
531 | table.updateSelection(); |
||
532 | } |
||
533 | } |
||
534 | 5207 | caballero | } |
535 | public String getStatus() { |
||
536 | try {
|
||
537 | ComplexSelectionCADToolState actualState = (ComplexSelectionCADToolState) _fsm |
||
538 | .getPreviousState(); |
||
539 | String status = actualState.getName();
|
||
540 | |||
541 | return status;
|
||
542 | } catch (NullPointerException e) { |
||
543 | return "Selection.FirstPoint"; |
||
544 | } |
||
545 | } |
||
546 | /*
|
||
547 | * (non-Javadoc)
|
||
548 | *
|
||
549 | * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet,
|
||
550 | * java.lang.String)
|
||
551 | */
|
||
552 | 5735 | caballero | public void transition(String s) throws CommandException { |
553 | 5207 | caballero | if (!super.changeCommand(s)){ |
554 | |||
555 | _fsm.addOption(s); |
||
556 | |||
557 | } |
||
558 | } |
||
559 | /*
|
||
560 | * (non-Javadoc)
|
||
561 | *
|
||
562 | * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet,
|
||
563 | * double)
|
||
564 | */
|
||
565 | public void transition(double d) { |
||
566 | 5735 | caballero | _fsm.addValue(d); |
567 | 5207 | caballero | } |
568 | |||
569 | public String toString() { |
||
570 | return "_complex_selection"; |
||
571 | } |
||
572 | public String getNextState() { |
||
573 | return nextState;
|
||
574 | } |
||
575 | |||
576 | } |