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