Revision 4115 trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/CADToolAdapter.java

View differences:

CADToolAdapter.java
12 12
import java.awt.geom.Rectangle2D;
13 13
import java.awt.image.MemoryImageSource;
14 14
import java.io.IOException;
15
import java.util.List;
15 16
import java.util.Stack;
16 17

  
17 18
import com.iver.andami.PluginServices;
18 19
import com.iver.cit.gvsig.CADExtension;
19
import com.iver.cit.gvsig.fmap.DriverException;
20
import com.iver.cit.gvsig.fmap.MapControl;
21 20
import com.iver.cit.gvsig.fmap.ViewPort;
22 21
import com.iver.cit.gvsig.fmap.core.Handler;
23
import com.iver.cit.gvsig.fmap.core.IFeature;
24 22
import com.iver.cit.gvsig.fmap.core.IGeometry;
25 23
import com.iver.cit.gvsig.fmap.core.v02.FConstant;
26 24
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
......
32 30
import com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener;
33 31
import com.iver.cit.gvsig.gui.View;
34 32
import com.iver.cit.gvsig.gui.cad.tools.SelectionCADTool;
33
import com.vividsolutions.jts.geom.Envelope;
34
import com.vividsolutions.jts.index.SpatialIndex;
35 35

  
36 36
public class CADToolAdapter extends Behavior {
37 37
	private Stack cadToolStack = new Stack();
38 38

  
39
	//Para pasarle las coordenadas cuando se produce un evento textEntered
39
	// Para pasarle las coordenadas cuando se produce un evento textEntered
40 40
	private int lastX;
41

  
41 42
	private int lastY;
43

  
42 44
	private FSymbol symbol = new FSymbol(FConstant.SYMBOL_TYPE_POINT, Color.RED);
45

  
43 46
	private Point2D mapAdjustedPoint;
47

  
44 48
	private boolean questionAsked = false;
49

  
45 50
	private Point2D adjustedPoint;
51

  
46 52
	private boolean snapping = false;
53

  
47 54
	private boolean adjustSnapping = false;
55

  
48 56
	private VectorialEditableAdapter vea;
49
	private CADGrid cadgrid=new CADGrid();
50 57

  
58
	private CADGrid cadgrid = new CADGrid();
59

  
60
	private SpatialIndex spatialCache;
61

  
51 62
	/**
52 63
	 * Pinta de alguna manera especial las geometrias seleccionadas para la
53
	 * edici?n. En caso de que el snapping est? activado, pintar? el efecto
54
	 * del mismo.
55
	 *
64
	 * edici?n. En caso de que el snapping est? activado, pintar? el efecto del
65
	 * mismo.
66
	 * 
56 67
	 * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#paintComponent(java.awt.Graphics)
57 68
	 */
58 69
	public void paintComponent(Graphics g) {
......
60 71
		drawCursor(g);
61 72
		getGrid().drawGrid(g);
62 73
		if (adjustedPoint != null) {
63
			Point2D p=null;
74
			Point2D p = null;
64 75
			if (mapAdjustedPoint != null) {
65 76
				p = mapAdjustedPoint;
66 77
			} else {
67 78
				p = getMapControl().getViewPort().toMapPoint(adjustedPoint);
68 79
			}
69
			((CADTool) cadToolStack.peek()).drawOperation(g,
70
				p.getX(), p.getY());
80
			((CADTool) cadToolStack.peek())
81
					.drawOperation(g, p.getX(), p.getY());
71 82
		}
72 83
	}
73 84

  
......
75 86
	 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
76 87
	 */
77 88
	public void mouseClicked(MouseEvent e) throws BehaviorException {
78
		if (e.getButton()==MouseEvent.BUTTON3){
89
		if (e.getButton() == MouseEvent.BUTTON3) {
79 90
			CADExtension.showPopup(e);
80 91
		}
81 92
	}
......
101 112
			ViewPort vp = getMapControl().getMapContext().getViewPort();
102 113
			Point2D p;
103 114

  
104
				if (mapAdjustedPoint != null) {
115
			if (mapAdjustedPoint != null) {
105 116
				p = mapAdjustedPoint;
106 117
			} else {
107 118
				p = vp.toMapPoint(adjustedPoint);
108 119
			}
109
			transition(vea,
110
				new double[] { p.getX(), p.getY() });
120
			transition(vea, new double[] { p.getX(), p.getY() });
111 121
		}
112 122
	}
113 123

  
114 124
	/**
115
	 * Ajusta un punto de la imagen que se pasa como  par?metro al grid si ?ste
125
	 * Ajusta un punto de la imagen que se pasa como par?metro al grid si ?ste
116 126
	 * est? activo y devuelve la distancia de un punto al punto ajustado
117
	 *
127
	 * 
118 128
	 * @param point
119
	 * @param mapHandlerAdjustedPoint DOCUMENT ME!
120
	 *
129
	 * @param mapHandlerAdjustedPoint
130
	 *            DOCUMENT ME!
131
	 * 
121 132
	 * @return Distancia del punto que se pasa como par?metro al punto ajustado
122 133
	 */
123 134
	private double adjustToHandler(Point2D point,
124
		Point2D mapHandlerAdjustedPoint) {
125
		//if (selection.cardinality() > 0) {
126
		double rw=getMapControl().getViewPort().toMapDistance(5);
127
		try {
128
			Point2D mapPoint = point;
129
			Rectangle2D r = new Rectangle2D.Double(mapPoint.getX() - rw/2,
130
					mapPoint.getY() - rw/2, rw, rw);
135
			Point2D mapHandlerAdjustedPoint) {
136
		// if (selection.cardinality() > 0) {
137
		double rw = getMapControl().getViewPort().toMapDistance(5);
138
		Point2D mapPoint = point;
139
		Rectangle2D r = new Rectangle2D.Double(mapPoint.getX() - rw / 2,
140
				mapPoint.getY() - rw / 2, rw, rw);
131 141

  
132
			int[] indexes = vea.getRowsIndexes(r);
142
		// int[] indexes = vea.getRowsIndexes(r);
143
		Envelope e = new Envelope(r.getX(), r.getX() + r.getWidth(), r.getY(),
144
				r.getY() + r.getHeight());
145
		List l = getSpatialCache().query(e);
146
		double min = Double.MAX_VALUE;
147
		Point2D argmin = null;
148
		Point2D mapArgmin = null;
133 149

  
134
			double min = Double.MAX_VALUE;
135
			Point2D argmin = null;
136
			Point2D mapArgmin = null;
150
		for (int i = 0; i < l.size(); i++) {
151
			IGeometry geometry = null;
152
			geometry = (IGeometry) l.get(i);// getFeature(indexes[i]);
153
			Handler[] handlers = geometry.getHandlers(IGeometry.SELECTHANDLER);
137 154

  
138
			for (int i = 0; i < indexes.length; i++) {
139
				IGeometry geometry=null;
140
					geometry = vea.getShape(indexes[i]);//getFeature(indexes[i]);
141
				Handler[] handlers = geometry.getHandlers(IGeometry.SELECTHANDLER);
142

  
143
				for (int j = 0; j < handlers.length; j++) {
144
					Point2D handlerPoint = handlers[j].getPoint();
145
					//System.err.println("handlerPoint= "+ handlerPoint);
146
					Point2D handlerImagePoint = handlerPoint;
147
					double dist = handlerImagePoint.distance(point);
148
					if ((dist < getMapControl().getViewPort().toMapDistance(SelectionCADTool.tolerance)) &&
149
							(dist < min)) {
150
						min = dist;
151
						argmin = handlerImagePoint;
152
						mapArgmin = handlerPoint;
153
					}
155
			for (int j = 0; j < handlers.length; j++) {
156
				Point2D handlerPoint = handlers[j].getPoint();
157
				// System.err.println("handlerPoint= "+ handlerPoint);
158
				Point2D handlerImagePoint = handlerPoint;
159
				double dist = handlerImagePoint.distance(point);
160
				if ((dist < getMapControl().getViewPort().toMapDistance(
161
						SelectionCADTool.tolerance))
162
						&& (dist < min)) {
163
					min = dist;
164
					argmin = handlerImagePoint;
165
					mapArgmin = handlerPoint;
154 166
				}
155 167
			}
168
		}
156 169

  
157
			if (argmin != null) {
158
				point.setLocation(argmin);
170
		if (argmin != null) {
171
			point.setLocation(argmin);
159 172

  
160
				//Se hace el casting porque no se quiere redondeo
161
				point.setLocation(argmin.getX(), argmin.getY());
173
			// Se hace el casting porque no se quiere redondeo
174
			point.setLocation(argmin.getX(), argmin.getY());
162 175

  
163
				mapHandlerAdjustedPoint.setLocation(mapArgmin);
176
			mapHandlerAdjustedPoint.setLocation(mapArgmin);
164 177

  
165
				return min;
166
			}
167
		} catch (DriverIOException e) {
168
			// TODO Auto-generated catch block
169
			e.printStackTrace();
178
			return min;
170 179
		}
171 180

  
172 181
		return Double.MAX_VALUE;
......
202 211

  
203 212
		getMapControl().repaint();
204 213
	}
205
	private void clearMouseImage(){
214

  
215
	private void clearMouseImage() {
206 216
		int[] pixels = new int[16 * 16];
207 217
		Image image = Toolkit.getDefaultToolkit().createImage(
208
			new MemoryImageSource(16, 16, pixels, 0, 16));
209
		Cursor transparentCursor =
210
			Toolkit.getDefaultToolkit().createCustomCursor
211
			    (image, new Point(0,0), "invisiblecursor");
218
				new MemoryImageSource(16, 16, pixels, 0, 16));
219
		Cursor transparentCursor = Toolkit.getDefaultToolkit()
220
				.createCustomCursor(image, new Point(0, 0), "invisiblecursor");
212 221

  
213 222
		getMapControl().setCursor(transparentCursor);
214 223
	}
224

  
215 225
	/**
216 226
	 * DOCUMENT ME!
217
	 *
218
	 * @param g DOCUMENT ME!
227
	 * 
228
	 * @param g
229
	 *            DOCUMENT ME!
219 230
	 */
220 231
	private void drawCursor(Graphics g) {
221 232

  
......
230 241
		int size1 = 15;
231 242
		int size2 = 3;
232 243
		g.drawLine((int) (p.getX() - size1), (int) (p.getY()),
233
			(int) (p.getX() + size1), (int) (p.getY()));
244
				(int) (p.getX() + size1), (int) (p.getY()));
234 245
		g.drawLine((int) (p.getX()), (int) (p.getY() - size1),
235
			(int) (p.getX()), (int) (p.getY() + size1));
246
				(int) (p.getX()), (int) (p.getY() + size1));
236 247

  
237 248
		if (adjustedPoint != null) {
238 249
			if (adjustSnapping) {
239 250
				g.setColor(Color.ORANGE);
240 251
				g.drawRect((int) (adjustedPoint.getX() - 6),
241
					(int) (adjustedPoint.getY() - 6), 12, 12);
252
						(int) (adjustedPoint.getY() - 6), 12, 12);
242 253
				g.drawRect((int) (adjustedPoint.getX() - 3),
243
					(int) (adjustedPoint.getY() - 3), 6, 6);
254
						(int) (adjustedPoint.getY() - 3), 6, 6);
244 255
				g.setColor(Color.MAGENTA);
245 256
				g.drawRect((int) (adjustedPoint.getX() - 4),
246
					(int) (adjustedPoint.getY() - 4), 8, 8);
257
						(int) (adjustedPoint.getY() - 4), 8, 8);
247 258

  
248 259
				adjustSnapping = false;
249 260
			} else {
250 261
				g.drawRect((int) (p.getX() - size2), (int) (p.getY() - size2),
251
					(int) (size2 * 2), (int) (size2 * 2));
262
						(int) (size2 * 2), (int) (size2 * 2));
252 263
			}
