Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / gui / cad / tools / PolylineCADTool.java @ 39280

History | View | Annotate | Download (23 KB)

1 37138 cordinyana
/* gvSIG. Geographic Information System of the Valencian Government
2 3765 caballero
 *
3 37138 cordinyana
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6 3765 caballero
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10 37138 cordinyana
 *
11 3765 caballero
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15 37138 cordinyana
 *
16 3765 caballero
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18 37138 cordinyana
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21 3765 caballero
 */
22 29616 jpiera
package org.gvsig.editing.gui.cad.tools;
23 3782 caballero
24 4313 fjp
import java.awt.event.InputEvent;
25 17984 vcaballero
import java.awt.event.MouseEvent;
26 3832 caballero
import java.awt.geom.Point2D;
27
import java.util.ArrayList;
28 39280 jldominguez
import java.util.List;
29 3832 caballero
30 39084 jldominguez
import javax.swing.JOptionPane;
31
32 39280 jldominguez
import org.slf4j.Logger;
33
import org.slf4j.LoggerFactory;
34
35 29616 jpiera
import org.gvsig.andami.PluginServices;
36 39084 jldominguez
import org.gvsig.app.ApplicationLocator;
37 29616 jpiera
import org.gvsig.editing.gui.cad.exception.CommandException;
38
import org.gvsig.editing.gui.cad.tools.smc.PolylineCADToolContext;
39
import org.gvsig.editing.gui.cad.tools.smc.PolylineCADToolContext.PolylineCADToolState;
40 24500 jmvivo
import org.gvsig.fmap.dal.exception.ReadException;
41 21668 vcaballero
import org.gvsig.fmap.geom.Geometry;
42 39280 jldominguez
import org.gvsig.fmap.geom.exception.CreateGeometryException;
43 21668 vcaballero
import org.gvsig.fmap.geom.handler.Handler;
44 30335 jpiera
import org.gvsig.fmap.geom.primitive.Curve;
45 21668 vcaballero
import org.gvsig.fmap.geom.primitive.GeneralPathX;
46 39280 jldominguez
import org.gvsig.fmap.geom.primitive.Point;
47
import org.gvsig.fmap.geom.primitive.Surface;
48 21668 vcaballero
import org.gvsig.fmap.geom.util.UtilFunctions;
49 22986 vcaballero
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
50 30335 jpiera
import org.gvsig.fmap.mapcontrol.MapControlDrawer;
51 39084 jldominguez
import org.gvsig.i18n.Messages;
52 21668 vcaballero
53 3782 caballero
/**
54
 * DOCUMENT ME!
55 37138 cordinyana
 *
56 3782 caballero
 * @author Vicente Caballero Navarro
57
 */
