Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libFMap_geometries / src / org / gvsig / fmap / geom / GeometryManager.java @ 29166

History | View | Annotate | Download (21.6 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.aggregate.MultiCurve;
44
import org.gvsig.fmap.geom.aggregate.MultiSurface;
45
import org.gvsig.fmap.geom.exception.CreateEnvelopeException;
46
import org.gvsig.fmap.geom.exception.CreateGeometryException;
47
import org.gvsig.fmap.geom.operation.GeometryOperation;
48
import org.gvsig.fmap.geom.operation.GeometryOperationContext;
49
import org.gvsig.fmap.geom.operation.GeometryOperationException;
50
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
51
import org.gvsig.fmap.geom.primitive.Curve;
52
import org.gvsig.fmap.geom.primitive.Envelope;
53
import org.gvsig.fmap.geom.primitive.GeneralPathX;
54
import org.gvsig.fmap.geom.primitive.NullGeometry;
55
import org.gvsig.fmap.geom.primitive.Point;
56
import org.gvsig.fmap.geom.primitive.Surface;
57
import org.gvsig.fmap.geom.type.GeometryType;
58
import org.gvsig.fmap.geom.type.GeometryTypeNotSupportedException;
59
import org.gvsig.fmap.geom.type.GeometryTypeNotValidException;
60

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

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

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

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

    
187

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

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

    
243
        /**
244
         * <p>
245
         * Registers a Geometry implementation class with a predefined geometry type and returns the
246
         * associated GeometryType instance. Available predefined types are defined in {@link Geometry.TYPES}
247
         * and the subtypes are defined in {@link Geometry.SUBTYPES}.
248
         * </p>
249
         * <p>
250
         * In this case the symbolic name will be the geometry's simple class name
251
         * </p>
252
         * How to register a new geometry type:
253
         * <pre>
254
         * GeometryType geomType = GeometryLocator.getGeometryManager().
255
         *      registerBasicGeometryType(Point2D.class, Geometry.TYPES.POINT, Geometry.SYBTYPES.GEOM2D);
256
         * </pre>
257
         *
258
         * @param geomClass Geometry implementation class. It must not be null and must implement Geometry,
259
         * otherwise an exception is thrown.
260
         * @param type
261
         * Type of geometry. Must be a value defined in {@link Geometry.TYPES}
262
         * @param subType
263
         * SubType of geometry. Must be a value defined in {@link Geometry.SUBTYPES}
264
         * @return Instance of GeometryType associated to the Geometry implementation class
265
         * @throws IllegalArgumentException
266
         *             If geomClass is null or does not implement Geometry
267
         */
268
        public GeometryType registerGeometryType(Class geomClass, int type, int subType);
269

    
270
        /**
271
         * <p>
272
         * Returns an instance of GeometryType given the Geometry type
273
         * and the subtype.
274
         * </p>
275
         * @param type
276
         * Type of geometry. Must be a value defined in {@link Geometry.TYPES}
277
         * @param subType
278
         * SubType of geometry. Must be a value defined in {@link Geometry.SUBTYPES}
279
         * @return Instance of GeometryType associated to the type and the subtype
280
         * @throws GeometryTypeNotSupportedException
281
         * Returns this exception if there is not a registered geometry with
282
         * these type and subtype
283
         * @throws GeometryTypeNotValidException
284
         * Returns if the type and subtype are not valid
285
         */
286
        public GeometryType getGeometryType(int type, int subType) throws GeometryTypeNotSupportedException, GeometryTypeNotValidException;
287

    
288
        /**
289
         * <p>
290
         * This method creates a {@link Geometry} with the type specified
291
         * by this GeometryType. The geometry is empty, and all the internal
292
         * attributes must be assigned to a value when the geometry has
293
         * been created.
294
         * </p>
295
         * <p>
296
         * This example creates a point2D and sets the coordinates to 1,1:
297
         *
298
         * <pre>
299
         * Point point = (Point)GeometryLocator
300
         *                 .getGeometryManager().create(GEOMETRY.TYPES.POINT, GEOMETRY.SUBTYPES.GEOM2D);
301
         *         point.setX(1);
302
         *         point.setY(1);
303
         * </pre>
304
         * </p>
305
         * @param geomType
306
         * The geometry type
307
         * @return
308
         * A instance of a geometry.
309
         * @throws CreateGeometryException
310
         * This exception is thrown when the manager can not create
311
         * the geometry.
312
         */
313
        public Geometry create(GeometryType geomType) throws CreateGeometryException;
314

    
315
        /**
316
         * <p>
317
         * Creates a Envelope with a concrete subtype. The envelope is empty
318
         * and it have to be filled with the corners once has been created.
319
         * </p>
320
         * @param subType
321
         * SubType of envelope. Must be a value defined in {@link Geometry.SUBTYPES}
322
         * @return
323
         * A Envelope
324
         * @throws CreateEnvelopeException
325
         * If it is not possible to create the envelope.
326
         */
327
        public Envelope createEnvelope(int subType) throws CreateEnvelopeException;
328

    
329
        /**
330
         * <p>
331
         * Creates a Envelope with a concrete subtype. It sets the values
332
         * for the lower corner and the upper corner (in 2D) using the
333
         * method parameters.
334
         * </p>
335
         * @param minX
336
         * The minimum value for the X coordinate.
337
         * @param minY
338
         * The minimum value for the Y coordinate.
339
         * @param maxX
340
         * The maximum value for the X coordinate.
341
         * @param maxY
342
         * The maximum value for the Y coordinate.
343
         * @param subType
344
         * SubType of envelope. Must be a value defined in {@link Geometry.SUBTYPES}
345
         * @return
346
         * @throws CreateEnvelopeException
347
         */
348
        public Envelope createEnvelope(double minX, double minY, double maxX, double maxY, int subType) throws CreateEnvelopeException;
349

    
350
        /**
351
         * <p>
352
         * This method creates a {@link Geometry} with the type specified
353
         * by this name. If a geometry with this name doesn't exist, a
354
         * {@link IllegalArgumentException} is thrown. The geometry is empty,
355
         * and all the internal attributes must be assigned to a value when
356
         * the geometry has  been created.
357
         * </p>
358
         * <p>
359
         * This example creates a point2D and sets the coordinates to 1,1:
360
         * It supposes that there is a Point2D class with name "Point2D".
361
         * </p>
362
         * <pre>
363
         * Point point = (Point)GeometryLocator
364
         *                 .getGeometryManager().create("Point2D");
365
         *         point.setX(1);
366
         *         point.setY(1);
367
         * </pre>
368
         *
369
         * @param name
370
         * The name of the geometry type
371
         * @return
372
         * A instance of a geometry.
373
         * @throws CreateGeometryException
374
         * This exception is thrown when the manager can not create
375
         * the geometry.
376
         */
377
        public Geometry create(String name) throws CreateGeometryException;
378

    
379
        /**
380
         * <p>
381
         * This method creates a {@link Geometry} with a concrete type and subtype.
382
         * The geometry is empty, and all the internal attributes must be assigned
383
         * to a value when the geometry has  been created.
384
         * </p>
385
         * <p>
386
         * This example creates a point2D and sets the coordinates to 1,1.
387
         * It supposes that there is a Point2D class with the id 1.
388
         * </p>
389
         * <pre>
390
         * Point point = (Point)GeometryLocator
391
         *                 .getGeometryManager().create(Geometry.TYPES.POINT, Geometry.SYBTYPES.GEOM2D);
392
         *         point.setX(1);
393
         *         point.setY(1);
394
         * </pre>
395
         * @param type
396
         * Type of geometry. Must be a value defined in {@link Geometry.TYPES}
397
         * @param subType
398
         * SubType of geometry. Must be a value defined in {@link Geometry.SUBTYPES}
399
         * @return
400
         * A instance of a geometry.
401
         * @throws CreateGeometryException
402
         * This exception is thrown when the manager can not create
403
         * the geometry.
404
         */
405
        public Geometry create(int type, int subType) throws CreateGeometryException;
406

    
407
        /**
408
         * <p>
409
         * It creates a null geometry with a concrete subtype.
410
         * <p>
411
         * @param subType
412
         * SubType of geometry. Must be a value defined in {@link Geometry.SUBTYPES}
413
         * @return
414
         * A NullGeometry
415
         * @throws CreateGeometryException
416
         * This exception is thrown when the manager can not create
417
         * the geometry.
418
         */
419
        public NullGeometry createNullGeometry(int subType) throws CreateGeometryException;
420

    
421
        /**
422
         * <p>
423
         * Create a new point with a concrete type and sets the value
424
         * for the X and the Y.
425
         * </p>
426
         * @param x
427
         * The X coordinate
428
         * @param y
429
         * The y coordinate
430
         * @param subType
431
         * SubType of geometry. Must be a value defined in {@link Geometry.SUBTYPES}
432
         * @throws CreateGeometryException
433
         * This exception is thrown when the manager can not create
434
         * the geometry.
435
         * @return
436
         * The Point
437
         */
438
        public Point createPoint(double x, double y, int subType) throws CreateGeometryException;
439

    
440
        /**
441
         * <p>
442
         * Create a new curve with a concrete type and sets the value
443
         * for the coordinates using a GeneralPathX.
444
         * </p>
445
         * @param generalPathX
446
         * It is used to set the values for the X and Y coordinates.
447
         * @param subType
448
         * SubType of geometry. Must be a value defined in {@link Geometry.SUBTYPES}
449
         * @return
450
         * A curve
451
         * @throws CreateGeometryException
452
         * This exception is thrown when the manager can not create
453
         * the geometry.
454
         */
455
        public Curve createCurve(GeneralPathX generalPathX, int subType) throws CreateGeometryException;
456

    
457

    
458
        /**
459
         * <p>
460
         * Create a new multicurve with a concrete type and sets the value for the
461
         * coordinates using a GeneralPathX.
462
         * </p>
463
         *
464
         * @param generalPathX
465
         *            It is used to set the values for the X and Y coordinates.
466
         * @param subType
467
         *            SubType of geometry. Must be a value defined in
468
         *            {@link Geometry.SUBTYPES}
469
         * @return A multicurve
470
         * @throws CreateGeometryException
471
         *             This exception is thrown when the manager can not create the
472
         *             geometry.
473
         */
474
        public MultiCurve createMultiCurve(GeneralPathX generalPathX, int subType) throws CreateGeometryException;
475

    
476

    
477
        /**
478
         * <p>
479
         * Create a new surface with a concrete type and sets the value
480
         * for the coordinates using a GeneralPathX.
481
         * </p>
482
         * @param generalPathX
483
         * It is used to set the values for the X and Y coordinates.
484
         * @param subType
485
         * SubType of geometry. Must be a value defined in {@link Geometry.SUBTYPES}
486
         * @return
487
         * A surface
488
         * @throws CreateGeometryException
489
         * This exception is thrown when the manager can not create
490
         * the geometry.
491
         */
492
        public Surface createSurface(GeneralPathX generalPathX, int subType) throws CreateGeometryException;
493

    
494
        /**
495
         * <p>
496
         * Create a new multisurface with a concrete type and sets the value for the
497
         * coordinates using a GeneralPathX.
498
         * </p>
499
         * 
500
         * @param generalPathX
501
         *            It is used to set the values for the X and Y coordinates.
502
         * @param subType
503
         *            SubType of geometry. Must be a value defined in
504
         *            {@link Geometry.SUBTYPES}
505
         * @return A multisurface
506
         * @throws CreateGeometryException
507
         *             This exception is thrown when the manager can not create the
508
         *             geometry.
509
         */
510
        public MultiSurface createMultiSurface(GeneralPathX generalPathX, int subType) throws CreateGeometryException;
511

    
512
        /**
513
         * <p>
514
         * Returns an operation given the Geometry type, the Geometry subtype and and the operation
515
         * code. If opCode corresponds to a common operation (a common operation is an operation
516
         * registered for all geometries), then this method returns the common operation.
517
         * </p>
518
         * <p>
519
         * For better performance, if you need to call an operation multiple times,
520
         * use this method only once and keep the returned object in a local variable
521
         * over which you can iterate. For instance:
522
         *
523
         * <pre>
524
         * // Get the operation you need
525
         * GeometryManager gm = GeometryLocator.getGeometryManager()
526
         * GeometryOperation geomOp = null;
527
         * try {
528
         *    geomOp = gm.getGeometryOperation(Draw2D.CODE);
529
         * } catch (GeometryTypeNotSupportedException gtnse) {
530
         *    // treat exception
531
         * } catch (GeometryOperationNotSupportedException gonse) {
532
         *    // treat exception
533
         * }
534
         *
535
         *  // Fill the operation context with required params
536
         * GeometryOperationContext ctx = new GeometryOperationContext();
537
         *
538
         *  // Here is the main loop where you call the operation
539
         * for (int i=0; i<MyGeometries.length; i++) {
540
         *    Object result = geomOp.invoke(myGeometries[i], ctx);
541
         * }
542
         * </pre>
543
         * </p>
544
         * @param opCode
545
         * The operation code
546
         * @param type
547
         * Type of geometry. Must be a value defined in {@link Geometry.TYPES}
548
         * @param subType
549
         * SubType of geometry. Must be a value defined in {@link Geometry.SUBTYPES}
550
         * @return Geometry operation
551
         * @throws GeometryTypeNotSupportedException
552
         * Returns this exception if there is not a registered geometry with
553
         * these type and subtype
554
         * @throws GeometryTypeNotValidException
555
         * Returns this exception if the type and subtype are not valid
556
         * @throws GeometryOperationNotSupportedException
557
         * Returns this exception if there is not a registered operation with
558
         * this operation code
559
         */
560
        public GeometryOperation getGeometryOperation(int opCode, int type, int subType) throws GeometryTypeNotSupportedException, GeometryOperationNotSupportedException, GeometryTypeNotValidException;
561

    
562
        /**
563
         * <p>
564
         * Invokes an operation given its code, the geometry and the operation context holding the
565
         * parameters required for the operation.
566
         * </p>
567
         * @param opCode
568
         * Operation code.
569
         * @param geom
570
         * Geometry to which apply the operation
571
         * @param ctx
572
         * Context holding the operation parameters
573
         * @return
574
         * The object returned by an operation, depends on each operation.
575
         */
576
        public Object invokeOperation(int opCode, Geometry geom, GeometryOperationContext ctx) throws GeometryOperationNotSupportedException, GeometryOperationException;
577

    
578
        /**
579
         * <p>
580
         * Invokes an operation given its code, the geometry and the operation context holding the
581
         * parameters required for the operation.
582
         * </p>
583
         * @param geomOpName
584
         * Operation name.
585
         * @param geom
586
         * Geometry to which apply the operation
587
         * @param ctx
588
         * Context holding the operation parameters
589
         * @return
590
         * The object returned by an operation, depends on each operation.
591
         */
592
        public Object invokeOperation(String geomOpName, Geometry geom, GeometryOperationContext ctx) throws GeometryOperationNotSupportedException, GeometryOperationException;
593
}