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