gvsig-vectorediting / org.gvsig.vectorediting / trunk / org.gvsig.vectorediting / org.gvsig.vectorediting.lib / org.gvsig.vectorediting.lib.impl / src / main / java / org / gvsig / vectorediting / lib / impl / DefaultEditingProviderServices.java @ 63
History | View | Annotate | Download (8.66 KB)
1 |
/*
|
---|---|
2 |
* Copyright 2014 DiSiD Technologies S.L.L. All rights reserved.
|
3 |
*
|
4 |
* Project : DiSiD org.gvsig.vectorediting.lib.impl
|
5 |
* SVN Id : $Id$
|
6 |
*/
|
7 |
package org.gvsig.vectorediting.lib.impl; |
8 |
|
9 |
import java.awt.geom.Point2D; |
10 |
|
11 |
import org.gvsig.andami.messages.NotificationManager; |
12 |
import org.gvsig.editing.EditingNotification; |
13 |
import org.gvsig.editing.EditingNotificationManager; |
14 |
import org.gvsig.fmap.dal.exception.DataException; |
15 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
16 |
import org.gvsig.fmap.dal.feature.Feature; |
17 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
18 |
import org.gvsig.fmap.geom.Geometry; |
19 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
20 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
21 |
import org.gvsig.fmap.geom.GeometryLocator; |
22 |
import org.gvsig.fmap.geom.GeometryManager; |
23 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
24 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
25 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
26 |
import org.gvsig.fmap.geom.primitive.Arc; |
27 |
import org.gvsig.fmap.geom.primitive.Circle; |
28 |
import org.gvsig.fmap.geom.primitive.Curve; |
29 |
import org.gvsig.fmap.geom.primitive.Point; |
30 |
import org.gvsig.fmap.geom.type.GeometryType; |
31 |
import org.gvsig.fmap.mapcontext.layers.CancelationException; |
32 |
import org.gvsig.fmap.mapcontrol.MapControlLocator; |
33 |
import org.gvsig.tools.service.spi.AbstractProviderServices; |
34 |
import org.gvsig.vectorediting.lib.spi.EditingProviderServices; |
35 |
|
36 |
public class DefaultEditingProviderServices extends AbstractProviderServices |
37 |
implements EditingProviderServices {
|
38 |
|
39 |
protected GeometryManager geomManager = GeometryLocator
|
40 |
.getGeometryManager(); |
41 |
|
42 |
public void insertFeatureIntoFeatureStore(Feature feature, |
43 |
FeatureStore featureStore) { |
44 |
try {
|
45 |
EditableFeature eFeature; |
46 |
|
47 |
if (feature instanceof EditableFeature){ |
48 |
eFeature = (EditableFeature)feature; |
49 |
} else {
|
50 |
eFeature = feature.getEditable(); |
51 |
} |
52 |
|
53 |
EditingNotificationManager editingNotificationManager = MapControlLocator |
54 |
.getEditingNotificationManager(); |
55 |
|
56 |
EditingNotification notification = editingNotificationManager |
57 |
.notifyObservers(this, // source |
58 |
EditingNotification.BEFORE_INSERT_FEATURE, // type
|
59 |
null,// document |
60 |
null,// layer |
61 |
featureStore,// store
|
62 |
eFeature// feature
|
63 |
); |
64 |
if (notification.isCanceled()) {
|
65 |
throw new CancelationException(""); |
66 |
} |
67 |
|
68 |
//FIXME: Este m?todo est? hecho al rev?s. Cuando est? corregido en EditingNotification, deber?a quitarse el !
|
69 |
if (!notification.shouldValidateTheFeature()) {
|
70 |
if (!editingNotificationManager.validateFeature(eFeature)) {
|
71 |
throw new Exception(""); |
72 |
} |
73 |
} |
74 |
|
75 |
featureStore.insert(eFeature); |
76 |
editingNotificationManager.notifyObservers(this,
|
77 |
EditingNotification.AFTER_INSERT_FEATURE, null, null, |
78 |
featureStore, eFeature); |
79 |
} catch (Exception e) { |
80 |
NotificationManager.addError(e.getMessage(), e); |
81 |
} |
82 |
} |
83 |
|
84 |
public void insertGeometryIntoFeatureStore(Geometry geometry, |
85 |
FeatureStore featureStore) { |
86 |
try {
|
87 |
EditableFeature eFeature = featureStore.createNewFeature(true);
|
88 |
|
89 |
eFeature.setGeometry(featureStore.getDefaultFeatureType() |
90 |
.getDefaultGeometryAttributeName(), geometry); |
91 |
|
92 |
EditingNotificationManager editingNotificationManager = MapControlLocator |
93 |
.getEditingNotificationManager(); |
94 |
|
95 |
EditingNotification notification = editingNotificationManager |
96 |
.notifyObservers(this, // source |
97 |
EditingNotification.BEFORE_INSERT_FEATURE, // type
|
98 |
null,// document |
99 |
null,// layer |
100 |
featureStore,// store
|
101 |
eFeature// feature
|
102 |
); |
103 |
if (notification.isCanceled()) {
|
104 |
throw new CancelationException(""); |
105 |
} |
106 |
//FIXME: Este m?todo est? hecho al rev?s. Cuando est? corregido en EditingNotification, deber?a quitarse el !
|
107 |
if (!notification.shouldValidateTheFeature()) {
|
108 |
if (!editingNotificationManager.validateFeature(eFeature)) {
|
109 |
throw new Exception(""); |
110 |
} |
111 |
} |
112 |
|
113 |
featureStore.insert(eFeature); |
114 |
|
115 |
editingNotificationManager.notifyObservers(this,
|
116 |
EditingNotification.AFTER_INSERT_FEATURE, null, null, featureStore, |
117 |
eFeature); |
118 |
|
119 |
} |
120 |
catch (Exception e) { |
121 |
NotificationManager.addError(e.getMessage(), e); |
122 |
} |
123 |
} |
124 |
|
125 |
public void deleteFeatureFromFeatureStore(Feature feature, |
126 |
FeatureStore featureStore) { |
127 |
// TODO Auto-generated method stub
|
128 |
|
129 |
} |
130 |
|
131 |
public void deleteGeometryFromFeatureStore(Geometry geometry, |
132 |
FeatureStore featureStore) { |
133 |
// TODO Auto-generated method stub
|
134 |
|
135 |
} |
136 |
|
137 |
public void updateFeatureInFeatureStore(Feature feature, |
138 |
FeatureStore featureStore) { |
139 |
try {
|
140 |
EditableFeature eFeature; |
141 |
|
142 |
if (feature instanceof EditableFeature){ |
143 |
eFeature = (EditableFeature)feature; |
144 |
} else {
|
145 |
eFeature = feature.getEditable(); |
146 |
} |
147 |
|
148 |
EditingNotificationManager editingNotificationManager = MapControlLocator |
149 |
.getEditingNotificationManager(); |
150 |
|
151 |
EditingNotification notification = editingNotificationManager |
152 |
.notifyObservers(this, // source |
153 |
EditingNotification.BEFORE_UPDATE_FEATURE, // type
|
154 |
null,// document |
155 |
null,// layer |
156 |
featureStore,// store
|
157 |
eFeature// feature
|
158 |
); |
159 |
if (notification.isCanceled()) {
|
160 |
throw new CancelationException(""); |
161 |
} |
162 |
//FIXME: Este m?todo est? hecho al rev?s. Cuando est? corregido en EditingNotification, deber?a quitarse el !
|
163 |
if (!notification.shouldValidateTheFeature()) {
|
164 |
if (!editingNotificationManager.validateFeature(eFeature)) {
|
165 |
throw new Exception(""); |
166 |
} |
167 |
} |
168 |
|
169 |
featureStore.update(eFeature); |
170 |
editingNotificationManager.notifyObservers(this,
|
171 |
EditingNotification.AFTER_UPDATE_FEATURE, null, null, |
172 |
featureStore, eFeature); |
173 |
} catch (Exception e) { |
174 |
NotificationManager.addError(e.getMessage(), e); |
175 |
} |
176 |
} |
177 |
|
178 |
public void updateGeometryInFeatureStore(Geometry geometry, |
179 |
FeatureStore featureStore) { |
180 |
// TODO Auto-generated method stub
|
181 |
|
182 |
} |
183 |
|
184 |
public Circle createCircle(Point2D p1, Point2D p2, FeatureStore featureStore) |
185 |
throws CreateGeometryException, DataException {
|
186 |
Point centro = createPoint(p1.getX(), p1.getY(), featureStore);
|
187 |
Point radio = createPoint(p2.getX(), p2.getY(), featureStore);
|
188 |
return createCircle(centro, radio, featureStore);
|
189 |
} |
190 |
|
191 |
public Circle createCircle(Point p1, Point p2, FeatureStore featureStore) |
192 |
throws CreateGeometryException, DataException {
|
193 |
Circle circle = null;
|
194 |
GeometryType featStoreGeomType = getGeomType(featureStore); |
195 |
circle = (Circle) geomManager.create(TYPES.CIRCLE, |
196 |
featStoreGeomType.getSubType()); |
197 |
circle.setPoints(p1, p2); |
198 |
|
199 |
return circle;
|
200 |
} |
201 |
|
202 |
public Circle createCircle(Point center, double radius, |
203 |
FeatureStore featureStore) |
204 |
throws CreateGeometryException, DataException {
|
205 |
Circle circle = null;
|
206 |
GeometryType featStoreGeomType = getGeomType(featureStore); |
207 |
circle = (Circle) geomManager.create(TYPES.CIRCLE, |
208 |
featStoreGeomType.getSubType()); |
209 |
circle.setPoints(center, radius); |
210 |
|
211 |
return circle;
|
212 |
} |
213 |
|
214 |
public Arc createArc(Point center, double radius, double startAngle, |
215 |
double angleExt, FeatureStore featureStore)
|
216 |
throws CreateGeometryException, DataException {
|
217 |
Arc arc = null;
|
218 |
GeometryType featStoreGeomType = getGeomType(featureStore); |
219 |
arc = (Arc) geomManager.create(TYPES.ARC, featStoreGeomType.getSubType()); |
220 |
arc.setPoints(center, radius, startAngle, angleExt); |
221 |
return arc;
|
222 |
} |
223 |
|
224 |
public Arc createArc(Point p1, Point midPoint, Point p2, |
225 |
FeatureStore featureStore) |
226 |
throws CreateGeometryException, DataException,
|
227 |
GeometryOperationNotSupportedException, GeometryOperationException { |
228 |
Arc arc = null;
|
229 |
GeometryType featStoreGeomType = getGeomType(featureStore); |
230 |
arc = (Arc) geomManager.create(TYPES.ARC, featStoreGeomType.getSubType()); |
231 |
arc.setPoints(p1, midPoint, p2); |
232 |
return arc;
|
233 |
} |
234 |
|
235 |
public Point createPoint(double x, double y, FeatureStore featureStore) |
236 |
throws CreateGeometryException, DataException {
|
237 |
Point point = null; |
238 |
point = (Point) geomManager.create(TYPES.POINT, getSubType(featureStore));
|
239 |
point.setX(x); |
240 |
point.setY(y); |
241 |
return point;
|
242 |
} |
243 |
|
244 |
public Curve createLine(double x1, double y1, double x2, double y2, |
245 |
FeatureStore featureStore) |
246 |
throws CreateGeometryException, DataException {
|
247 |
Curve line = null;
|
248 |
line = (Curve) geomManager.create(TYPES.CURVE, getSubType(featureStore)); |
249 |
line.addVertex(x1, y1); |
250 |
line.addVertex(x2, y2); |
251 |
return line;
|
252 |
} |
253 |
|
254 |
public int getSubType(FeatureStore featureStore) throws DataException { |
255 |
|
256 |
GeometryType geomType = getGeomType(featureStore); |
257 |
if (geomType != null) { |
258 |
return geomType.getSubType();
|
259 |
} |
260 |
return SUBTYPES.GEOM3D; // ??????? |
261 |
} |
262 |
|
263 |
public GeometryType getGeomType(FeatureStore featureStore)
|
264 |
throws DataException {
|
265 |
return featureStore.getDefaultFeatureType().getDefaultGeometryAttribute()
|
266 |
.getGeomType(); |
267 |
} |
268 |
|
269 |
} |