svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.editing.app / org.gvsig.editing.app.mainplugin / src / main / java / org / gvsig / editing / gui / cad / tools / PolylineCADTool.java @ 40557
History | View | Annotate | Download (23.6 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* 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 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* 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 |
*
|
16 |
* 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 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.editing.gui.cad.tools; |
25 |
|
26 |
import java.awt.event.InputEvent; |
27 |
import java.awt.event.MouseEvent; |
28 |
import java.awt.geom.Point2D; |
29 |
import java.util.ArrayList; |
30 |
import java.util.List; |
31 |
|
32 |
import javax.swing.JOptionPane; |
33 |
|
34 |
import org.gvsig.andami.PluginServices; |
35 |
import org.gvsig.app.ApplicationLocator; |
36 |
import org.gvsig.editing.gui.cad.exception.CommandException; |
37 |
import org.gvsig.editing.gui.cad.tools.smc.PolylineCADToolContext; |
38 |
import org.gvsig.editing.gui.cad.tools.smc.PolylineCADToolContext.PolylineCADToolState; |
39 |
import org.gvsig.fmap.dal.exception.ReadException; |
40 |
import org.gvsig.fmap.geom.Geometry; |
41 |
import org.gvsig.fmap.geom.GeometryLocator; |
42 |
import org.gvsig.fmap.geom.GeometryManager; |
43 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
44 |
import org.gvsig.fmap.geom.handler.Handler; |
45 |
import org.gvsig.fmap.geom.primitive.Curve; |
46 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
47 |
import org.gvsig.fmap.geom.primitive.Point; |
48 |
import org.gvsig.fmap.geom.primitive.Surface; |
49 |
import org.gvsig.fmap.geom.util.UtilFunctions; |
50 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
51 |
import org.gvsig.fmap.mapcontrol.MapControlDrawer; |
52 |
import org.gvsig.i18n.Messages; |
53 |
import org.slf4j.Logger; |
54 |
import org.slf4j.LoggerFactory; |
55 |
|
56 |
/**
|
57 |
* DOCUMENT ME!
|
58 |
*
|
59 |
* @author Vicente Caballero Navarro
|
60 |
*/
|
61 |
public class PolylineCADTool extends AbstractCurveSurfaceCADTool { |
62 |
|
63 |
private static final Logger LOG = LoggerFactory.getLogger(PolylineCADTool.class); |
64 |
|
65 |
protected PolylineCADToolContext _fsm;
|
66 |
protected Point2D firstPoint; |
67 |
protected Point2D antPoint; |
68 |
protected Point2D antantPoint; |
69 |
protected Point2D antCenter; |
70 |
protected Point2D antInter; |
71 |
protected List<Curve> list = new ArrayList<Curve>(); |
72 |
protected boolean close = false; |
73 |
protected GeometryManager geomManager = GeometryLocator.getGeometryManager();
|
74 |
|
75 |
/**
|
76 |
* M?todo de incio, para poner el c?digo de todo lo que se requiera de una
|
77 |
* carga previa a la utilizaci?n de la herramienta.
|
78 |
*/
|
79 |
public void init() { |
80 |
_fsm = new PolylineCADToolContext(this); |
81 |
} |
82 |
|
83 |
public Geometry getGeometry() {
|
84 |
Geometry newGeom = null;
|
85 |
newGeom = concatenateCurves(list, false);
|
86 |
return newGeom;
|
87 |
} |
88 |
|
89 |
|
90 |
|
91 |
public int getLinesCount() { |
92 |
return list.size();
|
93 |
} |
94 |
|
95 |
public boolean isPolygonLayer() { |
96 |
try {
|
97 |
return (((FLyrVect) getVLE().getLayer()).getShapeType() == Geometry.TYPES.SURFACE);
|
98 |
} catch (ReadException e) {
|
99 |
return false; |
100 |
} |
101 |
} |
102 |
|
103 |
public void endGeometry() { |
104 |
|
105 |
/*
|
106 |
if (gpx == null) {
|
107 |
gpx = new GeneralPathX();
|
108 |
Geometry[] geoms = (Geometry[]) list.toArray(new Geometry[0]);
|
109 |
MultiPrimitive fgc = createMultiPrimitive(geoms);
|
110 |
// No queremos guardar FGeometryCollections:
|
111 |
gpx.append(fgc.getPathIterator(null, geomManager.getFlatness()),
|
112 |
true);
|
113 |
}
|
114 |
|
115 |
try {
|
116 |
if (((FLyrVect) getVLE().getLayer()).getShapeType() == Geometry.TYPES.SURFACE
|
117 |
&& !close) {
|
118 |
closeGeometry();
|
119 |
}
|
120 |
} catch (ReadException e) {
|
121 |
NotificationManager.addError(e.getMessage(), e);
|
122 |
}
|
123 |
*/
|
124 |
|
125 |
|
126 |
Geometry newGeom = null;
|
127 |
int type = getCadToolAdapter().getActiveLayerType();
|
128 |
|
129 |
if ((type == Geometry.TYPES.SURFACE)
|
130 |
|| (type == Geometry.TYPES.MULTISURFACE)) { |
131 |
|
132 |
newGeom = concatenateCurves(list, true);
|
133 |
closeSurfaceIfNecessary((Surface) newGeom); |
134 |
// newGeom = createSurface(gpx);
|
135 |
} else {
|
136 |
newGeom = concatenateCurves(list, false);
|
137 |
// newGeom = createCurve(gpx);
|
138 |
} |
139 |
insertAndSelectGeometry(newGeom); |
140 |
_fsm = new PolylineCADToolContext(this); |
141 |
list.clear(); |
142 |
clearTemporalCache(); |
143 |
close = false;
|
144 |
antantPoint = antCenter = antInter = antPoint = firstPoint = null;
|
145 |
} |
146 |
|
147 |
/**
|
148 |
* @param newGeom
|
149 |
*/
|
150 |
private void closeSurfaceIfNecessary(Surface geo) { |
151 |
|
152 |
if (!close && geo != null && geo.getNumVertices() > 1) { |
153 |
Point firstp = geo.getVertex(0); |
154 |
firstp = (Point) firstp.cloneGeometry();
|
155 |
geo.addVertex(firstp); |
156 |
} |
157 |
// TODO Auto-generated method stub
|
158 |
|
159 |
} |
160 |
|
161 |
public void closeGeometry() { |
162 |
|
163 |
int ng = list.size();
|
164 |
if (ng > 0) { |
165 |
Curve firstcurve = list.get(0);
|
166 |
Curve lastcurve = list.get(ng - 1);
|
167 |
Point firstp = firstcurve.getVertex(0); |
168 |
firstp = (Point) firstp.cloneGeometry();
|
169 |
lastcurve.addVertex(firstp); |
170 |
} |
171 |
close = true;
|
172 |
} |
173 |
|
174 |
public void transition(double x, double y, InputEvent event) { |
175 |
_fsm.addPoint(x, y, event); |
176 |
} |
177 |
|
178 |
public void transition(double d) { |
179 |
_fsm.addValue(d); |
180 |
} |
181 |
|
182 |
public void transition(String s) throws CommandException { |
183 |
if (!super.changeCommand(s)) { |
184 |
_fsm.addOption(s); |
185 |
} |
186 |
} |
187 |
|
188 |
/**
|
189 |
* Equivale al transition del prototipo pero sin pasarle como par?metro el
|
190 |
* editableFeatureSource que ya estar? creado.
|
191 |
*
|
192 |
* @param sel
|
193 |
* Bitset con las geometr?as que est?n seleccionadas.
|
194 |
* @param x
|
195 |
* par?metro x del punto que se pase en esta transici?n.
|
196 |
* @param y
|
197 |
* par?metro y del punto que se pase en esta transici?n.
|
198 |
*/
|
199 |
public void addPoint(double x, double y, InputEvent event) { |
200 |
PolylineCADToolState actualState = |
201 |
(PolylineCADToolState) _fsm.getPreviousState(); |
202 |
String status = actualState.getName();
|
203 |
if (status.equals("Polyline.NextPointOrArcOrClose") |
204 |
|| status.equals("Polyline.FirstPoint")) {
|
205 |
|
206 |
if (firstPoint == null) { |
207 |
firstPoint = new Point2D.Double(x, y); |
208 |
} |
209 |
Point2D point = new Point2D.Double(x, y); |
210 |
|
211 |
if (antPoint != null |
212 |
&& (antPoint.getX() != point.getX() || antPoint.getY() != point |
213 |
.getY())) { |
214 |
GeneralPathX elShape = |
215 |
new GeneralPathX(GeneralPathX.WIND_EVEN_ODD, 2); |
216 |
elShape.moveTo(antPoint.getX(), antPoint.getY()); |
217 |
elShape.lineTo(point.getX(), point.getY()); |
218 |
Curve geom = createCurve(elShape); |
219 |
if (geom != null) { |
220 |
list.add(geom); |
221 |
addTemporalCache(geom); |
222 |
} |
223 |
} |
224 |
if (antPoint == null) |
225 |
antPoint = (Point2D) firstPoint.clone();
|
226 |
|
227 |
if (antPoint != null) { |
228 |
antantPoint = antPoint; |
229 |
} |
230 |
|
231 |
antPoint = point; |
232 |
} else
|
233 |
if (status.equals("Polyline.NextPointOrLineOrClose")) { |
234 |
Point2D point = new Point2D.Double(x, y); |
235 |
Point2D lastp = antPoint; // (Point2D)points.get(i-1); |
236 |
|
237 |
if (antantPoint == null) { |
238 |
antantPoint = |
239 |
new Point2D.Double(lastp.getX() + (point.getX() / 2), |
240 |
lastp.getY() + (point.getY() / 2));
|
241 |
} |
242 |
|
243 |
if (((point.getY() == lastp.getY()) && (point.getX() < lastp
|
244 |
.getX())) |
245 |
|| ((point.getX() == lastp.getX()) && (point.getY() < lastp |
246 |
.getY()))) { |
247 |
} else {
|
248 |
if (point.getX() == lastp.getX()) {
|
249 |
point = |
250 |
new Point2D.Double(point.getX() + 0.00000001, |
251 |
point.getY()); |
252 |
} else
|
253 |
if (point.getY() == lastp.getY()) {
|
254 |
point = |
255 |
new Point2D.Double(point.getX(), |
256 |
point.getY() + 0.00000001);
|
257 |
} |
258 |
|
259 |
if (point.getX() == antantPoint.getX()) {
|
260 |
point = |
261 |
new Point2D.Double(point.getX() + 0.00000001, |
262 |
point.getY()); |
263 |
} else
|
264 |
if (point.getY() == antantPoint.getY()) {
|
265 |
point = |
266 |
new Point2D.Double(point.getX(), |
267 |
point.getY() + 0.00000001);
|
268 |
} |
269 |
|
270 |
if (!(list.size() > 0) |
271 |
|| (((Geometry) list.get(list.size() - 1)).getType() == Geometry.TYPES.CURVE)) {
|
272 |
Point2D[] ps1 = |
273 |
UtilFunctions.getPerpendicular(antantPoint, lastp, |
274 |
lastp); |
275 |
Point2D mediop =
|
276 |
new Point2D.Double( |
277 |
(point.getX() + lastp.getX()) / 2,
|
278 |
(point.getY() + lastp.getY()) / 2);
|
279 |
Point2D[] ps2 = |
280 |
UtilFunctions |
281 |
.getPerpendicular(lastp, point, mediop); |
282 |
Point2D interp =
|
283 |
UtilFunctions.getIntersection(ps1[0], ps1[1], |
284 |
ps2[0], ps2[1]); |
285 |
antInter = interp; |
286 |
|
287 |
double radio = interp.distance(lastp);
|
288 |
|
289 |
if (UtilFunctions.isLowAngle(antantPoint, lastp,
|
290 |
interp, point)) { |
291 |
radio = -radio; |
292 |
} |
293 |
|
294 |
Point2D centerp =
|
295 |
UtilFunctions.getPoint(interp, mediop, radio); |
296 |
antCenter = centerp; |
297 |
|
298 |
Curve ig = createArc(lastp, centerp, point); |
299 |
|
300 |
if (ig != null) { |
301 |
list.add(ig); |
302 |
addTemporalCache(ig); |
303 |
} else {
|
304 |
|
305 |
ApplicationLocator.getManager().message( |
306 |
Messages.getText("_Unable_to_create_arc"),
|
307 |
JOptionPane.ERROR_MESSAGE);
|
308 |
|
309 |
} |
310 |
} else {
|
311 |
Point2D[] ps1 = |
312 |
UtilFunctions.getPerpendicular(lastp, antInter, |
313 |
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 |
|
320 |
if (UtilFunctions.absoluteAngleDistance(angle, a1) > UtilFunctions
|
321 |
.absoluteAngleDistance(angle, a2)) { |
322 |
ini1 = ps1[0];
|
323 |
ini2 = ps1[1];
|
324 |
} else {
|
325 |
ini1 = ps1[1];
|
326 |
ini2 = ps1[0];
|
327 |
} |
328 |
|
329 |
Point2D unit = UtilFunctions.getUnitVector(ini1, ini2);
|
330 |
Point2D correct =
|
331 |
new Point2D.Double(lastp.getX() + unit.getX(), |
332 |
lastp.getY() + unit.getY()); |
333 |
Point2D[] ps = |
334 |
UtilFunctions.getPerpendicular(lastp, correct, |
335 |
lastp); |
336 |
Point2D mediop =
|
337 |
new Point2D.Double( |
338 |
(point.getX() + lastp.getX()) / 2,
|
339 |
(point.getY() + lastp.getY()) / 2);
|
340 |
Point2D[] ps2 = |
341 |
UtilFunctions |
342 |
.getPerpendicular(lastp, point, mediop); |
343 |
Point2D interp =
|
344 |
UtilFunctions.getIntersection(ps[0], ps[1], ps2[0], |
345 |
ps2[1]);
|
346 |
antInter = interp; |
347 |
|
348 |
double radio = interp.distance(lastp);
|
349 |
|
350 |
if (UtilFunctions.isLowAngle(correct, lastp, interp,
|
351 |
point)) { |
352 |
radio = -radio; |
353 |
} |
354 |
|
355 |
Point2D centerp =
|
356 |
UtilFunctions.getPoint(interp, mediop, radio); |
357 |
antCenter = centerp; |
358 |
Curve geom = createArc(lastp, centerp, point); |
359 |
|
360 |
if (geom != null) { |
361 |
list.add(geom); |
362 |
addTemporalCache(geom); |
363 |
} |
364 |
} |
365 |
|
366 |
antantPoint = antPoint; |
367 |
antPoint = point; |
368 |
} |
369 |
} |
370 |
} |
371 |
|
372 |
/**
|
373 |
* M?todo para dibujar la lo necesario para el estado en el que nos
|
374 |
* encontremos.
|
375 |
*
|
376 |
* @param g
|
377 |
* Graphics sobre el que dibujar.
|
378 |
* @param selectedGeometries
|
379 |
* BitSet con las geometr?as seleccionadas.
|
380 |
* @param x
|
381 |
* par?metro x del punto que se pase para dibujar.
|
382 |
* @param y
|
383 |
* par?metro x del punto que se pase para dibujar.
|
384 |
*/
|
385 |
public void drawOperation(MapControlDrawer renderer, double x, double y) { |
386 |
PolylineCADToolState actualState = _fsm.getState(); |
387 |
String status = actualState.getName();
|
388 |
|
389 |
if (status.equals("Polyline.NextPointOrArcOrClose") |
390 |
|| status.equals("Polyline.FirstPoint")) {
|
391 |
for (int i = 0; i < list.size(); i++) { |
392 |
renderer.draw((Geometry) list.get(i), |
393 |
mapControlManager.getGeometrySelectionSymbol()); |
394 |
} |
395 |
if (antPoint != null) |
396 |
renderer.drawLine(antPoint, new Point2D.Double(x, y), |
397 |
mapControlManager.getGeometrySelectionSymbol()); |
398 |
|
399 |
} else
|
400 |
if ((status.equals("Polyline.NextPointOrLineOrClose"))) { |
401 |
for (int i = 0; i < list.size(); i++) { |
402 |
renderer.draw((Geometry) list.get(i), |
403 |
mapControlManager.getGeometrySelectionSymbol()); |
404 |
} |
405 |
|
406 |
Point2D point = new Point2D.Double(x, y); |
407 |
Point2D lastp = antPoint;
|
408 |
|
409 |
if (!(list.size() > 0) |
410 |
|| (((Geometry) list.get(list.size() - 1)).getType() == Geometry.TYPES.CURVE)) {
|
411 |
if (antantPoint == null) { |
412 |
drawArc(point, lastp, new Point2D.Double(lastp.getX() |
413 |
+ (point.getX() / 2), lastp.getY()
|
414 |
+ (point.getY() / 2)), renderer);
|
415 |
} else {
|
416 |
drawArc(point, lastp, antantPoint, renderer); |
417 |
} |
418 |
} else {
|
419 |
if (antInter != null) { |
420 |
Point2D[] ps1 = |
421 |
UtilFunctions.getPerpendicular(lastp, antInter, |
422 |
lastp); |
423 |
double a1 = UtilFunctions.getAngle(ps1[0], ps1[1]); |
424 |
double a2 = UtilFunctions.getAngle(ps1[1], ps1[0]); |
425 |
double angle = UtilFunctions.getAngle(antCenter, lastp);
|
426 |
Point2D ini1 = null; |
427 |
Point2D ini2 = null; |
428 |
|
429 |
if (UtilFunctions.absoluteAngleDistance(angle, a1) > UtilFunctions
|
430 |
.absoluteAngleDistance(angle, a2)) { |
431 |
ini1 = ps1[0];
|
432 |
ini2 = ps1[1];
|
433 |
} else {
|
434 |
ini1 = ps1[1];
|
435 |
ini2 = ps1[0];
|
436 |
} |
437 |
|
438 |
Point2D unit = UtilFunctions.getUnitVector(ini1, ini2);
|
439 |
Point2D correct =
|
440 |
new Point2D.Double(lastp.getX() + unit.getX(), |
441 |
lastp.getY() + unit.getY()); |
442 |
drawArc(point, lastp, correct, renderer); |
443 |
} |
444 |
} |
445 |
} |
446 |
try {
|
447 |
if (((FLyrVect) getVLE().getLayer()).getShapeType() == Geometry.TYPES.SURFACE
|
448 |
&& !list.isEmpty()) { |
449 |
Handler handler1 =
|
450 |
((Geometry) list.get(0))
|
451 |
.getHandlers(Geometry.SELECTHANDLER)[0];
|
452 |
GeneralPathX gpx = new GeneralPathX();
|
453 |
gpx.moveTo(x, y); |
454 |
Point2D p1 = handler1.getPoint();
|
455 |
gpx.lineTo(p1.getX(), p1.getY()); |
456 |
Curve curve = createCurve(gpx); |
457 |
renderer.draw(curve, |
458 |
mapControlManager.getGeometrySelectionSymbol()); |
459 |
} |
460 |
} catch (ReadException e) {
|
461 |
e.printStackTrace(); |
462 |
} |
463 |
} |
464 |
|
465 |
/**
|
466 |
* Dibuja el arco sobre el graphics.
|
467 |
*
|
468 |
* @param point
|
469 |
* Puntero del rat?n.
|
470 |
* @param lastp
|
471 |
* ?ltimo punto de la polilinea.
|
472 |
* @param antp
|
473 |
* Punto antepenultimo.
|
474 |
* @param g
|
475 |
* Graphics sobre el que se dibuja.
|
476 |
*/
|
477 |
private void drawArc(Point2D point, Point2D lastp, Point2D antp, |
478 |
MapControlDrawer renderer) { |
479 |
if (((point.getY() == lastp.getY()) && (point.getX() < lastp.getX()))
|
480 |
|| ((point.getX() == lastp.getX()) && (point.getY() < lastp.getY()))) { |
481 |
} else {
|
482 |
if (point.getX() == lastp.getX()) {
|
483 |
point = |
484 |
new Point2D.Double(point.getX() + 0.00000001, point.getY()); |
485 |
} else
|
486 |
if (point.getY() == lastp.getY()) {
|
487 |
point = |
488 |
new Point2D.Double(point.getX(), |
489 |
point.getY() + 0.00000001);
|
490 |
} |
491 |
|
492 |
if (point.getX() == antp.getX()) {
|
493 |
point = |
494 |
new Point2D.Double(point.getX() + 0.00000001, point.getY()); |
495 |
} else
|
496 |
if (point.getY() == antp.getY()) {
|
497 |
point = |
498 |
new Point2D.Double(point.getX(), |
499 |
point.getY() + 0.00000001);
|
500 |
} |
501 |
|
502 |
Point2D[] ps1 = UtilFunctions.getPerpendicular(lastp, antp, lastp); |
503 |
Point2D mediop =
|
504 |
new Point2D.Double((point.getX() + lastp.getX()) / 2, |
505 |
(point.getY() + lastp.getY()) / 2);
|
506 |
Point2D[] ps2 = |
507 |
UtilFunctions.getPerpendicular(lastp, point, mediop); |
508 |
Point2D interp =
|
509 |
UtilFunctions.getIntersection(ps1[0], ps1[1], ps2[0], ps2[1]); |
510 |
|
511 |
double radio = interp.distance(lastp);
|
512 |
|
513 |
if (UtilFunctions.isLowAngle(antp, lastp, interp, point)) {
|
514 |
radio = -radio; |
515 |
} |
516 |
|
517 |
Point2D centerp = UtilFunctions.getPoint(interp, mediop, radio);
|
518 |
renderer.drawLine(lastp, point, |
519 |
mapControlManager.getGeometrySelectionSymbol()); |
520 |
|
521 |
Geometry ig = createArc(lastp, centerp, point); |
522 |
|
523 |
if (ig != null) { |
524 |
renderer.draw(ig, |
525 |
mapControlManager.getGeometrySelectionSymbol()); |
526 |
} |
527 |
} |
528 |
} |
529 |
|
530 |
/**
|
531 |
* Add a diferent option.
|
532 |
*
|
533 |
* @param sel
|
534 |
* DOCUMENT ME!
|
535 |
* @param s
|
536 |
* Diferent option.
|
537 |
*/
|
538 |
public void addOption(String s) { |
539 |
// Nothing to do
|
540 |
} |
541 |
|
542 |
public void addValue(double d) { |
543 |
// Nothing to do
|
544 |
} |
545 |
|
546 |
public void cancel() { |
547 |
list.clear(); |
548 |
clearTemporalCache(); |
549 |
antantPoint = antCenter = antInter = antPoint = firstPoint = null;
|
550 |
} |
551 |
|
552 |
public void end() { |
553 |
// Nothing to do
|
554 |
} |
555 |
|
556 |
public String getName() { |
557 |
return PluginServices.getText(this, "polyline_"); |
558 |
} |
559 |
|
560 |
public String toString() { |
561 |
return "_polyline"; |
562 |
} |
563 |
|
564 |
public void endTransition(double x, double y, MouseEvent event) { |
565 |
_fsm.endPoint(x, y, event); |
566 |
} |
567 |
|
568 |
private Point create3DPoint(Point p) { |
569 |
try {
|
570 |
return geomManager.createPoint(p.getX(), p.getY(), Geometry.SUBTYPES.GEOM3D);
|
571 |
} catch (CreateGeometryException e) {
|
572 |
return p;
|
573 |
} |
574 |
} |
575 |
|
576 |
/**
|
577 |
* @param geoms
|
578 |
* @return
|
579 |
* @throws CreateGeometryException
|
580 |
*/
|
581 |
private Geometry concatenateCurves(List<Curve> cus, boolean surf) { |
582 |
|
583 |
Curve _curv = null;
|
584 |
Surface _surf = null;
|
585 |
int subtype = cus.size() > 0 && cus.get(0) != null ? cus.get(0).getGeometryType().getSubType() : Geometry.SUBTYPES.GEOM2D; |
586 |
boolean is3D = subtype == 1 || subtype == 3; |
587 |
|
588 |
try {
|
589 |
if (surf) {
|
590 |
_surf = (Surface) geomManager.create(Geometry.TYPES.SURFACE, subtype); |
591 |
} else {
|
592 |
_curv = (Curve) geomManager.create(Geometry.TYPES.CURVE, subtype); |
593 |
} |
594 |
} catch (CreateGeometryException e) {
|
595 |
LOG.info("Unable to create geometry: " + e.getMessage());
|
596 |
ApplicationLocator.getManager().message( |
597 |
Messages.getText("_Unable_to_create_geometry"),
|
598 |
JOptionPane.ERROR_MESSAGE);
|
599 |
return null; |
600 |
} |
601 |
|
602 |
|
603 |
if (cus == null || cus.size() == 0) { |
604 |
if (surf) {
|
605 |
return _surf;
|
606 |
} else {
|
607 |
return _curv;
|
608 |
} |
609 |
} |
610 |
|
611 |
Curve item_cu = cus.get(0);
|
612 |
int len = item_cu.getNumVertices();
|
613 |
Point po = null; |
614 |
/*
|
615 |
* All from first curve
|
616 |
*/
|
617 |
for (int i = 0; i < len; i++) { |
618 |
po = item_cu.getVertex(i); |
619 |
if(is3D) {
|
620 |
po = create3DPoint(po); |
621 |
} |
622 |
if (surf) {
|
623 |
_surf.addVertex(po); |
624 |
} else {
|
625 |
_curv.addVertex(po); |
626 |
} |
627 |
|
628 |
} |
629 |
|
630 |
for (int n = 1; n < cus.size(); n++) { |
631 |
|
632 |
item_cu = cus.get(n); |
633 |
len = item_cu.getNumVertices(); |
634 |
for (int i = 0; i < len; i++) { |
635 |
po = item_cu.getVertex(i); |
636 |
if(is3D) {
|
637 |
po = create3DPoint(po); |
638 |
} |
639 |
|
640 |
/*
|
641 |
* Add only if not same coords
|
642 |
*/
|
643 |
if (surf) {
|
644 |
if (differentCoordinates(po,
|
645 |
_surf.getVertex( |
646 |
_surf.getNumVertices()-1))) {
|
647 |
_surf.addVertex(po); |
648 |
} |
649 |
} else {
|
650 |
if (differentCoordinates(po,
|
651 |
_curv.getVertex( |
652 |
_curv.getNumVertices()-1))) {
|
653 |
_curv.addVertex(po); |
654 |
} |
655 |
} |
656 |
} |
657 |
} |
658 |
|
659 |
if (surf) {
|
660 |
return _surf;
|
661 |
} else {
|
662 |
return _curv;
|
663 |
} |
664 |
|
665 |
} |
666 |
|
667 |
/**
|
668 |
* @param po
|
669 |
* @param vertex
|
670 |
* @return
|
671 |
*/
|
672 |
private boolean differentCoordinates(Point p1, Point p2) { |
673 |
return !p1.equals(p2);
|
674 |
} |
675 |
|
676 |
} |