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 @ 57
History | View | Annotate | Download (6.82 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.getGeometryManager();
|
40 |
|
41 |
public void insertFeatureIntoFeatureStore(Feature feature, |
42 |
FeatureStore featureStore) { |
43 |
// TODO Auto-generated method stub
|
44 |
|
45 |
} |
46 |
|
47 |
public void insertGeometryIntoFeatureStore(Geometry geometry, |
48 |
FeatureStore featureStore) { |
49 |
try {
|
50 |
EditableFeature eFeature = featureStore.createNewFeature(true);
|
51 |
|
52 |
eFeature.setGeometry(featureStore.getDefaultFeatureType() |
53 |
.getDefaultGeometryAttributeName(), geometry); |
54 |
|
55 |
EditingNotificationManager editingNotificationManager = MapControlLocator |
56 |
.getEditingNotificationManager(); |
57 |
|
58 |
EditingNotification notification = editingNotificationManager |
59 |
.notifyObservers(this, // source |
60 |
EditingNotification.BEFORE_INSERT_FEATURE, // type
|
61 |
null,// document |
62 |
null,// layer |
63 |
featureStore,// store
|
64 |
eFeature// feature
|
65 |
); |
66 |
if (notification.isCanceled()) {
|
67 |
throw new CancelationException(""); |
68 |
} |
69 |
if (!notification.shouldValidateTheFeature()) {
|
70 |
if (!editingNotificationManager.validateFeature(eFeature)) {
|
71 |
throw new Exception(""); |
72 |
} |
73 |
} |
74 |
|
75 |
featureStore.insert(eFeature); |
76 |
|
77 |
editingNotificationManager.notifyObservers(this,
|
78 |
EditingNotification.AFTER_INSERT_FEATURE, null, null, featureStore, |
79 |
eFeature); |
80 |
|
81 |
} |
82 |
catch (Exception e) { |
83 |
NotificationManager.addError(e.getMessage(), e); |
84 |
} |
85 |
} |
86 |
|
87 |
public void deleteFeatureFromFeatureStore(Feature feature, |
88 |
FeatureStore featureStore) { |
89 |
// TODO Auto-generated method stub
|
90 |
|
91 |
} |
92 |
|
93 |
public void deleteGeometryFromFeatureStore(Geometry geometry, |
94 |
FeatureStore featureStore) { |
95 |
// TODO Auto-generated method stub
|
96 |
|
97 |
} |
98 |
|
99 |
public void updateFeatureInFeatureStore(Feature feature, |
100 |
FeatureStore featureStore) { |
101 |
// TODO Auto-generated method stub
|
102 |
|
103 |
} |
104 |
|
105 |
public void updateGeometryInFeatureStore(Geometry geometry, |
106 |
FeatureStore featureStore) { |
107 |
// TODO Auto-generated method stub
|
108 |
|
109 |
} |
110 |
|
111 |
public Circle createCircle(Point2D p1, Point2D p2, FeatureStore featureStore) |
112 |
throws CreateGeometryException, DataException {
|
113 |
Point centro = createPoint(p1.getX(), p1.getY(), featureStore);
|
114 |
Point radio = createPoint(p2.getX(), p2.getY(), featureStore);
|
115 |
return createCircle(centro, radio, featureStore);
|
116 |
} |
117 |
|
118 |
public Circle createCircle(Point p1, Point p2, FeatureStore featureStore) |
119 |
throws CreateGeometryException, DataException {
|
120 |
Circle circle = null;
|
121 |
GeometryType featStoreGeomType = getGeomType(featureStore); |
122 |
circle = (Circle) geomManager.create(TYPES.CIRCLE, |
123 |
featStoreGeomType.getSubType()); |
124 |
circle.setPoints(p1, p2); |
125 |
|
126 |
return circle;
|
127 |
} |
128 |
|
129 |
public Circle createCircle(Point center, double radius, |
130 |
FeatureStore featureStore) |
131 |
throws CreateGeometryException, DataException {
|
132 |
Circle circle = null;
|
133 |
GeometryType featStoreGeomType = getGeomType(featureStore); |
134 |
circle = (Circle) geomManager.create(TYPES.CIRCLE, |
135 |
featStoreGeomType.getSubType()); |
136 |
circle.setPoints(center, radius); |
137 |
|
138 |
return circle;
|
139 |
} |
140 |
|
141 |
public Arc createArc(Point center, double radius, double startAngle, |
142 |
double angleExt, FeatureStore featureStore)
|
143 |
throws CreateGeometryException, DataException {
|
144 |
Arc arc = null;
|
145 |
GeometryType featStoreGeomType = getGeomType(featureStore); |
146 |
arc = (Arc) geomManager.create(TYPES.ARC, featStoreGeomType.getSubType()); |
147 |
arc.setPoints(center, radius, startAngle, angleExt); |
148 |
return arc;
|
149 |
} |
150 |
|
151 |
public Arc createArc(Point p1, Point midPoint, Point p2, |
152 |
FeatureStore featureStore) |
153 |
throws CreateGeometryException, DataException,
|
154 |
GeometryOperationNotSupportedException, GeometryOperationException { |
155 |
Arc arc = null;
|
156 |
GeometryType featStoreGeomType = getGeomType(featureStore); |
157 |
arc = (Arc) geomManager.create(TYPES.ARC, featStoreGeomType.getSubType()); |
158 |
arc.setPoints(p1, midPoint, p2); |
159 |
return arc;
|
160 |
} |
161 |
|
162 |
public Point createPoint(double x, double y, FeatureStore featureStore) |
163 |
throws CreateGeometryException, DataException {
|
164 |
Point point = null; |
165 |
point = (Point) geomManager.create(TYPES.POINT, getSubType(featureStore));
|
166 |
point.setX(x); |
167 |
point.setY(y); |
168 |
return point;
|
169 |
} |
170 |
|
171 |
public Curve createLine(double x1, double y1, double x2, double y2, |
172 |
FeatureStore featureStore) |
173 |
throws CreateGeometryException, DataException {
|
174 |
Curve line = null;
|
175 |
line = (Curve) geomManager.create(TYPES.CURVE, getSubType(featureStore)); |
176 |
line.addVertex(x1, y1); |
177 |
line.addVertex(x2, y2); |
178 |
return line;
|
179 |
} |
180 |
|
181 |
public int getSubType(FeatureStore featureStore) throws DataException { |
182 |
|
183 |
GeometryType geomType = getGeomType(featureStore); |
184 |
if (geomType != null) { |
185 |
return geomType.getSubType();
|
186 |
} |
187 |
return SUBTYPES.GEOM3D; // ??????? |
188 |
} |
189 |
|
190 |
public GeometryType getGeomType(FeatureStore featureStore)
|
191 |
throws DataException {
|
192 |
return featureStore.getDefaultFeatureType().getDefaultGeometryAttribute()
|
193 |
.getGeomType(); |
194 |
} |
195 |
} |