svn-gvsig-desktop / trunk / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / CADToolAdapter.java @ 5165
History | View | Annotate | Download (24.3 KB)
1 |
package com.iver.cit.gvsig.gui.cad; |
---|---|
2 |
|
3 |
import java.awt.Color; |
4 |
import java.awt.Cursor; |
5 |
import java.awt.Graphics; |
6 |
import java.awt.Image; |
7 |
import java.awt.Point; |
8 |
import java.awt.Toolkit; |
9 |
import java.awt.event.InputEvent; |
10 |
import java.awt.event.MouseEvent; |
11 |
import java.awt.event.MouseWheelEvent; |
12 |
import java.awt.geom.Point2D; |
13 |
import java.awt.geom.Rectangle2D; |
14 |
import java.awt.image.MemoryImageSource; |
15 |
import java.io.IOException; |
16 |
import java.util.Stack; |
17 |
|
18 |
import com.iver.andami.PluginServices; |
19 |
import com.iver.cit.gvsig.CADExtension; |
20 |
import com.iver.cit.gvsig.fmap.DriverException; |
21 |
import com.iver.cit.gvsig.fmap.ViewPort; |
22 |
import com.iver.cit.gvsig.fmap.core.Handler; |
23 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
24 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
25 |
import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
26 |
import com.iver.cit.gvsig.fmap.core.v02.FConverter; |
27 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
28 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
29 |
import com.iver.cit.gvsig.fmap.edition.IRowEdited; |
30 |
import com.iver.cit.gvsig.fmap.edition.UtilFunctions; |
31 |
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter; |
32 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
33 |
import com.iver.cit.gvsig.fmap.tools.BehaviorException; |
34 |
import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior; |
35 |
import com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener; |
36 |
import com.iver.cit.gvsig.gui.View; |
37 |
import com.iver.cit.gvsig.gui.cad.tools.SelectionCADTool; |
38 |
import com.iver.cit.gvsig.layers.VectorialLayerEdited; |
39 |
import com.iver.utiles.console.JConsole; |
40 |
import com.vividsolutions.jts.geom.Envelope; |
41 |
import com.vividsolutions.jts.index.SpatialIndex; |
42 |
|
43 |
public class CADToolAdapter extends Behavior { |
44 |
public static int MAX_ENTITIES_IN_SPATIAL_CACHE = 5000; |
45 |
|
46 |
public static final int ABSOLUTE = 0; |
47 |
|
48 |
public static final int RELATIVE_SCP = 1; |
49 |
|
50 |
public static final int RELATIVE_SCU = 2; |
51 |
|
52 |
public static final int POLAR_SCP = 3; |
53 |
|
54 |
public static final int POLAR_SCU = 4; |
55 |
|
56 |
private double[] previousPoint = null; |
57 |
|
58 |
private Stack cadToolStack = new Stack(); |
59 |
|
60 |
// Para pasarle las coordenadas cuando se produce un evento textEntered
|
61 |
private int lastX; |
62 |
|
63 |
private int lastY; |
64 |
|
65 |
private FSymbol symbol = new FSymbol(FConstant.SYMBOL_TYPE_POINT, Color.RED); |
66 |
|
67 |
private Point2D mapAdjustedPoint; |
68 |
|
69 |
private boolean questionAsked = false; |
70 |
|
71 |
private Point2D adjustedPoint; |
72 |
|
73 |
private boolean snapping = false; |
74 |
|
75 |
private boolean adjustSnapping = false; |
76 |
|
77 |
private VectorialEditableAdapter vea;
|
78 |
|
79 |
private CADGrid cadgrid = new CADGrid(); |
80 |
|
81 |
private SpatialIndex spatialCache;
|
82 |
|
83 |
/**
|
84 |
* Pinta de alguna manera especial las geometrias seleccionadas para la
|
85 |
* edici?n. En caso de que el snapping est? activado, pintar? el efecto del
|
86 |
* mismo.
|
87 |
*
|
88 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#paintComponent(java.awt.Graphics)
|
89 |
*/
|
90 |
public void paintComponent(Graphics g) { |
91 |
super.paintComponent(g);
|
92 |
drawCursor(g); |
93 |
getGrid().drawGrid(g); |
94 |
if (adjustedPoint != null) { |
95 |
Point2D p = null; |
96 |
if (mapAdjustedPoint != null) { |
97 |
p = mapAdjustedPoint; |
98 |
} else {
|
99 |
p = getMapControl().getViewPort().toMapPoint(adjustedPoint); |
100 |
} |
101 |
((CADTool) cadToolStack.peek()) |
102 |
.drawOperation(g, p.getX(), p.getY()); |
103 |
} |
104 |
} |
105 |
|
106 |
/**
|
107 |
* @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
|
108 |
*/
|
109 |
public void mouseClicked(MouseEvent e) throws BehaviorException { |
110 |
if (e.getButton() == MouseEvent.BUTTON3) { |
111 |
CADExtension.showPopup(e); |
112 |
} |
113 |
} |
114 |
|
115 |
/**
|
116 |
* @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
|
117 |
*/
|
118 |
public void mouseEntered(MouseEvent e) throws BehaviorException { |
119 |
clearMouseImage(); |
120 |
} |
121 |
|
122 |
/**
|
123 |
* @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
|
124 |
*/
|
125 |
public void mouseExited(MouseEvent e) throws BehaviorException { |
126 |
} |
127 |
|
128 |
/**
|
129 |
* @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
|
130 |
*/
|
131 |
public void mousePressed(MouseEvent e) throws BehaviorException { |
132 |
if (e.getButton() == MouseEvent.BUTTON1) { |
133 |
ViewPort vp = getMapControl().getMapContext().getViewPort(); |
134 |
Point2D p;
|
135 |
|
136 |
if (mapAdjustedPoint != null) { |
137 |
p = mapAdjustedPoint; |
138 |
} else {
|
139 |
p = vp.toMapPoint(adjustedPoint); |
140 |
} |
141 |
transition(new double[] { p.getX(), p.getY() }, e, ABSOLUTE); |
142 |
} |
143 |
} |
144 |
|
145 |
/**
|
146 |
* Ajusta un punto de la imagen que se pasa como par?metro al grid si ?ste
|
147 |
* est? activo y devuelve la distancia de un punto al punto ajustado
|
148 |
*
|
149 |
* @param point
|
150 |
* @param mapHandlerAdjustedPoint
|
151 |
* DOCUMENT ME!
|
152 |
*
|
153 |
* @return Distancia del punto que se pasa como par?metro al punto ajustado
|
154 |
*/
|
155 |
private double adjustToHandler(Point2D point, |
156 |
Point2D mapHandlerAdjustedPoint) {
|
157 |
|
158 |
double rw = getMapControl().getViewPort().toMapDistance(5); |
159 |
Point2D mapPoint = point;
|
160 |
Rectangle2D r = new Rectangle2D.Double(mapPoint.getX() - rw / 2, |
161 |
mapPoint.getY() - rw / 2, rw, rw);
|
162 |
|
163 |
Envelope e = FConverter.convertRectangle2DtoEnvelope(r); |
164 |
double min = Double.MAX_VALUE; |
165 |
Point2D argmin = null; |
166 |
Point2D mapArgmin = null; |
167 |
|
168 |
IRowEdited[] feats;
|
169 |
ViewPort vp = getMapControl().getViewPort(); |
170 |
String strEPSG = vp.getProjection().getAbrev()
|
171 |
.substring(5);
|
172 |
try {
|
173 |
feats = vea.getFeatures(r, strEPSG); |
174 |
IGeometry geometry = null;
|
175 |
for (int i = 0; i < feats.length; i++) { |
176 |
IFeature feat = (IFeature) feats[i].getLinkedRow(); |
177 |
geometry = feat.getGeometry(); |
178 |
// TODO: PROVISIONAL. AVERIGUAR PORQU? DA FALLO EL DRIVER INDEXEDSHAPEDRIVER
|
179 |
|
180 |
if (geometry == null) break; |
181 |
Handler[] handlers = geometry.getHandlers(IGeometry.SELECTHANDLER); |
182 |
|
183 |
for (int j = 0; j < handlers.length; j++) { |
184 |
Point2D handlerPoint = handlers[j].getPoint();
|
185 |
// System.err.println("handlerPoint= "+ handlerPoint);
|
186 |
Point2D handlerImagePoint = handlerPoint;
|
187 |
double dist = handlerImagePoint.distance(point);
|
188 |
if ((dist < vp.toMapDistance(
|
189 |
SelectionCADTool.tolerance)) |
190 |
&& (dist < min)) { |
191 |
min = dist; |
192 |
argmin = handlerImagePoint; |
193 |
mapArgmin = handlerPoint; |
194 |
} |
195 |
} |
196 |
} |
197 |
} catch (DriverException e1) {
|
198 |
// TODO Auto-generated catch block
|
199 |
e1.printStackTrace(); |
200 |
} |
201 |
|
202 |
if (argmin != null) { |
203 |
point.setLocation(argmin); |
204 |
|
205 |
// Se hace el casting porque no se quiere redondeo
|
206 |
point.setLocation(argmin.getX(), argmin.getY()); |
207 |
|
208 |
mapHandlerAdjustedPoint.setLocation(mapArgmin); |
209 |
|
210 |
return min;
|
211 |
} |
212 |
|
213 |
return Double.MAX_VALUE; |
214 |
|
215 |
} |
216 |
|
217 |
/**
|
218 |
* @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
|
219 |
*/
|
220 |
public void mouseReleased(MouseEvent e) throws BehaviorException { |
221 |
getMapControl().repaint(); |
222 |
} |
223 |
|
224 |
/**
|
225 |
* @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent)
|
226 |
*/
|
227 |
public void mouseDragged(MouseEvent e) throws BehaviorException { |
228 |
lastX = e.getX(); |
229 |
lastY = e.getY(); |
230 |
|
231 |
calculateSnapPoint(e.getPoint()); |
232 |
} |
233 |
|
234 |
/**
|
235 |
* @see java.awt.event.MouseMotionListener#mouseMoved(java.awt.event.MouseEvent)
|
236 |
*/
|
237 |
public void mouseMoved(MouseEvent e) throws BehaviorException { |
238 |
|
239 |
lastX = e.getX(); |
240 |
lastY = e.getY(); |
241 |
|
242 |
calculateSnapPoint(e.getPoint()); |
243 |
|
244 |
getMapControl().repaint(); |
245 |
} |
246 |
|
247 |
private void clearMouseImage() { |
248 |
int[] pixels = new int[16 * 16]; |
249 |
Image image = Toolkit.getDefaultToolkit().createImage( |
250 |
new MemoryImageSource(16, 16, pixels, 0, 16)); |
251 |
Cursor transparentCursor = Toolkit.getDefaultToolkit() |
252 |
.createCustomCursor(image, new Point(0, 0), "invisiblecursor"); |
253 |
|
254 |
getMapControl().setCursor(transparentCursor); |
255 |
} |
256 |
|
257 |
/**
|
258 |
* DOCUMENT ME!
|
259 |
*
|
260 |
* @param g
|
261 |
* DOCUMENT ME!
|
262 |
*/
|
263 |
private void drawCursor(Graphics g) { |
264 |
|
265 |
Point2D p = adjustedPoint;
|
266 |
|
267 |
if (p == null) { |
268 |
getGrid().setViewPort(getMapControl().getViewPort()); |
269 |
|
270 |
return;
|
271 |
} |
272 |
|
273 |
int size1 = 15; |
274 |
int size2 = 3; |
275 |
g.drawLine((int) (p.getX() - size1), (int) (p.getY()), |
276 |
(int) (p.getX() + size1), (int) (p.getY())); |
277 |
g.drawLine((int) (p.getX()), (int) (p.getY() - size1), |
278 |
(int) (p.getX()), (int) (p.getY() + size1)); |
279 |
|
280 |
if (adjustedPoint != null) { |
281 |
if (adjustSnapping) {
|
282 |
g.setColor(Color.ORANGE);
|
283 |
g.drawRect((int) (adjustedPoint.getX() - 6), |
284 |
(int) (adjustedPoint.getY() - 6), 12, 12); |
285 |
g.drawRect((int) (adjustedPoint.getX() - 3), |
286 |
(int) (adjustedPoint.getY() - 3), 6, 6); |
287 |
g.setColor(Color.MAGENTA);
|
288 |
g.drawRect((int) (adjustedPoint.getX() - 4), |
289 |
(int) (adjustedPoint.getY() - 4), 8, 8); |
290 |
|
291 |
adjustSnapping = false;
|
292 |
} else {
|
293 |
g.drawRect((int) (p.getX() - size2), (int) (p.getY() - size2), |
294 |
(int) (size2 * 2), (int) (size2 * 2)); |
295 |
} |
296 |
} |
297 |
} |
298 |
|
299 |
/**
|
300 |
* DOCUMENT ME!
|
301 |
*
|
302 |
* @param point
|
303 |
*/
|
304 |
private void calculateSnapPoint(Point point) { |
305 |
// Se comprueba el ajuste a rejilla
|
306 |
|
307 |
Point2D gridAdjustedPoint = getMapControl().getViewPort().toMapPoint(
|
308 |
point); |
309 |
double minDistance = Double.MAX_VALUE; |
310 |
CADTool ct = (CADTool) cadToolStack.peek(); |
311 |
if (ct instanceof SelectionCADTool |
312 |
&& ((SelectionCADTool) ct).getStatus().equals( |
313 |
"Selection.FirstPoint")) {
|
314 |
mapAdjustedPoint = gridAdjustedPoint; |
315 |
adjustedPoint = (Point2D) point.clone();
|
316 |
} else {
|
317 |
|
318 |
minDistance = getGrid().adjustToGrid(gridAdjustedPoint); |
319 |
if (minDistance < Double.MAX_VALUE) { |
320 |
adjustedPoint = getMapControl().getViewPort().fromMapPoint( |
321 |
gridAdjustedPoint); |
322 |
mapAdjustedPoint = gridAdjustedPoint; |
323 |
} else {
|
324 |
mapAdjustedPoint = null;
|
325 |
} |
326 |
} |
327 |
Point2D handlerAdjustedPoint = null; |
328 |
|
329 |
// Se comprueba el ajuste a los handlers
|
330 |
if (mapAdjustedPoint != null) { |
331 |
handlerAdjustedPoint = (Point2D) mapAdjustedPoint.clone(); // getMapControl().getViewPort().toMapPoint(point); |
332 |
} else {
|
333 |
handlerAdjustedPoint = getMapControl().getViewPort().toMapPoint( |
334 |
point); |
335 |
} |
336 |
|
337 |
Point2D mapPoint = new Point2D.Double(); |
338 |
double distance = adjustToHandler(handlerAdjustedPoint, mapPoint);
|
339 |
|
340 |
if (distance < minDistance) {
|
341 |
adjustSnapping = true;
|
342 |
adjustedPoint = getMapControl().getViewPort().fromMapPoint( |
343 |
handlerAdjustedPoint); |
344 |
mapAdjustedPoint = mapPoint; |
345 |
minDistance = distance; |
346 |
} |
347 |
|
348 |
// Si no hay ajuste
|
349 |
if (minDistance == Double.MAX_VALUE) { |
350 |
adjustedPoint = point; |
351 |
mapAdjustedPoint = null;
|
352 |
} |
353 |
|
354 |
} |
355 |
|
356 |
/**
|
357 |
* @see java.awt.event.MouseWheelListener#mouseWheelMoved(java.awt.event.MouseWheelEvent)
|
358 |
*/
|
359 |
public void mouseWheelMoved(MouseWheelEvent e) throws BehaviorException { |
360 |
getMapControl().cancelDrawing(); |
361 |
ViewPort vp = getMapControl().getViewPort(); |
362 |
// Point2D pReal = vp.toMapPoint(e.getPoint());
|
363 |
|
364 |
Point2D pReal = new Point2D.Double(vp.getAdjustedExtent().getCenterX(), |
365 |
vp.getAdjustedExtent().getCenterY()); |
366 |
int amount = e.getWheelRotation();
|
367 |
double nuevoX;
|
368 |
double nuevoY;
|
369 |
double factor;
|
370 |
|
371 |
if (amount > 0) // nos acercamos |
372 |
{ |
373 |
factor = 0.9;
|
374 |
} else // nos alejamos |
375 |
{ |
376 |
factor = 1.2;
|
377 |
} |
378 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
379 |
if (vp.getExtent() != null) { |
380 |
nuevoX = pReal.getX() |
381 |
- ((vp.getExtent().getWidth() * factor) / 2.0);
|
382 |
nuevoY = pReal.getY() |
383 |
- ((vp.getExtent().getHeight() * factor) / 2.0);
|
384 |
r.x = nuevoX; |
385 |
r.y = nuevoY; |
386 |
r.width = vp.getExtent().getWidth() * factor; |
387 |
r.height = vp.getExtent().getHeight() * factor; |
388 |
|
389 |
vp.setExtent(r); |
390 |
} |
391 |
} |
392 |
|
393 |
/**
|
394 |
* M?todo que realiza las transiciones en las herramientas en funci?n de un
|
395 |
* texto introducido en la consola
|
396 |
*
|
397 |
* @param text
|
398 |
* DOCUMENT ME!
|
399 |
*/
|
400 |
public void textEntered(String text) { |
401 |
if (text == null) { |
402 |
transition("cancel");
|
403 |
} else {
|
404 |
/*
|
405 |
* if ("".equals(text)) { transition("aceptar"); } else {
|
406 |
*/
|
407 |
text = text.trim(); |
408 |
int type = ABSOLUTE;
|
409 |
String[] numbers = null; |
410 |
if (text.indexOf(",") != -1) { |
411 |
|
412 |
numbers = text.split(",");
|
413 |
if (numbers[0].substring(0, 1).equals("@")) { |
414 |
numbers[0] = numbers[0].substring(1, numbers[0].length()); |
415 |
type = RELATIVE_SCU; |
416 |
if (numbers[0].substring(0, 1).equals("*")) { |
417 |
type = RELATIVE_SCP; |
418 |
numbers[0] = numbers[0].substring(1, numbers[0] |
419 |
.length()); |
420 |
} |
421 |
} |
422 |
} else if (text.indexOf("<") != -1) { |
423 |
type = POLAR_SCP; |
424 |
numbers = text.split("<");
|
425 |
if (numbers[0].substring(0, 1).equals("@")) { |
426 |
numbers[0] = numbers[0].substring(1, numbers[0].length()); |
427 |
type = POLAR_SCU; |
428 |
if (numbers[0].substring(0, 1).equals("*")) { |
429 |
type = POLAR_SCP; |
430 |
numbers[0] = numbers[0].substring(1, numbers[0] |
431 |
.length()); |
432 |
} |
433 |
} |
434 |
} |
435 |
|
436 |
double[] values = null; |
437 |
|
438 |
try {
|
439 |
if (numbers.length == 2) { |
440 |
// punto
|
441 |
values = new double[] { Double.parseDouble(numbers[0]), |
442 |
Double.parseDouble(numbers[1]) }; |
443 |
transition(values, null, type);
|
444 |
} else if (numbers.length == 1) { |
445 |
// valor
|
446 |
values = new double[] { Double.parseDouble(numbers[0]) }; |
447 |
transition(values[0]);
|
448 |
} |
449 |
} catch (NumberFormatException e) { |
450 |
transition(text); |
451 |
} catch (NullPointerException e) { |
452 |
transition(text); |
453 |
} |
454 |
// }
|
455 |
} |
456 |
getMapControl().repaint(); |
457 |
} |
458 |
|
459 |
/**
|
460 |
* DOCUMENT ME!
|
461 |
*/
|
462 |
public void configureMenu() { |
463 |
String[] desc = ((CADTool) cadToolStack.peek()).getDescriptions(); |
464 |
// String[] labels = ((CADTool)
|
465 |
// cadToolStack.peek()).getCurrentTransitions();
|
466 |
CADExtension.clearMenu(); |
467 |
|
468 |
for (int i = 0; i < desc.length; i++) { |
469 |
if (desc[i] != null) { |
470 |
CADExtension |
471 |
.addMenuEntry(PluginServices.getText(this, desc[i]));// , |
472 |
// labels[i]);
|
473 |
} |
474 |
} |
475 |
|
476 |
} |
477 |
|
478 |
/**
|
479 |
* Recibe los valores de la transici?n (normalmente un punto) y el evento
|
480 |
* con el que se gener? (si fue de rat?n ser? MouseEvent, el que viene en el
|
481 |
* pressed) y si es de teclado, ser? un KeyEvent. Del evento se puede sacar
|
482 |
* informaci?n acerca de si estaba pulsada la tecla CTRL, o Alt, etc.
|
483 |
*
|
484 |
* @param values
|
485 |
* @param event
|
486 |
*/
|
487 |
private void transition(double[] values, InputEvent event, int type) { |
488 |
questionAsked = true;
|
489 |
if (!cadToolStack.isEmpty()) {
|
490 |
CADTool ct = (CADTool) cadToolStack.peek(); |
491 |
|
492 |
switch (type) {
|
493 |
case ABSOLUTE:
|
494 |
ct.transition(values[0], values[1], event); |
495 |
previousPoint = values; |
496 |
break;
|
497 |
case RELATIVE_SCU:
|
498 |
// Comprobar que tenemos almacenado el punto anterior
|
499 |
// y crear nuevo con coordenadas relativas a ?l.
|
500 |
double[] auxSCU = values; |
501 |
if (previousPoint != null) { |
502 |
auxSCU[0] = previousPoint[0] + values[0]; |
503 |
auxSCU[1] = previousPoint[1] + values[1]; |
504 |
} |
505 |
ct.transition(auxSCU[0], auxSCU[1], event); |
506 |
|
507 |
previousPoint = auxSCU; |
508 |
break;
|
509 |
case RELATIVE_SCP:
|
510 |
// TODO de momento no implementado.
|
511 |
ct.transition(values[0], values[1], event); |
512 |
previousPoint = values; |
513 |
break;
|
514 |
case POLAR_SCU:
|
515 |
// Comprobar que tenemos almacenado el punto anterior
|
516 |
// y crear nuevo con coordenadas relativas a ?l.
|
517 |
double[] auxPolarSCU = values; |
518 |
if (previousPoint != null) { |
519 |
Point2D point = UtilFunctions.getPoint(new Point2D.Double( |
520 |
previousPoint[0], previousPoint[1]), Math |
521 |
.toRadians(values[1]), values[0]); |
522 |
auxPolarSCU[0] = point.getX();
|
523 |
auxPolarSCU[1] = point.getY();
|
524 |
ct.transition(auxPolarSCU[0], auxPolarSCU[1], event); |
525 |
} else {
|
526 |
Point2D point = UtilFunctions.getPoint(new Point2D.Double( |
527 |
0, 0), Math.toRadians(values[1]), values[0]); |
528 |
auxPolarSCU[0] = point.getX();
|
529 |
auxPolarSCU[1] = point.getY();
|
530 |
ct.transition(auxPolarSCU[0], auxPolarSCU[1], event); |
531 |
} |
532 |
previousPoint = auxPolarSCU; |
533 |
break;
|
534 |
case POLAR_SCP:
|
535 |
double[] auxPolarSCP = values; |
536 |
if (previousPoint != null) { |
537 |
Point2D point = UtilFunctions.getPoint(new Point2D.Double( |
538 |
previousPoint[0], previousPoint[1]), values[1], |
539 |
values[0]);
|
540 |
auxPolarSCP[0] = point.getX();
|
541 |
auxPolarSCP[1] = point.getY();
|
542 |
ct.transition(auxPolarSCP[0], auxPolarSCP[1], event); |
543 |
} else {
|
544 |
Point2D point = UtilFunctions.getPoint(new Point2D.Double( |
545 |
0, 0), values[1], values[0]); |
546 |
auxPolarSCP[0] = point.getX();
|
547 |
auxPolarSCP[1] = point.getY();
|
548 |
ct.transition(auxPolarSCP[0], auxPolarSCP[1], event); |
549 |
} |
550 |
previousPoint = auxPolarSCP; |
551 |
break;
|
552 |
default:
|
553 |
break;
|
554 |
} |
555 |
askQuestion(); |
556 |
} |
557 |
configureMenu(); |
558 |
PluginServices.getMainFrame().enableControls(); |
559 |
} |
560 |
|
561 |
/**
|
562 |
* DOCUMENT ME!
|
563 |
*
|
564 |
* @param text
|
565 |
* DOCUMENT ME!
|
566 |
* @param source
|
567 |
* DOCUMENT ME!
|
568 |
* @param sel
|
569 |
* DOCUMENT ME!
|
570 |
* @param values
|
571 |
* DOCUMENT ME!
|
572 |
*/
|
573 |
private void transition(double value) { |
574 |
questionAsked = true;
|
575 |
if (!cadToolStack.isEmpty()) {
|
576 |
CADTool ct = (CADTool) cadToolStack.peek(); |
577 |
ct.transition(value); |
578 |
askQuestion(); |
579 |
} |
580 |
configureMenu(); |
581 |
PluginServices.getMainFrame().enableControls(); |
582 |
} |
583 |
|
584 |
public void transition(String option) { |
585 |
questionAsked = true;
|
586 |
if (!cadToolStack.isEmpty()) {
|
587 |
CADTool ct = (CADTool) cadToolStack.peek(); |
588 |
try {
|
589 |
ct.transition(option); |
590 |
} catch (Exception e) { |
591 |
View vista = (View) PluginServices.getMDIManager() |
592 |
.getActiveView(); |
593 |
vista.getConsolePanel().addText( |
594 |
"\n" + PluginServices.getText(this, "incorrect_option") |
595 |
+ " : " + option, JConsole.ERROR);
|
596 |
} |
597 |
askQuestion(); |
598 |
} |
599 |
configureMenu(); |
600 |
PluginServices.getMainFrame().enableControls(); |
601 |
} |
602 |
|
603 |
/**
|
604 |
* DOCUMENT ME!
|
605 |
*
|
606 |
* @param value
|
607 |
* DOCUMENT ME!
|
608 |
*/
|
609 |
public void setGrid(boolean value) { |
610 |
getGrid().setUseGrid(value); |
611 |
getGrid().setViewPort(getMapControl().getViewPort()); |
612 |
getMapControl().drawMap(false);
|
613 |
} |
614 |
|
615 |
/**
|
616 |
* DOCUMENT ME!
|
617 |
*
|
618 |
* @param activated
|
619 |
* DOCUMENT ME!
|
620 |
*/
|
621 |
public void setSnapping(boolean activated) { |
622 |
snapping = activated; |
623 |
} |
624 |
|
625 |
/**
|
626 |
* DOCUMENT ME!
|
627 |
*
|
628 |
* @param x
|
629 |
* DOCUMENT ME!
|
630 |
* @param y
|
631 |
* DOCUMENT ME!
|
632 |
* @param dist
|
633 |
* DOCUMENT ME!
|
634 |
*/
|
635 |
public void getSnapPoint(double x, double y, double dist) { |
636 |
} |
637 |
|
638 |
/**
|
639 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#getListener()
|
640 |
*/
|
641 |
public ToolListener getListener() {
|
642 |
return new ToolListener() { |
643 |
/**
|
644 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getCursor()
|
645 |
*/
|
646 |
public Cursor getCursor() { |
647 |
return null; |
648 |
} |
649 |
|
650 |
/**
|
651 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
|
652 |
*/
|
653 |
public boolean cancelDrawing() { |
654 |
return false; |
655 |
} |
656 |
}; |
657 |
} |
658 |
|
659 |
/**
|
660 |
* DOCUMENT ME!
|
661 |
*
|
662 |
* @return DOCUMENT ME!
|
663 |
*/
|
664 |
public CADTool getCadTool() {
|
665 |
return (CADTool) cadToolStack.peek();
|
666 |
} |
667 |
|
668 |
/**
|
669 |
* DOCUMENT ME!
|
670 |
*
|
671 |
* @param cadTool
|
672 |
* DOCUMENT ME!
|
673 |
*/
|
674 |
public void pushCadTool(CADTool cadTool) { |
675 |
cadToolStack.push(cadTool); |
676 |
cadTool.setCadToolAdapter(this);
|
677 |
// cadTool.initializeStatus();
|
678 |
// cadTool.setVectorialAdapter(vea);
|
679 |
/*
|
680 |
* int ret = cadTool.transition(null, editableFeatureSource, selection,
|
681 |
* new double[0]);
|
682 |
*
|
683 |
* if ((ret & Automaton.AUTOMATON_FINISHED) ==
|
684 |
* Automaton.AUTOMATON_FINISHED) { popCadTool();
|
685 |
*
|
686 |
* if (cadToolStack.isEmpty()) { pushCadTool(new
|
687 |
* com.iver.cit.gvsig.gui.cad.smc.gen.CADTool());//new
|
688 |
* SelectionCadTool());
|
689 |
* PluginServices.getMainFrame().setSelectedTool("selection"); }
|
690 |
*
|
691 |
* askQuestion();
|
692 |
*
|
693 |
* getMapControl().drawMap(false); }
|
694 |
*/
|
695 |
} |
696 |
|
697 |
/**
|
698 |
* DOCUMENT ME!
|
699 |
*/
|
700 |
public void popCadTool() { |
701 |
cadToolStack.pop(); |
702 |
} |
703 |
|
704 |
/**
|
705 |
* DOCUMENT ME!
|
706 |
*/
|
707 |
public void askQuestion() { |
708 |
CADTool cadtool = (CADTool) cadToolStack.peek(); |
709 |
/*
|
710 |
* if (cadtool..getStatus()==0){
|
711 |
* PluginServices.getMainFrame().addTextToConsole("\n"
|
712 |
* +cadtool.getName()); }
|
713 |
*/
|
714 |
View vista = (View) PluginServices.getMDIManager().getActiveView(); |
715 |
vista.getConsolePanel().addText( |
716 |
"\n" + "#" + cadtool.getQuestion() + " > ", JConsole.MESSAGE); |
717 |
// ***PluginServices.getMainFrame().addTextToConsole("\n" +
|
718 |
// cadtool.getQuestion());
|
719 |
questionAsked = true;
|
720 |
|
721 |
} |
722 |
|
723 |
/**
|
724 |
* DOCUMENT ME!
|
725 |
*
|
726 |
* @param cadTool
|
727 |
* DOCUMENT ME!
|
728 |
*/
|
729 |
public void setCadTool(CADTool cadTool) { |
730 |
cadToolStack.clear(); |
731 |
pushCadTool(cadTool); |
732 |
// askQuestion();
|
733 |
} |
734 |
|
735 |
/**
|
736 |
* DOCUMENT ME!
|
737 |
*
|
738 |
* @return DOCUMENT ME!
|
739 |
*/
|
740 |
public VectorialEditableAdapter getVectorialAdapter() {
|
741 |
return vea;
|
742 |
} |
743 |
|
744 |
/**
|
745 |
* DOCUMENT ME!
|
746 |
*
|
747 |
* @param editableFeatureSource
|
748 |
* DOCUMENT ME!
|
749 |
* @param selection
|
750 |
* DOCUMENT ME!
|
751 |
*/
|
752 |
public void setVectorialAdapter(VectorialEditableAdapter vea) { |
753 |
this.vea = vea;
|
754 |
} |
755 |
|
756 |
/**
|
757 |
* DOCUMENT ME!
|
758 |
*
|
759 |
* @return DOCUMENT ME!
|
760 |
*/
|
761 |
/*
|
762 |
* public CadMapControl getCadMapControl() { return cadMapControl; }
|
763 |
*/
|
764 |
/**
|
765 |
* DOCUMENT ME!
|
766 |
*
|
767 |
* @param cadMapControl
|
768 |
* DOCUMENT ME!
|
769 |
*/
|
770 |
/*
|
771 |
* public void setCadMapControl(CadMapControl cadMapControl) {
|
772 |
* this.cadMapControl = cadMapControl; }
|
773 |
*/
|
774 |
|
775 |
/**
|
776 |
* Elimina las geometr?as seleccionadas actualmente
|
777 |
*/
|
778 |
private void delete() { |
779 |
vea.startComplexRow(); |
780 |
FBitSet selection = getVectorialAdapter().getSelection(); |
781 |
try {
|
782 |
int[] indexesToDel = new int[selection.cardinality()]; |
783 |
int j = 0; |
784 |
for (int i = selection.nextSetBit(0); i >= 0; i = selection |
785 |
.nextSetBit(i + 1)) {
|
786 |
indexesToDel[j++] = i; |
787 |
// /vea.removeRow(i);
|
788 |
} |
789 |
/*
|
790 |
* VectorialLayerEdited vle = (VectorialLayerEdited) CADExtension
|
791 |
* .getEditionManager().getActiveLayerEdited(); ArrayList
|
792 |
* selectedRow = vle.getSelectedRow();
|
793 |
*
|
794 |
* int[] indexesToDel = new int[selectedRow.size()]; for (int i = 0;
|
795 |
* i < selectedRow.size(); i++) { IRowEdited edRow = (IRowEdited)
|
796 |
* selectedRow.get(i); indexesToDel[i] = edRow.getIndex(); }
|
797 |
*/
|
798 |
for (int i = indexesToDel.length - 1; i >= 0; i--) { |
799 |
vea.removeRow(indexesToDel[i], PluginServices.getText(this,
|
800 |
"deleted_feature"));
|
801 |
} |
802 |
} catch (DriverIOException e) {
|
803 |
e.printStackTrace(); |
804 |
} catch (IOException e) { |
805 |
e.printStackTrace(); |
806 |
} finally {
|
807 |
try {
|
808 |
vea.endComplexRow(); |
809 |
} catch (IOException e1) { |
810 |
e1.printStackTrace(); |
811 |
} catch (DriverIOException e1) {
|
812 |
e1.printStackTrace(); |
813 |
} |
814 |
} |
815 |
System.out.println("clear Selection"); |
816 |
selection.clear(); |
817 |
VectorialLayerEdited vle = (VectorialLayerEdited) CADExtension |
818 |
.getEditionManager().getActiveLayerEdited(); |
819 |
vle.clearSelection(); |
820 |
/*
|
821 |
* if (getCadTool() instanceof SelectionCADTool) { SelectionCADTool
|
822 |
* selTool = (SelectionCADTool) getCadTool(); selTool.clearSelection(); }
|
823 |
*/
|
824 |
getMapControl().drawMap(false);
|
825 |
} |
826 |
|
827 |
/**
|
828 |
* DOCUMENT ME!
|
829 |
*
|
830 |
* @param b
|
831 |
*/
|
832 |
public void setAdjustGrid(boolean b) { |
833 |
getGrid().setAdjustGrid(b); |
834 |
} |
835 |
|
836 |
/**
|
837 |
* DOCUMENT ME!
|
838 |
*
|
839 |
* @param actionCommand
|
840 |
*/
|
841 |
public void keyPressed(String actionCommand) { |
842 |
if (actionCommand.equals("eliminar")) { |
843 |
delete(); |
844 |
} else if (actionCommand.equals("escape")) { |
845 |
if (getMapControl().getTool().equals("cadtooladapter")) { |
846 |
CADTool ct = (CADTool) cadToolStack.peek(); |
847 |
ct.end(); |
848 |
cadToolStack.clear(); |
849 |
SelectionCADTool selCad = new SelectionCADTool();
|
850 |
selCad.init(); |
851 |
VectorialLayerEdited vle = (VectorialLayerEdited) CADExtension |
852 |
.getEditionManager().getActiveLayerEdited(); |
853 |
vle.clearSelection(); |
854 |
|
855 |
pushCadTool(selCad); |
856 |
// getVectorialAdapter().getSelection().clear();
|
857 |
getMapControl().drawMap(false);
|
858 |
PluginServices.getMainFrame().setSelectedTool("_selection");
|
859 |
// askQuestion();
|
860 |
} else {
|
861 |
getMapControl().setPrevTool(); |
862 |
} |
863 |
} |
864 |
|
865 |
PluginServices.getMainFrame().enableControls(); |
866 |
|
867 |
} |
868 |
|
869 |
public CADGrid getGrid() {
|
870 |
return cadgrid;
|
871 |
} |
872 |
|
873 |
/**
|
874 |
* @return Returns the spatialCache.
|
875 |
*/
|
876 |
public SpatialIndex getSpatialCache() {
|
877 |
return spatialCache;
|
878 |
} |
879 |
|
880 |
/**
|
881 |
* Se usa para rellenar la cache de entidades con la que queremos trabajar
|
882 |
* (para hacer snapping, por ejemplo. Lo normal ser? rellenarla cada vez que
|
883 |
* cambie el extent, y bas?ndonos en el futuro EditionManager para saber de
|
884 |
* cu?ntos temas hay que leer. Si el numero de entidades supera
|
885 |
* MAX_ENTITIES_IN_SPATIAL_CACHE, lo pondremos a nulo.
|
886 |
*
|
887 |
* @throws DriverException
|
888 |
*/
|
889 |
/*
|
890 |
* public void createSpatialCache() throws DriverException { ViewPort vp =
|
891 |
* getMapControl().getViewPort(); Rectangle2D extent =
|
892 |
* vp.getAdjustedExtent(); // TODO: Por ahora cogemos el VectorialAdapter //
|
893 |
* de aqu?, pero deber?amos tener un m?todo que // le pregunte al
|
894 |
* EditionManager el tema sobre // el que estamos pintando. String strEPSG =
|
895 |
* vp.getProjection().getAbrev().substring(5); IRowEdited[] feats =
|
896 |
* getVectorialAdapter().getFeatures(extent, strEPSG); if (feats.length >
|
897 |
* MAX_ENTITIES_IN_SPATIAL_CACHE) this.spatialCache = null; else
|
898 |
* this.spatialCache = new Quadtree(); for (int i=0; i < feats.length; i++) {
|
899 |
* IFeature feat = (IFeature)feats[i].getLinkedRow(); IGeometry geom =
|
900 |
* feat.getGeometry(); // TODO: EL getBounds2D del IGeometry ralentiza
|
901 |
* innecesariamente // Podr?amos hacer que GeneralPathX lo tenga guardado, //
|
902 |
* y tenga un constructor en el que se lo fijes. // De esta forma, el
|
903 |
* driver, a la vez que recupera // las geometr?as podr?a calcular el
|
904 |
* boundingbox // y asignarlo. Luego habr?a que poner un m?todo // que
|
905 |
* recalcule el bounding box bajo demanda.
|
906 |
*
|
907 |
* Envelope e = FConverter.convertRectangle2DtoEnvelope(geom.getBounds2D());
|
908 |
* spatialCache.insert(e, geom); } }
|
909 |
*/
|
910 |
} |