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