Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libFMap_geometries / src / org / gvsig / fmap / geom / impl / DefaultGeometryLibrary.java @ 38596

History | View | Annotate | Download (9.77 KB)

1 26328 jpiera
/* gvSIG. Geographic Information System of the Valencian Government
2 34708 jjdelcerro
 *
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 26328 jpiera
23
/*
24 34708 jjdelcerro
 * AUTHORS (In addition to CIT):
25
 * 2009 {Iver T.I.}   {Task}
26
 */
27 29051 jmvivo
28 27042 jpiera
package org.gvsig.fmap.geom.impl;
29 26328 jpiera
30 34690 jjdelcerro
import org.gvsig.fmap.geom.DataTypes;
31
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
32
import org.gvsig.fmap.geom.Geometry.TYPES;
33 33032 jjdelcerro
import org.gvsig.fmap.geom.GeometryLibrary;
34 27042 jpiera
import org.gvsig.fmap.geom.GeometryLocator;
35
import org.gvsig.fmap.geom.GeometryManager;
36 27029 jpiera
import org.gvsig.fmap.geom.aggregate.impl.BaseMultiPrimitive2D;
37
import org.gvsig.fmap.geom.aggregate.impl.MultiCurve2D;
38 29051 jmvivo
import org.gvsig.fmap.geom.aggregate.impl.MultiCurve2DZ;
39 27029 jpiera
import org.gvsig.fmap.geom.aggregate.impl.MultiPoint2D;
40
import org.gvsig.fmap.geom.aggregate.impl.MultiPoint2DZ;
41 35613 jpiera
import org.gvsig.fmap.geom.aggregate.impl.MultiSolid2DZ;
42 27029 jpiera
import org.gvsig.fmap.geom.aggregate.impl.MultiSurface2D;
43 35613 jpiera
import org.gvsig.fmap.geom.aggregate.impl.MultiSurface3D;
44 34690 jjdelcerro
import org.gvsig.fmap.geom.impl.coerce.CoerceToByteArray;
45
import org.gvsig.fmap.geom.impl.coerce.CoerceToEnvelope;
46
import org.gvsig.fmap.geom.impl.coerce.CoerceToGeometry;
47
import org.gvsig.fmap.geom.impl.coerce.CoerceToString;
48 31221 jldominguez
import org.gvsig.fmap.geom.operation.GeometryOperation;
49 27029 jpiera
import org.gvsig.fmap.geom.primitive.impl.Arc2D;
50
import org.gvsig.fmap.geom.primitive.impl.Arc2DZ;
51
import org.gvsig.fmap.geom.primitive.impl.Circle2D;
52
import org.gvsig.fmap.geom.primitive.impl.Circle2DZ;
53
import org.gvsig.fmap.geom.primitive.impl.Curve2D;
54
import org.gvsig.fmap.geom.primitive.impl.Curve2DZ;
55 33388 jpiera
import org.gvsig.fmap.geom.primitive.impl.DefaultEnvelope;
56 27037 jpiera
import org.gvsig.fmap.geom.primitive.impl.DefaultNullGeometry;
57 27029 jpiera
import org.gvsig.fmap.geom.primitive.impl.Ellipse2D;
58
import org.gvsig.fmap.geom.primitive.impl.Ellipse2DZ;
59
import org.gvsig.fmap.geom.primitive.impl.EllipticArc2D;
60
import org.gvsig.fmap.geom.primitive.impl.EllipticArc2DZ;
61 33388 jpiera
import org.gvsig.fmap.geom.primitive.impl.Envelope2D;
62
import org.gvsig.fmap.geom.primitive.impl.Envelope3D;
63 37336 fdiaz
import org.gvsig.fmap.geom.primitive.impl.Geometry2D;
64 38545 jldominguez
import org.gvsig.fmap.geom.primitive.impl.Geometry2DZ;
65 38596 cordinyana
import org.gvsig.fmap.geom.primitive.impl.Point2DGeometryType;
66
import org.gvsig.fmap.geom.primitive.impl.Point3DGeometryType;
67 27029 jpiera
import org.gvsig.fmap.geom.primitive.impl.Solid2DZ;
68
import org.gvsig.fmap.geom.primitive.impl.Spline2D;
69
import org.gvsig.fmap.geom.primitive.impl.Spline2DZ;
70
import org.gvsig.fmap.geom.primitive.impl.Surface2D;
71
import org.gvsig.fmap.geom.primitive.impl.Surface2DZ;
72 37322 cordinyana
import org.gvsig.fmap.geom.type.persistence.GeometryTypePersistenceFactory;
73 33650 jpiera
import org.gvsig.tools.ToolsLocator;
74 34690 jjdelcerro
import org.gvsig.tools.dataTypes.DataTypesManager;
75 30633 cordinyana
import org.gvsig.tools.library.AbstractLibrary;
76 30580 cordinyana
import org.gvsig.tools.library.LibraryException;
77 33650 jpiera
import org.gvsig.tools.persistence.PersistenceManager;
78 26328 jpiera
79
/**
80
 * Registers the default implementation for {@link GeometryManager}
81 34708 jjdelcerro
 *
82 26328 jpiera
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
83
 */
