svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / CADToolAdapter.java @ 24081
History | View | Annotate | Download (49.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 | 23646 | vcaballero | import java.awt.image.BufferedImage; |
17 | 3883 | caballero | import java.awt.image.MemoryImageSource; |
18 | 5261 | fjp | import java.util.ArrayList; |
19 | 6174 | caballero | import java.util.HashMap; |
20 | 22986 | vcaballero | import java.util.Iterator; |
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 | 23754 | jjdelcerro | import org.gvsig.fmap.data.exceptions.DataException; |
26 | import org.gvsig.fmap.data.exceptions.ReadException; |
||
27 | import org.gvsig.fmap.data.feature.CommandsRecord; |
||
28 | 22986 | vcaballero | import org.gvsig.fmap.data.feature.Feature; |
29 | 23842 | jjdelcerro | import org.gvsig.fmap.data.feature.FeatureSet; |
30 | 22360 | jmvivo | import org.gvsig.fmap.data.feature.FeatureStore; |
31 | 21668 | vcaballero | import org.gvsig.fmap.geom.Geometry; |
32 | 22986 | vcaballero | import org.gvsig.fmap.geom.primitive.DefaultEnvelope; |
33 | 21668 | vcaballero | import org.gvsig.fmap.geom.util.Converter; |
34 | import org.gvsig.fmap.geom.util.UtilFunctions; |
||
35 | import org.gvsig.fmap.mapcontext.MapContext; |
||
36 | import org.gvsig.fmap.mapcontext.ViewPort; |
||
37 | import org.gvsig.fmap.mapcontext.layers.SpatialCache; |
||
38 | import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
||
39 | import org.gvsig.fmap.mapcontext.rendering.symbols.FSymbol; |
||
40 | import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
||
41 | import org.gvsig.fmap.mapcontext.rendering.symbols.SymbologyFactory; |
||
42 | import org.gvsig.fmap.mapcontrol.MapControl; |
||
43 | import org.gvsig.fmap.mapcontrol.tools.BehaviorException; |
||
44 | 21744 | vcaballero | import org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior; |
45 | 21668 | vcaballero | import org.gvsig.fmap.mapcontrol.tools.Listeners.ToolListener; |
46 | 5874 | fjp | |
47 | 3711 | caballero | import com.iver.andami.PluginServices; |
48 | 12296 | caballero | import com.iver.andami.messages.NotificationManager; |
49 | 5874 | fjp | import com.iver.andami.ui.mdiFrame.MainFrame; |
50 | 12739 | caballero | import com.iver.andami.ui.mdiManager.IWindow; |
51 | 3883 | caballero | import com.iver.cit.gvsig.CADExtension; |
52 | 6174 | caballero | import com.iver.cit.gvsig.EditionManager; |
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 | 7304 | caballero | import com.iver.cit.gvsig.project.documents.view.gui.View; |
57 | 9956 | caballero | import com.iver.cit.gvsig.project.documents.view.toolListeners.StatusBarListener; |
58 | 4892 | caballero | import com.iver.utiles.console.JConsole; |
59 | 4115 | fjp | import com.vividsolutions.jts.geom.Envelope; |
60 | 3711 | caballero | |
61 | 20098 | jmvivo | /**
|
62 | * <p>Allows user interact with different CAD tools, on a layer being edited.</p>
|
||
63 | 21668 | vcaballero | *
|
64 | 20098 | jmvivo | * <p>There are two ways of interacting:
|
65 | * <ul>
|
||
66 | * <li><b>With the mouse</b> : user selects any {@link CADTool CADTool} that produces mouse events as consequence
|
||
67 | * of the actions working with the layer being edited.
|
||
68 | * </li>
|
||
69 | * <li><b>Writing commands in the edition console</b> : most of the {@link CADTool CADTool} mouse actions can also
|
||
70 | * be called writing a command or a command's parameter in the associated edition console, and pressing the key <code>Enter</code>.
|
||
71 | * If the command isn't valid, will notify it.
|
||
72 | * </li>
|
||
73 | * </ul>
|
||
74 | * </p>
|
||
75 | 21668 | vcaballero | *
|
76 | 20098 | jmvivo | * <p>The edition has been implemented as a <i>finite machine</i>, with three kind of transitions between states according
|
77 | * the parameters introduced:
|
||
78 | * <ul>
|
||
79 | * <li><i>First transition type: <b>Point</i></b>: if <code>text</code> matches with any pattern of
|
||
80 | * parameters needed for any kind of point coordinates.<br>
|
||
81 | * There are eight ways of introducing point 2D coordinates:
|
||
82 | * <ul>
|
||
83 | * <li><i>X,Y</i> : absolute cardinal 2D coordinate from the center <i>(0,0)</i> of the CCS <i>Current Coordinate System</i>.</li>
|
||
84 | * <li><i>@X,Y</i> : relative cardinal 2D distances from the last point added of the CCS. If it's the first point of the geometry,
|
||
85 | * works like <i>X,Y</i>.</li>
|
||
86 | * <li><i>length< angle</i> : absolute polar 2D coordinate from the center <i>(0,0)</i> of the CCS <i>Current Coordinate System</i>, using
|
||
87 | * <i>angle</i> from the <i>X</i> axis of CCS, and <i>length</i> far away.</li>
|
||
88 | * <li><i>@length< angle</i> : relative polar 2D coordinate from the last point added of the CCS <i>Current Coordinate System</i>, using
|
||
89 | * <i>angle</i> from the <i>X</i> axis of CCS, and <i>length</i> far away. If it's the first point of the geometry,
|
||
90 | * works like <i>length< angle</i>.</li>
|
||
91 | * <li><i>*X,Y</i> : like <i>X,Y</i> but using UCS <i>Universal Coordinate System</i> as reference.</li>
|
||
92 | * <li><i>@*X,Y</i> : like <i>@X,Y</i> but using UCS <i>Universal Coordinate System</i> as reference.
|
||
93 | * If it's the first point of the geometry, works like <i>*X,Y</i>.</li>
|
||
94 | * <li><i>*length< angle</i> : like <i>length< angle</i> but using UCS <i>Universal Coordinate System</i> as reference.</li>
|
||
95 | * <li><i>@*length< angle</i> : like <i>@length< angle</i> but using UCS <i>Universal Coordinate System</i> as reference.
|
||
96 | * If it's the first point of the geometry, works like <i>*length< angle</i>.</li>
|
||
97 | * </ul>
|
||
98 | * </li>
|
||
99 | * <li><i>Second transition type: <b>Value</i></b>: if recognizes it as a single number.</li>
|
||
100 | * <li><i>Third transition type: <b>Option</i></b>: by default, if can't classify the information as a single number
|
||
101 | * neither as a point. This information will be an <code>String</code> and dealt as an option of the current
|
||
102 | * tool state. Ultimately, if isn't valid, <code>text</code> will be rewritten in the console notifying the user
|
||
103 | * that isn't correct.</li>
|
||
104 | * </ul>
|
||
105 | * </p>
|
||
106 | 21668 | vcaballero | *
|
107 | 20098 | jmvivo | * @see Behavior
|
108 | * @see MapControl
|
||
109 | */
|
||
110 | 3711 | caballero | public class CADToolAdapter extends Behavior { |
111 | 23646 | vcaballero | |
112 | 20098 | jmvivo | /**
|
113 | * Stores the CAD tools to edit the layers of the associated <code>MapControl</code>.
|
||
114 | 21668 | vcaballero | *
|
115 | 20098 | jmvivo | * @see #addCADTool(String, CADTool)
|
116 | * @see #getCadTool()
|
||
117 | 21668 | vcaballero | * @see #getCADTool(String)
|
118 | 20098 | jmvivo | */
|
119 | 6174 | caballero | private static HashMap namesCadTools = new HashMap(); |
120 | 4366 | caballero | |
121 | 20098 | jmvivo | /**
|
122 | * Reference to the object used to manage the edition of the layers of the associated <code>MapControl</code>.
|
||
123 | 21668 | vcaballero | *
|
124 | 20098 | jmvivo | * @see EditionManager
|
125 | * @see #getEditionManager()
|
||
126 | */
|
||
127 | 6174 | caballero | private EditionManager editionManager = new EditionManager(); |
128 | |||
129 | 20098 | jmvivo | /**
|
130 | * Identifies that the data are absolute coordinates of the new point from the (0, 0) position.
|
||
131 | */
|
||
132 | 5165 | fjp | public static final int ABSOLUTE = 0; |
133 | |||
134 | 20098 | jmvivo | /**
|
135 | * Equivalent to {@link CADToolAdapter#ABSOLUTE CADToolAdapter#ABSOLUTE}.
|
||
136 | */
|
||
137 | 5165 | fjp | public static final int RELATIVE_SCP = 1; |
138 | |||
139 | 20098 | jmvivo | /**
|
140 | * Identifies that the data are relative distances of the new point from the previous introduced.
|
||
141 | */
|
||
142 | 5165 | fjp | public static final int RELATIVE_SCU = 2; |
143 | |||
144 | 20098 | jmvivo | /**
|
145 | * Identifies that the data are relative polar distances (longitude of the line and angle given in degrees)
|
||
146 | * of the new point from the previous introduced.
|
||
147 | */
|
||
148 | 5165 | fjp | public static final int POLAR_SCP = 3; |
149 | |||
150 | 20098 | jmvivo | /**
|
151 | * Identifies that the data are relative polar distances (longitude of the line and angle given in radians)
|
||
152 | * of the new point from the previous introduced.
|
||
153 | */
|
||
154 | 5165 | fjp | public static final int POLAR_SCU = 4; |
155 | |||
156 | 20098 | jmvivo | /**
|
157 | * Stores the 2D map coordinates of the last point added.
|
||
158 | */
|
||
159 | 5165 | fjp | private double[] previousPoint = null; |
160 | |||
161 | 20098 | jmvivo | /**
|
162 | * <i>Stack with CAD tools.</i>
|
||
163 | 21668 | vcaballero | *
|
164 | 20098 | jmvivo | * <i>For each CAD tool we use, the last item added in this stack will
|
165 | 21668 | vcaballero | * display a different icon according to the current operation and its status.</i>
|
166 | 20098 | jmvivo | */
|
167 | 3711 | caballero | private Stack cadToolStack = new Stack(); |
168 | |||
169 | 20098 | jmvivo | /**
|
170 | * X coordinate of the last dragging or moving mouse event.
|
||
171 | */
|
||
172 | 3711 | caballero | private int lastX; |
173 | 4115 | fjp | |
174 | 20098 | jmvivo | /**
|
175 | * Y coordinate of the last dragging or moving mouse event.
|
||
176 | */
|
||
177 | 3711 | caballero | private int lastY; |
178 | 4115 | fjp | |
179 | 20098 | jmvivo | /**
|
180 | * Unused attribute.
|
||
181 | */
|
||
182 | 21668 | vcaballero | private ISymbol symbol = SymbologyFactory.createDefaultSymbolByShapeType(Geometry.TYPES.POINT, Color.RED); |
183 | 4115 | fjp | |
184 | 20098 | jmvivo | /**
|
185 | * Represents the cursor's point selected in <i>map coordinates</i>.
|
||
186 | 21668 | vcaballero | *
|
187 | 20098 | jmvivo | * @see MapControl#toMapPoint
|
188 | */
|
||
189 | 3711 | caballero | private Point2D mapAdjustedPoint; |
190 | 5383 | caballero | |
191 | 20098 | jmvivo | /**
|
192 | * Kind of geometry drawn to identify the kind of control point selected by the cursor's mouse.
|
||
193 | */
|
||
194 | 23646 | vcaballero | // private ISnapper usedSnap = null;
|
195 | 4115 | fjp | |
196 | 20098 | jmvivo | /**
|
197 | * Determines if has displayed at the edition console, the question for the operations that can do
|
||
198 | * the user with the current CAD tool, in its current state.
|
||
199 | */
|
||
200 | 3711 | caballero | private boolean questionAsked = false; |
201 | 4115 | fjp | |
202 | 20098 | jmvivo | /**
|
203 | * Represents the cursor's point selected in <i>screen coordinates</i>.
|
||
204 | *
|
||
205 | * @see ViewPort#fromMapPoint(Point2D)
|
||
206 | */
|
||
207 | 3711 | caballero | private Point2D adjustedPoint; |
208 | 4115 | fjp | |
209 | 20098 | jmvivo | /**
|
210 | * Determines if the snap tools are enabled or disabled.
|
||
211 | 21668 | vcaballero | *
|
212 | 20098 | jmvivo | * @see #isRefentEnabled()
|
213 | * @see #setRefentEnabled(boolean)
|
||
214 | */
|
||
215 | 23646 | vcaballero | // private boolean bRefent = true;
|
216 | 4115 | fjp | |
217 | 20098 | jmvivo | /**
|
218 | * <p>Determines if the position of the snap of the mouse's cursor on the <code>MapControl</code>
|
||
219 | * is within the area around a control point of a geometry.</p>
|
||
220 | 21668 | vcaballero | *
|
221 | 20098 | jmvivo | * <p>The area is calculated as a circle centered at the control point and with radius the pixels tolerance
|
222 | * defined in the preferences.</p>
|
||
223 | */
|
||
224 | 23646 | vcaballero | // private boolean bForceCoord = false;
|
225 | 4115 | fjp | |
226 | 20098 | jmvivo | /**
|
227 | * Optional grid that could be applied on the <code>MapControl</code>'s view port.
|
||
228 | 21668 | vcaballero | *
|
229 | 20098 | jmvivo | * @see #getGrid()
|
230 | * @see #setAdjustGrid(boolean)
|
||
231 | */
|
||
232 | 23646 | vcaballero | // private CADGrid cadgrid = new CADGrid();
|
233 | 4115 | fjp | |
234 | 20098 | jmvivo | /**
|
235 | * Determines is is enabled or not the <i>Orto</i> mode.
|
||
236 | */
|
||
237 | 5874 | fjp | private boolean bOrtoMode; |
238 | |||
239 | 20098 | jmvivo | /**
|
240 | * A light yellow color for the tool tip text box associated to the point indicated by the mouse's cursor.
|
||
241 | */
|
||
242 | 5874 | fjp | private Color theTipColor = new Color(255, 255, 155); |
243 | 7072 | caballero | |
244 | 20098 | jmvivo | /**
|
245 | * Last question asked to the user in the CAD console.
|
||
246 | */
|
||
247 | 9121 | caballero | private Object lastQuestion; |
248 | |||
249 | 20098 | jmvivo | /**
|
250 | * Maximum tolerance in the approximation of a curved line by a polyline.
|
||
251 | 21668 | vcaballero | *
|
252 | 20098 | jmvivo | * @see #initializeFlatness()
|
253 | */
|
||
254 | 7072 | caballero | private static boolean flatnessInitialized=false; |
255 | 20098 | jmvivo | |
256 | /**
|
||
257 | * Edition preferences.
|
||
258 | */
|
||
259 | 6713 | caballero | private static Preferences prefs = Preferences.userRoot().node( "cadtooladapter" ); |
260 | 21668 | vcaballero | |
261 | 20098 | jmvivo | /**
|
262 | * Listener to display the coordinates in the current application's status bar.
|
||
263 | */
|
||
264 | 9956 | caballero | private StatusBarListener sbl=null; |
265 | 20098 | jmvivo | |
266 | /*
|
||
267 | * (non-Javadoc)
|
||
268 | * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#setMapControl(com.iver.cit.gvsig.fmap.MapControl)
|
||
269 | 9956 | caballero | */
|
270 | public void setMapControl(MapControl mc) { |
||
271 | super.setMapControl(mc);
|
||
272 | sbl=new StatusBarListener(getMapControl());
|
||
273 | } |
||
274 | 23646 | vcaballero | private static final Image imageCursor=new BufferedImage(32,32,BufferedImage.TYPE_INT_ARGB); |
275 | static {
|
||
276 | Graphics g=imageCursor.getGraphics();
|
||
277 | int size1 = 15; |
||
278 | int size2 = 3; |
||
279 | int x=16; |
||
280 | int y=16; |
||
281 | g.setColor(Color.MAGENTA);
|
||
282 | g.drawLine((int) (x - size1), (int) (y), |
||
283 | (int) (x + size1), (int) (y)); |
||
284 | g.drawLine((int) (x), (int) (y - size1), |
||
285 | (int) (x), (int) (y + size1)); |
||
286 | // g.setColor(Color.MAGENTA);
|
||
287 | g.drawRect((int) (x - 6), |
||
288 | (int) (y - 6), 12, 12); |
||
289 | g.drawRect((int) (x - 3), |
||
290 | (int) (y - 3), 6, 6); |
||
291 | 20098 | jmvivo | |
292 | 23646 | vcaballero | // // getMapControl().setToolTipText(null);
|
293 | // if (adjustedPoint != null) {
|
||
294 | // if (bForceCoord) {
|
||
295 | // /* g.setColor(Color.ORANGE);
|
||
296 | // g.drawRect((int) (adjustedPoint.getX() - 6),
|
||
297 | // (int) (adjustedPoint.getY() - 6), 12, 12);
|
||
298 | // g.drawRect((int) (adjustedPoint.getX() - 3),
|
||
299 | // (int) (adjustedPoint.getY() - 3), 6, 6);
|
||
300 | // g.setColor(Color.MAGENTA);
|
||
301 | // g.drawRect((int) (adjustedPoint.getX() - 4),
|
||
302 | // (int) (adjustedPoint.getY() - 4), 8, 8); */
|
||
303 | // if (usedSnap != null)
|
||
304 | // {
|
||
305 | // usedSnap.draw(g, adjustedPoint);
|
||
306 | //
|
||
307 | // Graphics2D g2 = (Graphics2D) g;
|
||
308 | // FontMetrics metrics = g2.getFontMetrics();
|
||
309 | // int w = metrics.stringWidth(usedSnap.getToolTipText()) + 5;
|
||
310 | // int h = metrics.getMaxAscent() + 5;
|
||
311 | // int x = (int)p.getX()+9;
|
||
312 | // int y = (int)p.getY()- 7;
|
||
313 | //
|
||
314 | // g2.setColor(theTipColor );
|
||
315 | // g2.fillRect(x, y-h, w, h);
|
||
316 | // g2.setColor(Color.BLACK);
|
||
317 | // g2.drawRect(x, y-h, w, h);
|
||
318 | // g2.drawString(usedSnap.getToolTipText(), x+3, y-3);
|
||
319 | //
|
||
320 | //
|
||
321 | // // getMapControl().setToolTipText(usedSnap.getToolTipText());
|
||
322 | // }
|
||
323 | //
|
||
324 | // bForceCoord = false;
|
||
325 | // } else {
|
||
326 | // g.drawRect((int) (p.getX() - size2), (int) (p.getY() - size2),
|
||
327 | // (int) (size2 * 2), (int) (size2 * 2));
|
||
328 | // }
|
||
329 | // }
|
||
330 | |||
331 | |||
332 | } |
||
333 | |||
334 | 3711 | caballero | /**
|
335 | 20098 | jmvivo | * <p>Draws the selected geometries to edit. And, if the <i>snapping</i> is enabled,
|
336 | * draws also its effect over them.</p>
|
||
337 | 5383 | caballero | *
|
338 | 3711 | caballero | * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#paintComponent(java.awt.Graphics)
|
339 | */
|
||
340 | public void paintComponent(Graphics g) { |
||
341 | super.paintComponent(g);
|
||
342 | 6174 | caballero | if (CADExtension.getCADToolAdapter()!=this) |
343 | return;
|
||
344 | 12888 | caballero | |
345 | 3711 | caballero | if (adjustedPoint != null) { |
346 | 4115 | fjp | Point2D p = null; |
347 | 3711 | caballero | if (mapAdjustedPoint != null) { |
348 | p = mapAdjustedPoint; |
||
349 | } else {
|
||
350 | p = getMapControl().getViewPort().toMapPoint(adjustedPoint); |
||
351 | } |
||
352 | 6174 | caballero | |
353 | 4115 | fjp | ((CADTool) cadToolStack.peek()) |
354 | .drawOperation(g, p.getX(), p.getY()); |
||
355 | 3711 | caballero | } |
356 | 23646 | vcaballero | // drawCursor(g);
|
357 | // getGrid().drawGrid(g);
|
||
358 | 3711 | caballero | } |
359 | |||
360 | /**
|
||
361 | 20098 | jmvivo | * <p>Responds two kind of mouse click events:
|
362 | * <ul>
|
||
363 | * <li><b><i>One click of the third mouse's button</i></b>: displays a popup with edition options.</li>
|
||
364 | * <li><b><i>Two clicks of the first mouse's button</i></b>: ends the last cad tool setting as end transition
|
||
365 | * point the event's one.</li>
|
||
366 | * </ul>
|
||
367 | * </p>
|
||
368 | 21668 | vcaballero | *
|
369 | *
|
||
370 | 20098 | jmvivo | * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseClicked(java.awt.event.MouseEvent)
|
371 | * @see CADExtension#showPopup(MouseEvent)
|
||
372 | 3711 | caballero | */
|
373 | public void mouseClicked(MouseEvent e) throws BehaviorException { |
||
374 | 4115 | fjp | if (e.getButton() == MouseEvent.BUTTON3) { |
375 | 3883 | caballero | CADExtension.showPopup(e); |
376 | 17984 | vcaballero | }else if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount()==2){ |
377 | questionAsked = true;
|
||
378 | if (!cadToolStack.isEmpty()) {
|
||
379 | CADTool ct = (CADTool) cadToolStack.peek(); |
||
380 | ViewPort vp = getMapControl().getMapContext().getViewPort(); |
||
381 | Point2D p;
|
||
382 | |||
383 | if (mapAdjustedPoint != null) { |
||
384 | p = mapAdjustedPoint; |
||
385 | } else {
|
||
386 | p = vp.toMapPoint(adjustedPoint); |
||
387 | } |
||
388 | ct.endTransition(p.getX(), p.getY(), e); |
||
389 | previousPoint = new double[]{p.getX(),p.getY()}; |
||
390 | } |
||
391 | 3883 | caballero | } |
392 | 3711 | caballero | } |
393 | |||
394 | 20098 | jmvivo | /*
|
395 | * (non-Javadoc)
|
||
396 | * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseEntered(java.awt.event.MouseEvent)
|
||
397 | 3711 | caballero | */
|
398 | public void mouseEntered(MouseEvent e) throws BehaviorException { |
||
399 | 3952 | fjp | clearMouseImage(); |
400 | 3711 | caballero | } |
401 | |||
402 | 20098 | jmvivo | /*
|
403 | * (non-Javadoc)
|
||
404 | * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseExited(java.awt.event.MouseEvent)
|
||
405 | 3711 | caballero | */
|
406 | public void mouseExited(MouseEvent e) throws BehaviorException { |
||
407 | } |
||
408 | |||
409 | /**
|
||
410 | 21668 | vcaballero | * Selects the vertex of a geometry at the point selected on the <code>MapControl</code>
|
411 | 20098 | jmvivo | * by pressing the first mouse's button.
|
412 | 21668 | vcaballero | *
|
413 | 20098 | jmvivo | * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mousePressed(java.awt.event.MouseEvent)
|
414 | 3711 | caballero | */
|
415 | public void mousePressed(MouseEvent e) throws BehaviorException { |
||
416 | if (e.getButton() == MouseEvent.BUTTON1) { |
||
417 | ViewPort vp = getMapControl().getMapContext().getViewPort(); |
||
418 | Point2D p;
|
||
419 | |||
420 | 4115 | fjp | if (mapAdjustedPoint != null) { |
421 | 3711 | caballero | p = mapAdjustedPoint; |
422 | } else {
|
||
423 | p = vp.toMapPoint(adjustedPoint); |
||
424 | } |
||
425 | 5165 | fjp | transition(new double[] { p.getX(), p.getY() }, e, ABSOLUTE); |
426 | 3711 | caballero | } |
427 | } |
||
428 | |||
429 | 23646 | vcaballero | // /**
|
430 | // * <p>Adjusts the <code>point</code> to the grid if its enabled, and
|
||
431 | // * sets <code>mapHandlerAdjustedPoint</code> with that new value.</p>
|
||
432 | // *
|
||
433 | // * <p>The value returned is the distance between those points: the original and
|
||
434 | // * the adjusted one.</p>
|
||
435 | // *
|
||
436 | // * @param point point to adjust
|
||
437 | // * @param mapHandlerAdjustedPoint <code>point</code> adjusted
|
||
438 | // *
|
||
439 | // * @return distance from <code>point</code> to the adjusted one. If there is no
|
||
440 | // * adjustment, returns <code>Double.MAX_VALUE</code>.
|
||
441 | // */
|
||
442 | // private double adjustToHandler(Point2D point,
|
||
443 | // Point2D mapHandlerAdjustedPoint) {
|
||
444 | //
|
||
445 | // if (!isRefentEnabled())
|
||
446 | // return Double.MAX_VALUE;
|
||
447 | //
|
||
448 | // ILayerEdited aux = CADExtension.getEditionManager().getActiveLayerEdited();
|
||
449 | // if (!(aux instanceof VectorialLayerEdited))
|
||
450 | // return Double.MAX_VALUE;
|
||
451 | // VectorialLayerEdited vle = (VectorialLayerEdited) aux;
|
||
452 | //
|
||
453 | // ArrayList snappers = vle.getSnappers();
|
||
454 | // ArrayList layersToSnap = vle.getLayersToSnap();
|
||
455 | //
|
||
456 | //
|
||
457 | // ViewPort vp = getMapControl().getViewPort();
|
||
458 | //
|
||
459 | // snappers=SnapConfigPage.getActivesSnappers();
|
||
460 | //
|
||
461 | // double mapTolerance = vp.toMapDistance(SelectionCADTool.tolerance);
|
||
462 | // double minDist = mapTolerance;
|
||
463 | //// double rw = getMapControl().getViewPort().toMapDistance(5);
|
||
464 | // Point2D mapPoint = point;
|
||
465 | // double middleTol=mapTolerance * 0.5;
|
||
466 | // org.gvsig.fmap.geom.primitive.Envelope r = new DefaultEnvelope(mapPoint.getX() - middleTol,
|
||
467 | // mapPoint.getY() - middleTol,
|
||
468 | // mapPoint.getX() + middleTol,
|
||
469 | // mapPoint.getY() + middleTol);
|
||
470 | //
|
||
471 | // Envelope e = Converter.convertEnvelopeToJTS(r);
|
||
472 | //
|
||
473 | // usedSnap = null;
|
||
474 | // Point2D lastPoint = null;
|
||
475 | // if (previousPoint != null)
|
||
476 | // {
|
||
477 | // lastPoint = new Point2D.Double(previousPoint[0], previousPoint[1]);
|
||
478 | // }
|
||
479 | // for (int j = 0; j < layersToSnap.size(); j++)
|
||
480 | // {
|
||
481 | // FLyrVect lyrVect = (FLyrVect) layersToSnap.get(j);
|
||
482 | // SpatialCache cache = lyrVect.getSpatialCache();
|
||
483 | // if (lyrVect.isVisible())
|
||
484 | // {
|
||
485 | // // La lista de snappers est? siempre ordenada por prioridad. Los de mayor
|
||
486 | // // prioridad est?n primero.
|
||
487 | // for (int i = 0; i < snappers.size(); i++)
|
||
488 | // {
|
||
489 | // ISnapper theSnapper = (ISnapper) snappers.get(i);
|
||
490 | //
|
||
491 | // if (usedSnap != null)
|
||
492 | // {
|
||
493 | // // Si ya tenemos un snap y es de alta prioridad, cogemos ese. (A no ser que en otra capa encontremos un snapper mejor)
|
||
494 | // if (theSnapper.getPriority() < usedSnap.getPriority())
|
||
495 | // break;
|
||
496 | // }
|
||
497 | // SnappingVisitor snapVisitor = null;
|
||
498 | // Point2D theSnappedPoint = null;
|
||
499 | //
|
||
500 | // if (theSnapper instanceof ISnapperVectorial)
|
||
501 | // {
|
||
502 | // if (theSnapper instanceof ISnapperGeometriesVectorial) {
|
||
503 | // snapVisitor=new GeometriesSnappingVisitor((ISnapperGeometriesVectorial) theSnapper,point,mapTolerance,lastPoint);
|
||
504 | // }else {
|
||
505 | // snapVisitor = new SnappingVisitor((ISnapperVectorial) theSnapper, point, mapTolerance, lastPoint);
|
||
506 | // }
|
||
507 | // // System.out.println("Cache size = " + cache.size());
|
||
508 | // cache.query(e, snapVisitor);
|
||
509 | // theSnappedPoint = snapVisitor.getSnapPoint();
|
||
510 | //
|
||
511 | // }
|
||
512 | // if (theSnapper instanceof ISnapperRaster)
|
||
513 | // {
|
||
514 | // ISnapperRaster snapRaster = (ISnapperRaster) theSnapper;
|
||
515 | // theSnappedPoint = snapRaster.getSnapPoint(getMapControl(), point, mapTolerance, lastPoint);
|
||
516 | // }
|
||
517 | //
|
||
518 | //
|
||
519 | // if (theSnappedPoint != null) {
|
||
520 | // double distAux = theSnappedPoint.distance(point);
|
||
521 | // if (minDist > distAux)
|
||
522 | // {
|
||
523 | // minDist = distAux;
|
||
524 | // usedSnap = theSnapper;
|
||
525 | // mapHandlerAdjustedPoint.setLocation(theSnappedPoint);
|
||
526 | // }
|
||
527 | // }
|
||
528 | // }
|
||
529 | // } // visible
|
||
530 | // }
|
||
531 | // if (usedSnap != null)
|
||
532 | // return minDist;
|
||
533 | // return Double.MAX_VALUE;
|
||
534 | //
|
||
535 | // }
|
||
536 | 5985 | caballero | |
537 | 20098 | jmvivo | /*
|
538 | * (non-Javadoc)
|
||
539 | * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseReleased(java.awt.event.MouseEvent)
|
||
540 | 3711 | caballero | */
|
541 | public void mouseReleased(MouseEvent e) throws BehaviorException { |
||
542 | 3883 | caballero | getMapControl().repaint(); |
543 | 3711 | caballero | } |
544 | |||
545 | 20098 | jmvivo | /*
|
546 | * (non-Javadoc)
|
||
547 | * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseDragged(java.awt.event.MouseEvent)
|
||
548 | 3711 | caballero | */
|
549 | public void mouseDragged(MouseEvent e) throws BehaviorException { |
||
550 | lastX = e.getX(); |
||
551 | lastY = e.getY(); |
||
552 | 23646 | vcaballero | adjustedPoint=e.getPoint(); |
553 | // calculateSnapPoint(e.getPoint());
|
||
554 | 3711 | caballero | } |
555 | |||
556 | 20098 | jmvivo | /*
|
557 | * (non-Javadoc)
|
||
558 | * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseMoved(java.awt.event.MouseEvent)
|
||
559 | 3711 | caballero | */
|
560 | public void mouseMoved(MouseEvent e) throws BehaviorException { |
||
561 | 3883 | caballero | |
562 | 3711 | caballero | lastX = e.getX(); |
563 | lastY = e.getY(); |
||
564 | 23646 | vcaballero | adjustedPoint=e.getPoint(); |
565 | // calculateSnapPoint(e.getPoint());
|
||
566 | 3711 | caballero | |
567 | 5874 | fjp | showCoords(e.getPoint()); |
568 | 5985 | caballero | |
569 | 3711 | caballero | getMapControl().repaint(); |
570 | } |
||
571 | 4115 | fjp | |
572 | 20098 | jmvivo | /**
|
573 | * Displays the current coordinates of the mouse's cursor on the associated <code>MapControl</code>
|
||
574 | * object, at the status bar of the application's main frame.
|
||
575 | 21668 | vcaballero | *
|
576 | 20098 | jmvivo | * @param pPix current 2D mouse's cursor coordinates on the <code>MapControl</code>
|
577 | */
|
||
578 | 5874 | fjp | private void showCoords(Point2D pPix) |
579 | { |
||
580 | String[] axisText = new String[2]; |
||
581 | 9956 | caballero | axisText[0] = "X = "; |
582 | axisText[1] = "Y = "; |
||
583 | // NumberFormat nf = NumberFormat.getInstance();
|
||
584 | 5874 | fjp | MapControl mapControl = getMapControl(); |
585 | ViewPort vp = mapControl.getMapContext().getViewPort(); |
||
586 | IProjection iProj = vp.getProjection(); |
||
587 | 9956 | caballero | |
588 | // if (iProj.getAbrev().equals("EPSG:4326") || iProj.getAbrev().equals("EPSG:4230")) {
|
||
589 | // axisText[0] = "Lon = ";
|
||
590 | // axisText[1] = "Lat = ";
|
||
591 | // nf.setMaximumFractionDigits(8);
|
||
592 | // } else {
|
||
593 | // axisText[0] = "X = ";
|
||
594 | // axisText[1] = "Y = ";
|
||
595 | // nf.setMaximumFractionDigits(2);
|
||
596 | // }
|
||
597 | 5874 | fjp | Point2D p;
|
598 | if (mapAdjustedPoint == null) |
||
599 | { |
||
600 | p = vp.toMapPoint(pPix); |
||
601 | } |
||
602 | else
|
||
603 | { |
||
604 | p = mapAdjustedPoint; |
||
605 | } |
||
606 | 9956 | caballero | sbl.setFractionDigits(p); |
607 | axisText = sbl.setCoorDisplayText(axisText); |
||
608 | 5874 | fjp | MainFrame mF = PluginServices.getMainFrame(); |
609 | |||
610 | if (mF != null) |
||
611 | 5985 | caballero | { |
612 | 6630 | caballero | mF.getStatusBar().setMessage("units",
|
613 | 21668 | vcaballero | PluginServices.getText(this, MapContext.getDistanceNames()[vp.getDistanceUnits()]));
|
614 | 6630 | caballero | mF.getStatusBar().setControlValue("scale",String.valueOf(mapControl.getMapContext().getScaleView())); |
615 | mF.getStatusBar().setMessage("projection", iProj.getAbrev());
|
||
616 | 5874 | fjp | |
617 | 9956 | caballero | String[] coords=sbl.getCoords(p); |
618 | 10545 | cesar | mF.getStatusBar().setMessage("x",
|
619 | axisText[0] + coords[0]); |
||
620 | mF.getStatusBar().setMessage("y",
|
||
621 | axisText[1] + coords[1]); |
||
622 | 5874 | fjp | } |
623 | } |
||
624 | |||
625 | 20098 | jmvivo | /**
|
626 | * Hides the mouse's cursor.
|
||
627 | */
|
||
628 | 4115 | fjp | private void clearMouseImage() { |
629 | 3883 | caballero | int[] pixels = new int[16 * 16]; |
630 | Image image = Toolkit.getDefaultToolkit().createImage( |
||
631 | 4115 | fjp | new MemoryImageSource(16, 16, pixels, 0, 16)); |
632 | Cursor transparentCursor = Toolkit.getDefaultToolkit() |
||
633 | .createCustomCursor(image, new Point(0, 0), "invisiblecursor"); |
||
634 | 3996 | caballero | |
635 | 3952 | fjp | getMapControl().setCursor(transparentCursor); |
636 | 3883 | caballero | } |
637 | 4115 | fjp | |
638 | 3711 | caballero | /**
|
639 | 20098 | jmvivo | * <p>Draws a 31x31 pixels cross round the mouse's cursor with an small geometry centered:
|
640 | * <ul>
|
||
641 | * <li><i>an square centered</i>: if isn't over a <i>control point</i>.
|
||
642 | * <li><i>an small geometry centered according to the kind of control point</i>: if it's over a control
|
||
643 | * point. In this case, the small geometry is drawn by a {@link ISnapper ISnapper} type object.<br>
|
||
644 | * On the other hand, a light-yellowed background tool tip text with the type of <i>control point</i> will
|
||
645 | * be displayed.</li>
|
||
646 | 21668 | vcaballero | * </p>
|
647 | 5383 | caballero | *
|
648 | 20098 | jmvivo | * @param g <code>MapControl</code>'s graphics where the data will be drawn
|
649 | 3711 | caballero | */
|
650 | 23646 | vcaballero | // private void drawCursor(Graphics g) {
|
651 | // g.setColor(Color.black);
|
||
652 | // Point2D p = adjustedPoint;
|
||
653 | //
|
||
654 | // if (p == null) {
|
||
655 | // getGrid().setViewPort(getMapControl().getViewPort());
|
||
656 | //
|
||
657 | // return;
|
||
658 | // }
|
||
659 | //
|
||
660 | // int size1 = 15;
|
||
661 | // int size2 = 3;
|
||
662 | // g.drawLine((int) (p.getX() - size1), (int) (p.getY()),
|
||
663 | // (int) (p.getX() + size1), (int) (p.getY()));
|
||
664 | // g.drawLine((int) (p.getX()), (int) (p.getY() - size1),
|
||
665 | // (int) (p.getX()), (int) (p.getY() + size1));
|
||
666 | //
|
||
667 | // // getMapControl().setToolTipText(null);
|
||
668 | // if (adjustedPoint != null) {
|
||
669 | // if (bForceCoord) {
|
||
670 | // /* g.setColor(Color.ORANGE);
|
||
671 | // g.drawRect((int) (adjustedPoint.getX() - 6),
|
||
672 | // (int) (adjustedPoint.getY() - 6), 12, 12);
|
||
673 | // g.drawRect((int) (adjustedPoint.getX() - 3),
|
||
674 | // (int) (adjustedPoint.getY() - 3), 6, 6);
|
||
675 | // g.setColor(Color.MAGENTA);
|
||
676 | // g.drawRect((int) (adjustedPoint.getX() - 4),
|
||
677 | // (int) (adjustedPoint.getY() - 4), 8, 8); */
|
||
678 | // if (usedSnap != null)
|
||
679 | // {
|
||
680 | // usedSnap.draw(g, adjustedPoint);
|
||
681 | //
|
||
682 | // Graphics2D g2 = (Graphics2D) g;
|
||
683 | // FontMetrics metrics = g2.getFontMetrics();
|
||
684 | // int w = metrics.stringWidth(usedSnap.getToolTipText()) + 5;
|
||
685 | // int h = metrics.getMaxAscent() + 5;
|
||
686 | // int x = (int)p.getX()+9;
|
||
687 | // int y = (int)p.getY()- 7;
|
||
688 | //
|
||
689 | // g2.setColor(theTipColor );
|
||
690 | // g2.fillRect(x, y-h, w, h);
|
||
691 | // g2.setColor(Color.BLACK);
|
||
692 | // g2.drawRect(x, y-h, w, h);
|
||
693 | // g2.drawString(usedSnap.getToolTipText(), x+3, y-3);
|
||
694 | //
|
||
695 | //
|
||
696 | // // getMapControl().setToolTipText(usedSnap.getToolTipText());
|
||
697 | // }
|
||
698 | //
|
||
699 | // bForceCoord = false;
|
||
700 | // } else {
|
||
701 | // g.drawRect((int) (p.getX() - size2), (int) (p.getY() - size2),
|
||
702 | // (int) (size2 * 2), (int) (size2 * 2));
|
||
703 | // }
|
||
704 | // }
|
||
705 | // }
|
||
706 | 3711 | caballero | |
707 | /**
|
||
708 | 20098 | jmvivo | * <p>Tries to find the nearest geometry or grid control point by the position of the current snap tool.</p>
|
709 | 21668 | vcaballero | *
|
710 | 20098 | jmvivo | * <p>Prioritizes the grid control points than the geometries ones.</p>
|
711 | 21668 | vcaballero | *
|
712 | 20098 | jmvivo | * <p>If finds any near, stores the <i>map</i> and <i>pixel</i> coordinates for the snap, and enables
|
713 | * the <code>bForceCoord</code> attribute for the next draw of the mouse's cursor.</p>
|
||
714 | 5383 | caballero | *
|
715 | 20098 | jmvivo | * @param point current mouse 2D position
|
716 | 3711 | caballero | */
|
717 | 23646 | vcaballero | // private void calculateSnapPoint(Point point) {
|
718 | // // Se comprueba el ajuste a rejilla
|
||
719 | //
|
||
720 | // Point2D gridAdjustedPoint = getMapControl().getViewPort().toMapPoint(
|
||
721 | // point);
|
||
722 | // double minDistance = Double.MAX_VALUE;
|
||
723 | // CADTool ct = (CADTool) cadToolStack.peek();
|
||
724 | // if (ct instanceof SelectionCADTool
|
||
725 | // && ((SelectionCADTool) ct).getStatus().equals(
|
||
726 | // "Selection.FirstPoint")) {
|
||
727 | // mapAdjustedPoint = gridAdjustedPoint;
|
||
728 | // adjustedPoint = (Point2D) point.clone();
|
||
729 | // } else {
|
||
730 | //
|
||
731 | // minDistance = getGrid().adjustToGrid(gridAdjustedPoint);
|
||
732 | // if (minDistance < Double.MAX_VALUE) {
|
||
733 | // adjustedPoint = getMapControl().getViewPort().fromMapPoint(
|
||
734 | // gridAdjustedPoint);
|
||
735 | // mapAdjustedPoint = gridAdjustedPoint;
|
||
736 | // } else {
|
||
737 | // mapAdjustedPoint = null;
|
||
738 | // }
|
||
739 | // }
|
||
740 | // Point2D handlerAdjustedPoint = null;
|
||
741 | //
|
||
742 | // // Se comprueba el ajuste a los handlers
|
||
743 | // if (mapAdjustedPoint != null) {
|
||
744 | // handlerAdjustedPoint = (Point2D) mapAdjustedPoint.clone(); // getMapControl().getViewPort().toMapPoint(point);
|
||
745 | // } else {
|
||
746 | // handlerAdjustedPoint = getMapControl().getViewPort().toMapPoint(
|
||
747 | // point);
|
||
748 | // }
|
||
749 | //
|
||
750 | // Point2D mapPoint = new Point2D.Double();
|
||
751 | // double distance = adjustToHandler(handlerAdjustedPoint, mapPoint);
|
||
752 | //
|
||
753 | // if (distance < minDistance) {
|
||
754 | // bForceCoord = true;
|
||
755 | // adjustedPoint = getMapControl().getViewPort().fromMapPoint(mapPoint);
|
||
756 | // mapAdjustedPoint = mapPoint;
|
||
757 | // minDistance = distance;
|
||
758 | // }
|
||
759 | //
|
||
760 | // // Si no hay ajuste
|
||
761 | // if (minDistance == Double.MAX_VALUE) {
|
||
762 | // adjustedPoint = point;
|
||
763 | // mapAdjustedPoint = null;
|
||
764 | // }
|
||
765 | //
|
||
766 | // }
|
||
767 | 3711 | caballero | |
768 | 20098 | jmvivo | /*
|
769 | * (non-Javadoc)
|
||
770 | * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseWheelMoved(java.awt.event.MouseWheelEvent)
|
||
771 | 3711 | caballero | */
|
772 | public void mouseWheelMoved(MouseWheelEvent e) throws BehaviorException { |
||
773 | } |
||
774 | |||
775 | /**
|
||
776 | 20098 | jmvivo | * <p>Process the information written by the user about the next point coordinate, determining
|
777 | * the kind of <i>transition</i> according the parameters written.</p>
|
||
778 | 21668 | vcaballero | *
|
779 | 20098 | jmvivo | * <p>After, invokes one of the three possible <i>transition</i> methods of the <i>finite machine</i> of
|
780 | * edition:
|
||
781 | * <ul>
|
||
782 | * <li><i>First transition type: <b>Point</i></b>: if <code>text</code> matches with any pattern of
|
||
783 | * parameters needed for any kind of point coordinates.<br>
|
||
784 | * There are eight ways of introducing point 2D coordinates:
|
||
785 | * <ul>
|
||
786 | * <li><i>X,Y</i> : absolute cardinal 2D coordinate from the center <i>(0,0)</i> of the CCS <i>Current Coordinate System</i>.</li>
|
||
787 | * <li><i>@X,Y</i> : relative cardinal 2D distances from the last point added of the CCS. If it's the first point of the geometry,
|
||
788 | * works like <i>X,Y</i>.</li>
|
||
789 | * <li><i>length< angle</i> : absolute polar 2D coordinate from the center <i>(0,0)</i> of the CCS <i>Current Coordinate System</i>, using
|
||
790 | * <i>angle</i> from the <i>X</i> axis of CCS, and <i>length</i> far away.</li>
|
||
791 | * <li><i>@length< angle</i> : relative polar 2D coordinate from the last point added of the CCS <i>Current Coordinate System</i>, using
|
||
792 | * <i>angle</i> from the <i>X</i> axis of CCS, and <i>length</i> far away. If it's the first point of the geometry,
|
||
793 | * works like <i>length< angle</i>.</li>
|
||
794 | * <li><i>*X,Y</i> : like <i>X,Y</i> but using UCS <i>Universal Coordinate System</i> as reference.</li>
|
||
795 | * <li><i>@*X,Y</i> : like <i>@X,Y</i> but using UCS <i>Universal Coordinate System</i> as reference.
|
||
796 | * If it's the first point of the geometry, works like <i>*X,Y</i>.</li>
|
||
797 | * <li><i>*length< angle</i> : like <i>length< angle</i> but using UCS <i>Universal Coordinate System</i> as reference.</li>
|
||
798 | * <li><i>@*length< angle</i> : like <i>@length< angle</i> but using UCS <i>Universal Coordinate System</i> as reference.
|
||
799 | * If it's the first point of the geometry, works like <i>*length< angle</i>.</li>
|
||
800 | * </ul>
|
||
801 | * </li>
|
||
802 | * <li><i>Second transition type: <b>Value</i></b>: if recognizes it as a single number.</li>
|
||
803 | * <li><i>Third transition type: <b>Option</i></b>: by default, if can't classify the information as a single number
|
||
804 | * neither as a point. This information will be an <code>String</code> and dealt as an option of the current
|
||
805 | * tool state. Ultimately, if isn't valid, <code>text</code> will be rewritten in the console notifying the user
|
||
806 | * that isn't correct.</li>
|
||
807 | * </ul>
|
||
808 | * </p>
|
||
809 | 5383 | caballero | *
|
810 | 20098 | jmvivo | * @param text command written by user in the edition's console
|
811 | 3711 | caballero | */
|
812 | public void textEntered(String text) { |
||
813 | if (text == null) { |
||
814 | 6156 | caballero | transition(PluginServices.getText(this,"cancel")); |
815 | 3711 | caballero | } else {
|
816 | 4115 | fjp | /*
|
817 | * if ("".equals(text)) { transition("aceptar"); } else {
|
||
818 | */
|
||
819 | text = text.trim(); |
||
820 | 5223 | fjp | int type = ABSOLUTE;
|
821 | String[] numbers = new String[1]; |
||
822 | numbers[0] = text;
|
||
823 | if (text.indexOf(",") != -1) { |
||
824 | 3711 | caballero | |
825 | 5015 | caballero | numbers = text.split(",");
|
826 | 5165 | fjp | if (numbers[0].substring(0, 1).equals("@")) { |
827 | numbers[0] = numbers[0].substring(1, numbers[0].length()); |
||
828 | type = RELATIVE_SCU; |
||
829 | if (numbers[0].substring(0, 1).equals("*")) { |
||
830 | type = RELATIVE_SCP; |
||
831 | numbers[0] = numbers[0].substring(1, numbers[0] |
||
832 | .length()); |
||
833 | 5015 | caballero | } |
834 | } |
||
835 | 5165 | fjp | } else if (text.indexOf("<") != -1) { |
836 | type = POLAR_SCP; |
||
837 | 5015 | caballero | numbers = text.split("<");
|
838 | 5165 | fjp | if (numbers[0].substring(0, 1).equals("@")) { |
839 | numbers[0] = numbers[0].substring(1, numbers[0].length()); |
||
840 | type = POLAR_SCU; |
||
841 | if (numbers[0].substring(0, 1).equals("*")) { |
||
842 | type = POLAR_SCP; |
||
843 | numbers[0] = numbers[0].substring(1, numbers[0] |
||
844 | .length()); |
||
845 | 5015 | caballero | } |
846 | } |
||
847 | } |
||
848 | |||
849 | 4115 | fjp | double[] values = null; |
850 | 3711 | caballero | |
851 | 4115 | fjp | try {
|
852 | if (numbers.length == 2) { |
||
853 | // punto
|
||
854 | values = new double[] { Double.parseDouble(numbers[0]), |
||
855 | Double.parseDouble(numbers[1]) }; |
||
856 | 5165 | fjp | transition(values, null, type);
|
857 | 4115 | fjp | } else if (numbers.length == 1) { |
858 | // valor
|
||
859 | values = new double[] { Double.parseDouble(numbers[0]) }; |
||
860 | 4147 | fjp | transition(values[0]);
|
861 | 3711 | caballero | } |
862 | 4115 | fjp | } catch (NumberFormatException e) { |
863 | 4147 | fjp | transition(text); |
864 | 5070 | caballero | } catch (NullPointerException e) { |
865 | transition(text); |
||
866 | 4115 | fjp | } |
867 | // }
|
||
868 | 3711 | caballero | } |
869 | 4002 | fjp | getMapControl().repaint(); |
870 | 3711 | caballero | } |
871 | |||
872 | /**
|
||
873 | 20098 | jmvivo | * If there are options related with the <code>CADTool</code> at the peek of the CAD tool stack,
|
874 | * displays them as a popup.
|
||
875 | 3711 | caballero | */
|
876 | 3883 | caballero | public void configureMenu() { |
877 | String[] desc = ((CADTool) cadToolStack.peek()).getDescriptions(); |
||
878 | 4115 | fjp | // String[] labels = ((CADTool)
|
879 | // cadToolStack.peek()).getCurrentTransitions();
|
||
880 | 3883 | caballero | CADExtension.clearMenu(); |
881 | 3711 | caballero | |
882 | for (int i = 0; i < desc.length; i++) { |
||
883 | if (desc[i] != null) { |
||
884 | 5165 | fjp | CADExtension |
885 | .addMenuEntry(PluginServices.getText(this, desc[i]));// , |
||
886 | 5223 | fjp | // labels[i]);
|
887 | 3711 | caballero | } |
888 | } |
||
889 | 3883 | caballero | |
890 | 3711 | caballero | } |
891 | |||
892 | /**
|
||
893 | 20098 | jmvivo | * <p>One of the three kind of transaction methods of the <i>finite machine</i> of
|
894 | * edition.</p>
|
||
895 | 21668 | vcaballero | *
|
896 | 20098 | jmvivo | * <p>This one deals <code>values</code> as two numbers that, according <code>type</code>
|
897 | * calculate a new point 2D in the current layer edited in the associated <code>MapControl</code>.</p>
|
||
898 | 5383 | caballero | *
|
899 | 21668 | vcaballero | * <p>There are different ways of calculating the new point 2D coordinates, according the value of <code>type</code>, see
|
900 | 20098 | jmvivo | * {@link #textEntered(String) #textEntered(String)}.</p>
|
901 | 21668 | vcaballero | *
|
902 | 20098 | jmvivo | * <p>After applying the changes, updates the controls available for managing the current data.</p>
|
903 | 21668 | vcaballero | *
|
904 | 20098 | jmvivo | * @param values numbers needed to calculate the new point coordinates according <code>type</code>
|
905 | * @param event event which generated this invocation (a <code>MouseEvent</code> or a <code>KeyEvent</code>)
|
||
906 | * @param type kind of information that is <code>values</code>. According this parameter, will calculate the
|
||
907 | * new point in a different way
|
||
908 | 21668 | vcaballero | *
|
909 | 20098 | jmvivo | * @see CADTool#transition(double, double, InputEvent)
|
910 | * @see #transition(double)
|
||
911 | * @see #transition(String)
|
||
912 | 3711 | caballero | */
|
913 | 5165 | fjp | private void transition(double[] values, InputEvent event, int type) { |
914 | 3711 | caballero | questionAsked = true;
|
915 | 4115 | fjp | if (!cadToolStack.isEmpty()) {
|
916 | CADTool ct = (CADTool) cadToolStack.peek(); |
||
917 | 5015 | caballero | |
918 | switch (type) {
|
||
919 | case ABSOLUTE:
|
||
920 | 4313 | fjp | ct.transition(values[0], values[1], event); |
921 | 5165 | fjp | previousPoint = values; |
922 | 5015 | caballero | break;
|
923 | case RELATIVE_SCU:
|
||
924 | 5165 | fjp | // Comprobar que tenemos almacenado el punto anterior
|
925 | // y crear nuevo con coordenadas relativas a ?l.
|
||
926 | double[] auxSCU = values; |
||
927 | if (previousPoint != null) { |
||
928 | auxSCU[0] = previousPoint[0] + values[0]; |
||
929 | auxSCU[1] = previousPoint[1] + values[1]; |
||
930 | 5015 | caballero | } |
931 | ct.transition(auxSCU[0], auxSCU[1], event); |
||
932 | 3744 | caballero | |
933 | 5165 | fjp | previousPoint = auxSCU; |
934 | 5015 | caballero | break;
|
935 | case RELATIVE_SCP:
|
||
936 | 5165 | fjp | // TODO de momento no implementado.
|
937 | 5015 | caballero | ct.transition(values[0], values[1], event); |
938 | 5165 | fjp | previousPoint = values; |
939 | 5015 | caballero | break;
|
940 | 14849 | vcaballero | case POLAR_SCU://Relativo |
941 | 5165 | fjp | // Comprobar que tenemos almacenado el punto anterior
|
942 | // y crear nuevo con coordenadas relativas a ?l.
|
||
943 | double[] auxPolarSCU = values; |
||
944 | if (previousPoint != null) { |
||
945 | Point2D point = UtilFunctions.getPoint(new Point2D.Double( |
||
946 | previousPoint[0], previousPoint[1]), Math |
||
947 | .toRadians(values[1]), values[0]); |
||
948 | auxPolarSCU[0] = point.getX();
|
||
949 | auxPolarSCU[1] = point.getY();
|
||
950 | 5015 | caballero | ct.transition(auxPolarSCU[0], auxPolarSCU[1], event); |
951 | 5165 | fjp | } else {
|
952 | Point2D point = UtilFunctions.getPoint(new Point2D.Double( |
||
953 | 0, 0), Math.toRadians(values[1]), values[0]); |
||
954 | auxPolarSCU[0] = point.getX();
|
||
955 | auxPolarSCU[1] = point.getY();
|
||
956 | 5015 | caballero | ct.transition(auxPolarSCU[0], auxPolarSCU[1], event); |
957 | } |
||
958 | 5165 | fjp | previousPoint = auxPolarSCU; |
959 | 5015 | caballero | break;
|
960 | 14849 | vcaballero | case POLAR_SCP://Absoluto |
961 | 5165 | fjp | double[] auxPolarSCP = values; |
962 | if (previousPoint != null) { |
||
963 | Point2D point = UtilFunctions.getPoint(new Point2D.Double( |
||
964 | 14849 | vcaballero | 0, 0), Math |
965 | .toRadians(values[1]), values[0]); |
||
966 | 5165 | fjp | auxPolarSCP[0] = point.getX();
|
967 | auxPolarSCP[1] = point.getY();
|
||
968 | 5015 | caballero | ct.transition(auxPolarSCP[0], auxPolarSCP[1], event); |
969 | 5165 | fjp | } else {
|
970 | Point2D point = UtilFunctions.getPoint(new Point2D.Double( |
||
971 | 0, 0), values[1], values[0]); |
||
972 | auxPolarSCP[0] = point.getX();
|
||
973 | auxPolarSCP[1] = point.getY();
|
||
974 | 5015 | caballero | ct.transition(auxPolarSCP[0], auxPolarSCP[1], event); |
975 | } |
||
976 | 5165 | fjp | previousPoint = auxPolarSCP; |
977 | 5015 | caballero | break;
|
978 | default:
|
||
979 | break;
|
||
980 | 4115 | fjp | } |
981 | 5015 | caballero | askQuestion(); |
982 | 3711 | caballero | } |
983 | 3883 | caballero | configureMenu(); |
984 | 4024 | caballero | PluginServices.getMainFrame().enableControls(); |
985 | 3711 | caballero | } |
986 | 4115 | fjp | |
987 | 3744 | caballero | /**
|
988 | 20098 | jmvivo | * <p>One of the three kind of transaction methods of the <i>finite machine</i> of
|
989 | * edition.</p>
|
||
990 | 21668 | vcaballero | *
|
991 | 20098 | jmvivo | * <p>This one deals <code>value</code> as a single number used as a parameter for the current
|
992 | * tool state. Ultimately, if isn't valid, <code>number</code> will be rewritten in the
|
||
993 | * console notifying the user that isn't correct.</p>
|
||
994 | 21668 | vcaballero | *
|
995 | 20098 | jmvivo | * <p>After applying the changes, updates the controls available for managing the current data.</p>
|
996 | 21668 | vcaballero | *
|
997 | 20098 | jmvivo | * @param value value for the current tool state
|
998 | 21668 | vcaballero | *
|
999 | 20098 | jmvivo | * @see CADTool#transition(double)
|
1000 | * @see #transition(double[], InputEvent, int)
|
||
1001 | * @see #transition(String)
|
||
1002 | 3744 | caballero | */
|
1003 | 4147 | fjp | private void transition(double value) { |
1004 | 3744 | caballero | questionAsked = true;
|
1005 | 4115 | fjp | if (!cadToolStack.isEmpty()) {
|
1006 | CADTool ct = (CADTool) cadToolStack.peek(); |
||
1007 | ct.transition(value); |
||
1008 | 3744 | caballero | askQuestion(); |
1009 | 4115 | fjp | } |
1010 | 3883 | caballero | configureMenu(); |
1011 | 3744 | caballero | PluginServices.getMainFrame().enableControls(); |
1012 | } |
||
1013 | 4115 | fjp | |
1014 | 20098 | jmvivo | /**
|
1015 | * <p>One of the three kind of transaction methods of the <i>finite machine</i> of
|
||
1016 | * edition.</p>
|
||
1017 | 21668 | vcaballero | *
|
1018 | 20098 | jmvivo | * <p>This one deals <code>option</code> as an option of the current
|
1019 | * tool state. Ultimately, if isn't valid, <code>option</code> will be rewritten in the
|
||
1020 | * console notifying the user that isn't correct.</p>
|
||
1021 | 21668 | vcaballero | *
|
1022 | 20098 | jmvivo | * @param option option for the current tool state
|
1023 | 21668 | vcaballero | *
|
1024 | 20098 | jmvivo | * @see CADTool#transition(String)
|
1025 | * @see #transition(double[], InputEvent, int)
|
||
1026 | * @see #transition(double)
|
||
1027 | */
|
||
1028 | 4147 | fjp | public void transition(String option) { |
1029 | 4115 | fjp | questionAsked = true;
|
1030 | if (!cadToolStack.isEmpty()) {
|
||
1031 | CADTool ct = (CADTool) cadToolStack.peek(); |
||
1032 | 5165 | fjp | try {
|
1033 | ct.transition(option); |
||
1034 | } catch (Exception e) { |
||
1035 | 12739 | caballero | IWindow window = PluginServices.getMDIManager().getActiveWindow(); |
1036 | |||
1037 | if (window instanceof View) { |
||
1038 | ((View)window).getConsolePanel().addText(
|
||
1039 | "\n" + PluginServices.getText(this, "incorrect_option") |
||
1040 | + " : " + option, JConsole.ERROR);
|
||
1041 | } |
||
1042 | 4892 | caballero | } |
1043 | 4115 | fjp | askQuestion(); |
1044 | } |
||
1045 | configureMenu(); |
||
1046 | PluginServices.getMainFrame().enableControls(); |
||
1047 | 3744 | caballero | } |
1048 | 4115 | fjp | |
1049 | 3711 | caballero | /**
|
1050 | 20098 | jmvivo | * Shows or hides a grid on the <code>ViewPort</code> of the associated <code>MapControl</code>.
|
1051 | 5383 | caballero | *
|
1052 | 20098 | jmvivo | * @param value <code>true</code> to make the grid visible; <code>false</code> to make it invisible
|
1053 | 3711 | caballero | */
|
1054 | 23646 | vcaballero | // public void setGridVisibility(boolean value) {
|
1055 | // getGrid().setShowGrid(value);
|
||
1056 | // getGrid().setViewPort(getMapControl().getViewPort());
|
||
1057 | // getMapControl().repaint();
|
||
1058 | // }
|
||
1059 | 3711 | caballero | |
1060 | 23646 | vcaballero | // /**
|
1061 | // * Sets the snap tools enabled or disabled.
|
||
1062 | // *
|
||
1063 | // * @param activated <code>true</code> to enable the snap tools; <code>false</code> to disable them
|
||
1064 | // *
|
||
1065 | // * @see #isRefentEnabled()
|
||
1066 | // */
|
||
1067 | // public void setRefentEnabled(boolean activated) {
|
||
1068 | // bRefent = activated;
|
||
1069 | // }
|
||
1070 | //
|
||
1071 | // /**
|
||
1072 | // * Determines if snap tools are enabled or disabled.
|
||
1073 | // *
|
||
1074 | // * @return <code>true</code> to enable the snap tools; <code>false</code> to disable them
|
||
1075 | // *
|
||
1076 | // * @see #setRefentEnabled(boolean)
|
||
1077 | // */
|
||
1078 | // public boolean isRefentEnabled()
|
||
1079 | // {
|
||
1080 | // return bRefent;
|
||
1081 | // }
|
||
1082 | 5985 | caballero | |
1083 | 20098 | jmvivo | /*
|
1084 | * (non-Javadoc)
|
||
1085 | 3711 | caballero | * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#getListener()
|
1086 | */
|
||
1087 | public ToolListener getListener() {
|
||
1088 | return new ToolListener() { |
||
1089 | 4115 | fjp | /**
|
1090 | * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getCursor()
|
||
1091 | */
|
||
1092 | 23646 | vcaballero | public Image getImageCursor() { |
1093 | return imageCursor;
|
||
1094 | 4115 | fjp | } |
1095 | 3711 | caballero | |
1096 | 4115 | fjp | /**
|
1097 | * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
|
||
1098 | */
|
||
1099 | public boolean cancelDrawing() { |
||
1100 | return false; |
||
1101 | } |
||
1102 | }; |
||
1103 | 3711 | caballero | } |
1104 | |||
1105 | /**
|
||
1106 | 20098 | jmvivo | * Returns the {@link CADTool CADTool} at the top of the stack without removing it from the CAD tool stack.
|
1107 | 21668 | vcaballero | *
|
1108 | 20098 | jmvivo | * @return the {@link CADTool CADTool} at the top of the stack
|
1109 | 21668 | vcaballero | *
|
1110 | 20098 | jmvivo | * @see #pushCadTool(CADTool)
|
1111 | * @see #popCadTool()
|
||
1112 | * @see #setCadTool(CADTool)
|
||
1113 | 3711 | caballero | */
|
1114 | public CADTool getCadTool() {
|
||
1115 | return (CADTool) cadToolStack.peek();
|
||
1116 | } |
||
1117 | |||
1118 | /**
|
||
1119 | 20098 | jmvivo | * <p>Pushes a {@link CADTool CADTool} onto the top of the CAD tool stack, and sets it as current.</p>
|
1120 | 21668 | vcaballero | *
|
1121 | 20098 | jmvivo | * @param cadTool CAD tool to enable as current
|
1122 | 21668 | vcaballero | *
|
1123 | 20098 | jmvivo | * @see #getCadTool()
|
1124 | * @see #popCadTool()
|
||
1125 | * @see #setCadTool(CADTool)
|
||
1126 | 3711 | caballero | */
|
1127 | public void pushCadTool(CADTool cadTool) { |
||
1128 | cadToolStack.push(cadTool); |
||
1129 | cadTool.setCadToolAdapter(this);
|
||
1130 | 4115 | fjp | // cadTool.initializeStatus();
|
1131 | // cadTool.setVectorialAdapter(vea);
|
||
1132 | /*
|
||
1133 | * int ret = cadTool.transition(null, editableFeatureSource, selection,
|
||
1134 | * new double[0]);
|
||
1135 | 5383 | caballero | *
|
1136 | 4115 | fjp | * if ((ret & Automaton.AUTOMATON_FINISHED) ==
|
1137 | * Automaton.AUTOMATON_FINISHED) { popCadTool();
|
||
1138 | 5383 | caballero | *
|
1139 | 4115 | fjp | * if (cadToolStack.isEmpty()) { pushCadTool(new
|
1140 | * com.iver.cit.gvsig.gui.cad.smc.gen.CADTool());//new
|
||
1141 | * SelectionCadTool());
|
||
1142 | * PluginServices.getMainFrame().setSelectedTool("selection"); }
|
||
1143 | 5383 | caballero | *
|
1144 | 4115 | fjp | * askQuestion();
|
1145 | 5383 | caballero | *
|
1146 | 4115 | fjp | * getMapControl().drawMap(false); }
|
1147 | */
|
||
1148 | 3711 | caballero | } |
1149 | |||
1150 | /**
|
||
1151 | 20098 | jmvivo | * Removes the peek of the CAD tool stack.
|
1152 | 21668 | vcaballero | *
|
1153 | 20098 | jmvivo | * @see #pushCadTool(CADTool)
|
1154 | * @see #getCadTool()
|
||
1155 | * @see #setCadTool(CADTool)
|
||
1156 | 3711 | caballero | */
|
1157 | public void popCadTool() { |
||
1158 | cadToolStack.pop(); |
||
1159 | } |
||
1160 | |||
1161 | /**
|
||
1162 | 20098 | jmvivo | * <p>Displays at the console associated to the current active view that's being edited, the question of the following
|
1163 | * operation that user can do with the current <code>CADTool</code>, only if it hasn't just answered.</p>
|
||
1164 | 21668 | vcaballero | *
|
1165 | 20098 | jmvivo | * <p>The format of the question will be according the following pattern:<br>
|
1166 | * "\n#"<i>{cadtool at CAD tool stack peek}</i>.getQuestion()">"
|
||
1167 | * </p>
|
||
1168 | 3711 | caballero | */
|
1169 | public void askQuestion() { |
||
1170 | 4115 | fjp | CADTool cadtool = (CADTool) cadToolStack.peek(); |
1171 | /*
|
||
1172 | * if (cadtool..getStatus()==0){
|
||
1173 | * PluginServices.getMainFrame().addTextToConsole("\n"
|
||
1174 | * +cadtool.getName()); }
|
||
1175 | */
|
||
1176 | 6880 | cesar | if (PluginServices.getMDIManager().getActiveWindow() instanceof View) |
1177 | 5923 | fjp | { |
1178 | 6880 | cesar | View vista = (View) PluginServices.getMDIManager().getActiveWindow(); |
1179 | 9121 | caballero | String question=cadtool.getQuestion();
|
1180 | if (lastQuestion==null || !(lastQuestion.equals(question)) || questionAsked) { |
||
1181 | 5923 | fjp | vista.getConsolePanel().addText( |
1182 | 9121 | caballero | "\n" + "#" + question + " > ", JConsole.MESSAGE); |
1183 | 5923 | fjp | // ***PluginServices.getMainFrame().addTextToConsole("\n" +
|
1184 | // cadtool.getQuestion());
|
||
1185 | 9121 | caballero | questionAsked = false;
|
1186 | } |
||
1187 | lastQuestion=question; |
||
1188 | 5923 | fjp | } |
1189 | 3711 | caballero | |
1190 | } |
||
1191 | |||
1192 | /**
|
||
1193 | 20098 | jmvivo | * Empties the CAD tools stack and pushes <code>cadTool</code> in it.
|
1194 | 21668 | vcaballero | *
|
1195 | 20098 | jmvivo | * @param cadTool CAD tool to set at the peek of the stack
|
1196 | 21668 | vcaballero | *
|
1197 | 20098 | jmvivo | * @see #pushCadTool(CADTool)
|
1198 | * @see #popCadTool()
|
||
1199 | * @see #getCadTool()
|
||
1200 | 3711 | caballero | */
|
1201 | public void setCadTool(CADTool cadTool) { |
||
1202 | cadToolStack.clear(); |
||
1203 | pushCadTool(cadTool); |
||
1204 | 5165 | fjp | // askQuestion();
|
1205 | 3711 | caballero | } |
1206 | |||
1207 | /**
|
||
1208 | 20098 | jmvivo | * <p>Removes all geometries selected in the associated <code>MapControl</code>.
|
1209 | 3711 | caballero | */
|
1210 | 18453 | vcaballero | public void delete() { |
1211 | 5223 | fjp | ILayerEdited aux = CADExtension.getEditionManager().getActiveLayerEdited(); |
1212 | 5383 | caballero | if (!(aux instanceof VectorialLayerEdited)) |
1213 | 5223 | fjp | return;
|
1214 | 5383 | caballero | VectorialLayerEdited vle = (VectorialLayerEdited) aux; |
1215 | 22986 | vcaballero | FeatureStore featureStore=null;
|
1216 | try {
|
||
1217 | featureStore = ((FLyrVect)vle.getLayer()).getFeatureStore(); |
||
1218 | } catch (ReadException e1) {
|
||
1219 | // TODO Auto-generated catch block
|
||
1220 | e1.printStackTrace(); |
||
1221 | } |
||
1222 | 5223 | fjp | |
1223 | 21668 | vcaballero | CommandsRecord cr=featureStore.getCommandsRecord(); |
1224 | cr.startComplex(); |
||
1225 | 3711 | caballero | try {
|
1226 | 23842 | jjdelcerro | FeatureSet selection = (FeatureSet)featureStore.getSelection(); |
1227 | 22986 | vcaballero | Iterator iterator=selection.iterator();
|
1228 | while (iterator.hasNext()) {
|
||
1229 | Feature feature = (Feature) iterator.next(); |
||
1230 | featureStore.delete(feature); |
||
1231 | 4584 | caballero | } |
1232 | 22986 | vcaballero | // int[] indexesToDel = new int[selection.cardinality()];
|
1233 | // int j = 0;
|
||
1234 | // for (int i = selection.nextSetBit(0); i >= 0; i = selection
|
||
1235 | // .nextSetBit(i + 1)) {
|
||
1236 | // indexesToDel[j++] = i;
|
||
1237 | // // /vea.removeRow(i);
|
||
1238 | // }
|
||
1239 | 5985 | caballero | |
1240 | // ArrayList selectedRow = vle.getSelectedRow();
|
||
1241 | //
|
||
1242 | // int[] indexesToDel = new int[selectedRow.size()];
|
||
1243 | // for (int i = 0;i < selectedRow.size(); i++) {
|
||
1244 | // IRowEdited edRow = (IRowEdited) selectedRow.get(i);
|
||
1245 | // indexesToDel[i] = vea.getInversedIndex(edRow.getIndex());
|
||
1246 | // }
|
||
1247 | //
|
||
1248 | 22986 | vcaballero | // for (int i = indexesToDel.length - 1; i >= 0; i--) {
|
1249 | // vea.removeRow(indexesToDel[i], PluginServices.getText(this,
|
||
1250 | // "deleted_feature"),EditionEvent.GRAPHIC);
|
||
1251 | // }
|
||
1252 | 10626 | caballero | System.out.println("clear Selection"); |
1253 | selection.clear(); |
||
1254 | vle.clearSelection(VectorialLayerEdited.NOTSAVEPREVIOUS); |
||
1255 | 21668 | vcaballero | } catch (ReadException e) {
|
1256 | 12739 | caballero | NotificationManager.addError(e.getMessage(),e); |
1257 | 22986 | vcaballero | } catch (DataException e) {
|
1258 | NotificationManager.addError(e.getMessage(),e); |
||
1259 | 3711 | caballero | } finally {
|
1260 | 10626 | caballero | String description=PluginServices.getText(this,"remove_geometry"); |
1261 | 21668 | vcaballero | cr.endComplex(description); |
1262 | 3711 | caballero | } |
1263 | 10626 | caballero | |
1264 | |||
1265 | 5165 | fjp | /*
|
1266 | * if (getCadTool() instanceof SelectionCADTool) { SelectionCADTool
|
||
1267 | * selTool = (SelectionCADTool) getCadTool(); selTool.clearSelection(); }
|
||
1268 | */
|
||
1269 | 5923 | fjp | refreshEditedLayer(); |
1270 | 3711 | caballero | } |
1271 | |||
1272 | /**
|
||
1273 | 20098 | jmvivo | * @see CADGrid#setAdjustGrid(boolean)
|
1274 | 3711 | caballero | */
|
1275 | 23646 | vcaballero | // public void setAdjustGrid(boolean b) {
|
1276 | // getGrid().setAdjustGrid(b);
|
||
1277 | // }
|
||
1278 | 3711 | caballero | |
1279 | /**
|
||
1280 | 20098 | jmvivo | * <p>Responds to actions of writing common key commands for all kind of CAD operations, enabling/disabling after
|
1281 | * the controls to manage the available information according the tool selected:
|
||
1282 | * <ul>
|
||
1283 | * <li><i>eliminar</i>: removes the geometries that are now selected.</li>
|
||
1284 | * <li><i>escape</i>: executes different actions according to the current CAD tool of the associated <code>MapControl</code>:
|
||
1285 | * <ul>
|
||
1286 | * <li>If the tool enabled is identified by <i>cadtooladapter</i>: empties the CAD tools stack, changing the current tool by
|
||
1287 | * a {@link SelectionCADTool SelectionCADTool}, which is identified by <i>_selection</i> and allows select features of the
|
||
1288 | * active vector layer of the associated <code>MapControl</code> instance. </li>
|
||
1289 | * <li>Otherwise, that means current associated <code>MapControl</code> instance isn't identified by "<i>cadtooladapter</i>",
|
||
1290 | * changes the enabled tool by the previous.</li>
|
||
1291 | * </ul>
|
||
1292 | * </li>
|
||
1293 | * </ul>
|
||
1294 | * </p>
|
||
1295 | 5383 | caballero | *
|
1296 | 20098 | jmvivo | * @param actionCommand identifier of the key action command executed by the user
|
1297 | 21668 | vcaballero | *
|
1298 | 20098 | jmvivo | * @see SelectionCADTool
|
1299 | * @see MapControl#setPrevTool()
|
||
1300 | 3711 | caballero | */
|
1301 | public void keyPressed(String actionCommand) { |
||
1302 | 7834 | jmvivo | if (CADExtension.getEditionManager().getActiveLayerEdited()== null) { |
1303 | return;
|
||
1304 | } |
||
1305 | 3725 | caballero | if (actionCommand.equals("eliminar")) { |
1306 | 3711 | caballero | delete(); |
1307 | } else if (actionCommand.equals("escape")) { |
||
1308 | 6385 | fjp | if (getMapControl().getCurrentTool().equals("cadtooladapter")) { |
1309 | 3847 | caballero | CADTool ct = (CADTool) cadToolStack.peek(); |
1310 | ct.end(); |
||
1311 | 3711 | caballero | cadToolStack.clear(); |
1312 | 4210 | fjp | SelectionCADTool selCad = new SelectionCADTool();
|
1313 | selCad.init(); |
||
1314 | 5165 | fjp | VectorialLayerEdited vle = (VectorialLayerEdited) CADExtension |
1315 | .getEditionManager().getActiveLayerEdited(); |
||
1316 | 10626 | caballero | try {
|
1317 | vle.clearSelection(VectorialLayerEdited.NOTSAVEPREVIOUS); |
||
1318 | 21668 | vcaballero | } catch (ReadException e) {
|
1319 | 12739 | caballero | NotificationManager.addError(e.getMessage(),e); |
1320 | 10626 | caballero | } |
1321 | 4366 | caballero | |
1322 | 4210 | fjp | pushCadTool(selCad); |
1323 | // getVectorialAdapter().getSelection().clear();
|
||
1324 | 5985 | caballero | |
1325 | 5923 | fjp | refreshEditedLayer(); |
1326 | 5985 | caballero | |
1327 | |||
1328 | 5015 | caballero | PluginServices.getMainFrame().setSelectedTool("_selection");
|
1329 | 5165 | fjp | // askQuestion();
|
1330 | } else {
|
||
1331 | 4892 | caballero | getMapControl().setPrevTool(); |
1332 | 3711 | caballero | } |
1333 | } |
||
1334 | 3725 | caballero | |
1335 | 3711 | caballero | PluginServices.getMainFrame().enableControls(); |
1336 | |||
1337 | } |
||
1338 | 5985 | caballero | |
1339 | 5923 | fjp | /**
|
1340 | 20098 | jmvivo | * <p>Applies a lightweight repaint of the active layer being edited.</p>
|
1341 | 21668 | vcaballero | *
|
1342 | 20098 | jmvivo | * <p>All layers under it won't be drawn, only the upper one and whose are over that layer in the TOC.</p>
|
1343 | 21668 | vcaballero | *
|
1344 | 20098 | jmvivo | * @see MapControl#rePaintDirtyLayers()
|
1345 | 5923 | fjp | */
|
1346 | public void refreshEditedLayer() |
||
1347 | { |
||
1348 | ILayerEdited edLayer = CADExtension.getEditionManager().getActiveLayerEdited(); |
||
1349 | if (edLayer != null) |
||
1350 | { |
||
1351 | edLayer.getLayer().setDirty(true);
|
||
1352 | getMapControl().rePaintDirtyLayers(); |
||
1353 | } |
||
1354 | 5985 | caballero | |
1355 | 5923 | fjp | } |
1356 | 4115 | fjp | |
1357 | 20098 | jmvivo | /**
|
1358 | * Gets the {@link CADGrid CADGrid} that can be drawn on the <code>ViewPort</code> of the associated <code>MapControl</code>.
|
||
1359 | 21668 | vcaballero | *
|
1360 | 20098 | jmvivo | * @return reference to the <i>grid</i> that can be applied on the <code>ViewPort</code>
|
1361 | 21668 | vcaballero | *
|
1362 | 20098 | jmvivo | * @see #setGridVisibility(boolean)
|
1363 | */
|
||
1364 | 23646 | vcaballero | // public CADGrid getGrid() {
|
1365 | // return cadgrid;
|
||
1366 | // }
|
||
1367 | 4115 | fjp | |
1368 | 20098 | jmvivo | /**
|
1369 | * Determines if is enabled or not the <i>orto</i> mode.
|
||
1370 | 21668 | vcaballero | *
|
1371 | * @return <code>true</code> if is enabled the <i>orto</i> mode; otherwise <code>false</code>
|
||
1372 | *
|
||
1373 | 20098 | jmvivo | * @see #setOrtoMode(boolean)
|
1374 | */
|
||
1375 | 5874 | fjp | public boolean isOrtoMode() { |
1376 | return bOrtoMode;
|
||
1377 | } |
||
1378 | 4115 | fjp | |
1379 | 20098 | jmvivo | /**
|
1380 | * Enables / disables the <i>orto</i> mode.
|
||
1381 | 21668 | vcaballero | *
|
1382 | 20098 | jmvivo | * @param b the desired value
|
1383 | 21668 | vcaballero | *
|
1384 | 20098 | jmvivo | * @see #isOrtoMode()
|
1385 | */
|
||
1386 | 5874 | fjp | public void setOrtoMode(boolean b) { |
1387 | bOrtoMode = b; |
||
1388 | } |
||
1389 | |||
1390 | 20098 | jmvivo | /**
|
1391 | * Associates and stores the specified name with the specified {@link CADTool CADTool}.
|
||
1392 | 21668 | vcaballero | *
|
1393 | 20098 | jmvivo | * @param name name of the tool
|
1394 | * @param c CAD tool to interactuate editing the layers
|
||
1395 | 21668 | vcaballero | *
|
1396 | 20098 | jmvivo | * @see #getCADTools()
|
1397 | * @see #getCADTool(String)
|
||
1398 | */
|
||
1399 | 6174 | caballero | public static void addCADTool(String name, CADTool c) { |
1400 | namesCadTools.put(name, c); |
||
1401 | 5874 | fjp | |
1402 | 6174 | caballero | } |
1403 | 20098 | jmvivo | |
1404 | /**
|
||
1405 | * Gets all CAD tools available to edit layers with this tool listener.
|
||
1406 | 21668 | vcaballero | *
|
1407 | 20098 | jmvivo | * @return CAD tools available to edit layers with this tool listener
|
1408 | *
|
||
1409 | * @see #addCADTool(String, CADTool)
|
||
1410 | * @see #getCADTool(String)
|
||
1411 | */
|
||
1412 | 6174 | caballero | public static CADTool[] getCADTools() { |
1413 | return (CADTool[]) CADToolAdapter.namesCadTools.values().toArray(new CADTool[0]); |
||
1414 | } |
||
1415 | 20098 | jmvivo | |
1416 | /**
|
||
1417 | * Returns the {@link CADTool CADTool} to which the specified name is mapped.
|
||
1418 | 21668 | vcaballero | *
|
1419 | 20098 | jmvivo | * @param text name of the tool
|
1420 | * @return the CAD tool whose associated name is to be returned
|
||
1421 | 21668 | vcaballero | *
|
1422 | 20098 | jmvivo | * @see #addCADTool(String, CADTool)
|
1423 | * @see #getCADTools()
|
||
1424 | */
|
||
1425 | 6174 | caballero | public CADTool getCADTool(String text) { |
1426 | CADTool ct = (CADTool) namesCadTools.get(text); |
||
1427 | return ct;
|
||
1428 | } |
||
1429 | |||
1430 | 20098 | jmvivo | /**
|
1431 | * Gets the object used to manage the edition of the layers of the associated <code>MapControl</code>.
|
||
1432 | 21668 | vcaballero | *
|
1433 | 20098 | jmvivo | * @see EditionManager
|
1434 | 21668 | vcaballero | *
|
1435 | 20098 | jmvivo | * @return object used to manage the edition of the layers
|
1436 | */
|
||
1437 | 6174 | caballero | public EditionManager getEditionManager() {
|
1438 | return editionManager;
|
||
1439 | } |
||
1440 | |||
1441 | 20098 | jmvivo | /**
|
1442 | * <p>Initializes the <i>flatness</i> with the defined in preferences.</p>
|
||
1443 | *
|
||
1444 | * <p>The <i>flatness</i> is the maximum tolerance used to approximate curved lines in a <i>shape</i> by polylines.</p>
|
||
1445 | * <p>The shapes doesn't support primitive like arcs neither other curved lines to draw their geometries, then for drawing any
|
||
1446 | * kind of this geometries the curved lines are drawn approximately by a polyline. And for doing more realistic that curves,
|
||
1447 | * is used the <i>flatness</i> parameter, that indicates that the difference between each arc and the straight segment that
|
||
1448 | * approximates it must be in the worse case, like the <i>flatness</i>.</p>
|
||
1449 | 21668 | vcaballero | *
|
1450 | 20098 | jmvivo | * @see FConverter#FLATNESS
|
1451 | */
|
||
1452 | 6713 | caballero | public void initializeFlatness() { |
1453 | 7072 | caballero | if (!flatnessInitialized){
|
1454 | flatnessInitialized=true;
|
||
1455 | Preferences prefs = Preferences.userRoot().node( "cadtooladapter" ); |
||
1456 | 21668 | vcaballero | double flatness = prefs.getDouble("flatness",Converter.FLATNESS); |
1457 | Converter.FLATNESS=flatness; |
||
1458 | 7072 | caballero | } |
1459 | 6713 | caballero | } |
1460 | 20098 | jmvivo | |
1461 | /**
|
||
1462 | * <p>Updates the grid on the <code>ViewPort</code> of the associated <code>MapControl</code>
|
||
1463 | * object according the values in the {@link com.iver.cit.gvsig.gui.cad.CADToolAdapter.prefs.Preferences com.iver.cit.gvsig.gui.cad.CADToolAdapter.prefs.Preferences}.</p>
|
||
1464 | 21668 | vcaballero | *
|
1465 | 20098 | jmvivo | * <p>The preferences are:
|
1466 | * <ul>
|
||
1467 | * <li>Show/hide the grid.</li>
|
||
1468 | * <li>Adjust or not the grid.</li>
|
||
1469 | * <li>Horizontal ( X ) line separation.</li>
|
||
1470 | * <li>Vertical ( Y ) line separation.</li>
|
||
1471 | * </ul>
|
||
1472 | * </p>
|
||
1473 | */
|
||
1474 | 23646 | vcaballero | // public void initializeGrid(){
|
1475 | // boolean showGrid = prefs.getBoolean("grid.showgrid",getGrid().isShowGrid());
|
||
1476 | // boolean adjustGrid = prefs.getBoolean("grid.adjustgrid",getGrid().isAdjustGrid());
|
||
1477 | //
|
||
1478 | // double dx = prefs.getDouble("grid.distancex",getGrid().getGridSizeX());
|
||
1479 | // double dy = prefs.getDouble("grid.distancey",getGrid().getGridSizeY());
|
||
1480 | //
|
||
1481 | // setGridVisibility(showGrid);
|
||
1482 | // setAdjustGrid(adjustGrid);
|
||
1483 | // getGrid().setGridSizeX(dx);
|
||
1484 | // getGrid().setGridSizeY(dy);
|
||
1485 | // }
|
||
1486 | 6713 | caballero | |
1487 | 12296 | caballero | /**
|
1488 | 20098 | jmvivo | * <p>Returns the type of the shape that's the current active and vector layer being edited.</p>
|
1489 | 21668 | vcaballero | *
|
1490 | 20098 | jmvivo | * @see FLyrVect#getShapeType()
|
1491 | 21668 | vcaballero | *
|
1492 | 20098 | jmvivo | * @return type of the shape that's the current active and vector layer being edited
|
1493 | */
|
||
1494 | 12296 | caballero | public int getActiveLayerType() { |
1495 | 22036 | vcaballero | int type=Geometry.TYPES.GEOMETRY;
|
1496 | 12296 | caballero | try {
|
1497 | type=((FLyrVect)CADExtension.getEditionManager().getActiveLayerEdited().getLayer()).getShapeType(); |
||
1498 | 21668 | vcaballero | } catch (ReadException e) {
|
1499 | 12296 | caballero | NotificationManager.addError(e); |
1500 | } |
||
1501 | return type;
|
||
1502 | } |
||
1503 | 23646 | vcaballero | |
1504 | 3711 | caballero | } |