Revision 55 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
AbstractEditingProvider.java | ||
---|---|---|
10 | 10 |
|
11 | 11 |
import org.gvsig.fmap.dal.exception.DataException; |
12 | 12 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
13 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
14 |
import org.gvsig.fmap.dal.feature.exception.CreateGeometryException; |
|
15 | 13 |
import org.gvsig.fmap.geom.Geometry; |
16 | 14 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
17 | 15 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
18 | 16 |
import org.gvsig.fmap.geom.GeometryLocator; |
19 | 17 |
import org.gvsig.fmap.geom.GeometryManager; |
18 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
|
20 | 19 |
import org.gvsig.fmap.geom.primitive.Arc; |
21 | 20 |
import org.gvsig.fmap.geom.primitive.Circle; |
21 |
import org.gvsig.fmap.geom.primitive.Curve; |
|
22 |
import org.gvsig.fmap.geom.primitive.Line; |
|
22 | 23 |
import org.gvsig.fmap.geom.primitive.Point; |
23 | 24 |
import org.gvsig.fmap.geom.type.GeometryType; |
24 | 25 |
import org.gvsig.tools.service.spi.AbstractProvider; |
... | ... | |
32 | 33 |
private static final Logger LOG = LoggerFactory |
33 | 34 |
.getLogger(AbstractEditingProvider.class); |
34 | 35 |
|
35 |
protected GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
|
36 | 36 |
|
37 | 37 |
public AbstractEditingProvider(ProviderServices providerServices) { |
38 | 38 |
super(providerServices); |
39 | 39 |
} |
40 | 40 |
|
41 |
/** |
|
42 |
* Create a circle from a GeneralPath. If there is an |
|
43 |
* error return <code>null</code> and add the error |
|
44 |
* to the log |
|
45 |
* |
|
46 |
* @param p1 |
|
47 |
* @param p2 |
|
48 |
* @return |
|
49 |
* The circle |
|
50 |
*/ |
|
51 |
protected Circle createCircle(Point2D p1, Point2D p2, FeatureStore featureStore) { |
|
52 |
Point centro = createPoint(p1.getX(),p1.getY(), featureStore); |
|
53 |
Point radio = createPoint(p2.getX(),p2.getY(), featureStore); |
|
54 |
return createCircle(centro, radio, featureStore); |
|
55 |
} |
|
56 | 41 |
|
57 |
/** |
|
58 |
* Create a circle. If there is an |
|
59 |
* error return <code>null</code> and add the error |
|
60 |
* to the log |
|
61 |
* |
|
62 |
* @param p1 |
|
63 |
* @param p2 |
|
64 |
* @return |
|
65 |
* The circle |
|
66 |
*/ |
|
67 |
protected Circle createCircle(Point p1, Point p2, FeatureStore featureStore) { |
|
68 |
Circle circle = null; |
|
69 |
try { |
|
70 |
GeometryType featStoreGeomType = getGeomType(featureStore); |
|
71 |
circle = (Circle) geomManager.create(TYPES.CIRCLE, featStoreGeomType.getSubType()); |
|
72 |
circle.setPoints(p1, p2); |
|
73 |
|
|
74 |
} catch (org.gvsig.fmap.geom.exception.CreateGeometryException e) { |
|
75 |
LOG.error("Error creating circle with p1=" + p1 + " p2=" + p2, |
|
76 |
new CreateGeometryException(TYPES.CIRCLE, getSubType(featureStore), e)); |
|
77 |
} |
|
78 |
return circle; |
|
79 |
} |
|
80 |
|
|
81 |
/** |
|
82 |
* Create a circle. If there is an |
|
83 |
* error return <code>null</code> and add the error |
|
84 |
* to the log |
|
85 |
* |
|
86 |
* @param center |
|
87 |
* @param radius |
|
88 |
* @return |
|
89 |
* The circle |
|
90 |
*/ |
|
91 |
protected Circle createCircle(Point center, double radius, FeatureStore featureStore) { |
|
92 |
Circle circle = null; |
|
93 |
try { |
|
94 |
GeometryType featStoreGeomType = getGeomType(featureStore); |
|
95 |
circle = (Circle) geomManager.create(TYPES.CIRCLE, featStoreGeomType.getSubType()); |
|
96 |
circle.setPoints(center, radius); |
|
97 |
|
|
98 |
} catch (org.gvsig.fmap.geom.exception.CreateGeometryException e) { |
|
99 |
LOG.error("Error creating circle with center=" + center + " radious=" + radius, |
|
100 |
new CreateGeometryException(TYPES.CIRCLE, getSubType(featureStore), e)); |
|
101 |
} |
|
102 |
return circle; |
|
103 |
} |
|
104 |
|
|
105 |
/** |
|
106 |
* Create a circle. If there is an |
|
107 |
* error return <code>null</code> and add the error |
|
108 |
* to the log |
|
109 |
* |
|
110 |
* @param center |
|
111 |
* @param radius |
|
112 |
* @param startAngle in radians |
|
113 |
* @param angleExt |
|
114 |
* @return |
|
115 |
* The circle |
|
116 |
*/ |
|
117 |
protected Arc createArc(Point center, double radius, double startAngle, double angleExt, FeatureStore featureStore) { |
|
118 |
Arc arc = null; |
|
119 |
try { |
|
120 |
GeometryType featStoreGeomType = getGeomType(featureStore); |
|
121 |
arc = (Arc) geomManager.create(TYPES.ARC, featStoreGeomType.getSubType()); |
|
122 |
arc.setPoints(center, radius, startAngle, angleExt); |
|
123 |
|
|
124 |
} catch (org.gvsig.fmap.geom.exception.CreateGeometryException e) { |
|
125 |
LOG.error("Error creating arc with center=" + center + " radious=" + radius, |
|
126 |
new CreateGeometryException(TYPES.CIRCLE, getSubType(featureStore), e)); |
|
127 |
} |
|
128 |
return arc; |
|
129 |
} |
|
130 |
|
|
131 |
/** |
|
132 |
* Create point. If there is an |
|
133 |
* error return <code>null</code> and add the error |
|
134 |
* to the log |
|
135 |
* |
|
136 |
* @param x |
|
137 |
* The X coordinate |
|
138 |
* @param y |
|
139 |
* The y coordinate |
|
140 |
* @return |
|
141 |
* The Point |
|
142 |
*/ |
|
143 |
protected Point createPoint(double x, double y, FeatureStore featureStore) { |
|
144 |
Point point = null; |
|
145 |
try { |
|
146 |
point = (Point) geomManager.create(TYPES.POINT, getSubType(featureStore)); |
|
147 |
point.setX(x); |
|
148 |
point.setY(y); |
|
149 |
} |
|
150 |
catch (org.gvsig.fmap.geom.exception.CreateGeometryException e) { |
|
151 |
LOG.error("Error creating point with x=" + x + ", y=" + y, |
|
152 |
new CreateGeometryException(TYPES.POINT, getSubType(featureStore), e)); |
|
153 |
} |
|
154 |
return point; |
|
155 |
} |
|
156 |
|
|
157 |
/** |
|
158 |
* @return the subtype of the default geometry. |
|
159 |
*/ |
|
160 |
protected int getSubType(FeatureStore featureStore) { |
|
161 |
|
|
162 |
GeometryType geomType = getGeomType(featureStore); |
|
163 |
if (geomType != null){ |
|
164 |
return geomType.getSubType(); |
|
165 |
} |
|
166 |
return SUBTYPES.GEOM3D; //??????? |
|
167 |
} |
|
168 |
|
|
169 |
/** |
|
170 |
* @return the subtype of the default geometry. |
|
171 |
*/ |
|
172 |
protected GeometryType getGeomType(FeatureStore featureStore) { |
|
173 |
|
|
174 |
try { |
|
175 |
return featureStore.getDefaultFeatureType() |
|
176 |
.getDefaultGeometryAttribute().getGeomType(); |
|
177 |
} catch (DataException e) { |
|
178 |
LOG.error( |
|
179 |
"Error getting type of the default feature type of the store: " |
|
180 |
+ featureStore, e); |
|
181 |
return null; |
|
182 |
} |
|
183 |
} |
|
184 |
|
|
185 | 42 |
} |
Also available in: Unified diff