84 34708 jjdelcerro
public class DefaultGeometryLibrary extends AbstractLibrary {
85 29051 jmvivo
86 35142 cordinyana
    public void doRegistration() {
87
        registerAsImplementationOf(GeometryLibrary.class);
88 34708 jjdelcerro
    }
89
90
    protected void doInitialize() throws LibraryException {
91
        // Register the default GeometryManager
92 26866 jpiera
        GeometryLocator.registerGeometryManager(DefaultGeometryManager.class);
93 34708 jjdelcerro
    }
94 26328 jpiera
95 34708 jjdelcerro
    protected void doPostInitialize() throws LibraryException {
96
        GeometryManager geometryManager = GeometryLocator.getGeometryManager();
97 34690 jjdelcerro
98 34708 jjdelcerro
        DataTypesManager dataTypesManager = ToolsLocator.getDataTypesManager();
99 34690 jjdelcerro
100 34708 jjdelcerro
        dataTypesManager
101 35185 jpiera
        .setCoercion(DataTypes.GEOMETRY, new CoerceToGeometry());
102 34708 jjdelcerro
        dataTypesManager
103 35185 jpiera
        .setCoercion(DataTypes.ENVELOPE, new CoerceToEnvelope());
104 34708 jjdelcerro
        dataTypesManager.setCoercion(DataTypes.STRING, new CoerceToString(
105
            dataTypesManager.getCoercion(DataTypes.STRING)));
106
        dataTypesManager.setCoercion(
107
            DataTypes.BYTEARRAY,
108
            new CoerceToByteArray(dataTypesManager
109
                .getCoercion(DataTypes.BYTEARRAY)));
110 31221 jldominguez
111 34708 jjdelcerro
        GeometryOperation.OPERATION_INTERSECTS_CODE =
112
            GeometryLocator.getGeometryManager().getGeometryOperationCode(
113
                GeometryOperation.OPERATION_INTERSECTS_NAME);
114 29051 jmvivo
115 34708 jjdelcerro
        GeometryOperation.OPERATION_CONTAINS_CODE =
116
            GeometryLocator.getGeometryManager().getGeometryOperationCode(
117
                GeometryOperation.OPERATION_CONTAINS_NAME);
118
119
        // Register the geometries in 2D
120
        geometryManager.registerGeometryType(DefaultNullGeometry.class, "Null",
121
            TYPES.NULL, SUBTYPES.GEOM2D);
122 37336 fdiaz
123
        geometryManager.registerGeometryType(Geometry2D.class, "Geometry2D",
124
                TYPES.GEOMETRY, SUBTYPES.GEOM2D);
125 38545 jldominguez
        geometryManager.registerGeometryType(Geometry2DZ.class, "Geometry3D",
126
            TYPES.GEOMETRY, SUBTYPES.GEOM3D);
127 35185 jpiera
128
        //Register points in 2D
129 38596 cordinyana
        geometryManager.registerGeometryType(new Point2DGeometryType());
130 35185 jpiera
131
        //Register curves in 2D
132 34708 jjdelcerro
        geometryManager.registerGeometryType(Curve2D.class, "Curve2D",
133
            TYPES.CURVE, SUBTYPES.GEOM2D);
134 35185 jpiera
        geometryManager.registerGeometryType(Arc2D.class, "Arc2D",
135
            TYPES.ARC, SUBTYPES.GEOM2D, TYPES.CURVE);
136 34708 jjdelcerro
        geometryManager.registerGeometryType(Spline2D.class, "Spline2D",
137 35185 jpiera
            TYPES.SPLINE, SUBTYPES.GEOM2D, TYPES.CURVE);
138
139
        //Register surfaces in 2D
140 34708 jjdelcerro
        geometryManager.registerGeometryType(Surface2D.class, "Surface2D",
141 35185 jpiera
            TYPES.SURFACE, SUBTYPES.GEOM2D, TYPES.SURFACE);
142
        geometryManager.registerGeometryType(Circle2D.class, "Circle2D",
143
            TYPES.CIRCLE, SUBTYPES.GEOM2D, TYPES.SURFACE);
144
        geometryManager.registerGeometryType(Ellipse2D.class, "Ellipse2D",
145
            TYPES.ELLIPSE, SUBTYPES.GEOM2D, TYPES.SURFACE);
146
        geometryManager.registerGeometryType(EllipticArc2D.class,"EllipticArc2D",
147
            TYPES.ELLIPTICARC, SUBTYPES.GEOM2D, TYPES.SURFACE);
148 34708 jjdelcerro
149 35185 jpiera
        //Register multigeometries in 2D
150
        geometryManager.registerGeometryType(BaseMultiPrimitive2D.class, "MultiPrimitive2D",
151
            TYPES.AGGREGATE, SUBTYPES.GEOM2D);
152
        geometryManager.registerGeometryType(MultiPoint2D.class, "MultiPoint2D",
153
            TYPES.MULTIPOINT, SUBTYPES.GEOM2D, TYPES.AGGREGATE);
154
        geometryManager.registerGeometryType(MultiCurve2D.class, "MultiCurve2D",
155
            TYPES.MULTICURVE, SUBTYPES.GEOM2D, TYPES.AGGREGATE);
156 35613 jpiera
        geometryManager.registerGeometryType(MultiSurface2D.class,"MultiSurface2D",
157 35185 jpiera
            TYPES.MULTISURFACE, SUBTYPES.GEOM2D, TYPES.AGGREGATE);
158
159
        // Register the geometries in 3D
160 34708 jjdelcerro
        geometryManager.registerGeometryType(DefaultNullGeometry.class,
161 34899 jpiera
            TYPES.NULL, SUBTYPES.GEOM3D);
162 35185 jpiera
163
        //Register points in 3D
164 38596 cordinyana
        geometryManager.registerGeometryType(new Point3DGeometryType());
165 35185 jpiera
166
        //Register curves in 3D
167
        geometryManager.registerGeometryType(Curve2DZ.class, "Curve3D",
168
            TYPES.CURVE, SUBTYPES.GEOM3D, new int[0], new int[]{SUBTYPES.GEOM2D});
169
        geometryManager.registerGeometryType(Arc2DZ.class, "Arc3D",
170
            TYPES.ARC, SUBTYPES.GEOM3D, TYPES.CURVE, SUBTYPES.GEOM2D);
171
        geometryManager.registerGeometryType(Spline2DZ.class, "Spline3D",
172
            TYPES.SPLINE, SUBTYPES.GEOM3D, TYPES.CURVE, SUBTYPES.GEOM2D);
173
174
        //Register surfaces in 2D
175
        geometryManager.registerGeometryType(Surface2DZ.class, "Surface3D",
176
            TYPES.SURFACE, SUBTYPES.GEOM3D, new int[0], new int[]{SUBTYPES.GEOM2D});
177
        geometryManager.registerGeometryType(Circle2DZ.class, "Circle3D",
178
            TYPES.CIRCLE, SUBTYPES.GEOM3D, TYPES.SURFACE, SUBTYPES.GEOM2D);
179
        geometryManager.registerGeometryType(Ellipse2DZ.class, "Ellipse3D",
180
            TYPES.ELLIPSE,SUBTYPES.GEOM3D, TYPES.SURFACE, SUBTYPES.GEOM2D);
181 34899 jpiera
        geometryManager.registerGeometryType(EllipticArc2DZ.class, "EllipticArc3D",
182 35185 jpiera
            TYPES.ELLIPTICARC, SUBTYPES.GEOM3D, TYPES.SURFACE, SUBTYPES.GEOM2D);
183
184
        //Register multigeometries in 3D
185 34899 jpiera
        geometryManager.registerGeometryType(MultiPoint2DZ.class, "Multipoint3D",
186 35185 jpiera
            TYPES.MULTIPOINT, SUBTYPES.GEOM3D, TYPES.AGGREGATE, SUBTYPES.GEOM2D);
187
        geometryManager.registerGeometryType(MultiCurve2DZ.class,"MultiCurve3D",
188
            TYPES.MULTICURVE, SUBTYPES.GEOM3D, TYPES.AGGREGATE, SUBTYPES.GEOM2D);
189 35613 jpiera
        geometryManager.registerGeometryType(MultiSurface3D.class,"MultiSurface3D",
190
            TYPES.MULTISURFACE, SUBTYPES.GEOM3D, TYPES.AGGREGATE, SUBTYPES.GEOM2D);
191 34708 jjdelcerro
192 35185 jpiera
        //Register solids
193
        geometryManager.registerGeometryType(Solid2DZ.class, "Solid3D",
194
            TYPES.SOLID, SUBTYPES.GEOM3D);
195 35613 jpiera
        geometryManager.registerGeometryType(MultiSolid2DZ.class,"MultiSolid3D",
196
            TYPES.MULTISOLID, SUBTYPES.GEOM3D, TYPES.AGGREGATE);
197 35185 jpiera
198 34708 jjdelcerro
        // Persistence
199 33388 jpiera
        DefaultEnvelope.registerPersistent();
200
        Envelope2D.registerPersistent();
201
        Envelope3D.registerPersistent();
202 34708 jjdelcerro
203
        PersistenceManager persistenceManager =
204
            ToolsLocator.getPersistenceManager();
205
206 33650 jpiera
        persistenceManager.registerFactory(new GeometryPersistenceFactory());
207 37322 cordinyana
        persistenceManager
208
            .registerFactory(new GeometryTypePersistenceFactory());
209 34708 jjdelcerro
    }
210
}