Revision 2616 org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.splitline/src/main/java/org/gvsig/vectorediting/lib/prov/splitline/SplitLineEditingProvider.java
SplitLineEditingProvider.java | ||
---|---|---|
25 | 25 |
package org.gvsig.vectorediting.lib.prov.splitline; |
26 | 26 |
|
27 | 27 |
import java.util.ArrayList; |
28 |
import java.util.Arrays; |
|
28 | 29 |
import java.util.HashMap; |
29 | 30 |
import java.util.List; |
30 | 31 |
import java.util.Map; |
31 |
|
|
32 | 32 |
import org.gvsig.fmap.dal.exception.DataException; |
33 | 33 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
34 | 34 |
import org.gvsig.fmap.dal.feature.Feature; |
... | ... | |
49 | 49 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
50 | 50 |
import org.gvsig.tools.ToolsLocator; |
51 | 51 |
import org.gvsig.tools.dispose.DisposableIterator; |
52 |
import org.gvsig.tools.dispose.DisposeUtils; |
|
52 | 53 |
import org.gvsig.tools.dynobject.DynObject; |
53 | 54 |
import org.gvsig.tools.exception.BaseException; |
54 | 55 |
import org.gvsig.tools.locator.LocatorException; |
55 | 56 |
import org.gvsig.tools.service.spi.ProviderServices; |
56 |
import org.gvsig.tools.visitor.VisitCanceledException; |
|
57 |
import org.gvsig.tools.visitor.Visitor; |
|
58 | 57 |
import org.gvsig.vectorediting.lib.api.DrawingStatus; |
59 | 58 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter; |
60 | 59 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter.TYPE; |
... | ... | |
81 | 80 |
public class SplitLineEditingProvider extends AbstractEditingProvider implements |
82 | 81 |
EditingProvider { |
83 | 82 |
|
84 |
private EditingServiceParameter selection; |
|
83 |
private final EditingServiceParameter selection;
|
|
85 | 84 |
|
86 |
private EditingServiceParameter point; |
|
85 |
private final EditingServiceParameter point;
|
|
87 | 86 |
|
88 |
private FeatureStore featureStore; |
|
87 |
private final FeatureStore featureStore;
|
|
89 | 88 |
|
90 | 89 |
private Map<EditingServiceParameter, Object> values; |
91 | 90 |
|
92 | 91 |
/** |
93 | 92 |
* Default constructor. |
94 | 93 |
* |
95 |
* @param providerServices
|
|
94 |
* @param services
|
|
96 | 95 |
* available services for this provider |
97 | 96 |
* @param parameters |
98 | 97 |
* of this provider |
... | ... | |
114 | 113 |
"indicate_new_point", TYPE.POSITION); |
115 | 114 |
} |
116 | 115 |
|
116 |
@Override |
|
117 | 117 |
public EditingServiceParameter next() { |
118 | 118 |
|
119 | 119 |
if (values.get(selection) == null) { |
... | ... | |
124 | 124 |
return null; |
125 | 125 |
} |
126 | 126 |
|
127 |
@Override |
|
127 | 128 |
public DrawingStatus getDrawingStatus(Point mousePosition) |
128 | 129 |
throws DrawServiceException { |
129 | 130 |
if (values != null) { |
... | ... | |
133 | 134 |
ISymbol auxiliaryPointSymbolEditing = editingProviderManager.getSymbol("auxiliary-point-symbol-editing"); |
134 | 135 |
ISymbol auxiliaryLineSymbolEditing = editingProviderManager.getSymbol("auxiliary-line-symbol-editing"); |
135 | 136 |
|
137 |
|
|
136 | 138 |
FeatureSelection featureSelection = |
137 | 139 |
(FeatureSelection) values.get(selection); |
138 | 140 |
|
... | ... | |
148 | 150 |
while (it.hasNext()) { |
149 | 151 |
|
150 | 152 |
Feature feature = (Feature) it.next(); |
153 |
|
|
154 |
ISymbol previewSymbol = this.getPreviewSymbol(feature); |
|
151 | 155 |
|
152 | 156 |
Geometry lineToSplit = |
153 | 157 |
getLineToSplit(feature.getDefaultGeometry()); |
... | ... | |
164 | 168 |
} catch (Exception e) { |
165 | 169 |
throw new DrawServiceException(e); |
166 | 170 |
} finally { |
167 |
it.dispose();
|
|
171 |
DisposeUtils.disposeQuietly(it);
|
|
168 | 172 |
} |
169 | 173 |
return drawingStatus; |
170 | 174 |
} |
... | ... | |
189 | 193 |
return (Point) lineToSplit.closestPoints(point)[0]; |
190 | 194 |
} |
191 | 195 |
|
196 |
@Override |
|
192 | 197 |
public void stop() throws StopServiceException { |
193 | 198 |
if (values != null) { |
194 | 199 |
values.clear(); |
195 | 200 |
} |
196 | 201 |
} |
197 | 202 |
|
203 |
@Override |
|
198 | 204 |
public List<EditingServiceParameter> getParameters() { |
199 | 205 |
List<EditingServiceParameter> parameters = |
200 |
new ArrayList<EditingServiceParameter>();
|
|
206 |
new ArrayList<>(); |
|
201 | 207 |
parameters.add(selection); |
202 | 208 |
parameters.add(point); |
203 | 209 |
return parameters; |
... | ... | |
208 | 214 |
validateAndInsertValue(parameter, value); |
209 | 215 |
} |
210 | 216 |
|
217 |
@Override |
|
211 | 218 |
public void setValue(Object value) throws InvalidEntryException { |
212 | 219 |
EditingServiceParameter parameter = next(); |
213 | 220 |
validateAndInsertValue(parameter, value); |
... | ... | |
225 | 232 |
if (feautureSelection.getSelectedCount() == 1) { |
226 | 233 |
|
227 | 234 |
try { |
228 |
feautureSelection.accept(new Visitor() { |
|
229 |
|
|
230 |
public void visit(Object obj) |
|
231 |
throws VisitCanceledException, BaseException { |
|
232 |
Feature feature = (Feature) obj; |
|
233 |
Geometry geometry = |
|
235 |
feautureSelection.accept((Object obj) -> { |
|
236 |
Feature feature = (Feature) obj; |
|
237 |
Geometry geometry = |
|
234 | 238 |
feature.getDefaultGeometry(); |
235 |
GeometryType geoType =
|
|
239 |
GeometryType geoType = |
|
236 | 240 |
geometry.getGeometryType(); |
237 |
|
|
238 |
if (geoType.isTypeOf(Geometry.TYPES.CURVE)) { |
|
239 |
|
|
240 |
if (isAnArcClosed((Curve) geometry)) { |
|
241 |
throw new InvalidEntryException(null); |
|
242 |
} else { |
|
243 |
values.put(selection, value); |
|
244 |
return; |
|
245 |
} |
|
246 |
|
|
247 |
} else if (geoType |
|
241 |
|
|
242 |
if (geoType.isTypeOf(Geometry.TYPES.CURVE)) { |
|
243 |
|
|
244 |
if (isAnArcClosed((Curve) geometry)) { |
|
245 |
throw new InvalidEntryException(null); |
|
246 |
} else { |
|
247 |
values.put(selection, value); |
|
248 |
} |
|
249 |
|
|
250 |
} else if (geoType |
|
248 | 251 |
.isTypeOf(Geometry.TYPES.MULTICURVE)) { |
249 |
|
|
250 |
MultiCurve multiCurve =
|
|
252 |
|
|
253 |
MultiCurve multiCurve = |
|
251 | 254 |
(MultiCurve) geometry; |
252 |
|
|
253 |
for (int i = 0; i < multiCurve
|
|
255 |
|
|
256 |
for (int i = 0; i < multiCurve |
|
254 | 257 |
.getPrimitivesNumber(); i++) { |
255 |
if (isAnArcClosed((Curve) multiCurve
|
|
258 |
if (isAnArcClosed((Curve) multiCurve |
|
256 | 259 |
.getPrimitiveAt(i))) { |
257 |
throw new InvalidEntryException(
|
|
260 |
throw new InvalidEntryException( |
|
258 | 261 |
null); |
259 |
} |
|
260 | 262 |
} |
261 |
values.put(selection, value); |
|
262 |
return; |
|
263 | 263 |
} |
264 |
values.put(selection, value); |
|
264 | 265 |
} |
265 | 266 |
}); |
266 | 267 |
return; |
... | ... | |
289 | 290 |
return false; |
290 | 291 |
} |
291 | 292 |
|
293 |
@Override |
|
292 | 294 |
public Geometry finish() throws FinishServiceException { |
293 | 295 |
return null; |
294 | 296 |
} |
295 | 297 |
|
298 |
@Override |
|
296 | 299 |
public void finishAndStore() throws FinishServiceException { |
297 | 300 |
|
298 | 301 |
if (values != null) { |
... | ... | |
307 | 310 |
final Point pointValue = (Point) values.get(point); |
308 | 311 |
|
309 | 312 |
try { |
310 |
featureSelection.accept(new Visitor() { |
|
311 |
|
|
312 |
public void visit(Object obj) |
|
313 |
throws VisitCanceledException, BaseException { |
|
314 |
Feature feature = (Feature) obj; |
|
315 |
|
|
316 |
Geometry lineToSplit = |
|
313 |
featureSelection.accept((Object obj) -> { |
|
314 |
Feature feature = (Feature) obj; |
|
315 |
|
|
316 |
Geometry lineToSplit = |
|
317 | 317 |
getLineToSplit(feature.getDefaultGeometry()); |
318 |
GeometryType geomType = lineToSplit.getGeometryType();
|
|
319 |
|
|
320 |
Point projectedPoint =
|
|
318 |
GeometryType geomType = lineToSplit.getGeometryType(); |
|
319 |
|
|
320 |
Point projectedPoint = |
|
321 | 321 |
getNearestPoint(lineToSplit, pointValue); |
322 |
|
|
323 |
if (geomType.isTypeOf(Geometry.TYPES.CURVE)) {
|
|
324 |
|
|
325 |
Curve[] splittedCurves =
|
|
322 |
|
|
323 |
if (geomType.isTypeOf(Geometry.TYPES.CURVE)) { |
|
324 |
|
|
325 |
Curve[] splittedCurves = |
|
326 | 326 |
splitCurve((Curve) lineToSplit, projectedPoint); |
327 |
|
|
328 |
// Deletes old feature
|
|
329 |
editingProviderService
|
|
327 |
|
|
328 |
// Deletes old feature |
|
329 |
editingProviderService |
|
330 | 330 |
.deleteFeatureFromFeatureStore(feature, |
331 |
featureStore); |
|
332 |
|
|
333 |
// Copy alfanumeric data and insert new feature
|
|
334 |
EditableFeature eFeature =
|
|
331 |
featureStore);
|
|
332 |
|
|
333 |
// Copy alfanumeric data and insert new feature |
|
334 |
EditableFeature eFeature = |
|
335 | 335 |
editingProviderService.getFeatureCopyWithoutUniqueIndex( |
336 |
featureStore, feature); |
|
337 |
eFeature.setDefaultGeometry(splittedCurves[0]);
|
|
338 |
editingProviderService
|
|
336 |
featureStore, feature);
|
|
337 |
eFeature.setDefaultGeometry(splittedCurves[0]); |
|
338 |
editingProviderService |
|
339 | 339 |
.insertFeatureIntoFeatureStore(eFeature, |
340 |
featureStore); |
|
341 |
|
|
342 |
eFeature =
|
|
340 |
featureStore);
|
|
341 |
|
|
342 |
eFeature = |
|
343 | 343 |
editingProviderService.getFeatureCopyWithoutUniqueIndex( |
344 |
featureStore, feature); |
|
345 |
eFeature.setDefaultGeometry(splittedCurves[1]);
|
|
346 |
editingProviderService
|
|
344 |
featureStore, feature);
|
|
345 |
eFeature.setDefaultGeometry(splittedCurves[1]); |
|
346 |
editingProviderService |
|
347 | 347 |
.insertFeatureIntoFeatureStore(eFeature, |
348 |
featureStore); |
|
349 |
|
|
350 |
} else if (geomType.isTypeOf(Geometry.TYPES.MULTICURVE)) { |
|
351 |
|
|
352 |
MultiCurve multiCurve = (MultiCurve) lineToSplit; |
|
353 |
|
|
354 |
List<Geometry> result = splitMultiCurve(multiCurve, projectedPoint); |
|
355 |
|
|
356 |
if (result != null && result.size() > 0) { |
|
357 |
|
|
358 |
// Deletes old feature |
|
359 |
editingProviderService |
|
360 |
.deleteFeatureFromFeatureStore(feature, |
|
361 | 348 |
featureStore); |
362 |
|
|
363 |
for (Geometry geometry : result) { |
|
364 |
// Copy alfanumeric data and insert new feature |
|
365 |
EditableFeature eFeature = |
|
349 |
|
|
350 |
} else if (geomType.isTypeOf(Geometry.TYPES.MULTICURVE)) { |
|
351 |
|
|
352 |
MultiCurve multiCurve = (MultiCurve) lineToSplit; |
|
353 |
|
|
354 |
List<Geometry> result = splitMultiCurve(multiCurve, projectedPoint); |
|
355 |
|
|
356 |
if (result != null && result.size() > 0) { |
|
357 |
|
|
358 |
// Deletes old feature |
|
359 |
editingProviderService |
|
360 |
.deleteFeatureFromFeatureStore(feature, |
|
361 |
featureStore); |
|
362 |
|
|
363 |
for (Geometry geometry : result) { |
|
364 |
// Copy alfanumeric data and insert new feature |
|
365 |
EditableFeature eFeature = |
|
366 | 366 |
editingProviderService.getFeatureCopyWithoutUniqueIndex( |
367 |
featureStore, feature); |
|
368 |
|
|
369 |
eFeature.setDefaultGeometry(geometry);
|
|
370 |
editingProviderService
|
|
367 |
featureStore, feature);
|
|
368 |
|
|
369 |
eFeature.setDefaultGeometry(geometry); |
|
370 |
editingProviderService |
|
371 | 371 |
.insertFeatureIntoFeatureStore(eFeature, |
372 |
featureStore); |
|
373 |
} |
|
372 |
featureStore); |
|
374 | 373 |
} |
375 | 374 |
} |
376 | 375 |
} |
... | ... | |
390 | 389 |
GeometryOperationException, LocatorException, |
391 | 390 |
DataException, GeometryException { |
392 | 391 |
|
393 |
List<Geometry> result = new ArrayList<Geometry>();
|
|
392 |
List<Geometry> result = new ArrayList<>(); |
|
394 | 393 |
|
395 | 394 |
Curve curveToSplit = null; |
396 | 395 |
|
... | ... | |
403 | 402 |
|
404 | 403 |
Curve[] splitedCurves = splitCurve(curveToSplit, projectedPoint); |
405 | 404 |
|
406 |
for(int i = 0; i < splitedCurves.length; i++){ |
|
407 |
result.add(splitedCurves[i]); |
|
408 |
} |
|
405 |
result.addAll(Arrays.asList(splitedCurves)); |
|
409 | 406 |
|
410 | 407 |
EditingProviderServices editingProviderService = |
411 | 408 |
(EditingProviderServices) getProviderServices(); |
... | ... | |
460 | 457 |
return curve.buffer(tolerance).intersects(projectedPoint); |
461 | 458 |
} |
462 | 459 |
|
460 |
@Override |
|
463 | 461 |
public void start() throws StartServiceException, InvalidEntryException { |
464 |
values = new HashMap<EditingServiceParameter, Object>();
|
|
462 |
values = new HashMap<>(); |
|
465 | 463 |
FeatureSelection selected = null; |
466 | 464 |
if (featureStore != null) { |
467 | 465 |
try { |
... | ... | |
475 | 473 |
} |
476 | 474 |
} |
477 | 475 |
|
476 |
@Override |
|
478 | 477 |
public String getName() { |
479 | 478 |
return SplitLineEditingProviderFactory.PROVIDER_NAME; |
480 | 479 |
} |
Also available in: Unified diff