svn-gvsig-desktop / trunk / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / CADToolAdapter.java @ 3996
History | View | Annotate | Download (17.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.MouseEvent; |
10 |
import java.awt.event.MouseWheelEvent; |
11 |
import java.awt.geom.Point2D; |
12 |
import java.awt.geom.Rectangle2D; |
13 |
import java.awt.image.MemoryImageSource; |
14 |
import java.io.IOException; |
15 |
import java.util.Stack; |
16 |
|
17 |
import com.iver.andami.PluginServices; |
18 |
import com.iver.cit.gvsig.CADExtension; |
19 |
import com.iver.cit.gvsig.fmap.DriverException; |
20 |
import com.iver.cit.gvsig.fmap.MapControl; |
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.FSymbol; |
27 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
28 |
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter; |
29 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
30 |
import com.iver.cit.gvsig.fmap.tools.BehaviorException; |
31 |
import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior; |
32 |
import com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener; |
33 |
import com.iver.cit.gvsig.gui.View; |
34 |
import com.iver.cit.gvsig.gui.cad.tools.SelectionCADTool; |
35 |
|
36 |
public class CADToolAdapter extends Behavior { |
37 |
private Stack cadToolStack = new Stack(); |
38 |
|
39 |
//Para pasarle las coordenadas cuando se produce un evento textEntered
|
40 |
private int lastX; |
41 |
private int lastY; |
42 |
private FSymbol symbol = new FSymbol(FConstant.SYMBOL_TYPE_POINT, Color.RED); |
43 |
private Point2D mapAdjustedPoint; |
44 |
private boolean questionAsked = false; |
45 |
private Point2D adjustedPoint; |
46 |
private boolean snapping = false; |
47 |
private boolean adjustSnapping = false; |
48 |
private VectorialEditableAdapter vea;
|
49 |
private CADGrid cadgrid=new CADGrid(); |
50 |
|
51 |
/**
|
52 |
* 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 |
*
|
56 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#paintComponent(java.awt.Graphics)
|
57 |
*/
|
58 |
public void paintComponent(Graphics g) { |
59 |
super.paintComponent(g);
|
60 |
drawCursor(g); |
61 |
getGrid().drawGrid(g); |
62 |
if (adjustedPoint != null) { |
63 |
Point2D p=null; |
64 |
if (mapAdjustedPoint != null) { |
65 |
p = mapAdjustedPoint; |
66 |
} else {
|
67 |
p = getMapControl().getViewPort().toMapPoint(adjustedPoint); |
68 |
} |
69 |
((CADTool) cadToolStack.peek()).drawOperation(g, |
70 |
p.getX(), p.getY()); |
71 |
} |
72 |
} |
73 |
|
74 |
/**
|
75 |
* @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
|
76 |
*/
|
77 |
public void mouseClicked(MouseEvent e) throws BehaviorException { |
78 |
if (e.getButton()==MouseEvent.BUTTON3){ |
79 |
CADExtension.showPopup(e); |
80 |
} |
81 |
} |
82 |
|
83 |
/**
|
84 |
* @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
|
85 |
*/
|
86 |
public void mouseEntered(MouseEvent e) throws BehaviorException { |
87 |
clearMouseImage(); |
88 |
} |
89 |
|
90 |
/**
|
91 |
* @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
|
92 |
*/
|
93 |
public void mouseExited(MouseEvent e) throws BehaviorException { |
94 |
} |
95 |
|
96 |
/**
|
97 |
* @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
|
98 |
*/
|
99 |
public void mousePressed(MouseEvent e) throws BehaviorException { |
100 |
if (e.getButton() == MouseEvent.BUTTON1) { |
101 |
ViewPort vp = getMapControl().getMapContext().getViewPort(); |
102 |
Point2D p;
|
103 |
|
104 |
if (mapAdjustedPoint != null) { |
105 |
p = mapAdjustedPoint; |
106 |
} else {
|
107 |
p = vp.toMapPoint(adjustedPoint); |
108 |
} |
109 |
transition(vea, |
110 |
new double[] { p.getX(), p.getY() }); |
111 |
} |
112 |
} |
113 |
|
114 |
/**
|
115 |
* Ajusta un punto de la imagen que se pasa como par?metro al grid si ?ste
|
116 |
* est? activo y devuelve la distancia de un punto al punto ajustado
|
117 |
*
|
118 |
* @param point
|
119 |
* @param mapHandlerAdjustedPoint DOCUMENT ME!
|
120 |
*
|
121 |
* @return Distancia del punto que se pasa como par?metro al punto ajustado
|
122 |
*/
|
123 |
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);
|
131 |
|
132 |
int[] indexes = vea.getRowsIndexes(r); |
133 |
|
134 |
double min = Double.MAX_VALUE; |
135 |
Point2D argmin = null; |
136 |
Point2D mapArgmin = null; |
137 |
|
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 |
} |
154 |
} |
155 |
} |
156 |
|
157 |
if (argmin != null) { |
158 |
point.setLocation(argmin); |
159 |
|
160 |
//Se hace el casting porque no se quiere redondeo
|
161 |
point.setLocation(argmin.getX(), argmin.getY()); |
162 |
|
163 |
mapHandlerAdjustedPoint.setLocation(mapArgmin); |
164 |
|
165 |
return min;
|
166 |
} |
167 |
} catch (DriverIOException e) {
|
168 |
// TODO Auto-generated catch block
|
169 |
e.printStackTrace(); |
170 |
} |
171 |
|
172 |
return Double.MAX_VALUE; |
173 |
|
174 |
} |
175 |
|
176 |
/**
|
177 |
* @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
|
178 |
*/
|
179 |
public void mouseReleased(MouseEvent e) throws BehaviorException { |
180 |
getMapControl().repaint(); |
181 |
} |
182 |
|
183 |
/**
|
184 |
* @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent)
|
185 |
*/
|
186 |
public void mouseDragged(MouseEvent e) throws BehaviorException { |
187 |
lastX = e.getX(); |
188 |
lastY = e.getY(); |
189 |
|
190 |
calculateSnapPoint(e.getPoint()); |
191 |
} |
192 |
|
193 |
/**
|
194 |
* @see java.awt.event.MouseMotionListener#mouseMoved(java.awt.event.MouseEvent)
|
195 |
*/
|
196 |
public void mouseMoved(MouseEvent e) throws BehaviorException { |
197 |
|
198 |
lastX = e.getX(); |
199 |
lastY = e.getY(); |
200 |
|
201 |
calculateSnapPoint(e.getPoint()); |
202 |
|
203 |
getMapControl().repaint(); |
204 |
} |
205 |
private void clearMouseImage(){ |
206 |
int[] pixels = new int[16 * 16]; |
207 |
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"); |
212 |
|
213 |
getMapControl().setCursor(transparentCursor); |
214 |
} |
215 |
/**
|
216 |
* DOCUMENT ME!
|
217 |
*
|
218 |
* @param g DOCUMENT ME!
|
219 |
*/
|
220 |
private void drawCursor(Graphics g) { |
221 |
|
222 |
Point2D p = adjustedPoint;
|
223 |
|
224 |
if (p == null) { |
225 |
getGrid().setViewPort(getMapControl().getViewPort()); |
226 |
|
227 |
return;
|
228 |
} |
229 |
|
230 |
int size1 = 15; |
231 |
int size2 = 3; |
232 |
g.drawLine((int) (p.getX() - size1), (int) (p.getY()), |
233 |
(int) (p.getX() + size1), (int) (p.getY())); |
234 |
g.drawLine((int) (p.getX()), (int) (p.getY() - size1), |
235 |
(int) (p.getX()), (int) (p.getY() + size1)); |
236 |
|
237 |
if (adjustedPoint != null) { |
238 |
if (adjustSnapping) {
|
239 |
g.setColor(Color.ORANGE);
|
240 |
g.drawRect((int) (adjustedPoint.getX() - 6), |
241 |
(int) (adjustedPoint.getY() - 6), 12, 12); |
242 |
g.drawRect((int) (adjustedPoint.getX() - 3), |
243 |
(int) (adjustedPoint.getY() - 3), 6, 6); |
244 |
g.setColor(Color.MAGENTA);
|
245 |
g.drawRect((int) (adjustedPoint.getX() - 4), |
246 |
(int) (adjustedPoint.getY() - 4), 8, 8); |
247 |
|
248 |
adjustSnapping = false;
|
249 |
} else {
|
250 |
g.drawRect((int) (p.getX() - size2), (int) (p.getY() - size2), |
251 |
(int) (size2 * 2), (int) (size2 * 2)); |
252 |
} |
253 |
} |
254 |
} |
255 |
|
256 |
/**
|
257 |
* DOCUMENT ME!
|
258 |
*
|
259 |
* @param point
|
260 |
*/
|
261 |
private void calculateSnapPoint(Point point) { |
262 |
//Se comprueba el ajuste a rejilla
|
263 |
|
264 |
Point2D gridAdjustedPoint = getMapControl().getViewPort().toMapPoint(point);
|
265 |
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{
|
271 |
|
272 |
minDistance= getGrid().adjustToGrid(gridAdjustedPoint); |
273 |
if (minDistance < Double.MAX_VALUE) { |
274 |
adjustedPoint = getMapControl().getViewPort().fromMapPoint(gridAdjustedPoint); |
275 |
mapAdjustedPoint = gridAdjustedPoint; |
276 |
} else {
|
277 |
mapAdjustedPoint = null;
|
278 |
} |
279 |
} |
280 |
Point2D handlerAdjustedPoint = null; |
281 |
|
282 |
//Se comprueba el ajuste a los handlers
|
283 |
if (mapAdjustedPoint != null) { |
284 |
handlerAdjustedPoint = (Point2D) mapAdjustedPoint.clone(); //getMapControl().getViewPort().toMapPoint(point); |
285 |
} else {
|
286 |
handlerAdjustedPoint = getMapControl().getViewPort().toMapPoint(point); |
287 |
} |
288 |
|
289 |
Point2D mapPoint = new Point2D.Double(); |
290 |
double distance = adjustToHandler(handlerAdjustedPoint, mapPoint);
|
291 |
|
292 |
if (distance < minDistance) {
|
293 |
adjustSnapping = true;
|
294 |
adjustedPoint = getMapControl().getViewPort().fromMapPoint(handlerAdjustedPoint); |
295 |
mapAdjustedPoint = mapPoint; |
296 |
minDistance = distance; |
297 |
} |
298 |
|
299 |
//Si no hay ajuste
|
300 |
if (minDistance == Double.MAX_VALUE) { |
301 |
adjustedPoint = point; |
302 |
mapAdjustedPoint = null;
|
303 |
} |
304 |
|
305 |
} |
306 |
|
307 |
/**
|
308 |
* @see java.awt.event.MouseWheelListener#mouseWheelMoved(java.awt.event.MouseWheelEvent)
|
309 |
*/
|
310 |
public void mouseWheelMoved(MouseWheelEvent e) throws BehaviorException { |
311 |
getMapControl().cancelDrawing(); |
312 |
ViewPort vp = getMapControl().getViewPort(); |
313 |
// Point2D pReal = vp.toMapPoint(e.getPoint());
|
314 |
|
315 |
Point2D pReal = new Point2D.Double(vp.getAdjustedExtent().getCenterX() |
316 |
, vp.getAdjustedExtent().getCenterY()); |
317 |
int amount = e.getWheelRotation();
|
318 |
double nuevoX;
|
319 |
double nuevoY;
|
320 |
double factor;
|
321 |
|
322 |
if (amount > 0) // nos acercamos |
323 |
{ |
324 |
factor = 0.9;
|
325 |
} |
326 |
else // nos alejamos |
327 |
{ |
328 |
factor = 1.2;
|
329 |
} |
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; |
339 |
|
340 |
vp.setExtent(r); |
341 |
} |
342 |
} |
343 |
|
344 |
/**
|
345 |
* M?todo que realiza las transiciones en las herramientas en funci?n de un
|
346 |
* texto introducido en la consola
|
347 |
*
|
348 |
* @param text DOCUMENT ME!
|
349 |
*/
|
350 |
public void textEntered(String text) { |
351 |
if (text == null) { |
352 |
transition("cancel");
|
353 |
} else {
|
354 |
/* if ("".equals(text)) {
|
355 |
transition("aceptar");
|
356 |
} else {*/
|
357 |
text = text.trim(); |
358 |
|
359 |
String[] numbers = text.split(","); |
360 |
double[] values = null; |
361 |
|
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 |
} |
381 |
//}
|
382 |
} |
383 |
|
384 |
} |
385 |
|
386 |
/**
|
387 |
* DOCUMENT ME!
|
388 |
*
|
389 |
* @param text DOCUMENT ME!
|
390 |
*/
|
391 |
public void transition(String text) { |
392 |
transition( vea, text); |
393 |
|
394 |
} |
395 |
|
396 |
/**
|
397 |
* DOCUMENT ME!
|
398 |
*/
|
399 |
public void configureMenu() { |
400 |
String[] desc = ((CADTool) cadToolStack.peek()).getDescriptions(); |
401 |
//String[] labels = ((CADTool) cadToolStack.peek()).getCurrentTransitions();
|
402 |
CADExtension.clearMenu(); |
403 |
|
404 |
for (int i = 0; i < desc.length; i++) { |
405 |
if (desc[i] != null) { |
406 |
CADExtension.addMenuEntry(desc[i]);//, labels[i]);
|
407 |
} |
408 |
} |
409 |
|
410 |
} |
411 |
|
412 |
/**
|
413 |
* DOCUMENT ME!
|
414 |
*
|
415 |
* @param text DOCUMENT ME!
|
416 |
* @param source DOCUMENT ME!
|
417 |
* @param sel DOCUMENT ME!
|
418 |
* @param values DOCUMENT ME!
|
419 |
*/
|
420 |
private void transition( VectorialEditableAdapter source, |
421 |
double[] values) { |
422 |
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.
|
437 |
|
438 |
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 |
} |
462 |
} |
463 |
configureMenu(); |
464 |
//PluginServices.getMainFrame().enableControls();
|
465 |
} |
466 |
/**
|
467 |
* DOCUMENT ME!
|
468 |
*
|
469 |
* @param text DOCUMENT ME!
|
470 |
* @param source DOCUMENT ME!
|
471 |
* @param sel DOCUMENT ME!
|
472 |
* @param values DOCUMENT ME!
|
473 |
*/
|
474 |
private void transition( VectorialEditableAdapter source, |
475 |
double value) {
|
476 |
questionAsked = true;
|
477 |
if (!cadToolStack.isEmpty()){
|
478 |
CADTool ct = (CADTool) cadToolStack.peek(); |
479 |
ct.transition(value); |
480 |
askQuestion(); |
481 |
} |
482 |
configureMenu(); |
483 |
PluginServices.getMainFrame().enableControls(); |
484 |
} |
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();
|
495 |
} |
496 |
/**
|
497 |
* DOCUMENT ME!
|
498 |
*
|
499 |
* @param value DOCUMENT ME!
|
500 |
*/
|
501 |
public void setGrid(boolean value) { |
502 |
getGrid().setUseGrid(value); |
503 |
getGrid().setViewPort(getMapControl().getViewPort()); |
504 |
getMapControl().drawMap(false);
|
505 |
} |
506 |
|
507 |
/**
|
508 |
* DOCUMENT ME!
|
509 |
*
|
510 |
* @param activated DOCUMENT ME!
|
511 |
*/
|
512 |
public void setSnapping(boolean activated) { |
513 |
snapping = activated; |
514 |
} |
515 |
|
516 |
/**
|
517 |
* DOCUMENT ME!
|
518 |
*
|
519 |
* @param x DOCUMENT ME!
|
520 |
* @param y DOCUMENT ME!
|
521 |
* @param dist DOCUMENT ME!
|
522 |
*/
|
523 |
public void getSnapPoint(double x, double y, double dist) { |
524 |
} |
525 |
|
526 |
/**
|
527 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#getListener()
|
528 |
*/
|
529 |
public ToolListener getListener() {
|
530 |
return new ToolListener() { |
531 |
/**
|
532 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getCursor()
|
533 |
*/
|
534 |
public Cursor getCursor() { |
535 |
return null; |
536 |
} |
537 |
|
538 |
/**
|
539 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
|
540 |
*/
|
541 |
public boolean cancelDrawing() { |
542 |
return false; |
543 |
} |
544 |
}; |
545 |
} |
546 |
|
547 |
/**
|
548 |
* DOCUMENT ME!
|
549 |
*
|
550 |
* @return DOCUMENT ME!
|
551 |
*/
|
552 |
public CADTool getCadTool() {
|
553 |
return (CADTool) cadToolStack.peek();
|
554 |
} |
555 |
|
556 |
/**
|
557 |
* DOCUMENT ME!
|
558 |
*
|
559 |
* @param cadTool DOCUMENT ME!
|
560 |
*/
|
561 |
public void pushCadTool(CADTool cadTool) { |
562 |
cadToolStack.push(cadTool); |
563 |
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 |
*/
|
582 |
} |
583 |
|
584 |
/**
|
585 |
* DOCUMENT ME!
|
586 |
*/
|
587 |
public void popCadTool() { |
588 |
cadToolStack.pop(); |
589 |
} |
590 |
|
591 |
/**
|
592 |
* DOCUMENT ME!
|
593 |
*/
|
594 |
public void askQuestion() { |
595 |
CADTool cadtool=(CADTool) cadToolStack.peek(); |
596 |
/*if (cadtool..getStatus()==0){
|
597 |
PluginServices.getMainFrame().addTextToConsole("\n" +cadtool.getName());
|
598 |
}
|
599 |
*/
|
600 |
View vista = (View) PluginServices.getMDIManager().getActiveView(); |
601 |
vista.getConsolePanel().addText("\n" + cadtool.getQuestion()+">"); |
602 |
//***PluginServices.getMainFrame().addTextToConsole("\n" + cadtool.getQuestion());
|
603 |
questionAsked = true;
|
604 |
|
605 |
} |
606 |
|
607 |
/**
|
608 |
* DOCUMENT ME!
|
609 |
*
|
610 |
* @param cadTool DOCUMENT ME!
|
611 |
*/
|
612 |
public void setCadTool(CADTool cadTool) { |
613 |
cadToolStack.clear(); |
614 |
pushCadTool(cadTool); |
615 |
askQuestion(); |
616 |
} |
617 |
|
618 |
/**
|
619 |
* DOCUMENT ME!
|
620 |
*
|
621 |
* @return DOCUMENT ME!
|
622 |
*/
|
623 |
public VectorialEditableAdapter getVectorialAdapter() {
|
624 |
return vea;
|
625 |
} |
626 |
|
627 |
/**
|
628 |
* DOCUMENT ME!
|
629 |
*
|
630 |
* @param editableFeatureSource DOCUMENT ME!
|
631 |
* @param selection DOCUMENT ME!
|
632 |
*/
|
633 |
public void setVectorialAdapter( |
634 |
VectorialEditableAdapter vea) { |
635 |
this.vea = vea;
|
636 |
} |
637 |
|
638 |
/**
|
639 |
* DOCUMENT ME!
|
640 |
*
|
641 |
* @return DOCUMENT ME!
|
642 |
*/
|
643 |
/*public CadMapControl getCadMapControl() {
|
644 |
return cadMapControl;
|
645 |
}
|
646 |
*/
|
647 |
/**
|
648 |
* DOCUMENT ME!
|
649 |
*
|
650 |
* @param cadMapControl DOCUMENT ME!
|
651 |
*/
|
652 |
/*public void setCadMapControl(CadMapControl cadMapControl) {
|
653 |
this.cadMapControl = cadMapControl;
|
654 |
}
|
655 |
*/
|
656 |
|
657 |
/**
|
658 |
* Elimina las geometr?as seleccionadas actualmente
|
659 |
*/
|
660 |
private void delete() { |
661 |
vea.startComplexRow(); |
662 |
FBitSet selection=getVectorialAdapter().getSelection(); |
663 |
try {
|
664 |
for (int i = selection.nextSetBit(0); i >= 0; |
665 |
i = selection.nextSetBit(i + 1)) {
|
666 |
vea.removeRow(i); |
667 |
} |
668 |
} catch (DriverIOException e) {
|
669 |
e.printStackTrace(); |
670 |
} catch (IOException e) { |
671 |
e.printStackTrace(); |
672 |
} finally {
|
673 |
try {
|
674 |
vea.endComplexRow(); |
675 |
} catch (IOException e1) { |
676 |
e1.printStackTrace(); |
677 |
} catch (DriverIOException e1) {
|
678 |
e1.printStackTrace(); |
679 |
} |
680 |
} |
681 |
|
682 |
selection.clear(); |
683 |
getMapControl().drawMap(false);
|
684 |
} |
685 |
|
686 |
/**
|
687 |
* DOCUMENT ME!
|
688 |
*
|
689 |
* @param b
|
690 |
*/
|
691 |
public void setAdjustGrid(boolean b) { |
692 |
getGrid().setAdjustGrid(b); |
693 |
} |
694 |
|
695 |
/**
|
696 |
* DOCUMENT ME!
|
697 |
*
|
698 |
* @param actionCommand
|
699 |
*/
|
700 |
public void keyPressed(String actionCommand) { |
701 |
if (actionCommand.equals("eliminar")) { |
702 |
delete(); |
703 |
} else if (actionCommand.equals("escape")) { |
704 |
if (getMapControl().getTool().equals("cadtooladapter")){ |
705 |
CADTool ct = (CADTool) cadToolStack.peek(); |
706 |
ct.end(); |
707 |
cadToolStack.clear(); |
708 |
pushCadTool(new SelectionCADTool());
|
709 |
getVectorialAdapter().getSelection().clear(); |
710 |
getMapControl().drawMap(false);
|
711 |
PluginServices.getMainFrame().setSelectedTool("SELCAD");
|
712 |
askQuestion(); |
713 |
} |
714 |
} |
715 |
|
716 |
PluginServices.getMainFrame().enableControls(); |
717 |
|
718 |
} |
719 |
public CADGrid getGrid(){
|
720 |
return cadgrid;
|
721 |
} |
722 |
} |