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 / AbstractCurveSurfaceCADTool.java @ 40557
History | View | Annotate | Download (2.99 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 org.gvsig.editing.gui.cad.DefaultCADTool; |
27 |
import org.gvsig.fmap.dal.feature.Feature; |
28 |
import org.gvsig.fmap.geom.Geometry; |
29 |
import org.gvsig.fmap.geom.aggregate.MultiCurve; |
30 |
import org.gvsig.fmap.geom.aggregate.MultiSurface; |
31 |
import org.gvsig.fmap.geom.primitive.Curve; |
32 |
import org.gvsig.fmap.geom.primitive.OrientablePrimitive; |
33 |
import org.gvsig.fmap.geom.primitive.Surface; |
34 |
import org.gvsig.fmap.geom.type.GeometryType; |
35 |
|
36 |
/**
|
37 |
* Parent class for tools which create Curve or Surface geometries, depending
|
38 |
* on the layer geometry type.
|
39 |
*
|
40 |
* @author gvSIG team
|
41 |
*/
|
42 |
public abstract class AbstractCurveSurfaceCADTool extends DefaultCADTool { |
43 |
|
44 |
private static final int TYPE_CURVE = 0; |
45 |
private static final int TYPE_MULTICURVE = 1; |
46 |
private static final int TYPE_MULTISURFACE = 3; |
47 |
|
48 |
@Override
|
49 |
public Feature insertAndSelectGeometry(Geometry geometry) {
|
50 |
Geometry finalGeometry = geometry; |
51 |
GeometryType type = getGeometryType(); |
52 |
|
53 |
GeometryType[] types = getSupportedTypes();
|
54 |
|
55 |
if (types[TYPE_MULTICURVE].isTypeOf(type)) {
|
56 |
MultiCurve mcurve = createMultiCurve(); |
57 |
mcurve.addCurve((Curve) geometry); |
58 |
finalGeometry = mcurve; |
59 |
} else
|
60 |
if (types[TYPE_MULTISURFACE].isTypeOf(type)) {
|
61 |
MultiSurface msurface = createMultiSurface(); |
62 |
msurface.addSurface((Surface) geometry); |
63 |
finalGeometry = msurface; |
64 |
} |
65 |
|
66 |
return super.insertAndSelectGeometry(finalGeometry); |
67 |
} |
68 |
|
69 |
protected OrientablePrimitive createOrientablePrimitive() {
|
70 |
GeometryType type = getGeometryType(); |
71 |
|
72 |
GeometryType[] types = getSupportedTypes();
|
73 |
|
74 |
if (types[TYPE_CURVE].isTypeOf(type)
|
75 |
|| types[TYPE_MULTICURVE].isTypeOf(type)) { |
76 |
return createCurve();
|
77 |
} else { // SURFACE or MULTISURFACE |
78 |
return createSurface();
|
79 |
} |
80 |
} |
81 |
|
82 |
@Override
|
83 |
protected int[] getSupportedGeometryTypes() { |
84 |
return new int[] { CURVE, MULTICURVE, SURFACE, MULTISURFACE }; |
85 |
} |
86 |
} |