root / trunk / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / tools / PolylineCADTool.java @ 9243
History | View | Annotate | Download (19.3 KB)
1 | 3765 | caballero | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
4 | *
|
||
5 | * This program is free software; you can redistribute it and/or
|
||
6 | * modify it under the terms of the GNU General Public License
|
||
7 | * as published by the Free Software Foundation; either version 2
|
||
8 | * of the License, or (at your option) any later version.
|
||
9 | *
|
||
10 | * This program is distributed in the hope that it will be useful,
|
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | * GNU General Public License for more details.
|
||
14 | *
|
||
15 | * You should have received a copy of the GNU General Public License
|
||
16 | * along with this program; if not, write to the Free Software
|
||
17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
18 | *
|
||
19 | * For more information, contact:
|
||
20 | *
|
||
21 | * Generalitat Valenciana
|
||
22 | * Conselleria d'Infraestructures i Transport
|
||
23 | * Av. Blasco Ib??ez, 50
|
||
24 | * 46010 VALENCIA
|
||
25 | * SPAIN
|
||
26 | *
|
||
27 | * +34 963862235
|
||
28 | * gvsig@gva.es
|
||
29 | * www.gvsig.gva.es
|
||
30 | *
|
||
31 | * or
|
||
32 | *
|
||
33 | * IVER T.I. S.A
|
||
34 | * Salamanca 50
|
||
35 | * 46005 Valencia
|
||
36 | * Spain
|
||
37 | *
|
||
38 | * +34 963163400
|
||
39 | * dac@iver.es
|
||
40 | */
|
||
41 | 3782 | caballero | package com.iver.cit.gvsig.gui.cad.tools; |
42 | |||
43 | 3832 | caballero | import java.awt.Graphics; |
44 | import java.awt.Graphics2D; |
||
45 | 4313 | fjp | import java.awt.event.InputEvent; |
46 | 3832 | caballero | import java.awt.geom.Point2D; |
47 | import java.util.ArrayList; |
||
48 | |||
49 | 5747 | fjp | import org.apache.log4j.Logger; |
50 | |||
51 | 4584 | caballero | import com.iver.andami.PluginServices; |
52 | 3782 | caballero | import com.iver.cit.gvsig.fmap.core.FGeometryCollection; |
53 | import com.iver.cit.gvsig.fmap.core.FShape; |
||
54 | import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
||
55 | import com.iver.cit.gvsig.fmap.core.IGeometry; |
||
56 | import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
||
57 | 6714 | caballero | import com.iver.cit.gvsig.fmap.core.v02.FConverter; |
58 | 5747 | fjp | import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
59 | 3782 | caballero | import com.iver.cit.gvsig.fmap.edition.UtilFunctions; |
60 | import com.iver.cit.gvsig.gui.cad.CADTool; |
||
61 | 3832 | caballero | import com.iver.cit.gvsig.gui.cad.DefaultCADTool; |
62 | 5735 | caballero | import com.iver.cit.gvsig.gui.cad.exception.CommandException; |
63 | 3782 | caballero | import com.iver.cit.gvsig.gui.cad.tools.smc.PolylineCADToolContext; |
64 | import com.iver.cit.gvsig.gui.cad.tools.smc.PolylineCADToolContext.PolylineCADToolState; |
||
65 | |||
66 | |||
67 | /**
|
||
68 | * DOCUMENT ME!
|
||
69 | *
|
||
70 | * @author Vicente Caballero Navarro
|
||
71 | */
|
||
72 | 3765 | caballero | public class PolylineCADTool extends DefaultCADTool { |
73 | 5747 | fjp | private static Logger logger = Logger.getLogger(PolylineCADTool.class.getName()); |
74 | 3765 | caballero | private PolylineCADToolContext _fsm;
|
75 | private Point2D firstPoint; |
||
76 | private Point2D antPoint; |
||
77 | private Point2D antantPoint; |
||
78 | private Point2D antCenter; |
||
79 | 3782 | caballero | private Point2D antInter; |
80 | private ArrayList list = new ArrayList(); |
||
81 | 6161 | caballero | private boolean close=false; |
82 | 3782 | caballero | |
83 | /**
|
||
84 | 3765 | caballero | * Crea un nuevo PolylineCADTool.
|
85 | */
|
||
86 | public PolylineCADTool() {
|
||
87 | 3883 | caballero | |
88 | 3765 | caballero | } |
89 | |||
90 | /**
|
||
91 | * M?todo de incio, para poner el c?digo de todo lo que se requiera de una
|
||
92 | * carga previa a la utilizaci?n de la herramienta.
|
||
93 | */
|
||
94 | public void init() { |
||
95 | 5170 | caballero | _fsm = new PolylineCADToolContext(this); |
96 | 3765 | caballero | } |
97 | |||
98 | 3883 | caballero | public void endGeometry() { |
99 | 5170 | caballero | IGeometry[] geoms = (IGeometry[]) list.toArray(new IGeometry[0]); |
100 | 3846 | caballero | FGeometryCollection fgc = new FGeometryCollection(geoms);
|
101 | 6161 | caballero | try {
|
102 | if (getVLE().getVEA().getShapeType()==FShape.POLYGON && !close){
|
||
103 | 5880 | fjp | GeneralPathX gpx=new GeneralPathX();
|
104 | gpx.moveTo(antPoint.getX(),antPoint.getY()); |
||
105 | gpx.lineTo(firstPoint.getX(),firstPoint.getY()); |
||
106 | IGeometry line=ShapeFactory.createPolyline2D(gpx); |
||
107 | fgc.addGeometry(line); |
||
108 | } |
||
109 | } catch (DriverIOException e) {
|
||
110 | e.printStackTrace(); |
||
111 | 6161 | caballero | } |
112 | 5880 | fjp | |
113 | // No queremos guardar FGeometryCollections:
|
||
114 | GeneralPathX gp = new GeneralPathX();
|
||
115 | 7072 | caballero | gp.append(fgc.getPathIterator(null,FConverter.FLATNESS), true); |
116 | 5880 | fjp | IGeometry newGeom = ShapeFactory.createPolyline2D(gp); |
117 | 6034 | fjp | // if (gp.isClosed())
|
118 | // {
|
||
119 | // gp.ensureOrientation(false); // Poligono exterior.
|
||
120 | // // Voy a testear que se puede convertir a JTS:
|
||
121 | // IGeometry gAux = ShapeFactory.createPolygon2D(gp);
|
||
122 | // Geometry jtsG = gAux.toJTSGeometry();
|
||
123 | // logger.debug("A punto de escribir " + jtsG.toText());
|
||
124 | // try {
|
||
125 | // int shapeType = getVLE().getVEA().getShapeType();
|
||
126 | // if ((shapeType ==FShape.POLYGON) || (shapeType == FShape.MULTI)) {
|
||
127 | // newGeom = gAux;
|
||
128 | // }
|
||
129 | // } catch (DriverIOException e) {
|
||
130 | // // TODO Auto-generated catch block
|
||
131 | // e.printStackTrace();
|
||
132 | // return;
|
||
133 | // }
|
||
134 | //
|
||
135 | // }
|
||
136 | //
|
||
137 | 5880 | fjp | addGeometry(newGeom); |
138 | 3782 | caballero | _fsm = new PolylineCADToolContext(this); |
139 | 3883 | caballero | list.clear(); |
140 | antantPoint=antCenter=antInter=antPoint=firstPoint=null;
|
||
141 | 3765 | caballero | } |
142 | 3883 | caballero | public void closeGeometry(){ |
143 | 6161 | caballero | close=true;
|
144 | 5170 | caballero | GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD,
|
145 | 2);
|
||
146 | elShape.moveTo(antPoint.getX(), antPoint.getY()); |
||
147 | elShape.lineTo(firstPoint.getX(), firstPoint.getY()); |
||
148 | 3765 | caballero | |
149 | 5170 | caballero | list.add(ShapeFactory.createPolyline2D(elShape)); |
150 | 5747 | fjp | |
151 | 5945 | caballero | |
152 | 5170 | caballero | // list.add(ShapeFactory.createPolyline2D(elShape));
|
153 | 5880 | fjp | |
154 | 3883 | caballero | } |
155 | 3765 | caballero | /* (non-Javadoc)
|
156 | 3782 | caballero | * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double, double)
|
157 | */
|
||
158 | 4313 | fjp | public void transition(double x, double y, InputEvent event) { |
159 | 4324 | caballero | _fsm.addPoint(x, y, event); |
160 | 3765 | caballero | } |
161 | |||
162 | /* (non-Javadoc)
|
||
163 | 3782 | caballero | * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double)
|
164 | */
|
||
165 | 3832 | caballero | public void transition(double d) { |
166 | 5735 | caballero | _fsm.addValue(d); |
167 | 3782 | caballero | } |
168 | 3765 | caballero | |
169 | 3782 | caballero | /* (non-Javadoc)
|
170 | * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, java.lang.String)
|
||
171 | */
|
||
172 | 5735 | caballero | public void transition(String s) throws CommandException { |
173 | 5170 | caballero | if (!super.changeCommand(s)){ |
174 | _fsm.addOption(s); |
||
175 | } |
||
176 | 3782 | caballero | } |
177 | |||
178 | 3765 | caballero | /**
|
179 | * Equivale al transition del prototipo pero sin pasarle como par?metro el
|
||
180 | * editableFeatureSource que ya estar? creado.
|
||
181 | *
|
||
182 | * @param sel Bitset con las geometr?as que est?n seleccionadas.
|
||
183 | * @param x par?metro x del punto que se pase en esta transici?n.
|
||
184 | * @param y par?metro y del punto que se pase en esta transici?n.
|
||
185 | */
|
||
186 | 4365 | caballero | public void addPoint(double x, double y,InputEvent event) { |
187 | 5170 | caballero | PolylineCADToolState actualState = (PolylineCADToolState) _fsm.getPreviousState(); |
188 | 3765 | caballero | String status = actualState.getName();
|
189 | 3782 | caballero | |
190 | 5945 | caballero | // if (status.equals("Polyline.FirstPoint")) {
|
191 | // antPoint = new Point2D.Double(x, y);
|
||
192 | //
|
||
193 | // if (firstPoint == null) {
|
||
194 | // firstPoint = (Point2D) antPoint.clone();
|
||
195 | // }
|
||
196 | // } else
|
||
197 | if (status.equals("Polyline.NextPointOrArcOrClose") || status.equals("Polyline.FirstPoint")) { |
||
198 | 6071 | caballero | |
199 | 5945 | caballero | if (firstPoint == null) { |
200 | 6071 | caballero | firstPoint = new Point2D.Double(x, y); |
201 | 5945 | caballero | } |
202 | Point2D point = new Point2D.Double(x, y); |
||
203 | 3782 | caballero | |
204 | if (antPoint != null) { |
||
205 | GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD,
|
||
206 | 2);
|
||
207 | elShape.moveTo(antPoint.getX(), antPoint.getY()); |
||
208 | elShape.lineTo(point.getX(), point.getY()); |
||
209 | 5170 | caballero | list.add(ShapeFactory.createPolyline2D(elShape)); |
210 | 3978 | caballero | |
211 | 3782 | caballero | } |
212 | 6071 | caballero | if (antPoint==null) |
213 | antPoint = (Point2D)firstPoint.clone();
|
||
214 | 3765 | caballero | |
215 | 3782 | caballero | if (antPoint != null) { |
216 | antantPoint = antPoint; |
||
217 | } |
||
218 | 3765 | caballero | |
219 | 3782 | caballero | antPoint = point; |
220 | 3978 | caballero | } else if (status.equals("Polyline.NextPointOrLineOrClose")) { |
221 | 3782 | caballero | Point2D point = new Point2D.Double(x, y); |
222 | Point2D lastp = antPoint; //(Point2D)points.get(i-1); |
||
223 | 3765 | caballero | |
224 | 3782 | caballero | if (antantPoint == null) { |
225 | antantPoint = new Point2D.Double(lastp.getX() + |
||
226 | (point.getX() / 2), lastp.getY() + (point.getY() / 2)); |
||
227 | } |
||
228 | 3765 | caballero | |
229 | 3782 | caballero | if (((point.getY() == lastp.getY()) &&
|
230 | (point.getX() < lastp.getX())) || |
||
231 | ((point.getX() == lastp.getX()) && |
||
232 | (point.getY() < lastp.getY()))) { |
||
233 | } else {
|
||
234 | if (point.getX() == lastp.getX()) {
|
||
235 | point = new Point2D.Double(point.getX() + 0.00000001, |
||
236 | point.getY()); |
||
237 | } else if (point.getY() == lastp.getY()) { |
||
238 | point = new Point2D.Double(point.getX(), |
||
239 | point.getY() + 0.00000001);
|
||
240 | } |
||
241 | 3765 | caballero | |
242 | 3782 | caballero | if (point.getX() == antantPoint.getX()) {
|
243 | point = new Point2D.Double(point.getX() + 0.00000001, |
||
244 | point.getY()); |
||
245 | } else if (point.getY() == antantPoint.getY()) { |
||
246 | point = new Point2D.Double(point.getX(), |
||
247 | point.getY() + 0.00000001);
|
||
248 | } |
||
249 | 3765 | caballero | |
250 | 3782 | caballero | if (!(list.size() > 0) || |
251 | (((IGeometry) list.get(list.size() - 1)).getGeometryType() == FShape.LINE)) {
|
||
252 | Point2D[] ps1 = UtilFunctions.getPerpendicular(antantPoint, |
||
253 | lastp, lastp); |
||
254 | Point2D mediop = new Point2D.Double((point.getX() + |
||
255 | lastp.getX()) / 2, (point.getY() + lastp.getY()) / 2); |
||
256 | Point2D[] ps2 = UtilFunctions.getPerpendicular(lastp, |
||
257 | point, mediop); |
||
258 | Point2D interp = UtilFunctions.getIntersection(ps1[0], |
||
259 | ps1[1], ps2[0], ps2[1]); |
||
260 | antInter = interp; |
||
261 | 3765 | caballero | |
262 | 3782 | caballero | double radio = interp.distance(lastp);
|
263 | 3765 | caballero | |
264 | 3782 | caballero | if (UtilFunctions.isLowAngle(antantPoint, lastp, interp,
|
265 | point)) { |
||
266 | radio = -radio; |
||
267 | } |
||
268 | 3765 | caballero | |
269 | 3782 | caballero | Point2D centerp = UtilFunctions.getPoint(interp, mediop,
|
270 | radio); |
||
271 | antCenter = centerp; |
||
272 | 3765 | caballero | |
273 | 3782 | caballero | IGeometry ig = ShapeFactory.createArc(lastp, centerp, point); |
274 | 3765 | caballero | |
275 | 3782 | caballero | if (ig != null) { |
276 | list.add(ig); |
||
277 | } |
||
278 | } else {
|
||
279 | Point2D[] ps1 = UtilFunctions.getPerpendicular(lastp, |
||
280 | antInter, lastp); |
||
281 | double a1 = UtilFunctions.getAngle(ps1[0], ps1[1]); |
||
282 | double a2 = UtilFunctions.getAngle(ps1[1], ps1[0]); |
||
283 | double angle = UtilFunctions.getAngle(antCenter, lastp);
|
||
284 | Point2D ini1 = null; |
||
285 | Point2D ini2 = null; |
||
286 | 3765 | caballero | |
287 | 3782 | caballero | if (UtilFunctions.absoluteAngleDistance(angle, a1) > UtilFunctions.absoluteAngleDistance(
|
288 | angle, a2)) { |
||
289 | ini1 = ps1[0];
|
||
290 | ini2 = ps1[1];
|
||
291 | } else {
|
||
292 | ini1 = ps1[1];
|
||
293 | ini2 = ps1[0];
|
||
294 | } |
||
295 | 3765 | caballero | |
296 | 3782 | caballero | Point2D unit = UtilFunctions.getUnitVector(ini1, ini2);
|
297 | Point2D correct = new Point2D.Double(lastp.getX() + |
||
298 | unit.getX(), lastp.getY() + unit.getY()); |
||
299 | Point2D[] ps = UtilFunctions.getPerpendicular(lastp, |
||
300 | correct, lastp); |
||
301 | Point2D mediop = new Point2D.Double((point.getX() + |
||
302 | lastp.getX()) / 2, (point.getY() + lastp.getY()) / 2); |
||
303 | Point2D[] ps2 = UtilFunctions.getPerpendicular(lastp, |
||
304 | point, mediop); |
||
305 | Point2D interp = UtilFunctions.getIntersection(ps[0], |
||
306 | ps[1], ps2[0], ps2[1]); |
||
307 | antInter = interp; |
||
308 | 3765 | caballero | |
309 | 3782 | caballero | double radio = interp.distance(lastp);
|
310 | 3765 | caballero | |
311 | 3782 | caballero | if (UtilFunctions.isLowAngle(correct, lastp, interp, point)) {
|
312 | radio = -radio; |
||
313 | } |
||
314 | 3765 | caballero | |
315 | 3782 | caballero | Point2D centerp = UtilFunctions.getPoint(interp, mediop,
|
316 | radio); |
||
317 | antCenter = centerp; |
||
318 | list.add(ShapeFactory.createArc(lastp, centerp, point)); |
||
319 | } |
||
320 | 3765 | caballero | |
321 | 3782 | caballero | antantPoint = antPoint; |
322 | antPoint = point; |
||
323 | } |
||
324 | 3765 | caballero | } |
325 | } |
||
326 | |||
327 | /**
|
||
328 | * M?todo para dibujar la lo necesario para el estado en el que nos
|
||
329 | * encontremos.
|
||
330 | *
|
||
331 | * @param g Graphics sobre el que dibujar.
|
||
332 | * @param selectedGeometries BitSet con las geometr?as seleccionadas.
|
||
333 | * @param x par?metro x del punto que se pase para dibujar.
|
||
334 | * @param y par?metro x del punto que se pase para dibujar.
|
||
335 | */
|
||
336 | 3832 | caballero | public void drawOperation(Graphics g, double x, |
337 | 3765 | caballero | double y) {
|
338 | 3883 | caballero | PolylineCADToolState actualState = ((PolylineCADToolContext)_fsm).getState(); |
339 | 3765 | caballero | String status = actualState.getName();
|
340 | |||
341 | 5945 | caballero | if (status.equals("Polyline.NextPointOrArcOrClose") || status.equals("Polyline.FirstPoint")) { |
342 | 3782 | caballero | for (int i = 0; i < list.size(); i++) { |
343 | ((IGeometry) list.get(i)).cloneGeometry().draw((Graphics2D) g,
|
||
344 | getCadToolAdapter().getMapControl().getViewPort(), |
||
345 | 3997 | fjp | CADTool.drawingSymbol); |
346 | 3782 | caballero | } |
347 | 5945 | caballero | if (antPoint!=null) |
348 | drawLine((Graphics2D) g, antPoint, new Point2D.Double(x, y)); |
||
349 | 3765 | caballero | |
350 | 3978 | caballero | } else if ((status.equals("Polyline.NextPointOrLineOrClose"))) { |
351 | 3782 | caballero | for (int i = 0; i < list.size(); i++) { |
352 | ((IGeometry) list.get(i)).cloneGeometry().draw((Graphics2D) g,
|
||
353 | getCadToolAdapter().getMapControl().getViewPort(), |
||
354 | 3997 | fjp | CADTool.drawingSymbol); |
355 | 3782 | caballero | } |
356 | 3765 | caballero | |
357 | 3782 | caballero | Point2D point = new Point2D.Double(x, y); |
358 | Point2D lastp = antPoint;
|
||
359 | 3765 | caballero | |
360 | 3782 | caballero | if (!(list.size() > 0) || |
361 | (((IGeometry) list.get(list.size() - 1)).getGeometryType() == FShape.LINE)) {
|
||
362 | if (antantPoint == null) { |
||
363 | drawArc(point, lastp, |
||
364 | new Point2D.Double(lastp.getX() + (point.getX() / 2), |
||
365 | lastp.getY() + (point.getY() / 2)), g);
|
||
366 | } else {
|
||
367 | drawArc(point, lastp, antantPoint, g); |
||
368 | } |
||
369 | } else {
|
||
370 | if (antInter != null) { |
||
371 | Point2D[] ps1 = UtilFunctions.getPerpendicular(lastp, |
||
372 | antInter, lastp); |
||
373 | double a1 = UtilFunctions.getAngle(ps1[0], ps1[1]); |
||
374 | double a2 = UtilFunctions.getAngle(ps1[1], ps1[0]); |
||
375 | double angle = UtilFunctions.getAngle(antCenter, lastp);
|
||
376 | Point2D ini1 = null; |
||
377 | Point2D ini2 = null; |
||
378 | 3765 | caballero | |
379 | 3782 | caballero | if (UtilFunctions.absoluteAngleDistance(angle, a1) > UtilFunctions.absoluteAngleDistance(
|
380 | angle, a2)) { |
||
381 | ini1 = ps1[0];
|
||
382 | ini2 = ps1[1];
|
||
383 | } else {
|
||
384 | ini1 = ps1[1];
|
||
385 | ini2 = ps1[0];
|
||
386 | } |
||
387 | 3765 | caballero | |
388 | 3782 | caballero | Point2D unit = UtilFunctions.getUnitVector(ini1, ini2);
|
389 | Point2D correct = new Point2D.Double(lastp.getX() + |
||
390 | unit.getX(), lastp.getY() + unit.getY()); |
||
391 | drawArc(point, lastp, correct, g); |
||
392 | } |
||
393 | } |
||
394 | } |
||
395 | 3765 | caballero | } |
396 | 3782 | caballero | |
397 | 3765 | caballero | /**
|
398 | 3782 | caballero | * Dibuja el arco sobre el graphics.
|
399 | *
|
||
400 | * @param point Puntero del rat?n.
|
||
401 | * @param lastp ?ltimo punto de la polilinea.
|
||
402 | * @param antp Punto antepenultimo.
|
||
403 | * @param g Graphics sobre el que se dibuja.
|
||
404 | */
|
||
405 | private void drawArc(Point2D point, Point2D lastp, Point2D antp, Graphics g) { |
||
406 | if (((point.getY() == lastp.getY()) && (point.getX() < lastp.getX())) ||
|
||
407 | ((point.getX() == lastp.getX()) && |
||
408 | (point.getY() < lastp.getY()))) { |
||
409 | } else {
|
||
410 | if (point.getX() == lastp.getX()) {
|
||
411 | point = new Point2D.Double(point.getX() + 0.00000001, |
||
412 | point.getY()); |
||
413 | } else if (point.getY() == lastp.getY()) { |
||
414 | point = new Point2D.Double(point.getX(), |
||
415 | point.getY() + 0.00000001);
|
||
416 | } |
||
417 | 3765 | caballero | |
418 | 3782 | caballero | if (point.getX() == antp.getX()) {
|
419 | point = new Point2D.Double(point.getX() + 0.00000001, |
||
420 | point.getY()); |
||
421 | } else if (point.getY() == antp.getY()) { |
||
422 | point = new Point2D.Double(point.getX(), |
||
423 | point.getY() + 0.00000001);
|
||
424 | } |
||
425 | 3765 | caballero | |
426 | 3782 | caballero | Point2D[] ps1 = UtilFunctions.getPerpendicular(lastp, antp, lastp); |
427 | Point2D mediop = new Point2D.Double((point.getX() + lastp.getX()) / 2, |
||
428 | (point.getY() + lastp.getY()) / 2);
|
||
429 | Point2D[] ps2 = UtilFunctions.getPerpendicular(lastp, point, mediop); |
||
430 | Point2D interp = UtilFunctions.getIntersection(ps1[0], ps1[1], |
||
431 | ps2[0], ps2[1]); |
||
432 | 3765 | caballero | |
433 | 3782 | caballero | double radio = interp.distance(lastp);
|
434 | 3765 | caballero | |
435 | 3782 | caballero | if (UtilFunctions.isLowAngle(antp, lastp, interp, point)) {
|
436 | radio = -radio; |
||
437 | } |
||
438 | 3765 | caballero | |
439 | 3782 | caballero | Point2D centerp = UtilFunctions.getPoint(interp, mediop, radio);
|
440 | 3765 | caballero | |
441 | 3782 | caballero | drawLine((Graphics2D) g, lastp, point);
|
442 | 3765 | caballero | |
443 | 3782 | caballero | IGeometry ig = ShapeFactory.createArc(lastp, centerp, point); |
444 | 3765 | caballero | |
445 | 3782 | caballero | if (ig != null) { |
446 | ig.draw((Graphics2D) g,
|
||
447 | getCadToolAdapter().getMapControl().getViewPort(), |
||
448 | CADTool.modifySymbol); |
||
449 | } |
||
450 | } |
||
451 | 3765 | caballero | } |
452 | |||
453 | /**
|
||
454 | * Add a diferent option.
|
||
455 | *
|
||
456 | 3782 | caballero | * @param sel DOCUMENT ME!
|
457 | 3765 | caballero | * @param s Diferent option.
|
458 | */
|
||
459 | 3832 | caballero | public void addOption(String s) { |
460 | 5395 | caballero | /* PolylineCADToolState actualState = (PolylineCADToolState) _fsm.getPreviousState();
|
461 | 3765 | caballero | String status = actualState.getName();
|
462 | 3782 | caballero | |
463 | 3978 | caballero | if (status.equals("Polyline.NextPointOrArcOrClose")) {
|
464 | 5170 | caballero | if (s.equals("A") || s.equals("a") || s.equals(PluginServices.getText(this,"inter_arc"))) {
|
465 | 3782 | caballero | //Arco
|
466 | } else if (s.equals("C") || s.equals("c")) {
|
||
467 | 5170 | caballero | GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD, 2);
|
468 | 3846 | caballero | elShape.moveTo(antPoint.getX(), antPoint.getY());
|
469 | elShape.lineTo(firstPoint.getX(), firstPoint.getY());
|
||
470 | list.add(ShapeFactory.createPolyline2D(elShape));
|
||
471 | 5170 | caballero | //closeGeometry();
|
472 | 3765 | caballero | }
|
473 | 3978 | caballero | } else if (status.equals("Polyline.NextPointOrLineOrClose")) {
|
474 | 5170 | caballero | if (s.equals("N") || s.equals("n") || s.equals(PluginServices.getText(this,"inter_line"))) {
|
475 | 3782 | caballero | //L?nea
|
476 | } else if (s.equals("C") || s.equals("c")) {
|
||
477 | 5170 | caballero | GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD, 2);
|
478 | 3846 | caballero | elShape.moveTo(antPoint.getX(), antPoint.getY());
|
479 | elShape.lineTo(firstPoint.getX(), firstPoint.getY());
|
||
480 | list.add(ShapeFactory.createPolyline2D(elShape));
|
||
481 | //closeGeometry();
|
||
482 | 3782 | caballero | }
|
483 | 3765 | caballero | }
|
484 | 5395 | caballero | */
|
485 | 3765 | caballero | } |
486 | |||
487 | /* (non-Javadoc)
|
||
488 | * @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
|
||
489 | */
|
||
490 | 3832 | caballero | public void addValue(double d) { |
491 | 3765 | caballero | } |
492 | 3883 | caballero | |
493 | public void cancel(){ |
||
494 | 5395 | caballero | //endGeometry();
|
495 | 5170 | caballero | list.clear(); |
496 | antantPoint=antCenter=antInter=antPoint=firstPoint=null;
|
||
497 | 3883 | caballero | } |
498 | 4002 | fjp | |
499 | 5170 | caballero | public void end() { |
500 | /* CADExtension.setCADTool("polyline");
|
||
501 | PluginServices.getMainFrame().setSelectedTool("POLYLINE"); */
|
||
502 | } |
||
503 | 4118 | caballero | |
504 | 5170 | caballero | public String getName() { |
505 | return PluginServices.getText(this,"polyline_"); |
||
506 | } |
||
507 | 4892 | caballero | |
508 | 5170 | caballero | public String toString() { |
509 | return "_polyline"; |
||
510 | } |
||
511 | public boolean isApplicable(int shapeType) { |
||
512 | switch (shapeType) {
|
||
513 | case FShape.POINT:
|
||
514 | 6024 | caballero | case FShape.MULTIPOINT:
|
515 | 5170 | caballero | return false; |
516 | } |
||
517 | return true; |
||
518 | } |
||
519 | 3765 | caballero | } |