Revision 2871 org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.duplicate/src/main/java/org/gvsig/vectorediting/lib/prov/duplicate/DuplicateEditingProvider.java
DuplicateEditingProvider.java | ||
---|---|---|
25 | 25 |
package org.gvsig.vectorediting.lib.prov.duplicate; |
26 | 26 |
|
27 | 27 |
import java.awt.geom.AffineTransform; |
28 |
import java.text.DecimalFormat; |
|
28 | 29 |
import java.util.ArrayList; |
29 | 30 |
import java.util.HashMap; |
30 | 31 |
import java.util.List; |
... | ... | |
37 | 38 |
import org.gvsig.fmap.geom.Geometry; |
38 | 39 |
import org.gvsig.fmap.geom.GeometryLocator; |
39 | 40 |
import org.gvsig.fmap.geom.GeometryManager; |
41 |
import org.gvsig.fmap.geom.GeometryUtils; |
|
40 | 42 |
import org.gvsig.fmap.geom.aggregate.Aggregate; |
41 | 43 |
import org.gvsig.fmap.geom.aggregate.MultiCurve; |
42 | 44 |
import org.gvsig.fmap.geom.aggregate.MultiPoint; |
43 | 45 |
import org.gvsig.fmap.geom.aggregate.MultiSurface; |
44 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
|
45 | 46 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
46 | 47 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
47 | 48 |
import org.gvsig.fmap.geom.primitive.Curve; |
... | ... | |
49 | 50 |
import org.gvsig.fmap.geom.primitive.Point; |
50 | 51 |
import org.gvsig.fmap.geom.primitive.Surface; |
51 | 52 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
52 |
import org.gvsig.tools.ToolsLocator; |
|
53 |
import org.gvsig.symbology.SymbologyLocator; |
|
54 |
import org.gvsig.symbology.SymbologyManager; |
|
55 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.text.ISimpleTextSymbol; |
|
53 | 56 |
import org.gvsig.tools.dispose.DisposableIterator; |
54 | 57 |
import org.gvsig.tools.dispose.DisposeUtils; |
55 | 58 |
import org.gvsig.tools.dynobject.DynObject; |
56 | 59 |
import org.gvsig.tools.exception.BaseException; |
57 | 60 |
import org.gvsig.tools.service.spi.ProviderServices; |
58 |
import org.gvsig.tools.visitor.VisitCanceledException; |
|
59 |
import org.gvsig.tools.visitor.Visitor; |
|
60 | 61 |
import org.gvsig.vectorediting.lib.api.DrawingStatus; |
61 | 62 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter; |
62 | 63 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter.TYPE; |
... | ... | |
86 | 87 |
private final EditingServiceParameter firstPoint; |
87 | 88 |
|
88 | 89 |
private final EditingServiceParameter secondPoint; |
90 |
|
|
91 |
private final EditingServiceParameter equidistantCopies; |
|
89 | 92 |
|
90 | 93 |
private final FeatureStore featureStore; |
91 | 94 |
|
... | ... | |
118 | 121 |
this.secondPoint = |
119 | 122 |
new DefaultEditingServiceParameter("second_point", "second_point", |
120 | 123 |
TYPE.POSITION); |
124 |
|
|
125 |
this.equidistantCopies = new DefaultEditingServiceParameter("equidistant_copies", "equidistant_copies", true, TYPE.VALUE); |
|
126 |
this.equidistantCopies.setDefaultValue(1); |
|
127 |
|
|
121 | 128 |
} |
122 | 129 |
|
123 | 130 |
@Override |
... | ... | |
159 | 166 |
FeatureSelection featureSelection = |
160 | 167 |
(FeatureSelection) values.get(selection); |
161 | 168 |
Point firstPointValue = (Point) values.get(firstPoint); |
169 |
Number equidistantCopiesNumberValue = ((Number) values.get(this.equidistantCopies)); |
|
170 |
int equidistantCopiesValue = equidistantCopiesNumberValue != null ? equidistantCopiesNumberValue.intValue() : ((Number)this.equidistantCopies.getDefaultValue()).intValue(); |
|
162 | 171 |
|
163 | 172 |
if (featureSelection != null && firstPointValue != null) { |
164 | 173 |
drawingStatus.addStatus(firstPointValue, auxiliaryPointSymbolEditing, ""); |
165 |
Line auxLine; |
|
166 |
try { |
|
167 |
auxLine = geometryManager.createLine(subtype); |
|
168 |
} catch (CreateGeometryException e1) { |
|
169 |
throw new DrawServiceException(e1); |
|
170 |
} |
|
171 |
auxLine.setPoints(firstPointValue, mousePosition); |
|
172 |
drawingStatus.addStatus(auxLine, auxiliarylineSymbolEditing, ""); |
|
173 | 174 |
|
175 |
Point offset = GeometryUtils.createPoint( |
|
176 |
mousePosition.getX() - firstPointValue.getX(), |
|
177 |
mousePosition.getY() - firstPointValue.getY() |
|
178 |
); |
|
179 |
|
|
174 | 180 |
DisposableIterator it = null; |
175 | 181 |
try { |
176 | 182 |
it = featureSelection.fastIterator(); |
183 |
Point pos = null; |
|
177 | 184 |
while (it.hasNext()) { |
178 | 185 |
Feature feature = (Feature) it.next(); |
179 | 186 |
ISymbol previewSymbol = this.getPreviewSymbol(feature); |
180 | 187 |
|
181 |
Geometry geometry = |
|
182 |
feature.getDefaultGeometry().cloneGeometry(); |
|
188 |
Point antPos = firstPointValue; |
|
189 |
for (int c = 1; c <= equidistantCopiesValue; c++) { |
|
190 |
|
|
191 |
pos = GeometryUtils.createPoint( |
|
192 |
firstPointValue.getX() + (c * offset.getX()), |
|
193 |
firstPointValue.getY() + (c * offset.getY()) |
|
194 |
); |
|
183 | 195 |
|
184 |
AffineTransform at = |
|
185 |
getMoveAffineTransform(firstPointValue, |
|
186 |
mousePosition); |
|
187 |
geometry.transform(at); |
|
188 |
ISymbol symbol=null; |
|
189 |
if(geometry instanceof Curve || geometry instanceof MultiCurve){ |
|
190 |
symbol = lineSymbolEditing; |
|
191 |
} else if(geometry instanceof Surface || geometry instanceof MultiSurface){ |
|
192 |
symbol = polygonSymbolEditing; |
|
193 |
} else if(geometry instanceof Point || geometry instanceof MultiPoint){ |
|
194 |
symbol = auxiliaryPointSymbolEditing; |
|
195 |
} |
|
196 |
if(geometry instanceof Aggregate){ |
|
197 |
int primitivesNumber = ((Aggregate)geometry).getPrimitivesNumber(); |
|
198 |
for (int i = 0; i < primitivesNumber; i++) { |
|
199 |
drawingStatus.addStatus(((Aggregate)geometry).getPrimitiveAt(i), symbol, ""); |
|
200 |
drawingStatus.addStatus(((Aggregate)geometry).getPrimitiveAt(i), previewSymbol, ""); |
|
196 |
Geometry geometry |
|
197 |
= feature.getDefaultGeometry().cloneGeometry(); |
|
198 |
AffineTransform at |
|
199 |
= getMoveAffineTransform(firstPointValue, |
|
200 |
pos); |
|
201 |
geometry.transform(at); |
|
202 |
ISymbol symbol = null; |
|
203 |
if (geometry instanceof Curve || geometry instanceof MultiCurve) { |
|
204 |
symbol = lineSymbolEditing; |
|
205 |
} else if (geometry instanceof Surface || geometry instanceof MultiSurface) { |
|
206 |
symbol = polygonSymbolEditing; |
|
207 |
} else if (geometry instanceof Point || geometry instanceof MultiPoint) { |
|
208 |
symbol = auxiliaryPointSymbolEditing; |
|
201 | 209 |
} |
202 |
} else { |
|
203 |
drawingStatus.addStatus(geometry, symbol, ""); |
|
204 |
drawingStatus.addStatus(geometry, previewSymbol, ""); |
|
210 |
|
|
211 |
if (geometry instanceof Aggregate) { |
|
212 |
int primitivesNumber = ((Aggregate) geometry).getPrimitivesNumber(); |
|
213 |
for (int i = 0; i < primitivesNumber; i++) { |
|
214 |
drawingStatus.addStatus(((Aggregate) geometry).getPrimitiveAt(i), symbol, ""); |
|
215 |
drawingStatus.addStatus(((Aggregate) geometry).getPrimitiveAt(i), previewSymbol, ""); |
|
216 |
} |
|
217 |
} else { |
|
218 |
drawingStatus.addStatus(geometry, symbol, ""); |
|
219 |
drawingStatus.addStatus(geometry, previewSymbol, ""); |
|
220 |
} |
|
221 |
antPos = pos; |
|
205 | 222 |
} |
206 |
// drawingStatus.addGeometry(geometry); |
|
223 |
|
|
207 | 224 |
} |
225 |
|
|
226 |
if(pos != null) { |
|
227 |
Line auxLine = GeometryUtils.createLine(firstPointValue, pos, subtype); |
|
228 |
drawingStatus.addStatus(auxLine, auxiliarylineSymbolEditing, ""); |
|
229 |
} |
|
230 |
|
|
231 |
Point pointText = GeometryUtils.createPoint( |
|
232 |
firstPointValue.getX() + (0.5 * offset.getX()), |
|
233 |
firstPointValue.getY() + (0.5 * offset.getY()) |
|
234 |
); |
|
235 |
|
|
236 |
ISimpleTextSymbol textSymbol = getTextSymbol(); |
|
237 |
drawingStatus.addStatus( |
|
238 |
pointText, |
|
239 |
textSymbol, |
|
240 |
new DecimalFormat("#.0#").format(Math.sqrt(Math.pow(offset.getX(),2)+Math.pow(offset.getY(),2))) |
|
241 |
); |
|
242 |
|
|
208 | 243 |
} catch (BaseException e) { |
209 | 244 |
throw new DrawServiceException(e); |
210 | 245 |
} finally { |
... | ... | |
240 | 275 |
parameters.add(selection); |
241 | 276 |
parameters.add(firstPoint); |
242 | 277 |
parameters.add(secondPoint); |
278 |
parameters.add(equidistantCopies); |
|
243 | 279 |
return parameters; |
244 | 280 |
} |
245 | 281 |
|
... | ... | |
267 | 303 |
if (value instanceof Point) { |
268 | 304 |
values.put(parameter, value); |
269 | 305 |
} |
306 |
} else if (parameter == equidistantCopies) { |
|
307 |
if (value instanceof Number) { |
|
308 |
int intValue = ((Number) value).intValue(); |
|
309 |
if(intValue >= 1) { |
|
310 |
values.put(parameter, ((Number) value).intValue()); |
|
311 |
} |
|
312 |
} |
|
270 | 313 |
} |
271 | 314 |
} |
272 | 315 |
|
... | ... | |
281 | 324 |
|
282 | 325 |
final Point p1 = (Point) values.get(firstPoint); |
283 | 326 |
final Point p2 = (Point) values.get(secondPoint); |
327 |
Number equidistantCopiesNumberValue = ((Number) values.get(this.equidistantCopies)); |
|
328 |
int equidistantCopiesValue = equidistantCopiesNumberValue != null ? equidistantCopiesNumberValue.intValue() : ((Number)this.equidistantCopies.getDefaultValue()).intValue(); |
|
284 | 329 |
|
285 | 330 |
FeatureSelection featureSelection = |
286 | 331 |
(FeatureSelection) values.get(selection); |
287 |
ToolsLocator.getDisposableManager().bind(featureSelection); |
|
332 |
// ToolsLocator.getDisposableManager().bind(featureSelection);
|
|
288 | 333 |
|
289 | 334 |
try { |
290 | 335 |
featureSelection.accept((Object obj) -> { |
... | ... | |
293 | 338 |
EditingProviderServices editingProviderServices = |
294 | 339 |
(EditingProviderServices) getProviderServices(); |
295 | 340 |
|
296 |
EditableFeature editable = |
|
297 |
editingProviderServices.getFeatureCopyWithoutUniqueIndex( |
|
298 |
featureStore, feature); |
|
341 |
Point offset = GeometryUtils.createPoint( |
|
342 |
p2.getX() - p1.getX(), |
|
343 |
p2.getY() - p1.getY() |
|
344 |
); |
|
299 | 345 |
|
300 |
Geometry geometry = |
|
301 |
feature.getDefaultGeometry().cloneGeometry(); |
|
302 |
geometry.transform(getMoveAffineTransform(p1, p2)); |
|
303 |
|
|
304 |
editable.setDefaultGeometry(geometry); |
|
305 |
editingProviderServices.insertFeatureIntoFeatureStore( |
|
306 |
editable, featureStore); |
|
346 |
for(int c = 1; c <= equidistantCopiesValue; c++){ |
|
347 |
|
|
348 |
EditableFeature editable = |
|
349 |
editingProviderServices.getFeatureCopyWithoutUniqueIndex( |
|
350 |
featureStore, feature); |
|
351 |
|
|
352 |
Geometry geometry = |
|
353 |
feature.getDefaultGeometry().cloneGeometry(); |
|
354 |
|
|
355 |
Point pos = GeometryUtils.createPoint( |
|
356 |
p1.getX() + (c * offset.getX()), |
|
357 |
p1.getY() + (c * offset.getY()) |
|
358 |
); |
|
359 |
|
|
360 |
|
|
361 |
geometry.transform(getMoveAffineTransform(p1, pos)); |
|
362 |
|
|
363 |
editable.setDefaultGeometry(geometry); |
|
364 |
editingProviderServices.insertFeatureIntoFeatureStore( |
|
365 |
editable, featureStore); |
|
366 |
} |
|
307 | 367 |
}); |
308 | 368 |
|
309 |
featureStore.getFeatureSelection().deselectAll(); |
|
310 |
featureSelection.dispose(); |
|
369 |
// featureStore.getFeatureSelection().deselectAll();
|
|
370 |
// featureSelection.dispose();
|
|
311 | 371 |
|
312 | 372 |
} catch (BaseException e) { |
313 | 373 |
throw new FinishServiceException(e); |
... | ... | |
334 | 394 |
} |
335 | 395 |
|
336 | 396 |
@Override |
397 |
public void restart() throws StartServiceException, InvalidEntryException, StopServiceException { |
|
398 |
values.put(secondPoint,null); |
|
399 |
} |
|
400 |
|
|
401 |
@Override |
|
337 | 402 |
public String getName() { |
338 | 403 |
return DuplicateEditingProviderFactory.PROVIDER_NAME; |
339 | 404 |
} |
... | ... | |
342 | 407 |
public Object getValue(EditingServiceParameter parameter) { |
343 | 408 |
return values!=null?values.get(parameter):null; |
344 | 409 |
} |
410 |
|
|
411 |
private ISimpleTextSymbol getTextSymbol(){ |
|
412 |
SymbologyManager symbologyManager = SymbologyLocator.getSymbologyManager(); |
|
413 |
ISimpleTextSymbol textSymbol = symbologyManager.createSimpleTextSymbol(); |
|
414 |
textSymbol.setFontSize(10); |
|
415 |
return textSymbol; |
|
416 |
} |
|
345 | 417 |
|
418 |
@Override |
|
419 |
public boolean isEnabled(EditingServiceParameter parameter) { |
|
420 |
|
|
421 |
if (parameter == equidistantCopies) { |
|
422 |
return true; |
|
423 |
} |
|
424 |
return true; |
|
425 |
} |
|
426 |
|
|
346 | 427 |
} |
Also available in: Unified diff