Revision 4447 trunk/extensions/extGeoProcessing/src/com/iver/gvsig/geoprocessing/impl/difference/DifferenceGeoprocess.java
DifferenceGeoprocess.java | ||
---|---|---|
45 | 45 |
* |
46 | 46 |
* $Id$ |
47 | 47 |
* $Log$ |
48 |
* Revision 1.5 2006-03-14 18:32:46 fjp |
|
48 |
* Revision 1.6 2006-03-15 18:31:50 azabala |
|
49 |
* *** empty log message *** |
|
50 |
* |
|
51 |
* Revision 1.5 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.4 2006/03/07 21:01:33 azabala |
... | ... | |
69 | 72 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
70 | 73 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
71 | 74 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
75 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
|
72 | 76 |
import com.iver.cit.gvsig.fmap.drivers.ILayerDefinition; |
73 |
import com.iver.cit.gvsig.fmap.drivers.ITableDefinition; |
|
74 | 77 |
import com.iver.cit.gvsig.fmap.edition.EditionException; |
75 | 78 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
76 | 79 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
80 |
import com.iver.cit.gvsig.fmap.operations.CancellableMonitorable; |
|
81 |
import com.iver.cit.gvsig.fmap.operations.DefaultCancellableMonitorable; |
|
77 | 82 |
import com.iver.cit.gvsig.fmap.operations.strategies.Strategy; |
78 | 83 |
import com.iver.cit.gvsig.fmap.operations.strategies.StrategyManager; |
79 | 84 |
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException; |
... | ... | |
83 | 88 |
import com.iver.gvsig.geoprocessing.model.IOverlayGeoprocess; |
84 | 89 |
import com.iver.gvsig.geoprocessing.schemabuilder.DefinitionUtils; |
85 | 90 |
import com.iver.gvsig.geoprocessing.schemabuilder.XTypes; |
91 |
import com.iver.utiles.swing.threads.IMonitorableTask; |
|
86 | 92 |
|
87 | 93 |
/** |
88 | 94 |
* This geoprocess computes diference geometries of two overlay polygon layers. |
... | ... | |
212 | 218 |
} |
213 | 219 |
|
214 | 220 |
public void cancel() { |
221 |
try { |
|
222 |
schemaManager.drop(); |
|
223 |
} catch (EditionException e) { |
|
224 |
// FIXME (debe lanzar una excepcion cancel) |
|
225 |
e.printStackTrace(); |
|
226 |
} |
|
215 | 227 |
} |
216 | 228 |
|
217 | 229 |
public ILayerDefinition createLayerDefinition() { |
... | ... | |
240 | 252 |
return null; |
241 | 253 |
} |
242 | 254 |
|
255 |
public IMonitorableTask createTask() { |
|
256 |
try { |
|
257 |
return new DifferenceMonitorableTask(); |
|
258 |
} catch (DriverIOException e) { |
|
259 |
//FIXME Debe lanzar excepcion createTask ? |
|
260 |
return null; |
|
261 |
} |
|
262 |
} |
|
263 |
|
|
264 |
/** |
|
265 |
* IMonitorableTask that allows to run diff geoprocess in background, |
|
266 |
* with cancelation requests. |
|
267 |
* |
|
268 |
* @author azabala |
|
269 |
* |
|
270 |
*/ |
|
271 |
class DifferenceMonitorableTask implements IMonitorableTask { |
|
272 |
private CancellableMonitorable cancelMonitor = null; |
|
273 |
|
|
274 |
// FIXME INTERNACIONALIZAR ESTO |
|
275 |
String DIFFERENCE_MESSAGE = "Computing differences: "; |
|
276 |
|
|
277 |
private boolean finished = false; |
|
278 |
|
|
279 |
DifferenceMonitorableTask() throws DriverIOException { |
|
280 |
initialize(); |
|
281 |
} |
|
282 |
void initialize() throws DriverIOException { |
|
283 |
cancelMonitor = createCancelMonitor(); |
|
284 |
} |
|
285 |
|
|
286 |
private CancellableMonitorable createCancelMonitor() |
|
287 |
throws DriverIOException { |
|
288 |
DefaultCancellableMonitorable monitor = new |
|
289 |
DefaultCancellableMonitorable(); |
|
290 |
monitor.setInitialStep(0); |
|
291 |
//Really its undeterminated, but so we must to process all |
|
292 |
//elements of first layer (or selection) we are going to |
|
293 |
//consideer determinated |
|
294 |
monitor.setDeterminatedProcess(true); |
|
295 |
int numSteps = 0; |
|
296 |
if (onlyFirstLayerSelection) { |
|
297 |
FBitSet selection = firstLayer.getRecordset().getSelection(); |
|
298 |
numSteps = selection.cardinality(); |
|
299 |
} else { |
|
300 |
numSteps = firstLayer.getSource().getShapeCount(); |
|
301 |
} |
|
302 |
monitor.setFinalStep(numSteps); |
|
303 |
return monitor; |
|
304 |
} |
|
305 |
|
|
306 |
public int getInitialStep() { |
|
307 |
return cancelMonitor.getInitialStep(); |
|
308 |
} |
|
309 |
|
|
310 |
public int getFinishStep() { |
|
311 |
return cancelMonitor.getFinalStep(); |
|
312 |
} |
|
313 |
|
|
314 |
public int getCurrentStep() { |
|
315 |
return cancelMonitor.getCurrentStep(); |
|
316 |
} |
|
317 |
|
|
318 |
public String getStatusMessage() { |
|
319 |
// FIXME Cambiar esto por un mecanismo de eventos, |
|
320 |
// de forma que la tarea lo que tenga sea un escuchador |
|
321 |
// que cambie el mensaje de estado segun los eventos |
|
322 |
// de tareas que se est?n realizando |
|
323 |
return "Difference Geoprocess..."; |
|
324 |
} |
|
325 |
|
|
326 |
public String getNote() { |
|
327 |
// FIXME Cambiar esto por un mecanismo de eventos, |
|
328 |
// de forma que la tarea lo que tenga sea un escuchador |
|
329 |
// que cambie el mensaje de estado segun los eventos |
|
330 |
// de tareas que se est?n realizando |
|
331 |
return DIFFERENCE_MESSAGE + getCurrentStep() + "of " + getFinishStep(); |
|
332 |
} |
|
333 |
|
|
334 |
public void cancel() { |
|
335 |
((DefaultCancellableMonitorable) cancelMonitor).setCanceled(true); |
|
336 |
} |
|
337 |
|
|
338 |
public void run() throws GeoprocessException { |
|
339 |
|
|
340 |
try { |
|
341 |
//FIXME Sacar esto de aqu? y ponerlo fuera. Marcaremos como precondicion |
|
342 |
//que el esquema del geoproceso haya sido creado |
|
343 |
// Prepare the result |
|
344 |
schemaManager.createOrAlterSchema(createLayerDefinition()); |
|
345 |
writer.preProcess(); |
|
346 |
Strategy strategy = |
|
347 |
StrategyManager.getStrategy(firstLayer); |
|
348 |
FeaturePersisterProcessor2 featureProcessor = |
|
349 |
new FeaturePersisterProcessor2(writer); |
|
350 |
Strategy overlayStrategy = |
|
351 |
StrategyManager.getStrategy(overlayLayer); |
|
352 |
DifferenceVisitor visitor = new DifferenceVisitor(overlayLayer, |
|
353 |
featureProcessor, overlayStrategy, onlyClipLayerSelection); |
|
354 |
if (onlyFirstLayerSelection) { |
|
355 |
strategy.process(visitor, firstLayer.getRecordset() |
|
356 |
.getSelection(), cancelMonitor); |
|
357 |
} else { |
|
358 |
strategy.process(visitor, cancelMonitor); |
|
359 |
} |
|
360 |
|
|
361 |
} catch (EditionException e) { |
|
362 |
throw new GeoprocessException( |
|
363 |
"Error al crear el esquema/fichero de la nueva capa"); |
|
364 |
} catch (DriverException e) { |
|
365 |
throw new GeoprocessException( |
|
366 |
"Error de driver al calcular el geoproceso interseccion"); |
|
367 |
} catch (com.iver.cit.gvsig.fmap.DriverException e) { |
|
368 |
throw new GeoprocessException( |
|
369 |
"Error de driver al calcular el geoproceso interseccion"); |
|
370 |
} catch (VisitException e) { |
|
371 |
throw new GeoprocessException( |
|
372 |
"Error al procesar el feature de una capa durante el geoproceso interseccion"); |
|
373 |
}finally{ |
|
374 |
finished = true; |
|
375 |
} |
|
376 |
} |
|
377 |
|
|
378 |
public boolean isDefined() { |
|
379 |
return cancelMonitor.isDeterminatedProcess(); |
|
380 |
} |
|
381 |
|
|
382 |
public boolean isCanceled() { |
|
383 |
return cancelMonitor.isCanceled(); |
|
384 |
} |
|
385 |
|
|
386 |
public boolean isFinished() { |
|
387 |
return finished; |
|
388 |
} |
|
389 |
} |
|
390 |
|
|
243 | 391 |
} |
Also available in: Unified diff