58 37328 cordinyana
public class PolylineCADTool extends AbstractCurveSurfaceCADTool {
59 27270 vcaballero
60 39280 jldominguez
    private static final Logger LOG = LoggerFactory.getLogger(PolylineCADTool.class);
61
62 37138 cordinyana
    protected PolylineCADToolContext _fsm;
63
    protected Point2D firstPoint;
64
    protected Point2D antPoint;
65
    protected Point2D antantPoint;
66
    protected Point2D antCenter;
67
    protected Point2D antInter;
68 39280 jldominguez
    protected List<Curve> list = new ArrayList<Curve>();
69 37138 cordinyana
    protected boolean close = false;
70
71 3782 caballero
    /**
72 3765 caballero
     * M?todo de incio, para poner el c?digo de todo lo que se requiera de una
73
     * carga previa a la utilizaci?n de la herramienta.
74
     */
75
    public void init() {
76 5170 caballero
        _fsm = new PolylineCADToolContext(this);
77 3765 caballero
    }
78 37138 cordinyana
79 21668 vcaballero
    public Geometry getGeometry() {
80 39280 jldominguez
        Geometry newGeom = null;
81
        newGeom = concatenateCurves(list, false);
82 37138 cordinyana
        return newGeom;
83
    }
84
85 39280 jldominguez
86
87 13561 caballero
    public int getLinesCount() {
88 37138 cordinyana
        return list.size();
89 13561 caballero
    }
90 37138 cordinyana
91
    public boolean isPolygonLayer() {
92
        try {
93
            return (((FLyrVect) getVLE().getLayer()).getShapeType() == Geometry.TYPES.SURFACE);
94
        } catch (ReadException e) {
95
            return false;
96
        }
97 17619 vcaballero
    }
98 37138 cordinyana
99 3883 caballero
    public void endGeometry() {
100 39280 jldominguez
101
        /*
102 37138 cordinyana
        if (gpx == null) {
103
            gpx = new GeneralPathX();
104
            Geometry[] geoms = (Geometry[]) list.toArray(new Geometry[0]);
105
            MultiPrimitive fgc = createMultiPrimitive(geoms);
106
            // No queremos guardar FGeometryCollections:
107
            gpx.append(fgc.getPathIterator(null, geomManager.getFlatness()),
108
                true);
109
        }
110 39280 jldominguez

111 10427 caballero
        try {
112 37138 cordinyana
            if (((FLyrVect) getVLE().getLayer()).getShapeType() == Geometry.TYPES.SURFACE
113
                && !close) {
114
                closeGeometry();
115
            }
116
        } catch (ReadException e) {
117
            NotificationManager.addError(e.getMessage(), e);
118
        }
119 39280 jldominguez
        */
120
121 5880 fjp
122 21668 vcaballero
        Geometry newGeom = null;
123 35619 jpiera
        int type = getCadToolAdapter().getActiveLayerType();
124 39280 jldominguez
125 37138 cordinyana
        if ((type == Geometry.TYPES.SURFACE)
126
            || (type == Geometry.TYPES.MULTISURFACE)) {
127 39280 jldominguez
128
            newGeom = concatenateCurves(list, true);
129
            closeSurfaceIfNecessary((Surface) newGeom);
130
            // newGeom = createSurface(gpx);
131 37138 cordinyana
        } else {
132 39280 jldominguez
            newGeom = concatenateCurves(list, false);
133
            // newGeom = createCurve(gpx);
134 12297 caballero
        }
135 27270 vcaballero
        insertAndSelectGeometry(newGeom);
136 3782 caballero
        _fsm = new PolylineCADToolContext(this);
137 3883 caballero
        list.clear();
138 13561 caballero
        clearTemporalCache();
139 37138 cordinyana
        close = false;
140
        antantPoint = antCenter = antInter = antPoint = firstPoint = null;
141 3765 caballero
    }
142 37138 cordinyana
143 39280 jldominguez
    /**
144
     * @param newGeom
145
     */
146
    private void closeSurfaceIfNecessary(Surface geo) {
147
148
        if (!close && geo != null && geo.getNumVertices() > 1) {
149
            Point firstp = geo.getVertex(0);
150
            firstp = (Point) firstp.cloneGeometry();
151
            geo.addVertex(firstp);
152
        }
153
        // TODO Auto-generated method stub
154
155
    }
156
157 37138 cordinyana
    public void closeGeometry() {
158 39280 jldominguez
159
        int ng = list.size();
160
        if (ng > 0) {
161
            Curve firstcurve = list.get(0);
162
            Curve lastcurve = list.get(ng - 1);
163
            Point firstp = firstcurve.getVertex(0);
164
            firstp = (Point) firstp.cloneGeometry();
165
            lastcurve.addVertex(firstp);
166 37138 cordinyana
        }
167
        close = true;
168 3883 caballero
    }
169 37138 cordinyana
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 3832 caballero
    public void transition(double d) {
175 5735 caballero
        _fsm.addValue(d);
176 3782 caballero
    }
177 3765 caballero
178 5735 caballero
    public void transition(String s) throws CommandException {
179 37138 cordinyana
        if (!super.changeCommand(s)) {
180 5170 caballero
            _fsm.addOption(s);
181
        }
182 3782 caballero
    }
183
184 3765 caballero
    /**
185
     * Equivale al transition del prototipo pero sin pasarle como par?metro el
186
     * editableFeatureSource que ya estar? creado.
187 37138 cordinyana
     *
188
     * @param sel
189
     *            Bitset con las geometr?as que est?n seleccionadas.
190
     * @param x
191
     *            par?metro x del punto que se pase en esta transici?n.
192
     * @param y
193
     *            par?metro y del punto que se pase en esta transici?n.
194 3765 caballero
     */
195 37138 cordinyana
    public void addPoint(double x, double y, InputEvent event) {
196
        PolylineCADToolState actualState =
197
            (PolylineCADToolState) _fsm.getPreviousState();
198 3765 caballero
        String status = actualState.getName();
199 37138 cordinyana
        if (status.equals("Polyline.NextPointOrArcOrClose")
200
            || status.equals("Polyline.FirstPoint")) {
201 6071 caballero
202 37138 cordinyana
            if (firstPoint == null) {
203
                firstPoint = new Point2D.Double(x, y);
204
            }
205
            Point2D point = new Point2D.Double(x, y);
206 3782 caballero
207 37138 cordinyana
            if (antPoint != null
208
                && (antPoint.getX() != point.getX() || antPoint.getY() != point
209
                    .getY())) {
210
                GeneralPathX elShape =
211
                    new GeneralPathX(GeneralPathX.WIND_EVEN_ODD, 2);
212 3782 caballero
                elShape.moveTo(antPoint.getX(), antPoint.getY());
213
                elShape.lineTo(point.getX(), point.getY());
214 39280 jldominguez
                Curve geom = createCurve(elShape);
215 39063 jldominguez
                if (geom != null) {
216
                    list.add(geom);
217
                    addTemporalCache(geom);
218
                }
219 3782 caballero
            }
220 37138 cordinyana
            if (antPoint == null)
221
                antPoint = (Point2D) firstPoint.clone();
222 3765 caballero
223 3782 caballero
            if (antPoint != null) {
224
                antantPoint = antPoint;
225
            }
226 3765 caballero
227 3782 caballero
            antPoint = point;
228 37138 cordinyana
        } else
229
            if (status.equals("Polyline.NextPointOrLineOrClose")) {
230
                Point2D point = new Point2D.Double(x, y);
231
                Point2D lastp = antPoint; // (Point2D)points.get(i-1);
232 3765 caballero
233 37138 cordinyana
                if (antantPoint == null) {
234
                    antantPoint =
235
                        new Point2D.Double(lastp.getX() + (point.getX() / 2),
236
                            lastp.getY() + (point.getY() / 2));
237 3782 caballero
                }
238 3765 caballero
239 37138 cordinyana
                if (((point.getY() == lastp.getY()) && (point.getX() < lastp
240
                    .getX()))
241
                    || ((point.getX() == lastp.getX()) && (point.getY() < lastp
242
                        .getY()))) {
243
                } else {
244
                    if (point.getX() == lastp.getX()) {
245
                        point =
246
                            new Point2D.Double(point.getX() + 0.00000001,
247
                                point.getY());
248
                    } else
249
                        if (point.getY() == lastp.getY()) {
250
                            point =
251
                                new Point2D.Double(point.getX(),
252
                                    point.getY() + 0.00000001);
253
                        }
254 3765 caballero
255 37138 cordinyana
                    if (point.getX() == antantPoint.getX()) {
256
                        point =
257
                            new Point2D.Double(point.getX() + 0.00000001,
258
                                point.getY());
259
                    } else
260
                        if (point.getY() == antantPoint.getY()) {
261
                            point =
262
                                new Point2D.Double(point.getX(),
263
                                    point.getY() + 0.00000001);
264
                        }
265 3765 caballero
266 37138 cordinyana
                    if (!(list.size() > 0)
267
                        || (((Geometry) list.get(list.size() - 1)).getType() == Geometry.TYPES.CURVE)) {
268
                        Point2D[] ps1 =
269
                            UtilFunctions.getPerpendicular(antantPoint, lastp,
270
                                lastp);
271
                        Point2D mediop =
272
                            new Point2D.Double(
273
                                (point.getX() + lastp.getX()) / 2,
274
                                (point.getY() + lastp.getY()) / 2);
275
                        Point2D[] ps2 =
276
                            UtilFunctions
277
                                .getPerpendicular(lastp, point, mediop);
278
                        Point2D interp =
279
                            UtilFunctions.getIntersection(ps1[0], ps1[1],
280
                                ps2[0], ps2[1]);
281
                        antInter = interp;
282 3765 caballero
283 37138 cordinyana
                        double radio = interp.distance(lastp);
284 3765 caballero
285 37138 cordinyana
                        if (UtilFunctions.isLowAngle(antantPoint, lastp,
286
                            interp, point)) {
287
                            radio = -radio;
288
                        }
289 3765 caballero
290 37138 cordinyana
                        Point2D centerp =
291
                            UtilFunctions.getPoint(interp, mediop, radio);
292
                        antCenter = centerp;
293 3765 caballero
294 39280 jldominguez
                        Curve ig = createArc(lastp, centerp, point);
295 3765 caballero
296 37138 cordinyana
                        if (ig != null) {
297
                            list.add(ig);
298
                            addTemporalCache(ig);
299 39084 jldominguez
                        } else {
300
301
                            ApplicationLocator.getManager().message(
302
                                Messages.getText("_Unable_to_create_arc"),
303
                                JOptionPane.ERROR_MESSAGE);
304
305 37138 cordinyana
                        }
306 3782 caballero
                    } else {
307 37138 cordinyana
                        Point2D[] ps1 =
308
                            UtilFunctions.getPerpendicular(lastp, antInter,
309
                                lastp);
310
                        double a1 = UtilFunctions.getAngle(ps1[0], ps1[1]);
311
                        double a2 = UtilFunctions.getAngle(ps1[1], ps1[0]);
312
                        double angle = UtilFunctions.getAngle(antCenter, lastp);
313
                        Point2D ini1 = null;
314
                        Point2D ini2 = null;
315 3765 caballero
316 37138 cordinyana
                        if (UtilFunctions.absoluteAngleDistance(angle, a1) > UtilFunctions
317
                            .absoluteAngleDistance(angle, a2)) {
318
                            ini1 = ps1[0];
319
                            ini2 = ps1[1];
320
                        } else {
321
                            ini1 = ps1[1];
322
                            ini2 = ps1[0];
323
                        }
324 3765 caballero
325 37138 cordinyana
                        Point2D unit = UtilFunctions.getUnitVector(ini1, ini2);
326
                        Point2D correct =
327
                            new Point2D.Double(lastp.getX() + unit.getX(),
328
                                lastp.getY() + unit.getY());
329
                        Point2D[] ps =
330
                            UtilFunctions.getPerpendicular(lastp, correct,
331
                                lastp);
332
                        Point2D mediop =
333
                            new Point2D.Double(
334
                                (point.getX() + lastp.getX()) / 2,
335
                                (point.getY() + lastp.getY()) / 2);
336
                        Point2D[] ps2 =
337
                            UtilFunctions
338
                                .getPerpendicular(lastp, point, mediop);
339
                        Point2D interp =
340
                            UtilFunctions.getIntersection(ps[0], ps[1], ps2[0],
341
                                ps2[1]);
342
                        antInter = interp;
343 3765 caballero
344 37138 cordinyana
                        double radio = interp.distance(lastp);
345
346
                        if (UtilFunctions.isLowAngle(correct, lastp, interp,
347
                            point)) {
348
                            radio = -radio;
349
                        }
350
351
                        Point2D centerp =
352
                            UtilFunctions.getPoint(interp, mediop, radio);
353
                        antCenter = centerp;
354 39280 jldominguez
                        Curve geom = createArc(lastp, centerp, point);
355 39063 jldominguez
356
                        if (geom != null) {
357
                            list.add(geom);
358
                            addTemporalCache(geom);
359
                        }
360 3782 caballero
                    }
361 3765 caballero
362 37138 cordinyana
                    antantPoint = antPoint;
363
                    antPoint = point;
364 3782 caballero
                }
365
            }
366 3765 caballero
    }
367
368
    /**
369
     * M?todo para dibujar la lo necesario para el estado en el que nos
370
     * encontremos.
371 37138 cordinyana
     *
372
     * @param g
373
     *            Graphics sobre el que dibujar.
374
     * @param selectedGeometries
375
     *            BitSet con las geometr?as seleccionadas.
376
     * @param x
377
     *            par?metro x del punto que se pase para dibujar.
378
     * @param y
379
     *            par?metro x del punto que se pase para dibujar.
380 3765 caballero
     */
381 37138 cordinyana
    public void drawOperation(MapControlDrawer renderer, double x, double y) {
382 10427 caballero
        PolylineCADToolState actualState = _fsm.getState();
383 3765 caballero
        String status = actualState.getName();
384
385 37138 cordinyana
        if (status.equals("Polyline.NextPointOrArcOrClose")
386
            || status.equals("Polyline.FirstPoint")) {
387 3782 caballero
            for (int i = 0; i < list.size(); i++) {
388 37138 cordinyana
                renderer.draw((Geometry) list.get(i),
389
                    mapControlManager.getGeometrySelectionSymbol());
390 3782 caballero
            }
391 37138 cordinyana
            if (antPoint != null)
392
                renderer.drawLine(antPoint, new Point2D.Double(x, y),
393
                    mapControlManager.getGeometrySelectionSymbol());
394 3765 caballero
395 37138 cordinyana
        } else
396
            if ((status.equals("Polyline.NextPointOrLineOrClose"))) {
397
                for (int i = 0; i < list.size(); i++) {
398
                    renderer.draw((Geometry) list.get(i),
399
                        mapControlManager.getGeometrySelectionSymbol());
400
                }
401 3765 caballero
402 37138 cordinyana
                Point2D point = new Point2D.Double(x, y);
403
                Point2D lastp = antPoint;
404 3765 caballero
405 37138 cordinyana
                if (!(list.size() > 0)
406
                    || (((Geometry) list.get(list.size() - 1)).getType() == Geometry.TYPES.CURVE)) {
407
                    if (antantPoint == null) {
408
                        drawArc(point, lastp, new Point2D.Double(lastp.getX()
409
                            + (point.getX() / 2), lastp.getY()
410
                            + (point.getY() / 2)), renderer);
411
                    } else {
412
                        drawArc(point, lastp, antantPoint, renderer);
413
                    }
414 3782 caballero
                } else {
415 37138 cordinyana
                    if (antInter != null) {
416
                        Point2D[] ps1 =
417
                            UtilFunctions.getPerpendicular(lastp, antInter,
418
                                lastp);
419
                        double a1 = UtilFunctions.getAngle(ps1[0], ps1[1]);
420
                        double a2 = UtilFunctions.getAngle(ps1[1], ps1[0]);
421
                        double angle = UtilFunctions.getAngle(antCenter, lastp);
422
                        Point2D ini1 = null;
423
                        Point2D ini2 = null;
424 3765 caballero
425 37138 cordinyana
                        if (UtilFunctions.absoluteAngleDistance(angle, a1) > UtilFunctions
426
                            .absoluteAngleDistance(angle, a2)) {
427
                            ini1 = ps1[0];
428
                            ini2 = ps1[1];
429
                        } else {
430
                            ini1 = ps1[1];
431
                            ini2 = ps1[0];
432
                        }
433
434
                        Point2D unit = UtilFunctions.getUnitVector(ini1, ini2);
435
                        Point2D correct =
436
                            new Point2D.Double(lastp.getX() + unit.getX(),
437
                                lastp.getY() + unit.getY());
438
                        drawArc(point, lastp, correct, renderer);
439 3782 caballero
                    }
440
                }
441
            }
442 37138 cordinyana
        try {
443
            if (((FLyrVect) getVLE().getLayer()).getShapeType() == Geometry.TYPES.SURFACE
444
                && !list.isEmpty()) {
445
                Handler handler1 =
446
                    ((Geometry) list.get(0))
447
                        .getHandlers(Geometry.SELECTHANDLER)[0];
448
                GeneralPathX gpx = new GeneralPathX();
449
                gpx.moveTo(x, y);
450
                Point2D p1 = handler1.getPoint();
451
                gpx.lineTo(p1.getX(), p1.getY());
452
                Curve curve = createCurve(gpx);
453
                renderer.draw(curve,
454
                    mapControlManager.getGeometrySelectionSymbol());
455
            }
456
        } catch (ReadException e) {
457
            e.printStackTrace();
458 3782 caballero
        }
459 3765 caballero
    }
460 3782 caballero
461 3765 caballero
    /**
462 3782 caballero
     * Dibuja el arco sobre el graphics.
463 37138 cordinyana
     *
464
     * @param point
465
     *            Puntero del rat?n.
466
     * @param lastp
467
     *            ?ltimo punto de la polilinea.
468
     * @param antp
469
     *            Punto antepenultimo.
470
     * @param g
471
     *            Graphics sobre el que se dibuja.
472 3782 caballero
     */
473 37138 cordinyana
    private void drawArc(Point2D point, Point2D lastp, Point2D antp,
474
        MapControlDrawer renderer) {
475
        if (((point.getY() == lastp.getY()) && (point.getX() < lastp.getX()))
476
            || ((point.getX() == lastp.getX()) && (point.getY() < lastp.getY()))) {
477 3782 caballero
        } else {
478
            if (point.getX() == lastp.getX()) {
479 37138 cordinyana
                point =
480
                    new Point2D.Double(point.getX() + 0.00000001, point.getY());
481
            } else
482
                if (point.getY() == lastp.getY()) {
483
                    point =
484
                        new Point2D.Double(point.getX(),
485
                            point.getY() + 0.00000001);
486
                }
487 3765 caballero
488 3782 caballero
            if (point.getX() == antp.getX()) {
489 37138 cordinyana
                point =
490
                    new Point2D.Double(point.getX() + 0.00000001, point.getY());
491
            } else
492
                if (point.getY() == antp.getY()) {
493
                    point =
494
                        new Point2D.Double(point.getX(),
495
                            point.getY() + 0.00000001);
496
                }
497 3765 caballero
498 3782 caballero
            Point2D[] ps1 = UtilFunctions.getPerpendicular(lastp, antp, lastp);
499 37138 cordinyana
            Point2D mediop =
500
                new Point2D.Double((point.getX() + lastp.getX()) / 2,
501 3782 caballero
                    (point.getY() + lastp.getY()) / 2);
502 37138 cordinyana
            Point2D[] ps2 =
503
                UtilFunctions.getPerpendicular(lastp, point, mediop);
504
            Point2D interp =
505
                UtilFunctions.getIntersection(ps1[0], ps1[1], ps2[0], ps2[1]);
506 3765 caballero
507 3782 caballero
            double radio = interp.distance(lastp);
508 3765 caballero
509 3782 caballero
            if (UtilFunctions.isLowAngle(antp, lastp, interp, point)) {
510
                radio = -radio;
511
            }
512 3765 caballero
513 3782 caballero
            Point2D centerp = UtilFunctions.getPoint(interp, mediop, radio);
514 37138 cordinyana
            renderer.drawLine(lastp, point,
515
                mapControlManager.getGeometrySelectionSymbol());
516 3765 caballero
517 26921 jpiera
            Geometry ig = createArc(lastp, centerp, point);
518 3765 caballero
519 3782 caballero
            if (ig != null) {
520 37138 cordinyana
                renderer.draw(ig,
521
                    mapControlManager.getGeometrySelectionSymbol());
522 3782 caballero
            }
523
        }
524 3765 caballero
    }
525
526
    /**
527
     * Add a diferent option.
528 37138 cordinyana
     *
529
     * @param sel
530
     *            DOCUMENT ME!
531
     * @param s
532
     *            Diferent option.
533 3765 caballero
     */
534 3832 caballero
    public void addOption(String s) {
535 37328 cordinyana
        // Nothing to do
536 3765 caballero
    }
537
538 3832 caballero
    public void addValue(double d) {
539 37328 cordinyana
        // Nothing to do
540 3765 caballero
    }
541 3883 caballero
542 37138 cordinyana
    public void cancel() {
543 5170 caballero
        list.clear();
544 13561 caballero
        clearTemporalCache();
545 37138 cordinyana
        antantPoint = antCenter = antInter = antPoint = firstPoint = null;
546 3883 caballero
    }
547 4002 fjp
548 5170 caballero
    public void end() {
549 37328 cordinyana
        // Nothing to do
550 5170 caballero
    }
551 4118 caballero
552 5170 caballero
    public String getName() {
553 37138 cordinyana
        return PluginServices.getText(this, "polyline_");
554 5170 caballero
    }
555 4892 caballero
556 5170 caballero
    public String toString() {
557
        return "_polyline";
558
    }
559 37138 cordinyana
560
    public void endTransition(double x, double y, MouseEvent event) {
561
        _fsm.endPoint(x, y, event);
562
    }
563 39280 jldominguez
564
    /**
565
     * @param geoms
566
     * @return
567
     * @throws CreateGeometryException
568
     */
569
    private Geometry concatenateCurves(List<Curve> cus, boolean surf) {
570
571
        Curve _curv = null;
572
        Surface _surf = null;
573
574
        try {
575
            if (surf) {
576
                _surf = (Surface) geomManager.create(
577
                    Geometry.TYPES.SURFACE, Geometry.SUBTYPES.GEOM2D);
578
            } else {
579
                _curv = (Curve) geomManager.create(
580
                    Geometry.TYPES.CURVE, Geometry.SUBTYPES.GEOM2D);
581
            }
582
        } catch (CreateGeometryException e) {
583
            LOG.info("Unable to create geometry: " + e.getMessage());
584
            ApplicationLocator.getManager().message(
585
                Messages.getText("_Unable_to_create_geometry"),
586
                JOptionPane.ERROR_MESSAGE);
587
            return null;
588
        }
589
590
591
        if (cus == null || cus.size() == 0) {
592
            if (surf) {
593
                return _surf;
594
            } else {
595
                return _curv;
596
            }
597
        }
598
599
        Curve item_cu = cus.get(0);
600
        int len = item_cu.getNumVertices();
601
        Point po = null;
602
        /*
603
         * All from first curve
604
         */
605
        for (int i=0; i<len; i++) {
606
            po = item_cu.getVertex(i);
607
            if (surf) {
608
                _surf.addVertex(po);
609
            } else {
610
                _curv.addVertex(po);
611
            }
612
613
        }
614
615
        for (int n=1; n<cus.size(); n++) {
616
617
            item_cu = cus.get(n);
618
            len = item_cu.getNumVertices();
619
            for (int i=0; i<len; i++) {
620
                po = item_cu.getVertex(i);
621
                /*
622
                 * Add only if not same coords
623
                 */
624
                if (surf) {
625
                    if (differentCoordinates(po,
626
                        _surf.getVertex(
627
                        _surf.getNumVertices()-1))) {
628
                        _surf.addVertex(po);
629
                    }
630
                } else {
631
                    if (differentCoordinates(po,
632
                        _curv.getVertex(
633
                        _curv.getNumVertices()-1))) {
634
                        _curv.addVertex(po);
635
                    }
636
                }
637
            }
638
        }
639
640
        if (surf) {
641
            return _surf;
642
        } else {
643
            return _curv;
644
        }
645
646
    }
647 37328 cordinyana
648 39280 jldominguez
    /**
649
     * @param po
650
     * @param vertex
651
     * @return
652
     */
653
    private boolean differentCoordinates(Point p1, Point p2) {
654
        return !p1.equals(p2);
655
    }
656
657 3765 caballero
}