253 264
		}
254 265
	}
255 266

  
256 267
	/**
257 268
	 * DOCUMENT ME!
258
	 *
269
	 * 
259 270
	 * @param point
260 271
	 */
261 272
	private void calculateSnapPoint(Point point) {
262
		//Se comprueba el ajuste a rejilla
273
		// Se comprueba el ajuste a rejilla
263 274

  
264
		Point2D gridAdjustedPoint = getMapControl().getViewPort().toMapPoint(point);
275
		Point2D gridAdjustedPoint = getMapControl().getViewPort().toMapPoint(
276
				point);
265 277
		double minDistance = Double.MAX_VALUE;
266
		CADTool ct=(CADTool)cadToolStack.peek();
267
		if (ct instanceof SelectionCADTool && ((SelectionCADTool)ct).getStatus().equals("ExecuteMap.Initial")){
268
			mapAdjustedPoint=gridAdjustedPoint;
269
			adjustedPoint=(Point2D)point.clone();
270
		}else{
278
		CADTool ct = (CADTool) cadToolStack.peek();
279
		if (ct instanceof SelectionCADTool
280
				&& ((SelectionCADTool) ct).getStatus().equals(
281
						"ExecuteMap.Initial")) {
282
			mapAdjustedPoint = gridAdjustedPoint;
283
			adjustedPoint = (Point2D) point.clone();
284
		} else {
271 285

  
272
			minDistance= getGrid().adjustToGrid(gridAdjustedPoint);
286
			minDistance = getGrid().adjustToGrid(gridAdjustedPoint);
273 287
			if (minDistance < Double.MAX_VALUE) {
274
				adjustedPoint = getMapControl().getViewPort().fromMapPoint(gridAdjustedPoint);
288
				adjustedPoint = getMapControl().getViewPort().fromMapPoint(
289
						gridAdjustedPoint);
275 290
				mapAdjustedPoint = gridAdjustedPoint;
276 291
			} else {
277 292
				mapAdjustedPoint = null;
......
279 294
		}
280 295
		Point2D handlerAdjustedPoint = null;
281 296

  
282
		//Se comprueba el ajuste a los handlers
297
		// Se comprueba el ajuste a los handlers
283 298
		if (mapAdjustedPoint != null) {
284
			handlerAdjustedPoint = (Point2D) mapAdjustedPoint.clone(); //getMapControl().getViewPort().toMapPoint(point);
299
			handlerAdjustedPoint = (Point2D) mapAdjustedPoint.clone(); // getMapControl().getViewPort().toMapPoint(point);
285 300
		} else {
286
			handlerAdjustedPoint = getMapControl().getViewPort().toMapPoint(point);
301
			handlerAdjustedPoint = getMapControl().getViewPort().toMapPoint(
302
					point);
287 303
		}
288 304

  
289 305
		Point2D mapPoint = new Point2D.Double();
......
291 307

  
292 308
		if (distance < minDistance) {
293 309
			adjustSnapping = true;
294
			adjustedPoint = getMapControl().getViewPort().fromMapPoint(handlerAdjustedPoint);
310
			adjustedPoint = getMapControl().getViewPort().fromMapPoint(
311
					handlerAdjustedPoint);
295 312
			mapAdjustedPoint = mapPoint;
296 313
			minDistance = distance;
297 314
		}
298 315

  
299
		//Si no hay ajuste
316
		// Si no hay ajuste
300 317
		if (minDistance == Double.MAX_VALUE) {
301 318
			adjustedPoint = point;
302 319
			mapAdjustedPoint = null;
......
312 329
		ViewPort vp = getMapControl().getViewPort();
313 330
		// Point2D pReal = vp.toMapPoint(e.getPoint());
314 331

  
315
		Point2D pReal = new Point2D.Double(vp.getAdjustedExtent().getCenterX()
316
				, vp.getAdjustedExtent().getCenterY());
332
		Point2D pReal = new Point2D.Double(vp.getAdjustedExtent().getCenterX(),
333
				vp.getAdjustedExtent().getCenterY());
317 334
		int amount = e.getWheelRotation();
318
        double nuevoX;
319
        double nuevoY;
320
        double factor;
335
		double nuevoX;
336
		double nuevoY;
337
		double factor;
321 338

  
322 339
		if (amount > 0) // nos acercamos
323 340
		{
324 341
			factor = 0.9;
325
		}
326
		else // nos alejamos
342
		} else // nos alejamos
327 343
		{
328 344
			factor = 1.2;
329 345
		}
330
        Rectangle2D.Double r = new Rectangle2D.Double();
331
        if (vp.getExtent()!=null)
332
        {
333
	        nuevoX = pReal.getX() - ((vp.getExtent().getWidth() * factor) / 2.0);
334
	        nuevoY = pReal.getY() - ((vp.getExtent().getHeight() * factor) / 2.0);
335
	        r.x = nuevoX;
336
	        r.y = nuevoY;
337
	        r.width = vp.getExtent().getWidth() * factor;
338
	        r.height = vp.getExtent().getHeight() * factor;
346
		Rectangle2D.Double r = new Rectangle2D.Double();
347
		if (vp.getExtent() != null) {
348
			nuevoX = pReal.getX()
349
					- ((vp.getExtent().getWidth() * factor) / 2.0);
350
			nuevoY = pReal.getY()
351
					- ((vp.getExtent().getHeight() * factor) / 2.0);
352
			r.x = nuevoX;
353
			r.y = nuevoY;
354
			r.width = vp.getExtent().getWidth() * factor;
355
			r.height = vp.getExtent().getHeight() * factor;
339 356

  
340
	        vp.setExtent(r);
341
        }
357
			vp.setExtent(r);
358
		}
342 359
	}
343 360

  
344 361
	/**
345 362
	 * M?todo que realiza las transiciones en las herramientas en funci?n de un
346 363
	 * texto introducido en la consola
347
	 *
348
	 * @param text DOCUMENT ME!
364
	 * 
365
	 * @param text
366
	 *            DOCUMENT ME!
349 367
	 */
350 368
	public void textEntered(String text) {
351 369
		if (text == null) {
352 370
			transition("cancel");
353 371
		} else {
354
		/*	if ("".equals(text)) {
355
				transition("aceptar");
356
			} else {*/
357
				text = text.trim();
372
			/*
373
			 * if ("".equals(text)) { transition("aceptar"); } else {
374
			 */
375
			text = text.trim();
358 376

  
359
				String[] numbers = text.split(",");
360
				double[] values = null;
377
			String[] numbers = text.split(",");
378
			double[] values = null;
361 379

  
362
				try {
363
					if (numbers.length == 2) {
364
						//punto
365
						values = new double[] {
366
								Double.parseDouble(numbers[0]),
367
								Double.parseDouble(numbers[1])
368
							};
369
						transition( vea,
370
							values);
371
					} else if (numbers.length == 1) {
372
						//valor
373
						values = new double[] { Double.parseDouble(numbers[0]) };
374
						transition( vea,
375
							values[0]);
376
					}
377
				} catch (NumberFormatException e) {
378
					transition( vea,
379
						text);
380
			try {
381
				if (numbers.length == 2) {
382
					// punto
383
					values = new double[] { Double.parseDouble(numbers[0]),
384
							Double.parseDouble(numbers[1]) };
385
					transition(vea, values);
386
				} else if (numbers.length == 1) {
387
					// valor
388
					values = new double[] { Double.parseDouble(numbers[0]) };
389
					transition(vea, values[0]);
380 390
				}
381
			//}
391
			} catch (NumberFormatException e) {
392
				transition(vea, text);
393
			}
394
			// }
382 395
		}
383 396
		getMapControl().repaint();
384 397
	}
385 398

  
386 399
	/**
387 400
	 * Transici?n por comando ("cancel", actionCommand de una herramienta, etc).
388
	 *
389
	 * @param text DOCUMENT ME!
401
	 * 
402
	 * @param text
403
	 *            DOCUMENT ME!
390 404
	 */
391 405
	public void transition(String text) {
392
		transition( vea, text);
406
		transition(vea, text);
393 407
		// getMapControl().repaint();
394 408
	}
395 409

  
......
398 412
	 */
399 413
	public void configureMenu() {
400 414
		String[] desc = ((CADTool) cadToolStack.peek()).getDescriptions();
401
		//String[] labels = ((CADTool) cadToolStack.peek()).getCurrentTransitions();
415
		// String[] labels = ((CADTool)
416
		// cadToolStack.peek()).getCurrentTransitions();
402 417
		CADExtension.clearMenu();
403 418

  
404 419
		for (int i = 0; i < desc.length; i++) {
405 420
			if (desc[i] != null) {
406
				CADExtension.addMenuEntry(desc[i]);//, labels[i]);
421
				CADExtension.addMenuEntry(desc[i]);// , labels[i]);
407 422
			}
408 423
		}
409 424

  
......
411 426

  
412 427
	/**
413 428
	 * DOCUMENT ME!
414
	 *
415
	 * @param text DOCUMENT ME!
416
	 * @param source DOCUMENT ME!
417
	 * @param sel DOCUMENT ME!
418
	 * @param values DOCUMENT ME!
429
	 * 
430
	 * @param text
431
	 *            DOCUMENT ME!
432
	 * @param source
433
	 *            DOCUMENT ME!
434
	 * @param sel
435
	 *            DOCUMENT ME!
436
	 * @param values
437
	 *            DOCUMENT ME!
419 438
	 */
420
	private void transition( VectorialEditableAdapter source,
421
		double[] values) {
439
	private void transition(VectorialEditableAdapter source, double[] values) {
422 440
		questionAsked = true;
423
		if (!cadToolStack.isEmpty()){
424
		    CADTool ct = (CADTool) cadToolStack.peek();
425
		    ///String[] trs = ct.getAutomaton().getCurrentTransitions();
426
		    boolean esta = true;
427
		  /*  for (int i = 0; i < trs.length; i++) {
428
                if (trs[i].toUpperCase().equals(text.toUpperCase()))
429
                    esta = true;
430
            }
431
		    */
432
		    if (!esta){
433
		        askQuestion();
434
		    }else{
435
				ct.transition(values[0],values[1]);
436
				//Si es la transici?n que finaliza una geometria hay que redibujar la vista.
441
		if (!cadToolStack.isEmpty()) {
442
			CADTool ct = (CADTool) cadToolStack.peek();
443
			// /String[] trs = ct.getAutomaton().getCurrentTransitions();
444
			boolean esta = true;
445
			/*
446
			 * for (int i = 0; i < trs.length; i++) { if
447
			 * (trs[i].toUpperCase().equals(text.toUpperCase())) esta = true; }
448
			 */
449
			if (!esta) {
450
				askQuestion();
451
			} else {
452
				ct.transition(values[0], values[1]);
453
				// Si es la transici?n que finaliza una geometria hay que
454
				// redibujar la vista.
437 455

  
438 456
				askQuestion();
439
			/*	if ((ret & Automaton.AUTOMATON_FINISHED) == Automaton.AUTOMATON_FINISHED) {
440
					popCadTool();
441

  
442
					if (cadToolStack.isEmpty()) {
443
						pushCadTool(new com.iver.cit.gvsig.gui.cad.smc.gen.CADTool());//new SelectionCadTool());
444
						PluginServices.getMainFrame().setSelectedTool("selection");
445
					}
446

  
447
					askQuestion();
448

  
449
					getMapControl().drawMap(false);
450
				} else {
451
					if (((CadTool) cadToolStack.peek()).getAutomaton().checkState('c')) {
452
						getMapControl().drawMap(false);
453
					}
454

  
455
					if (!questionAsked) {
456
						askQuestion();
457
					}
458
				}
459

  
460
				configureMenu();*/
461
		    }
457
				/*
458
				 * if ((ret & Automaton.AUTOMATON_FINISHED) ==
459
				 * Automaton.AUTOMATON_FINISHED) { popCadTool();
460
				 * 
461
				 * if (cadToolStack.isEmpty()) { pushCadTool(new
462
				 * com.iver.cit.gvsig.gui.cad.smc.gen.CADTool());//new
463
				 * SelectionCadTool());
464
				 * PluginServices.getMainFrame().setSelectedTool("selection"); }
465
				 * 
466
				 * askQuestion();
467
				 * 
468
				 * getMapControl().drawMap(false); } else { if (((CadTool)
469
				 * cadToolStack.peek()).getAutomaton().checkState('c')) {
470
				 * getMapControl().drawMap(false); }
471
				 * 
472
				 * if (!questionAsked) { askQuestion(); } }
473
				 * 
474
				 * configureMenu();
475
				 */
476
			}
462 477
		}
463 478
		configureMenu();
464 479
		PluginServices.getMainFrame().enableControls();
465 480
	}
481

  
466 482
	/**
467 483
	 * DOCUMENT ME!
468
	 *
469
	 * @param text DOCUMENT ME!
470
	 * @param source DOCUMENT ME!
471
	 * @param sel DOCUMENT ME!
472
	 * @param values DOCUMENT ME!
484
	 * 
485
	 * @param text
486
	 *            DOCUMENT ME!
487
	 * @param source
488
	 *            DOCUMENT ME!
489
	 * @param sel
490
	 *            DOCUMENT ME!
491
	 * @param values
492
	 *            DOCUMENT ME!
473 493
	 */
474
	private void transition( VectorialEditableAdapter source,
475
		double value) {
494
	private void transition(VectorialEditableAdapter source, double value) {
476 495
		questionAsked = true;
477
		if (!cadToolStack.isEmpty()){
478
		    CADTool ct = (CADTool) cadToolStack.peek();
479
		    ct.transition(value);
496
		if (!cadToolStack.isEmpty()) {
497
			CADTool ct = (CADTool) cadToolStack.peek();
498
			ct.transition(value);
480 499
			askQuestion();
481
		    }
500
		}
482 501
		configureMenu();
483 502
		PluginServices.getMainFrame().enableControls();
484 503
	}
485
	private void transition(VectorialEditableAdapter source,
486
			String option) {
487
			questionAsked = true;
488
			if (!cadToolStack.isEmpty()){
489
			    CADTool ct = (CADTool) cadToolStack.peek();
490
			    ct.transition(option);
491
				askQuestion();
492
			    }
493
			configureMenu();
494
			PluginServices.getMainFrame().enableControls();
504

  
505
	private void transition(VectorialEditableAdapter source, String option) {
506
		questionAsked = true;
507
		if (!cadToolStack.isEmpty()) {
508
			CADTool ct = (CADTool) cadToolStack.peek();
509
			ct.transition(option);
510
			askQuestion();
511
		}
512
		configureMenu();
513
		PluginServices.getMainFrame().enableControls();
495 514
	}
515

  
496 516
	/**
497 517
	 * DOCUMENT ME!
498
	 *
499
	 * @param value DOCUMENT ME!
518
	 * 
519
	 * @param value
520
	 *            DOCUMENT ME!
500 521
	 */
501 522
	public void setGrid(boolean value) {
502 523
		getGrid().setUseGrid(value);
......
506 527

  
507 528
	/**
508 529
	 * DOCUMENT ME!
509
	 *
510
	 * @param activated DOCUMENT ME!
530
	 * 
531
	 * @param activated
532
	 *            DOCUMENT ME!
511 533
	 */
512 534
	public void setSnapping(boolean activated) {
513 535
		snapping = activated;
......
515 537

  
516 538
	/**
517 539
	 * DOCUMENT ME!
518
	 *
519
	 * @param x DOCUMENT ME!
520
	 * @param y DOCUMENT ME!
521
	 * @param dist DOCUMENT ME!
540
	 * 
541
	 * @param x
542
	 *            DOCUMENT ME!
543
	 * @param y
544
	 *            DOCUMENT ME!
545
	 * @param dist
546
	 *            DOCUMENT ME!
522 547
	 */
523 548
	public void getSnapPoint(double x, double y, double dist) {
524 549
	}
......
528 553
	 */
529 554
	public ToolListener getListener() {
530 555
		return new ToolListener() {
531
				/**
532
				 * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getCursor()
533
				 */
534
				public Cursor getCursor() {
535
					return null;
536
				}
556
			/**
557
			 * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getCursor()
558
			 */
559
			public Cursor getCursor() {
560
				return null;
561
			}
537 562

  
538
				/**
539
				 * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
540
				 */
541
				public boolean cancelDrawing() {
542
					return false;
543
				}
544
			};
563
			/**
564
			 * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
565
			 */
566
			public boolean cancelDrawing() {
567
				return false;
568
			}
569
		};
545 570
	}
546 571

  
547 572
	/**
548 573
	 * DOCUMENT ME!
549
	 *
574
	 * 
550 575
	 * @return DOCUMENT ME!
551 576
	 */
552 577
	public CADTool getCadTool() {
......
555 580

  
556 581
	/**
557 582
	 * DOCUMENT ME!
558
	 *
559
	 * @param cadTool DOCUMENT ME!
583
	 * 
584
	 * @param cadTool
585
	 *            DOCUMENT ME!
560 586
	 */
561 587
	public void pushCadTool(CADTool cadTool) {
562 588
		cadToolStack.push(cadTool);
563 589
		cadTool.setCadToolAdapter(this);
564
		//cadTool.initializeStatus();
565
		//cadTool.setVectorialAdapter(vea);
566
		/*int ret = cadTool.transition(null, editableFeatureSource, selection,
567
				new double[0]);
568

  
569
		if ((ret & Automaton.AUTOMATON_FINISHED) == Automaton.AUTOMATON_FINISHED) {
570
			popCadTool();
571

  
572
			if (cadToolStack.isEmpty()) {
573
				pushCadTool(new com.iver.cit.gvsig.gui.cad.smc.gen.CADTool());//new SelectionCadTool());
574
				PluginServices.getMainFrame().setSelectedTool("selection");
575
			}
576

  
577
			askQuestion();
578

  
579
			getMapControl().drawMap(false);
580
		}
581
		*/
590
		// cadTool.initializeStatus();
591
		// cadTool.setVectorialAdapter(vea);
592
		/*
593
		 * int ret = cadTool.transition(null, editableFeatureSource, selection,
594
		 * new double[0]);
595
		 * 
596
		 * if ((ret & Automaton.AUTOMATON_FINISHED) ==
597
		 * Automaton.AUTOMATON_FINISHED) { popCadTool();
598
		 * 
599
		 * if (cadToolStack.isEmpty()) { pushCadTool(new
600
		 * com.iver.cit.gvsig.gui.cad.smc.gen.CADTool());//new
601
		 * SelectionCadTool());
602
		 * PluginServices.getMainFrame().setSelectedTool("selection"); }
603
		 * 
604
		 * askQuestion();
605
		 * 
606
		 * getMapControl().drawMap(false); }
607
		 */
582 608
	}
583 609

  
584 610
	/**
......
592 618
	 * DOCUMENT ME!
593 619
	 */
594 620
	public void askQuestion() {
595
		CADTool cadtool=(CADTool) cadToolStack.peek();
596
		/*if (cadtool..getStatus()==0){
597
			PluginServices.getMainFrame().addTextToConsole("\n" +cadtool.getName());
598
		}
599
*/
621
		CADTool cadtool = (CADTool) cadToolStack.peek();
622
		/*
623
		 * if (cadtool..getStatus()==0){
624
		 * PluginServices.getMainFrame().addTextToConsole("\n"
625
		 * +cadtool.getName()); }
626
		 */
600 627
		View vista = (View) PluginServices.getMDIManager().getActiveView();
601
		vista.getConsolePanel().addText("\n" + cadtool.getQuestion()+">");
602
		//***PluginServices.getMainFrame().addTextToConsole("\n" + cadtool.getQuestion());
628
		vista.getConsolePanel().addText("\n" + cadtool.getQuestion() + ">");
629
		// ***PluginServices.getMainFrame().addTextToConsole("\n" +
630
		// cadtool.getQuestion());
603 631
		questionAsked = true;
604 632

  
605 633
	}
606 634

  
607 635
	/**
608 636
	 * DOCUMENT ME!
609
	 *
610
	 * @param cadTool DOCUMENT ME!
637
	 * 
638
	 * @param cadTool
639
	 *            DOCUMENT ME!
611 640
	 */
612 641
	public void setCadTool(CADTool cadTool) {
613 642
		cadToolStack.clear();
......
617 646

  
618 647
	/**
619 648
	 * DOCUMENT ME!
620
	 *
649
	 * 
621 650
	 * @return DOCUMENT ME!
622 651
	 */
623 652
	public VectorialEditableAdapter getVectorialAdapter() {
......
626 655

  
627 656
	/**
628 657
	 * DOCUMENT ME!
629
	 *
630
	 * @param editableFeatureSource DOCUMENT ME!
631
	 * @param selection DOCUMENT ME!
658
	 * 
659
	 * @param editableFeatureSource
660
	 *            DOCUMENT ME!
661
	 * @param selection
662
	 *            DOCUMENT ME!
632 663
	 */
633
	public void setVectorialAdapter(
634
		VectorialEditableAdapter vea) {
664
	public void setVectorialAdapter(VectorialEditableAdapter vea) {
635 665
		this.vea = vea;
636 666
	}
637 667

  
638 668
	/**
639 669
	 * DOCUMENT ME!
640
	 *
670
	 * 
641 671
	 * @return DOCUMENT ME!
642 672
	 */
643
	/*public CadMapControl getCadMapControl() {
644
		return cadMapControl;
645
	}
646
*/
673
	/*
674
	 * public CadMapControl getCadMapControl() { return cadMapControl; }
675
	 */
647 676
	/**
648 677
	 * DOCUMENT ME!
649
	 *
650
	 * @param cadMapControl DOCUMENT ME!
678
	 * 
679
	 * @param cadMapControl
680
	 *            DOCUMENT ME!
651 681
	 */
652
	/*public void setCadMapControl(CadMapControl cadMapControl) {
653
		this.cadMapControl = cadMapControl;
654
	}
655
*/
682
	/*
683
	 * public void setCadMapControl(CadMapControl cadMapControl) {
684
	 * this.cadMapControl = cadMapControl; }
685
	 */
656 686

  
657 687
	/**
658 688
	 * Elimina las geometr?as seleccionadas actualmente
659 689
	 */
660 690
	private void delete() {
661 691
		vea.startComplexRow();
662
		FBitSet selection=getVectorialAdapter().getSelection();
692
		FBitSet selection = getVectorialAdapter().getSelection();
663 693
		try {
664
			int[] indexesToDel=new int[selection.cardinality()];
665
			int j=0;
666
			for (int i = selection.nextSetBit(0); i >= 0;
667
					i = selection.nextSetBit(i + 1)) {
668
				indexesToDel[j++]=i;
669
				///vea.removeRow(i);
694
			int[] indexesToDel = new int[selection.cardinality()];
695
			int j = 0;
696
			for (int i = selection.nextSetBit(0); i >= 0; i = selection
697
					.nextSetBit(i + 1)) {
698
				indexesToDel[j++] = i;
699
				// /vea.removeRow(i);
670 700
			}
671
			for (j=indexesToDel.length-1;j>=0;j--){
701
			for (j = indexesToDel.length - 1; j >= 0; j--) {
672 702
				vea.removeRow(indexesToDel[j]);
673 703
			}
674 704
		} catch (DriverIOException e) {
......
691 721

  
692 722
	/**
693 723
	 * DOCUMENT ME!
694
	 *
724
	 * 
695 725
	 * @param b
696 726
	 */
697 727
	public void setAdjustGrid(boolean b) {
......
700 730

  
701 731
	/**
702 732
	 * DOCUMENT ME!
703
	 *
733
	 * 
704 734
	 * @param actionCommand
705 735
	 */
706 736
	public void keyPressed(String actionCommand) {
707 737
		if (actionCommand.equals("eliminar")) {
708 738
			delete();
709 739
		} else if (actionCommand.equals("escape")) {
710
			if (getMapControl().getTool().equals("cadtooladapter")){
740
			if (getMapControl().getTool().equals("cadtooladapter")) {
711 741
				CADTool ct = (CADTool) cadToolStack.peek();
712 742
				ct.end();
713 743
				cadToolStack.clear();
......
722 752
		PluginServices.getMainFrame().enableControls();
723 753

  
724 754
	}
725
	public CADGrid getGrid(){
755

  
756
	public CADGrid getGrid() {
726 757
		return cadgrid;
727 758
	}
759

  
760
	/**
761
	 * @return Returns the spatialCache.
762
	 */
763
	public SpatialIndex getSpatialCache() {
764
		return spatialCache;
765
	}
766

  
767
	/**
768
	 * @param spatialCache
769
	 *            The spatialCache to set.
770
	 */
771
	public void setSpatialCache(SpatialIndex spatialCache) {
772
		this.spatialCache = spatialCache;
773
	}
728 774
}

Also available in: Unified diff