Revision 3067 org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.trimline/src/main/java/org/gvsig/vectorediting/lib/prov/trimline/TrimPolygonEditingProvider.java
TrimPolygonEditingProvider.java | ||
---|---|---|
25 | 25 |
package org.gvsig.vectorediting.lib.prov.trimline; |
26 | 26 |
|
27 | 27 |
import java.util.ArrayList; |
28 |
import java.util.Collections; |
|
28 | 29 |
import java.util.HashMap; |
29 | 30 |
import java.util.List; |
30 | 31 |
import java.util.Map; |
31 |
import java.util.logging.Level; |
|
32 |
import java.util.logging.Logger; |
|
33 | 32 |
import org.gvsig.fmap.dal.exception.DataException; |
34 | 33 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
35 | 34 |
import org.gvsig.fmap.dal.feature.Feature; |
... | ... | |
47 | 46 |
import org.gvsig.fmap.mapcontext.MapContext; |
48 | 47 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
49 | 48 |
import org.gvsig.tools.dispose.DisposableIterator; |
50 |
import org.gvsig.tools.dispose.DisposeUtils; |
|
51 | 49 |
import org.gvsig.tools.dynobject.DynObject; |
52 | 50 |
import org.gvsig.tools.exception.BaseException; |
53 | 51 |
import org.gvsig.tools.service.spi.ProviderServices; |
... | ... | |
69 | 67 |
import org.gvsig.vectorediting.lib.spi.EditingProviderServices; |
70 | 68 |
|
71 | 69 |
/** |
72 |
* @author llmarques
|
|
70 |
* @author gvSIG Team
|
|
73 | 71 |
* |
74 | 72 |
*/ |
73 |
@SuppressWarnings("UseSpecificCatch") |
|
75 | 74 |
public class TrimPolygonEditingProvider extends AbstractEditingProvider implements |
76 | 75 |
EditingProvider { |
77 | 76 |
|
... | ... | |
89 | 88 |
|
90 | 89 |
private final MapContext mapContext; |
91 | 90 |
|
91 |
private List<Feature> selectedFeatures; |
|
92 |
|
|
92 | 93 |
/** |
93 | 94 |
* Default constructor. |
94 | 95 |
* |
... | ... | |
150 | 151 |
|
151 | 152 |
try { |
152 | 153 |
|
153 |
DisposableIterator selectionIterator = selection.fastIterator(); |
|
154 |
while (selectionIterator.hasNext()) { |
|
155 |
Feature feature = (Feature) selectionIterator.next(); |
|
154 |
for (Feature feature : selectedFeatures) { |
|
156 | 155 |
if (feature != null) { |
157 | 156 |
ISymbol previewSymbol = this.getPreviewSymbol(feature); |
158 | 157 |
|
... | ... | |
200 | 199 |
@Override |
201 | 200 |
public void stop() throws StopServiceException { |
202 | 201 |
values.clear(); |
202 |
this.selectedFeatures = Collections.EMPTY_LIST; |
|
203 | 203 |
} |
204 | 204 |
|
205 | 205 |
@Override |
... | ... | |
228 | 228 |
throws InvalidEntryException { |
229 | 229 |
|
230 | 230 |
if (parameter == selectionParameter) { |
231 |
if (value instanceof FeatureSelection) { |
|
232 |
FeatureSelection featureSelection = (FeatureSelection) value; |
|
233 |
if (featureSelection.getSelectedCount() > 0) { |
|
234 |
try { |
|
235 |
featureSelection.accept((Object obj) -> { |
|
236 |
Feature feature = (Feature) obj; |
|
237 |
Geometry geometry |
|
238 |
= feature.getDefaultGeometry(); |
|
239 |
|
|
240 |
if (!isValidGeometryToSelect(geometry)) { |
|
241 |
throw new InvalidEntryException(null); |
|
242 |
} |
|
243 |
}); |
|
244 |
values.put(parameter, featureSelection); |
|
245 |
return; |
|
246 |
} catch (BaseException e) { |
|
247 |
throw new InvalidEntryException(e); |
|
248 |
} |
|
231 |
this.selectedFeatures = this.getSelectedFeaturesCopy((FeatureSelection) value); |
|
232 |
for (Feature feature : selectedFeatures) { |
|
233 |
Geometry geometry= feature.getDefaultGeometry(); |
|
234 |
if (!isValidGeometryToSelect(geometry)) { |
|
235 |
this.selectedFeatures = Collections.EMPTY_LIST; |
|
236 |
throw new InvalidEntryException(null); |
|
249 | 237 |
} |
250 | 238 |
} |
239 |
values.put(parameter, value); |
|
240 |
return; |
|
251 | 241 |
} else if (parameter == geometryToTrimWithParameter && value instanceof Point) { |
252 | 242 |
|
253 | 243 |
if (value instanceof Point) { |
... | ... | |
316 | 306 |
Point point = (Point) values.get(shearingPointParameter); |
317 | 307 |
|
318 | 308 |
if (selection != null && shearsGeometry != null && point != null) { |
319 |
DisposableIterator selectionIterator = null; |
|
320 | 309 |
try { |
321 |
selectionIterator = selection.fastIterator(); |
|
322 |
while (selectionIterator.hasNext()) { |
|
323 |
Feature feature = (Feature) selectionIterator.next(); |
|
324 |
|
|
310 |
for (Feature feature : selectedFeatures) { |
|
325 | 311 |
Geometry geometry = feature.getDefaultGeometry(); |
326 |
|
|
327 | 312 |
EditableFeature eFeature = feature.getEditable(); |
328 |
|
|
329 | 313 |
if(geometry.intersects(shearsGeometry)){ |
330 | 314 |
eFeature.setDefaultGeometry(trimSurface(point, geometry, shearsGeometry)); |
331 | 315 |
selection.update(eFeature); |
... | ... | |
333 | 317 |
} |
334 | 318 |
} catch (BaseException ex) { |
335 | 319 |
throw new FinishServiceException(ex); |
336 |
} finally { |
|
337 |
DisposeUtils.disposeQuietly(selectionIterator); |
|
338 | 320 |
} |
339 | 321 |
} |
340 | 322 |
} |
341 | 323 |
|
342 | 324 |
@Override |
343 | 325 |
public void start() throws StartServiceException, InvalidEntryException { |
344 |
|
|
345 | 326 |
this.values = new HashMap<>(); |
346 |
FeatureSelection selected = null; |
|
347 |
if (featureStore != null && values.get(selectionParameter) == null) { |
|
327 |
this.selectedFeatures = Collections.EMPTY_LIST; |
|
328 |
if (featureStore != null) { |
|
329 |
FeatureSelection selected = null; |
|
348 | 330 |
try { |
349 |
selected = featureStore.getFeatureSelection();
|
|
331 |
selected = (FeatureSelection) featureStore.getFeatureSelection().clone();
|
|
350 | 332 |
} catch (DataException e) { |
351 | 333 |
throw new StartServiceException(e); |
334 |
} catch (CloneNotSupportedException ex) { |
|
335 |
LOGGER.debug("Can't init selection",ex); |
|
352 | 336 |
} |
353 |
if (selected.getSelectedCount() > 0) { |
|
354 |
try { |
|
355 |
setValue(selected); |
|
356 |
} catch (InvalidEntryException e) { |
|
357 |
throw new InvalidEntryException(e); |
|
358 |
} |
|
337 |
if ((selected != null) && (selected.getSelectedCount() > 0)) { |
|
338 |
values.put(selectionParameter, selected); |
|
339 |
this.selectedFeatures = this.getSelectedFeaturesCopy(selected); |
|
359 | 340 |
} |
360 | 341 |
} |
361 | 342 |
|
Also available in: Unified diff