Statistics
| Revision:

root / trunk / libraries / libTopology / src / org / gvsig / topology / TopologyError.java @ 24685

History | View | Annotate | Download (6.93 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
 */
50
package org.gvsig.topology;
51

    
52
import org.gvsig.fmap.core.FeatureUtil;
53

    
54
import com.iver.cit.gvsig.fmap.core.DefaultFeature;
55
import com.iver.cit.gvsig.fmap.core.FGeometryCollection;
56
import com.iver.cit.gvsig.fmap.core.FShape;
57
import com.iver.cit.gvsig.fmap.core.IFeature;
58
import com.iver.cit.gvsig.fmap.core.IGeometry;
59
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
60
import com.iver.utiles.IPersistence;
61
import com.iver.utiles.XMLEntity;
62

    
63

    
64
/**
65
 * Error produced when one or many features 
66
 * dont pass a topology rule.
67
 */
68
public class TopologyError extends DefaultFeature implements IPersistence{
69
        
70
        /**
71
         * Reference to the topology to which this error is associated.
72
         */
73
        private Topology topology;
74
                
75
        /**
76
         *rule which has been violated
77
         */
78
        private ITopologyRule violatedRule;
79
         
80
        /**
81
         First feature that causes the topology error
82
         (Some rules' topology error will have only one feature associated
83
         */
84
        private IFeature feature1;
85
         
86
        /**
87
         *Second feature that causes the topology error (null if dont exists)
88
         */
89
        private IFeature feature2;
90
         
91
        /**
92
         * Flag that marks if this error is allowed
93
         * (it has been marked as an exception)
94
         */
95
        private boolean exception;
96
        
97
        /**
98
         * Constructor
99
         * @param geometry geometry of the error
100
         * @param errorFid unique identifier for this error in the error container
101
         * (topology)
102
         * 
103
         * @param violatedRule topology rule that this error violates
104
         * 
105
         * @param sourceLyrFeatures features of the origin layer in the rule
106
         * that violates the rule
107
         * 
108
         * @param destinationLyrFeatures features of the destination layer in the rule
109
         * that violates the rule
110
         */
111
        public TopologyError(IGeometry geometry, 
112
                                            String errorFid,
113
                                            AbstractTopologyRule violatedRule,
114
                                            IFeature feature1, 
115
                                            IFeature feature2,
116
                                            Topology topology){
117
                super(geometry, null, errorFid);
118
                this.exception = false;
119
                this.violatedRule = violatedRule;
120
                this.feature1 = feature1;
121
                this.feature2 = feature2;
122
                this.topology = topology;
123
        }
124
        
125
        public TopologyError(IGeometry geometry,
126
                                                 AbstractTopologyRule violatedRule,
127
                                                 IFeature feature1, 
128
                                                 Topology topology){
129
                super(geometry, null, null);
130
                this.violatedRule = violatedRule;
131
                this.feature1 = feature1;
132
                this.topology = topology;
133
        }
134
        
135
        
136
        public TopologyError(Topology parentTopology){
137
                super(null, null, null);
138
                this.topology = parentTopology;
139
        }
140
         
141
        public void setViolatedRule(AbstractTopologyRule violatedRule) {
142
                this.violatedRule = violatedRule;
143
        }
144
         
145
        public ITopologyRule getViolatedRule() {
146
                return violatedRule;
147
        }
148
         
149
        public void setFeature1(IFeature feature) {
150
                this.feature1 = feature;
151
        }
152
         
153
        public IFeature getFeature1() {
154
                return feature1;
155
        }
156
         
157
        public void setFeature2(IFeature feature) {
158
                this.feature2 = feature;
159
        }
160
         
161
        public IFeature getFeature2() {
162
                return feature2;
163
        }
164
         
165
        /**
166
         *Ruturns the type of geometry of the error
167
         */
168
        public int getShapeType() {
169
                return getGeometry().getGeometryType();
170
        }
171
        
172
        public String getShapeTypeAsText(){
173
                String solution = "";
174
                int shapeType = getShapeType();
175
                switch (shapeType) {
176
                case FShape.POINT:
177
                case FShape.TEXT:
178
                        solution = Messages.getText("POINT");
179
                        break;
180
                case FShape.POLYGON:
181
                        solution = Messages.getText("POLYGON");
182
                        break;
183
                case FShape.LINE:
184
                case FShape.ARC:
185
                case FShape.CIRCLE:
186
                case FShape.ELLIPSE:
187
                        //needed because FGeometryCollection returns FShape.LINE
188
                        if(getGeometry() instanceof FGeometryCollection)
189
                                solution = Messages.getText("MULTIGEOMETRY");
190
                        else
191
                                solution = Messages.getText("LINE");
192
                        break;
193
                case FShape.MULTI:
194
                        solution = Messages.getText("MULTI");
195
                        break;
196
                case FShape.MULTIPOINT:
197
                        solution = Messages.getText("MULTIPOINT");
198
                        break;
199
                }
200
                return solution;
201
        }
202
         
203
        public void setException(boolean exception) {
204
                this.exception = exception;
205
        }
206
         
207
        public boolean isException() {
208
                return exception;
209
        }
210

    
211
        
212
        public FLyrVect getOriginLayer(){
213
                return ((IOneLyrRule)violatedRule).getOriginLyr();
214
        }
215
        
216
        public FLyrVect getDestinationLayer(){
217
                if(violatedRule instanceof ITwoLyrRule)
218
                        return  ((ITwoLyrRule)violatedRule).getDestinationLyr();
219
                else
220
                        return null;
221
        }
222

    
223
        public String getClassName() {
224
                return this.getClass().getName();
225
        }
226
        
227
        public Topology getTopology(){
228
                return this.topology;
229
        }
230

    
231
        public XMLEntity getXMLEntity() {
232
                XMLEntity solution = FeatureUtil.getAsXmlEntity(this);
233
                solution.putProperty("exception", this.exception);
234
                
235
                solution.addChild(this.violatedRule.getXMLEntity());
236
                XMLEntity xmlFeature = null;
237
                boolean hasFeature1 = false;
238
                if(feature1 != null){
239
                        hasFeature1 = true;
240
                        xmlFeature = FeatureUtil.getAsXmlEntity(feature1);
241
                        solution.addChild(xmlFeature);
242
                }
243
                solution.putProperty("hasFeature1", hasFeature1);
244
                
245
                boolean hasFeature2 = false;
246
                if(feature2 != null){
247
                        hasFeature2 = true;
248
                        xmlFeature = FeatureUtil.getAsXmlEntity(feature2);
249
                        solution.addChild(xmlFeature);
250
                }
251
                solution.putProperty("hasFeature2", hasFeature2);
252
                return solution;
253
        }
254

    
255
        public void setXMLEntity(XMLEntity xml) {
256
                //first of all information xml of feature
257
                FeatureUtil.setXMLEntity(this, xml);
258
                
259
                if(xml.contains("exception")){
260
                        exception = xml.getBooleanProperty("exception");
261
                }
262
                
263
                this.violatedRule =
264
                         TopologyRuleFactory.createFromXML(this.topology, xml.getChild(0));
265
                int childNumber = 1;
266
                
267
                if(xml.contains("hasFeature1")){
268
                                boolean hasFeature1 = xml.getBooleanProperty("hasFeature1");
269
                                if(hasFeature1)
270
                                {
271
                                        this.feature1 = FeatureUtil.getFeatureFromXmlEntity(xml.getChild(childNumber));
272
                                        childNumber++;
273
                                }
274
                }//if
275
                
276
                if(xml.contains("hasFeature2")){
277
                        boolean hasFeature2 = xml.getBooleanProperty("hasFeature2");
278
                        if(hasFeature2)
279
                        {
280
                                this.feature2 = FeatureUtil.getFeatureFromXmlEntity(xml.getChild(childNumber));
281
                        }
282
                }//if
283
        }
284

    
285
}
286