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