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 @ 40559

History | View | Annotate | Download (9.82 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
 * AUTHORS (In addition to CIT):
26
 * 2009 {Iver T.I.}   {Task}
27
 */
28

    
29
package org.gvsig.fmap.geom.impl;
30

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

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

    
87
    public void doRegistration() {
88
        registerAsImplementationOf(GeometryLibrary.class);
89
    }
90

    
91
    protected void doInitialize() throws LibraryException {
92
        // Register the default GeometryManager
93
        GeometryLocator.registerGeometryManager(DefaultGeometryManager.class);
94
    }
95

    
96
    protected void doPostInitialize() throws LibraryException {
97
        GeometryManager geometryManager = GeometryLocator.getGeometryManager();
98

    
99
        DataTypesManager dataTypesManager = ToolsLocator.getDataTypesManager();
100

    
101
        dataTypesManager
102
        .setCoercion(DataTypes.GEOMETRY, new CoerceToGeometry());
103
        dataTypesManager
104
        .setCoercion(DataTypes.ENVELOPE, new CoerceToEnvelope());
105
        dataTypesManager.setCoercion(DataTypes.STRING, new CoerceToString(
106
            dataTypesManager.getCoercion(DataTypes.STRING)));
107
        dataTypesManager.setCoercion(
108
            DataTypes.BYTEARRAY,
109
            new CoerceToByteArray(dataTypesManager
110
                .getCoercion(DataTypes.BYTEARRAY)));
111

    
112
        GeometryOperation.OPERATION_INTERSECTS_CODE =
113
            GeometryLocator.getGeometryManager().getGeometryOperationCode(
114
                GeometryOperation.OPERATION_INTERSECTS_NAME);
115

    
116
        GeometryOperation.OPERATION_CONTAINS_CODE =
117
            GeometryLocator.getGeometryManager().getGeometryOperationCode(
118
                GeometryOperation.OPERATION_CONTAINS_NAME);
119

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

    
129
        //Register points in 2D
130
        geometryManager.registerGeometryType(new Point2DGeometryType());
131

    
132
        //Register curves in 2D
133
        geometryManager.registerGeometryType(Curve2D.class, "Curve2D",
134
            TYPES.CURVE, SUBTYPES.GEOM2D);
135
        geometryManager.registerGeometryType(Arc2D.class, "Arc2D", 
136
            TYPES.ARC, SUBTYPES.GEOM2D, TYPES.CURVE);
137
        geometryManager.registerGeometryType(Spline2D.class, "Spline2D",
138
            TYPES.SPLINE, SUBTYPES.GEOM2D, TYPES.CURVE);
139

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

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

    
160
        // Register the geometries in 3D
161
        geometryManager.registerGeometryType(DefaultNullGeometry.class,
162
            TYPES.NULL, SUBTYPES.GEOM3D);
163

    
164
        //Register points in 3D
165
        geometryManager.registerGeometryType(new Point3DGeometryType());
166

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

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

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

    
193
        //Register solids
194
        geometryManager.registerGeometryType(Solid2DZ.class, "Solid3D",
195
            TYPES.SOLID, SUBTYPES.GEOM3D);
196
        geometryManager.registerGeometryType(MultiSolid2DZ.class,"MultiSolid3D",
197
            TYPES.MULTISOLID, SUBTYPES.GEOM3D, TYPES.AGGREGATE);
198

    
199
        // Persistence
200
        DefaultEnvelope.registerPersistent();
201
        Envelope2D.registerPersistent();
202
        Envelope3D.registerPersistent();
203

    
204
        PersistenceManager persistenceManager =
205
            ToolsLocator.getPersistenceManager();
206

    
207
        persistenceManager.registerFactory(new GeometryPersistenceFactory());
208
        persistenceManager
209
            .registerFactory(new GeometryTypePersistenceFactory());
210
    }
211
}