svn-gvsig-desktop / trunk / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / CADToolAdapter.java @ 5070
History | View | Annotate | Download (23.9 KB)
1 | 3711 | caballero | package com.iver.cit.gvsig.gui.cad; |
---|---|---|---|
2 | |||
3 | import java.awt.Color; |
||
4 | import java.awt.Cursor; |
||
5 | import java.awt.Graphics; |
||
6 | 3883 | caballero | import java.awt.Image; |
7 | 3711 | caballero | import java.awt.Point; |
8 | 3883 | caballero | import java.awt.Toolkit; |
9 | 4313 | fjp | import java.awt.event.InputEvent; |
10 | 3711 | caballero | import java.awt.event.MouseEvent; |
11 | import java.awt.event.MouseWheelEvent; |
||
12 | import java.awt.geom.Point2D; |
||
13 | 3883 | caballero | import java.awt.geom.Rectangle2D; |
14 | import java.awt.image.MemoryImageSource; |
||
15 | 3711 | caballero | import java.io.IOException; |
16 | 4115 | fjp | import java.util.List; |
17 | 3711 | caballero | import java.util.Stack; |
18 | |||
19 | import com.iver.andami.PluginServices; |
||
20 | 3883 | caballero | import com.iver.cit.gvsig.CADExtension; |
21 | 3711 | caballero | import com.iver.cit.gvsig.fmap.ViewPort; |
22 | 3883 | caballero | import com.iver.cit.gvsig.fmap.core.Handler; |
23 | import com.iver.cit.gvsig.fmap.core.IGeometry; |
||
24 | 3711 | caballero | import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
25 | 4124 | fjp | import com.iver.cit.gvsig.fmap.core.v02.FConverter; |
26 | 3711 | caballero | import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
27 | import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
||
28 | 5015 | caballero | import com.iver.cit.gvsig.fmap.edition.UtilFunctions; |
29 | 3711 | caballero | 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 | 3733 | fjp | import com.iver.cit.gvsig.gui.View; |
35 | 3847 | caballero | import com.iver.cit.gvsig.gui.cad.tools.SelectionCADTool; |
36 | 4366 | caballero | import com.iver.cit.gvsig.layers.VectorialLayerEdited; |
37 | 4892 | caballero | import com.iver.utiles.console.JConsole; |
38 | 4115 | fjp | import com.vividsolutions.jts.geom.Envelope; |
39 | import com.vividsolutions.jts.index.SpatialIndex; |
||
40 | 3711 | caballero | |
41 | public class CADToolAdapter extends Behavior { |
||
42 | 4366 | caballero | public static int MAX_ENTITIES_IN_SPATIAL_CACHE = 5000; |
43 | 5015 | caballero | 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 | 4366 | caballero | |
50 | 3711 | caballero | private Stack cadToolStack = new Stack(); |
51 | |||
52 | 4115 | fjp | // Para pasarle las coordenadas cuando se produce un evento textEntered
|
53 | 3711 | caballero | private int lastX; |
54 | 4115 | fjp | |
55 | 3711 | caballero | private int lastY; |
56 | 4115 | fjp | |
57 | 3711 | caballero | private FSymbol symbol = new FSymbol(FConstant.SYMBOL_TYPE_POINT, Color.RED); |
58 | 4115 | fjp | |
59 | 3711 | caballero | private Point2D mapAdjustedPoint; |
60 | 4115 | fjp | |
61 | 3711 | caballero | private boolean questionAsked = false; |
62 | 4115 | fjp | |
63 | 3711 | caballero | private Point2D adjustedPoint; |
64 | 4115 | fjp | |
65 | 3711 | caballero | private boolean snapping = false; |
66 | 4115 | fjp | |
67 | 3711 | caballero | private boolean adjustSnapping = false; |
68 | 4115 | fjp | |
69 | 3711 | caballero | private VectorialEditableAdapter vea;
|
70 | 3883 | caballero | |
71 | 4115 | fjp | private CADGrid cadgrid = new CADGrid(); |
72 | |||
73 | private SpatialIndex spatialCache;
|
||
74 | |||
75 | 3711 | caballero | /**
|
76 | * Pinta de alguna manera especial las geometrias seleccionadas para la
|
||
77 | 4115 | fjp | * edici?n. En caso de que el snapping est? activado, pintar? el efecto del
|
78 | * mismo.
|
||
79 | 4118 | caballero | *
|
80 | 3711 | caballero | * @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 | 3883 | caballero | getGrid().drawGrid(g); |
86 | 3711 | caballero | if (adjustedPoint != null) { |
87 | 4115 | fjp | Point2D p = null; |
88 | 3711 | caballero | if (mapAdjustedPoint != null) { |
89 | p = mapAdjustedPoint; |
||
90 | } else {
|
||
91 | p = getMapControl().getViewPort().toMapPoint(adjustedPoint); |
||
92 | } |
||
93 | 4115 | fjp | ((CADTool) cadToolStack.peek()) |
94 | .drawOperation(g, p.getX(), p.getY()); |
||
95 | 3711 | caballero | } |
96 | } |
||
97 | |||
98 | /**
|
||
99 | * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
|
||
100 | */
|
||
101 | public void mouseClicked(MouseEvent e) throws BehaviorException { |
||
102 | 4115 | fjp | if (e.getButton() == MouseEvent.BUTTON3) { |
103 | 3883 | caballero | CADExtension.showPopup(e); |
104 | } |
||
105 | 3711 | caballero | } |
106 | |||
107 | /**
|
||
108 | * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
|
||
109 | */
|
||
110 | public void mouseEntered(MouseEvent e) throws BehaviorException { |
||
111 | 3952 | fjp | clearMouseImage(); |
112 | 3711 | caballero | } |
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 | 4115 | fjp | if (mapAdjustedPoint != null) { |
129 | 3711 | caballero | p = mapAdjustedPoint; |
130 | } else {
|
||
131 | p = vp.toMapPoint(adjustedPoint); |
||
132 | } |
||
133 | 5015 | caballero | transition(new double[] { p.getX(), p.getY() }, e,ABSOLUTE); |
134 | 3711 | caballero | } |
135 | } |
||
136 | |||
137 | /**
|
||
138 | 4115 | fjp | * Ajusta un punto de la imagen que se pasa como par?metro al grid si ?ste
|
139 | 3711 | caballero | * est? activo y devuelve la distancia de un punto al punto ajustado
|
140 | 4118 | caballero | *
|
141 | 3711 | caballero | * @param point
|
142 | 4115 | fjp | * @param mapHandlerAdjustedPoint
|
143 | * DOCUMENT ME!
|
||
144 | 4118 | caballero | *
|
145 | 3711 | caballero | * @return Distancia del punto que se pasa como par?metro al punto ajustado
|
146 | */
|
||
147 | private double adjustToHandler(Point2D point, |
||
148 | 4115 | fjp | Point2D mapHandlerAdjustedPoint) {
|
149 | // if (selection.cardinality() > 0) {
|
||
150 | 4124 | fjp | if (getSpatialCache() == null) |
151 | 4366 | caballero | return Double.MAX_VALUE; |
152 | |||
153 | 4115 | fjp | 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 | 3711 | caballero | |
158 | 4144 | fjp | // int[] indexes = vea.getRowsIndexes_OLD(r);
|
159 | 4124 | fjp | Envelope e = FConverter.convertRectangle2DtoEnvelope(r); |
160 | 4115 | fjp | List l = getSpatialCache().query(e);
|
161 | double min = Double.MAX_VALUE; |
||
162 | Point2D argmin = null; |
||
163 | Point2D mapArgmin = null; |
||
164 | 3711 | caballero | |
165 | 4115 | fjp | for (int i = 0; i < l.size(); i++) { |
166 | 4144 | fjp | // for (int i = 0; i < indexes.length; i++) {
|
167 | 4115 | fjp | IGeometry geometry = null;
|
168 | 4144 | fjp | /* try {
|
169 | geometry = vea.getShape(indexes[i]);
|
||
170 | } catch (DriverIOException e1) {
|
||
171 | // TODO Auto-generated catch block
|
||
172 | e1.printStackTrace();
|
||
173 | } */
|
||
174 | 4115 | fjp | geometry = (IGeometry) l.get(i);// getFeature(indexes[i]);
|
175 | Handler[] handlers = geometry.getHandlers(IGeometry.SELECTHANDLER); |
||
176 | 3711 | caballero | |
177 | 4115 | fjp | 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 | 3711 | caballero | } |
189 | } |
||
190 | 4115 | fjp | } |
191 | 3711 | caballero | |
192 | 4115 | fjp | if (argmin != null) { |
193 | point.setLocation(argmin); |
||
194 | 3711 | caballero | |
195 | 4115 | fjp | // Se hace el casting porque no se quiere redondeo
|
196 | point.setLocation(argmin.getX(), argmin.getY()); |
||
197 | 3711 | caballero | |
198 | 4115 | fjp | mapHandlerAdjustedPoint.setLocation(mapArgmin); |
199 | 3711 | caballero | |
200 | 4115 | fjp | return min;
|
201 | 3711 | caballero | } |
202 | 3883 | caballero | |
203 | 3711 | caballero | 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 | 3883 | caballero | getMapControl().repaint(); |
212 | 3711 | caballero | } |
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 | 3883 | caballero | |
229 | 3711 | caballero | lastX = e.getX(); |
230 | lastY = e.getY(); |
||
231 | |||
232 | calculateSnapPoint(e.getPoint()); |
||
233 | |||
234 | getMapControl().repaint(); |
||
235 | } |
||
236 | 4115 | fjp | |
237 | private void clearMouseImage() { |
||
238 | 3883 | caballero | int[] pixels = new int[16 * 16]; |
239 | Image image = Toolkit.getDefaultToolkit().createImage( |
||
240 | 4115 | fjp | new MemoryImageSource(16, 16, pixels, 0, 16)); |
241 | Cursor transparentCursor = Toolkit.getDefaultToolkit() |
||
242 | .createCustomCursor(image, new Point(0, 0), "invisiblecursor"); |
||
243 | 3996 | caballero | |
244 | 3952 | fjp | getMapControl().setCursor(transparentCursor); |
245 | 3883 | caballero | } |
246 | 4115 | fjp | |
247 | 3711 | caballero | /**
|
248 | * DOCUMENT ME!
|
||
249 | 4118 | caballero | *
|
250 | 4115 | fjp | * @param g
|
251 | * DOCUMENT ME!
|
||
252 | 3711 | caballero | */
|
253 | private void drawCursor(Graphics g) { |
||
254 | 3996 | caballero | |
255 | 3711 | caballero | 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 | 4115 | fjp | (int) (p.getX() + size1), (int) (p.getY())); |
267 | 3711 | caballero | g.drawLine((int) (p.getX()), (int) (p.getY() - size1), |
268 | 4115 | fjp | (int) (p.getX()), (int) (p.getY() + size1)); |
269 | 3711 | caballero | |
270 | if (adjustedPoint != null) { |
||
271 | if (adjustSnapping) {
|
||
272 | g.setColor(Color.ORANGE);
|
||
273 | 3883 | caballero | g.drawRect((int) (adjustedPoint.getX() - 6), |
274 | 4115 | fjp | (int) (adjustedPoint.getY() - 6), 12, 12); |
275 | 3711 | caballero | g.drawRect((int) (adjustedPoint.getX() - 3), |
276 | 4115 | fjp | (int) (adjustedPoint.getY() - 3), 6, 6); |
277 | 3711 | caballero | g.setColor(Color.MAGENTA);
|
278 | g.drawRect((int) (adjustedPoint.getX() - 4), |
||
279 | 4115 | fjp | (int) (adjustedPoint.getY() - 4), 8, 8); |
280 | 3711 | caballero | |
281 | adjustSnapping = false;
|
||
282 | } else {
|
||
283 | g.drawRect((int) (p.getX() - size2), (int) (p.getY() - size2), |
||
284 | 4115 | fjp | (int) (size2 * 2), (int) (size2 * 2)); |
285 | 3711 | caballero | } |
286 | } |
||
287 | } |
||
288 | |||
289 | /**
|
||
290 | * DOCUMENT ME!
|
||
291 | 4118 | caballero | *
|
292 | 3711 | caballero | * @param point
|
293 | */
|
||
294 | private void calculateSnapPoint(Point point) { |
||
295 | 4115 | fjp | // Se comprueba el ajuste a rejilla
|
296 | 3711 | caballero | |
297 | 4115 | fjp | Point2D gridAdjustedPoint = getMapControl().getViewPort().toMapPoint(
|
298 | point); |
||
299 | 3711 | caballero | double minDistance = Double.MAX_VALUE; |
300 | 4115 | fjp | CADTool ct = (CADTool) cadToolStack.peek(); |
301 | if (ct instanceof SelectionCADTool |
||
302 | && ((SelectionCADTool) ct).getStatus().equals( |
||
303 | 4742 | caballero | "Selection.FirstPoint")) {
|
304 | 4115 | fjp | mapAdjustedPoint = gridAdjustedPoint; |
305 | adjustedPoint = (Point2D) point.clone();
|
||
306 | } else {
|
||
307 | 3883 | caballero | |
308 | 4115 | fjp | minDistance = getGrid().adjustToGrid(gridAdjustedPoint); |
309 | 3711 | caballero | if (minDistance < Double.MAX_VALUE) { |
310 | 4115 | fjp | adjustedPoint = getMapControl().getViewPort().fromMapPoint( |
311 | gridAdjustedPoint); |
||
312 | 3711 | caballero | mapAdjustedPoint = gridAdjustedPoint; |
313 | } else {
|
||
314 | mapAdjustedPoint = null;
|
||
315 | } |
||
316 | 3883 | caballero | } |
317 | 3711 | caballero | Point2D handlerAdjustedPoint = null; |
318 | |||
319 | 4115 | fjp | // Se comprueba el ajuste a los handlers
|
320 | 3711 | caballero | if (mapAdjustedPoint != null) { |
321 | 4115 | fjp | handlerAdjustedPoint = (Point2D) mapAdjustedPoint.clone(); // getMapControl().getViewPort().toMapPoint(point); |
322 | 3711 | caballero | } else {
|
323 | 4115 | fjp | handlerAdjustedPoint = getMapControl().getViewPort().toMapPoint( |
324 | point); |
||
325 | 3711 | caballero | } |
326 | |||
327 | Point2D mapPoint = new Point2D.Double(); |
||
328 | double distance = adjustToHandler(handlerAdjustedPoint, mapPoint);
|
||
329 | |||
330 | if (distance < minDistance) {
|
||
331 | adjustSnapping = true;
|
||
332 | 4115 | fjp | adjustedPoint = getMapControl().getViewPort().fromMapPoint( |
333 | handlerAdjustedPoint); |
||
334 | 3711 | caballero | mapAdjustedPoint = mapPoint; |
335 | minDistance = distance; |
||
336 | } |
||
337 | |||
338 | 4115 | fjp | // Si no hay ajuste
|
339 | 3711 | caballero | 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 | 3964 | fjp | getMapControl().cancelDrawing(); |
351 | ViewPort vp = getMapControl().getViewPort(); |
||
352 | // Point2D pReal = vp.toMapPoint(e.getPoint());
|
||
353 | 3996 | caballero | |
354 | 4115 | fjp | Point2D pReal = new Point2D.Double(vp.getAdjustedExtent().getCenterX(), |
355 | vp.getAdjustedExtent().getCenterY()); |
||
356 | 3996 | caballero | int amount = e.getWheelRotation();
|
357 | 4115 | fjp | double nuevoX;
|
358 | double nuevoY;
|
||
359 | double factor;
|
||
360 | 3964 | fjp | |
361 | if (amount > 0) // nos acercamos |
||
362 | { |
||
363 | factor = 0.9;
|
||
364 | 4115 | fjp | } else // nos alejamos |
365 | 3964 | fjp | { |
366 | factor = 1.2;
|
||
367 | } |
||
368 | 4115 | fjp | 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 | 3996 | caballero | |
379 | 4115 | fjp | vp.setExtent(r); |
380 | } |
||
381 | 3711 | caballero | } |
382 | |||
383 | /**
|
||
384 | * M?todo que realiza las transiciones en las herramientas en funci?n de un
|
||
385 | * texto introducido en la consola
|
||
386 | 4118 | caballero | *
|
387 | 4115 | fjp | * @param text
|
388 | * DOCUMENT ME!
|
||
389 | 3711 | caballero | */
|
390 | public void textEntered(String text) { |
||
391 | if (text == null) { |
||
392 | transition("cancel");
|
||
393 | } else {
|
||
394 | 4115 | fjp | /*
|
395 | * if ("".equals(text)) { transition("aceptar"); } else {
|
||
396 | */
|
||
397 | text = text.trim(); |
||
398 | 5015 | caballero | int type=ABSOLUTE;
|
399 | String[] numbers=null; |
||
400 | if (text.indexOf(",")!=-1){ |
||
401 | 3711 | caballero | |
402 | 5015 | caballero | 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 | 4115 | fjp | double[] values = null; |
426 | 3711 | caballero | |
427 | 4115 | fjp | try {
|
428 | if (numbers.length == 2) { |
||
429 | // punto
|
||
430 | values = new double[] { Double.parseDouble(numbers[0]), |
||
431 | Double.parseDouble(numbers[1]) }; |
||
432 | 5015 | caballero | transition(values, null,type);
|
433 | 4115 | fjp | } else if (numbers.length == 1) { |
434 | // valor
|
||
435 | values = new double[] { Double.parseDouble(numbers[0]) }; |
||
436 | 4147 | fjp | transition(values[0]);
|
437 | 3711 | caballero | } |
438 | 4115 | fjp | } catch (NumberFormatException e) { |
439 | 4147 | fjp | transition(text); |
440 | 5070 | caballero | } catch (NullPointerException e) { |
441 | transition(text); |
||
442 | 4115 | fjp | } |
443 | // }
|
||
444 | 3711 | caballero | } |
445 | 4002 | fjp | getMapControl().repaint(); |
446 | 3711 | caballero | } |
447 | |||
448 | |||
449 | /**
|
||
450 | * DOCUMENT ME!
|
||
451 | */
|
||
452 | 3883 | caballero | public void configureMenu() { |
453 | String[] desc = ((CADTool) cadToolStack.peek()).getDescriptions(); |
||
454 | 4115 | fjp | // String[] labels = ((CADTool)
|
455 | // cadToolStack.peek()).getCurrentTransitions();
|
||
456 | 3883 | caballero | CADExtension.clearMenu(); |
457 | 3711 | caballero | |
458 | for (int i = 0; i < desc.length; i++) { |
||
459 | if (desc[i] != null) { |
||
460 | 4584 | caballero | CADExtension.addMenuEntry(PluginServices.getText(this,desc[i]));// , labels[i]); |
461 | 3711 | caballero | } |
462 | } |
||
463 | 3883 | caballero | |
464 | 3711 | caballero | } |
465 | |||
466 | /**
|
||
467 | 4313 | fjp | * 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 | 4115 | fjp | * @param values
|
473 | 4313 | fjp | * @param event
|
474 | 3711 | caballero | */
|
475 | 5015 | caballero | private void transition(double[] values, InputEvent event,int type) { |
476 | 3711 | caballero | questionAsked = true;
|
477 | 4115 | fjp | if (!cadToolStack.isEmpty()) {
|
478 | CADTool ct = (CADTool) cadToolStack.peek(); |
||
479 | 5015 | caballero | |
480 | switch (type) {
|
||
481 | case ABSOLUTE:
|
||
482 | 4313 | fjp | ct.transition(values[0], values[1], event); |
483 | 5015 | caballero | 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 | 3744 | caballero | |
495 | 5015 | caballero | 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 | 5070 | caballero | Point2D point=UtilFunctions.getPoint(new Point2D.Double(previousPoint[0],previousPoint[1]),Math.toRadians(values[1]),values[0]); |
508 | 5015 | caballero | auxPolarSCU[0]=point.getX();
|
509 | auxPolarSCU[1]=point.getY();
|
||
510 | ct.transition(auxPolarSCU[0], auxPolarSCU[1], event); |
||
511 | }else{
|
||
512 | 5070 | caballero | Point2D point=UtilFunctions.getPoint(new Point2D.Double(0,0),Math.toRadians(values[1]),values[0]); |
513 | 5015 | caballero | 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 | 4115 | fjp | } |
537 | 5015 | caballero | askQuestion(); |
538 | 3711 | caballero | } |
539 | 3883 | caballero | configureMenu(); |
540 | 4024 | caballero | PluginServices.getMainFrame().enableControls(); |
541 | 3711 | caballero | } |
542 | 4115 | fjp | |
543 | 3744 | caballero | /**
|
544 | * DOCUMENT ME!
|
||
545 | 4118 | caballero | *
|
546 | 4115 | fjp | * @param text
|
547 | * DOCUMENT ME!
|
||
548 | * @param source
|
||
549 | * DOCUMENT ME!
|
||
550 | * @param sel
|
||
551 | * DOCUMENT ME!
|
||
552 | * @param values
|
||
553 | * DOCUMENT ME!
|
||
554 | 3744 | caballero | */
|
555 | 4147 | fjp | private void transition(double value) { |
556 | 3744 | caballero | questionAsked = true;
|
557 | 4115 | fjp | if (!cadToolStack.isEmpty()) {
|
558 | CADTool ct = (CADTool) cadToolStack.peek(); |
||
559 | ct.transition(value); |
||
560 | 3744 | caballero | askQuestion(); |
561 | 4115 | fjp | } |
562 | 3883 | caballero | configureMenu(); |
563 | 3744 | caballero | PluginServices.getMainFrame().enableControls(); |
564 | } |
||
565 | 4115 | fjp | |
566 | 4147 | fjp | public void transition(String option) { |
567 | 4115 | fjp | questionAsked = true;
|
568 | if (!cadToolStack.isEmpty()) {
|
||
569 | CADTool ct = (CADTool) cadToolStack.peek(); |
||
570 | 4892 | caballero | try{
|
571 | 4115 | fjp | ct.transition(option); |
572 | 4892 | caballero | }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 | 4115 | fjp | askQuestion(); |
577 | } |
||
578 | configureMenu(); |
||
579 | PluginServices.getMainFrame().enableControls(); |
||
580 | 3744 | caballero | } |
581 | 4115 | fjp | |
582 | 3711 | caballero | /**
|
583 | * DOCUMENT ME!
|
||
584 | 4118 | caballero | *
|
585 | 4115 | fjp | * @param value
|
586 | * DOCUMENT ME!
|
||
587 | 3711 | caballero | */
|
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 | 4118 | caballero | *
|
597 | 4115 | fjp | * @param activated
|
598 | * DOCUMENT ME!
|
||
599 | 3711 | caballero | */
|
600 | public void setSnapping(boolean activated) { |
||
601 | snapping = activated; |
||
602 | } |
||
603 | |||
604 | /**
|
||
605 | * DOCUMENT ME!
|
||
606 | 4118 | caballero | *
|
607 | 4115 | fjp | * @param x
|
608 | * DOCUMENT ME!
|
||
609 | * @param y
|
||
610 | * DOCUMENT ME!
|
||
611 | * @param dist
|
||
612 | * DOCUMENT ME!
|
||
613 | 3711 | caballero | */
|
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 | 4115 | fjp | /**
|
623 | * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getCursor()
|
||
624 | */
|
||
625 | public Cursor getCursor() { |
||
626 | return null; |
||
627 | } |
||
628 | 3711 | caballero | |
629 | 4115 | fjp | /**
|
630 | * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
|
||
631 | */
|
||
632 | public boolean cancelDrawing() { |
||
633 | return false; |
||
634 | } |
||
635 | }; |
||
636 | 3711 | caballero | } |
637 | |||
638 | /**
|
||
639 | * DOCUMENT ME!
|
||
640 | 4118 | caballero | *
|
641 | 3711 | caballero | * @return DOCUMENT ME!
|
642 | */
|
||
643 | public CADTool getCadTool() {
|
||
644 | return (CADTool) cadToolStack.peek();
|
||
645 | } |
||
646 | |||
647 | /**
|
||
648 | * DOCUMENT ME!
|
||
649 | 4118 | caballero | *
|
650 | 4115 | fjp | * @param cadTool
|
651 | * DOCUMENT ME!
|
||
652 | 3711 | caballero | */
|
653 | public void pushCadTool(CADTool cadTool) { |
||
654 | cadToolStack.push(cadTool); |
||
655 | cadTool.setCadToolAdapter(this);
|
||
656 | 4115 | fjp | // cadTool.initializeStatus();
|
657 | // cadTool.setVectorialAdapter(vea);
|
||
658 | /*
|
||
659 | * int ret = cadTool.transition(null, editableFeatureSource, selection,
|
||
660 | * new double[0]);
|
||
661 | 4118 | caballero | *
|
662 | 4115 | fjp | * if ((ret & Automaton.AUTOMATON_FINISHED) ==
|
663 | * Automaton.AUTOMATON_FINISHED) { popCadTool();
|
||
664 | 4118 | caballero | *
|
665 | 4115 | fjp | * if (cadToolStack.isEmpty()) { pushCadTool(new
|
666 | * com.iver.cit.gvsig.gui.cad.smc.gen.CADTool());//new
|
||
667 | * SelectionCadTool());
|
||
668 | * PluginServices.getMainFrame().setSelectedTool("selection"); }
|
||
669 | 4118 | caballero | *
|
670 | 4115 | fjp | * askQuestion();
|
671 | 4118 | caballero | *
|
672 | 4115 | fjp | * getMapControl().drawMap(false); }
|
673 | */
|
||
674 | 3711 | caballero | } |
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 | 4115 | fjp | CADTool cadtool = (CADTool) cadToolStack.peek(); |
688 | /*
|
||
689 | * if (cadtool..getStatus()==0){
|
||
690 | * PluginServices.getMainFrame().addTextToConsole("\n"
|
||
691 | * +cadtool.getName()); }
|
||
692 | */
|
||
693 | 3711 | caballero | View vista = (View) PluginServices.getMDIManager().getActiveView(); |
694 | 4892 | caballero | vista.getConsolePanel().addText("\n" +"#" +cadtool.getQuestion() + " > ",JConsole.MESSAGE); |
695 | 4115 | fjp | // ***PluginServices.getMainFrame().addTextToConsole("\n" +
|
696 | // cadtool.getQuestion());
|
||
697 | 3711 | caballero | questionAsked = true;
|
698 | |||
699 | } |
||
700 | |||
701 | /**
|
||
702 | * DOCUMENT ME!
|
||
703 | 4118 | caballero | *
|
704 | 4115 | fjp | * @param cadTool
|
705 | * DOCUMENT ME!
|
||
706 | 3711 | caballero | */
|
707 | public void setCadTool(CADTool cadTool) { |
||
708 | cadToolStack.clear(); |
||
709 | pushCadTool(cadTool); |
||
710 | 4584 | caballero | //askQuestion();
|
711 | 3711 | caballero | } |
712 | |||
713 | /**
|
||
714 | * DOCUMENT ME!
|
||
715 | 4118 | caballero | *
|
716 | 3711 | caballero | * @return DOCUMENT ME!
|
717 | */
|
||
718 | public VectorialEditableAdapter getVectorialAdapter() {
|
||
719 | return vea;
|
||
720 | } |
||
721 | |||
722 | /**
|
||
723 | * DOCUMENT ME!
|
||
724 | 4118 | caballero | *
|
725 | 4115 | fjp | * @param editableFeatureSource
|
726 | * DOCUMENT ME!
|
||
727 | * @param selection
|
||
728 | * DOCUMENT ME!
|
||
729 | 3711 | caballero | */
|
730 | 4115 | fjp | public void setVectorialAdapter(VectorialEditableAdapter vea) { |
731 | 3711 | caballero | this.vea = vea;
|
732 | } |
||
733 | |||
734 | /**
|
||
735 | * DOCUMENT ME!
|
||
736 | 4118 | caballero | *
|
737 | 3711 | caballero | * @return DOCUMENT ME!
|
738 | */
|
||
739 | 4115 | fjp | /*
|
740 | * public CadMapControl getCadMapControl() { return cadMapControl; }
|
||
741 | */
|
||
742 | 3711 | caballero | /**
|
743 | * DOCUMENT ME!
|
||
744 | 4118 | caballero | *
|
745 | 4115 | fjp | * @param cadMapControl
|
746 | * DOCUMENT ME!
|
||
747 | 3711 | caballero | */
|
748 | 4115 | fjp | /*
|
749 | * public void setCadMapControl(CadMapControl cadMapControl) {
|
||
750 | * this.cadMapControl = cadMapControl; }
|
||
751 | */
|
||
752 | 3711 | caballero | |
753 | /**
|
||
754 | * Elimina las geometr?as seleccionadas actualmente
|
||
755 | */
|
||
756 | private void delete() { |
||
757 | vea.startComplexRow(); |
||
758 | 4115 | fjp | FBitSet selection = getVectorialAdapter().getSelection(); |
759 | 3711 | caballero | try {
|
760 | 4115 | fjp | 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 | 4584 | caballero | } |
767 | 4454 | fjp | /* 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 | 4584 | caballero | } */
|
777 | 4454 | fjp | for (int i = indexesToDel.length - 1; i >= 0; i--) { |
778 | 4584 | caballero | vea.removeRow(indexesToDel[i],PluginServices.getText(this,"deleted_feature")); |
779 | 3711 | caballero | } |
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 | 3999 | caballero | System.out.println("clear Selection"); |
794 | 3711 | caballero | selection.clear(); |
795 | 4366 | caballero | VectorialLayerEdited vle=(VectorialLayerEdited)CADExtension.getEditionManager().getActiveLayerEdited(); |
796 | vle.clearSelection(); |
||
797 | /* if (getCadTool() instanceof SelectionCADTool)
|
||
798 | 4195 | fjp | {
|
799 | SelectionCADTool selTool = (SelectionCADTool) getCadTool();
|
||
800 | selTool.clearSelection();
|
||
801 | }
|
||
802 | 4366 | caballero | */
|
803 | 3711 | caballero | getMapControl().drawMap(false);
|
804 | } |
||
805 | |||
806 | /**
|
||
807 | * DOCUMENT ME!
|
||
808 | 4118 | caballero | *
|
809 | 3711 | caballero | * @param b
|
810 | */
|
||
811 | public void setAdjustGrid(boolean b) { |
||
812 | getGrid().setAdjustGrid(b); |
||
813 | } |
||
814 | |||
815 | /**
|
||
816 | * DOCUMENT ME!
|
||
817 | 4118 | caballero | *
|
818 | 3711 | caballero | * @param actionCommand
|
819 | */
|
||
820 | public void keyPressed(String actionCommand) { |
||
821 | 3725 | caballero | if (actionCommand.equals("eliminar")) { |
822 | 3711 | caballero | delete(); |
823 | } else if (actionCommand.equals("escape")) { |
||
824 | 4115 | fjp | if (getMapControl().getTool().equals("cadtooladapter")) { |
825 | 3847 | caballero | CADTool ct = (CADTool) cadToolStack.peek(); |
826 | ct.end(); |
||
827 | 3711 | caballero | cadToolStack.clear(); |
828 | 4210 | fjp | SelectionCADTool selCad = new SelectionCADTool();
|
829 | selCad.init(); |
||
830 | 4366 | caballero | VectorialLayerEdited vle=(VectorialLayerEdited)CADExtension.getEditionManager().getActiveLayerEdited(); |
831 | vle.clearSelection(); |
||
832 | |||
833 | 4210 | fjp | pushCadTool(selCad); |
834 | // getVectorialAdapter().getSelection().clear();
|
||
835 | 3711 | caballero | getMapControl().drawMap(false);
|
836 | 5015 | caballero | PluginServices.getMainFrame().setSelectedTool("_selection");
|
837 | 4892 | caballero | //askQuestion();
|
838 | }else{
|
||
839 | getMapControl().setPrevTool(); |
||
840 | 3711 | caballero | } |
841 | } |
||
842 | 3725 | caballero | |
843 | 3711 | caballero | PluginServices.getMainFrame().enableControls(); |
844 | |||
845 | } |
||
846 | 4115 | fjp | |
847 | public CADGrid getGrid() {
|
||
848 | 3711 | caballero | return cadgrid;
|
849 | } |
||
850 | 4115 | fjp | |
851 | /**
|
||
852 | * @return Returns the spatialCache.
|
||
853 | */
|
||
854 | public SpatialIndex getSpatialCache() {
|
||
855 | return spatialCache;
|
||
856 | } |
||
857 | |||
858 | /**
|
||
859 | 4124 | fjp | * Se usa para rellenar la cache de entidades
|
860 | * con la que queremos trabajar (para hacer snapping,
|
||
861 | * por ejemplo. Lo normal ser?
|
||
862 | 4366 | caballero | * rellenarla cada vez que cambie el extent, y
|
863 | 4124 | fjp | * 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 | 4366 | caballero | * @throws DriverException
|
868 | 4115 | fjp | */
|
869 | 4742 | caballero | /* public void createSpatialCache() throws DriverException {
|
870 | 4124 | fjp | 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 | 4366 | caballero | // Podr?amos hacer que GeneralPathX lo tenga guardado,
|
888 | 4124 | fjp | // 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 | 4366 | caballero | |
894 | 4124 | fjp | Envelope e = FConverter.convertRectangle2DtoEnvelope(geom.getBounds2D());
|
895 | spatialCache.insert(e, geom);
|
||
896 | }
|
||
897 | 4742 | caballero | }*/
|
898 | 3711 | caballero | } |