root / branches / v2_0_0_prep / extensions / extEditing / src / com / iver / cit / gvsig / gui / cad / tools / SelectionCADTool.java @ 27270
History | View | Annotate | Download (19 KB)
1 | 3832 | 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 | 4522 | caballero | import java.awt.Color; |
44 | import java.awt.Graphics; |
||
45 | import java.awt.Graphics2D; |
||
46 | 4637 | caballero | import java.awt.Image; |
47 | 4522 | caballero | import java.awt.event.InputEvent; |
48 | import java.awt.geom.Point2D; |
||
49 | import java.util.ArrayList; |
||
50 | 23086 | vcaballero | import java.util.Iterator; |
51 | 4365 | caballero | |
52 | 24500 | jmvivo | import org.gvsig.fmap.dal.exception.DataException; |
53 | import org.gvsig.fmap.dal.exception.ReadException; |
||
54 | 24490 | jmvivo | import org.gvsig.fmap.dal.feature.EditableFeature; |
55 | import org.gvsig.fmap.dal.feature.Feature; |
||
56 | import org.gvsig.fmap.dal.feature.FeatureSet; |
||
57 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
58 | 24500 | jmvivo | import org.gvsig.fmap.dal.feature.exception.NeedEditingModeException; |
59 | 21668 | vcaballero | import org.gvsig.fmap.geom.Geometry; |
60 | import org.gvsig.fmap.geom.handler.Handler; |
||
61 | 22025 | jmvivo | import org.gvsig.fmap.geom.operation.Draw; |
62 | import org.gvsig.fmap.geom.operation.DrawOperationContext; |
||
63 | 21668 | vcaballero | import org.gvsig.fmap.geom.operation.GeometryOperationException; |
64 | import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
||
65 | import org.gvsig.fmap.geom.primitive.GeneralPathX; |
||
66 | import org.gvsig.fmap.mapcontext.MapContext; |
||
67 | import org.gvsig.fmap.mapcontext.ViewPort; |
||
68 | import org.gvsig.fmap.mapcontext.layers.FLayer; |
||
69 | import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
||
70 | 23657 | vcaballero | import org.gvsig.fmap.mapcontrol.MapControl; |
71 | 25069 | vcaballero | import org.gvsig.project.document.table.gui.FeatureTableDocumentPanel; |
72 | 21668 | vcaballero | |
73 | 4522 | caballero | import com.iver.andami.PluginServices; |
74 | 27270 | vcaballero | import com.iver.andami.messages.NotificationManager; |
75 | 3883 | caballero | import com.iver.cit.gvsig.CADExtension; |
76 | 3832 | caballero | import com.iver.cit.gvsig.gui.cad.DefaultCADTool; |
77 | 5735 | caballero | import com.iver.cit.gvsig.gui.cad.exception.CommandException; |
78 | 3832 | caballero | import com.iver.cit.gvsig.gui.cad.tools.smc.SelectionCADToolContext; |
79 | import com.iver.cit.gvsig.gui.cad.tools.smc.SelectionCADToolContext.SelectionCADToolState; |
||
80 | 4365 | caballero | import com.iver.cit.gvsig.layers.VectorialLayerEdited; |
81 | 3832 | caballero | |
82 | /**
|
||
83 | * DOCUMENT ME!
|
||
84 | 4465 | caballero | *
|
85 | 3832 | caballero | * @author Vicente Caballero Navarro
|
86 | */
|
||
87 | public class SelectionCADTool extends DefaultCADTool { |
||
88 | 23657 | vcaballero | // public static int tolerance = 4;
|
89 | 3832 | caballero | |
90 | 26921 | jpiera | protected SelectionCADToolContext _fsm;
|
91 | 3832 | caballero | |
92 | 5207 | caballero | protected Point2D firstPoint; |
93 | 27270 | vcaballero | |
94 | 5207 | caballero | protected String nextState; |
95 | 23086 | vcaballero | // Registros de los que se ha seleccionado alg?n handler.
|
96 | 5207 | caballero | protected ArrayList rowselectedHandlers=new ArrayList(); |
97 | protected String type=PluginServices.getText(this,"simple"); |
||
98 | 23646 | vcaballero | // protected ArrayList pointsPolygon=new ArrayList();
|
99 | 5908 | caballero | |
100 | protected boolean multipleSelection=false; |
||
101 | 4016 | caballero | /**
|
102 | 5196 | caballero | * Crea un nuevo SelectionCADTool.
|
103 | 4016 | caballero | */
|
104 | public SelectionCADTool() {
|
||
105 | } |
||
106 | /**
|
||
107 | * M?todo de incio, para poner el c?digo de todo lo que se requiera de una
|
||
108 | * carga previa a la utilizaci?n de la herramienta.
|
||
109 | */
|
||
110 | public void init() { |
||
111 | _fsm = new SelectionCADToolContext(this); |
||
112 | setNextTool("selection");
|
||
113 | 4708 | caballero | setType(PluginServices.getText(this,"simple")); |
114 | 4016 | caballero | } |
115 | 3847 | caballero | |
116 | 4016 | caballero | /*
|
117 | * (non-Javadoc)
|
||
118 | 4465 | caballero | *
|
119 | 4016 | caballero | * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet,
|
120 | * double, double)
|
||
121 | */
|
||
122 | 4313 | fjp | public void transition(double x, double y, InputEvent event) { |
123 | 4448 | fjp | System.out.println("TRANSICION DESDE ESTADO " + _fsm.getState() |
124 | + " x= " + x + " y=" + y); |
||
125 | 5171 | caballero | try{
|
126 | 4324 | caballero | _fsm.addPoint(x, y, event); |
127 | 5171 | caballero | }catch (Exception e) { |
128 | init(); |
||
129 | 26242 | vcaballero | PluginServices.getMDIManager().restoreCursor(); |
130 | 5171 | caballero | } |
131 | 4445 | fjp | System.out.println("ESTADO ACTUAL: " + getStatus()); |
132 | 5196 | caballero | |
133 | 5174 | fjp | // ESTO LO QUITO POR AHORA, PERO PUEDE QUE LO NECESITEMOS VOLVER A PONER.
|
134 | // Lo he quitado porque cuando seleccionas algo con CAD, molesta que
|
||
135 | // te hagan un redibujado.
|
||
136 | 5205 | caballero | FLyrVect lv=(FLyrVect)((VectorialLayerEdited)CADExtension.getEditionManager().getActiveLayerEdited()).getLayer(); |
137 | //lv.getSource().getRecordset().getSelectionSupport().fireSelectionEvents();
|
||
138 | 6880 | cesar | com.iver.andami.ui.mdiManager.IWindow[] views = (com.iver.andami.ui.mdiManager.IWindow[]) PluginServices.getMDIManager().getAllWindows(); |
139 | 5205 | caballero | |
140 | for (int i=0 ; i<views.length ; i++){ |
||
141 | 25069 | vcaballero | if (views[i] instanceof FeatureTableDocumentPanel){ |
142 | FeatureTableDocumentPanel table=(FeatureTableDocumentPanel)views[i]; |
||
143 | if (table.getModel().getAssociatedLayer()!=null && table.getModel().getAssociatedLayer().equals(lv)) |
||
144 | 5205 | caballero | table.updateSelection(); |
145 | } |
||
146 | } |
||
147 | 4016 | caballero | } |
148 | 3847 | caballero | |
149 | 4016 | caballero | /*
|
150 | * (non-Javadoc)
|
||
151 | 4465 | caballero | *
|
152 | 4016 | caballero | * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet,
|
153 | * double)
|
||
154 | */
|
||
155 | public void transition(double d) { |
||
156 | 5735 | caballero | _fsm.addValue(d); |
157 | 4016 | caballero | } |
158 | 3847 | caballero | |
159 | 4016 | caballero | /*
|
160 | * (non-Javadoc)
|
||
161 | 4465 | caballero | *
|
162 | 4016 | caballero | * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet,
|
163 | * java.lang.String)
|
||
164 | */
|
||
165 | 5735 | caballero | public void transition(String s) throws CommandException { |
166 | 4892 | caballero | if (!super.changeCommand(s)){ |
167 | 5171 | caballero | _fsm.addOption(s); |
168 | 4892 | caballero | } |
169 | 4016 | caballero | } |
170 | 4144 | fjp | |
171 | 4445 | fjp | public String getNextState() { |
172 | return nextState;
|
||
173 | 4058 | caballero | } |
174 | 4144 | fjp | |
175 | 21668 | vcaballero | protected void pointDoubleClick(MapContext map) throws ReadException { |
176 | FLayer[] actives = map
|
||
177 | 10661 | caballero | .getLayers().getActives(); |
178 | 21668 | vcaballero | // for (int i=0; i < actives.length; i++){
|
179 | // if (actives[i] instanceof FLyrAnnotation && actives[i].isEditing()) {
|
||
180 | // FLyrAnnotation lyrAnnotation = (FLyrAnnotation) actives[i];
|
||
181 | // lyrAnnotation.setSelectedEditing();
|
||
182 | // lyrAnnotation.setInEdition(lyrAnnotation.getRecordset().getSelection().nextSetBit(0));
|
||
183 | // FLabel fl=lyrAnnotation.getLabel(lyrAnnotation.getInEdition());
|
||
184 | // if (fl!=null){
|
||
185 | // View vista=(View)PluginServices.getMDIManager().getActiveWindow();
|
||
186 | // TextFieldEdit tfe=new TextFieldEdit(lyrAnnotation);
|
||
187 | // tfe.show(vista.getMapControl().getViewPort().fromMapPoint(fl.getOrig()),vista.getMapControl());
|
||
188 | // }
|
||
189 | // }
|
||
190 | // }
|
||
191 | 5105 | caballero | } |
192 | 4016 | caballero | /**
|
193 | 4118 | caballero | * Equivale al transition del prototipo pero sin pasarle como par? metro el
|
194 | 4016 | caballero | * editableFeatureSource que ya estar? creado.
|
195 | 4465 | caballero | *
|
196 | 4016 | caballero | * @param selection
|
197 | * Bitset con las geometr?as que est?n seleccionadas.
|
||
198 | * @param x
|
||
199 | * par?metro x del punto que se pase en esta transici?n.
|
||
200 | * @param y
|
||
201 | * par?metro y del punto que se pase en esta transici?n.
|
||
202 | */
|
||
203 | 4365 | caballero | public void addPoint(double x, double y, InputEvent event) { |
204 | 21668 | vcaballero | // if (event!=null && ((MouseEvent)event).getClickCount()==2){
|
205 | // try {
|
||
206 | // pointDoubleClick((MapControl)event.getComponent());
|
||
207 | // } catch (ReadException e) {
|
||
208 | // NotificationManager.addError(e.getMessage(),e);
|
||
209 | // }
|
||
210 | // return;
|
||
211 | // }
|
||
212 | 4016 | caballero | SelectionCADToolState actualState = (SelectionCADToolState) _fsm |
213 | .getPreviousState(); |
||
214 | String status = actualState.getName();
|
||
215 | 4448 | fjp | System.out.println("PREVIOUSSTATE =" + status); // + "ESTADO ACTUAL: " + |
216 | // _fsm.getState());
|
||
217 | 4637 | caballero | VectorialLayerEdited vle = getVLE(); |
218 | 23086 | vcaballero | FeatureStore featureStore=null;
|
219 | try {
|
||
220 | featureStore = vle.getFeatureStore(); |
||
221 | 24429 | vcaballero | |
222 | 4365 | caballero | ArrayList selectedHandler = vle.getSelectedHandler();
|
223 | 23842 | jjdelcerro | FeatureSet selection = (FeatureSet)featureStore.getSelection();//vle.getSelectedRow();
|
224 | 4491 | fjp | System.out.println("STATUS ACTUAL = " + _fsm.getTransition()); |
225 | 4448 | fjp | if (status.equals("Selection.FirstPoint")) { |
226 | 4708 | caballero | firstPoint=new Point2D.Double(x,y); |
227 | 23646 | vcaballero | // pointsPolygon.add(firstPoint);
|
228 | 4448 | fjp | } else if (status.equals("Selection.SecondPoint")) { |
229 | 4491 | fjp | } else if (status.equals("Selection.WithFeatures")) { |
230 | 4448 | fjp | } else if (status.equals("Selection.WithHandlers")) { |
231 | 24429 | vcaballero | String description=PluginServices.getText(this,"move_handlers"); |
232 | featureStore.beginEditingGroup(description); |
||
233 | 5909 | caballero | ArrayList selectedRowsAux=new ArrayList(); |
234 | 23086 | vcaballero | Iterator iterator=selection.iterator();
|
235 | while (iterator.hasNext()) {
|
||
236 | Feature feature = (Feature) iterator.next(); |
||
237 | // }
|
||
238 | // for (int i = 0; i < selectedRow.size(); i++) {
|
||
239 | // IRowEdited row = (IRowEdited) selectedRow.get(i);
|
||
240 | // IFeature feat = (IFeature) row.getLinkedRow().cloneRow();
|
||
241 | 24429 | vcaballero | Geometry ig = (Geometry)feature.getDefaultGeometry().cloneGeometry(); |
242 | 23086 | vcaballero | // if (vea instanceof AnnotationEditableAdapter) {
|
243 | // // Movemos la geometr?a
|
||
244 | // UtilFunctions.moveGeom(ig, x -
|
||
245 | // firstPoint.getX(), y - firstPoint.getY());
|
||
246 | // }else {
|
||
247 | 5909 | caballero | // Movemos los handlers que hemos seleccionado
|
248 | // previamente dentro del m?todo select()
|
||
249 | 23086 | vcaballero | Handler[] handlers=ig.getHandlers(Geometry.SELECTHANDLER); |
250 | 5909 | caballero | for (int k = 0; k < selectedHandler.size(); k++) { |
251 | 12590 | caballero | Handler h = (Handler)selectedHandler.get(k); |
252 | for (int j=0;j<handlers.length;j++) { |
||
253 | if (h.getPoint().equals(handlers[j].getPoint()))
|
||
254 | handlers[j].set(x,y); |
||
255 | } |
||
256 | 5909 | caballero | } |
257 | 23086 | vcaballero | // }
|
258 | 24429 | vcaballero | EditableFeature eFeature=feature.getEditable(); |
259 | eFeature.setGeometry(featureStore.getDefaultFeatureType().getDefaultGeometryAttributeName(), ig); |
||
260 | featureStore.update(eFeature); |
||
261 | // modifyFeature(feature, feature);
|
||
262 | 23086 | vcaballero | // selectedRowsAux.add(new DefaultRowEdited(feat,IRowEdited.STATUS_MODIFIED,row.getIndex()));
|
263 | 4448 | fjp | } |
264 | 5909 | caballero | firstPoint=new Point2D.Double(x,y); |
265 | 23086 | vcaballero | // vle.setSelectionCache(VectorialLayerEdited.SAVEPREVIOUS, selectedRowsAux);
|
266 | 5985 | caballero | //clearSelection();
|
267 | //selectedRow.addAll(selectedRowsAux);
|
||
268 | 24429 | vcaballero | |
269 | featureStore.endEditingGroup(); |
||
270 | 4448 | fjp | } |
271 | 24429 | vcaballero | } catch (ReadException e) {
|
272 | // TODO Auto-generated catch block
|
||
273 | e.printStackTrace(); |
||
274 | } catch (NeedEditingModeException e) {
|
||
275 | // TODO Auto-generated catch block
|
||
276 | e.printStackTrace(); |
||
277 | } catch (DataException e) {
|
||
278 | // TODO Auto-generated catch block
|
||
279 | e.printStackTrace(); |
||
280 | } |
||
281 | 4448 | fjp | } |
282 | 3832 | caballero | |
283 | 4448 | fjp | /**
|
284 | * Receives second point
|
||
285 | * @param x
|
||
286 | * @param y
|
||
287 | * @return numFeatures selected
|
||
288 | */
|
||
289 | 24263 | vcaballero | public long selectWithSecondPoint(double x, double y, InputEvent event) { |
290 | 4637 | caballero | VectorialLayerEdited vle = getVLE(); |
291 | PluginServices.getMDIManager().setWaitCursor(); |
||
292 | vle.selectWithSecondPoint(x,y); |
||
293 | 23842 | jjdelcerro | FeatureSet selection=null;
|
294 | 23086 | vcaballero | try {
|
295 | 23842 | jjdelcerro | selection = (FeatureSet)vle.getFeatureStore().getSelection(); |
296 | 24263 | vcaballero | PluginServices.getMDIManager().restoreCursor(); |
297 | long countSel=selection.getSize();
|
||
298 | if (countSel > 0) { |
||
299 | nextState = "Selection.WithSelectedFeatures";
|
||
300 | } else
|
||
301 | nextState = "Selection.FirstPoint";
|
||
302 | return countSel;
|
||
303 | 23086 | vcaballero | } catch (ReadException e) {
|
304 | e.printStackTrace(); |
||
305 | 24263 | vcaballero | return 0; |
306 | } catch (DataException e) {
|
||
307 | e.printStackTrace(); |
||
308 | return 0; |
||
309 | } |
||
310 | 4016 | caballero | } |
311 | 3832 | caballero | |
312 | 4016 | caballero | /**
|
313 | * M?todo para dibujar la lo necesario para el estado en el que nos
|
||
314 | * encontremos.
|
||
315 | 4465 | caballero | *
|
316 | 4016 | caballero | * @param g
|
317 | * Graphics sobre el que dibujar.
|
||
318 | * @param selectedGeometries
|
||
319 | * BitSet con las geometr?as seleccionadas.
|
||
320 | * @param x
|
||
321 | * par?metro x del punto que se pase para dibujar.
|
||
322 | * @param y
|
||
323 | * par?metro x del punto que se pase para dibujar.
|
||
324 | */
|
||
325 | public void drawOperation(Graphics g, double x, double y) { |
||
326 | SelectionCADToolState actualState = _fsm.getState(); |
||
327 | String status = actualState.getName();
|
||
328 | 4637 | caballero | VectorialLayerEdited vle = getVLE(); |
329 | 5595 | fjp | if (vle == null) return; |
330 | 4365 | caballero | ArrayList selectedHandler = vle.getSelectedHandler();
|
331 | 6881 | cesar | ViewPort vp=vle.getLayer().getMapContext().getViewPort(); |
332 | 5207 | caballero | if (status.equals("Selection.SecondPoint")) { |
333 | 4144 | fjp | // Dibuja el rect?ngulo de selecci?n
|
334 | 4016 | caballero | GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD,
|
335 | 4);
|
||
336 | elShape.moveTo(firstPoint.getX(), firstPoint.getY()); |
||
337 | elShape.lineTo(x, firstPoint.getY()); |
||
338 | elShape.lineTo(x, y); |
||
339 | elShape.lineTo(firstPoint.getX(), y); |
||
340 | elShape.lineTo(firstPoint.getX(), firstPoint.getY()); |
||
341 | 21668 | vcaballero | DrawOperationContext doc=new DrawOperationContext();
|
342 | doc.setGraphics((Graphics2D)g);
|
||
343 | doc.setViewPort(vp); |
||
344 | doc.setSymbol(DefaultCADTool.geometrySelectSymbol); |
||
345 | try {
|
||
346 | 26921 | jpiera | createCurve(elShape).cloneGeometry().invokeOperation(Draw.CODE,doc); |
347 | 21668 | vcaballero | } catch (GeometryOperationNotSupportedException e) {
|
348 | e.printStackTrace(); |
||
349 | } catch (GeometryOperationException e) {
|
||
350 | e.printStackTrace(); |
||
351 | } |
||
352 | // geomFactory.createPolyline2D(elShape).draw((Graphics2D) g,
|
||
353 | // vp,
|
||
354 | // DefaultCADTool.geometrySelectSymbol);
|
||
355 | 4637 | caballero | Image img = vle.getSelectionImage();
|
356 | g.drawImage(img, 0, 0, null); |
||
357 | return;
|
||
358 | 4708 | caballero | }else if (status.equals("Selection.WithHandlers")) { |
359 | 4144 | fjp | // Movemos los handlers que hemos seleccionado
|
360 | // previamente dentro del m?todo select()
|
||
361 | 12590 | caballero | double xPrev=0; |
362 | double yPrev=0; |
||
363 | 4144 | fjp | for (int k = 0; k < selectedHandler.size(); k++) { |
364 | 12590 | caballero | Handler h = (Handler)selectedHandler.get(k); |
365 | xPrev=h.getPoint().getX(); |
||
366 | yPrev=h.getPoint().getY(); |
||
367 | 4144 | fjp | h.set(x, y); |
368 | } |
||
369 | // Y una vez movidos los v?rtices (handles)
|
||
370 | // redibujamos la nueva geometr?a.
|
||
371 | 4637 | caballero | for (int i = 0; i < rowselectedHandlers.size(); i++) { |
372 | 23086 | vcaballero | Feature feature=(Feature)rowselectedHandlers.get(i); |
373 | // IRowEdited rowEd = (IRowEdited) rowselectedHandlers.get(i);
|
||
374 | // IGeometry geom = ((IFeature) rowEd.getLinkedRow())
|
||
375 | // .getGeometry().cloneGeometry();
|
||
376 | Geometry geom=((Geometry)feature.getDefaultGeometry()).cloneGeometry(); |
||
377 | 4016 | caballero | g.setColor(Color.gray);
|
378 | 23086 | vcaballero | DrawOperationContext doc=new DrawOperationContext();
|
379 | doc.setGraphics((Graphics2D)g);
|
||
380 | doc.setViewPort(vp); |
||
381 | doc.setSymbol(DefaultCADTool.axisReferencesSymbol); |
||
382 | try {
|
||
383 | geom.invokeOperation(Draw.CODE,doc); |
||
384 | } catch (GeometryOperationNotSupportedException e) {
|
||
385 | e.printStackTrace(); |
||
386 | } catch (GeometryOperationException e) {
|
||
387 | e.printStackTrace(); |
||
388 | } |
||
389 | 4016 | caballero | } |
390 | 12590 | caballero | for (int k = 0; k < selectedHandler.size(); k++) { |
391 | Handler h = (Handler)selectedHandler.get(k); |
||
392 | h.set(xPrev, yPrev); |
||
393 | } |
||
394 | 4637 | caballero | return;
|
395 | }else{
|
||
396 | 7547 | caballero | if (!vle.getLayer().isVisible())
|
397 | return;
|
||
398 | 4637 | caballero | try{
|
399 | Image imgSel = vle.getSelectionImage();
|
||
400 | if (imgSel!=null) |
||
401 | g.drawImage(imgSel, 0, 0, null); |
||
402 | Image imgHand = vle.getHandlersImage();
|
||
403 | if (imgHand!=null) |
||
404 | g.drawImage(imgHand, 0, 0, null); |
||
405 | }catch (Exception e) { |
||
406 | } |
||
407 | 4016 | caballero | } |
408 | } |
||
409 | 3832 | caballero | |
410 | 4016 | caballero | /**
|
411 | * Add a diferent option.
|
||
412 | 4465 | caballero | *
|
413 | 4016 | caballero | * @param sel
|
414 | * DOCUMENT ME!
|
||
415 | * @param s
|
||
416 | * Diferent option.
|
||
417 | */
|
||
418 | public void addOption(String s) { |
||
419 | 4708 | caballero | SelectionCADToolState actualState = (SelectionCADToolState) _fsm |
420 | .getPreviousState(); |
||
421 | String status = actualState.getName();
|
||
422 | System.out.println("PREVIOUSSTATE =" + status); // + "ESTADO ACTUAL: " + |
||
423 | // _fsm.getState());
|
||
424 | System.out.println("STATUS ACTUAL = " + _fsm.getTransition()); |
||
425 | if (s.equals(PluginServices.getText(this,"cancel"))){ |
||
426 | init(); |
||
427 | return;
|
||
428 | } |
||
429 | if (status.equals("Selection.FirstPoint")) { |
||
430 | setType(s); |
||
431 | 5171 | caballero | return;
|
432 | 4708 | caballero | } |
433 | 5171 | caballero | init(); |
434 | 4016 | caballero | } |
435 | |||
436 | 4708 | caballero | |
437 | 5207 | caballero | |
438 | |||
439 | 4016 | caballero | /*
|
440 | * (non-Javadoc)
|
||
441 | 4465 | caballero | *
|
442 | 4016 | caballero | * @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
|
443 | */
|
||
444 | public void addValue(double d) { |
||
445 | } |
||
446 | |||
447 | public String getStatus() { |
||
448 | try {
|
||
449 | SelectionCADToolState actualState = (SelectionCADToolState) _fsm |
||
450 | .getPreviousState(); |
||
451 | String status = actualState.getName();
|
||
452 | 4365 | caballero | |
453 | 4016 | caballero | return status;
|
454 | } catch (NullPointerException e) { |
||
455 | 5196 | caballero | return "Selection.FirstPoint"; |
456 | 3883 | caballero | } |
457 | 4016 | caballero | } |
458 | 3832 | caballero | |
459 | 3883 | caballero | |
460 | 4016 | caballero | |
461 | 3883 | caballero | public void end() { |
462 | 4708 | caballero | if (!getNextTool().equals("selection")) |
463 | 4892 | caballero | CADExtension.setCADTool(getNextTool(),false);
|
464 | 4016 | caballero | } |
465 | 3883 | caballero | |
466 | 4118 | caballero | public String getName() { |
467 | 4584 | caballero | return PluginServices.getText(this,"selection_"); |
468 | 4118 | caballero | } |
469 | 4445 | fjp | |
470 | 4491 | fjp | public boolean selectFeatures(double x, double y, InputEvent event) { |
471 | 4445 | fjp | SelectionCADToolState actualState = (SelectionCADToolState) _fsm |
472 | 4448 | fjp | .getState(); |
473 | 4445 | fjp | |
474 | String status = actualState.getName();
|
||
475 | 4637 | caballero | VectorialLayerEdited vle = getVLE(); |
476 | 26242 | vcaballero | multipleSelection=event.isControlDown(); |
477 | 4445 | fjp | |
478 | 4448 | fjp | if ((status.equals("Selection.FirstPoint")) |
479 | || (status.equals("Selection.WithSelectedFeatures"))) {
|
||
480 | PluginServices.getMDIManager().setWaitCursor(); |
||
481 | 4637 | caballero | firstPoint = new Point2D.Double(x, y); |
482 | 27270 | vcaballero | try {
|
483 | vle.getFeatureStore().beginEditingGroup(getName()); |
||
484 | vle.selectWithPoint(x,y,multipleSelection); |
||
485 | vle.getFeatureStore().endEditingGroup(); |
||
486 | } catch (NeedEditingModeException e) {
|
||
487 | NotificationManager.showMessageError(getName(), e); |
||
488 | } catch (ReadException e) {
|
||
489 | NotificationManager.showMessageError(getName(), e); |
||
490 | } |
||
491 | 4448 | fjp | PluginServices.getMDIManager().restoreCursor(); |
492 | } |
||
493 | 23842 | jjdelcerro | FeatureSet selection=null;
|
494 | 23086 | vcaballero | try {
|
495 | 23842 | jjdelcerro | selection = (FeatureSet)vle.getFeatureStore().getSelection(); |
496 | 24263 | vcaballero | |
497 | 23086 | vcaballero | // ArrayList selectedRow = vle.getSelectedRow();
|
498 | 24263 | vcaballero | long countSel=selection.getSize();
|
499 | 23086 | vcaballero | if (countSel > 0) { |
500 | 4445 | fjp | nextState = "Selection.WithSelectedFeatures";
|
501 | return true; |
||
502 | 4448 | fjp | } else {
|
503 | { |
||
504 | nextState = "Selection.SecondPoint";
|
||
505 | return true; |
||
506 | } |
||
507 | 4445 | fjp | } |
508 | 24263 | vcaballero | } catch (ReadException e) {
|
509 | e.printStackTrace(); |
||
510 | return false; |
||
511 | } catch (DataException e) {
|
||
512 | e.printStackTrace(); |
||
513 | return false; |
||
514 | } |
||
515 | 4445 | fjp | } |
516 | |||
517 | 4491 | fjp | public int selectHandlers(double x, double y, InputEvent event) { |
518 | 4445 | fjp | Point2D auxPoint = new Point2D.Double(x, y); |
519 | |||
520 | 4637 | caballero | VectorialLayerEdited vle = getVLE(); |
521 | 4445 | fjp | ArrayList selectedHandler = vle.getSelectedHandler();
|
522 | 23842 | jjdelcerro | FeatureSet selection=null;
|
523 | 23086 | vcaballero | try {
|
524 | 23842 | jjdelcerro | selection = (FeatureSet)vle.getFeatureStore().getSelection(); |
525 | 24263 | vcaballero | |
526 | 23086 | vcaballero | // ArrayList selectedRow = vle.getSelectedRow();
|
527 | 24263 | vcaballero | long countSel=selection.getSize();
|
528 | 4448 | fjp | System.out.println("DENTRO DE selectHandlers. selectedRow.size= " |
529 | 23086 | vcaballero | + countSel); |
530 | 4445 | fjp | selectedHandler.clear(); |
531 | 4448 | fjp | |
532 | 4445 | fjp | // Se comprueba si se pincha en una gemometr?a
|
533 | PluginServices.getMDIManager().setWaitCursor(); |
||
534 | |||
535 | double tam = getCadToolAdapter().getMapControl().getViewPort()
|
||
536 | 23657 | vcaballero | .toMapDistance(MapControl.tolerance); |
537 | 4448 | fjp | |
538 | 4445 | fjp | Handler[] handlers = null; |
539 | 4637 | caballero | rowselectedHandlers.clear(); |
540 | 23086 | vcaballero | Iterator iterator=selection.iterator();
|
541 | while (iterator.hasNext()) {
|
||
542 | Feature feature = (Feature) iterator.next(); |
||
543 | 4448 | fjp | |
544 | 23086 | vcaballero | // }
|
545 | // for (int i = 0; i < selectedRow.size(); i++) {
|
||
546 | // IRowEdited rowEd = (IRowEdited) selectedRow.get(i);
|
||
547 | //
|
||
548 | // IFeature fea = (IFeature) rowEd.getLinkedRow();
|
||
549 | handlers = ((Geometry)feature.getDefaultGeometry()).getHandlers(Geometry.SELECTHANDLER); |
||
550 | 4445 | fjp | // y miramos los handlers de cada entidad seleccionada
|
551 | double min = tam;
|
||
552 | // int hSel = -1;
|
||
553 | 4637 | caballero | |
554 | 4445 | fjp | for (int j = 0; j < handlers.length; j++) { |
555 | Point2D handlerPoint = handlers[j].getPoint();
|
||
556 | double distance = auxPoint.distance(handlerPoint);
|
||
557 | if (distance <= min) {
|
||
558 | min = distance; |
||
559 | 4448 | fjp | // hSel = j;
|
560 | 4445 | fjp | selectedHandler.add(handlers[j]); |
561 | 23086 | vcaballero | rowselectedHandlers.add(feature); |
562 | 4445 | fjp | } |
563 | } |
||
564 | } |
||
565 | PluginServices.getMDIManager().restoreCursor(); |
||
566 | 24263 | vcaballero | } catch (ReadException e) {
|
567 | // TODO Auto-generated catch block
|
||
568 | e.printStackTrace(); |
||
569 | } catch (DataException e) {
|
||
570 | // TODO Auto-generated catch block
|
||
571 | e.printStackTrace(); |
||
572 | } |
||
573 | 4445 | fjp | int numHandlesSelected = selectedHandler.size();
|
574 | |||
575 | 4448 | fjp | /*
|
576 | * if (numHandlesSelected == 0) selectFeatures(x,y);
|
||
577 | */
|
||
578 | |||
579 | 4445 | fjp | return numHandlesSelected;
|
580 | } |
||
581 | 4708 | caballero | |
582 | public String getType() { |
||
583 | return type;
|
||
584 | } |
||
585 | |||
586 | public void setType(String type) { |
||
587 | if (type.equals("S") || type.equals("s")){ |
||
588 | this.type=PluginServices.getText(this,"simple"); |
||
589 | }else{
|
||
590 | this.type = type;
|
||
591 | } |
||
592 | 23646 | vcaballero | // pointsPolygon.clear();
|
593 | 4708 | caballero | } |
594 | 4892 | caballero | |
595 | public String toString() { |
||
596 | return "_selection"; |
||
597 | } |
||
598 | 5908 | caballero | public void multipleSelection(boolean b) { |
599 | multipleSelection=b; |
||
600 | 5171 | caballero | |
601 | 5908 | caballero | } |
602 | |||
603 | 3832 | caballero | } |