Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_geometries / src / org / gvsig / fmap / geom / GeometryManager.java @ 29097

History | View | Annotate | Download (17.8 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package org.gvsig.fmap.geom;
42

    
43
import org.gvsig.fmap.geom.exception.CreateEnvelopeException;
44
import org.gvsig.fmap.geom.exception.CreateGeometryException;
45
import org.gvsig.fmap.geom.operation.GeometryOperation;
46
import org.gvsig.fmap.geom.operation.GeometryOperationContext;
47
import org.gvsig.fmap.geom.operation.GeometryOperationException;
48
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
49
import org.gvsig.fmap.geom.primitive.Curve;
50
import org.gvsig.fmap.geom.primitive.Envelope;
51
import org.gvsig.fmap.geom.primitive.GeneralPathX;
52
import org.gvsig.fmap.geom.primitive.NullGeometry;
53
import org.gvsig.fmap.geom.primitive.Point;
54
import org.gvsig.fmap.geom.primitive.Surface;
55
import org.gvsig.fmap.geom.type.GeometryType;
56
import org.gvsig.fmap.geom.type.GeometryTypeNotSupportedException;
57
import org.gvsig.fmap.geom.type.GeometryTypeNotValidException;
58

    
59
/**
60
 * This singleton provides a centralized access to gvSIG's Geometry Model.
61
 * Its responsibilities are:<br>
62
 *
63
 * <ul>
64
 * <li>Offering a set of convenient methods for registering and retrieving geometry types.
65
 * <li>Offering a set of convenient methods for registering and retrieving geometry operations associated
66
 * to one or more geometry types.
67
 * <li>Offering a set of convenient methods for registering and retrieving new geometries.
68
 * <ul>
69
 *
70
 * @author jiyarza
71
 */
72
public interface GeometryManager {
73
        /**
74
         * <p>
75
         * Registers a GeometryOperation associated to a GeometryType.
76
         * Returns an unique index that is used later to identify and invoke the operation.
77
         * </p>
78
         * <p>
79
         * By convention, the return value should be stored in a public constant within the class implementing
80
         * the operation:<BR>
81
         * <pre>
82
         * public class MyOperation extends GeometryOperation {
83
         *   public static final int CODE =
84
         *     GeometryManager.getInstance()
85
         *        .registerGeometryOperation("MyOperation", new MyOperation(), geomType);
86
         * }
87
         * </pre>
88
         * </p>
89
         * @param geomOpName Operation's unique name
90
         * @param geomOp Specific GeometryOperation's instance implementing this operation
91
         * @param geomType GeometryType instance to which this operation should be associated
92
         * @return Index assigned to this operation. This index is used later to access the operation.
93
         *
94
         */
95
        public int registerGeometryOperation(String geomOpName,
96
                        GeometryOperation geomOp, GeometryType geomType);
97

    
98
        /**
99
         * <p>
100
         * Registers a GeometryOperation that is common for all GeometryType (registered yet or not).
101
         * Returns an unique index that is used later to identify and invoke the operation.
102
         * </p>
103
         * <p>
104
         * By convention, the return value should be stored in a public constant within the class implementing
105
         * the operation:<BR>
106
         * <pre>
107
         * public class MyOperation extends GeometryOperation {
108
         *   public static final int CODE =
109
         *     GeometryManager.getInstance()
110
         *        .registerGeometryOperation("MyOperation", new MyOperation());
111
         * }
112
         * </pre>
113
         * </p>
114
         * @param geomOpName Operation's unique name
115
         * @param geomOp Specific GeometryOperation's instance implementing this operation
116
         * @return Index assigned to this operation. This index is used later to access the operation.
117
         */
118
        public int registerGeometryOperation(String geomOpName,
119
                        GeometryOperation geomOp);
120

    
121
        /**
122
         * <p>
123
         * Registers a GeometryOperation associated to a GeometryType, that has been specified 
124
         * using the type code and the subtype code.
125
         * Returns an unique index that is used later to identify and invoke the operation.
126
         * </p>
127
         * <p>
128
         * By convention, the return value should be stored in a public constant within the class implementing
129
         * the operation:<BR>
130
         * <pre>
131
         * public class MyOperation extends GeometryOperation {
132
         *   public static final int CODE =
133
         *     GeometryManager.getInstance()
134
         *        .registerGeometryOperation("MyOperation", new MyOperation(), TYPES.POINT, SUBTYPES.GEOM2D);
135
         * }
136
         * </pre>
137
         * </p>
138
         * <p>
139
         * This method is only used if you have not a reference to the GeometryType associated to the
140
         * geometry class. If you have such reference then it is slightly faster to use the method that receives
141
         * the GeometryType.<br>
142
         * </p>
143
         * @param geomOpName Operation's unique name
144
         * @param geomOp Specific GeometryOperation's instance implementing this operation
145
         * @param type
146
         * Type of geometry. Must be a value defined in {@link Geometry.TYPES}
147
         * @param subType
148
         * SubType of geometry. Must be a value defined in {@link Geometry.SUBTYPES}
149
         * @return Index assigned to this operation. This index is used later to access the operation.
150
         * @throws GeometryTypeNotSupportedException 
151
         * @throws GeometryTypeNotValidException 
152
         */
153
        public int registerGeometryOperation(String geomOpName,
154
                        GeometryOperation geomOp, int type, int subType) throws GeometryTypeNotSupportedException, GeometryTypeNotValidException;
155

    
156
        /**
157
         * <p>
158
         * Registers a GeometryOperation associated to all the geometries with a concrete type.
159
         * Returns an unique index that is used later to identify and invoke the operation.<br>
160
         * </p>
161
         * <p>
162
         * By convention, the return value should be stored in a public constant within the class implementing
163
         * the operation:<BR>
164
         * <pre>
165
         * public class MyOperation extends GeometryOperation {
166
         *   public static final int CODE =
167
         *     GeometryManager.getInstance()
168
         *        .registerGeometryOperation("MyOperation", new MyOperation(), TYPES.POINT);
169
         * }
170
         * </pre>
171
         * </p>
172
         * @param geomOpName Operation's unique name
173
         * @param geomOp Specific GeometryOperation's instance implementing this operation
174
         * @param type
175
         * Type of geometry. Must be a value defined in {@link Geometry.TYPES}
176
         * @return Index assigned to this operation. This index is used later to access the operation.
177
         */
178
        public int registerGeometryOperation(String geomOpName,
179
                        GeometryOperation geomOp, int type);
180

    
181

    
182
        /**
183
         * <p>
184
         * Registers a GeometryOperation associated to all the geometries with a concrete subtype.
185
         * Returns an unique index that is used later to identify and invoke the operation.<br>
186
         * </p>
187
         * <p>
188
         * By convention, the return value should be stored in a public constant within the class implementing
189
         * the operation:<BR>
190
         * <pre>
191
         * public class MyOperation extends GeometryOperation {
192
         *   public static final int CODE =
193
         *     GeometryManager.getInstance()
194
         *        .registerGeometryOperation("MyOperation", new MyOperation(), SUBTYPES.GEOM2D);
195
         * }
196
         * </pre>
197
         * </p>
198
         * @param geomOpName Operation's unique name
199
         * @param geomOp Specific GeometryOperation's instance implementing this operation
200
         * @param subType
201
         * SubType of geometry. Must be a value defined in {@link Geometry.SUBTYPES}
202
         * @return Index assigned to this operation. This index is used later to access the operation.
203
         */
204
        public int registerGeometryOperationBySubtype(String geomOpName,
205
                        GeometryOperation geomOp, int subType);
206

    
207
        /**
208
         * <p>
209
         * Registers a Geometry implementation class with a predefined geometry type and returns the
210
         * associated GeometryType instance. Available predefined types are defined in {@link Geometry.TYPES}
211
         * If the class is already registered then this method throws an IllegalArgumentException.<br>
212
         *
213
         * How to register a geometry class with a predefined type:
214
         * <pre>
215
         *
216
         * public class Point2D implements Point {
217
         *   private static final GeometryType geomType = GeometryManager.getInstance()
218
         *           .registerBasicGeometryType(Point2D.class, "Point2D", Geometry.TYPES.POINT);
219
         *
220
         *   public static final int CODE = geomType.getType();
221
         * ...
222
         *   public int getType() {
223
         *      return CODE;
224
         *   }
225
         * }
226
         * </pre>
227
         *
228
         * @param geomClass
229
         *            Geometry subclass. It must not be null and must implement Geometry, otherwise an exception
230
         *            is raised.
231
         * @param name
232
         *                           Symbolic name for the geometry type, it can be null. If it is null then the symbolic name
233
         *                       will be the simple class name.
234
         * @param type
235
         * Type of geometry. Must be a value defined in {@link Geometry.TYPES}
236
         * @param subType
237
         * SubType of geometry. Must be a value defined in {@link Geometry.SUBTYPES}
238
         * @return Instance of GeometryType associated to the Geometry implementation class
239
         *         geomClass
240
         * @throws IllegalArgumentException
241
         *             If geomClass is null or does not implement Geometry
242
         */
243
        public GeometryType registerGeometryType(Class geomClass, String name, int type, int subType);
244

    
245
        /**
246
         * Registers a Geometry implementation as a new geometry type and returns the
247
         * associated GeometryType instance. If the class is already registered
248
         * then this method throws an IllegalArgumentException.<br>
249
         *
250
         * In this case the symbolic name will be the geometry's simple class name
251
         *
252
         * How to register a new geometry type:
253
         * <pre>
254
         *
255
         * public class MyGeom3D implements Solid {
256
         *   private static final GeometryType geomType = GeometryManager.getInstance()
257
         *           .registerGeometryType(MyGeom3D.class);
258
         *
259
         *   public static final int .CODE = geomType.getType();
260
         * ...
261
         *   public int getType() {
262
         *      return .CODE;
263
         *   }
264
         * }
265
         * </pre>
266
         *
267
         * @param geomClass Geometry implementation class. It must not be null and must implement Geometry,
268
         * otherwise an exception is thrown.
269
         * @param type
270
         * Type of geometry. Must be a value defined in {@link Geometry.TYPES}
271
         * @param subType
272
         * SubType of geometry. Must be a value defined in {@link Geometry.SUBTYPES}
273
         * @return Instance of GeometryType associated to the Geometry implementation class
274
         * @throws IllegalArgumentException
275
         *             If geomClass is null or does not implement Geometry
276
         */
277
        public GeometryType registerGeometryType(Class geomClass, int type, int subType);
278

    
279
        /**
280
         * Returns an instance of GeometryType given the associated Geometry implementation
281
         * class.
282
         *
283
         *  * @param type
284
         * Type of geometry. Must be a value defined in {@link Geometry.TYPES}
285
         * @param subType
286
         * SubType of geometry. Must be a value defined in {@link Geometry.SUBTYPES}
287
         * @return Instance of GeometryType associated to the type and the subtype
288
         * @throws GeometryTypeNotValidException 
289
         */
290
        public GeometryType getGeometryType(int type, int subType) throws GeometryTypeNotSupportedException, GeometryTypeNotValidException;
291

    
292
        /**
293
         * Returns the associated GeometryType given the fully qualified name of
294
         * the Geometry implementation class.
295
         *
296
         * @param className
297
         *            Fully qualified name of the Geometry implementation class
298
         * @return GeometryType associated to the class
299
         */
300
        public GeometryType getGeometryType(String className) throws GeometryTypeNotSupportedException;
301

    
302
        /**
303
         * This method creates a {@link Geometry} with the type specified 
304
         * by this GeometryType. The geometry is empty, and all the internal 
305
         * attributes must be assigned to a value when the geometry has 
306
         * been created.
307
         * 
308
         * This example creates a point2D and sets the coordinates to 1,1:
309
         * 
310
         * <pre>
311
         * Point point = (Point)GeometryLocator
312
         *                 .getGeometryManager().create(Point2D.CODE);
313
         *         point.setX(1);
314
         *         point.setY(1);
315
         * </pre>
316
         * 
317
         * @param geomType
318
         * The geometry type
319
         * @return
320
         * A instance of a geometry.
321
         * @throws CreateGeometryException
322
         * This exception is thrown when the manager can not create
323
         * the geometry.
324
         */
325
        public Geometry create(GeometryType geomType) throws CreateGeometryException;
326

    
327
        public Envelope createEnvelope(int subType) throws CreateEnvelopeException;
328

    
329
        public Envelope createEnvelope(double minX, double minY, double maxX, double maxY, int subType) throws CreateEnvelopeException;
330

    
331
        /**
332
         * This method creates a {@link Geometry} with the type specified 
333
         * by this name. If a geometry with this name doesn't exist, a
334
         * {@link IllegalArgumentException} is thrown. The geometry is empty, 
335
         * and all the internal attributes must be assigned to a value when 
336
         * the geometry has  been created.
337
         * 
338
         * This example creates a point2D and sets the coordinates to 1,1:
339
         * It supposes that there is a Point2D class with name "Point2D".
340
         *  
341
         * <pre>
342
         * Point point = (Point)GeometryLocator
343
         *                 .getGeometryManager().create("Point2D");
344
         *         point.setX(1);
345
         *         point.setY(1);
346
         * </pre>
347
         * 
348
         * @param name
349
         * The name of the geometry type
350
         * @return
351
         * A instance of a geometry.
352
         * @throws CreateGeometryException
353
         * This exception is thrown when the manager can not create
354
         * the geometry.
355
         */
356
        public Geometry create(String name) throws CreateGeometryException;
357

    
358
        /**
359
         * This method creates a {@link Geometry} with the type specified 
360
         * by this id. If a geometry with this id doesn't exist, a
361
         * {@link IllegalArgumentException} is thrown. The geometry is empty, 
362
         * and all the internal attributes must be assigned to a value when 
363
         * the geometry has  been created.
364
         * 
365
         * This example creates a point2D and sets the coordinates to 1,1.
366
         * It supposes that there is a Point2D class with the id 1.
367
         * 
368
         * <pre>
369
         * Point point = (Point)GeometryLocator
370
         *                 .getGeometryManager().create(1);
371
         *         point.setX(1);
372
         *         point.setY(1);
373
         * </pre>
374
         * 
375
         * @param type
376
         * Type of geometry. Must be a value defined in {@link Geometry.TYPES}
377
         * @param subType
378
         * SubType of geometry. Must be a value defined in {@link Geometry.SUBTYPES}
379
         * @return
380
         * A instance of a geometry.
381
         * @throws CreateGeometryException
382
         * This exception is thrown when the manager can not create
383
         * the geometry.
384
         */
385
        public Geometry create(int type, int subType) throws CreateGeometryException;
386

    
387
        public NullGeometry createNullGeometry(int subType) throws CreateGeometryException;
388

    
389
        /**
390
         * Create point. If there is an
391
         * error return <code>null</code> and add the error
392
         * to the log
393
         * @param x
394
         * The X coordinate
395
         * @param y
396
         * The y coordinate
397
         * @return
398
         * The Point
399
         */
400
        public Point createPoint(double x, double y, int subType) throws CreateGeometryException;
401

    
402
        public Curve createCurve(GeneralPathX generalPathX, int subType) throws CreateGeometryException;
403

    
404
        public Surface createSurface(GeneralPathX generalPathX, int subType) throws CreateGeometryException; 
405

    
406
        /**
407
         * Returns an operation given the Geometry type, the Geometry subtype and and the operation
408
         * code. If opCode corresponds to a common operation (a common operation is an operation
409
         * registered for all geometries), then this method returns the common operation.
410
         * <br>
411
         * For better performance, if you need to call an operation multiple times,
412
         * use this method only once and keep the returned object in a local variable
413
         * over which you can iterate. For instance:
414
         *
415
         * <pre>
416
         * ...
417
         *  // Get the operation you need
418
         * GeometryManager gm = GeometryManager.getInstance();
419
         * GeometryOperation geomOp = null;
420
         * try {
421
         *    geomOp = gm.getGeometryOperation(Draw2D.CODE);
422
         * } catch (GeometryTypeNotSupportedException gtnse) {
423
         *    // treat exception
424
         * } catch (GeometryOperationNotSupportedException gonse) {
425
         *    // treat exception
426
         * }
427
         *
428
         *  // Fill the operation context with required params
429
         * GeometryOperationContext ctx = new GeometryOperationContext();
430
         *
431
         *  // Here is the main loop where you call the operation
432
         * for (int i=0; i<MyGeometries.length; i++) {
433
         *    Object result = geomOp.invoke(myGeometries[i], ctx);
434
         * }
435
         *
436
         * </pre>
437
         *
438
         * @param opCode
439
         * @param type
440
         * Type of geometry. Must be a value defined in {@link Geometry.TYPES}
441
         * @param subType
442
         * SubType of geometry. Must be a value defined in {@link Geometry.SUBTYPES}
443
         * @return Geometry operation
444
         * @throws GeometryTypeNotValidException 
445
         */
446
        public GeometryOperation getGeometryOperation(int opCode, int type, int subType) throws GeometryTypeNotSupportedException, GeometryOperationNotSupportedException, GeometryTypeNotValidException;
447

    
448
        /**
449
         * Invokes an operation given its code, the geometry and the operation context holding the
450
         * parameters required for the operation.
451
         *
452
         * @param opCode Operation code.
453
         * @param geom Geometry to which apply the operation
454
         * @param ctx Context holding the operation parameters
455
         * @return The object returned by an operation, depends on each operation.
456
         */
457
        public Object invokeOperation(int opCode, Geometry geom, GeometryOperationContext ctx) throws GeometryOperationNotSupportedException, GeometryOperationException;
458

    
459
        /**
460
         * Invokes an operation given its code, the geometry and the operation context holding the
461
         * parameters required for the operation.
462
         *
463
         * @param geomOpName Operation name.
464
         * @param geom Geometry to which apply the operation
465
         * @param ctx Context holding the operation parameters
466
         * @return The object returned by an operation, depends on each operation.
467
         */
468
        public Object invokeOperation(String geomOpName, Geometry geom, GeometryOperationContext ctx) throws GeometryOperationNotSupportedException, GeometryOperationException;
469

    
470
        /**
471
         * Unregisters a geometry class.
472
         * @param geomTypeName
473
         * @return
474
         */
475
        public GeometryType unregisterGeometryType(Class geomClass);
476

    
477
}