Statistics
| Revision:

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

History | View | Annotate | Download (4.98 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 com.iver.cit.gvsig.fmap.core.DefaultFeature;
53
import com.iver.cit.gvsig.fmap.core.IFeature;
54
import com.iver.cit.gvsig.fmap.core.IGeometry;
55
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
56
import com.iver.utiles.IPersistence;
57
import com.iver.utiles.XMLEntity;
58

    
59

    
60
/**
61
 * Error produced when one or many features 
62
 * dont pass a topology rule.
63
 */
64
public class TopologyError extends DefaultFeature implements IPersistence{
65
 
66
        /**
67
         *rule which has been violated
68
         */
69
        private ITopologyRule violatedRule;
70
         
71
        /**
72
         *features of the source layer that
73
         *violates the rule (if the rule is a self-rule,
74
         *the error will only have source layer features)
75
         *
76
         *Although we are validating one only feature a time, in self reflexive
77
         *rules it could cause errors with many features (a feature overlaps with
78
         *other features of the same layer)
79
         */
80
        private IFeature[] sourceLyrFeatures;
81
         
82
        /**
83
         *features of the destination layer
84
         *that violate the rule (only in rules between
85
         *two layers)
86
         */
87
        private IFeature[] destinationLyrFeatures;
88
         
89
        /**
90
         * Flag that marks if this error is allowed
91
         * (it has been marked as an exception)
92
         */
93
        private boolean exception;
94
        
95
        /**
96
         * Constructor
97
         * @param geometry geometry of the error
98
         * @param errorFid unique identifier for this error in the error container
99
         * (topology)
100
         * 
101
         * @param violatedRule topology rule that this error violates
102
         * 
103
         * @param sourceLyrFeatures features of the origin layer in the rule
104
         * that violates the rule
105
         * 
106
         * @param destinationLyrFeatures features of the destination layer in the rule
107
         * that violates the rule
108
         */
109
        public TopologyError(IGeometry geometry, 
110
                                            String errorFid,
111
                                            AbstractTopologyRule violatedRule,
112
                                            IFeature[] sourceLyrFeatures, 
113
                                            IFeature[] destinationLyrFeatures){
114
                super(geometry, null, errorFid);
115
                this.exception = false;
116
                this.violatedRule = violatedRule;
117
                this.sourceLyrFeatures = sourceLyrFeatures;
118
                this.destinationLyrFeatures = destinationLyrFeatures;
119
        }
120
        
121
        public TopologyError(IGeometry geometry,
122
                                                 AbstractTopologyRule violatedRule,
123
                                                 IFeature[] sourceLyrFeatures){
124
                super(geometry, null, null);
125
                this.violatedRule = violatedRule;
126
                this.sourceLyrFeatures = sourceLyrFeatures;
127
        }
128
         
129
        public void setViolatedRule(AbstractTopologyRule violatedRule) {
130
                this.violatedRule = violatedRule;
131
        }
132
         
133
        public ITopologyRule getViolatedRule() {
134
                return violatedRule;
135
        }
136
         
137
        public void setSourceLyrFeatures(IFeature[] sourceLyrFeatures) {
138
                this.sourceLyrFeatures =sourceLyrFeatures;
139
        }
140
         
141
        public IFeature[] getSourceLyrFeatures() {
142
                return sourceLyrFeatures;
143
        }
144
         
145
        public void setDestinationLyrFeatures(IFeature[] destinationLyrFeatures) {
146
                this.destinationLyrFeatures = destinationLyrFeatures;
147
        }
148
         
149
        public IFeature[] getDestinationLyrFeatures() {
150
                return destinationLyrFeatures;
151
        }
152
         
153
        /**
154
         *Ruturns the type of geometry of the error
155
         */
156
        public int getShapeType() {
157
                return getGeometry().getGeometryType();
158
        }
159
         
160
        public void setException(boolean exception) {
161
                this.exception = exception;
162
        }
163
         
164
        public boolean isException() {
165
                return exception;
166
        }
167

    
168
        
169
        public FLyrVect getOriginLayer(){
170
                return ((IOneLyrRule)violatedRule).getOriginLyr();
171
        }
172
        
173
        public FLyrVect getDestinationLayer(){
174
                if(violatedRule instanceof ITwoLyrRule)
175
                        return  ((ITwoLyrRule)violatedRule).getDestinationLyr();
176
                else
177
                        return null;
178
        }
179

    
180
        public String getClassName() {
181
                return this.getClass().getName();
182
        }
183

    
184
        public XMLEntity getXMLEntity() {
185
                XMLEntity solution = new XMLEntity();
186
                solution.putProperty("violatedRule", this.violatedRule.getName());
187
                solution.putProperty("isException", exception);
188
                return solution;
189
        }
190

    
191
        public void setXMLEntity(XMLEntity xml) {
192
                // TODO Auto-generated method stub
193
                
194
        }
195

    
196
}
197