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