Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.geometry / org.gvsig.fmap.geometry.impl / src / main / java / org / gvsig / fmap / geom / impl / DefaultGeometryLibrary.java @ 40767

History | View | Annotate | Download (9.75 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

    
25
package org.gvsig.fmap.geom.impl;
26

    
27
import org.gvsig.fmap.geom.DataTypes;
28
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
29
import org.gvsig.fmap.geom.Geometry.TYPES;
30
import org.gvsig.fmap.geom.GeometryLibrary;
31
import org.gvsig.fmap.geom.GeometryLocator;
32
import org.gvsig.fmap.geom.GeometryManager;
33
import org.gvsig.fmap.geom.aggregate.impl.BaseMultiPrimitive2D;
34
import org.gvsig.fmap.geom.aggregate.impl.MultiCurve2D;
35
import org.gvsig.fmap.geom.aggregate.impl.MultiCurve2DZ;
36
import org.gvsig.fmap.geom.aggregate.impl.MultiPoint2D;
37
import org.gvsig.fmap.geom.aggregate.impl.MultiPoint2DZ;
38
import org.gvsig.fmap.geom.aggregate.impl.MultiSolid2DZ;
39
import org.gvsig.fmap.geom.aggregate.impl.MultiSurface2D;
40
import org.gvsig.fmap.geom.aggregate.impl.MultiSurface3D;
41
import org.gvsig.fmap.geom.impl.coerce.CoerceToByteArray;
42
import org.gvsig.fmap.geom.impl.coerce.CoerceToEnvelope;
43
import org.gvsig.fmap.geom.impl.coerce.CoerceToGeometry;
44
import org.gvsig.fmap.geom.impl.coerce.CoerceToString;
45
import org.gvsig.fmap.geom.operation.GeometryOperation;
46
import org.gvsig.fmap.geom.primitive.impl.Arc2D;
47
import org.gvsig.fmap.geom.primitive.impl.Arc2DZ;
48
import org.gvsig.fmap.geom.primitive.impl.Circle2D;
49
import org.gvsig.fmap.geom.primitive.impl.Circle2DZ;
50
import org.gvsig.fmap.geom.primitive.impl.Curve2D;
51
import org.gvsig.fmap.geom.primitive.impl.Curve2DZ;
52
import org.gvsig.fmap.geom.primitive.impl.DefaultEnvelope;
53
import org.gvsig.fmap.geom.primitive.impl.DefaultNullGeometry;
54
import org.gvsig.fmap.geom.primitive.impl.Ellipse2D;
55
import org.gvsig.fmap.geom.primitive.impl.Ellipse2DZ;
56
import org.gvsig.fmap.geom.primitive.impl.EllipticArc2D;
57
import org.gvsig.fmap.geom.primitive.impl.EllipticArc2DZ;
58
import org.gvsig.fmap.geom.primitive.impl.Envelope2D;
59
import org.gvsig.fmap.geom.primitive.impl.Envelope3D;
60
import org.gvsig.fmap.geom.primitive.impl.Geometry2D;
61
import org.gvsig.fmap.geom.primitive.impl.Geometry2DZ;
62
import org.gvsig.fmap.geom.primitive.impl.Point2DGeometryType;
63
import org.gvsig.fmap.geom.primitive.impl.Point3DGeometryType;
64
import org.gvsig.fmap.geom.primitive.impl.Solid2DZ;
65
import org.gvsig.fmap.geom.primitive.impl.Spline2D;
66
import org.gvsig.fmap.geom.primitive.impl.Spline2DZ;
67
import org.gvsig.fmap.geom.primitive.impl.Surface2D;
68
import org.gvsig.fmap.geom.primitive.impl.Surface2DZ;
69
import org.gvsig.fmap.geom.type.persistence.GeometryTypePersistenceFactory;
70
import org.gvsig.tools.ToolsLocator;
71
import org.gvsig.tools.dataTypes.DataTypesManager;
72
import org.gvsig.tools.library.AbstractLibrary;
73
import org.gvsig.tools.library.LibraryException;
74
import org.gvsig.tools.persistence.PersistenceManager;
75

    
76
/**
77
 * Registers the default implementation for {@link GeometryManager}
78
 * 
79
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
80
 */
81
public class DefaultGeometryLibrary extends AbstractLibrary {
82

    
83
    public void doRegistration() {
84
        registerAsImplementationOf(GeometryLibrary.class);
85
    }
86

    
87
    protected void doInitialize() throws LibraryException {
88
        // Register the default GeometryManager
89
        GeometryLocator.registerGeometryManager(DefaultGeometryManager.class);
90
    }
91

    
92
    protected void doPostInitialize() throws LibraryException {
93
        GeometryManager geometryManager = GeometryLocator.getGeometryManager();
94

    
95
        DataTypesManager dataTypesManager = ToolsLocator.getDataTypesManager();
96

    
97
        dataTypesManager
98
        .setCoercion(DataTypes.GEOMETRY, new CoerceToGeometry());
99
        dataTypesManager
100
        .setCoercion(DataTypes.ENVELOPE, new CoerceToEnvelope());
101
        dataTypesManager.setCoercion(DataTypes.STRING, new CoerceToString(
102
            dataTypesManager.getCoercion(DataTypes.STRING)));
103
        dataTypesManager.setCoercion(
104
            DataTypes.BYTEARRAY,
105
            new CoerceToByteArray(dataTypesManager
106
                .getCoercion(DataTypes.BYTEARRAY)));
107

    
108
        GeometryOperation.OPERATION_INTERSECTS_CODE =
109
            GeometryLocator.getGeometryManager().getGeometryOperationCode(
110
                GeometryOperation.OPERATION_INTERSECTS_NAME);
111

    
112
        GeometryOperation.OPERATION_CONTAINS_CODE =
113
            GeometryLocator.getGeometryManager().getGeometryOperationCode(
114
                GeometryOperation.OPERATION_CONTAINS_NAME);
115

    
116
        // Register the geometries in 2D
117
        geometryManager.registerGeometryType(DefaultNullGeometry.class, "Null",
118
            TYPES.NULL, SUBTYPES.GEOM2D);
119
        
120
        geometryManager.registerGeometryType(Geometry2D.class, "Geometry2D",
121
                TYPES.GEOMETRY, SUBTYPES.GEOM2D);
122
        geometryManager.registerGeometryType(Geometry2DZ.class, "Geometry3D",
123
            TYPES.GEOMETRY, SUBTYPES.GEOM3D);
124

    
125
        //Register points in 2D
126
        geometryManager.registerGeometryType(new Point2DGeometryType());
127

    
128
        //Register curves in 2D
129
        geometryManager.registerGeometryType(Curve2D.class, "Curve2D",
130
            TYPES.CURVE, SUBTYPES.GEOM2D);
131
        geometryManager.registerGeometryType(Arc2D.class, "Arc2D", 
132
            TYPES.ARC, SUBTYPES.GEOM2D, TYPES.CURVE);
133
        geometryManager.registerGeometryType(Spline2D.class, "Spline2D",
134
            TYPES.SPLINE, SUBTYPES.GEOM2D, TYPES.CURVE);
135

    
136
        //Register surfaces in 2D
137
        geometryManager.registerGeometryType(Surface2D.class, "Surface2D",
138
            TYPES.SURFACE, SUBTYPES.GEOM2D, TYPES.SURFACE);
139
        geometryManager.registerGeometryType(Circle2D.class, "Circle2D",
140
            TYPES.CIRCLE, SUBTYPES.GEOM2D, TYPES.SURFACE);      
141
        geometryManager.registerGeometryType(Ellipse2D.class, "Ellipse2D",
142
            TYPES.ELLIPSE, SUBTYPES.GEOM2D, TYPES.SURFACE);
143
        geometryManager.registerGeometryType(EllipticArc2D.class,"EllipticArc2D", 
144
            TYPES.ELLIPTICARC, SUBTYPES.GEOM2D, TYPES.SURFACE);
145

    
146
        //Register multigeometries in 2D
147
        geometryManager.registerGeometryType(BaseMultiPrimitive2D.class, "MultiPrimitive2D", 
148
            TYPES.AGGREGATE, SUBTYPES.GEOM2D);
149
        geometryManager.registerGeometryType(MultiPoint2D.class, "MultiPoint2D",
150
            TYPES.MULTIPOINT, SUBTYPES.GEOM2D, TYPES.AGGREGATE);
151
        geometryManager.registerGeometryType(MultiCurve2D.class, "MultiCurve2D",
152
            TYPES.MULTICURVE, SUBTYPES.GEOM2D, TYPES.AGGREGATE); 
153
        geometryManager.registerGeometryType(MultiSurface2D.class,"MultiSurface2D",
154
            TYPES.MULTISURFACE, SUBTYPES.GEOM2D, TYPES.AGGREGATE);
155

    
156
        // Register the geometries in 3D
157
        geometryManager.registerGeometryType(DefaultNullGeometry.class,
158
            TYPES.NULL, SUBTYPES.GEOM3D);
159

    
160
        //Register points in 3D
161
        geometryManager.registerGeometryType(new Point3DGeometryType());
162

    
163
        //Register curves in 3D
164
        geometryManager.registerGeometryType(Curve2DZ.class, "Curve3D", 
165
            TYPES.CURVE, SUBTYPES.GEOM3D, new int[0], new int[]{SUBTYPES.GEOM2D});
166
        geometryManager.registerGeometryType(Arc2DZ.class, "Arc3D", 
167
            TYPES.ARC, SUBTYPES.GEOM3D, TYPES.CURVE, SUBTYPES.GEOM2D);
168
        geometryManager.registerGeometryType(Spline2DZ.class, "Spline3D", 
169
            TYPES.SPLINE, SUBTYPES.GEOM3D, TYPES.CURVE, SUBTYPES.GEOM2D);
170

    
171
        //Register surfaces in 3D
172
        geometryManager.registerGeometryType(Surface2DZ.class, "Surface3D", 
173
            TYPES.SURFACE, SUBTYPES.GEOM3D, new int[0], new int[]{SUBTYPES.GEOM2D});
174
        geometryManager.registerGeometryType(Circle2DZ.class, "Circle3D",
175
            TYPES.CIRCLE, SUBTYPES.GEOM3D, TYPES.SURFACE, SUBTYPES.GEOM2D);
176
        geometryManager.registerGeometryType(Ellipse2DZ.class, "Ellipse3D", 
177
            TYPES.ELLIPSE,SUBTYPES.GEOM3D, TYPES.SURFACE, SUBTYPES.GEOM2D);
178
        geometryManager.registerGeometryType(EllipticArc2DZ.class, "EllipticArc3D",
179
            TYPES.ELLIPTICARC, SUBTYPES.GEOM3D, TYPES.SURFACE, SUBTYPES.GEOM2D);
180

    
181
        //Register multigeometries in 3D
182
        geometryManager.registerGeometryType(MultiPoint2DZ.class, "Multipoint3D", 
183
            TYPES.MULTIPOINT, SUBTYPES.GEOM3D, TYPES.AGGREGATE, SUBTYPES.GEOM2D);
184
        geometryManager.registerGeometryType(MultiCurve2DZ.class,"MultiCurve3D",
185
            TYPES.MULTICURVE, SUBTYPES.GEOM3D, TYPES.AGGREGATE, SUBTYPES.GEOM2D);
186
        geometryManager.registerGeometryType(MultiSurface3D.class,"MultiSurface3D",
187
            TYPES.MULTISURFACE, SUBTYPES.GEOM3D, TYPES.AGGREGATE, SUBTYPES.GEOM2D);
188

    
189
        //Register solids
190
        geometryManager.registerGeometryType(Solid2DZ.class, "Solid3D",
191
            TYPES.SOLID, SUBTYPES.GEOM3D);
192
        geometryManager.registerGeometryType(MultiSolid2DZ.class,"MultiSolid3D",
193
            TYPES.MULTISOLID, SUBTYPES.GEOM3D, TYPES.AGGREGATE);
194

    
195
        // Persistence
196
        DefaultEnvelope.registerPersistent();
197
        Envelope2D.registerPersistent();
198
        Envelope3D.registerPersistent();
199

    
200
        PersistenceManager persistenceManager =
201
            ToolsLocator.getPersistenceManager();
202

    
203
        persistenceManager.registerFactory(new GeometryPersistenceFactory());
204
        persistenceManager
205
            .registerFactory(new GeometryTypePersistenceFactory());
206
    }
207
}