Revision 24685

View differences:

trunk/libraries/libTopology/src/org/gvsig/topology/TopologyPersister.java
121 121
		return null;
122 122
	}
123 123

  
124
	public static ITopologyErrorContainer createErrorContainerFromXML(
125
			XMLEntity xml) {
124
	public static ITopologyErrorContainer createErrorContainerFromXML(Topology owner,
125
																		XMLEntity xml) {
126 126
		ITopologyErrorContainer solution = null;
127 127
		String className = null;
128 128
		if (xml.contains("className")) {
129 129
			className = xml.getStringProperty("className");
130 130
			Class clazz = null;
131
			ITopologyErrorContainer obj = null;
132 131
			try {
133 132
				clazz = Class.forName(className);
134
				obj = (ITopologyErrorContainer) clazz.newInstance();
135
				obj.setXMLEntity(xml);
133
				solution = (ITopologyErrorContainer) clazz.newInstance();
134
				solution.setTopology(owner);
135
				solution.setXMLEntity(xml);
136 136
			} catch (Exception e) {
137 137
				logger.error(e);
138 138
			}
trunk/libraries/libTopology/src/org/gvsig/topology/TopologyError.java
135 135
	
136 136
	public TopologyError(Topology parentTopology){
137 137
		super(null, null, null);
138
		this.topology = parentTopology;
138 139
	}
139 140
	 
140 141
	public void setViolatedRule(AbstractTopologyRule violatedRule) {
......
229 230

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

  
......
252 256
		//first of all information xml of feature
253 257
		FeatureUtil.setXMLEntity(this, xml);
254 258
		
255
		if(xml.contains("violatedRule")){
256
			int violatedRuleId = xml.getIntProperty("violatedRule");
257
			violatedRule = topology.getRuleById(violatedRuleId);
258
		}
259
		
260 259
		if(xml.contains("exception")){
261 260
			exception = xml.getBooleanProperty("exception");
262 261
		}
263 262
		
264
		if(xml.contains("feature1")){
265
				XMLEntity entity = (XMLEntity) xml.getObjectProperty("feature1");
266
				IFeature feature = FeatureUtil.getFeatureFromXmlEntity(entity);
267
				feature1 = feature;
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
				}
268 274
		}//if
269 275
		
270
		if(xml.contains("feature2")){
271
			XMLEntity entity = (XMLEntity) xml.getObjectProperty("feature2");
272
			IFeature feature = FeatureUtil.getFeatureFromXmlEntity(entity);
273
			feature2 = feature;
276
		if(xml.contains("hasFeature2")){
277
			boolean hasFeature2 = xml.getBooleanProperty("hasFeature2");
278
			if(hasFeature2)
279
			{
280
				this.feature2 = FeatureUtil.getFeatureFromXmlEntity(xml.getChild(childNumber));
281
			}
274 282
		}//if
275 283
	}
276 284

  
trunk/libraries/libTopology/src/org/gvsig/topology/AbstractTopologyRule.java
268 268
		xml.putProperty("className", getClassName());
269 269
		xml.putProperty("originLayerName", this.originLyr.getName());
270 270
		xml.putProperty("ruleId", this.ruleId);
271
		if(this instanceof IRuleWithClusterTolerance){
272
			double clusterTolerance = ((IRuleWithClusterTolerance)this).getClusterTolerance();
273
			xml.putProperty("clusterTolerance", clusterTolerance);
274
		}
271 275
		return xml;
272 276
	}
273 277
	    
274 278
	public void setXMLEntity(XMLEntity xml){
275 279
		String originLayerName = "";
276
		if (xml.contains("originLayer")) {
277
			originLayerName = xml.getStringProperty("originLayer");
280
		if (xml.contains("originLayerName")) {
281
			originLayerName = xml.getStringProperty("originLayerName");
278 282
			this.originLyr = (FLyrVect) topology.getLayer(originLayerName);
279 283
		}//if
280 284
		
281 285
		if(xml.contains("ruleId")){
282 286
			ruleId = xml.getIntProperty("ruleId");
283 287
		}
288
		
289
		if(xml.contains("clusterTolerance")){
290
			double clusterTolerance = xml.getDoubleProperty("clusterTolerance");
291
			if(this instanceof IRuleWithClusterTolerance)
292
				((IRuleWithClusterTolerance)this).setClusterTolerance(clusterTolerance);
293
		}
284 294
	}
285 295
	
286 296
    public void setId(int ruleId){
trunk/libraries/libTopology/src/org/gvsig/topology/topologyrules/PolygonMustNotOverlapWith.java
72 72
import com.iver.cit.gvsig.fmap.core.symbols.MultiShapeSymbol;
73 73
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator;
74 74
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
75
import com.iver.utiles.XMLEntity;
75 76
import com.vividsolutions.jts.geom.Envelope;
76 77
import com.vividsolutions.jts.geom.Geometry;
77 78
import com.vividsolutions.jts.geom.Polygon;
......
138 139
		return automaticErrorFixes;
139 140
	}
140 141
	
142
	public XMLEntity getXMLEntity(){
143
		XMLEntity xml = super.getXMLEntity();
144
		xml.putProperty("destinationLayerName", this.destinationLyr.getName());
145
		return xml;
146
	}
147
	@Override    
148
	public void setXMLEntity(XMLEntity xml){
149
		super.setXMLEntity(xml);
150
		String destinationLayerName = "";
151
		if (xml.contains("destinationLayerName")) {
152
			destinationLayerName = xml.getStringProperty("destinationLayerName");
153
			this.destinationLyr = (FLyrVect) topology.getLayer(destinationLayerName);
154
		}//if
155
	}
156
	
141 157
	@Override
142 158
	protected void process(IGeometry geometry, IFeature feature) {
143 159
		Geometry jtsGeom = NewFConverter.toJtsGeometry(geometry);
trunk/libraries/libTopology/src/org/gvsig/topology/topologyrules/AbstractSpatialPredicateTwoLyrRule.java
69 69
import com.iver.cit.gvsig.fmap.core.symbols.MultiShapeSymbol;
70 70
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator;
71 71
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
72
import com.iver.utiles.XMLEntity;
72 73
import com.vividsolutions.jts.geom.Geometry;
73 74

  
74 75
public abstract class AbstractSpatialPredicateTwoLyrRule extends AbstractTopologyRule implements ITwoLyrRule {
......
93 94
	}
94 95
	
95 96
	
97
	
98
	/**
99
	 * Constructor without topology param
100
	 * 
101
	 * @param originLyr
102
	 */
103
	public AbstractSpatialPredicateTwoLyrRule(FLyrVect originLyr, FLyrVect destinationLyr){
104
		this(null, originLyr, destinationLyr);
105
	}
106
	
107
	
108
	
96 109
	public AbstractSpatialPredicateTwoLyrRule(){
97 110
		super();
98 111
	}
......
105 118
		this.destinationLyr = destinationLyr;
106 119
	}
107 120
	
121
	public XMLEntity getXMLEntity(){
122
		XMLEntity xml = super.getXMLEntity();
123
		xml.putProperty("destinationLayerName", this.destinationLyr.getName());
124
		return xml;
125
	}
126
	    
127
	public void setXMLEntity(XMLEntity xml){
128
		super.setXMLEntity(xml);
129
		String destinationLayerName = "";
130
		if (xml.contains("destinationLayerName")) {
131
			destinationLayerName = xml.getStringProperty("destinationLayerName");
132
			this.destinationLyr = (FLyrVect) topology.getLayer(destinationLayerName);
133
		}//if
134
	}
135
	
108 136
	protected TopologyError createTopologyError(Geometry errorGeometry, 
109 137
												IFeature feature, 
110 138
												IFeature neighbour){
trunk/libraries/libTopology/src/org/gvsig/topology/Topology.java
191 191
	 * Map that relates a FLyrVect of the Topology with its rank (weight when we
192 192
	 * are going to snap many coordinates)
193 193
	 */
194
	private Map<FLyrVect, XYZLayerRank> layerRanks;
194
//	private Map<FLyrVect, XYZLayerRank> layerRanks;
195 195

  
196 196
	/**
197 197
	 * Numerical identifier for rules of a topology
......
238 238
		rules = new ArrayList<ITopologyRule>();
239 239
		clusterToleranceRules = new ArrayList<MustBeLargerThanClusterTolerance>();
240 240
		dirtyZones = new ArrayList<Rectangle2D>();
241
		layerRanks = new HashMap<FLyrVect, XYZLayerRank>();
241
//		layerRanks = new HashMap<FLyrVect, XYZLayerRank>();
242 242

  
243 243
		statusListeners = new ArrayList<ITopologyStatusListener>();
244 244
		// This listener updates the icon status returneb by this kind of layer
......
427 427
		
428 428
		
429 429
		super.addLayer(pos, layer);
430
		setRank((FLyrVect) layer, 1, 1);
430
//		setRank((FLyrVect) layer, 1, 1);
431 431

  
432 432
		int shapeType = -1;
433 433
		try {
......
573 573
	 * @param zRank
574 574
	 *            importante of this layer coordinates in z plane
575 575
	 */
576
	public void setRank(FLyrVect lyr, int xyRank, int zRank) {
577
		XYZLayerRank rank = new XYZLayerRank(lyr.getName(), xyRank, zRank);
578
		layerRanks.put(lyr, rank);
579
	}
576
//	public void setRank(FLyrVect lyr, int xyRank, int zRank) {
577
//		XYZLayerRank rank = new XYZLayerRank(lyr.getName(), xyRank, zRank);
578
//		layerRanks.put(lyr, rank);
579
//	}
580 580

  
581
	public XYZLayerRank getRank(FLyrVect lyr) {
582
		return layerRanks.get(lyr);
583
	}
581
//	public XYZLayerRank getRank(FLyrVect lyr) {
582
//		return layerRanks.get(lyr);
583
//	}
584 584

  
585 585
	/**
586 586
	 * Adds a layer to the topology. If the topology has been validated, changes
......
589 589
	 */
590 590
	public void addLayer(FLyrVect layer, int xyRank, int zRank) {
591 591
		this.addLayer(layer);
592
		setRank(layer, xyRank, zRank);
592
//		setRank(layer, xyRank, zRank);
593 593
	}
594 594

  
595 595
	/**
......
638 638
		}// while
639 639

  
640 640
		this.errorContainer.removeErrorsByLayer((FLyrVect) lyr);
641
		this.layerRanks.remove(lyr);
641
//		this.layerRanks.remove(lyr);
642 642
		this.updateDirtyZones();
643 643
		callLayerRemoved(LayerCollectionEvent.createLayerRemovedEvent(lyr));
644 644
	}
......
1213 1213
	}
1214 1214

  
1215 1215
	public XMLEntity getXMLEntity() throws XMLException {
1216

  
1216
		boolean errorLayerExists = this.errorLayer != null;
1217
		FLayer errorLayerCopy = null;
1218
		if(errorLayerExists){
1219
			errorLayerCopy = this.errorLayer;
1220
			super.removeLayer(this.errorLayer);
1221
		}
1217 1222
		// Topology is a subclass of FLayers, so the call to super
1218 1223
		// allows to persist layer status, toc information and layers
1219 1224
		XMLEntity xml = super.getXMLEntity();
......
1232 1237
			xml.addChild(rule.getXMLEntity());
1233 1238
		}
1234 1239

  
1235
		int numberOfClusterRules = clusterToleranceRules.size();
1236
		xml.putProperty("numberOfClusterRules", numberOfClusterRules);
1237
		for (int i = 0; i < numberOfClusterRules; i++) {
1238
			MustBeLargerThanClusterTolerance rule = clusterToleranceRules
1239
					.get(i);
1240
			xml.addChild(rule.getXMLEntity());
1241
		}
1240
//		int numberOfClusterRules = clusterToleranceRules.size();
1241
//		xml.putProperty("numberOfClusterRules", numberOfClusterRules);
1242
//		for (int i = 0; i < numberOfClusterRules; i++) {
1243
//			MustBeLargerThanClusterTolerance rule = clusterToleranceRules
1244
//					.get(i);
1245
//			xml.addChild(rule.getXMLEntity());
1246
//		}
1242 1247

  
1243 1248
		int numberOfDirtyZones = dirtyZones.size();
1244 1249
		xml.putProperty("numberOfDirtyZones", numberOfDirtyZones);
......
1258 1263

  
1259 1264
		XMLEntity errorContainerXML = errorContainer.getXMLEntity();
1260 1265
		xml.addChild(errorContainerXML);
1266
		
1267
		xml.putProperty("errorLayerExists", errorLayerExists);
1268
		xml.putProperty("nextRuleFid", ruleId);
1269
		
1270
		if(errorLayerExists){
1271
			this.errorLayer = errorLayerCopy;
1272
			try {
1273
				if(((FLyrVect)errorLayer).getSource().getShapeCount() > 0)
1274
					super.addLayer(this.layers.size(), this.errorLayer);
1275
			} catch (ReadDriverException e) {
1276
				e.printStackTrace();
1277
			}	
1278
			
1279
		}
1261 1280

  
1262
		Collection<XYZLayerRank> ranksVal = layerRanks.values();
1263
		int numberOfRanks = ranksVal.size();
1264
		xml.putProperty("numberOfRanks", numberOfRanks);
1265
		Iterator<XYZLayerRank> xyzRankIterator = layerRanks.values().iterator();
1266
		while (xyzRankIterator.hasNext()) {
1267
			XYZLayerRank layerRank = xyzRankIterator.next();
1268
			XMLEntity entity = layerRank.getXMLEntity();
1269
			xml.addChild(entity);
1270
		}
1281
//		Collection<XYZLayerRank> ranksVal = layerRanks.values();
1282
//		int numberOfRanks = ranksVal.size();
1283
//		xml.putProperty("numberOfRanks", numberOfRanks);
1284
//		Iterator<XYZLayerRank> xyzRankIterator = layerRanks.values().iterator();
1285
//		while (xyzRankIterator.hasNext()) {
1286
//			XYZLayerRank layerRank = xyzRankIterator.next();
1287
//			XMLEntity entity = layerRank.getXMLEntity();
1288
//			xml.addChild(entity);
1289
//		}
1271 1290
		return xml;
1272 1291
	}
1273 1292

  
1274 1293
	public void setXMLEntity(XMLEntity xml) throws XMLException {
1275 1294
		super.setXMLEntity(xml);
1276 1295

  
1277
		// FIXME Cambiar el uso de childrenCount por el empleo de propiedades
1278 1296
		int numLayers = this.getLayersCount();
1279 1297
		int numProperties = this.getExtendedProperties().size();
1280 1298

  
......
1289 1307
		}
1290 1308

  
1291 1309
		if (xml.contains("status")) {
1292
			this.status = (byte) xml.getIntProperty("status");
1310
			int newStatus = xml.getIntProperty("status");
1311
			this.setStatus((byte) newStatus);
1293 1312
		}
1294 1313

  
1295 1314
		if (xml.contains("maxNumberOfErrors")) {
1296 1315
			this.maxNumberOfErrors = xml.getIntProperty("maxNumberOfErrors");
1297 1316
		}
1298

  
1317
		
1318
		if (xml.contains("nextRuleFid")) {
1319
			this.ruleId = xml.getIntProperty("nextRuleFid");
1320
		}
1321
	
1322
		boolean errorLayerExists = false;
1323
		if (xml.contains("errorLayerExists")) {
1324
			errorLayerExists = xml.getBooleanProperty("errorLayerExists");
1325
		}
1299 1326
		if (xml.contains("numberOfTopologyRules")) {
1300 1327
			int numberOfTopologyRules = xml
1301 1328
					.getIntProperty("numberOfTopologyRules");
......
1303 1330
				XMLEntity ruleXML = xml.getChild(childrenCount++);
1304 1331
				ITopologyRule rule = TopologyRuleFactory.createFromXML(this,
1305 1332
						ruleXML);
1333
				
1306 1334
				this.rules.add(rule);
1307 1335
			}
1308 1336
		}
1309 1337

  
1310
		if (xml.contains("numberOfClusterRules")) {
1311
			int numberOfClusterRules = xml
1312
					.getIntProperty("numberOfClusterRules");
1313
			for (int i = 0; i < numberOfClusterRules; i++) {
1314
				XMLEntity ruleXML = xml.getChild(childrenCount++);
1315
				MustBeLargerThanClusterTolerance rule = (MustBeLargerThanClusterTolerance) TopologyRuleFactory
1316
						.createFromXML(this, ruleXML);
1317
				this.clusterToleranceRules.add(rule);
1318
			}
1319
		}
1338
//		if (xml.contains("numberOfClusterRules")) {
1339
//			int numberOfClusterRules = xml
1340
//					.getIntProperty("numberOfClusterRules");
1341
//			for (int i = 0; i < numberOfClusterRules; i++) {
1342
//				XMLEntity ruleXML = xml.getChild(childrenCount++);
1343
//				MustBeLargerThanClusterTolerance rule = (MustBeLargerThanClusterTolerance) TopologyRuleFactory
1344
//						.createFromXML(this, ruleXML);
1345
//				this.clusterToleranceRules.add(rule);
1346
//			}
1347
//		}
1320 1348

  
1321 1349
		if (xml.contains("numberOfDirtyZones")) {
1322 1350
			int numberOfDirtyZones = xml.getIntProperty("numberOfDirtyZones");
......
1335 1363
		XMLEntity errorContainerXML = xml.getChild(childrenCount++);
1336 1364
		if (errorContainerXML != null) {
1337 1365
			this.errorContainer = TopologyPersister
1338
					.createErrorContainerFromXML(errorContainerXML);
1366
					.createErrorContainerFromXML(this, errorContainerXML);
1367
			if(errorLayerExists)
1368
			{
1369
				setErrorLyr();
1370
				updateErrorLyr();
1371
			}
1372
			
1339 1373
		}
1340 1374

  
1341
		if (xml.contains("numberOfRanks")) {
1342
			int numberOfRanks = xml.getIntProperty("numberOfRanks");
1343
			for (int i = 0; i < numberOfRanks; i++) {
1344
				XMLEntity xmlRank = xml.getChild(childrenCount++);
1345
				XYZLayerRank rank = new XYZLayerRank();
1346
				rank.setXMLEntity(xmlRank);
1347
			}
1348
		}
1375
//		if (xml.contains("numberOfRanks")) {
1376
//			int numberOfRanks = xml.getIntProperty("numberOfRanks");
1377
//			for (int i = 0; i < numberOfRanks; i++) {
1378
//				XMLEntity xmlRank = xml.getChild(childrenCount++);
1379
//				XYZLayerRank rank = new XYZLayerRank();
1380
//				rank.setXMLEntity(xmlRank);
1381
//			}
1382
//		}
1349 1383
	}
1350 1384

  
1351 1385
	public int getNumberOfExceptions() {
......
1401 1435
		this.statusListeners = statusListeners;
1402 1436
	}
1403 1437

  
1404
	public void setLayerRanks(Map<FLyrVect, XYZLayerRank> layerRanks) {
1405
		this.layerRanks = layerRanks;
1406
	}
1438
//	public void setLayerRanks(Map<FLyrVect, XYZLayerRank> layerRanks) {
1439
//		this.layerRanks = layerRanks;
1440
//	}
1407 1441

  
1408 1442
	public Object clone() {
1409 1443
		Topology newTopology = new Topology(super.getMapContext(), super
......
1454 1488
		
1455 1489
//		to.setStatusListeners(from.statusListeners);
1456 1490
		
1457
		to.setLayerRanks(from.layerRanks);
1491
//		to.setLayerRanks(from.layerRanks);
1458 1492
		
1459 1493
		to.ruleId = from.ruleId;
1460 1494
		
......
1485 1519

  
1486 1520
	public void removeError(TopologyError topologyError) {
1487 1521
		this.errorContainer.removeError(topologyError);
1522
		
1523
		Rectangle2D rect = topologyError.getGeometry().getBounds2D();
1524
		removeDirtyZone(rect);
1525
		if (status == VALIDATED_WITH_DIRTY_ZONES) {
1526
			if (dirtyZones.size() == 0)
1527
				setStatus(VALIDATED);
1528
		} else if (status == VALIDATED_WITH_ERRORS) {
1529
			if (getNumberOfErrors() == getNumberOfExceptions() || getNumberOfErrors() == 0)
1530
				setStatus(VALIDATED);
1531
		}
1488 1532
	}
1489 1533
	
1490 1534
	public List<LayerCollectionListener> getLayerCollectionListeners(){
trunk/libraries/libTopology/src/org/gvsig/fmap/core/FeatureUtil.java
173 173
		return solution;
174 174
	}
175 175
	
176
	private static IGeometry geometryFromXmlByteArray(String xmlByteArray){
177
		String[] bytes = xmlByteArray.split(",");
178
		byte[] wkbErrorGeometry = new byte[bytes.length];
179
		for(int i = 0; i < bytes.length; i++){
180
			wkbErrorGeometry[i] = new Byte(bytes[i].trim()).byteValue();
181
		}
182
		return wkbParser.parse(wkbErrorGeometry);
183
	}
176 184
	
177
	
178 185
	public static void setXMLEntity(IFeature feature, XMLEntity xml){
179 186
		if(xml.contains("fid")){
180 187
			feature.setID(xml.getStringProperty("fid"));
181 188
		}
182 189
		
183 190
		if(xml.contains("geometry")){
184
			byte[] wkbErrorGeometry = (byte[]) xml.getObjectProperty("geometry");
185
			feature.setGeometry( wkbParser.parse(wkbErrorGeometry) );
191
			String xmlByteArray = (String) xml.getObjectProperty("geometry");
192
			feature.setGeometry( geometryFromXmlByteArray(xmlByteArray) );
186 193
		}
187 194
		
188 195
		if(xml.contains("numberOfAttributes")){
......
211 218
		}
212 219
		
213 220
		if(xml.contains("geometry")){
214
			byte[] wkbErrorGeometry = (byte[]) xml.getObjectProperty("geometry");
215
			geometry = wkbParser.parse(wkbErrorGeometry);
221
			String xmlByteArray = (String) xml.getObjectProperty("geometry");
222
			geometry = geometryFromXmlByteArray(xmlByteArray);
216 223
		}
217 224
		
218 225
		if(xml.contains("numberOfAttributes")){

Also available in: Unified diff