root / trunk / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / CADToolAdapter.java @ 9243
History | View | Annotate | Download (27.4 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 | 3847 | caballero | import com.iver.cit.gvsig.gui.cad.tools.SelectionCADTool; |
47 | 8932 | caballero | import com.iver.cit.gvsig.gui.preferences.SnapConfigPage; |
48 | 5223 | fjp | import com.iver.cit.gvsig.layers.ILayerEdited; |
49 | 4366 | caballero | import com.iver.cit.gvsig.layers.VectorialLayerEdited; |
50 | 7304 | caballero | import com.iver.cit.gvsig.project.documents.view.gui.View; |
51 | 8932 | caballero | import com.iver.cit.gvsig.project.documents.view.snapping.GeometriesSnappingVisitor; |
52 | import com.iver.cit.gvsig.project.documents.view.snapping.ISnapper; |
||
53 | import com.iver.cit.gvsig.project.documents.view.snapping.ISnapperGeometriesVectorial; |
||
54 | import com.iver.cit.gvsig.project.documents.view.snapping.ISnapperRaster; |
||
55 | import com.iver.cit.gvsig.project.documents.view.snapping.ISnapperVectorial; |
||
56 | import com.iver.cit.gvsig.project.documents.view.snapping.SnappingVisitor; |
||
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 | 9121 | caballero | private Object lastQuestion; |
105 | |||
106 | 7072 | caballero | private static boolean flatnessInitialized=false; |
107 | 6713 | caballero | private static Preferences prefs = Preferences.userRoot().node( "cadtooladapter" ); |
108 | 5874 | fjp | |
109 | 3711 | caballero | /**
|
110 | * Pinta de alguna manera especial las geometrias seleccionadas para la
|
||
111 | 4115 | fjp | * edici?n. En caso de que el snapping est? activado, pintar? el efecto del
|
112 | * mismo.
|
||
113 | 5383 | caballero | *
|
114 | 3711 | caballero | * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#paintComponent(java.awt.Graphics)
|
115 | */
|
||
116 | public void paintComponent(Graphics g) { |
||
117 | super.paintComponent(g);
|
||
118 | 6174 | caballero | if (CADExtension.getCADToolAdapter()!=this) |
119 | return;
|
||
120 | 3711 | caballero | drawCursor(g); |
121 | 3883 | caballero | getGrid().drawGrid(g); |
122 | 3711 | caballero | if (adjustedPoint != null) { |
123 | 4115 | fjp | Point2D p = null; |
124 | 3711 | caballero | if (mapAdjustedPoint != null) { |
125 | p = mapAdjustedPoint; |
||
126 | } else {
|
||
127 | p = getMapControl().getViewPort().toMapPoint(adjustedPoint); |
||
128 | } |
||
129 | 6174 | caballero | |
130 | 4115 | fjp | ((CADTool) cadToolStack.peek()) |
131 | .drawOperation(g, p.getX(), p.getY()); |
||
132 | 3711 | caballero | } |
133 | } |
||
134 | |||
135 | /**
|
||
136 | * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
|
||
137 | */
|
||
138 | public void mouseClicked(MouseEvent e) throws BehaviorException { |
||
139 | 4115 | fjp | if (e.getButton() == MouseEvent.BUTTON3) { |
140 | 3883 | caballero | CADExtension.showPopup(e); |
141 | } |
||
142 | 3711 | caballero | } |
143 | |||
144 | /**
|
||
145 | * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
|
||
146 | */
|
||
147 | public void mouseEntered(MouseEvent e) throws BehaviorException { |
||
148 | 3952 | fjp | clearMouseImage(); |
149 | 3711 | caballero | } |
150 | |||
151 | /**
|
||
152 | * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
|
||
153 | */
|
||
154 | public void mouseExited(MouseEvent e) throws BehaviorException { |
||
155 | } |
||
156 | |||
157 | /**
|
||
158 | * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
|
||
159 | */
|
||
160 | public void mousePressed(MouseEvent e) throws BehaviorException { |
||
161 | if (e.getButton() == MouseEvent.BUTTON1) { |
||
162 | ViewPort vp = getMapControl().getMapContext().getViewPort(); |
||
163 | Point2D p;
|
||
164 | |||
165 | 4115 | fjp | if (mapAdjustedPoint != null) { |
166 | 3711 | caballero | p = mapAdjustedPoint; |
167 | } else {
|
||
168 | p = vp.toMapPoint(adjustedPoint); |
||
169 | } |
||
170 | 5165 | fjp | transition(new double[] { p.getX(), p.getY() }, e, ABSOLUTE); |
171 | 3711 | caballero | } |
172 | } |
||
173 | |||
174 | /**
|
||
175 | 4115 | fjp | * Ajusta un punto de la imagen que se pasa como par?metro al grid si ?ste
|
176 | 3711 | caballero | * est? activo y devuelve la distancia de un punto al punto ajustado
|
177 | 5383 | caballero | *
|
178 | 3711 | caballero | * @param point
|
179 | 4115 | fjp | * @param mapHandlerAdjustedPoint
|
180 | * DOCUMENT ME!
|
||
181 | 5383 | caballero | *
|
182 | 5223 | fjp | * @return Distancia del punto que se pasa como
|
183 | 5383 | caballero | * par?metro al punto ajustado. Si no hay ajuste,
|
184 | 5223 | fjp | * devuelve Double.MAX_VALUE
|
185 | 3711 | caballero | */
|
186 | private double adjustToHandler(Point2D point, |
||
187 | 4115 | fjp | Point2D mapHandlerAdjustedPoint) {
|
188 | 5985 | caballero | |
189 | 5874 | fjp | if (!isRefentEnabled())
|
190 | return Double.MAX_VALUE; |
||
191 | 4366 | caballero | |
192 | 5223 | fjp | ILayerEdited aux = CADExtension.getEditionManager().getActiveLayerEdited(); |
193 | 5383 | caballero | if (!(aux instanceof VectorialLayerEdited)) |
194 | 5223 | fjp | return Double.MAX_VALUE; |
195 | 5383 | caballero | VectorialLayerEdited vle = (VectorialLayerEdited) aux; |
196 | 5985 | caballero | |
197 | 5261 | fjp | ArrayList snappers = vle.getSnappers();
|
198 | 5813 | fjp | ArrayList layersToSnap = vle.getLayersToSnap();
|
199 | 5383 | caballero | |
200 | 5813 | fjp | |
201 | 5223 | fjp | ViewPort vp = getMapControl().getViewPort(); |
202 | 5383 | caballero | |
203 | 8932 | caballero | snappers=SnapConfigPage.getActivesSnappers(); |
204 | 5383 | caballero | |
205 | 5223 | fjp | double mapTolerance = vp.toMapDistance(SelectionCADTool.tolerance);
|
206 | 5261 | fjp | double minDist = mapTolerance;
|
207 | 5817 | fjp | // double rw = getMapControl().getViewPort().toMapDistance(5);
|
208 | Point2D mapPoint = point;
|
||
209 | Rectangle2D r = new Rectangle2D.Double(mapPoint.getX() - mapTolerance / 2, |
||
210 | mapPoint.getY() - mapTolerance / 2, mapTolerance, mapTolerance);
|
||
211 | |||
212 | Envelope e = FConverter.convertRectangle2DtoEnvelope(r); |
||
213 | 5985 | caballero | |
214 | 5261 | fjp | usedSnap = null;
|
215 | Point2D lastPoint = null; |
||
216 | if (previousPoint != null) |
||
217 | { |
||
218 | lastPoint = new Point2D.Double(previousPoint[0], previousPoint[1]); |
||
219 | } |
||
220 | 5813 | fjp | for (int j = 0; j < layersToSnap.size(); j++) |
221 | 5261 | fjp | { |
222 | 5813 | fjp | FLyrVect lyrVect = (FLyrVect) layersToSnap.get(j); |
223 | SpatialCache cache = lyrVect.getSpatialCache(); |
||
224 | if (lyrVect.isVisible())
|
||
225 | { |
||
226 | 5874 | fjp | // La lista de snappers est? siempre ordenada por prioridad. Los de mayor
|
227 | // prioridad est?n primero.
|
||
228 | 5813 | fjp | for (int i = 0; i < snappers.size(); i++) |
229 | 5261 | fjp | { |
230 | 5813 | fjp | ISnapper theSnapper = (ISnapper) snappers.get(i); |
231 | 5985 | caballero | |
232 | 5874 | fjp | if (usedSnap != null) |
233 | { |
||
234 | // Si ya tenemos un snap y es de alta prioridad, cogemos ese. (A no ser que en otra capa encontremos un snapper mejor)
|
||
235 | if (theSnapper.getPriority() < usedSnap.getPriority())
|
||
236 | 5985 | caballero | break;
|
237 | 5874 | fjp | } |
238 | 6771 | fjp | SnappingVisitor snapVisitor = null;
|
239 | Point2D theSnappedPoint = null; |
||
240 | 8932 | caballero | |
241 | 6771 | fjp | if (theSnapper instanceof ISnapperVectorial) |
242 | { |
||
243 | 8932 | caballero | if (theSnapper instanceof ISnapperGeometriesVectorial) { |
244 | snapVisitor=new GeometriesSnappingVisitor((ISnapperGeometriesVectorial) theSnapper,point,mapTolerance,lastPoint);
|
||
245 | }else {
|
||
246 | snapVisitor = new SnappingVisitor((ISnapperVectorial) theSnapper, point, mapTolerance, lastPoint);
|
||
247 | } |
||
248 | 6771 | fjp | // System.out.println("Cache size = " + cache.size());
|
249 | cache.query(e, snapVisitor); |
||
250 | theSnappedPoint = snapVisitor.getSnapPoint(); |
||
251 | 8932 | caballero | |
252 | 6771 | fjp | } |
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 | 8194 | jmvivo | 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 | 9121 | caballero | String question=cadtool.getQuestion();
|
798 | if (lastQuestion==null || !(lastQuestion.equals(question)) || questionAsked) { |
||
799 | 5923 | fjp | vista.getConsolePanel().addText( |
800 | 9121 | caballero | "\n" + "#" + question + " > ", JConsole.MESSAGE); |
801 | 5923 | fjp | // ***PluginServices.getMainFrame().addTextToConsole("\n" +
|
802 | // cadtool.getQuestion());
|
||
803 | 9121 | caballero | questionAsked = false;
|
804 | } |
||
805 | lastQuestion=question; |
||
806 | 5923 | fjp | } |
807 | 3711 | caballero | |
808 | } |
||
809 | |||
810 | /**
|
||
811 | * DOCUMENT ME!
|
||
812 | 5383 | caballero | *
|
813 | 4115 | fjp | * @param cadTool
|
814 | * DOCUMENT ME!
|
||
815 | 3711 | caballero | */
|
816 | public void setCadTool(CADTool cadTool) { |
||
817 | cadToolStack.clear(); |
||
818 | pushCadTool(cadTool); |
||
819 | 5165 | fjp | // askQuestion();
|
820 | 3711 | caballero | } |
821 | |||
822 | |||
823 | /**
|
||
824 | * Elimina las geometr?as seleccionadas actualmente
|
||
825 | */
|
||
826 | private void delete() { |
||
827 | 5223 | fjp | ILayerEdited aux = CADExtension.getEditionManager().getActiveLayerEdited(); |
828 | 5383 | caballero | if (!(aux instanceof VectorialLayerEdited)) |
829 | 5223 | fjp | return;
|
830 | 5383 | caballero | VectorialLayerEdited vle = (VectorialLayerEdited) aux; |
831 | 5223 | fjp | VectorialEditableAdapter vea = vle.getVEA(); |
832 | |||
833 | 3711 | caballero | vea.startComplexRow(); |
834 | 5223 | fjp | FBitSet selection = vea.getSelection(); |
835 | 3711 | caballero | try {
|
836 | 4115 | fjp | int[] indexesToDel = new int[selection.cardinality()]; |
837 | int j = 0; |
||
838 | for (int i = selection.nextSetBit(0); i >= 0; i = selection |
||
839 | .nextSetBit(i + 1)) {
|
||
840 | indexesToDel[j++] = i; |
||
841 | // /vea.removeRow(i);
|
||
842 | 4584 | caballero | } |
843 | 5985 | caballero | |
844 | // ArrayList selectedRow = vle.getSelectedRow();
|
||
845 | //
|
||
846 | // int[] indexesToDel = new int[selectedRow.size()];
|
||
847 | // for (int i = 0;i < selectedRow.size(); i++) {
|
||
848 | // IRowEdited edRow = (IRowEdited) selectedRow.get(i);
|
||
849 | // indexesToDel[i] = vea.getInversedIndex(edRow.getIndex());
|
||
850 | // }
|
||
851 | //
|
||
852 | 4454 | fjp | for (int i = indexesToDel.length - 1; i >= 0; i--) { |
853 | 5165 | fjp | vea.removeRow(indexesToDel[i], PluginServices.getText(this,
|
854 | 5184 | caballero | "deleted_feature"),EditionEvent.GRAPHIC);
|
855 | 3711 | caballero | } |
856 | } catch (DriverIOException e) {
|
||
857 | e.printStackTrace(); |
||
858 | } catch (IOException e) { |
||
859 | e.printStackTrace(); |
||
860 | } finally {
|
||
861 | try {
|
||
862 | 6071 | caballero | String description=PluginServices.getText(this,"remove_geometry"); |
863 | vea.endComplexRow(description); |
||
864 | 3711 | caballero | } catch (IOException e1) { |
865 | e1.printStackTrace(); |
||
866 | } catch (DriverIOException e1) {
|
||
867 | e1.printStackTrace(); |
||
868 | } |
||
869 | } |
||
870 | 3999 | caballero | System.out.println("clear Selection"); |
871 | 3711 | caballero | selection.clear(); |
872 | 8932 | caballero | vle.clearSelection(VectorialLayerEdited.NOTSAVEPREVIOUS); |
873 | 5165 | fjp | /*
|
874 | * if (getCadTool() instanceof SelectionCADTool) { SelectionCADTool
|
||
875 | * selTool = (SelectionCADTool) getCadTool(); selTool.clearSelection(); }
|
||
876 | */
|
||
877 | 5923 | fjp | refreshEditedLayer(); |
878 | 3711 | caballero | } |
879 | |||
880 | /**
|
||
881 | * DOCUMENT ME!
|
||
882 | 5383 | caballero | *
|
883 | 3711 | caballero | * @param b
|
884 | */
|
||
885 | public void setAdjustGrid(boolean b) { |
||
886 | getGrid().setAdjustGrid(b); |
||
887 | } |
||
888 | |||
889 | /**
|
||
890 | * DOCUMENT ME!
|
||
891 | 5383 | caballero | *
|
892 | 3711 | caballero | * @param actionCommand
|
893 | */
|
||
894 | public void keyPressed(String actionCommand) { |
||
895 | 7834 | jmvivo | if (CADExtension.getEditionManager().getActiveLayerEdited()== null) { |
896 | return;
|
||
897 | } |
||
898 | 3725 | caballero | if (actionCommand.equals("eliminar")) { |
899 | 3711 | caballero | delete(); |
900 | } else if (actionCommand.equals("escape")) { |
||
901 | 6385 | fjp | if (getMapControl().getCurrentTool().equals("cadtooladapter")) { |
902 | 3847 | caballero | CADTool ct = (CADTool) cadToolStack.peek(); |
903 | ct.end(); |
||
904 | 3711 | caballero | cadToolStack.clear(); |
905 | 4210 | fjp | SelectionCADTool selCad = new SelectionCADTool();
|
906 | selCad.init(); |
||
907 | 5165 | fjp | VectorialLayerEdited vle = (VectorialLayerEdited) CADExtension |
908 | .getEditionManager().getActiveLayerEdited(); |
||
909 | 8932 | caballero | vle.clearSelection(VectorialLayerEdited.NOTSAVEPREVIOUS); |
910 | 4366 | caballero | |
911 | 4210 | fjp | pushCadTool(selCad); |
912 | // getVectorialAdapter().getSelection().clear();
|
||
913 | 5985 | caballero | |
914 | 5923 | fjp | refreshEditedLayer(); |
915 | 5985 | caballero | |
916 | |||
917 | 5015 | caballero | PluginServices.getMainFrame().setSelectedTool("_selection");
|
918 | 5165 | fjp | // askQuestion();
|
919 | } else {
|
||
920 | 4892 | caballero | getMapControl().setPrevTool(); |
921 | 3711 | caballero | } |
922 | } |
||
923 | 3725 | caballero | |
924 | 3711 | caballero | PluginServices.getMainFrame().enableControls(); |
925 | |||
926 | } |
||
927 | 5985 | caballero | |
928 | 5923 | fjp | /**
|
929 | * Provoca un repintado "soft" de la capa activa en edici?n.
|
||
930 | 5985 | caballero | * Las capas por debajo de ella no se dibujan de verdad, solo
|
931 | 5923 | fjp | * se dibuja la que est? en edici?n y las que est?n por encima
|
932 | * de ella en el TOC.
|
||
933 | */
|
||
934 | public void refreshEditedLayer() |
||
935 | { |
||
936 | ILayerEdited edLayer = CADExtension.getEditionManager().getActiveLayerEdited(); |
||
937 | if (edLayer != null) |
||
938 | { |
||
939 | edLayer.getLayer().setDirty(true);
|
||
940 | getMapControl().rePaintDirtyLayers(); |
||
941 | } |
||
942 | 5985 | caballero | |
943 | 5923 | fjp | } |
944 | 4115 | fjp | |
945 | public CADGrid getGrid() {
|
||
946 | 3711 | caballero | return cadgrid;
|
947 | } |
||
948 | 4115 | fjp | |
949 | 5874 | fjp | public boolean isOrtoMode() { |
950 | return bOrtoMode;
|
||
951 | } |
||
952 | 4115 | fjp | |
953 | 5874 | fjp | public void setOrtoMode(boolean b) { |
954 | bOrtoMode = b; |
||
955 | } |
||
956 | |||
957 | 6174 | caballero | public static void addCADTool(String name, CADTool c) { |
958 | namesCadTools.put(name, c); |
||
959 | 5874 | fjp | |
960 | 6174 | caballero | } |
961 | public static CADTool[] getCADTools() { |
||
962 | return (CADTool[]) CADToolAdapter.namesCadTools.values().toArray(new CADTool[0]); |
||
963 | } |
||
964 | public CADTool getCADTool(String text) { |
||
965 | CADTool ct = (CADTool) namesCadTools.get(text); |
||
966 | return ct;
|
||
967 | } |
||
968 | |||
969 | public EditionManager getEditionManager() {
|
||
970 | return editionManager;
|
||
971 | } |
||
972 | |||
973 | 6713 | caballero | public void initializeFlatness() { |
974 | 7072 | caballero | if (!flatnessInitialized){
|
975 | flatnessInitialized=true;
|
||
976 | Preferences prefs = Preferences.userRoot().node( "cadtooladapter" ); |
||
977 | double flatness = prefs.getDouble("flatness",FConverter.FLATNESS); |
||
978 | FConverter.FLATNESS=flatness; |
||
979 | } |
||
980 | 6713 | caballero | } |
981 | public void initializeGrid(){ |
||
982 | boolean showGrid = prefs.getBoolean("grid.showgrid",getGrid().isShowGrid()); |
||
983 | boolean adjustGrid = prefs.getBoolean("grid.adjustgrid",getGrid().isAdjustGrid()); |
||
984 | |||
985 | double dx = prefs.getDouble("grid.distancex",getGrid().getGridSizeX()); |
||
986 | double dy = prefs.getDouble("grid.distancey",getGrid().getGridSizeY()); |
||
987 | |||
988 | setGridVisibility(showGrid); |
||
989 | setAdjustGrid(adjustGrid); |
||
990 | getGrid().setGridSizeX(dx); |
||
991 | getGrid().setGridSizeY(dy); |
||
992 | } |
||
993 | |||
994 | 3711 | caballero | } |