Statistics
| Revision:

root / trunk / libraries / libTopology / src / org / gvsig / topology / Topology.java @ 13887

History | View | Annotate | Download (7.2 KB)

1
/*
2
 * Created on 07-sep-2007
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
21
 *
22
 * For more information, contact:
23
 *
24
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib??ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33
 *
34
 *    or
35
 *
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 *
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
/* CVS MESSAGES:
45
 *
46
 * $Id: 
47
 * $Log: 
48
 */
49
package org.gvsig.topology;
50

    
51
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
52
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileReadException;
53
import com.iver.cit.gvsig.fmap.MapContext;
54
import com.iver.cit.gvsig.fmap.layers.FLayer;
55
import com.iver.cit.gvsig.fmap.layers.FLayers;
56
import com.vividsolutions.jts.geom.Envelope;
57
import java.awt.geom.Rectangle2D;
58
import java.util.ArrayList;
59
import java.util.List;
60

    
61
import org.cresques.cts.IProjection;
62
import org.gvsig.topology.topologyrules.MustBeLargerThanClusterTolerance;
63
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
64

    
65
public class Topology extends FLayers implements ITopologyErrorContainer, ITopologyStatus {
66
 
67
        /**
68
         * Unique identifier which will be autoupdating for all those new errors
69
         * added to the ITopologyErrorContainer
70
         */
71
        private int errorFid = 0;
72
        
73
        /**
74
         * cluster tolerance of the topology
75
         */
76
        private double clusterTolerance;
77
         
78
        /**
79
         * validation status of the topology
80
         */
81
        private byte status = ITopologyStatus.NON_VALIDATED;
82
         
83
        
84
        /**
85
         *If during validation process a topoly
86
         *exceeds this parameters, validation will be stopped.
87
         *
88
         */
89
        private int maxNumberOfErrors = -1;
90
        
91
        /**
92
         * topology rules of the topology
93
         */
94
        private List rules;
95
        
96
        /**
97
         * Each layer of a topology must have a cluster tolerance
98
         * rule
99
         */
100
        private List clusterToleranceRules;
101
         
102
        /**
103
         * Regions of the topology to be validated
104
         */
105
        private List dirtyZones;
106
        
107
        //TODO Change List for a persistent datastore
108
        //as TopologyError extends DefaultFeature, we could use a driver and a writer
109
        private List topologyErrors;
110
         
111
        /**
112
         * Default constructor for a topology as a FLayers
113
         * @param fmap
114
         * @param parent
115
         */
116
        public Topology(MapContext fmap, FLayers parent) {
117
                super(fmap, parent);
118
        }
119
        
120
        /**
121
         * Constructor
122
         * @param clusterTolerance
123
         * @param maxNumberOfErrors
124
         */
125
        public Topology(double clusterTolerance, int maxNumberOfErrors){
126
                super(null, null);
127
                this.clusterTolerance = clusterTolerance;
128
                this.maxNumberOfErrors = maxNumberOfErrors;
129
                rules = new  ArrayList();
130
                clusterToleranceRules = new ArrayList();
131
                dirtyZones = new ArrayList();
132
        }
133
        
134
        /**
135
         * Changes the cluster tolerance of the topology
136
         * @param clusterTolerance
137
         */
138
        public void setClusterTolerance(double clusterTolerance){
139
                this.clusterTolerance = clusterTolerance;
140
        }
141
        
142
        public double getClusterTolerance() {
143
                return clusterTolerance;
144
        }
145
         
146
        /**
147
         *Adds a new topology rule to the topology.
148
         */
149
        public void addRule(AbstractTopologyRule rule) {
150
                rules.add(rule);
151
        }
152
        
153
        
154
        /*
155
         * Overwrited implementations of FLayers methods
156
         * */
157
        public void addLayer(FLayer layer) {
158
                if(! (layer instanceof FLyrVect))
159
                        throw new WrongLyrForTopologyException("Intentando a?adir capa no vectorial a una topologia");
160
                super.addLayer(layer);
161
                
162
                status = ITopologyStatus.NON_VALIDATED;
163
                MustBeLargerThanClusterTolerance rule = new MustBeLargerThanClusterTolerance();
164
                try {
165
                        addDirtyZone(layer.getFullExtent());
166
                } catch (ExpansionFileReadException e) {
167
                        // TODO Auto-generated catch block
168
                        e.printStackTrace();
169
                } catch (ReadDriverException e) {
170
                        // TODO Auto-generated catch block
171
                        e.printStackTrace();
172
                }
173
        }
174
        
175
        public void addLayer(int pos, FLayer layer) {
176
                if(! (layer instanceof FLyrVect))
177
                        throw new WrongLyrForTopologyException("Intentando a?adir capa no vectorial a una topologia");
178
                super.addLayer(pos, layer);
179
                status = ITopologyStatus.NON_VALIDATED;
180
                try {
181
                        addDirtyZone(layer.getFullExtent());
182
                } catch (ExpansionFileReadException e) {
183
                        // TODO Auto-generated catch block
184
                        e.printStackTrace();
185
                } catch (ReadDriverException e) {
186
                        // TODO Auto-generated catch block
187
                        e.printStackTrace();
188
                }
189
        }
190
         
191
        /**
192
         *Adds a layer to the topology. If the topology has been validated, changes
193
         *topology status to NON-VALIDATED and adds a dirty zone equals to
194
         *the layer extent.
195
         */
196
        public void addLayer(FLyrVect layer, int xyRank, int zRank) {
197
//                
198
//                MustBeLargerThanClusterTolerance rule = 
199
//                        new MustBeLargerThanClusterTolerance();
200
        }
201
        
202
        
203
        
204
        
205
         
206
        public void setStatus(byte status) {
207
                this.status = status; 
208
        }
209
         
210
        public byte getStatus() {
211
                return status;
212
        }
213
         
214
        /**
215
         *Adds a dirty zone to the topology
216
         *(usually whe a feature of a layer
217
         *of the topology has been edited)
218
         */
219
        public void addDirtyZone(Rectangle2D dirtyZone) {
220
        }
221
         
222
        public Rectangle2D getDirtyZone() {
223
                return null;
224
        }
225
         
226
        public void validate() {
227
        }
228
         
229
        public int getLayerCount() {
230
                return super.getLayersCount();
231
        }
232
         
233
        public int getRuleCount() {
234
                return 0;
235
        }
236
         
237
        public FLyrVect getLyr(int lyrIndex) {
238
                return (FLyrVect) super.getLayer(lyrIndex);
239
        }
240
         
241
        public AbstractTopologyRule getRule(int ruleIndex) {
242
                return (AbstractTopologyRule) rules.get(ruleIndex);
243
        }
244
         
245
        /**
246
         *Returns if a specified rectangle touch one
247
         *of the existing dirty zones. If not, probably
248
         *is needed to add to the dirty zones collection.
249
         *If true, maybe it could modify the dirty zone.
250
         */
251
        public boolean isInDirtyZone(Rectangle2D envelope) {
252
                return false;
253
        }
254
         
255
        /**
256
         *Modify the dirty zone of the specified index
257
         */
258
        public void updateDirtyZone(int dirtyZoneIndex, Rectangle2D dirtyZone) {
259
        }
260
         
261
        public void setMaxNumberOfErrors(int maxNumberOfErrors) {
262
                this.maxNumberOfErrors = maxNumberOfErrors;
263
        }
264
         
265
        public int getMaxNumberOfErrors() {
266
                return maxNumberOfErrors;
267
        }
268

    
269
        
270
        /*
271
         * @see org.gvsig.topology.ITopologyErrorContainer#addTopologyError(org.gvsig.topology.TopologyError)
272
         */
273
        
274
        public void addTopologyError(TopologyError topologyError) {
275
                // TODO Auto-generated method stub
276
                
277
        }
278

    
279
        public void markAsTopologyException(TopologyError topologyError,
280
                        boolean markAsException) {
281
                // TODO Auto-generated method stub
282
                
283
        }
284

    
285
        public TopologyError[] getTopologyErrors(String ruleName, int shapeType,
286
                        FLyrVect sourceLayer, IProjection desiredProjection,
287
                        int includeExceptions) {
288
                // TODO Auto-generated method stub
289
                return null;
290
        }
291

    
292
        public String getErrorFid() {
293
                String solution =  Integer.toString(errorFid);
294
                errorFid++;
295
                return solution;
296
        }
297
         
298
}
299