Revision 38596

View differences:

branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/impl/DefaultGeometryLibrary.java
62 62
import org.gvsig.fmap.geom.primitive.impl.Envelope3D;
63 63
import org.gvsig.fmap.geom.primitive.impl.Geometry2D;
64 64
import org.gvsig.fmap.geom.primitive.impl.Geometry2DZ;
65
import org.gvsig.fmap.geom.primitive.impl.Point2D;
66
import org.gvsig.fmap.geom.primitive.impl.Point2DZ;
65
import org.gvsig.fmap.geom.primitive.impl.Point2DGeometryType;
66
import org.gvsig.fmap.geom.primitive.impl.Point3DGeometryType;
67 67
import org.gvsig.fmap.geom.primitive.impl.Solid2DZ;
68 68
import org.gvsig.fmap.geom.primitive.impl.Spline2D;
69 69
import org.gvsig.fmap.geom.primitive.impl.Spline2DZ;
......
126 126
            TYPES.GEOMETRY, SUBTYPES.GEOM3D);
127 127

  
128 128
        //Register points in 2D
129
        geometryManager.registerGeometryType(Point2D.class, "Point2D",
130
            TYPES.POINT, SUBTYPES.GEOM2D);
129
        geometryManager.registerGeometryType(new Point2DGeometryType());
131 130

  
132 131
        //Register curves in 2D
133 132
        geometryManager.registerGeometryType(Curve2D.class, "Curve2D",
......
162 161
            TYPES.NULL, SUBTYPES.GEOM3D);
163 162

  
164 163
        //Register points in 3D
165
        geometryManager.registerGeometryType(Point2DZ.class, "Point3D",
166
            TYPES.POINT, SUBTYPES.GEOM3D, new int[0], new int[]{SUBTYPES.GEOM2D});
164
        geometryManager.registerGeometryType(new Point3DGeometryType());
167 165

  
168 166
        //Register curves in 3D
169 167
        geometryManager.registerGeometryType(Curve2DZ.class, "Curve3D", 
branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/impl/DefaultGeometryManager.java
57 57
import org.gvsig.fmap.geom.primitive.GeneralPathX;
58 58
import org.gvsig.fmap.geom.primitive.NullGeometry;
59 59
import org.gvsig.fmap.geom.primitive.Point;
60
import org.gvsig.fmap.geom.primitive.PointGeometryType;
60 61
import org.gvsig.fmap.geom.primitive.Surface;
61 62
import org.gvsig.fmap.geom.primitive.impl.DefaultNullGeometry;
62 63
import org.gvsig.fmap.geom.primitive.impl.Envelope2D;
......
109 110
     */
110 111
    private GeometryType[][] geometryTypes;
111 112

  
112
    /**
113
     * GeometryType index counter. Each time a new geometry type (not
114
     * predefined) is registered it is assigned this counter's value as index
115
     * and after that
116
     * it is incremented by 1
117
     */
118
    private int geometryTypeIndex = 0;// Geometry.EXTENDED_GEOMTYPE_OFFSET;
119
    // //65536;//2^16
120

  
121 113
    // Initially create a matrix of 17 x 6, which are the current default
122 114
    // types and subtypes. If another type or subtype is registered, the
123 115
    // matrix will grow as needed
......
261 253
    }
262 254

  
263 255
    public GeometryType registerGeometryType(Class geomClass, String name,
264
        int type, int subType, int[] superTypes, int[] superSubTypes) {
265
        return registerGeometryType(geomClass, name, geometryTypeIndex++, type, subType,
266
            superTypes, superSubTypes);
267
    }
