Revision 70 org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.polyline/src/main/java/org/gvsig/vectorediting/lib/prov/polyline/PolylineEditingProvider.java
PolylineEditingProvider.java | ||
---|---|---|
25 | 25 |
import org.gvsig.fmap.geom.primitive.Point; |
26 | 26 |
import org.gvsig.fmap.geom.primitive.Surface; |
27 | 27 |
import org.gvsig.fmap.geom.type.GeometryType; |
28 |
import org.gvsig.tools.ToolsLocator; |
|
28 | 29 |
import org.gvsig.tools.dynobject.DynObject; |
30 |
import org.gvsig.tools.i18n.I18nManager; |
|
29 | 31 |
import org.gvsig.tools.service.spi.ProviderServices; |
30 | 32 |
import org.gvsig.vectorediting.lib.api.DrawingStatus; |
31 | 33 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter; |
... | ... | |
49 | 51 |
|
50 | 52 |
private EditingProviderServices editingProviderServices = (EditingProviderServices) getProviderServices(); |
51 | 53 |
|
54 |
private I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
55 |
|
|
52 | 56 |
private EditingServiceParameter points = new DefaultEditingServiceParameter( |
53 |
"Polyline", "Inserts a new point.", TYPE.LIST_POSITIONS, TYPE.OPTION); |
|
57 |
"Polyline", i18nManager.getTranslation("indicates_new_point"), |
|
58 |
TYPE.LIST_POSITIONS, TYPE.OPTION); |
|
54 | 59 |
|
55 | 60 |
private boolean arcMode = false; |
56 | 61 |
|
... | ... | |
125 | 130 |
try { |
126 | 131 |
|
127 | 132 |
lineAntPointToPoint = editingProviderServices.createLine( |
128 |
point.getX(), point.getY(), nextPoint.getX(), nextPoint.getY(), |
|
129 |
featureStore); |
|
133 |
point.getX(), point.getY(), nextPoint.getX(), nextPoint.getY(),
|
|
134 |
featureStore);
|
|
130 | 135 |
|
131 |
Double[] lineParams = getLineParams(point, nextPoint); |
|
132 |
m = lineParams[0]; |
|
133 |
b = lineParams[1]; |
|
136 |
Double[] lineParams = getLineParams(point, nextPoint);
|
|
137 |
m = lineParams[0];
|
|
138 |
b = lineParams[1];
|
|
134 | 139 |
|
135 |
Point[] pointPerpendicular = getPerpendicular(antm, antb, point, |
|
136 |
featureStore); |
|
137 |
Line linePointPerpendicular = geomManager |
|
138 |
.createLine(editingProviderServices.getSubType(featureStore)); |
|
139 |
linePointPerpendicular.setPoints(pointPerpendicular[0], |
|
140 |
pointPerpendicular[1]); |
|
140 |
Point[] pointPerpendicular = getPerpendicular(antm, antb, point,
|
|
141 |
featureStore);
|
|
142 |
Line linePointPerpendicular = geomManager
|
|
143 |
.createLine(editingProviderServices.getSubType(featureStore));
|
|
144 |
linePointPerpendicular.setPoints(pointPerpendicular[0],
|
|
145 |
pointPerpendicular[1]);
|
|
141 | 146 |
|
142 |
Point[] bisector = getPerpendicular(m, b, |
|
143 |
getMidPoint(point, nextPoint, featureStore), featureStore); |
|
144 |
Line lineBisector = geomManager.createLine(editingProviderServices |
|
145 |
.getSubType(featureStore)); |
|
146 |
lineBisector.setPoints(bisector[0], bisector[1]); |
|
147 |
Point[] bisector = getPerpendicular(m, b,
|
|
148 |
getMidPoint(point, nextPoint, featureStore), featureStore);
|
|
149 |
Line lineBisector = geomManager.createLine(editingProviderServices
|
|
150 |
.getSubType(featureStore));
|
|
151 |
lineBisector.setPoints(bisector[0], bisector[1]);
|
|
147 | 152 |
|
148 | 153 |
center = getIntersection(bisector, pointPerpendicular, featureStore); |
149 | 154 |
|
... | ... | |
204 | 209 |
Arc arco = null; |
205 | 210 |
try { |
206 | 211 |
arco = editingProviderServices.createArc(center, radius, |
207 |
startAngle, angleExt, featureStore); |
|
212 |
startAngle, angleExt, featureStore);
|
|
208 | 213 |
} |
209 | 214 |
catch (Exception e) { |
210 | 215 |
throw new DrawServiceException(e); |
... | ... | |
238 | 243 |
} |
239 | 244 |
else { |
240 | 245 |
try { |
241 |
Curve geometry = editingProviderServices.createLine(point.getX(), |
|
242 |
point.getY(), nextPoint.getX(), nextPoint.getY(), featureStore); |
|
243 |
geometries.addGeometry(geometry); |
|
246 |
Curve geometry = editingProviderServices.createLine(point.getX(),
|
|
247 |
point.getY(), nextPoint.getX(), nextPoint.getY(), featureStore);
|
|
248 |
geometries.addGeometry(geometry);
|
|
244 | 249 |
} |
245 | 250 |
catch (Exception e) { |
246 | 251 |
throw new DrawServiceException(e); |
... | ... | |
271 | 276 |
|
272 | 277 |
public DrawingStatus draw(Point mousePosition) throws DrawServiceException { |
273 | 278 |
try { |
274 |
return calculatePolyline(mousePosition); |
|
275 |
} |
|
279 |
return calculatePolyline(mousePosition);
|
|
280 |
}
|
|
276 | 281 |
catch (Exception e) { |
277 | 282 |
throw new DrawServiceException(e); |
278 | 283 |
} |
... | ... | |
280 | 285 |
|
281 | 286 |
public void finish() throws FinishServiceException { |
282 | 287 |
try { |
283 |
GeometryType storeGeomType = editingProviderServices |
|
284 |
.getGeomType(featureStore); |
|
285 |
DrawingStatus finalGeometries = calculatePolyline(null); |
|
286 |
if (storeGeomType.isTypeOf(SURFACE)) { |
|
287 |
Surface surface = geomManager.createPolygon(storeGeomType.getSubType()); |
|
288 |
for (Geometry geometry : finalGeometries.getGeometries()) { |
|
289 |
surface.addVertex((Point) geometry); |
|
290 |
} |
|
291 |
surface = closeSurfaceIfNecessary(surface); |
|
292 |
editingProviderServices.insertGeometryIntoFeatureStore(surface, |
|
293 |
featureStore); |
|
294 |
} |
|
295 |
else if (storeGeomType.isTypeOf(CURVE)) { |
|
296 |
for (Geometry geometry : finalGeometries.getGeometries()) { |
|
297 |
editingProviderServices.insertGeometryIntoFeatureStore(geometry, |
|
288 |
GeometryType storeGeomType = editingProviderServices |
|
289 |
.getGeomType(featureStore); |
|
290 |
DrawingStatus finalGeometries = calculatePolyline(null); |
|
291 |
if (storeGeomType.isTypeOf(SURFACE)) { |
|
292 |
Surface surface = geomManager.createPolygon(storeGeomType.getSubType()); |
|
293 |
for (Geometry geometry : finalGeometries.getGeometries()) { |
|
294 |
surface.addVertex((Point) geometry); |
|
295 |
} |
|
296 |
surface = closeSurfaceIfNecessary(surface); |
|
297 |
editingProviderServices.insertGeometryIntoFeatureStore(surface, |
|
298 | 298 |
featureStore); |
299 | 299 |
} |
300 |
} |
|
301 |
else if (storeGeomType.isTypeOf(MULTISURFACE)) { |
|
302 |
MultiSurface multiSurface; |
|
300 |
else if (storeGeomType.isTypeOf(CURVE)) { |
|
301 |
for (Geometry geometry : finalGeometries.getGeometries()) { |
|
302 |
editingProviderServices.insertGeometryIntoFeatureStore(geometry, |
|
303 |
featureStore); |
|
304 |
} |
|
305 |
} |
|
306 |
else if (storeGeomType.isTypeOf(MULTISURFACE)) { |
|
307 |
MultiSurface multiSurface; |
|
303 | 308 |
multiSurface = geomManager.createMultiSurface(storeGeomType |
304 | 309 |
.getSubType()); |
305 |
Surface surface = geomManager.createPolygon(storeGeomType.getSubType()); |
|
306 |
for (Geometry geometry : finalGeometries.getGeometries()) { |
|
307 |
if(geometry instanceof Curve){ |
|
308 |
Curve curve = (Curve) geometry; |
|
309 |
for(int i=0; i < curve.getNumVertices(); i++){ |
|
310 |
surface.addVertex((Point) curve.getVertex(i)); |
|
310 |
Surface surface = geomManager.createPolygon(storeGeomType.getSubType()); |
|
311 |
for (Geometry geometry : finalGeometries.getGeometries()) { |
|
312 |
if (geometry instanceof Curve) { |
|
313 |
Curve curve = (Curve) geometry; |
|
314 |
for (int i = 0; i < curve.getNumVertices(); i++) { |
|
315 |
surface.addVertex((Point) curve.getVertex(i)); |
|
316 |
} |
|
311 | 317 |
} |
312 | 318 |
} |
319 |
surface = closeSurfaceIfNecessary(surface); |
|
320 |
multiSurface.addSurface(surface); |
|
321 |
editingProviderServices.insertGeometryIntoFeatureStore(multiSurface, |
|
322 |
featureStore); |
|
313 | 323 |
} |
314 |
surface = closeSurfaceIfNecessary(surface); |
|
315 |
multiSurface.addSurface(surface); |
|
316 |
editingProviderServices.insertGeometryIntoFeatureStore(multiSurface, |
|
317 |
featureStore); |
|
318 |
} |
|
319 |
else if (storeGeomType.isTypeOf(MULTICURVE)) { |
|
320 |
MultiCurve multiCurve; |
|
321 |
multiCurve = geomManager.createMultiCurve(storeGeomType.getSubType()); |
|
322 |
for (Geometry geometry : finalGeometries.getGeometries()) { |
|
323 |
multiCurve.addCurve((Curve) geometry); |
|
324 |
else if (storeGeomType.isTypeOf(MULTICURVE)) { |
|
325 |
MultiCurve multiCurve; |
|
326 |
multiCurve = geomManager.createMultiCurve(storeGeomType.getSubType()); |
|
327 |
for (Geometry geometry : finalGeometries.getGeometries()) { |
|
328 |
multiCurve.addCurve((Curve) geometry); |
|
329 |
} |
|
330 |
editingProviderServices.insertGeometryIntoFeatureStore(multiCurve, |
|
331 |
featureStore); |
|
324 | 332 |
} |
325 |
editingProviderServices.insertGeometryIntoFeatureStore(multiCurve, |
|
326 |
featureStore); |
|
327 | 333 |
} |
328 |
} |
|
329 | 334 |
catch (Exception e) { |
330 | 335 |
throw new FinishServiceException(e); |
331 | 336 |
} |
... | ... | |
542 | 547 |
*/ |
543 | 548 |
private boolean isClose(Surface surface) { |
544 | 549 |
|
545 |
if(surface != null){
|
|
550 |
if (surface != null) {
|
|
546 | 551 |
Point firstPoint = surface.getVertex(0); |
547 |
Point lastPoint = surface.getVertex(surface.getNumVertices()-1);
|
|
548 |
if(firstPoint.equals(lastPoint)){
|
|
552 |
Point lastPoint = surface.getVertex(surface.getNumVertices() - 1);
|
|
553 |
if (firstPoint.equals(lastPoint)) {
|
|
549 | 554 |
return true; |
550 | 555 |
} |
551 | 556 |
} |
... | ... | |
553 | 558 |
} |
554 | 559 |
|
555 | 560 |
public EditingServiceParameter next() { |
556 |
if( values.size() >= 2){
|
|
557 |
if(arcMode){
|
|
561 |
if (values.size() >= 2) {
|
|
562 |
if (arcMode) {
|
|
558 | 563 |
points |
559 |
.setDescription("Inserts [L] to change to line mode. Double-click to finish. Inserts new point."); |
|
564 |
.setDescription(i18nManager |
|
565 |
.getTranslation("inserts_L_to_change_to_line_mode_double_click_to_finish_indate_new_point")); |
|
566 |
|
|
560 | 567 |
} |
561 |
else{ |
|
568 |
else {
|
|
562 | 569 |
points |
563 |
.setDescription("Inserts [A] to change to arc mode. Double-click to finish. Inserts new point."); |
|
570 |
.setDescription(i18nManager |
|
571 |
.getTranslation("inserts_A_to_change_to_arc_mode_double_click_to_finish_indate_new_point")); |
|
564 | 572 |
} |
565 | 573 |
} |
566 | 574 |
return points; |
... | ... | |
569 | 577 |
public void start() throws StartServiceException { |
570 | 578 |
stop(); |
571 | 579 |
values = new ArrayList<MyPolyLinePoint>(); |
572 |
|
|
580 |
|
|
573 | 581 |
} |
574 | 582 |
|
575 | 583 |
public void stop() { |
576 |
points.setDescription("Inserts a new point.");
|
|
584 |
points.setDescription(i18nManager.getTranslation("indicates_new_point"));
|
|
577 | 585 |
arcMode = false; |
578 | 586 |
} |
579 | 587 |
|
... | ... | |
582 | 590 |
* @param value |
583 | 591 |
*/ |
584 | 592 |
private void validateAndInsertValue(EditingServiceParameter param, |
585 |
Object value) throws InvalidEntryException { |
|
593 |
Object value) |
|
594 |
throws InvalidEntryException { |
|
586 | 595 |
if (value instanceof String) { |
587 | 596 |
if (values.size() >= 2) { |
588 |
if(((String) value).equalsIgnoreCase("A") || ((String) value).equalsIgnoreCase("L")){ |
|
589 |
if (((String) value).equalsIgnoreCase("A")) { |
|
590 |
arcMode = true; |
|
597 |
if (((String) value).equalsIgnoreCase("A") |
|
598 |
|| ((String) value).equalsIgnoreCase("L")) { |
|
599 |
if (((String) value).equalsIgnoreCase("A")) { |
|
600 |
arcMode = true; |
|
601 |
} |
|
602 |
else if (((String) value).equalsIgnoreCase("L")) { |
|
603 |
arcMode = false; |
|
604 |
} |
|
605 |
if (values.size() > 0) { |
|
606 |
values.get(values.size() - 1).setArcMode(arcMode); |
|
607 |
return; |
|
608 |
} |
|
591 | 609 |
} |
592 |
else if (((String) value).equalsIgnoreCase("L")) { |
|
593 |
arcMode = false; |
|
594 |
} |
|
595 |
if (values.size() > 0) { |
|
596 |
values.get(values.size() - 1).setArcMode(arcMode); |
|
597 |
return; |
|
598 |
} |
|
599 |
} else{ |
|
610 |
else { |
|
600 | 611 |
throw new InvalidEntryException(null); |
601 | 612 |
} |
602 |
|
|
603 |
} else{ |
|
604 |
throw new InvalidEntryException(null); |
|
613 |
|
|
605 | 614 |
} |
615 |
else { |
|
616 |
throw new InvalidEntryException(null); |
|
617 |
} |
|
606 | 618 |
} |
607 | 619 |
else if (param == points && value instanceof Point) { |
608 | 620 |
values.add(new MyPolyLinePoint((Point) value, arcMode)); |
609 | 621 |
} |
610 | 622 |
} |
611 | 623 |
|
612 |
public void value(Object value) throws InvalidEntryException{ |
|
624 |
public void value(Object value) throws InvalidEntryException {
|
|
613 | 625 |
EditingServiceParameter param = next(); |
614 | 626 |
validateAndInsertValue(param, value); |
615 | 627 |
} |
Also available in: Unified diff