Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libTopology / src / org / gvsig / topology / TopologyError.java @ 18995

History | View | Annotate | Download (6.74 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.FShape;
56
import com.iver.cit.gvsig.fmap.core.IFeature;
57
import com.iver.cit.gvsig.fmap.core.IGeometry;
58
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
59
import com.iver.utiles.IPersistence;
60
import com.iver.utiles.XMLEntity;
61

    
62

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

    
205
        
206
        public FLyrVect getOriginLayer(){
207
                return ((IOneLyrRule)violatedRule).getOriginLyr();
208
        }
209
        
210
        public FLyrVect getDestinationLayer(){
211
                if(violatedRule instanceof ITwoLyrRule)
212
                        return  ((ITwoLyrRule)violatedRule).getDestinationLyr();
213
                else
214
                        return null;
215
        }
216

    
217
        public String getClassName() {
218
                return this.getClass().getName();
219
        }
220
        
221
        public Topology getTopology(){
222
                return this.topology;
223
        }
224

    
225
        public XMLEntity getXMLEntity() {
226
                XMLEntity solution = FeatureUtil.getAsXmlEntity(this);
227
                solution.putProperty("violatedRule", this.violatedRule.getId());
228
                solution.putProperty("exception", this.exception);
229
                
230
                if(feature1 != null){
231
                        FLyrVect originLyr = ((IOneLyrRule)violatedRule).getOriginLyr();
232
                        solution.putProperty("sourceLyr", originLyr.getName());
233
                        XMLEntity xmlFeature = FeatureUtil.getAsXmlEntity(feature1);
234
                        solution.putProperty("feature1", xmlFeature);
235
                }
236
                
237
                if(feature2 != null){
238
                        FLyrVect destinationLyr = ((ITwoLyrRule)violatedRule).getDestinationLyr();
239
                        solution.putProperty("sourceLyr", destinationLyr.getName());
240
                        XMLEntity xmlFeature = FeatureUtil.getAsXmlEntity(feature2);
241
                        solution.putProperty("feature2", xmlFeature);
242
                }
243
                return solution;
244
        }
245

    
246
        public void setXMLEntity(XMLEntity xml) {
247
                //first of all information xml of feature
248
                FeatureUtil.setXMLEntity(this, xml);
249
                
250
                if(xml.contains("violatedRule")){
251
                        int violatedRuleId = xml.getIntProperty("violatedRule");
252
                        violatedRule = topology.getRuleById(violatedRuleId);
253
                }
254
                
255
                if(xml.contains("exception")){
256
                        exception = xml.getBooleanProperty("exception");
257
                }
258
                
259
                if(xml.contains("feature1")){
260
                                XMLEntity entity = (XMLEntity) xml.getObjectProperty("feature1");
261
                                IFeature feature = FeatureUtil.getFeatureFromXmlEntity(entity);
262
                                feature1 = feature;
263
                }//if
264
                
265
                if(xml.contains("feature2")){
266
                        XMLEntity entity = (XMLEntity) xml.getObjectProperty("feature2");
267
                        IFeature feature = FeatureUtil.getFeatureFromXmlEntity(entity);
268
                        feature2 = feature;
269
                }//if
270
        }
271

    
272
}
273