svn-gvsig-desktop / tags / v1_1_Build_1012 / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / CADToolAdapter.java @ 12987
History | View | Annotate | Download (27.8 KB)
1 | 3711 | caballero | package com.iver.cit.gvsig.gui.cad; |
---|---|---|---|
2 | |||
3 | import java.awt.Color; |
||
4 | import java.awt.Cursor; |
||
5 | 5874 | fjp | import java.awt.FontMetrics; |
6 | 3711 | caballero | import java.awt.Graphics; |
7 | 5874 | fjp | import java.awt.Graphics2D; |
8 | 3883 | caballero | import java.awt.Image; |
9 | 3711 | caballero | import java.awt.Point; |
10 | 3883 | caballero | import java.awt.Toolkit; |
11 | 4313 | fjp | import java.awt.event.InputEvent; |
12 | 3711 | caballero | import java.awt.event.MouseEvent; |
13 | import java.awt.event.MouseWheelEvent; |
||
14 | import java.awt.geom.Point2D; |
||
15 | 3883 | caballero | import java.awt.geom.Rectangle2D; |
16 | import java.awt.image.MemoryImageSource; |
||
17 | 3711 | caballero | import java.io.IOException; |
18 | 5874 | fjp | import java.text.NumberFormat; |
19 | 5261 | fjp | import java.util.ArrayList; |
20 | 6174 | caballero | import java.util.HashMap; |
21 | 3711 | caballero | import java.util.Stack; |
22 | 6713 | caballero | import java.util.prefs.Preferences; |
23 | 3711 | caballero | |
24 | 5874 | fjp | import org.cresques.cts.IProjection; |
25 | |||
26 | 3711 | caballero | import com.iver.andami.PluginServices; |
27 | 12159 | caballero | import com.iver.andami.messages.NotificationManager; |
28 | 5874 | fjp | import com.iver.andami.ui.mdiFrame.MainFrame; |
29 | 12659 | caballero | import com.iver.andami.ui.mdiManager.IWindow; |
30 | 3883 | caballero | import com.iver.cit.gvsig.CADExtension; |
31 | 6174 | caballero | import com.iver.cit.gvsig.EditionManager; |
32 | 12159 | caballero | import com.iver.cit.gvsig.fmap.DriverException; |
33 | 6878 | cesar | import com.iver.cit.gvsig.fmap.MapContext; |
34 | 5874 | fjp | import com.iver.cit.gvsig.fmap.MapControl; |
35 | 3711 | caballero | import com.iver.cit.gvsig.fmap.ViewPort; |
36 | 12159 | caballero | import com.iver.cit.gvsig.fmap.core.FShape; |
37 | 3711 | caballero | import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
38 | 4124 | fjp | import com.iver.cit.gvsig.fmap.core.v02.FConverter; |
39 | 3711 | caballero | import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
40 | import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
||
41 | 5184 | caballero | import com.iver.cit.gvsig.fmap.edition.EditionEvent; |
42 | 5015 | caballero | import com.iver.cit.gvsig.fmap.edition.UtilFunctions; |
43 | 3711 | caballero | import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter; |
44 | import com.iver.cit.gvsig.fmap.layers.FBitSet; |
||
45 | 5223 | fjp | import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
46 | import com.iver.cit.gvsig.fmap.layers.SpatialCache; |
||
47 | 3711 | caballero | import com.iver.cit.gvsig.fmap.tools.BehaviorException; |
48 | import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior; |
||
49 | import com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener; |
||
50 | 6771 | fjp | import com.iver.cit.gvsig.gui.cad.snapping.FinalPointSnapper; |
51 | 5261 | fjp | import com.iver.cit.gvsig.gui.cad.snapping.ISnapper; |
52 | 6771 | fjp | import com.iver.cit.gvsig.gui.cad.snapping.ISnapperRaster; |
53 | import com.iver.cit.gvsig.gui.cad.snapping.ISnapperVectorial; |
||
54 | 5223 | fjp | import com.iver.cit.gvsig.gui.cad.snapping.NearestPointSnapper; |
55 | 6771 | fjp | import com.iver.cit.gvsig.gui.cad.snapping.PixelSnapper; |
56 | 5223 | fjp | import com.iver.cit.gvsig.gui.cad.snapping.SnappingVisitor; |
57 | 3847 | caballero | import com.iver.cit.gvsig.gui.cad.tools.SelectionCADTool; |
58 | 5223 | fjp | import com.iver.cit.gvsig.layers.ILayerEdited; |
59 | 4366 | caballero | import com.iver.cit.gvsig.layers.VectorialLayerEdited; |
60 | 8765 | jjdelcerro | import com.iver.cit.gvsig.project.documents.view.gui.View; |
61 | 4892 | caballero | import com.iver.utiles.console.JConsole; |
62 | 4115 | fjp | import com.vividsolutions.jts.geom.Envelope; |
63 | 3711 | caballero | |
64 | public class CADToolAdapter extends Behavior { |
||
65 | 6174 | caballero | private static HashMap namesCadTools = new HashMap(); |
66 | 4366 | caballero | |
67 | 6174 | caballero | private EditionManager editionManager = new EditionManager(); |
68 | |||
69 | 5165 | fjp | public static final int ABSOLUTE = 0; |
70 | |||
71 | public static final int RELATIVE_SCP = 1; |
||
72 | |||
73 | public static final int RELATIVE_SCU = 2; |
||
74 | |||
75 | public static final int POLAR_SCP = 3; |
||
76 | |||
77 | public static final int POLAR_SCU = 4; |
||
78 | |||
79 | private double[] previousPoint = null; |
||
80 | |||
81 | 3711 | caballero | private Stack cadToolStack = new Stack(); |
82 | |||
83 | 4115 | fjp | // Para pasarle las coordenadas cuando se produce un evento textEntered
|
84 | 3711 | caballero | private int lastX; |
85 | 4115 | fjp | |
86 | 3711 | caballero | private int lastY; |
87 | 4115 | fjp | |
88 | 3711 | caballero | private FSymbol symbol = new FSymbol(FConstant.SYMBOL_TYPE_POINT, Color.RED); |
89 | 4115 | fjp | |
90 | 3711 | caballero | private Point2D mapAdjustedPoint; |
91 | 5383 | caballero | |
92 | 5261 | fjp | private ISnapper usedSnap = null; |
93 | 4115 | fjp | |
94 | 3711 | caballero | private boolean questionAsked = false; |
95 | 4115 | fjp | |
96 | 3711 | caballero | private Point2D adjustedPoint; |
97 | 4115 | fjp | |
98 | 5874 | fjp | private boolean bRefent = true; |
99 | 4115 | fjp | |
100 | 5874 | fjp | private boolean bForceCoord = false; |
101 | 4115 | fjp | |
102 | private CADGrid cadgrid = new CADGrid(); |
||
103 | |||
104 | 5874 | fjp | private boolean bOrtoMode; |
105 | |||
106 | private Color theTipColor = new Color(255, 255, 155); |
||
107 | 7072 | caballero | |
108 | private static boolean flatnessInitialized=false; |
||
109 | 6713 | caballero | private static Preferences prefs = Preferences.userRoot().node( "cadtooladapter" ); |
110 | 5874 | fjp | |
111 | 3711 | caballero | /**
|
112 | * Pinta de alguna manera especial las geometrias seleccionadas para la
|
||
113 | 4115 | fjp | * edici?n. En caso de que el snapping est? activado, pintar? el efecto del
|
114 | * mismo.
|
||
115 | 5383 | caballero | *
|
116 | 3711 | caballero | * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#paintComponent(java.awt.Graphics)
|
117 | */
|
||
118 | public void paintComponent(Graphics g) { |
||
119 | super.paintComponent(g);
|
||
120 | 6174 | caballero | if (CADExtension.getCADToolAdapter()!=this) |
121 | return;
|
||
122 | 3711 | caballero | if (adjustedPoint != null) { |
123 | 4115 | fjp | Point2D p = null; |
124 | 3711 | caballero | if (mapAdjustedPoint != null) { |
125 | p = mapAdjustedPoint; |
||
126 | } else {
|
||
127 | p = getMapControl().getViewPort().toMapPoint(adjustedPoint); |
||
128 | } |
||
129 | 6174 | caballero | |
130 | 4115 | fjp | ((CADTool) cadToolStack.peek()) |
131 | .drawOperation(g, p.getX(), p.getY()); |
||
132 | 3711 | caballero | } |
133 | 12814 | caballero | drawCursor(g); |
134 | getGrid().drawGrid(g); |
||
135 | 3711 | caballero | } |
136 | |||
137 | /**
|
||
138 | * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
|
||
139 | */
|
||
140 | public void mouseClicked(MouseEvent e) throws BehaviorException { |
||
141 | 4115 | fjp | if (e.getButton() == MouseEvent.BUTTON3) { |
142 | 3883 | caballero | CADExtension.showPopup(e); |
143 | } |
||
144 | 3711 | caballero | } |
145 | |||
146 | /**
|
||
147 | * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
|
||
148 | */
|
||
149 | public void mouseEntered(MouseEvent e) throws BehaviorException { |
||
150 | 3952 | fjp | clearMouseImage(); |
151 | 3711 | caballero | } |
152 | |||
153 | /**
|
||
154 | * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
|
||
155 | */
|
||
156 | public void mouseExited(MouseEvent e) throws BehaviorException { |
||
157 | } |
||
158 | |||
159 | /**
|
||
160 | * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
|
||
161 | */
|
||
162 | public void mousePressed(MouseEvent e) throws BehaviorException { |
||
163 | if (e.getButton() == MouseEvent.BUTTON1) { |
||
164 | ViewPort vp = getMapControl().getMapContext().getViewPort(); |
||
165 | Point2D p;
|
||
166 | |||
167 | 4115 | fjp | if (mapAdjustedPoint != null) { |
168 | 3711 | caballero | p = mapAdjustedPoint; |
169 | } else {
|
||
170 | p = vp.toMapPoint(adjustedPoint); |
||
171 | } |
||
172 | 5165 | fjp | transition(new double[] { p.getX(), p.getY() }, e, ABSOLUTE); |
173 | 3711 | caballero | } |
174 | } |
||
175 | |||
176 | /**
|
||
177 | 4115 | fjp | * Ajusta un punto de la imagen que se pasa como par?metro al grid si ?ste
|
178 | 3711 | caballero | * est? activo y devuelve la distancia de un punto al punto ajustado
|
179 | 5383 | caballero | *
|
180 | 3711 | caballero | * @param point
|
181 | 4115 | fjp | * @param mapHandlerAdjustedPoint
|
182 | * DOCUMENT ME!
|
||
183 | 5383 | caballero | *
|
184 | 5223 | fjp | * @return Distancia del punto que se pasa como
|
185 | 5383 | caballero | * par?metro al punto ajustado. Si no hay ajuste,
|
186 | 5223 | fjp | * devuelve Double.MAX_VALUE
|
187 | 3711 | caballero | */
|
188 | private double adjustToHandler(Point2D point, |
||
189 | 4115 | fjp | Point2D mapHandlerAdjustedPoint) {
|
190 | 5985 | caballero | |
191 | 5874 | fjp | if (!isRefentEnabled())
|
192 | return Double.MAX_VALUE; |
||
193 | 4366 | caballero | |
194 | 5223 | fjp | ILayerEdited aux = CADExtension.getEditionManager().getActiveLayerEdited(); |
195 | 5383 | caballero | if (!(aux instanceof VectorialLayerEdited)) |
196 | 5223 | fjp | return Double.MAX_VALUE; |
197 | 5383 | caballero | VectorialLayerEdited vle = (VectorialLayerEdited) aux; |
198 | 5985 | caballero | |
199 | 5261 | fjp | ArrayList snappers = vle.getSnappers();
|
200 | 5813 | fjp | ArrayList layersToSnap = vle.getLayersToSnap();
|
201 | 5383 | caballero | |
202 | 5813 | fjp | |
203 | 5223 | fjp | ViewPort vp = getMapControl().getViewPort(); |
204 | 5383 | caballero | |
205 | 5261 | fjp | // TODO: PROVISIONAL. PONER ALGO COMO ESTO EN UN CUADRO DE DIALOGO
|
206 | // DE CONFIGURACI?N DEL SNAPPING
|
||
207 | 5874 | fjp | FinalPointSnapper defaultSnap = new FinalPointSnapper();
|
208 | NearestPointSnapper nearestSnap = new NearestPointSnapper();
|
||
209 | 6773 | fjp | // PixelSnapper pixSnap = new PixelSnapper();
|
210 | 5261 | fjp | snappers.clear(); |
211 | snappers.add(defaultSnap); |
||
212 | 5874 | fjp | snappers.add(nearestSnap); |
213 | 6773 | fjp | // snappers.add(pixSnap);
|
214 | 5383 | caballero | |
215 | 5223 | fjp | double mapTolerance = vp.toMapDistance(SelectionCADTool.tolerance);
|
216 | 5261 | fjp | double minDist = mapTolerance;
|
217 | 5817 | fjp | // double rw = getMapControl().getViewPort().toMapDistance(5);
|
218 | Point2D mapPoint = point;
|
||
219 | Rectangle2D r = new Rectangle2D.Double(mapPoint.getX() - mapTolerance / 2, |
||
220 | mapPoint.getY() - mapTolerance / 2, mapTolerance, mapTolerance);
|
||
221 | |||
222 | Envelope e = FConverter.convertRectangle2DtoEnvelope(r); |
||
223 | 5985 | caballero | |
224 | 5261 | fjp | usedSnap = null;
|
225 | Point2D lastPoint = null; |
||
226 | if (previousPoint != null) |
||
227 | { |
||
228 | lastPoint = new Point2D.Double(previousPoint[0], previousPoint[1]); |
||
229 | } |
||
230 | 5813 | fjp | for (int j = 0; j < layersToSnap.size(); j++) |
231 | 5261 | fjp | { |
232 | 5813 | fjp | FLyrVect lyrVect = (FLyrVect) layersToSnap.get(j); |
233 | SpatialCache cache = lyrVect.getSpatialCache(); |
||
234 | if (lyrVect.isVisible())
|
||
235 | { |
||
236 | 5874 | fjp | // La lista de snappers est? siempre ordenada por prioridad. Los de mayor
|
237 | // prioridad est?n primero.
|
||
238 | 5813 | fjp | for (int i = 0; i < snappers.size(); i++) |
239 | 5261 | fjp | { |
240 | 5813 | fjp | ISnapper theSnapper = (ISnapper) snappers.get(i); |
241 | 5985 | caballero | |
242 | 5874 | fjp | if (usedSnap != null) |
243 | { |
||
244 | // Si ya tenemos un snap y es de alta prioridad, cogemos ese. (A no ser que en otra capa encontremos un snapper mejor)
|
||
245 | if (theSnapper.getPriority() < usedSnap.getPriority())
|
||
246 | 5985 | caballero | break;
|
247 | 5874 | fjp | } |
248 | 6771 | fjp | SnappingVisitor snapVisitor = null;
|
249 | Point2D theSnappedPoint = null; |
||
250 | if (theSnapper instanceof ISnapperVectorial) |
||
251 | { |
||
252 | snapVisitor = new SnappingVisitor((ISnapperVectorial) theSnapper, point, mapTolerance, lastPoint);
|
||
253 | // System.out.println("Cache size = " + cache.size());
|
||
254 | cache.query(e, snapVisitor); |
||
255 | theSnappedPoint = snapVisitor.getSnapPoint(); |
||
256 | } |
||
257 | if (theSnapper instanceof ISnapperRaster) |
||
258 | { |
||
259 | ISnapperRaster snapRaster = (ISnapperRaster) theSnapper; |
||
260 | theSnappedPoint = snapRaster.getSnapPoint(getMapControl(), point, mapTolerance, lastPoint); |
||
261 | } |
||
262 | 5985 | caballero | |
263 | 7072 | caballero | |
264 | 6771 | fjp | if (theSnappedPoint != null) { |
265 | double distAux = theSnappedPoint.distance(point);
|
||
266 | if (minDist > distAux)
|
||
267 | 5813 | fjp | { |
268 | 6771 | fjp | minDist = distAux; |
269 | 5813 | fjp | usedSnap = theSnapper; |
270 | 6771 | fjp | mapHandlerAdjustedPoint.setLocation(theSnappedPoint); |
271 | 5813 | fjp | } |
272 | } |
||
273 | 5261 | fjp | } |
274 | 5813 | fjp | } // visible
|
275 | 4115 | fjp | } |
276 | 5261 | fjp | if (usedSnap != null) |
277 | return minDist;
|
||
278 | 3711 | caballero | return Double.MAX_VALUE; |
279 | |||
280 | } |
||
281 | |||
282 | /**
|
||
283 | * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
|
||
284 | */
|
||
285 | public void mouseReleased(MouseEvent e) throws BehaviorException { |
||
286 | 3883 | caballero | getMapControl().repaint(); |
287 | 3711 | caballero | } |
288 | |||
289 | /**
|
||
290 | * @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent)
|
||
291 | */
|
||
292 | public void mouseDragged(MouseEvent e) throws BehaviorException { |
||
293 | lastX = e.getX(); |
||
294 | lastY = e.getY(); |
||
295 | |||
296 | calculateSnapPoint(e.getPoint()); |
||
297 | } |
||
298 | |||
299 | /**
|
||
300 | * @see java.awt.event.MouseMotionListener#mouseMoved(java.awt.event.MouseEvent)
|
||
301 | */
|
||
302 | public void mouseMoved(MouseEvent e) throws BehaviorException { |
||
303 | 3883 | caballero | |
304 | 3711 | caballero | lastX = e.getX(); |
305 | lastY = e.getY(); |
||
306 | |||
307 | calculateSnapPoint(e.getPoint()); |
||
308 | 6071 | caballero | |
309 | 5874 | fjp | showCoords(e.getPoint()); |
310 | 5985 | caballero | |
311 | 3711 | caballero | getMapControl().repaint(); |
312 | } |
||
313 | 4115 | fjp | |
314 | 5874 | fjp | private void showCoords(Point2D pPix) |
315 | { |
||
316 | String[] axisText = new String[2]; |
||
317 | NumberFormat nf = NumberFormat.getInstance(); |
||
318 | MapControl mapControl = getMapControl(); |
||
319 | ViewPort vp = mapControl.getMapContext().getViewPort(); |
||
320 | IProjection iProj = vp.getProjection(); |
||
321 | if (iProj.getAbrev().equals("EPSG:4326") || iProj.getAbrev().equals("EPSG:4230")) { |
||
322 | axisText[0] = "Lon = "; |
||
323 | axisText[1] = "Lat = "; |
||
324 | nf.setMaximumFractionDigits(8);
|
||
325 | } else {
|
||
326 | axisText[0] = "X = "; |
||
327 | axisText[1] = "Y = "; |
||
328 | nf.setMaximumFractionDigits(2);
|
||
329 | } |
||
330 | Point2D p;
|
||
331 | if (mapAdjustedPoint == null) |
||
332 | { |
||
333 | p = vp.toMapPoint(pPix); |
||
334 | } |
||
335 | else
|
||
336 | { |
||
337 | p = mapAdjustedPoint; |
||
338 | } |
||
339 | MainFrame mF = PluginServices.getMainFrame(); |
||
340 | |||
341 | if (mF != null) |
||
342 | 5985 | caballero | { |
343 | 6630 | caballero | mF.getStatusBar().setMessage("units",
|
344 | 8765 | jjdelcerro | PluginServices.getText(this, FConstant.NAMES[vp.getDistanceUnits()]));
|
345 | 6630 | caballero | mF.getStatusBar().setControlValue("scale",String.valueOf(mapControl.getMapContext().getScaleView())); |
346 | mF.getStatusBar().setMessage("projection", iProj.getAbrev());
|
||
347 | 5874 | fjp | |
348 | 6630 | caballero | mF.getStatusBar().setMessage("x",
|
349 | 6878 | cesar | axisText[0] + String.valueOf(nf.format(p.getX()/MapContext.CHANGEM[vp.getDistanceUnits()]))); |
350 | 6630 | caballero | mF.getStatusBar().setMessage("y",
|
351 | 6878 | cesar | axisText[1] + String.valueOf(nf.format(p.getY()/MapContext.CHANGEM[vp.getDistanceUnits()]))); |
352 | 5874 | fjp | } |
353 | } |
||
354 | |||
355 | 4115 | fjp | private void clearMouseImage() { |
356 | 3883 | caballero | int[] pixels = new int[16 * 16]; |
357 | Image image = Toolkit.getDefaultToolkit().createImage( |
||
358 | 4115 | fjp | new MemoryImageSource(16, 16, pixels, 0, 16)); |
359 | Cursor transparentCursor = Toolkit.getDefaultToolkit() |
||
360 | .createCustomCursor(image, new Point(0, 0), "invisiblecursor"); |
||
361 | 3996 | caballero | |
362 | 3952 | fjp | getMapControl().setCursor(transparentCursor); |
363 | 3883 | caballero | } |
364 | 4115 | fjp | |
365 | 3711 | caballero | /**
|
366 | * DOCUMENT ME!
|
||
367 | 5383 | caballero | *
|
368 | 4115 | fjp | * @param g
|
369 | * DOCUMENT ME!
|
||
370 | 3711 | caballero | */
|
371 | private void drawCursor(Graphics g) { |
||
372 | Point2D p = adjustedPoint;
|
||
373 | |||
374 | if (p == null) { |
||
375 | getGrid().setViewPort(getMapControl().getViewPort()); |
||
376 | |||
377 | return;
|
||
378 | } |
||
379 | |||
380 | int size1 = 15; |
||
381 | int size2 = 3; |
||
382 | g.drawLine((int) (p.getX() - size1), (int) (p.getY()), |
||
383 | 4115 | fjp | (int) (p.getX() + size1), (int) (p.getY())); |
384 | 3711 | caballero | g.drawLine((int) (p.getX()), (int) (p.getY() - size1), |
385 | 4115 | fjp | (int) (p.getX()), (int) (p.getY() + size1)); |
386 | 3711 | caballero | |
387 | 5874 | fjp | // getMapControl().setToolTipText(null);
|
388 | 3711 | caballero | if (adjustedPoint != null) { |
389 | 5874 | fjp | if (bForceCoord) {
|
390 | 5261 | fjp | /* g.setColor(Color.ORANGE);
|
391 | 3883 | caballero | g.drawRect((int) (adjustedPoint.getX() - 6),
|
392 | 4115 | fjp | (int) (adjustedPoint.getY() - 6), 12, 12);
|
393 | 3711 | caballero | g.drawRect((int) (adjustedPoint.getX() - 3),
|
394 | 4115 | fjp | (int) (adjustedPoint.getY() - 3), 6, 6);
|
395 | 3711 | caballero | g.setColor(Color.MAGENTA);
|
396 | g.drawRect((int) (adjustedPoint.getX() - 4),
|
||
397 | 5261 | fjp | (int) (adjustedPoint.getY() - 4), 8, 8); */
|
398 | if (usedSnap != null) |
||
399 | 5383 | caballero | { |
400 | 5261 | fjp | usedSnap.draw(g, adjustedPoint); |
401 | 5985 | caballero | |
402 | 5874 | fjp | Graphics2D g2 = (Graphics2D) g; |
403 | FontMetrics metrics = g2.getFontMetrics();
|
||
404 | int w = metrics.stringWidth(usedSnap.getToolTipText()) + 5; |
||
405 | int h = metrics.getMaxAscent() + 5; |
||
406 | int x = (int)p.getX()+9; |
||
407 | int y = (int)p.getY()- 7; |
||
408 | 5985 | caballero | |
409 | 5874 | fjp | g2.setColor(theTipColor ); |
410 | g2.fillRect(x, y-h, w, h); |
||
411 | g2.setColor(Color.BLACK);
|
||
412 | g2.drawRect(x, y-h, w, h); |
||
413 | g2.drawString(usedSnap.getToolTipText(), x+3, y-3); |
||
414 | |||
415 | 5985 | caballero | |
416 | 5817 | fjp | // getMapControl().setToolTipText(usedSnap.getToolTipText());
|
417 | 5261 | fjp | } |
418 | 3711 | caballero | |
419 | 5874 | fjp | bForceCoord = false;
|
420 | 3711 | caballero | } else {
|
421 | g.drawRect((int) (p.getX() - size2), (int) (p.getY() - size2), |
||
422 | 4115 | fjp | (int) (size2 * 2), (int) (size2 * 2)); |
423 | 3711 | caballero | } |
424 | } |
||
425 | } |
||
426 | |||
427 | /**
|
||
428 | * DOCUMENT ME!
|
||
429 | 5383 | caballero | *
|
430 | 3711 | caballero | * @param point
|
431 | */
|
||
432 | private void calculateSnapPoint(Point point) { |
||
433 | 4115 | fjp | // Se comprueba el ajuste a rejilla
|
434 | 3711 | caballero | |
435 | 4115 | fjp | Point2D gridAdjustedPoint = getMapControl().getViewPort().toMapPoint(
|
436 | point); |
||
437 | 3711 | caballero | double minDistance = Double.MAX_VALUE; |
438 | 4115 | fjp | CADTool ct = (CADTool) cadToolStack.peek(); |
439 | if (ct instanceof SelectionCADTool |
||
440 | && ((SelectionCADTool) ct).getStatus().equals( |
||
441 | 4742 | caballero | "Selection.FirstPoint")) {
|
442 | 4115 | fjp | mapAdjustedPoint = gridAdjustedPoint; |
443 | adjustedPoint = (Point2D) point.clone();
|
||
444 | } else {
|
||
445 | 3883 | caballero | |
446 | 4115 | fjp | minDistance = getGrid().adjustToGrid(gridAdjustedPoint); |
447 | 3711 | caballero | if (minDistance < Double.MAX_VALUE) { |
448 | 4115 | fjp | adjustedPoint = getMapControl().getViewPort().fromMapPoint( |
449 | gridAdjustedPoint); |
||
450 | 3711 | caballero | mapAdjustedPoint = gridAdjustedPoint; |
451 | } else {
|
||
452 | mapAdjustedPoint = null;
|
||
453 | } |
||
454 | 3883 | caballero | } |
455 | 3711 | caballero | Point2D handlerAdjustedPoint = null; |
456 | |||
457 | 4115 | fjp | // Se comprueba el ajuste a los handlers
|
458 | 3711 | caballero | if (mapAdjustedPoint != null) { |
459 | 4115 | fjp | handlerAdjustedPoint = (Point2D) mapAdjustedPoint.clone(); // getMapControl().getViewPort().toMapPoint(point); |
460 | 3711 | caballero | } else {
|
461 | 4115 | fjp | handlerAdjustedPoint = getMapControl().getViewPort().toMapPoint( |
462 | point); |
||
463 | 3711 | caballero | } |
464 | |||
465 | Point2D mapPoint = new Point2D.Double(); |
||
466 | double distance = adjustToHandler(handlerAdjustedPoint, mapPoint);
|
||
467 | |||
468 | if (distance < minDistance) {
|
||
469 | 5874 | fjp | bForceCoord = true;
|
470 | 5223 | fjp | adjustedPoint = getMapControl().getViewPort().fromMapPoint(mapPoint); |
471 | 3711 | caballero | mapAdjustedPoint = mapPoint; |
472 | minDistance = distance; |
||
473 | } |
||
474 | |||
475 | 4115 | fjp | // Si no hay ajuste
|
476 | 3711 | caballero | if (minDistance == Double.MAX_VALUE) { |
477 | adjustedPoint = point; |
||
478 | mapAdjustedPoint = null;
|
||
479 | } |
||
480 | |||
481 | } |
||
482 | |||
483 | /**
|
||
484 | * @see java.awt.event.MouseWheelListener#mouseWheelMoved(java.awt.event.MouseWheelEvent)
|
||
485 | */
|
||
486 | public void mouseWheelMoved(MouseWheelEvent e) throws BehaviorException { |
||
487 | } |
||
488 | |||
489 | /**
|
||
490 | * M?todo que realiza las transiciones en las herramientas en funci?n de un
|
||
491 | * texto introducido en la consola
|
||
492 | 5383 | caballero | *
|
493 | 4115 | fjp | * @param text
|
494 | * DOCUMENT ME!
|
||
495 | 3711 | caballero | */
|
496 | public void textEntered(String text) { |
||
497 | if (text == null) { |
||
498 | 6156 | caballero | transition(PluginServices.getText(this,"cancel")); |
499 | 3711 | caballero | } else {
|
500 | 4115 | fjp | /*
|
501 | * if ("".equals(text)) { transition("aceptar"); } else {
|
||
502 | */
|
||
503 | text = text.trim(); |
||
504 | 5223 | fjp | int type = ABSOLUTE;
|
505 | String[] numbers = new String[1]; |
||
506 | numbers[0] = text;
|
||
507 | if (text.indexOf(",") != -1) { |
||
508 | 3711 | caballero | |
509 | 5015 | caballero | numbers = text.split(",");
|
510 | 5165 | fjp | if (numbers[0].substring(0, 1).equals("@")) { |
511 | numbers[0] = numbers[0].substring(1, numbers[0].length()); |
||
512 | type = RELATIVE_SCU; |
||
513 | if (numbers[0].substring(0, 1).equals("*")) { |
||
514 | type = RELATIVE_SCP; |
||
515 | numbers[0] = numbers[0].substring(1, numbers[0] |
||
516 | .length()); |
||
517 | 5015 | caballero | } |
518 | } |
||
519 | 5165 | fjp | } else if (text.indexOf("<") != -1) { |
520 | type = POLAR_SCP; |
||
521 | 5015 | caballero | numbers = text.split("<");
|
522 | 5165 | fjp | if (numbers[0].substring(0, 1).equals("@")) { |
523 | numbers[0] = numbers[0].substring(1, numbers[0].length()); |
||
524 | type = POLAR_SCU; |
||
525 | if (numbers[0].substring(0, 1).equals("*")) { |
||
526 | type = POLAR_SCP; |
||
527 | numbers[0] = numbers[0].substring(1, numbers[0] |
||
528 | .length()); |
||
529 | 5015 | caballero | } |
530 | } |
||
531 | } |
||
532 | |||
533 | 4115 | fjp | double[] values = null; |
534 | 3711 | caballero | |
535 | 4115 | fjp | try {
|
536 | if (numbers.length == 2) { |
||
537 | // punto
|
||
538 | values = new double[] { Double.parseDouble(numbers[0]), |
||
539 | Double.parseDouble(numbers[1]) }; |
||
540 | 5165 | fjp | transition(values, null, type);
|
541 | 4115 | fjp | } else if (numbers.length == 1) { |
542 | // valor
|
||
543 | values = new double[] { Double.parseDouble(numbers[0]) }; |
||
544 | 4147 | fjp | transition(values[0]);
|
545 | 3711 | caballero | } |
546 | 4115 | fjp | } catch (NumberFormatException e) { |
547 | 4147 | fjp | transition(text); |
548 | 5070 | caballero | } catch (NullPointerException e) { |
549 | transition(text); |
||
550 | 4115 | fjp | } |
551 | // }
|
||
552 | 3711 | caballero | } |
553 | 4002 | fjp | getMapControl().repaint(); |
554 | 3711 | caballero | } |
555 | |||
556 | /**
|
||
557 | * DOCUMENT ME!
|
||
558 | */
|
||
559 | 3883 | caballero | public void configureMenu() { |
560 | String[] desc = ((CADTool) cadToolStack.peek()).getDescriptions(); |
||
561 | 4115 | fjp | // String[] labels = ((CADTool)
|
562 | // cadToolStack.peek()).getCurrentTransitions();
|
||
563 | 3883 | caballero | CADExtension.clearMenu(); |
564 | 3711 | caballero | |
565 | for (int i = 0; i < desc.length; i++) { |
||
566 | if (desc[i] != null) { |
||
567 | 5165 | fjp | CADExtension |
568 | .addMenuEntry(PluginServices.getText(this, desc[i]));// , |
||
569 | 5223 | fjp | // labels[i]);
|
570 | 3711 | caballero | } |
571 | } |
||
572 | 3883 | caballero | |
573 | 3711 | caballero | } |
574 | |||
575 | /**
|
||
576 | 4313 | fjp | * Recibe los valores de la transici?n (normalmente un punto) y el evento
|
577 | 5165 | fjp | * con el que se gener? (si fue de rat?n ser? MouseEvent, el que viene en el
|
578 | * pressed) y si es de teclado, ser? un KeyEvent. Del evento se puede sacar
|
||
579 | * informaci?n acerca de si estaba pulsada la tecla CTRL, o Alt, etc.
|
||
580 | 5383 | caballero | *
|
581 | 4115 | fjp | * @param values
|
582 | 4313 | fjp | * @param event
|
583 | 3711 | caballero | */
|
584 | 5165 | fjp | private void transition(double[] values, InputEvent event, int type) { |
585 | 3711 | caballero | questionAsked = true;
|
586 | 4115 | fjp | if (!cadToolStack.isEmpty()) {
|
587 | CADTool ct = (CADTool) cadToolStack.peek(); |
||
588 | 5015 | caballero | |
589 | switch (type) {
|
||
590 | case ABSOLUTE:
|
||
591 | 4313 | fjp | ct.transition(values[0], values[1], event); |
592 | 5165 | fjp | previousPoint = values; |
593 | 5015 | caballero | break;
|
594 | case RELATIVE_SCU:
|
||
595 | 5165 | fjp | // Comprobar que tenemos almacenado el punto anterior
|
596 | // y crear nuevo con coordenadas relativas a ?l.
|
||
597 | double[] auxSCU = values; |
||
598 | if (previousPoint != null) { |
||
599 | auxSCU[0] = previousPoint[0] + values[0]; |
||
600 | auxSCU[1] = previousPoint[1] + values[1]; |
||
601 | 5015 | caballero | } |
602 | ct.transition(auxSCU[0], auxSCU[1], event); |
||
603 | 3744 | caballero | |
604 | 5165 | fjp | previousPoint = auxSCU; |
605 | 5015 | caballero | break;
|
606 | case RELATIVE_SCP:
|
||
607 | 5165 | fjp | // TODO de momento no implementado.
|
608 | 5015 | caballero | ct.transition(values[0], values[1], event); |
609 | 5165 | fjp | previousPoint = values; |
610 | 5015 | caballero | break;
|
611 | case POLAR_SCU:
|
||
612 | 5165 | fjp | // Comprobar que tenemos almacenado el punto anterior
|
613 | // y crear nuevo con coordenadas relativas a ?l.
|
||
614 | double[] auxPolarSCU = values; |
||
615 | if (previousPoint != null) { |
||
616 | Point2D point = UtilFunctions.getPoint(new Point2D.Double( |
||
617 | previousPoint[0], previousPoint[1]), Math |
||
618 | .toRadians(values[1]), values[0]); |
||
619 | auxPolarSCU[0] = point.getX();
|
||
620 | auxPolarSCU[1] = point.getY();
|
||
621 | 5015 | caballero | ct.transition(auxPolarSCU[0], auxPolarSCU[1], event); |
622 | 5165 | fjp | } else {
|
623 | Point2D point = UtilFunctions.getPoint(new Point2D.Double( |
||
624 | 0, 0), Math.toRadians(values[1]), values[0]); |
||
625 | auxPolarSCU[0] = point.getX();
|
||
626 | auxPolarSCU[1] = point.getY();
|
||
627 | 5015 | caballero | ct.transition(auxPolarSCU[0], auxPolarSCU[1], event); |
628 | } |
||
629 | 5165 | fjp | previousPoint = auxPolarSCU; |
630 | 5015 | caballero | break;
|
631 | case POLAR_SCP:
|
||
632 | 5165 | fjp | double[] auxPolarSCP = values; |
633 | if (previousPoint != null) { |
||
634 | Point2D point = UtilFunctions.getPoint(new Point2D.Double( |
||
635 | previousPoint[0], previousPoint[1]), values[1], |
||
636 | values[0]);
|
||
637 | auxPolarSCP[0] = point.getX();
|
||
638 | auxPolarSCP[1] = point.getY();
|
||
639 | 5015 | caballero | ct.transition(auxPolarSCP[0], auxPolarSCP[1], event); |
640 | 5165 | fjp | } else {
|
641 | Point2D point = UtilFunctions.getPoint(new Point2D.Double( |
||
642 | 0, 0), values[1], values[0]); |
||
643 | auxPolarSCP[0] = point.getX();
|
||
644 | auxPolarSCP[1] = point.getY();
|
||
645 | 5015 | caballero | ct.transition(auxPolarSCP[0], auxPolarSCP[1], event); |
646 | } |
||
647 | 5165 | fjp | previousPoint = auxPolarSCP; |
648 | 5015 | caballero | break;
|
649 | default:
|
||
650 | break;
|
||
651 | 4115 | fjp | } |
652 | 5015 | caballero | askQuestion(); |
653 | 3711 | caballero | } |
654 | 3883 | caballero | configureMenu(); |
655 | 4024 | caballero | PluginServices.getMainFrame().enableControls(); |
656 | 3711 | caballero | } |
657 | 4115 | fjp | |
658 | 3744 | caballero | /**
|
659 | * DOCUMENT ME!
|
||
660 | 5383 | caballero | *
|
661 | 4115 | fjp | * @param text
|
662 | * DOCUMENT ME!
|
||
663 | * @param source
|
||
664 | * DOCUMENT ME!
|
||
665 | * @param sel
|
||
666 | * DOCUMENT ME!
|
||
667 | * @param values
|
||
668 | * DOCUMENT ME!
|
||
669 | 3744 | caballero | */
|
670 | 4147 | fjp | private void transition(double value) { |
671 | 3744 | caballero | questionAsked = true;
|
672 | 4115 | fjp | if (!cadToolStack.isEmpty()) {
|
673 | CADTool ct = (CADTool) cadToolStack.peek(); |
||
674 | ct.transition(value); |
||
675 | 3744 | caballero | askQuestion(); |
676 | 4115 | fjp | } |
677 | 3883 | caballero | configureMenu(); |
678 | 3744 | caballero | PluginServices.getMainFrame().enableControls(); |
679 | } |
||
680 | 4115 | fjp | |
681 | 4147 | fjp | public void transition(String option) { |
682 | 4115 | fjp | questionAsked = true;
|
683 | if (!cadToolStack.isEmpty()) {
|
||
684 | CADTool ct = (CADTool) cadToolStack.peek(); |
||
685 | 5165 | fjp | try {
|
686 | ct.transition(option); |
||
687 | } catch (Exception e) { |
||
688 | 12659 | caballero | IWindow window = (IWindow) PluginServices.getMDIManager() |
689 | 6880 | cesar | .getActiveWindow(); |
690 | 12659 | caballero | |
691 | if (window instanceof View) { |
||
692 | ((View)window).getConsolePanel().addText(
|
||
693 | 5165 | fjp | "\n" + PluginServices.getText(this, "incorrect_option") |
694 | + " : " + option, JConsole.ERROR);
|
||
695 | 12659 | caballero | } |
696 | 4892 | caballero | } |
697 | 4115 | fjp | askQuestion(); |
698 | } |
||
699 | configureMenu(); |
||
700 | PluginServices.getMainFrame().enableControls(); |
||
701 | 3744 | caballero | } |
702 | 4115 | fjp | |
703 | 3711 | caballero | /**
|
704 | * DOCUMENT ME!
|
||
705 | 5383 | caballero | *
|
706 | 4115 | fjp | * @param value
|
707 | * DOCUMENT ME!
|
||
708 | 3711 | caballero | */
|
709 | 5874 | fjp | public void setGridVisibility(boolean value) { |
710 | 6713 | caballero | getGrid().setShowGrid(value); |
711 | 3711 | caballero | getGrid().setViewPort(getMapControl().getViewPort()); |
712 | 5874 | fjp | getMapControl().repaint(); |
713 | 3711 | caballero | } |
714 | |||
715 | 5874 | fjp | public void setRefentEnabled(boolean activated) { |
716 | bRefent = activated; |
||
717 | 3711 | caballero | } |
718 | 5985 | caballero | |
719 | 5874 | fjp | public boolean isRefentEnabled() |
720 | { |
||
721 | return bRefent;
|
||
722 | } |
||
723 | 3711 | caballero | |
724 | /**
|
||
725 | * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#getListener()
|
||
726 | */
|
||
727 | public ToolListener getListener() {
|
||
728 | return new ToolListener() { |
||
729 | 4115 | fjp | /**
|
730 | * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getCursor()
|
||
731 | */
|
||
732 | public Cursor getCursor() { |
||
733 | return null; |
||
734 | } |
||
735 | 3711 | caballero | |
736 | 4115 | fjp | /**
|
737 | * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
|
||
738 | */
|
||
739 | public boolean cancelDrawing() { |
||
740 | return false; |
||
741 | } |
||
742 | }; |
||
743 | 3711 | caballero | } |
744 | |||
745 | /**
|
||
746 | * DOCUMENT ME!
|
||
747 | 5383 | caballero | *
|
748 | 3711 | caballero | * @return DOCUMENT ME!
|
749 | */
|
||
750 | public CADTool getCadTool() {
|
||
751 | return (CADTool) cadToolStack.peek();
|
||
752 | } |
||
753 | |||
754 | /**
|
||
755 | * DOCUMENT ME!
|
||
756 | 5383 | caballero | *
|
757 | 4115 | fjp | * @param cadTool
|
758 | * DOCUMENT ME!
|
||
759 | 3711 | caballero | */
|
760 | public void pushCadTool(CADTool cadTool) { |
||
761 | cadToolStack.push(cadTool); |
||
762 | cadTool.setCadToolAdapter(this);
|
||
763 | 4115 | fjp | // cadTool.initializeStatus();
|
764 | // cadTool.setVectorialAdapter(vea);
|
||
765 | /*
|
||
766 | * int ret = cadTool.transition(null, editableFeatureSource, selection,
|
||
767 | * new double[0]);
|
||
768 | 5383 | caballero | *
|
769 | 4115 | fjp | * if ((ret & Automaton.AUTOMATON_FINISHED) ==
|
770 | * Automaton.AUTOMATON_FINISHED) { popCadTool();
|
||
771 | 5383 | caballero | *
|
772 | 4115 | fjp | * if (cadToolStack.isEmpty()) { pushCadTool(new
|
773 | * com.iver.cit.gvsig.gui.cad.smc.gen.CADTool());//new
|
||
774 | * SelectionCadTool());
|
||
775 | * PluginServices.getMainFrame().setSelectedTool("selection"); }
|
||
776 | 5383 | caballero | *
|
777 | 4115 | fjp | * askQuestion();
|
778 | 5383 | caballero | *
|
779 | 4115 | fjp | * getMapControl().drawMap(false); }
|
780 | */
|
||
781 | 3711 | caballero | } |
782 | |||
783 | /**
|
||
784 | * DOCUMENT ME!
|
||
785 | */
|
||
786 | public void popCadTool() { |
||
787 | cadToolStack.pop(); |
||
788 | } |
||
789 | |||
790 | /**
|
||
791 | * DOCUMENT ME!
|
||
792 | */
|
||
793 | public void askQuestion() { |
||
794 | 4115 | fjp | CADTool cadtool = (CADTool) cadToolStack.peek(); |
795 | /*
|
||
796 | * if (cadtool..getStatus()==0){
|
||
797 | * PluginServices.getMainFrame().addTextToConsole("\n"
|
||
798 | * +cadtool.getName()); }
|
||
799 | */
|
||
800 | 6880 | cesar | if (PluginServices.getMDIManager().getActiveWindow() instanceof View) |
801 | 5923 | fjp | { |
802 | 6880 | cesar | View vista = (View) PluginServices.getMDIManager().getActiveWindow(); |
803 | 5923 | fjp | vista.getConsolePanel().addText( |
804 | "\n" + "#" + cadtool.getQuestion() + " > ", JConsole.MESSAGE); |
||
805 | // ***PluginServices.getMainFrame().addTextToConsole("\n" +
|
||
806 | // cadtool.getQuestion());
|
||
807 | questionAsked = true;
|
||
808 | } |
||
809 | 3711 | caballero | |
810 | } |
||
811 | |||
812 | /**
|
||
813 | * DOCUMENT ME!
|
||
814 | 5383 | caballero | *
|
815 | 4115 | fjp | * @param cadTool
|
816 | * DOCUMENT ME!
|
||
817 | 3711 | caballero | */
|
818 | public void setCadTool(CADTool cadTool) { |
||
819 | cadToolStack.clear(); |
||
820 | pushCadTool(cadTool); |
||
821 | 5165 | fjp | // askQuestion();
|
822 | 3711 | caballero | } |
823 | |||
824 | |||
825 | /**
|
||
826 | * Elimina las geometr?as seleccionadas actualmente
|
||
827 | */
|
||
828 | private void delete() { |
||
829 | 5223 | fjp | ILayerEdited aux = CADExtension.getEditionManager().getActiveLayerEdited(); |
830 | 5383 | caballero | if (!(aux instanceof VectorialLayerEdited)) |
831 | 5223 | fjp | return;
|
832 | 5383 | caballero | VectorialLayerEdited vle = (VectorialLayerEdited) aux; |
833 | 5223 | fjp | VectorialEditableAdapter vea = vle.getVEA(); |
834 | |||
835 | 3711 | caballero | vea.startComplexRow(); |
836 | 5223 | fjp | FBitSet selection = vea.getSelection(); |
837 | 3711 | caballero | try {
|
838 | 4115 | fjp | int[] indexesToDel = new int[selection.cardinality()]; |
839 | int j = 0; |
||
840 | for (int i = selection.nextSetBit(0); i >= 0; i = selection |
||
841 | .nextSetBit(i + 1)) {
|
||
842 | indexesToDel[j++] = i; |
||
843 | // /vea.removeRow(i);
|
||
844 | 4584 | caballero | } |
845 | 5985 | caballero | |
846 | // ArrayList selectedRow = vle.getSelectedRow();
|
||
847 | //
|
||
848 | // int[] indexesToDel = new int[selectedRow.size()];
|
||
849 | // for (int i = 0;i < selectedRow.size(); i++) {
|
||
850 | // IRowEdited edRow = (IRowEdited) selectedRow.get(i);
|
||
851 | // indexesToDel[i] = vea.getInversedIndex(edRow.getIndex());
|
||
852 | // }
|
||
853 | //
|
||
854 | 4454 | fjp | for (int i = indexesToDel.length - 1; i >= 0; i--) { |
855 | 5165 | fjp | vea.removeRow(indexesToDel[i], PluginServices.getText(this,
|
856 | 5184 | caballero | "deleted_feature"),EditionEvent.GRAPHIC);
|
857 | 3711 | caballero | } |
858 | } catch (DriverIOException e) {
|
||
859 | 12643 | caballero | NotificationManager.addError(e.getMessage(), e); |
860 | 3711 | caballero | } catch (IOException e) { |
861 | 12643 | caballero | NotificationManager.addError(e.getMessage(), e); |
862 | 3711 | caballero | } finally {
|
863 | try {
|
||
864 | 6071 | caballero | String description=PluginServices.getText(this,"remove_geometry"); |
865 | vea.endComplexRow(description); |
||
866 | 3711 | caballero | } catch (IOException e1) { |
867 | 12643 | caballero | NotificationManager.addError(e1.getMessage(), e1); |
868 | 3711 | caballero | } catch (DriverIOException e1) {
|
869 | 12643 | caballero | NotificationManager.addError(e1.getMessage(), e1); |
870 | 3711 | caballero | } |
871 | } |
||
872 | 3999 | caballero | System.out.println("clear Selection"); |
873 | 3711 | caballero | selection.clear(); |
874 | 4366 | caballero | vle.clearSelection(); |
875 | 5165 | fjp | /*
|
876 | * if (getCadTool() instanceof SelectionCADTool) { SelectionCADTool
|
||
877 | * selTool = (SelectionCADTool) getCadTool(); selTool.clearSelection(); }
|
||
878 | */
|
||
879 | 5923 | fjp | refreshEditedLayer(); |
880 | 3711 | caballero | } |
881 | |||
882 | /**
|
||
883 | * DOCUMENT ME!
|
||
884 | 5383 | caballero | *
|
885 | 3711 | caballero | * @param b
|
886 | */
|
||
887 | public void setAdjustGrid(boolean b) { |
||
888 | getGrid().setAdjustGrid(b); |
||
889 | } |
||
890 | |||
891 | /**
|
||
892 | * DOCUMENT ME!
|
||
893 | 5383 | caballero | *
|
894 | 3711 | caballero | * @param actionCommand
|
895 | */
|
||
896 | public void keyPressed(String actionCommand) { |
||
897 | 8765 | jjdelcerro | if (CADExtension.getEditionManager().getActiveLayerEdited()== null) { |
898 | 7831 | jmvivo | return;
|
899 | } |
||
900 | 3725 | caballero | if (actionCommand.equals("eliminar")) { |
901 | 3711 | caballero | delete(); |
902 | } else if (actionCommand.equals("escape")) { |
||
903 | 6385 | fjp | if (getMapControl().getCurrentTool().equals("cadtooladapter")) { |
904 | 3847 | caballero | CADTool ct = (CADTool) cadToolStack.peek(); |
905 | ct.end(); |
||
906 | 3711 | caballero | cadToolStack.clear(); |
907 | 4210 | fjp | SelectionCADTool selCad = new SelectionCADTool();
|
908 | selCad.init(); |
||
909 | 5165 | fjp | VectorialLayerEdited vle = (VectorialLayerEdited) CADExtension |
910 | .getEditionManager().getActiveLayerEdited(); |
||
911 | 4366 | caballero | vle.clearSelection(); |
912 | |||
913 | 4210 | fjp | pushCadTool(selCad); |
914 | // getVectorialAdapter().getSelection().clear();
|
||
915 | 5985 | caballero | |
916 | 5923 | fjp | refreshEditedLayer(); |
917 | 5985 | caballero | |
918 | |||
919 | 5015 | caballero | PluginServices.getMainFrame().setSelectedTool("_selection");
|
920 | 5165 | fjp | // askQuestion();
|
921 | } else {
|
||
922 | 4892 | caballero | getMapControl().setPrevTool(); |
923 | 3711 | caballero | } |
924 | } |
||
925 | 3725 | caballero | |
926 | 3711 | caballero | PluginServices.getMainFrame().enableControls(); |
927 | |||
928 | } |
||
929 | 5985 | caballero | |
930 | 5923 | fjp | /**
|
931 | * Provoca un repintado "soft" de la capa activa en edici?n.
|
||
932 | 5985 | caballero | * Las capas por debajo de ella no se dibujan de verdad, solo
|
933 | 5923 | fjp | * se dibuja la que est? en edici?n y las que est?n por encima
|
934 | * de ella en el TOC.
|
||
935 | */
|
||
936 | public void refreshEditedLayer() |
||
937 | { |
||
938 | ILayerEdited edLayer = CADExtension.getEditionManager().getActiveLayerEdited(); |
||
939 | if (edLayer != null) |
||
940 | { |
||
941 | edLayer.getLayer().setDirty(true);
|
||
942 | getMapControl().rePaintDirtyLayers(); |
||
943 | } |
||
944 | 5985 | caballero | |
945 | 5923 | fjp | } |
946 | 4115 | fjp | |
947 | public CADGrid getGrid() {
|
||
948 | 3711 | caballero | return cadgrid;
|
949 | } |
||
950 | 4115 | fjp | |
951 | 5874 | fjp | public boolean isOrtoMode() { |
952 | return bOrtoMode;
|
||
953 | } |
||
954 | 4115 | fjp | |
955 | 5874 | fjp | public void setOrtoMode(boolean b) { |
956 | bOrtoMode = b; |
||
957 | } |
||
958 | |||
959 | 6174 | caballero | public static void addCADTool(String name, CADTool c) { |
960 | namesCadTools.put(name, c); |
||
961 | 5874 | fjp | |
962 | 6174 | caballero | } |
963 | public static CADTool[] getCADTools() { |
||
964 | return (CADTool[]) CADToolAdapter.namesCadTools.values().toArray(new CADTool[0]); |
||
965 | } |
||
966 | public CADTool getCADTool(String text) { |
||
967 | CADTool ct = (CADTool) namesCadTools.get(text); |
||
968 | return ct;
|
||
969 | } |
||
970 | |||
971 | public EditionManager getEditionManager() {
|
||
972 | return editionManager;
|
||
973 | } |
||
974 | |||
975 | 6713 | caballero | public void initializeFlatness() { |
976 | 7072 | caballero | if (!flatnessInitialized){
|
977 | flatnessInitialized=true;
|
||
978 | Preferences prefs = Preferences.userRoot().node( "cadtooladapter" ); |
||
979 | double flatness = prefs.getDouble("flatness",FConverter.FLATNESS); |
||
980 | FConverter.FLATNESS=flatness; |
||
981 | } |
||
982 | 6713 | caballero | } |
983 | public void initializeGrid(){ |
||
984 | boolean showGrid = prefs.getBoolean("grid.showgrid",getGrid().isShowGrid()); |
||
985 | boolean adjustGrid = prefs.getBoolean("grid.adjustgrid",getGrid().isAdjustGrid()); |
||
986 | |||
987 | double dx = prefs.getDouble("grid.distancex",getGrid().getGridSizeX()); |
||
988 | double dy = prefs.getDouble("grid.distancey",getGrid().getGridSizeY()); |
||
989 | |||
990 | setGridVisibility(showGrid); |
||
991 | setAdjustGrid(adjustGrid); |
||
992 | getGrid().setGridSizeX(dx); |
||
993 | getGrid().setGridSizeY(dy); |
||
994 | } |
||
995 | 12159 | caballero | /**
|
996 | * Returns the type of active layer.
|
||
997 | **/
|
||
998 | public int getActiveLayerType() { |
||
999 | int type=FShape.MULTI;
|
||
1000 | try {
|
||
1001 | type=((FLyrVect)CADExtension.getEditionManager().getActiveLayerEdited().getLayer()).getShapeType(); |
||
1002 | } catch (DriverException e) {
|
||
1003 | NotificationManager.addError(e); |
||
1004 | } |
||
1005 | return type;
|
||
1006 | } |
||
1007 | 6713 | caballero | |
1008 | 3711 | caballero | } |