svn-gvsig-desktop / tags / v1_1_Build_1009 / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / CADToolAdapter.java @ 12649
History | View | Annotate | Download (27.7 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 | 3883 | caballero | import com.iver.cit.gvsig.CADExtension; |
30 | 6174 | caballero | import com.iver.cit.gvsig.EditionManager; |
31 | 12159 | caballero | import com.iver.cit.gvsig.fmap.DriverException; |
32 | 6878 | cesar | import com.iver.cit.gvsig.fmap.MapContext; |
33 | 5874 | fjp | import com.iver.cit.gvsig.fmap.MapControl; |
34 | 3711 | caballero | import com.iver.cit.gvsig.fmap.ViewPort; |
35 | 12159 | caballero | import com.iver.cit.gvsig.fmap.core.FShape; |
36 | 3711 | caballero | import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
37 | 4124 | fjp | import com.iver.cit.gvsig.fmap.core.v02.FConverter; |
38 | 3711 | caballero | import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
39 | import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
||
40 | 5184 | caballero | import com.iver.cit.gvsig.fmap.edition.EditionEvent; |
41 | 5015 | caballero | import com.iver.cit.gvsig.fmap.edition.UtilFunctions; |
42 | 3711 | caballero | import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter; |
43 | import com.iver.cit.gvsig.fmap.layers.FBitSet; |
||
44 | 5223 | fjp | import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
45 | import com.iver.cit.gvsig.fmap.layers.SpatialCache; |
||
46 | 3711 | caballero | import com.iver.cit.gvsig.fmap.tools.BehaviorException; |
47 | import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior; |
||
48 | import com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener; |
||
49 | 6771 | fjp | import com.iver.cit.gvsig.gui.cad.snapping.FinalPointSnapper; |
50 | 5261 | fjp | import com.iver.cit.gvsig.gui.cad.snapping.ISnapper; |
51 | 6771 | fjp | import com.iver.cit.gvsig.gui.cad.snapping.ISnapperRaster; |
52 | import com.iver.cit.gvsig.gui.cad.snapping.ISnapperVectorial; |
||
53 | 5223 | fjp | import com.iver.cit.gvsig.gui.cad.snapping.NearestPointSnapper; |
54 | 6771 | fjp | import com.iver.cit.gvsig.gui.cad.snapping.PixelSnapper; |
55 | 5223 | fjp | import com.iver.cit.gvsig.gui.cad.snapping.SnappingVisitor; |
56 | 3847 | caballero | import com.iver.cit.gvsig.gui.cad.tools.SelectionCADTool; |
57 | 5223 | fjp | import com.iver.cit.gvsig.layers.ILayerEdited; |
58 | 4366 | caballero | import com.iver.cit.gvsig.layers.VectorialLayerEdited; |
59 | 8765 | jjdelcerro | import com.iver.cit.gvsig.project.documents.view.gui.View; |
60 | 4892 | caballero | import com.iver.utiles.console.JConsole; |
61 | 4115 | fjp | import com.vividsolutions.jts.geom.Envelope; |
62 | 3711 | caballero | |
63 | public class CADToolAdapter extends Behavior { |
||
64 | 6174 | caballero | private static HashMap namesCadTools = new HashMap(); |
65 | 4366 | caballero | |
66 | 6174 | caballero | private EditionManager editionManager = new EditionManager(); |
67 | |||
68 | 5165 | fjp | public static final int ABSOLUTE = 0; |
69 | |||
70 | public static final int RELATIVE_SCP = 1; |
||
71 | |||
72 | public static final int RELATIVE_SCU = 2; |
||
73 | |||
74 | public static final int POLAR_SCP = 3; |
||
75 | |||
76 | public static final int POLAR_SCU = 4; |
||
77 | |||
78 | private double[] previousPoint = null; |
||
79 | |||
80 | 3711 | caballero | private Stack cadToolStack = new Stack(); |
81 | |||
82 | 4115 | fjp | // Para pasarle las coordenadas cuando se produce un evento textEntered
|
83 | 3711 | caballero | private int lastX; |
84 | 4115 | fjp | |
85 | 3711 | caballero | private int lastY; |
86 | 4115 | fjp | |
87 | 3711 | caballero | private FSymbol symbol = new FSymbol(FConstant.SYMBOL_TYPE_POINT, Color.RED); |
88 | 4115 | fjp | |
89 | 3711 | caballero | private Point2D mapAdjustedPoint; |
90 | 5383 | caballero | |
91 | 5261 | fjp | private ISnapper usedSnap = null; |
92 | 4115 | fjp | |
93 | 3711 | caballero | private boolean questionAsked = false; |
94 | 4115 | fjp | |
95 | 3711 | caballero | private Point2D adjustedPoint; |
96 | 4115 | fjp | |
97 | 5874 | fjp | private boolean bRefent = true; |
98 | 4115 | fjp | |
99 | 5874 | fjp | private boolean bForceCoord = false; |
100 | 4115 | fjp | |
101 | private CADGrid cadgrid = new CADGrid(); |
||
102 | |||
103 | 5874 | fjp | private boolean bOrtoMode; |
104 | |||
105 | private Color theTipColor = new Color(255, 255, 155); |
||
106 | 7072 | caballero | |
107 | private static boolean flatnessInitialized=false; |
||
108 | 6713 | caballero | private static Preferences prefs = Preferences.userRoot().node( "cadtooladapter" ); |
109 | 5874 | fjp | |
110 | 3711 | caballero | /**
|
111 | * Pinta de alguna manera especial las geometrias seleccionadas para la
|
||
112 | 4115 | fjp | * edici?n. En caso de que el snapping est? activado, pintar? el efecto del
|
113 | * mismo.
|
||
114 | 5383 | caballero | *
|
115 | 3711 | caballero | * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#paintComponent(java.awt.Graphics)
|
116 | */
|
||
117 | public void paintComponent(Graphics g) { |
||
118 | super.paintComponent(g);
|
||
119 | 6174 | caballero | if (CADExtension.getCADToolAdapter()!=this) |
120 | return;
|
||
121 | 3711 | caballero | drawCursor(g); |
122 | 3883 | caballero | getGrid().drawGrid(g); |
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 | } |
||
135 | |||
136 | /**
|
||
137 | * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
|
||
138 | */
|
||
139 | public void mouseClicked(MouseEvent e) throws BehaviorException { |
||
140 | 4115 | fjp | if (e.getButton() == MouseEvent.BUTTON3) { |
141 | 3883 | caballero | CADExtension.showPopup(e); |
142 | } |
||
143 | 3711 | caballero | } |
144 | |||
145 | /**
|
||
146 | * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
|
||
147 | */
|
||
148 | public void mouseEntered(MouseEvent e) throws BehaviorException { |
||
149 | 3952 | fjp | clearMouseImage(); |
150 | 3711 | caballero | } |
151 | |||
152 | /**
|
||
153 | * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
|
||
154 | */
|
||
155 | public void mouseExited(MouseEvent e) throws BehaviorException { |
||
156 | } |
||
157 | |||
158 | /**
|
||
159 | * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
|
||
160 | */
|
||
161 | public void mousePressed(MouseEvent e) throws BehaviorException { |
||
162 | if (e.getButton() == MouseEvent.BUTTON1) { |
||
163 | ViewPort vp = getMapControl().getMapContext().getViewPort(); |
||
164 | Point2D p;
|
||
165 | |||
166 | 4115 | fjp | if (mapAdjustedPoint != null) { |
167 | 3711 | caballero | p = mapAdjustedPoint; |
168 | } else {
|
||
169 | p = vp.toMapPoint(adjustedPoint); |
||
170 | } |
||
171 | 5165 | fjp | transition(new double[] { p.getX(), p.getY() }, e, ABSOLUTE); |
172 | 3711 | caballero | } |
173 | } |
||
174 | |||
175 | /**
|
||
176 | 4115 | fjp | * Ajusta un punto de la imagen que se pasa como par?metro al grid si ?ste
|
177 | 3711 | caballero | * est? activo y devuelve la distancia de un punto al punto ajustado
|
178 | 5383 | caballero | *
|
179 | 3711 | caballero | * @param point
|
180 | 4115 | fjp | * @param mapHandlerAdjustedPoint
|
181 | * DOCUMENT ME!
|
||
182 | 5383 | caballero | *
|
183 | 5223 | fjp | * @return Distancia del punto que se pasa como
|
184 | 5383 | caballero | * par?metro al punto ajustado. Si no hay ajuste,
|
185 | 5223 | fjp | * devuelve Double.MAX_VALUE
|
186 | 3711 | caballero | */
|
187 | private double adjustToHandler(Point2D point, |
||
188 | 4115 | fjp | Point2D mapHandlerAdjustedPoint) {
|
189 | 5985 | caballero | |
190 | 5874 | fjp | if (!isRefentEnabled())
|
191 | return Double.MAX_VALUE; |
||
192 | 4366 | caballero | |
193 | 5223 | fjp | ILayerEdited aux = CADExtension.getEditionManager().getActiveLayerEdited(); |
194 | 5383 | caballero | if (!(aux instanceof VectorialLayerEdited)) |
195 | 5223 | fjp | return Double.MAX_VALUE; |
196 | 5383 | caballero | VectorialLayerEdited vle = (VectorialLayerEdited) aux; |
197 | 5985 | caballero | |
198 | 5261 | fjp | ArrayList snappers = vle.getSnappers();
|
199 | 5813 | fjp | ArrayList layersToSnap = vle.getLayersToSnap();
|
200 | 5383 | caballero | |
201 | 5813 | fjp | |
202 | 5223 | fjp | ViewPort vp = getMapControl().getViewPort(); |
203 | 5383 | caballero | |
204 | 5261 | fjp | // TODO: PROVISIONAL. PONER ALGO COMO ESTO EN UN CUADRO DE DIALOGO
|
205 | // DE CONFIGURACI?N DEL SNAPPING
|
||
206 | 5874 | fjp | FinalPointSnapper defaultSnap = new FinalPointSnapper();
|
207 | NearestPointSnapper nearestSnap = new NearestPointSnapper();
|
||
208 | 6773 | fjp | // PixelSnapper pixSnap = new PixelSnapper();
|
209 | 5261 | fjp | snappers.clear(); |
210 | snappers.add(defaultSnap); |
||
211 | 5874 | fjp | snappers.add(nearestSnap); |
212 | 6773 | fjp | // snappers.add(pixSnap);
|
213 | 5383 | caballero | |
214 | 5223 | fjp | double mapTolerance = vp.toMapDistance(SelectionCADTool.tolerance);
|
215 | 5261 | fjp | double minDist = mapTolerance;
|
216 | 5817 | fjp | // double rw = getMapControl().getViewPort().toMapDistance(5);
|
217 | Point2D mapPoint = point;
|
||
218 | Rectangle2D r = new Rectangle2D.Double(mapPoint.getX() - mapTolerance / 2, |
||
219 | mapPoint.getY() - mapTolerance / 2, mapTolerance, mapTolerance);
|
||
220 | |||
221 | Envelope e = FConverter.convertRectangle2DtoEnvelope(r); |
||
222 | 5985 | caballero | |
223 | 5261 | fjp | usedSnap = null;
|
224 | Point2D lastPoint = null; |
||
225 | if (previousPoint != null) |
||
226 | { |
||
227 | lastPoint = new Point2D.Double(previousPoint[0], previousPoint[1]); |
||
228 | } |
||
229 | 5813 | fjp | for (int j = 0; j < layersToSnap.size(); j++) |
230 | 5261 | fjp | { |
231 | 5813 | fjp | FLyrVect lyrVect = (FLyrVect) layersToSnap.get(j); |
232 | SpatialCache cache = lyrVect.getSpatialCache(); |
||
233 | if (lyrVect.isVisible())
|
||
234 | { |
||
235 | 5874 | fjp | // La lista de snappers est? siempre ordenada por prioridad. Los de mayor
|
236 | // prioridad est?n primero.
|
||
237 | 5813 | fjp | for (int i = 0; i < snappers.size(); i++) |
238 | 5261 | fjp | { |
239 | 5813 | fjp | ISnapper theSnapper = (ISnapper) snappers.get(i); |
240 | 5985 | caballero | |
241 | 5874 | fjp | if (usedSnap != null) |
242 | { |
||
243 | // Si ya tenemos un snap y es de alta prioridad, cogemos ese. (A no ser que en otra capa encontremos un snapper mejor)
|
||
244 | if (theSnapper.getPriority() < usedSnap.getPriority())
|
||
245 | 5985 | caballero | break;
|
246 | 5874 | fjp | } |
247 | 6771 | fjp | SnappingVisitor snapVisitor = null;
|
248 | Point2D theSnappedPoint = null; |
||
249 | if (theSnapper instanceof ISnapperVectorial) |
||
250 | { |
||
251 | snapVisitor = new SnappingVisitor((ISnapperVectorial) theSnapper, point, mapTolerance, lastPoint);
|
||
252 | // System.out.println("Cache size = " + cache.size());
|
||
253 | cache.query(e, snapVisitor); |
||
254 | theSnappedPoint = snapVisitor.getSnapPoint(); |
||
255 | } |
||
256 | if (theSnapper instanceof ISnapperRaster) |
||
257 | { |
||
258 | ISnapperRaster snapRaster = (ISnapperRaster) theSnapper; |
||
259 | theSnappedPoint = snapRaster.getSnapPoint(getMapControl(), point, mapTolerance, lastPoint); |
||
260 | } |
||
261 | 5985 | caballero | |
262 | 7072 | caballero | |
263 | 6771 | fjp | if (theSnappedPoint != null) { |
264 | double distAux = theSnappedPoint.distance(point);
|
||
265 | if (minDist > distAux)
|
||
266 | 5813 | fjp | { |
267 | 6771 | fjp | minDist = distAux; |
268 | 5813 | fjp | usedSnap = theSnapper; |
269 | 6771 | fjp | mapHandlerAdjustedPoint.setLocation(theSnappedPoint); |
270 | 5813 | fjp | } |
271 | } |
||
272 | 5261 | fjp | } |
273 | 5813 | fjp | } // visible
|
274 | 4115 | fjp | } |
275 | 5261 | fjp | if (usedSnap != null) |
276 | return minDist;
|
||
277 | 3711 | caballero | return Double.MAX_VALUE; |
278 | |||
279 | } |
||
280 | |||
281 | /**
|
||
282 | * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
|
||
283 | */
|
||
284 | public void mouseReleased(MouseEvent e) throws BehaviorException { |
||
285 | 3883 | caballero | getMapControl().repaint(); |
286 | 3711 | caballero | } |
287 | |||
288 | /**
|
||
289 | * @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent)
|
||
290 | */
|
||
291 | public void mouseDragged(MouseEvent e) throws BehaviorException { |
||
292 | lastX = e.getX(); |
||
293 | lastY = e.getY(); |
||
294 | |||
295 | calculateSnapPoint(e.getPoint()); |
||
296 | } |
||
297 | |||
298 | /**
|
||
299 | * @see java.awt.event.MouseMotionListener#mouseMoved(java.awt.event.MouseEvent)
|
||
300 | */
|
||
301 | public void mouseMoved(MouseEvent e) throws BehaviorException { |
||
302 | 3883 | caballero | |
303 | 3711 | caballero | lastX = e.getX(); |
304 | lastY = e.getY(); |
||
305 | |||
306 | calculateSnapPoint(e.getPoint()); |
||
307 | 6071 | caballero | |
308 | 5874 | fjp | showCoords(e.getPoint()); |
309 | 5985 | caballero | |
310 | 3711 | caballero | getMapControl().repaint(); |
311 | } |
||
312 | 4115 | fjp | |
313 | 5874 | fjp | private void showCoords(Point2D pPix) |
314 | { |
||
315 | String[] axisText = new String[2]; |
||
316 | NumberFormat nf = NumberFormat.getInstance(); |
||
317 | MapControl mapControl = getMapControl(); |
||
318 | ViewPort vp = mapControl.getMapContext().getViewPort(); |
||
319 | IProjection iProj = vp.getProjection(); |
||
320 | if (iProj.getAbrev().equals("EPSG:4326") || iProj.getAbrev().equals("EPSG:4230")) { |
||
321 | axisText[0] = "Lon = "; |
||
322 | axisText[1] = "Lat = "; |
||
323 | nf.setMaximumFractionDigits(8);
|
||
324 | } else {
|
||
325 | axisText[0] = "X = "; |
||
326 | axisText[1] = "Y = "; |
||
327 | nf.setMaximumFractionDigits(2);
|
||
328 | } |
||
329 | Point2D p;
|
||
330 | if (mapAdjustedPoint == null) |
||
331 | { |
||
332 | p = vp.toMapPoint(pPix); |
||
333 | } |
||
334 | else
|
||
335 | { |
||
336 | p = mapAdjustedPoint; |
||
337 | } |
||
338 | MainFrame mF = PluginServices.getMainFrame(); |
||
339 | |||
340 | if (mF != null) |
||
341 | 5985 | caballero | { |
342 | 6630 | caballero | mF.getStatusBar().setMessage("units",
|
343 | 8765 | jjdelcerro | PluginServices.getText(this, FConstant.NAMES[vp.getDistanceUnits()]));
|
344 | 6630 | caballero | mF.getStatusBar().setControlValue("scale",String.valueOf(mapControl.getMapContext().getScaleView())); |
345 | mF.getStatusBar().setMessage("projection", iProj.getAbrev());
|
||
346 | 5874 | fjp | |
347 | 6630 | caballero | mF.getStatusBar().setMessage("x",
|
348 | 6878 | cesar | axisText[0] + String.valueOf(nf.format(p.getX()/MapContext.CHANGEM[vp.getDistanceUnits()]))); |
349 | 6630 | caballero | mF.getStatusBar().setMessage("y",
|
350 | 6878 | cesar | axisText[1] + String.valueOf(nf.format(p.getY()/MapContext.CHANGEM[vp.getDistanceUnits()]))); |
351 | 5874 | fjp | } |
352 | } |
||
353 | |||
354 | 4115 | fjp | private void clearMouseImage() { |
355 | 3883 | caballero | int[] pixels = new int[16 * 16]; |
356 | Image image = Toolkit.getDefaultToolkit().createImage( |
||
357 | 4115 | fjp | new MemoryImageSource(16, 16, pixels, 0, 16)); |
358 | Cursor transparentCursor = Toolkit.getDefaultToolkit() |
||
359 | .createCustomCursor(image, new Point(0, 0), "invisiblecursor"); |
||
360 | 3996 | caballero | |
361 | 3952 | fjp | getMapControl().setCursor(transparentCursor); |
362 | 3883 | caballero | } |
363 | 4115 | fjp | |
364 | 3711 | caballero | /**
|
365 | * DOCUMENT ME!
|
||
366 | 5383 | caballero | *
|
367 | 4115 | fjp | * @param g
|
368 | * DOCUMENT ME!
|
||
369 | 3711 | caballero | */
|
370 | private void drawCursor(Graphics g) { |
||
371 | 3996 | caballero | |
372 | 3711 | caballero | 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 | View vista = (View) PluginServices.getMDIManager() |
||
689 | 6880 | cesar | .getActiveWindow(); |
690 | 5165 | fjp | vista.getConsolePanel().addText( |
691 | "\n" + PluginServices.getText(this, "incorrect_option") |
||
692 | + " : " + option, JConsole.ERROR);
|
||
693 | 4892 | caballero | } |
694 | 4115 | fjp | askQuestion(); |
695 | } |
||
696 | configureMenu(); |
||
697 | PluginServices.getMainFrame().enableControls(); |
||
698 | 3744 | caballero | } |
699 | 4115 | fjp | |
700 | 3711 | caballero | /**
|
701 | * DOCUMENT ME!
|
||
702 | 5383 | caballero | *
|
703 | 4115 | fjp | * @param value
|
704 | * DOCUMENT ME!
|
||
705 | 3711 | caballero | */
|
706 | 5874 | fjp | public void setGridVisibility(boolean value) { |
707 | 6713 | caballero | getGrid().setShowGrid(value); |
708 | 3711 | caballero | getGrid().setViewPort(getMapControl().getViewPort()); |
709 | 5874 | fjp | getMapControl().repaint(); |
710 | 3711 | caballero | } |
711 | |||
712 | 5874 | fjp | public void setRefentEnabled(boolean activated) { |
713 | bRefent = activated; |
||
714 | 3711 | caballero | } |
715 | 5985 | caballero | |
716 | 5874 | fjp | public boolean isRefentEnabled() |
717 | { |
||
718 | return bRefent;
|
||
719 | } |
||
720 | 3711 | caballero | |
721 | /**
|
||
722 | * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#getListener()
|
||
723 | */
|
||
724 | public ToolListener getListener() {
|
||
725 | return new ToolListener() { |
||
726 | 4115 | fjp | /**
|
727 | * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getCursor()
|
||
728 | */
|
||
729 | public Cursor getCursor() { |
||
730 | return null; |
||
731 | } |
||
732 | 3711 | caballero | |
733 | 4115 | fjp | /**
|
734 | * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
|
||
735 | */
|
||
736 | public boolean cancelDrawing() { |
||
737 | return false; |
||
738 | } |
||
739 | }; |
||
740 | 3711 | caballero | } |
741 | |||
742 | /**
|
||
743 | * DOCUMENT ME!
|
||
744 | 5383 | caballero | *
|
745 | 3711 | caballero | * @return DOCUMENT ME!
|
746 | */
|
||
747 | public CADTool getCadTool() {
|
||
748 | return (CADTool) cadToolStack.peek();
|
||
749 | } |
||
750 | |||
751 | /**
|
||
752 | * DOCUMENT ME!
|
||
753 | 5383 | caballero | *
|
754 | 4115 | fjp | * @param cadTool
|
755 | * DOCUMENT ME!
|
||
756 | 3711 | caballero | */
|
757 | public void pushCadTool(CADTool cadTool) { |
||
758 | cadToolStack.push(cadTool); |
||
759 | cadTool.setCadToolAdapter(this);
|
||
760 | 4115 | fjp | // cadTool.initializeStatus();
|
761 | // cadTool.setVectorialAdapter(vea);
|
||
762 | /*
|
||
763 | * int ret = cadTool.transition(null, editableFeatureSource, selection,
|
||
764 | * new double[0]);
|
||
765 | 5383 | caballero | *
|
766 | 4115 | fjp | * if ((ret & Automaton.AUTOMATON_FINISHED) ==
|
767 | * Automaton.AUTOMATON_FINISHED) { popCadTool();
|
||
768 | 5383 | caballero | *
|
769 | 4115 | fjp | * if (cadToolStack.isEmpty()) { pushCadTool(new
|
770 | * com.iver.cit.gvsig.gui.cad.smc.gen.CADTool());//new
|
||
771 | * SelectionCadTool());
|
||
772 | * PluginServices.getMainFrame().setSelectedTool("selection"); }
|
||
773 | 5383 | caballero | *
|
774 | 4115 | fjp | * askQuestion();
|
775 | 5383 | caballero | *
|
776 | 4115 | fjp | * getMapControl().drawMap(false); }
|
777 | */
|
||
778 | 3711 | caballero | } |
779 | |||
780 | /**
|
||
781 | * DOCUMENT ME!
|
||
782 | */
|
||
783 | public void popCadTool() { |
||
784 | cadToolStack.pop(); |
||
785 | } |
||
786 | |||
787 | /**
|
||
788 | * DOCUMENT ME!
|
||
789 | */
|
||
790 | public void askQuestion() { |
||
791 | 4115 | fjp | CADTool cadtool = (CADTool) cadToolStack.peek(); |
792 | /*
|
||
793 | * if (cadtool..getStatus()==0){
|
||
794 | * PluginServices.getMainFrame().addTextToConsole("\n"
|
||
795 | * +cadtool.getName()); }
|
||
796 | */
|
||
797 | 6880 | cesar | if (PluginServices.getMDIManager().getActiveWindow() instanceof View) |
798 | 5923 | fjp | { |
799 | 6880 | cesar | View vista = (View) PluginServices.getMDIManager().getActiveWindow(); |
800 | 5923 | fjp | vista.getConsolePanel().addText( |
801 | "\n" + "#" + cadtool.getQuestion() + " > ", JConsole.MESSAGE); |
||
802 | // ***PluginServices.getMainFrame().addTextToConsole("\n" +
|
||
803 | // cadtool.getQuestion());
|
||
804 | questionAsked = true;
|
||
805 | } |
||
806 | 3711 | caballero | |
807 | } |
||
808 | |||
809 | /**
|
||
810 | * DOCUMENT ME!
|
||
811 | 5383 | caballero | *
|
812 | 4115 | fjp | * @param cadTool
|
813 | * DOCUMENT ME!
|
||
814 | 3711 | caballero | */
|
815 | public void setCadTool(CADTool cadTool) { |
||
816 | cadToolStack.clear(); |
||
817 | pushCadTool(cadTool); |
||
818 | 5165 | fjp | // askQuestion();
|
819 | 3711 | caballero | } |
820 | |||
821 | |||
822 | /**
|
||
823 | * Elimina las geometr?as seleccionadas actualmente
|
||
824 | */
|
||
825 | private void delete() { |
||
826 | 5223 | fjp | ILayerEdited aux = CADExtension.getEditionManager().getActiveLayerEdited(); |
827 | 5383 | caballero | if (!(aux instanceof VectorialLayerEdited)) |
828 | 5223 | fjp | return;
|
829 | 5383 | caballero | VectorialLayerEdited vle = (VectorialLayerEdited) aux; |
830 | 5223 | fjp | VectorialEditableAdapter vea = vle.getVEA(); |
831 | |||
832 | 3711 | caballero | vea.startComplexRow(); |
833 | 5223 | fjp | FBitSet selection = vea.getSelection(); |
834 | 3711 | caballero | try {
|
835 | 4115 | fjp | int[] indexesToDel = new int[selection.cardinality()]; |
836 | int j = 0; |
||
837 | for (int i = selection.nextSetBit(0); i >= 0; i = selection |
||
838 | .nextSetBit(i + 1)) {
|
||
839 | indexesToDel[j++] = i; |
||
840 | // /vea.removeRow(i);
|
||
841 | 4584 | caballero | } |
842 | 5985 | caballero | |
843 | // ArrayList selectedRow = vle.getSelectedRow();
|
||
844 | //
|
||
845 | // int[] indexesToDel = new int[selectedRow.size()];
|
||
846 | // for (int i = 0;i < selectedRow.size(); i++) {
|
||
847 | // IRowEdited edRow = (IRowEdited) selectedRow.get(i);
|
||
848 | // indexesToDel[i] = vea.getInversedIndex(edRow.getIndex());
|
||
849 | // }
|
||
850 | //
|
||
851 | 4454 | fjp | for (int i = indexesToDel.length - 1; i >= 0; i--) { |
852 | 5165 | fjp | vea.removeRow(indexesToDel[i], PluginServices.getText(this,
|
853 | 5184 | caballero | "deleted_feature"),EditionEvent.GRAPHIC);
|
854 | 3711 | caballero | } |
855 | } catch (DriverIOException e) {
|
||
856 | 12643 | caballero | NotificationManager.addError(e.getMessage(), e); |
857 | 3711 | caballero | } catch (IOException e) { |
858 | 12643 | caballero | NotificationManager.addError(e.getMessage(), e); |
859 | 3711 | caballero | } finally {
|
860 | try {
|
||
861 | 6071 | caballero | String description=PluginServices.getText(this,"remove_geometry"); |
862 | vea.endComplexRow(description); |
||
863 | 3711 | caballero | } catch (IOException e1) { |
864 | 12643 | caballero | NotificationManager.addError(e1.getMessage(), e1); |
865 | 3711 | caballero | } catch (DriverIOException e1) {
|
866 | 12643 | caballero | NotificationManager.addError(e1.getMessage(), e1); |
867 | 3711 | caballero | } |
868 | } |
||
869 | 3999 | caballero | System.out.println("clear Selection"); |
870 | 3711 | caballero | selection.clear(); |
871 | 4366 | caballero | vle.clearSelection(); |
872 | 5165 | fjp | /*
|
873 | * if (getCadTool() instanceof SelectionCADTool) { SelectionCADTool
|
||
874 | * selTool = (SelectionCADTool) getCadTool(); selTool.clearSelection(); }
|
||
875 | */
|
||
876 | 5923 | fjp | refreshEditedLayer(); |
877 | 3711 | caballero | } |
878 | |||
879 | /**
|
||
880 | * DOCUMENT ME!
|
||
881 | 5383 | caballero | *
|
882 | 3711 | caballero | * @param b
|
883 | */
|
||
884 | public void setAdjustGrid(boolean b) { |
||
885 | getGrid().setAdjustGrid(b); |
||
886 | } |
||
887 | |||
888 | /**
|
||
889 | * DOCUMENT ME!
|
||
890 | 5383 | caballero | *
|
891 | 3711 | caballero | * @param actionCommand
|
892 | */
|
||
893 | public void keyPressed(String actionCommand) { |
||
894 | 8765 | jjdelcerro | if (CADExtension.getEditionManager().getActiveLayerEdited()== null) { |
895 | 7831 | jmvivo | return;
|
896 | } |
||
897 | 3725 | caballero | if (actionCommand.equals("eliminar")) { |
898 | 3711 | caballero | delete(); |
899 | } else if (actionCommand.equals("escape")) { |
||
900 | 6385 | fjp | if (getMapControl().getCurrentTool().equals("cadtooladapter")) { |
901 | 3847 | caballero | CADTool ct = (CADTool) cadToolStack.peek(); |
902 | ct.end(); |
||
903 | 3711 | caballero | cadToolStack.clear(); |
904 | 4210 | fjp | SelectionCADTool selCad = new SelectionCADTool();
|
905 | selCad.init(); |
||
906 | 5165 | fjp | VectorialLayerEdited vle = (VectorialLayerEdited) CADExtension |
907 | .getEditionManager().getActiveLayerEdited(); |
||
908 | 4366 | caballero | vle.clearSelection(); |
909 | |||
910 | 4210 | fjp | pushCadTool(selCad); |
911 | // getVectorialAdapter().getSelection().clear();
|
||
912 | 5985 | caballero | |
913 | 5923 | fjp | refreshEditedLayer(); |
914 | 5985 | caballero | |
915 | |||
916 | 5015 | caballero | PluginServices.getMainFrame().setSelectedTool("_selection");
|
917 | 5165 | fjp | // askQuestion();
|
918 | } else {
|
||
919 | 4892 | caballero | getMapControl().setPrevTool(); |
920 | 3711 | caballero | } |
921 | } |
||
922 | 3725 | caballero | |
923 | 3711 | caballero | PluginServices.getMainFrame().enableControls(); |
924 | |||
925 | } |
||
926 | 5985 | caballero | |
927 | 5923 | fjp | /**
|
928 | * Provoca un repintado "soft" de la capa activa en edici?n.
|
||
929 | 5985 | caballero | * Las capas por debajo de ella no se dibujan de verdad, solo
|
930 | 5923 | fjp | * se dibuja la que est? en edici?n y las que est?n por encima
|
931 | * de ella en el TOC.
|
||
932 | */
|
||
933 | public void refreshEditedLayer() |
||
934 | { |
||
935 | ILayerEdited edLayer = CADExtension.getEditionManager().getActiveLayerEdited(); |
||
936 | if (edLayer != null) |
||
937 | { |
||
938 | edLayer.getLayer().setDirty(true);
|
||
939 | getMapControl().rePaintDirtyLayers(); |
||
940 | } |
||
941 | 5985 | caballero | |
942 | 5923 | fjp | } |
943 | 4115 | fjp | |
944 | public CADGrid getGrid() {
|
||
945 | 3711 | caballero | return cadgrid;
|
946 | } |
||
947 | 4115 | fjp | |
948 | 5874 | fjp | public boolean isOrtoMode() { |
949 | return bOrtoMode;
|
||
950 | } |
||
951 | 4115 | fjp | |
952 | 5874 | fjp | public void setOrtoMode(boolean b) { |
953 | bOrtoMode = b; |
||
954 | } |
||
955 | |||
956 | 6174 | caballero | public static void addCADTool(String name, CADTool c) { |
957 | namesCadTools.put(name, c); |
||
958 | 5874 | fjp | |
959 | 6174 | caballero | } |
960 | public static CADTool[] getCADTools() { |
||
961 | return (CADTool[]) CADToolAdapter.namesCadTools.values().toArray(new CADTool[0]); |
||
962 | } |
||
963 | public CADTool getCADTool(String text) { |
||
964 | CADTool ct = (CADTool) namesCadTools.get(text); |
||
965 | return ct;
|
||
966 | } |
||
967 | |||
968 | public EditionManager getEditionManager() {
|
||
969 | return editionManager;
|
||
970 | } |
||
971 | |||
972 | 6713 | caballero | public void initializeFlatness() { |
973 | 7072 | caballero | if (!flatnessInitialized){
|
974 | flatnessInitialized=true;
|
||
975 | Preferences prefs = Preferences.userRoot().node( "cadtooladapter" ); |
||
976 | double flatness = prefs.getDouble("flatness",FConverter.FLATNESS); |
||
977 | FConverter.FLATNESS=flatness; |
||
978 | } |
||
979 | 6713 | caballero | } |
980 | public void initializeGrid(){ |
||
981 | boolean showGrid = prefs.getBoolean("grid.showgrid",getGrid().isShowGrid()); |
||
982 | boolean adjustGrid = prefs.getBoolean("grid.adjustgrid",getGrid().isAdjustGrid()); |
||
983 | |||
984 | double dx = prefs.getDouble("grid.distancex",getGrid().getGridSizeX()); |
||
985 | double dy = prefs.getDouble("grid.distancey",getGrid().getGridSizeY()); |
||
986 | |||
987 | setGridVisibility(showGrid); |
||
988 | setAdjustGrid(adjustGrid); |
||
989 | getGrid().setGridSizeX(dx); |
||
990 | getGrid().setGridSizeY(dy); |
||
991 | } |
||
992 | 12159 | caballero | /**
|
993 | * Returns the type of active layer.
|
||
994 | **/
|
||
995 | public int getActiveLayerType() { |
||
996 | int type=FShape.MULTI;
|
||
997 | try {
|
||
998 | type=((FLyrVect)CADExtension.getEditionManager().getActiveLayerEdited().getLayer()).getShapeType(); |
||
999 | } catch (DriverException e) {
|
||
1000 | NotificationManager.addError(e); |
||
1001 | } |
||
1002 | return type;
|
||
1003 | } |
||
1004 | 6713 | caballero | |
1005 | 3711 | caballero | } |