Revision 4447 trunk/extensions/extGeoProcessing/src/com/iver/gvsig/geoprocessing/impl/intersection/IntersectionGeoprocess.java

View differences:

IntersectionGeoprocess.java
45 45
 *
46 46
 * $Id$
47 47
 * $Log$
48
 * Revision 1.4  2006-03-14 18:32:46  fjp
48
 * Revision 1.5  2006-03-15 18:33:36  azabala
49
 * *** empty log message ***
50
 *
51
 * Revision 1.4  2006/03/14 18:32:46  fjp
49 52
 * Cambio con LayerDefinition para que sea compatible con la definici?n de tablas tambi?n.
50 53
 *
51 54
 * Revision 1.3  2006/03/07 21:01:33  azabala
......
66 69
import com.hardcode.gdbms.engine.data.driver.DriverException;
67 70
import com.iver.cit.gvsig.fmap.core.IFeature;
68 71
import com.iver.cit.gvsig.fmap.core.IGeometry;
72
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
69 73
import com.iver.cit.gvsig.fmap.drivers.ILayerDefinition;
70
import com.iver.cit.gvsig.fmap.drivers.ITableDefinition;
71 74
import com.iver.cit.gvsig.fmap.edition.EditionException;
72 75
import com.iver.cit.gvsig.fmap.layers.FBitSet;
73 76
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
77
import com.iver.cit.gvsig.fmap.operations.CancellableMonitorable;
78
import com.iver.cit.gvsig.fmap.operations.DefaultCancellableMonitorable;
74 79
import com.iver.cit.gvsig.fmap.operations.strategies.Strategy;
75 80
import com.iver.cit.gvsig.fmap.operations.strategies.StrategyManager;
76 81
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException;
......
80 85
import com.iver.gvsig.geoprocessing.model.IOverlayGeoprocess;
81 86
import com.iver.gvsig.geoprocessing.schemabuilder.DefinitionUtils;
82 87
import com.iver.gvsig.geoprocessing.schemabuilder.XTypes;
88
import com.iver.utiles.swing.threads.IMonitorableTask;
83 89
/**
84 90
 * Computes intersection between two layers.
85 91
 * 
......
224 230
		return null;
225 231
	}
226 232

  
233
	public IMonitorableTask createTask() {
234
		try {
235
			return new IntersectionMonitorableTask();
236
		} catch (DriverIOException e) {
237
			return null;
238
		}
239
	}
240
	
241
	/**
242
	 * IMonitorableTask that allows to run diff geoprocess in background,
243
	 * with cancelation requests.
244
	 * 
245
	 * @author azabala
246
	 * 
247
	 */
248
	class IntersectionMonitorableTask implements IMonitorableTask {
249
		private CancellableMonitorable cancelMonitor = null;
250

  
251
		// FIXME INTERNACIONALIZAR ESTO
252
		String INTERSECTION_MESSAGE = "Computing intersections: ";
253

  
254
		private boolean finished = false;
255

  
256
		IntersectionMonitorableTask() throws DriverIOException {
257
			initialize();
258
		}
259
		void initialize() throws DriverIOException {
260
			cancelMonitor = createCancelMonitor();
261
		}
262

  
263
		private CancellableMonitorable createCancelMonitor()
264
				throws DriverIOException {
265
			DefaultCancellableMonitorable monitor = new 
266
							DefaultCancellableMonitorable();
267
			monitor.setInitialStep(0);
268
			//Really its undeterminated, but  we must to process all
269
			//elements of first layer (or selection) we are going to 
270
			//consideer determinated
271
			monitor.setDeterminatedProcess(true);
272
			int numSteps = 0;
273
			if (onlyFirstLayerSelection) {
274
				FBitSet selection = firstLayer.getRecordset().getSelection();
275
				numSteps = selection.cardinality();
276
			} else {
277
				numSteps = firstLayer.getSource().getShapeCount();
278
			}
279
			monitor.setFinalStep(numSteps);
280
			return monitor;
281
		}
282

  
283
		public int getInitialStep() {
284
			return cancelMonitor.getInitialStep();
285
		}
286

  
287
		public int getFinishStep() {
288
			return cancelMonitor.getFinalStep();
289
		}
290

  
291
		public int getCurrentStep() {
292
			return cancelMonitor.getCurrentStep();
293
		}
294

  
295
		public String getStatusMessage() {
296
			// FIXME Cambiar esto por un mecanismo de eventos,
297
			// de forma que la tarea lo que tenga sea un escuchador
298
			// que cambie el mensaje de estado segun los eventos
299
			// de tareas que se est?n realizando
300
			return "Intersection Geoprocess...";
301
		}
302

  
303
		public String getNote() {
304
			// FIXME Cambiar esto por un mecanismo de eventos,
305
			// de forma que la tarea lo que tenga sea un escuchador
306
			// que cambie el mensaje de estado segun los eventos
307
			// de tareas que se est?n realizando
308
			return INTERSECTION_MESSAGE + getCurrentStep() + "of " + getFinishStep();
309
		}
310

  
311
		public void cancel() {
312
			((DefaultCancellableMonitorable) cancelMonitor).setCanceled(true);
313
		}
314

  
315
		public void run() throws GeoprocessException {
316

  
317
			try {
318
				//Prepare the result
319
				schemaManager.createOrAlterSchema(createLayerDefinition());
320
				writer.preProcess();
321
				Strategy strategy = 
322
					StrategyManager.getStrategy(firstLayer);
323
				Strategy overlayStrategy = 
324
					StrategyManager.getStrategy(overlayLayer);
325
				FeaturePersisterProcessor2 featureProcessor =
326
					new FeaturePersisterProcessor2(writer);
327
				IntersectVisitor visitor = new IntersectVisitor(overlayLayer, 
328
															featureProcessor, 
329
															overlayStrategy,
330
															onlyClipLayerSelection);
331
				if(onlyFirstLayerSelection){
332
					strategy.process(visitor, 
333
						firstLayer.getRecordset().getSelection(),
334
						cancelMonitor);
335
				}else{
336
					strategy.process(visitor, cancelMonitor);
337
				}
338
				
339
			} catch (EditionException e) {
340
				throw new GeoprocessException("Error al crear el esquema/fichero de la nueva capa");
341
			} catch (DriverException e) {
342
				throw new GeoprocessException("Error de driver al calcular el geoproceso interseccion");
343
			} catch (com.iver.cit.gvsig.fmap.DriverException e) {
344
				throw new GeoprocessException("Error de driver al calcular el geoproceso interseccion");
345
			} catch (VisitException e) {
346
				throw new GeoprocessException("Error al procesar el feature de una capa durante el geoproceso interseccion");
347
			}finally{
348
				finished = true;
349
			}
350
		}
351

  
352
		public boolean isDefined() {
353
			return cancelMonitor.isDeterminatedProcess();
354
		}
355

  
356
		public boolean isCanceled() {
357
			return cancelMonitor.isCanceled();
358
		}
359

  
360
		public boolean isFinished() {
361
			return finished;
362
		}
363
	}
364

  
227 365
}

Also available in: Unified diff