root / trunk / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / tools / PolylineCADTool.java @ 5878
History | View | Annotate | Download (20.7 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 | import org.cresques.cts.GeoCalc; |
||
51 | |||
52 | 4584 | caballero | import com.iver.andami.PluginServices; |
53 | 5878 | caballero | import com.iver.cit.gvsig.fmap.core.FArc2D; |
54 | 3782 | caballero | import com.iver.cit.gvsig.fmap.core.FGeometryCollection; |
55 | 5878 | caballero | import com.iver.cit.gvsig.fmap.core.FPolyline2D; |
56 | 3782 | caballero | import com.iver.cit.gvsig.fmap.core.FShape; |
57 | import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
||
58 | 5878 | caballero | import com.iver.cit.gvsig.fmap.core.Handler; |
59 | 3782 | caballero | import com.iver.cit.gvsig.fmap.core.IGeometry; |
60 | import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
||
61 | 5747 | fjp | import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
62 | 3782 | caballero | import com.iver.cit.gvsig.fmap.edition.UtilFunctions; |
63 | 5747 | fjp | import com.iver.cit.gvsig.gui.Table; |
64 | 3782 | caballero | import com.iver.cit.gvsig.gui.cad.CADTool; |
65 | 3832 | caballero | import com.iver.cit.gvsig.gui.cad.DefaultCADTool; |
66 | 5735 | caballero | import com.iver.cit.gvsig.gui.cad.exception.CommandException; |
67 | 3782 | caballero | import com.iver.cit.gvsig.gui.cad.tools.smc.PolylineCADToolContext; |
68 | import com.iver.cit.gvsig.gui.cad.tools.smc.PolylineCADToolContext.PolylineCADToolState; |
||
69 | 5747 | fjp | import com.vividsolutions.jts.geom.Geometry; |
70 | 3782 | caballero | |
71 | |||
72 | /**
|
||
73 | * DOCUMENT ME!
|
||
74 | *
|
||
75 | * @author Vicente Caballero Navarro
|
||
76 | */
|
||
77 | 3765 | caballero | public class PolylineCADTool extends DefaultCADTool { |
78 | 5747 | fjp | private static Logger logger = Logger.getLogger(PolylineCADTool.class.getName()); |
79 | 3765 | caballero | private PolylineCADToolContext _fsm;
|
80 | private Point2D firstPoint; |
||
81 | private Point2D antPoint; |
||
82 | private Point2D antantPoint; |
||
83 | private Point2D antCenter; |
||
84 | 3782 | caballero | private Point2D antInter; |
85 | private ArrayList list = new ArrayList(); |
||
86 | 5878 | caballero | private boolean isClosed=false; |
87 | 3782 | caballero | |
88 | /**
|
||
89 | 3765 | caballero | * Crea un nuevo PolylineCADTool.
|
90 | */
|
||
91 | public PolylineCADTool() {
|
||
92 | 3883 | caballero | |
93 | 3765 | caballero | } |
94 | |||
95 | /**
|
||
96 | * M?todo de incio, para poner el c?digo de todo lo que se requiera de una
|
||
97 | * carga previa a la utilizaci?n de la herramienta.
|
||
98 | */
|
||
99 | public void init() { |
||
100 | 5170 | caballero | _fsm = new PolylineCADToolContext(this); |
101 | 3765 | caballero | } |
102 | |||
103 | 3883 | caballero | public void endGeometry() { |
104 | 5170 | caballero | IGeometry[] geoms = (IGeometry[]) list.toArray(new IGeometry[0]); |
105 | 3846 | caballero | FGeometryCollection fgc = new FGeometryCollection(geoms);
|
106 | 5878 | caballero | if (isClosed) {
|
107 | GeneralPathX gpx=new GeneralPathX();
|
||
108 | for (int i=0;i<geoms.length;i++) { |
||
109 | gpx.append(geoms[i].getPathIterator(null),true); |
||
110 | } |
||
111 | if (gpx.isCCW()) {
|
||
112 | ArrayList geomsAux=new ArrayList(); |
||
113 | for (int i=0;i<geoms.length;i++) { |
||
114 | if (geoms[i].getInternalShape() instanceof FPolyline2D) { |
||
115 | Handler[] handlers=((FPolyline2D)geoms[i]).getSelectHandlers(); |
||
116 | GeneralPathX gpxAux=new GeneralPathX();
|
||
117 | gpxAux.moveTo(handlers[1].getPoint().getX(),handlers[1].getPoint().getY()); |
||
118 | gpxAux.lineTo(handlers[0].getPoint().getX(),handlers[0].getPoint().getY()); |
||
119 | geomsAux.add(ShapeFactory.createPolyline2D(gpxAux)); |
||
120 | }else if (geoms[i].getInternalShape() instanceof FArc2D) { |
||
121 | Handler[] handlers=((FArc2D)geoms[i]).getSelectHandlers(); |
||
122 | geomsAux.add(ShapeFactory.createArc(handlers[2].getPoint(),handlers[1].getPoint(),handlers[0].getPoint())); |
||
123 | } |
||
124 | } |
||
125 | fgc = new FGeometryCollection((IGeometry[]) geomsAux.toArray(new IGeometry[0])); |
||
126 | } |
||
127 | fgc.setGeometryType(FShape.POLYGON); |
||
128 | }else {
|
||
129 | fgc.setGeometryType(FShape.LINE); |
||
130 | 5747 | fjp | } |
131 | 4892 | caballero | |
132 | 5878 | caballero | |
133 | //
|
||
134 | // GeneralPathX gpx=new GeneralPathX();
|
||
135 | // for (int i=0;i<geoms.length;i++) {
|
||
136 | // gpx.append(geoms[0].getPathIterator(null),true);
|
||
137 | // }
|
||
138 | // /* try {
|
||
139 | // if (getVLE().getVEA().getShapeType()==FShape.POLYGON){
|
||
140 | // GeneralPathX gpx=new GeneralPathX();
|
||
141 | // gpx.moveTo(antPoint.getX(),antPoint.getY());
|
||
142 | // gpx.lineTo(firstPoint.getX(),firstPoint.getY());
|
||
143 | // IGeometry line=ShapeFactory.createPolyline2D(gpx);
|
||
144 | // fgc.addGeometry(line);
|
||
145 | // }
|
||
146 | // } catch (DriverIOException e) {
|
||
147 | // e.printStackTrace();
|
||
148 | // } */
|
||
149 | //
|
||
150 | // ///IGeometry newGeom = ShapeFactory.createPolyline2D(gpx);
|
||
151 | // if (gpx.isClosed())
|
||
152 | // {
|
||
153 | // gpx.ensureOrientation(false); // Poligono exterior.
|
||
154 | // // Voy a testear que se puede convertir a JTS:
|
||
155 | // IGeometry gAux = ShapeFactory.createPolygon2D(gpx);
|
||
156 | // Geometry jtsG = gAux.toJTSGeometry();
|
||
157 | // logger.debug("A punto de escribir " + jtsG.toText());
|
||
158 | // try {
|
||
159 | // int shapeType = getVLE().getVEA().getShapeType();
|
||
160 | // if ((shapeType ==FShape.POLYGON) || (shapeType == FShape.MULTI)) {
|
||
161 | //// GeneralPathX gpx=new GeneralPathX();
|
||
162 | //// gpx.moveTo(antPoint.getX(),antPoint.getY());
|
||
163 | //// gpx.lineTo(firstPoint.getX(),firstPoint.getY());
|
||
164 | //// IGeometry line=ShapeFactory.createPolyline2D(gpx);
|
||
165 | //// fgc.addGeometry(line);
|
||
166 | // newGeom = gAux;
|
||
167 | // }
|
||
168 | // } catch (DriverIOException e) {
|
||
169 | // e.printStackTrace();
|
||
170 | // return;
|
||
171 | // }
|
||
172 | //
|
||
173 | //
|
||
174 | //
|
||
175 | //
|
||
176 | //
|
||
177 | // }
|
||
178 | |||
179 | addGeometry(fgc); |
||
180 | 3782 | caballero | _fsm = new PolylineCADToolContext(this); |
181 | 3883 | caballero | list.clear(); |
182 | antantPoint=antCenter=antInter=antPoint=firstPoint=null;
|
||
183 | 3765 | caballero | } |
184 | 3883 | caballero | public void closeGeometry(){ |
185 | 5170 | caballero | GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD,
|
186 | 2);
|
||
187 | elShape.moveTo(antPoint.getX(), antPoint.getY()); |
||
188 | elShape.lineTo(firstPoint.getX(), firstPoint.getY()); |
||
189 | 3765 | caballero | |
190 | 5170 | caballero | list.add(ShapeFactory.createPolyline2D(elShape)); |
191 | 5878 | caballero | isClosed=true;
|
192 | 5747 | fjp | |
193 | 5170 | caballero | // list.add(ShapeFactory.createPolyline2D(elShape));
|
194 | 3883 | caballero | } |
195 | 3765 | caballero | /* (non-Javadoc)
|
196 | 3782 | caballero | * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double, double)
|
197 | */
|
||
198 | 4313 | fjp | public void transition(double x, double y, InputEvent event) { |
199 | 4324 | caballero | _fsm.addPoint(x, y, event); |
200 | 3765 | caballero | } |
201 | |||
202 | /* (non-Javadoc)
|
||
203 | 3782 | caballero | * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double)
|
204 | */
|
||
205 | 3832 | caballero | public void transition(double d) { |
206 | 5735 | caballero | _fsm.addValue(d); |
207 | 3782 | caballero | } |
208 | 3765 | caballero | |
209 | 3782 | caballero | /* (non-Javadoc)
|
210 | * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, java.lang.String)
|
||
211 | */
|
||
212 | 5735 | caballero | public void transition(String s) throws CommandException { |
213 | 5170 | caballero | if (!super.changeCommand(s)){ |
214 | _fsm.addOption(s); |
||
215 | } |
||
216 | 3782 | caballero | } |
217 | |||
218 | 3765 | caballero | /**
|
219 | * Equivale al transition del prototipo pero sin pasarle como par?metro el
|
||
220 | * editableFeatureSource que ya estar? creado.
|
||
221 | *
|
||
222 | * @param sel Bitset con las geometr?as que est?n seleccionadas.
|
||
223 | * @param x par?metro x del punto que se pase en esta transici?n.
|
||
224 | * @param y par?metro y del punto que se pase en esta transici?n.
|
||
225 | */
|
||
226 | 4365 | caballero | public void addPoint(double x, double y,InputEvent event) { |
227 | 5170 | caballero | PolylineCADToolState actualState = (PolylineCADToolState) _fsm.getPreviousState(); |
228 | 3765 | caballero | String status = actualState.getName();
|
229 | 3782 | caballero | |
230 | 3978 | caballero | if (status.equals("Polyline.FirstPoint")) { |
231 | 3765 | caballero | antPoint = new Point2D.Double(x, y); |
232 | 3782 | caballero | |
233 | if (firstPoint == null) { |
||
234 | firstPoint = (Point2D) antPoint.clone();
|
||
235 | } |
||
236 | 3978 | caballero | } else if (status.equals("Polyline.NextPointOrArcOrClose")) { |
237 | 3782 | caballero | Point2D point = new Point2D.Double(x, y); |
238 | 3765 | caballero | |
239 | 3782 | caballero | if (antPoint != null) { |
240 | GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD,
|
||
241 | 2);
|
||
242 | elShape.moveTo(antPoint.getX(), antPoint.getY()); |
||
243 | elShape.lineTo(point.getX(), point.getY()); |
||
244 | 5170 | caballero | list.add(ShapeFactory.createPolyline2D(elShape)); |
245 | 3978 | caballero | |
246 | 3782 | caballero | } |
247 | 3765 | caballero | |
248 | 3782 | caballero | if (antPoint != null) { |
249 | antantPoint = antPoint; |
||
250 | } |
||
251 | 3765 | caballero | |
252 | 3782 | caballero | antPoint = point; |
253 | 3978 | caballero | } else if (status.equals("Polyline.NextPointOrLineOrClose")) { |
254 | 3782 | caballero | Point2D point = new Point2D.Double(x, y); |
255 | Point2D lastp = antPoint; //(Point2D)points.get(i-1); |
||
256 | 3765 | caballero | |
257 | 3782 | caballero | if (antantPoint == null) { |
258 | antantPoint = new Point2D.Double(lastp.getX() + |
||
259 | (point.getX() / 2), lastp.getY() + (point.getY() / 2)); |
||
260 | } |
||
261 | 3765 | caballero | |
262 | 3782 | caballero | if (((point.getY() == lastp.getY()) &&
|
263 | (point.getX() < lastp.getX())) || |
||
264 | ((point.getX() == lastp.getX()) && |
||
265 | (point.getY() < lastp.getY()))) { |
||
266 | } else {
|
||
267 | if (point.getX() == lastp.getX()) {
|
||
268 | point = new Point2D.Double(point.getX() + 0.00000001, |
||
269 | point.getY()); |
||
270 | } else if (point.getY() == lastp.getY()) { |
||
271 | point = new Point2D.Double(point.getX(), |
||
272 | point.getY() + 0.00000001);
|
||
273 | } |
||
274 | 3765 | caballero | |
275 | 3782 | caballero | if (point.getX() == antantPoint.getX()) {
|
276 | point = new Point2D.Double(point.getX() + 0.00000001, |
||
277 | point.getY()); |
||
278 | } else if (point.getY() == antantPoint.getY()) { |
||
279 | point = new Point2D.Double(point.getX(), |
||
280 | point.getY() + 0.00000001);
|
||
281 | } |
||
282 | 3765 | caballero | |
283 | 3782 | caballero | if (!(list.size() > 0) || |
284 | (((IGeometry) list.get(list.size() - 1)).getGeometryType() == FShape.LINE)) {
|
||
285 | Point2D[] ps1 = UtilFunctions.getPerpendicular(antantPoint, |
||
286 | lastp, lastp); |
||
287 | Point2D mediop = new Point2D.Double((point.getX() + |
||
288 | lastp.getX()) / 2, (point.getY() + lastp.getY()) / 2); |
||
289 | Point2D[] ps2 = UtilFunctions.getPerpendicular(lastp, |
||
290 | point, mediop); |
||
291 | Point2D interp = UtilFunctions.getIntersection(ps1[0], |
||
292 | ps1[1], ps2[0], ps2[1]); |
||
293 | antInter = interp; |
||
294 | 3765 | caballero | |
295 | 3782 | caballero | double radio = interp.distance(lastp);
|
296 | 3765 | caballero | |
297 | 3782 | caballero | if (UtilFunctions.isLowAngle(antantPoint, lastp, interp,
|
298 | point)) { |
||
299 | radio = -radio; |
||
300 | } |
||
301 | 3765 | caballero | |
302 | 3782 | caballero | Point2D centerp = UtilFunctions.getPoint(interp, mediop,
|
303 | radio); |
||
304 | antCenter = centerp; |
||
305 | 3765 | caballero | |
306 | 3782 | caballero | IGeometry ig = ShapeFactory.createArc(lastp, centerp, point); |
307 | 3765 | caballero | |
308 | 3782 | caballero | if (ig != null) { |
309 | list.add(ig); |
||
310 | } |
||
311 | } else {
|
||
312 | Point2D[] ps1 = UtilFunctions.getPerpendicular(lastp, |
||
313 | antInter, lastp); |
||
314 | double a1 = UtilFunctions.getAngle(ps1[0], ps1[1]); |
||
315 | double a2 = UtilFunctions.getAngle(ps1[1], ps1[0]); |
||
316 | double angle = UtilFunctions.getAngle(antCenter, lastp);
|
||
317 | Point2D ini1 = null; |
||
318 | Point2D ini2 = null; |
||
319 | 3765 | caballero | |
320 | 3782 | caballero | if (UtilFunctions.absoluteAngleDistance(angle, a1) > UtilFunctions.absoluteAngleDistance(
|
321 | angle, a2)) { |
||
322 | ini1 = ps1[0];
|
||
323 | ini2 = ps1[1];
|
||
324 | } else {
|
||
325 | ini1 = ps1[1];
|
||
326 | ini2 = ps1[0];
|
||
327 | } |
||
328 | 3765 | caballero | |
329 | 3782 | caballero | Point2D unit = UtilFunctions.getUnitVector(ini1, ini2);
|
330 | Point2D correct = new Point2D.Double(lastp.getX() + |
||
331 | unit.getX(), lastp.getY() + unit.getY()); |
||
332 | Point2D[] ps = UtilFunctions.getPerpendicular(lastp, |
||
333 | correct, lastp); |
||
334 | Point2D mediop = new Point2D.Double((point.getX() + |
||
335 | lastp.getX()) / 2, (point.getY() + lastp.getY()) / 2); |
||
336 | Point2D[] ps2 = UtilFunctions.getPerpendicular(lastp, |
||
337 | point, mediop); |
||
338 | Point2D interp = UtilFunctions.getIntersection(ps[0], |
||
339 | ps[1], ps2[0], ps2[1]); |
||
340 | antInter = interp; |
||
341 | 3765 | caballero | |
342 | 3782 | caballero | double radio = interp.distance(lastp);
|
343 | 3765 | caballero | |
344 | 3782 | caballero | if (UtilFunctions.isLowAngle(correct, lastp, interp, point)) {
|
345 | radio = -radio; |
||
346 | } |
||
347 | 3765 | caballero | |
348 | 3782 | caballero | Point2D centerp = UtilFunctions.getPoint(interp, mediop,
|
349 | radio); |
||
350 | antCenter = centerp; |
||
351 | list.add(ShapeFactory.createArc(lastp, centerp, point)); |
||
352 | } |
||
353 | 3765 | caballero | |
354 | 3782 | caballero | antantPoint = antPoint; |
355 | antPoint = point; |
||
356 | } |
||
357 | 3765 | caballero | } |
358 | } |
||
359 | |||
360 | /**
|
||
361 | * M?todo para dibujar la lo necesario para el estado en el que nos
|
||
362 | * encontremos.
|
||
363 | *
|
||
364 | * @param g Graphics sobre el que dibujar.
|
||
365 | * @param selectedGeometries BitSet con las geometr?as seleccionadas.
|
||
366 | * @param x par?metro x del punto que se pase para dibujar.
|
||
367 | * @param y par?metro x del punto que se pase para dibujar.
|
||
368 | */
|
||
369 | 3832 | caballero | public void drawOperation(Graphics g, double x, |
370 | 3765 | caballero | double y) {
|
371 | 3883 | caballero | PolylineCADToolState actualState = ((PolylineCADToolContext)_fsm).getState(); |
372 | 3765 | caballero | String status = actualState.getName();
|
373 | |||
374 | 3978 | caballero | if (status.equals("Polyline.NextPointOrArcOrClose")) { |
375 | 3782 | caballero | for (int i = 0; i < list.size(); i++) { |
376 | ((IGeometry) list.get(i)).cloneGeometry().draw((Graphics2D) g,
|
||
377 | getCadToolAdapter().getMapControl().getViewPort(), |
||
378 | 3997 | fjp | CADTool.drawingSymbol); |
379 | 3782 | caballero | } |
380 | 3765 | caballero | |
381 | 3782 | caballero | drawLine((Graphics2D) g, antPoint, new Point2D.Double(x, y)); |
382 | 3978 | caballero | } else if ((status.equals("Polyline.NextPointOrLineOrClose"))) { |
383 | 3782 | caballero | for (int i = 0; i < list.size(); i++) { |
384 | ((IGeometry) list.get(i)).cloneGeometry().draw((Graphics2D) g,
|
||
385 | getCadToolAdapter().getMapControl().getViewPort(), |
||
386 | 3997 | fjp | CADTool.drawingSymbol); |
387 | 3782 | caballero | } |
388 | 3765 | caballero | |
389 | 3782 | caballero | Point2D point = new Point2D.Double(x, y); |
390 | Point2D lastp = antPoint;
|
||
391 | 3765 | caballero | |
392 | 3782 | caballero | if (!(list.size() > 0) || |
393 | (((IGeometry) list.get(list.size() - 1)).getGeometryType() == FShape.LINE)) {
|
||
394 | if (antantPoint == null) { |
||
395 | drawArc(point, lastp, |
||
396 | new Point2D.Double(lastp.getX() + (point.getX() / 2), |
||
397 | lastp.getY() + (point.getY() / 2)), g);
|
||
398 | } else {
|
||
399 | drawArc(point, lastp, antantPoint, g); |
||
400 | } |
||
401 | } else {
|
||
402 | if (antInter != null) { |
||
403 | Point2D[] ps1 = UtilFunctions.getPerpendicular(lastp, |
||
404 | antInter, lastp); |
||
405 | double a1 = UtilFunctions.getAngle(ps1[0], ps1[1]); |
||
406 | double a2 = UtilFunctions.getAngle(ps1[1], ps1[0]); |
||
407 | double angle = UtilFunctions.getAngle(antCenter, lastp);
|
||
408 | Point2D ini1 = null; |
||
409 | Point2D ini2 = null; |
||
410 | 3765 | caballero | |
411 | 3782 | caballero | if (UtilFunctions.absoluteAngleDistance(angle, a1) > UtilFunctions.absoluteAngleDistance(
|
412 | angle, a2)) { |
||
413 | ini1 = ps1[0];
|
||
414 | ini2 = ps1[1];
|
||
415 | } else {
|
||
416 | ini1 = ps1[1];
|
||
417 | ini2 = ps1[0];
|
||
418 | } |
||
419 | 3765 | caballero | |
420 | 3782 | caballero | Point2D unit = UtilFunctions.getUnitVector(ini1, ini2);
|
421 | Point2D correct = new Point2D.Double(lastp.getX() + |
||
422 | unit.getX(), lastp.getY() + unit.getY()); |
||
423 | drawArc(point, lastp, correct, g); |
||
424 | } |
||
425 | } |
||
426 | } |
||
427 | 3765 | caballero | } |
428 | 3782 | caballero | |
429 | 3765 | caballero | /**
|
430 | 3782 | caballero | * Dibuja el arco sobre el graphics.
|
431 | *
|
||
432 | * @param point Puntero del rat?n.
|
||
433 | * @param lastp ?ltimo punto de la polilinea.
|
||
434 | * @param antp Punto antepenultimo.
|
||
435 | * @param g Graphics sobre el que se dibuja.
|
||
436 | */
|
||
437 | private void drawArc(Point2D point, Point2D lastp, Point2D antp, Graphics g) { |
||
438 | if (((point.getY() == lastp.getY()) && (point.getX() < lastp.getX())) ||
|
||
439 | ((point.getX() == lastp.getX()) && |
||
440 | (point.getY() < lastp.getY()))) { |
||
441 | } else {
|
||
442 | if (point.getX() == lastp.getX()) {
|
||
443 | point = new Point2D.Double(point.getX() + 0.00000001, |
||
444 | point.getY()); |
||
445 | } else if (point.getY() == lastp.getY()) { |
||
446 | point = new Point2D.Double(point.getX(), |
||
447 | point.getY() + 0.00000001);
|
||
448 | } |
||
449 | 3765 | caballero | |
450 | 3782 | caballero | if (point.getX() == antp.getX()) {
|
451 | point = new Point2D.Double(point.getX() + 0.00000001, |
||
452 | point.getY()); |
||
453 | } else if (point.getY() == antp.getY()) { |
||
454 | point = new Point2D.Double(point.getX(), |
||
455 | point.getY() + 0.00000001);
|
||
456 | } |
||
457 | 3765 | caballero | |
458 | 3782 | caballero | Point2D[] ps1 = UtilFunctions.getPerpendicular(lastp, antp, lastp); |
459 | Point2D mediop = new Point2D.Double((point.getX() + lastp.getX()) / 2, |
||
460 | (point.getY() + lastp.getY()) / 2);
|
||
461 | Point2D[] ps2 = UtilFunctions.getPerpendicular(lastp, point, mediop); |
||
462 | Point2D interp = UtilFunctions.getIntersection(ps1[0], ps1[1], |
||
463 | ps2[0], ps2[1]); |
||
464 | 3765 | caballero | |
465 | 3782 | caballero | double radio = interp.distance(lastp);
|
466 | 3765 | caballero | |
467 | 3782 | caballero | if (UtilFunctions.isLowAngle(antp, lastp, interp, point)) {
|
468 | radio = -radio; |
||
469 | } |
||
470 | 3765 | caballero | |
471 | 3782 | caballero | Point2D centerp = UtilFunctions.getPoint(interp, mediop, radio);
|
472 | 3765 | caballero | |
473 | 3782 | caballero | drawLine((Graphics2D) g, lastp, point);
|
474 | 3765 | caballero | |
475 | 3782 | caballero | IGeometry ig = ShapeFactory.createArc(lastp, centerp, point); |
476 | 3765 | caballero | |
477 | 3782 | caballero | if (ig != null) { |
478 | ig.draw((Graphics2D) g,
|
||
479 | getCadToolAdapter().getMapControl().getViewPort(), |
||
480 | CADTool.modifySymbol); |
||
481 | } |
||
482 | } |
||
483 | 3765 | caballero | } |
484 | |||
485 | /**
|
||
486 | * Add a diferent option.
|
||
487 | *
|
||
488 | 3782 | caballero | * @param sel DOCUMENT ME!
|
489 | 3765 | caballero | * @param s Diferent option.
|
490 | */
|
||
491 | 3832 | caballero | public void addOption(String s) { |
492 | 5395 | caballero | /* PolylineCADToolState actualState = (PolylineCADToolState) _fsm.getPreviousState();
|
493 | 3765 | caballero | String status = actualState.getName();
|
494 | 3782 | caballero | |
495 | 3978 | caballero | if (status.equals("Polyline.NextPointOrArcOrClose")) {
|
496 | 5170 | caballero | if (s.equals("A") || s.equals("a") || s.equals(PluginServices.getText(this,"inter_arc"))) {
|
497 | 3782 | caballero | //Arco
|
498 | } else if (s.equals("C") || s.equals("c")) {
|
||
499 | 5170 | caballero | GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD, 2);
|
500 | 3846 | caballero | elShape.moveTo(antPoint.getX(), antPoint.getY());
|
501 | elShape.lineTo(firstPoint.getX(), firstPoint.getY());
|
||
502 | list.add(ShapeFactory.createPolyline2D(elShape));
|
||
503 | 5170 | caballero | //closeGeometry();
|
504 | 3765 | caballero | }
|
505 | 3978 | caballero | } else if (status.equals("Polyline.NextPointOrLineOrClose")) {
|
506 | 5170 | caballero | if (s.equals("N") || s.equals("n") || s.equals(PluginServices.getText(this,"inter_line"))) {
|
507 | 3782 | caballero | //L?nea
|
508 | } else if (s.equals("C") || s.equals("c")) {
|
||
509 | 5170 | caballero | GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD, 2);
|
510 | 3846 | caballero | elShape.moveTo(antPoint.getX(), antPoint.getY());
|
511 | elShape.lineTo(firstPoint.getX(), firstPoint.getY());
|
||
512 | list.add(ShapeFactory.createPolyline2D(elShape));
|
||
513 | //closeGeometry();
|
||
514 | 3782 | caballero | }
|
515 | 3765 | caballero | }
|
516 | 5395 | caballero | */
|
517 | 3765 | caballero | } |
518 | |||
519 | /* (non-Javadoc)
|
||
520 | * @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
|
||
521 | */
|
||
522 | 3832 | caballero | public void addValue(double d) { |
523 | 3765 | caballero | } |
524 | 3883 | caballero | |
525 | public void cancel(){ |
||
526 | 5395 | caballero | //endGeometry();
|
527 | 5170 | caballero | list.clear(); |
528 | antantPoint=antCenter=antInter=antPoint=firstPoint=null;
|
||
529 | 3883 | caballero | } |
530 | 4002 | fjp | |
531 | 5170 | caballero | public void end() { |
532 | /* CADExtension.setCADTool("polyline");
|
||
533 | PluginServices.getMainFrame().setSelectedTool("POLYLINE"); */
|
||
534 | } |
||
535 | 4118 | caballero | |
536 | 5170 | caballero | public String getName() { |
537 | return PluginServices.getText(this,"polyline_"); |
||
538 | } |
||
539 | 4892 | caballero | |
540 | 5170 | caballero | public String toString() { |
541 | return "_polyline"; |
||
542 | } |
||
543 | public boolean isApplicable(int shapeType) { |
||
544 | switch (shapeType) {
|
||
545 | case FShape.POINT:
|
||
546 | return false; |
||
547 | } |
||
548 | return true; |
||
549 | } |
||
550 | 3765 | caballero | } |