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