Revision 2616 org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.simplify/src/main/java/org/gvsig/vectorediting/lib/prov/simplify/SimplifyEditingProvider.java
SimplifyEditingProvider.java | ||
---|---|---|
28 | 28 |
import java.util.HashMap; |
29 | 29 |
import java.util.List; |
30 | 30 |
import java.util.Map; |
31 |
|
|
32 | 31 |
import org.gvsig.fmap.dal.exception.DataException; |
33 | 32 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
34 | 33 |
import org.gvsig.fmap.dal.feature.Feature; |
... | ... | |
52 | 51 |
import org.gvsig.tools.dynobject.DynObject; |
53 | 52 |
import org.gvsig.tools.exception.BaseException; |
54 | 53 |
import org.gvsig.tools.service.spi.ProviderServices; |
55 |
import org.gvsig.tools.visitor.VisitCanceledException; |
|
56 |
import org.gvsig.tools.visitor.Visitor; |
|
57 | 54 |
import org.gvsig.vectorediting.lib.api.DrawingStatus; |
58 | 55 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter; |
59 | 56 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter.TYPE; |
... | ... | |
75 | 72 |
public class SimplifyEditingProvider extends AbstractEditingProvider implements |
76 | 73 |
EditingProvider { |
77 | 74 |
|
78 |
private EditingServiceParameter selection; |
|
75 |
private final EditingServiceParameter selection;
|
|
79 | 76 |
|
80 |
private EditingServiceParameter tolerance; |
|
77 |
private final EditingServiceParameter tolerance;
|
|
81 | 78 |
|
82 |
private FeatureStore featureStore; |
|
79 |
private final FeatureStore featureStore;
|
|
83 | 80 |
|
84 | 81 |
private Map<EditingServiceParameter, Object> values; |
85 | 82 |
|
86 | 83 |
/** |
87 | 84 |
* Default constructor. |
88 | 85 |
* |
89 |
* @param providerServices
|
|
86 |
* @param services
|
|
90 | 87 |
* available services for this provider |
91 | 88 |
* @param parameters |
92 | 89 |
* of this provider |
... | ... | |
108 | 105 |
TYPE.VALUE); |
109 | 106 |
} |
110 | 107 |
|
108 |
@Override |
|
111 | 109 |
public EditingServiceParameter next() { |
112 | 110 |
if (values.get(selection) == null) { |
113 | 111 |
return selection; |
... | ... | |
117 | 115 |
return null; |
118 | 116 |
} |
119 | 117 |
|
118 |
@Override |
|
120 | 119 |
public DrawingStatus getDrawingStatus(Point mousePosition) |
121 | 120 |
throws DrawServiceException { |
122 | 121 |
return null; |
123 | 122 |
} |
124 | 123 |
|
124 |
@Override |
|
125 | 125 |
public void stop() throws StopServiceException { |
126 | 126 |
if (values != null) { |
127 | 127 |
values.clear(); |
128 | 128 |
} |
129 | 129 |
} |
130 | 130 |
|
131 |
@Override |
|
131 | 132 |
public List<EditingServiceParameter> getParameters() { |
132 | 133 |
List<EditingServiceParameter> parameters = |
133 |
new ArrayList<EditingServiceParameter>();
|
|
134 |
new ArrayList<>(); |
|
134 | 135 |
parameters.add(selection); |
135 | 136 |
parameters.add(tolerance); |
136 | 137 |
return parameters; |
... | ... | |
141 | 142 |
validateAndInsertValue(parameter, value); |
142 | 143 |
} |
143 | 144 |
|
145 |
@Override |
|
144 | 146 |
public void setValue(Object value) throws InvalidEntryException { |
145 | 147 |
EditingServiceParameter parameter = next(); |
146 | 148 |
validateAndInsertValue(parameter, value); |
... | ... | |
155 | 157 |
|
156 | 158 |
if (featureSelection.getSelectedCount() > 0) { |
157 | 159 |
try { |
158 |
featureSelection.accept(new Visitor() { |
|
159 |
|
|
160 |
public void visit(Object obj) |
|
161 |
throws VisitCanceledException, BaseException { |
|
162 |
|
|
163 |
Feature feature = (Feature) obj; |
|
164 |
Geometry geometry = feature.getDefaultGeometry(); |
|
165 |
GeometryType geometryType = |
|
160 |
featureSelection.accept((Object obj) -> { |
|
161 |
Feature feature = (Feature) obj; |
|
162 |
Geometry geometry = feature.getDefaultGeometry(); |
|
163 |
GeometryType geometryType = |
|
166 | 164 |
geometry.getGeometryType(); |
167 |
|
|
168 |
if (!geometryType
|
|
165 |
|
|
166 |
if (!geometryType |
|
169 | 167 |
.isTypeOf(Geometry.TYPES.MULTISURFACE) |
170 | 168 |
&& !geometryType |
171 |
.isTypeOf(Geometry.TYPES.SURFACE) |
|
169 |
.isTypeOf(Geometry.TYPES.SURFACE)
|
|
172 | 170 |
&& !geometryType.isTypeOf(Geometry.TYPES.CURVE) |
173 | 171 |
&& !geometryType |
174 |
.isTypeOf(Geometry.TYPES.MULTICURVE)) { |
|
175 |
|
|
176 |
throw new InvalidEntryException(null); |
|
177 |
} |
|
172 |
.isTypeOf(Geometry.TYPES.MULTICURVE)) { |
|
173 |
|
|
174 |
throw new InvalidEntryException(null); |
|
178 | 175 |
} |
179 | 176 |
}); |
180 | 177 |
|
... | ... | |
196 | 193 |
throw new InvalidEntryException(null); |
197 | 194 |
} |
198 | 195 |
|
196 |
@Override |
|
199 | 197 |
public Geometry finish() throws FinishServiceException { |
200 | 198 |
return null; |
201 | 199 |
} |
202 | 200 |
|
201 |
@Override |
|
203 | 202 |
public void finishAndStore() throws FinishServiceException { |
204 | 203 |
|
205 | 204 |
if (values != null) { |
... | ... | |
218 | 217 |
final int subtype = |
219 | 218 |
editingProviderServices.getSubType(featureStore); |
220 | 219 |
|
221 |
featureSelection.accept(new Visitor() { |
|
222 |
|
|
223 |
public void visit(Object obj) |
|
224 |
throws VisitCanceledException, BaseException { |
|
225 |
|
|
226 |
Feature feature = (Feature) obj; |
|
227 |
Geometry geometry = feature.getDefaultGeometry(); |
|
228 |
GeometryType geoType = geometry.getGeometryType(); |
|
229 |
|
|
230 |
if (geoType.isTypeOf(CURVE) |
|
220 |
featureSelection.accept((Object obj) -> { |
|
221 |
Feature feature = (Feature) obj; |
|
222 |
Geometry geometry = feature.getDefaultGeometry(); |
|
223 |
GeometryType geoType = geometry.getGeometryType(); |
|
224 |
|
|
225 |
if (geoType.isTypeOf(CURVE) |
|
231 | 226 |
|| (geoType.isTypeOf(SURFACE))) { |
232 |
|
|
233 |
if (geoType.isTypeOf(CURVE)) {
|
|
234 |
|
|
235 |
Curve curveToSimplify = (Curve) geometry;
|
|
236 |
curveToSimplify =
|
|
227 |
|
|
228 |
if (geoType.isTypeOf(CURVE)) { |
|
229 |
|
|
230 |
Curve curveToSimplify = (Curve) geometry; |
|
231 |
curveToSimplify = |
|
237 | 232 |
simplifyLine(curveToSimplify, |
238 |
toleranceValue); |
|
239 |
geometry = curveToSimplify;
|
|
240 |
|
|
241 |
} else {
|
|
242 |
|
|
243 |
Surface surfaceToSimplify = (Surface) geometry;
|
|
244 |
surfaceToSimplify =
|
|
233 |
toleranceValue);
|
|
234 |
geometry = curveToSimplify; |
|
235 |
|
|
236 |
} else { |
|
237 |
|
|
238 |
Surface surfaceToSimplify = (Surface) geometry; |
|
239 |
surfaceToSimplify = |
|
245 | 240 |
simplifySurface(surfaceToSimplify, |
246 |
toleranceValue); |
|
247 |
geometry = surfaceToSimplify;
|
|
248 |
|
|
249 |
}
|
|
250 |
|
|
251 |
EditableFeature eFeature = feature.getEditable();
|
|
252 |
eFeature.setDefaultGeometry(geometry);
|
|
253 |
editingProviderServices
|
|
241 |
toleranceValue);
|
|
242 |
geometry = surfaceToSimplify; |
|
243 |
|
|
244 |
} |
|
245 |
|
|
246 |
EditableFeature eFeature = feature.getEditable(); |
|
247 |
eFeature.setDefaultGeometry(geometry); |
|
248 |
editingProviderServices |
|
254 | 249 |
.updateFeatureInFeatureStore(eFeature, |
255 |
featureStore); |
|
256 |
|
|
257 |
} else if (geoType.isTypeOf(MULTICURVE)
|
|
250 |
featureStore);
|
|
251 |
|
|
252 |
} else if (geoType.isTypeOf(MULTICURVE) |
|
258 | 253 |
|| geoType.isTypeOf(MULTISURFACE)) { |
259 |
|
|
260 |
if (geoType.isTypeOf(MULTICURVE)) {
|
|
261 |
|
|
262 |
MultiCurve multiCurveToSimplify =
|
|
254 |
|
|
255 |
if (geoType.isTypeOf(MULTICURVE)) { |
|
256 |
|
|
257 |
MultiCurve multiCurveToSimplify = |
|
263 | 258 |
(MultiCurve) geometry; |
264 |
|
|
265 |
MultiCurve multiCurveSimplified =
|
|
259 |
|
|
260 |
MultiCurve multiCurveSimplified = |
|
266 | 261 |
GeometryLocator.getGeometryManager() |
267 |
.createMultiCurve(subtype); |
|
268 |
|
|
269 |
for (int i = 0; i < multiCurveToSimplify
|
|
262 |
.createMultiCurve(subtype);
|
|
263 |
|
|
264 |
for (int i = 0; i < multiCurveToSimplify |
|
270 | 265 |
.getPrimitivesNumber(); i++) { |
271 |
|
|
272 |
Curve curveToSimplify =
|
|
266 |
|
|
267 |
Curve curveToSimplify = |
|
273 | 268 |
(Curve) multiCurveToSimplify |
274 |
.getPrimitiveAt(i); |
|
275 |
|
|
276 |
curveToSimplify =
|
|
269 |
.getPrimitiveAt(i);
|
|
270 |
|
|
271 |
curveToSimplify = |
|
277 | 272 |
simplifyLine(curveToSimplify, |
278 |
toleranceValue); |
|
279 |
|
|
280 |
multiCurveSimplified
|
|
273 |
toleranceValue);
|
|
274 |
|
|
275 |
multiCurveSimplified |
|
281 | 276 |
.addCurve(curveToSimplify); |
282 |
|
|
283 |
geometry = multiCurveSimplified;
|
|
284 |
}
|
|
285 |
|
|
286 |
} else {
|
|
287 |
|
|
288 |
MultiSurface multiSurfaceToSimplify =
|
|
277 |
|
|
278 |
geometry = multiCurveSimplified; |
|
279 |
} |
|
280 |
|
|
281 |
} else { |
|
282 |
|
|
283 |
MultiSurface multiSurfaceToSimplify = |
|
289 | 284 |
(MultiSurface) geometry; |
290 |
|
|
291 |
MultiSurface multiSurfaceSimplified =
|
|
285 |
|
|
286 |
MultiSurface multiSurfaceSimplified = |
|
292 | 287 |
GeometryLocator.getGeometryManager() |
293 |
.createMultiSurface(subtype); |
|
294 |
|
|
295 |
for (int i = 0; i < multiSurfaceToSimplify
|
|
288 |
.createMultiSurface(subtype);
|
|
289 |
|
|
290 |
for (int i = 0; i < multiSurfaceToSimplify |
|
296 | 291 |
.getPrimitivesNumber(); i++) { |
297 |
|
|
298 |
Surface surfaceToSimplify =
|
|
292 |
|
|
293 |
Surface surfaceToSimplify = |
|
299 | 294 |
(Surface) multiSurfaceToSimplify |
300 |
.getPrimitiveAt(i); |
|
301 |
|
|
302 |
surfaceToSimplify =
|
|
295 |
.getPrimitiveAt(i);
|
|
296 |
|
|
297 |
surfaceToSimplify = |
|
303 | 298 |
simplifySurface(surfaceToSimplify, |
304 |
toleranceValue); |
|
305 |
|
|
306 |
multiSurfaceSimplified
|
|
299 |
toleranceValue);
|
|
300 |
|
|
301 |
multiSurfaceSimplified |
|
307 | 302 |
.addSurface(surfaceToSimplify); |
308 |
|
|
309 |
geometry = multiSurfaceSimplified; |
|
310 |
} |
|
303 |
|
|
304 |
geometry = multiSurfaceSimplified; |
|
311 | 305 |
} |
312 |
|
|
313 |
EditableFeature eFeature = feature.getEditable(); |
|
314 |
eFeature.setDefaultGeometry(geometry); |
|
315 |
editingProviderServices |
|
316 |
.updateFeatureInFeatureStore(eFeature, |
|
317 |
featureStore); |
|
318 | 306 |
} |
307 |
|
|
308 |
EditableFeature eFeature = feature.getEditable(); |
|
309 |
eFeature.setDefaultGeometry(geometry); |
|
310 |
editingProviderServices |
|
311 |
.updateFeatureInFeatureStore(eFeature, |
|
312 |
featureStore); |
|
319 | 313 |
} |
320 | 314 |
}); |
321 | 315 |
|
... | ... | |
401 | 395 |
return simplifiedLine; |
402 | 396 |
} |
403 | 397 |
|
398 |
@Override |
|
404 | 399 |
public void start() throws StartServiceException, InvalidEntryException { |
405 |
values = new HashMap<EditingServiceParameter, Object>();
|
|
400 |
values = new HashMap<>(); |
|
406 | 401 |
|
407 | 402 |
FeatureSelection selected = null; |
408 | 403 |
if (featureStore != null) { |
... | ... | |
421 | 416 |
} |
422 | 417 |
} |
423 | 418 |
|
419 |
@Override |
|
424 | 420 |
public String getName() { |
425 | 421 |
return SimplifyEditingProviderFactory.PROVIDER_NAME; |
426 | 422 |
} |
Also available in: Unified diff