268

  
269
    public GeometryType registerGeometryType(Class geomClass, String name,
270 256
        int type, int subType, int[] superTypes) {
271 257
        return registerGeometryType(geomClass, name, type, subType,
272 258
            superTypes, new int[0]);
......
287 273
     *   private static final GeometryType geomType = GeometryManager.getInstance()
288 274
     *    .registerBasicGeometryType(Point2D.class, "Point2D", Geometry.TYPES.POINT);
289 275
     * 
290
     *   public static final int CODE = geomType.getId();
291 276
     * ...
292 277
     *   public int getType() {
293 278
     *      return geomType.getType();
......
317 302
     * @throws IllegalArgumentException
318 303
     *             If geomClass is null or does not implement Geometry
319 304
     */
320
    private GeometryType registerGeometryType(Class geomClass, String name,
321
        int id, int type, int subType, int[] superTypes, int superSubTypes[]) {
305
    public GeometryType registerGeometryType(Class geomClass, String name,
306
        int type, int subType, int[] superTypes, int superSubTypes[]) {
322 307
        if (geomClass == null) {
323 308
            throw new IllegalArgumentException("geomClass cannot be null.");
324 309
        }
......
333 318
        if (type >= geometryTypes.length || subType >= geometryTypes[0].length
334 319
            || (geomType = geometryTypes[type][subType]) == null) {
335 320
            geomType =
336
                new DefaultGeometryType(geomClass, name, id, type, subType,
321
                new DefaultGeometryType(geomClass, name, type, subType,
337 322
                    superTypes, superSubTypes);
338 323
            registerGeometryType(geomType);
339 324
            geometryTypeName.put(geomClass.getName(), geomType);
......
345 330
        return geomType;
346 331
    }
347 332

  
348
    private void registerGeometryType(GeometryType geometryType) {
333
    public void registerGeometryType(GeometryType geometryType) {
349 334
        if (geometryType.getType() >= geometryTypes.length
350 335
            || geometryType.getSubType() >= geometryTypes[0].length) {
351 336

  
......
525 510
        org.gvsig.fmap.geom.primitive.Point min = null;
526 511
        org.gvsig.fmap.geom.primitive.Point max = null;
527 512
        try {
528
            GeometryType gType = getGeometryType(TYPES.POINT, subType);
529
            min = (Point) gType.create();
530
            min.setX(minX);
531
            min.setY(minY);
532
            max = (Point) gType.create();
533
            max.setX(maxX);
534
            max.setY(maxY);
535
            // min = createPoint(minX, minY, subType);
536
            // max = createPoint(maxX, maxY, subType);
537
        } catch (CreateGeometryException e) {
538
            throw new CreateEnvelopeException(subType, e);
513
            PointGeometryType gType = (PointGeometryType) getGeometryType(TYPES.POINT, subType);
514
            min = gType.createPoint(minX, minY);
515
            max = gType.createPoint(maxX, maxY);
539 516
        } catch (GeometryTypeNotSupportedException e) {
540 517
            throw new CreateEnvelopeException(subType, e);
541 518
        } catch (GeometryTypeNotValidException e) {
branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/GeometryManager.java
359 359

  
360 360
    /**
361 361
     * <p>
362
     * Registers a GeometryType instance. 
363
     * </p>
364
     * 
365
     * @param geometryType
366
     *            A {@link GeometryType} instance to create {@link Geometry} objects
367
     */
368
    public void registerGeometryType(GeometryType geometryType);
369
    
370
    /**
371
     * <p>
362 372
     * Registers a Geometry implementation class with a predefined geometry type
363 373
     * and returns the associated GeometryType instance. Available predefined
364 374
     * types are defined in {@link Geometry.TYPES} and the subtypes are defined
branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/primitive/impl/Point2DGeometryType.java
1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2012 gvSIG Association
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.fmap.geom.primitive.impl;
24

  
25
import org.gvsig.fmap.geom.Geometry;
26
import org.gvsig.fmap.geom.exception.CreateGeometryException;
27
import org.gvsig.fmap.geom.primitive.Point;
28
import org.gvsig.fmap.geom.primitive.PointGeometryType;
29
import org.gvsig.fmap.geom.type.AbstractGeometryType;
30

  
31
/**
32
 * Geometry type implementation for the creation of {@link Point2D} objects.
33
 * 
34
 * @author gvSIG Team
35
 */
36
public class Point2DGeometryType extends AbstractGeometryType implements
37
    PointGeometryType {
38

  
39
    public String getName() {
40
        return "Point2D";
41
    }
42

  
43
    public int getType() {
44
        return Geometry.TYPES.POINT;
45
    }
46

  
47
    public int getSubType() {
48
        return Geometry.SUBTYPES.GEOM2D;
49
    }
50

  
51
    public boolean isTypeOf(int geometryType) {
52
        return Geometry.TYPES.POINT == geometryType
53
            || Geometry.TYPES.GEOMETRY == geometryType;
54
    }
55

  
56
    public boolean isSubTypeOf(int geometrySubType) {
57
        return Geometry.SUBTYPES.GEOM2D == geometrySubType;
58
    }
59

  
60
    public Geometry create() throws CreateGeometryException {
61
        return new Point2D(this);
62
    }
63

  
64
    public Point createPoint(double x, double y) {
65
        return new Point2D(this, x, y);
66
    }
67

  
68
    public Point createPoint(double[] coordinates) {
69
        return new Point2D(this, coordinates[0], coordinates[1]);
70
    }
71

  
72
}
branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/primitive/impl/Point3DGeometryType.java
1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2012 gvSIG Association
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.fmap.geom.primitive.impl;
24

  
25
import org.gvsig.fmap.geom.Geometry;
26
import org.gvsig.fmap.geom.exception.CreateGeometryException;
27
import org.gvsig.fmap.geom.primitive.Point;
28

  
29
/**
30
 * Geometry type implementation for the creation of {@link Point3D} objects.
31
 * 
32
 * @author gvSIG Team
33
 */
34
public class Point3DGeometryType extends Point2DGeometryType {
35

  
36
    public String getName() {
37
        return "Point3D";
38
    }
39

  
40
    public int getSubType() {
41
        return Geometry.SUBTYPES.GEOM3D;
42
    }
43

  
44
    public boolean isSubTypeOf(int geometrySubType) {
45
        return Geometry.SUBTYPES.GEOM3D == geometrySubType
46
            || super.isSubTypeOf(geometrySubType);
47
    }
48

  
49
    public Geometry create() throws CreateGeometryException {
50
        return new Point2DZ(this);
51
    }
52

  
53
    public Point createPoint(double x, double y) {
54
        return new Point2DZ(x, y, 0.0d, this);
55
    }
56

  
57
    public Point createPoint(double[] coordinates) {
58
        return new Point2DZ(coordinates[0], coordinates[1], coordinates[2],
59
            this);
60
    }
61

  
62
}
branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/primitive/PointGeometryType.java
1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2012 gvSIG Association
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.fmap.geom.primitive;
24

  
25
import org.gvsig.fmap.geom.type.GeometryType;
26

  
27
/**
28
 * Geometry type for point geometries.
29
 * 
30
 * @author gvSIG Team
31
 */
32
public interface PointGeometryType extends GeometryType {
33

  
34
    /**
35
     * Creates a new point object 
36
     * @param x the x coordinate of the point
37
     * @param y the y coordinate of the point
38
     * @return the new point
39
     */
40
    Point createPoint(double x, double y);
41
    
42
    /**
43
     * Creates a new point object 
44
     * @param coordinates the coordinates of the point
45
     * @return the new point
46
     */
47
    Point createPoint(double[] coordinates);
48
}
branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/type/GeometryType.java
1 1
package org.gvsig.fmap.geom.type;
2 2

  
3 3
import org.gvsig.fmap.geom.Geometry;
4
import org.gvsig.fmap.geom.GeometryManager;
5 4
import org.gvsig.fmap.geom.exception.CreateGeometryException;
6 5
import org.gvsig.fmap.geom.operation.GeometryOperation;
7 6

  
......
13 12
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
14 13
 */
15 14
public interface GeometryType {
16
		
17
	/**
18
	 * @return the identifier of the geometry type. This identifier
19
	 * is assigned by the {@link GeometryManager} in run time.
20
	 */
21
	public int getId();
22 15
	
23 16
	/**
24 17
	 * @return the name of the geometry type.
branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/type/AbstractGeometryType.java
1
package org.gvsig.fmap.geom.type;
2

  
3
import java.util.ArrayList;
4
import java.util.List;
5

  
6
import org.gvsig.fmap.geom.operation.GeometryOperation;
7

  
8
public abstract class AbstractGeometryType implements GeometryType {
9

  
10
    /**
11
     * Registered operations for a concrete geometry type
12
     */
13
    private List geometryOperations = new ArrayList();
14
    
15
    public boolean isTypeOf(GeometryType geometryType) {
16
        return isTypeOf(geometryType.getType());
17
    }
18

  
19
    public boolean isSubTypeOf(GeometryType geometryType) {
20
        return isSubTypeOf(geometryType.getSubType());
21
    }
22

  
23
    public void setGeometryOperation(int index, GeometryOperation geomOp) {
24
        while (index > geometryOperations.size()) {
25
            geometryOperations.add(null);
26
        }
27

  
28
        if (index == geometryOperations.size()) {
29
            geometryOperations.add(geomOp);
30
        } else {
31
            geometryOperations.set(index, geomOp);
32
        }
33
    }
34

  
35
    public GeometryOperation getGeometryOperation(int index) {
36
        return (GeometryOperation) geometryOperations.get(index);
37
    }
38

  
39
    public boolean equals(Object obj) {
40
        if (obj instanceof GeometryType) {
41
            GeometryType other = (GeometryType) obj;
42
            return getType() == other.getType()
43
                && getSubType() == other.getSubType();
44
        }
45
        return false;
46
    }
47

  
48
    protected List getGeometryOperations() {
49
        return geometryOperations;
50
    }
51

  
52
    public String toString() {
53
        StringBuffer sb =
54
            new StringBuffer("[").append(getName()).append(",[")
55
                .append(getGeometryOperations().toString()).append("]");
56

  
57
        return sb.toString();
58
    }
59

  
60
}
branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/type/impl/DefaultGeometryType.java
28 28
package org.gvsig.fmap.geom.type.impl;
29 29

  
30 30
import java.lang.reflect.Constructor;
31
import java.util.ArrayList;
32
import java.util.List;
33 31

  
34 32
import org.gvsig.fmap.geom.Geometry;
35 33
import org.gvsig.fmap.geom.GeometryManager;
36 34
import org.gvsig.fmap.geom.exception.CreateGeometryException;
37
import org.gvsig.fmap.geom.operation.GeometryOperation;
35
import org.gvsig.fmap.geom.type.AbstractGeometryType;
38 36
import org.gvsig.fmap.geom.type.GeometryType;
39 37

  
40 38
/**
41 39
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
42 40
 */
43
public class DefaultGeometryType implements GeometryType {
44
	/** 
45
	 * The geometry identifier
46
	 */
47
	private int id;
41
public class DefaultGeometryType extends AbstractGeometryType {
48 42
	
49 43
	/** 
50 44
	 * Geometry type name
......
68 62
	 */
69 63
	private int subType;	
70 64
		
71
	/** 
72
	 * Registered operations for a concrete geometry type
73
	 */
74
	private List geometryOperations = new ArrayList();
75
	
76 65
	/**
77 66
	 * Super types of a geometry. e.g: the super type of an
78 67
	 * arc is a curve, the super type of a circle is a surface...
......
114 103
     * @param superSubTypes
115 104
     * The superSubtypes of the geometry type      
116 105
     */
117
    public DefaultGeometryType(Class geomClass, String name, int id, int type, int subType, 
106
    public DefaultGeometryType(Class geomClass, String name, int type, int subType, 
118 107
        int[] superTypes, int[] superSubTypes) {
119 108
        this.geometryClass = geomClass;
120 109
        if (name == null) {
......
122 111
        } else {
123 112
            this.name = name;
124 113
        }
125
        this.id = id;       
126 114
        this.type = type;   
127 115
        this.subType = subType;
128 116
        this.superTypes = superTypes;
......
155 143
	 * @param type
156 144
	 * The geometry abstract type			
157 145
	 */
158
	public DefaultGeometryType(Class geomClass, String name, int id, int type, int subType) {
159
		this(geomClass, name, id, type, subType, new int[0], new int[0]);
146
	public DefaultGeometryType(Class geomClass, String name, int type, int subType) {
147
		this(geomClass, name, type, subType, new int[0], new int[0]);
160 148
	}
161 149
	
162 150
	/**
......
175 163
		} 
176 164
	}
177 165
	
178
	/**
179
	 * Guardamos una referencia a una instancia de la operación en el índice que se pasa como parámetro.
180
	 * Si el índice ya está ocupado se sobrescribe.
181
	 * 
182
	 * @param index
183
	 * @param geomOp
184
	 */
185
	public void setGeometryOperation(int index, GeometryOperation geomOp) {
186
		
187
		while (index > geometryOperations.size()) {
188
			geometryOperations.add(null);
189
		}
190
		
191
		if (index == geometryOperations.size()) {
192
			geometryOperations.add(geomOp);
193
		} else {				
194
			geometryOperations.set(index, geomOp);
195
		}
196
	}
197
	
198
	public GeometryOperation getGeometryOperation(int index) {
199
		return (GeometryOperation) geometryOperations.get(index);
200
	}
201
	
202 166
	public Class getGeometryClass() {
203 167
		return geometryClass;
204 168
	}
205 169
	
206
	public String toString() {
207
		StringBuffer sb = new StringBuffer("[")
208
		.append(geometryClass.getName())
209
		.append(",[")
210
		.append(geometryOperations.toString())
211
		.append("]");
212
		
213
		return sb.toString();
214
	}
215
	
216
	public int getId() {
217
		return id;
218
	}
219

  
220 170
	public String getName() {
221 171
		return name;
222 172
	}
......
253 203
        return false;
254 204
    }
255 205

  
256
    public boolean isTypeOf(GeometryType geometryType) {
257
        return isTypeOf(geometryType.getType());
258
    }
259

  
260
    public boolean isSubTypeOf(GeometryType geometryType) {
261
        return isSubTypeOf(geometryType.getSubType());
262
    }
263

  
264
    public boolean equals(Object obj) {
265
        if (obj instanceof GeometryType) {
266
            GeometryType other = (GeometryType) obj;
267
            return type == other.getType() && subType == other.getSubType();
268
        }
269
        return false;
270
    }
271 206
}
272 207

  

Also available in: Unified diff