gvsig-vectorediting / org.gvsig.vectorediting / trunk / org.gvsig.vectorediting / org.gvsig.vectorediting.lib / org.gvsig.vectorediting.lib.spi / src / main / java / org / gvsig / vectorediting / lib / spi / AbstractEditingProvider.java @ 28
History | View | Annotate | Download (3.62 KB)
1 |
/*
|
---|---|
2 |
* Copyright 2014 DiSiD Technologies S.L.L. All rights reserved.
|
3 |
*
|
4 |
* Project : DiSiD org.gvsig.vectorediting.lib.spi
|
5 |
* SVN Id : $Id$
|
6 |
*/
|
7 |
package org.gvsig.vectorediting.lib.spi; |
8 |
|
9 |
import java.awt.geom.Point2D; |
10 |
|
11 |
import org.gvsig.fmap.dal.exception.DataException; |
12 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
13 |
import org.gvsig.fmap.dal.feature.exception.CreateGeometryException; |
14 |
import org.gvsig.fmap.geom.Geometry; |
15 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
16 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
17 |
import org.gvsig.fmap.geom.GeometryLocator; |
18 |
import org.gvsig.fmap.geom.GeometryManager; |
19 |
import org.gvsig.fmap.geom.primitive.Circle; |
20 |
import org.gvsig.fmap.geom.primitive.Point; |
21 |
import org.gvsig.tools.service.spi.AbstractProvider; |
22 |
import org.gvsig.tools.service.spi.ProviderServices; |
23 |
import org.slf4j.Logger; |
24 |
import org.slf4j.LoggerFactory; |
25 |
|
26 |
public abstract class AbstractEditingProvider extends AbstractProvider |
27 |
implements EditingProvider, Geometry.TYPES, Geometry.SUBTYPES {
|
28 |
|
29 |
private static final Logger LOG = LoggerFactory |
30 |
.getLogger(AbstractEditingProvider.class); |
31 |
|
32 |
protected GeometryManager geomManager = GeometryLocator.getGeometryManager();
|
33 |
|
34 |
public AbstractEditingProvider(ProviderServices providerServices) {
|
35 |
super(providerServices);
|
36 |
} |
37 |
|
38 |
/**
|
39 |
* Create a circle from a GeneralPath. If there is an
|
40 |
* error return <code>null</code> and add the error
|
41 |
* to the log
|
42 |
*
|
43 |
* @param p1
|
44 |
* @param p2
|
45 |
* @return
|
46 |
* The circle
|
47 |
*/
|
48 |
protected Circle createCircle(Point2D p1, Point2D p2, FeatureStore featureStore) { |
49 |
Point centro = createPoint(p1.getX(),p1.getY(), featureStore);
|
50 |
Point radio = createPoint(p2.getX(),p2.getY(), featureStore);
|
51 |
return createCircle(centro, radio, featureStore);
|
52 |
} |
53 |
|
54 |
/**
|
55 |
* Create a circle. If there is an
|
56 |
* error return <code>null</code> and add the error
|
57 |
* to the log
|
58 |
*
|
59 |
* @param p1
|
60 |
* @param p2
|
61 |
* @return
|
62 |
* The circle
|
63 |
*/
|
64 |
protected Circle createCircle(Point p1, Point p2, FeatureStore featureStore) { |
65 |
Circle circle = null;
|
66 |
try {
|
67 |
circle = (Circle) geomManager.create(TYPES.CIRCLE, getSubType(featureStore)); |
68 |
circle.setPoints(p1, p2); |
69 |
} catch (org.gvsig.fmap.geom.exception.CreateGeometryException e) {
|
70 |
LOG.error("Error creating circle with p1=" + p1 + " p2=" + p2, |
71 |
new CreateGeometryException(TYPES.CIRCLE, getSubType(featureStore), e));
|
72 |
} |
73 |
return circle;
|
74 |
} |
75 |
|
76 |
/**
|
77 |
* Create point. If there is an
|
78 |
* error return <code>null</code> and add the error
|
79 |
* to the log
|
80 |
*
|
81 |
* @param x
|
82 |
* The X coordinate
|
83 |
* @param y
|
84 |
* The y coordinate
|
85 |
* @return
|
86 |
* The Point
|
87 |
*/
|
88 |
protected Point createPoint(double x, double y, FeatureStore featureStore) { |
89 |
Point point = null; |
90 |
try {
|
91 |
point = (Point) geomManager.create(TYPES.POINT, getSubType(featureStore));
|
92 |
point.setX(x); |
93 |
point.setY(y); |
94 |
} |
95 |
catch (org.gvsig.fmap.geom.exception.CreateGeometryException e) {
|
96 |
LOG.error("Error creating point with x=" + x + ", y=" + y, |
97 |
new CreateGeometryException(TYPES.POINT, getSubType(featureStore), e));
|
98 |
} |
99 |
return point;
|
100 |
} |
101 |
|
102 |
/**
|
103 |
* @return the subtype of the default geometry.
|
104 |
*/
|
105 |
protected int getSubType(FeatureStore featureStore) { |
106 |
|
107 |
try {
|
108 |
return featureStore.getDefaultFeatureType()
|
109 |
.getDefaultGeometryAttribute().getGeometrySubType(); |
110 |
} catch (DataException e) {
|
111 |
LOG.error( |
112 |
"Error getting subtype of the default feature type of the store: "
|
113 |
+ featureStore, e); |
114 |
return SUBTYPES.GEOM3D;
|
115 |
} |
116 |
} |
117 |
|
118 |
} |