Revision 57
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.app/org.gvsig.vectorediting.app.mainplugin/src/main/assembly/gvsig-plugin-package.xml | ||
---|---|---|
58 | 58 |
<include>org.gvsig:org.gvsig.vectorediting.swing.api</include> |
59 | 59 |
<include>org.gvsig:org.gvsig.vectorediting.lib.impl</include> |
60 | 60 |
<include>org.gvsig:org.gvsig.vectorediting.swing.impl</include> |
61 |
<include>org.gvsig:org.gvsig.vectorediting.lib.spi</include> |
|
61 | 62 |
<include>org.gvsig:org.gvsig.vectorediting.lib.prov.insertpoint</include> |
62 | 63 |
<include>org.gvsig:org.gvsig.vectorediting.lib.prov.circlecr</include> |
63 |
<include>org.gvsig:org.gvsig.vectorediting.lib.spi</include>
|
|
64 |
<include>org.gvsig:org.gvsig.vectorediting.lib.prov.polyline</include>
|
|
64 | 65 |
</includes> |
65 | 66 |
</dependencySet> |
66 | 67 |
</dependencySets> |
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/pom.xml | ||
---|---|---|
125 | 125 |
</artifactId> |
126 | 126 |
<version>1.0.0-SNAPSHOT</version> |
127 | 127 |
</dependency> |
128 |
<dependency> |
|
129 |
<groupId>org.gvsig</groupId> |
|
130 |
<artifactId> |
|
131 |
org.gvsig.vectorediting.lib.prov.polyline |
|
132 |
</artifactId> |
|
133 |
<version>1.0.0-SNAPSHOT</version> |
|
134 |
</dependency> |
|
128 | 135 |
</dependencies> |
129 | 136 |
</dependencyManagement> |
130 | 137 |
</project> |
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.main/src/main/java/org/gvsig/vectorediting/main/Main.java | ||
---|---|---|
74 | 74 |
import org.gvsig.vectorediting.lib.api.EditingManager; |
75 | 75 |
import org.gvsig.vectorediting.lib.prov.circlecr.CircleCREditingProviderFactory; |
76 | 76 |
import org.gvsig.vectorediting.lib.prov.insertpoint.InsertPointEditingProviderFactory; |
77 |
import org.gvsig.vectorediting.lib.prov.polyline.PolylineEditingProviderFactory; |
|
77 | 78 |
import org.gvsig.vectorediting.lib.spi.EditingProviderLocator; |
78 | 79 |
import org.gvsig.vectorediting.lib.spi.EditingProviderManager; |
79 | 80 |
import org.gvsig.vectorediting.swing.api.EditingBehavior; |
... | ... | |
149 | 150 |
AbstractAction addLayer; |
150 | 151 |
|
151 | 152 |
AbstractAction circleCr; |
153 |
|
|
154 |
AbstractAction polyline; |
|
152 | 155 |
|
153 | 156 |
public static void main(String args[]) { |
154 | 157 |
new DefaultLibrariesInitializer().fullInitialize(); |
... | ... | |
244 | 247 |
|
245 | 248 |
JButton insertPointButton = new JButton(insertPoint); |
246 | 249 |
JButton circleCrButton = new JButton(circleCr); |
250 |
JButton polylineButton = new JButton(polyline); |
|
247 | 251 |
|
248 | 252 |
paletteTools.add(new JLabel("Insert tools")); |
249 | 253 |
paletteTools.add(insertPointButton); |
250 | 254 |
paletteTools.add(circleCrButton); |
255 |
paletteTools.add(polylineButton); |
|
251 | 256 |
} |
252 | 257 |
|
253 | 258 |
private void createToolBar() { |
... | ... | |
284 | 289 |
menuTool.addSeparator(); |
285 | 290 |
menuTool.add(new JMenuItem(insertPoint)); |
286 | 291 |
menuTool.add(new JMenuItem(circleCr)); |
292 |
menuTool.add(new JMenuItem(polyline)); |
|
287 | 293 |
|
288 | 294 |
menuBar.add(menuFile); |
289 | 295 |
menuBar.add(menuTool); |
... | ... | |
338 | 344 |
|
339 | 345 |
public void actionPerformed(ActionEvent e) { |
340 | 346 |
paletteTools.setVisible(true); |
347 |
if(mapControl.hasTool("VectorEditing")){ |
|
348 |
mapControl.setTool("VectorEditing"); |
|
349 |
} |
|
341 | 350 |
} |
342 | 351 |
}; |
343 | 352 |
|
... | ... | |
394 | 403 |
mapControl); |
395 | 404 |
} |
396 | 405 |
}; |
406 |
|
|
407 |
polyline = new AbstractAction("PolylineAction") { |
|
408 |
|
|
409 |
public void actionPerformed(ActionEvent e) { |
|
410 |
swingManager.activateTool(PolylineEditingProviderFactory.PROVIDER_NAME, |
|
411 |
mapControl); |
|
412 |
} |
|
413 |
}; |
|
397 | 414 |
} |
398 | 415 |
|
399 | 416 |
private void updateControls() { |
... | ... | |
405 | 422 |
public void addLayer(String shpPath) throws InitializeException, |
406 | 423 |
ProviderNotRegisteredException, ValidateDataParametersException, |
407 | 424 |
LoadLayerException { |
425 |
// shpPath = "/home/lmarques/data/cartography/Andalucia/hidro_andalucia.shp"; |
|
408 | 426 |
DataStoreParameters params; |
409 | 427 |
params = dataManager.createStoreParameters("Shape"); |
410 | 428 |
|
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 | ||
---|---|---|
16 | 16 |
import org.gvsig.fmap.dal.feature.Feature; |
17 | 17 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
18 | 18 |
import org.gvsig.fmap.geom.Geometry; |
19 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
|
20 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
|
19 | 21 |
import org.gvsig.fmap.geom.GeometryLocator; |
20 | 22 |
import org.gvsig.fmap.geom.GeometryManager; |
21 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
|
22 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
|
23 | 23 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
24 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
|
25 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
|
24 | 26 |
import org.gvsig.fmap.geom.primitive.Arc; |
25 | 27 |
import org.gvsig.fmap.geom.primitive.Circle; |
26 | 28 |
import org.gvsig.fmap.geom.primitive.Curve; |
... | ... | |
32 | 34 |
import org.gvsig.vectorediting.lib.spi.EditingProviderServices; |
33 | 35 |
|
34 | 36 |
public class DefaultEditingProviderServices extends AbstractProviderServices |
35 |
implements EditingProviderServices {
|
|
37 |
implements EditingProviderServices {
|
|
36 | 38 |
|
37 |
protected GeometryManager geomManager = GeometryLocator.getGeometryManager();
|
|
39 |
protected GeometryManager geomManager = GeometryLocator.getGeometryManager();
|
|
38 | 40 |
|
39 |
public void insertFeatureIntoFeatureStore(Feature feature,
|
|
40 |
FeatureStore featureStore) {
|
|
41 |
// TODO Auto-generated method stub
|
|
41 |
public void insertFeatureIntoFeatureStore(Feature feature,
|
|
42 |
FeatureStore featureStore) {
|
|
43 |
// TODO Auto-generated method stub
|
|
42 | 44 |
|
43 |
}
|
|
45 |
}
|
|
44 | 46 |
|
45 |
public void insertGeometryIntoFeatureStore(Geometry geometry,
|
|
46 |
FeatureStore featureStore) {
|
|
47 |
try {
|
|
48 |
EditableFeature eFeature = featureStore.createNewFeature(true);
|
|
47 |
public void insertGeometryIntoFeatureStore(Geometry geometry,
|
|
48 |
FeatureStore featureStore) {
|
|
49 |
try {
|
|
50 |
EditableFeature eFeature = featureStore.createNewFeature(true);
|
|
49 | 51 |
|
50 |
eFeature.setGeometry(featureStore.getDefaultFeatureType()
|
|
51 |
.getDefaultGeometryAttributeName(), geometry);
|
|
52 |
eFeature.setGeometry(featureStore.getDefaultFeatureType()
|
|
53 |
.getDefaultGeometryAttributeName(), geometry);
|
|
52 | 54 |
|
53 |
EditingNotificationManager editingNotificationManager = MapControlLocator
|
|
54 |
.getEditingNotificationManager();
|
|
55 |
EditingNotificationManager editingNotificationManager = MapControlLocator
|
|
56 |
.getEditingNotificationManager();
|
|
55 | 57 |
|
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 |
if (!notification.shouldValidateTheFeature()) {
|
|
68 |
if (!editingNotificationManager.validateFeature(eFeature)) {
|
|
69 |
throw new Exception("");
|
|
70 |
}
|
|
71 |
}
|
|
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 |
}
|
|
72 | 74 |
|
73 |
featureStore.insert(eFeature);
|
|
75 |
featureStore.insert(eFeature);
|
|
74 | 76 |
|
75 |
editingNotificationManager.notifyObservers(this,
|
|
76 |
EditingNotification.AFTER_INSERT_FEATURE, null, null,
|
|
77 |
featureStore, eFeature);
|
|
77 |
editingNotificationManager.notifyObservers(this,
|
|
78 |
EditingNotification.AFTER_INSERT_FEATURE, null, null, featureStore,
|
|
79 |
eFeature);
|
|
78 | 80 |
|
79 |
} catch (Exception e) { |
|
80 |
NotificationManager.addError(e.getMessage(), e); |
|
81 |
} |
|
82 |
} |
|
81 |
} |
|
82 |
catch (Exception e) { |
|
83 |
NotificationManager.addError(e.getMessage(), e); |
|
84 |
} |
|
85 |
} |
|
83 | 86 |
|
84 |
public void deleteFeatureFromFeatureStore(Feature feature,
|
|
85 |
FeatureStore featureStore) {
|
|
86 |
// TODO Auto-generated method stub
|
|
87 |
public void deleteFeatureFromFeatureStore(Feature feature,
|
|
88 |
FeatureStore featureStore) {
|
|
89 |
// TODO Auto-generated method stub
|
|
87 | 90 |
|
88 |
}
|
|
91 |
}
|
|
89 | 92 |
|
90 |
public void deleteGeometryFromFeatureStore(Geometry geometry,
|
|
91 |
FeatureStore featureStore) {
|
|
92 |
// TODO Auto-generated method stub
|
|
93 |
public void deleteGeometryFromFeatureStore(Geometry geometry,
|
|
94 |
FeatureStore featureStore) {
|
|
95 |
// TODO Auto-generated method stub
|
|
93 | 96 |
|
94 |
}
|
|
97 |
}
|
|
95 | 98 |
|
96 |
public void updateFeatureInFeatureStore(Feature feature,
|
|
97 |
FeatureStore featureStore) {
|
|
98 |
// TODO Auto-generated method stub
|
|
99 |
public void updateFeatureInFeatureStore(Feature feature,
|
|
100 |
FeatureStore featureStore) {
|
|
101 |
// TODO Auto-generated method stub
|
|
99 | 102 |
|
100 |
}
|
|
103 |
}
|
|
101 | 104 |
|
102 |
public void updateGeometryInFeatureStore(Geometry geometry,
|
|
103 |
FeatureStore featureStore) {
|
|
104 |
// TODO Auto-generated method stub
|
|
105 |
public void updateGeometryInFeatureStore(Geometry geometry,
|
|
106 |
FeatureStore featureStore) {
|
|
107 |
// TODO Auto-generated method stub
|
|
105 | 108 |
|
106 |
}
|
|
109 |
}
|
|
107 | 110 |
|
108 |
public Circle createCircle(Point2D p1, Point2D p2, FeatureStore featureStore)
|
|
109 |
throws CreateGeometryException, DataException {
|
|
110 |
Point centro = createPoint(p1.getX(), p1.getY(), featureStore);
|
|
111 |
Point radio = createPoint(p2.getX(), p2.getY(), featureStore);
|
|
112 |
return createCircle(centro, radio, featureStore);
|
|
113 |
}
|
|
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 |
}
|
|
114 | 117 |
|
115 |
public Circle createCircle(Point p1, Point p2, FeatureStore featureStore)
|
|
116 |
throws CreateGeometryException, DataException {
|
|
117 |
Circle circle = null;
|
|
118 |
GeometryType featStoreGeomType = getGeomType(featureStore);
|
|
119 |
circle = (Circle) geomManager.create(TYPES.CIRCLE,
|
|
120 |
featStoreGeomType.getSubType());
|
|
121 |
circle.setPoints(p1, p2);
|
|
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);
|
|
122 | 125 |
|
123 |
return circle;
|
|
124 |
}
|
|
126 |
return circle;
|
|
127 |
}
|
|
125 | 128 |
|
126 |
public Circle createCircle(Point center, double radius,
|
|
127 |
FeatureStore featureStore) throws CreateGeometryException,
|
|
128 |
DataException {
|
|
129 |
Circle circle = null;
|
|
130 |
GeometryType featStoreGeomType = getGeomType(featureStore);
|
|
131 |
circle = (Circle) geomManager.create(TYPES.CIRCLE,
|
|
132 |
featStoreGeomType.getSubType());
|
|
133 |
circle.setPoints(center, radius);
|
|
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);
|
|
134 | 137 |
|
135 |
return circle;
|
|
136 |
}
|
|
138 |
return circle;
|
|
139 |
}
|
|
137 | 140 |
|
138 |
public Arc createArc(Point center, double radius, double startAngle, |
|
139 |
double angleExt, FeatureStore featureStore) |
|
140 |
throws CreateGeometryException, DataException { |
|
141 |
Arc arc = null; |
|
142 |
GeometryType featStoreGeomType = getGeomType(featureStore); |
|
143 |
arc = (Arc) geomManager.create(TYPES.ARC, |
|
144 |
featStoreGeomType.getSubType()); |
|
145 |
arc.setPoints(center, radius, startAngle, angleExt); |
|
146 |
return arc; |
|
147 |
} |
|
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 |
} |
|
148 | 150 |
|
149 |
public Point createPoint(double x, double y, FeatureStore featureStore) |
|
150 |
throws CreateGeometryException, DataException { |
|
151 |
Point point = null; |
|
152 |
point = (Point) geomManager.create(TYPES.POINT, |
|
153 |
getSubType(featureStore)); |
|
154 |
point.setX(x); |
|
155 |
point.setY(y); |
|
156 |
return point; |
|
157 |
} |
|
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 |
} |
|
158 | 161 |
|
159 |
public Curve createLine(double x1, double y1, double x2, double y2, |
|
160 |
FeatureStore featureStore) throws CreateGeometryException, |
|
161 |
DataException { |
|
162 |
Curve line = null; |
|
163 |
line = (Curve) geomManager |
|
164 |
.create(TYPES.CURVE, getSubType(featureStore)); |
|
165 |
line.addVertex(x1, y1); |
|
166 |
line.addVertex(x2, y2); |
|
167 |
return line; |
|
168 |
} |
|
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 |
} |
|
169 | 170 |
|
170 |
public int getSubType(FeatureStore featureStore) throws DataException { |
|
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 |
} |
|
171 | 180 |
|
172 |
GeometryType geomType = getGeomType(featureStore); |
|
173 |
if (geomType != null) { |
|
174 |
return geomType.getSubType(); |
|
175 |
} |
|
176 |
return SUBTYPES.GEOM3D; // ??????? |
|
177 |
} |
|
181 |
public int getSubType(FeatureStore featureStore) throws DataException { |
|
178 | 182 |
|
179 |
public GeometryType getGeomType(FeatureStore featureStore) |
|
180 |
throws DataException { |
|
181 |
return featureStore.getDefaultFeatureType() |
|
182 |
.getDefaultGeometryAttribute().getGeomType(); |
|
183 |
} |
|
183 |
GeometryType geomType = getGeomType(featureStore); |
|
184 |
if (geomType != null) { |
|
185 |
return geomType.getSubType(); |
|
186 |
} |
|
187 |
return SUBTYPES.GEOM3D; // ??????? |
|
188 |
} |
|
184 | 189 |
|
190 |
public GeometryType getGeomType(FeatureStore featureStore) |
|
191 |
throws DataException { |
|
192 |
return featureStore.getDefaultFeatureType().getDefaultGeometryAttribute() |
|
193 |
.getGeomType(); |
|
194 |
} |
|
185 | 195 |
} |
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.impl/src/main/java/org/gvsig/vectorediting/lib/impl/DefaultEditingProviderLibrary.java | ||
---|---|---|
11 | 11 |
import org.gvsig.tools.library.LibraryException; |
12 | 12 |
import org.gvsig.vectorediting.lib.prov.circlecr.CircleCREditingProviderFactory; |
13 | 13 |
import org.gvsig.vectorediting.lib.prov.insertpoint.InsertPointEditingProviderFactory; |
14 |
import org.gvsig.vectorediting.lib.prov.polyline.PolylineEditingProviderFactory; |
|
14 | 15 |
import org.gvsig.vectorediting.lib.spi.EditingProviderLibrary; |
15 | 16 |
import org.gvsig.vectorediting.lib.spi.EditingProviderLocator; |
16 | 17 |
import org.gvsig.vectorediting.lib.spi.EditingProviderManager; |
... | ... | |
39 | 40 |
|
40 | 41 |
manager.addProviderFactory(new InsertPointEditingProviderFactory()); |
41 | 42 |
manager.addProviderFactory(new CircleCREditingProviderFactory()); |
43 |
manager.addProviderFactory(new PolylineEditingProviderFactory()); |
|
42 | 44 |
|
43 | 45 |
} |
44 | 46 |
|
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.impl/pom.xml | ||
---|---|---|
31 | 31 |
org.gvsig.vectorediting.lib.prov.circlecr |
32 | 32 |
</artifactId> |
33 | 33 |
</dependency> |
34 |
<dependency> |
|
35 |
<groupId>org.gvsig</groupId> |
|
36 |
<artifactId> |
|
37 |
org.gvsig.vectorediting.lib.prov.polyline |
|
38 |
</artifactId> |
|
39 |
</dependency> |
|
34 | 40 |
</dependencies> |
35 | 41 |
</project> |
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/PolylineEditingProviderFactory.java | ||
---|---|---|
1 |
/* |
|
2 |
* Copyright 2014 DiSiD Technologies S.L.L. All rights reserved. |
|
3 |
* |
|
4 |
* Project : DiSiD org.gvsig.vectorediting.lib.prov.polyline |
|
5 |
* SVN Id : $Id$ |
|
6 |
*/ |
|
7 |
package org.gvsig.vectorediting.lib.prov.polyline; |
|
8 |
|
|
9 |
import org.gvsig.fmap.geom.Geometry; |
|
10 |
import org.gvsig.tools.ToolsLocator; |
|
11 |
import org.gvsig.tools.dynobject.DynClass; |
|
12 |
import org.gvsig.tools.dynobject.DynObject; |
|
13 |
import org.gvsig.tools.service.spi.AbstractProviderFactory; |
|
14 |
import org.gvsig.tools.service.spi.Provider; |
|
15 |
import org.gvsig.tools.service.spi.ProviderServices; |
|
16 |
import org.gvsig.vectorediting.lib.api.EditingServiceInfo; |
|
17 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter; |
|
18 |
import org.gvsig.vectorediting.lib.spi.DefaultEditingServiceinfo; |
|
19 |
import org.gvsig.vectorediting.lib.spi.EditingProviderFactory; |
|
20 |
|
|
21 |
|
|
22 |
public class PolylineEditingProviderFactory extends AbstractProviderFactory implements EditingProviderFactory { |
|
23 |
|
|
24 |
public final static String PROVIDER_NAME = "layer-polyline"; |
|
25 |
|
|
26 |
public final static String PROVIDER_DESCRIPTION = "Inserts a polyline on the view"; |
|
27 |
|
|
28 |
public static final String PROVIDER_NAME_PARAMS = "PolylineParams"; |
|
29 |
|
|
30 |
public static final String PROVIDER_NAME_PARAMS_DESCRIPTION = ""; |
|
31 |
|
|
32 |
private DynClass dynclass; |
|
33 |
|
|
34 |
public String getName() { |
|
35 |
return PROVIDER_NAME; |
|
36 |
} |
|
37 |
|
|
38 |
public DynObject createParameters() { |
|
39 |
DynObject dynobject = ToolsLocator.getDynObjectManager().createDynObject( |
|
40 |
dynclass); |
|
41 |
|
|
42 |
dynobject.setDynValue(PROVIDER_NAME_FIELD, PROVIDER_NAME); |
|
43 |
return dynobject; |
|
44 |
} |
|
45 |
|
|
46 |
public void initialize() { |
|
47 |
dynclass = ToolsLocator.getDynObjectManager().createDynClass( |
|
48 |
PROVIDER_NAME_PARAMS, PROVIDER_NAME_PARAMS_DESCRIPTION); |
|
49 |
|
|
50 |
dynclass.addDynFieldString(PROVIDER_NAME_FIELD); |
|
51 |
dynclass.addDynFieldObject(FEATURE_STORE_FIELD); |
|
52 |
|
|
53 |
} |
|
54 |
|
|
55 |
public EditingServiceInfo getServiceInfo() { |
|
56 |
EditingServiceInfo serviceInfo = new DefaultEditingServiceinfo( |
|
57 |
PROVIDER_NAME, |
|
58 |
"", |
|
59 |
true, |
|
60 |
null, |
|
61 |
null, |
|
62 |
new int[]{ |
|
63 |
Geometry.TYPES.SURFACE, |
|
64 |
Geometry.TYPES.MULTISURFACE, |
|
65 |
Geometry.TYPES.CURVE, |
|
66 |
Geometry.TYPES.MULTICURVE}); |
|
67 |
|
|
68 |
|
|
69 |
return serviceInfo; |
|
70 |
} |
|
71 |
|
|
72 |
public EditingServiceParameter getServiceParameterInfo() { |
|
73 |
// TODO Auto-generated method stub |
|
74 |
return null; |
|
75 |
} |
|
76 |
|
|
77 |
@Override |
|
78 |
protected Provider doCreate(DynObject parameters, ProviderServices services) { |
|
79 |
return new PolylineEditingProvider(services, parameters); |
|
80 |
} |
|
81 |
|
|
82 |
@Override |
|
83 |
protected DynClass createParametersDynClass() { |
|
84 |
// TODO Auto-generated method stub |
|
85 |
return null; |
|
86 |
} |
|
87 |
|
|
88 |
} |
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 | ||
---|---|---|
1 |
/* |
|
2 |
* Copyright 2014 DiSiD Technologies S.L.L. All rights reserved. |
|
3 |
* |
|
4 |
* Project : DiSiD org.gvsig.vectorediting.lib.prov.polyline |
|
5 |
* SVN Id : $Id$ |
|
6 |
*/ |
|
7 |
package org.gvsig.vectorediting.lib.prov.polyline; |
|
8 |
|
|
9 |
import java.util.ArrayList; |
|
10 |
import java.util.List; |
|
11 |
|
|
12 |
import org.gvsig.fmap.dal.exception.DataException; |
|
13 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
14 |
import org.gvsig.fmap.geom.Geometry; |
|
15 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
16 |
import org.gvsig.fmap.geom.GeometryManager; |
|
17 |
import org.gvsig.fmap.geom.aggregate.MultiCurve; |
|
18 |
import org.gvsig.fmap.geom.aggregate.MultiSurface; |
|
19 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
|
20 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
|
21 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
|
22 |
import org.gvsig.fmap.geom.primitive.Arc; |
|
23 |
import org.gvsig.fmap.geom.primitive.Curve; |
|
24 |
import org.gvsig.fmap.geom.primitive.Line; |
|
25 |
import org.gvsig.fmap.geom.primitive.Point; |
|
26 |
import org.gvsig.fmap.geom.primitive.Surface; |
|
27 |
import org.gvsig.fmap.geom.type.GeometryType; |
|
28 |
import org.gvsig.tools.dynobject.DynObject; |
|
29 |
import org.gvsig.tools.exception.BaseException; |
|
30 |
import org.gvsig.tools.service.spi.ProviderServices; |
|
31 |
import org.gvsig.vectorediting.lib.api.DrawingStatus; |
|
32 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter; |
|
33 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter.TYPE; |
|
34 |
import org.gvsig.vectorediting.lib.spi.AbstractEditingProvider; |
|
35 |
import org.gvsig.vectorediting.lib.spi.DefaultDrawingStatus; |
|
36 |
import org.gvsig.vectorediting.lib.spi.DefaultEditingServiceParameter; |
|
37 |
import org.gvsig.vectorediting.lib.spi.EditingProvider; |
|
38 |
import org.gvsig.vectorediting.lib.spi.EditingProviderFactory; |
|
39 |
import org.gvsig.vectorediting.lib.spi.EditingProviderServices; |
|
40 |
|
|
41 |
public class PolylineEditingProvider extends AbstractEditingProvider implements |
|
42 |
EditingProvider { |
|
43 |
|
|
44 |
protected GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
|
45 |
|
|
46 |
private EditingProviderServices editingProviderServices = (EditingProviderServices) getProviderServices(); |
|
47 |
|
|
48 |
private EditingServiceParameter points = new DefaultEditingServiceParameter( |
|
49 |
"Polyline", "Inserts a new point.", TYPE.LIST_POSITIONS, TYPE.OPTION); |
|
50 |
|
|
51 |
private boolean arcMode = false; |
|
52 |
|
|
53 |
private List<MyPolyLinePoint> values; |
|
54 |
|
|
55 |
private FeatureStore featureStore; |
|
56 |
|
|
57 |
public PolylineEditingProvider(ProviderServices providerServices, |
|
58 |
DynObject parameters) { |
|
59 |
super(providerServices); |
|
60 |
this.featureStore = (FeatureStore) parameters |
|
61 |
.getDynValue(EditingProviderFactory.FEATURE_STORE_FIELD); |
|
62 |
} |
|
63 |
|
|
64 |
/** |
|
65 |
* |
|
66 |
* @param angle1 |
|
67 |
* @param angle2 |
|
68 |
* @return |
|
69 |
*/ |
|
70 |
private static double angleDistance(double angle1, double angle2) { |
|
71 |
if (angle1 < angle2) { |
|
72 |
return angle2 - angle1; |
|
73 |
} |
|
74 |
else { |
|
75 |
return ((Math.PI * 2) - angle1) + angle2; |
|
76 |
} |
|
77 |
} |
|
78 |
|
|
79 |
/** |
|
80 |
* |
|
81 |
* @param lastPosition |
|
82 |
* @return |
|
83 |
* @throws BaseException |
|
84 |
*/ |
|
85 |
private DrawingStatus calculatePolyline(Point lastPosition) |
|
86 |
throws BaseException { |
|
87 |
DrawingStatus geometries = new DefaultDrawingStatus(); |
|
88 |
Double antm = null; |
|
89 |
Double antb = null; |
|
90 |
Double m = null; |
|
91 |
Double b = null; |
|
92 |
boolean right = false; |
|
93 |
boolean addGeom = false; |
|
94 |
|
|
95 |
if (!values.isEmpty()) { |
|
96 |
for (int i = 0; i < values.size(); i++) { |
|
97 |
|
|
98 |
MyPolyLinePoint polyLinePoint = values.get(i); |
|
99 |
MyPolyLinePoint polyLineNextPoint = getNextPoint(i); |
|
100 |
|
|
101 |
Point point = polyLinePoint.getPoint(); |
|
102 |
Point nextPoint; |
|
103 |
|
|
104 |
if (polyLineNextPoint == null) { |
|
105 |
nextPoint = lastPosition; |
|
106 |
addGeom = true; |
|
107 |
} |
|
108 |
else { |
|
109 |
nextPoint = polyLineNextPoint.getPoint(); |
|
110 |
} |
|
111 |
|
|
112 |
if (nextPoint == null) { |
|
113 |
return geometries; |
|
114 |
} |
|
115 |
if (polyLinePoint.isArcMode()) { |
|
116 |
|
|
117 |
Curve lineAntPointToPoint = editingProviderServices.createLine( |
|
118 |
point.getX(), point.getY(), nextPoint.getX(), nextPoint.getY(), |
|
119 |
featureStore); |
|
120 |
|
|
121 |
Double[] lineParams = getLineParams(point, nextPoint); |
|
122 |
m = lineParams[0]; |
|
123 |
b = lineParams[1]; |
|
124 |
|
|
125 |
Point[] pointPerpendicular = getPerpendicular(antm, antb, point, |
|
126 |
featureStore); |
|
127 |
Line linePointPerpendicular = geomManager |
|
128 |
.createLine(editingProviderServices.getSubType(featureStore)); |
|
129 |
linePointPerpendicular.setPoints(pointPerpendicular[0], |
|
130 |
pointPerpendicular[1]); |
|
131 |
|
|
132 |
Point[] bisector = getPerpendicular(m, b, |
|
133 |
getMidPoint(point, nextPoint, featureStore), featureStore); |
|
134 |
Line lineBisector = geomManager.createLine(editingProviderServices |
|
135 |
.getSubType(featureStore)); |
|
136 |
lineBisector.setPoints(bisector[0], bisector[1]); |
|
137 |
|
|
138 |
Point center = getIntersection(bisector, pointPerpendicular, |
|
139 |
featureStore); |
|
140 |
|
|
141 |
double startAngle = getAngle(center, point); |
|
142 |
double endAngle = getAngle(center, nextPoint); |
|
143 |
|
|
144 |
double radius = center.distance(point); |
|
145 |
|
|
146 |
double angleExt = 0.0; |
|
147 |
|
|
148 |
if (right) { |
|
149 |
if (nextPoint.getX() >= point.getX()) { |
|
150 |
if (m >= antm) { |
|
151 |
angleExt = angleDistance(endAngle, startAngle); |
|
152 |
right = !(nextPoint.getY() >= center.getY()); |
|
153 |
} |
|
154 |
else { |
|
155 |
angleExt = -angleDistance(startAngle, endAngle); |
|
156 |
right = (nextPoint.getY() >= center.getY()); |
|
157 |
} |
|
158 |
} |
|
159 |
else { |
|
160 |
if (m >= antm) { |
|
161 |
angleExt = -angleDistance(startAngle, endAngle); |
|
162 |
right = (nextPoint.getY() >= center.getY()); |
|
163 |
} |
|
164 |
else { |
|
165 |
angleExt = angleDistance(endAngle, startAngle); |
|
166 |
right = !(nextPoint.getY() >= center.getY()); |
|
167 |
} |
|
168 |
} |
|
169 |
} |
|
170 |
else { |
|
171 |
if (nextPoint.getX() < point.getX()) { |
|
172 |
if (m >= antm) { |
|
173 |
angleExt = angleDistance(endAngle, startAngle); |
|
174 |
right = !(nextPoint.getY() >= center.getY()); |
|
175 |
} |
|
176 |
else { |
|
177 |
angleExt = -angleDistance(startAngle, endAngle); |
|
178 |
right = (nextPoint.getY() >= center.getY()); |
|
179 |
} |
|
180 |
} |
|
181 |
else { |
|
182 |
if (m >= antm) { |
|
183 |
angleExt = -angleDistance(startAngle, endAngle); |
|
184 |
right = (nextPoint.getY() >= center.getY()); |
|
185 |
} |
|
186 |
else { |
|
187 |
angleExt = angleDistance(endAngle, startAngle); |
|
188 |
right = !(nextPoint.getY() >= center.getY()); |
|
189 |
} |
|
190 |
} |
|
191 |
} |
|
192 |
|
|
193 |
Arc arco = editingProviderServices.createArc(center, radius, |
|
194 |
startAngle, angleExt, featureStore); |
|
195 |
|
|
196 |
antm = -(nextPoint.getX() - center.getX()) |
|
197 |
/ (nextPoint.getY() - center.getY()); |
|
198 |
if (antm == Double.POSITIVE_INFINITY) { |
|
199 |
antb = Double.NEGATIVE_INFINITY; |
|
200 |
if (nextPoint.getX() == 0) { |
|
201 |
antb = 0.0; |
|
202 |
} |
|
203 |
} |
|
204 |
else if (antm == Double.NEGATIVE_INFINITY) { |
|
205 |
antb = Double.POSITIVE_INFINITY; |
|
206 |
if (nextPoint.getX() == 0) { |
|
207 |
antb = 0.0; |
|
208 |
} |
|
209 |
} |
|
210 |
else { |
|
211 |
antb = nextPoint.getY() - (antm * nextPoint.getX()); |
|
212 |
} |
|
213 |
|
|
214 |
// Draw geometries. |
|
215 |
if (addGeom) { |
|
216 |
geometries.addGeometry(lineAntPointToPoint); |
|
217 |
geometries.addGeometry(center); |
|
218 |
} |
|
219 |
geometries.addGeometry(arco); |
|
220 |
|
|
221 |
} |
|
222 |
else { |
|
223 |
Curve geometry = editingProviderServices.createLine(point.getX(), |
|
224 |
point.getY(), nextPoint.getX(), nextPoint.getY(), featureStore); |
|
225 |
geometries.addGeometry(geometry); |
|
226 |
|
|
227 |
Double[] antLineParams = getLineParams(point, nextPoint); |
|
228 |
antm = antLineParams[0]; |
|
229 |
antb = antLineParams[1]; |
|
230 |
right = (nextPoint.getX() >= point.getX()); |
|
231 |
} |
|
232 |
} |
|
233 |
return geometries; |
|
234 |
} |
|
235 |
else { |
|
236 |
// TODO throw exception to be catch by editingBehavior to and error at |
|
237 |
// console. |
|
238 |
} |
|
239 |
return null; |
|
240 |
} |
|
241 |
|
|
242 |
/** |
|
243 |
* |
|
244 |
* @param surface |
|
245 |
* @return |
|
246 |
*/ |
|
247 |
private Surface closeSurfaceIfNecessary(Surface surface) { |
|
248 |
if (!isClose(surface) && surface != null) { |
|
249 |
Point firstp = surface.getVertex(0); |
|
250 |
firstp = (Point) firstp.cloneGeometry(); |
|
251 |
surface.addVertex(firstp); |
|
252 |
} |
|
253 |
return surface; |
|
254 |
} |
|
255 |
|
|
256 |
public DrawingStatus draw(Point mousePosition) throws BaseException { |
|
257 |
return calculatePolyline(mousePosition); |
|
258 |
} |
|
259 |
|
|
260 |
public void finish() throws BaseException, DataException { |
|
261 |
GeometryType storeGeomType = editingProviderServices |
|
262 |
.getGeomType(featureStore); |
|
263 |
DrawingStatus finalGeometries = calculatePolyline(null); |
|
264 |
if (storeGeomType.isTypeOf(SURFACE)) { |
|
265 |
Surface surface = geomManager.createPolygon(storeGeomType.getSubType()); |
|
266 |
for (Geometry geometry : finalGeometries.getGeometries()) { |
|
267 |
surface.addVertex((Point) geometry); |
|
268 |
} |
|
269 |
surface = closeSurfaceIfNecessary(surface); |
|
270 |
editingProviderServices.insertGeometryIntoFeatureStore(surface, |
|
271 |
featureStore); |
|
272 |
} |
|
273 |
else if (storeGeomType.isTypeOf(CURVE)) { |
|
274 |
for (Geometry geometry : finalGeometries.getGeometries()) { |
|
275 |
editingProviderServices.insertGeometryIntoFeatureStore(geometry, |
|
276 |
featureStore); |
|
277 |
} |
|
278 |
} |
|
279 |
else if (storeGeomType.isTypeOf(MULTISURFACE)) { |
|
280 |
MultiSurface multiSurface; |
|
281 |
multiSurface = geomManager.createMultiSurface(storeGeomType.getSubType()); |
|
282 |
Surface surface = geomManager.createPolygon(storeGeomType.getSubType()); |
|
283 |
for (Geometry geometry : finalGeometries.getGeometries()) { |
|
284 |
if(geometry instanceof Curve){ |
|
285 |
Curve curve = (Curve) geometry; |
|
286 |
for(int i=0; i < curve.getNumVertices(); i++){ |
|
287 |
surface.addVertex((Point) curve.getVertex(i)); |
|
288 |
} |
|
289 |
} |
|
290 |
} |
|
291 |
surface = closeSurfaceIfNecessary(surface); |
|
292 |
multiSurface.addSurface(surface); |
|
293 |
editingProviderServices.insertGeometryIntoFeatureStore(multiSurface, |
|
294 |
featureStore); |
|
295 |
} |
|
296 |
else if (storeGeomType.isTypeOf(MULTICURVE)) { |
|
297 |
MultiCurve multiCurve; |
|
298 |
multiCurve = geomManager.createMultiCurve(storeGeomType.getSubType()); |
|
299 |
for (Geometry geometry : finalGeometries.getGeometries()) { |
|
300 |
multiCurve.addCurve((Curve) geometry); |
|
301 |
} |
|
302 |
editingProviderServices.insertGeometryIntoFeatureStore(multiCurve, |
|
303 |
featureStore); |
|
304 |
} |
|
305 |
} |
|
306 |
|
|
307 |
/** |
|
308 |
* |
|
309 |
* @param start |
|
310 |
* @param end |
|
311 |
* @return |
|
312 |
* @throws GeometryOperationNotSupportedException |
|
313 |
* @throws GeometryOperationException |
|
314 |
*/ |
|
315 |
private static double getAngle(Point start, Point end) |
|
316 |
throws GeometryOperationNotSupportedException, GeometryOperationException { |
|
317 |
double angle = Math.acos((end.getX() - start.getX()) / start.distance(end)); |
|
318 |
|
|
319 |
if (start.getY() > end.getY()) { |
|
320 |
angle = -angle; |
|
321 |
} |
|
322 |
|
|
323 |
if (angle < 0) { |
|
324 |
angle += (2 * Math.PI); |
|
325 |
} |
|
326 |
|
|
327 |
return angle; |
|
328 |
} |
|
329 |
|
|
330 |
/** |
|
331 |
* |
|
332 |
* @param bisector |
|
333 |
* @param perpendicular |
|
334 |
* @param featureStore |
|
335 |
* @return |
|
336 |
* @throws CreateGeometryException |
|
337 |
* @throws DataException |
|
338 |
*/ |
|
339 |
private Point getIntersection(Point[] bisector, Point[] perpendicular, |
|
340 |
FeatureStore featureStore) |
|
341 |
throws CreateGeometryException, DataException { |
|
342 |
Point p1 = bisector[0]; |
|
343 |
Point p2 = bisector[1]; |
|
344 |
Point p3 = perpendicular[0]; |
|
345 |
Point p4 = perpendicular[1]; |
|
346 |
|
|
347 |
double m1 = Double.POSITIVE_INFINITY; |
|
348 |
|
|
349 |
if ((p2.getX() - p1.getX()) != 0) { |
|
350 |
m1 = (p2.getY() - p1.getY()) / (p2.getX() - p1.getX()); |
|
351 |
} |
|
352 |
|
|
353 |
double m2 = Double.POSITIVE_INFINITY; |
|
354 |
|
|
355 |
if ((p4.getX() - p3.getX()) != 0) { |
|
356 |
m2 = (p4.getY() - p3.getY()) / (p4.getX() - p3.getX()); |
|
357 |
} |
|
358 |
|
|
359 |
if ((m1 == Double.POSITIVE_INFINITY) && (m2 == Double.POSITIVE_INFINITY)) { |
|
360 |
return null; |
|
361 |
} |
|
362 |
|
|
363 |
double b1 = p2.getY() - (m1 * p2.getX()); |
|
364 |
|
|
365 |
double b2 = p4.getY() - (m2 * p4.getX()); |
|
366 |
|
|
367 |
if ((m1 != Double.POSITIVE_INFINITY) && (m2 != Double.POSITIVE_INFINITY)) { |
|
368 |
if (m1 == m2) { |
|
369 |
return null; |
|
370 |
} |
|
371 |
|
|
372 |
double x = (b2 - b1) / (m1 - m2); |
|
373 |
|
|
374 |
return editingProviderServices |
|
375 |
.createPoint(x, (m1 * x) + b1, featureStore); |
|
376 |
} |
|
377 |
else if (m1 == Double.POSITIVE_INFINITY) { |
|
378 |
double x = p1.getX(); |
|
379 |
|
|
380 |
return editingProviderServices |
|
381 |
.createPoint(x, (m2 * x) + b2, featureStore); |
|
382 |
} |
|
383 |
else if (m2 == Double.POSITIVE_INFINITY) { |
|
384 |
double x = p3.getX(); |
|
385 |
|
|
386 |
return editingProviderServices |
|
387 |
.createPoint(x, (m1 * x) + b1, featureStore); |
|
388 |
} |
|
389 |
|
|
390 |
return null; |
|
391 |
} |
|
392 |
|
|
393 |
/** |
|
394 |
* |
|
395 |
* @param point |
|
396 |
* @param nextPoint |
|
397 |
* @return |
|
398 |
*/ |
|
399 |
private Double[] getLineParams(Point point, Point nextPoint) { |
|
400 |
Double[] lineParams = new Double[2]; |
|
401 |
double denom = nextPoint.getX() - point.getX(); |
|
402 |
if (denom != 0) { |
|
403 |
lineParams[0] = (nextPoint.getY() - point.getY()) / denom; |
|
404 |
lineParams[1] = point.getY() - (lineParams[0] * point.getX()); |
|
405 |
} |
|
406 |
else { |
|
407 |
if (nextPoint.getY() >= point.getY()) { |
|
408 |
lineParams[0] = Double.POSITIVE_INFINITY; |
|
409 |
lineParams[1] = Double.NEGATIVE_INFINITY; |
|
410 |
if (point.getX() == 0) { |
|
411 |
lineParams[1] = 0.0; |
|
412 |
} |
|
413 |
} |
|
414 |
else { |
|
415 |
lineParams[0] = Double.NEGATIVE_INFINITY; |
|
416 |
lineParams[1] = Double.POSITIVE_INFINITY; |
|
417 |
if (point.getX() == 0) { |
|
418 |
lineParams[1] = 0.0; |
|
419 |
} |
|
420 |
} |
|
421 |
} |
|
422 |
return lineParams; |
|
423 |
} |
|
424 |
|
|
425 |
/** |
|
426 |
* |
|
427 |
* @param p1 |
|
428 |
* @param p2 |
|
429 |
* @param featureStore |
|
430 |
* @return |
|
431 |
* @throws CreateGeometryException |
|
432 |
* @throws DataException |
|
433 |
*/ |
|
434 |
private Point getMidPoint(Point p1, Point p2, FeatureStore featureStore) |
|
435 |
throws CreateGeometryException, DataException { |
|
436 |
double x = (p1.getX() + p2.getX()) / 2; |
|
437 |
double y = (p1.getY() + p2.getY()) / 2; |
|
438 |
return editingProviderServices.createPoint(x, y, featureStore); |
|
439 |
} |
|
440 |
|
|
441 |
public String getName() { |
|
442 |
return PolylineEditingProviderFactory.PROVIDER_NAME; |
|
443 |
} |
|
444 |
|
|
445 |
/** |
|
446 |
* |
|
447 |
* @param i |
|
448 |
* @return |
|
449 |
*/ |
|
450 |
private MyPolyLinePoint getNextPoint(int i) { |
|
451 |
if (!values.isEmpty() && i < values.size() - 1) { |
|
452 |
return values.get(i + 1); |
|
453 |
} |
|
454 |
return null; |
|
455 |
} |
|
456 |
|
|
457 |
public List<EditingServiceParameter> getParameters() { |
|
458 |
List<EditingServiceParameter> list = new ArrayList<EditingServiceParameter>(); |
|
459 |
list.add(points); |
|
460 |
return list; |
|
461 |
} |
|
462 |
|
|
463 |
/** |
|
464 |
* |
|
465 |
* @param m |
|
466 |
* @param b |
|
467 |
* @param perp |
|
468 |
* @param featureStore |
|
469 |
* @return |
|
470 |
* @throws CreateGeometryException |
|
471 |
* @throws DataException |
|
472 |
*/ |
|
473 |
private Point[] getPerpendicular(Double m, Double b, Point perp, |
|
474 |
FeatureStore featureStore) |
|
475 |
throws CreateGeometryException, DataException { |
|
476 |
if (m == Double.POSITIVE_INFINITY) { |
|
477 |
Point[] res = new Point[2]; |
|
478 |
res[0] = editingProviderServices |
|
479 |
.createPoint(0, perp.getY(), featureStore); |
|
480 |
res[1] = editingProviderServices |
|
481 |
.createPoint(1, perp.getY(), featureStore); |
|
482 |
return res; |
|
483 |
} |
|
484 |
else if (m == Double.NEGATIVE_INFINITY) { |
|
485 |
Point[] res = new Point[2]; |
|
486 |
res[0] = editingProviderServices |
|
487 |
.createPoint(1, perp.getY(), featureStore); |
|
488 |
res[1] = editingProviderServices |
|
489 |
.createPoint(0, perp.getY(), featureStore); |
|
490 |
return res; |
|
491 |
} |
|
492 |
else { |
|
493 |
// Pendiente de la recta perpendicular |
|
494 |
Double m1 = -1 / m; |
|
495 |
|
|
496 |
// b de la funcion de la recta perpendicular |
|
497 |
Double b1 = perp.getY() - (m1 * perp.getX()); |
|
498 |
|
|
499 |
// Obtenemos un par de puntos |
|
500 |
Point[] res = new Point[2]; |
|
501 |
|
|
502 |
if (Double.isInfinite(m1)) { |
|
503 |
res[0] = editingProviderServices.createPoint(perp.getX(), 0.0, |
|
504 |
featureStore); |
|
505 |
res[1] = editingProviderServices.createPoint(perp.getX(), perp.getY(), |
|
506 |
featureStore); |
|
507 |
} |
|
508 |
else { |
|
509 |
res[0] = editingProviderServices.createPoint(0, 0.0 + b1, featureStore); |
|
510 |
res[1] = editingProviderServices.createPoint(perp.getX(), |
|
511 |
(m1 * perp.getX()) + b1, featureStore); |
|
512 |
} |
|
513 |
|
|
514 |
return res; |
|
515 |
} |
|
516 |
} |
|
517 |
|
|
518 |
/** |
|
519 |
* |
|
520 |
* @param surface |
|
521 |
* @return |
|
522 |
*/ |
|
523 |
private boolean isClose(Surface surface) { |
|
524 |
|
|
525 |
if(surface != null){ |
|
526 |
Point firstPoint = surface.getVertex(0); |
|
527 |
Point lastPoint = surface.getVertex(surface.getNumVertices()-1); |
|
528 |
if(firstPoint.equals(lastPoint)){ |
|
529 |
return true; |
|
530 |
} |
|
531 |
} |
|
532 |
return false; |
|
533 |
} |
|
534 |
|
|
535 |
public EditingServiceParameter next() { |
|
536 |
if( values.size() >= 2){ |
|
537 |
if(arcMode){ |
|
538 |
points.setDescription("Inserts [L] to change to line mode. Double-click to finish. Inserts new point."); |
|
539 |
} |
|
540 |
else{ |
|
541 |
points.setDescription("Inserts [A] to change to arc mode. Double-click to finish. Inserts new point."); |
|
542 |
} |
|
543 |
} |
|
544 |
return points; |
|
545 |
} |
|
546 |
|
|
547 |
public void start() { |
|
548 |
values = new ArrayList<MyPolyLinePoint>(); |
|
549 |
} |
|
550 |
|
|
551 |
public void stop() { |
|
552 |
// TODO Auto-generated method stub |
|
553 |
|
|
554 |
} |
|
555 |
|
|
556 |
/** |
|
557 |
* |
|
558 |
* @param param |
|
559 |
* @param value |
|
560 |
*/ |
|
561 |
private void validateAndInsertValue(EditingServiceParameter param, |
|
562 |
Object value) { |
|
563 |
if (value instanceof String) { |
|
564 |
if (values.size() >= 2) { |
|
565 |
if (((String) value).equalsIgnoreCase("A")) { |
|
566 |
arcMode = true; |
|
567 |
} |
|
568 |
else if (((String) value).equalsIgnoreCase("L")) { |
|
569 |
arcMode = false; |
|
570 |
} |
|
571 |
if (values.size() > 0) { |
|
572 |
values.get(values.size() - 1).setArcMode(arcMode); |
|
573 |
return; |
|
574 |
} |
|
575 |
} |
|
576 |
} |
|
577 |
else if (param == points && value instanceof Point) { |
|
578 |
values.add(new MyPolyLinePoint((Point) value, arcMode)); |
|
579 |
} |
|
580 |
} |
|
581 |
|
|
582 |
public void value(Object value) { |
|
583 |
EditingServiceParameter param = next(); |
|
584 |
validateAndInsertValue(param, value); |
|
585 |
} |
|
586 |
|
|
587 |
} |
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/MyPolyLinePoint.java | ||
---|---|---|
1 |
/* |
|
2 |
* Copyright 2014 DiSiD Technologies S.L.L. All rights reserved. |
|
3 |
* |
|
4 |
* Project : DiSiD org.gvsig.vectorediting.lib.prov.polyline |
|
5 |
* SVN Id : $Id$ |
|
6 |
*/ |
|
7 |
package org.gvsig.vectorediting.lib.prov.polyline; |
|
8 |
|
|
9 |
import org.gvsig.fmap.geom.primitive.Point; |
|
10 |
|
|
11 |
|
|
12 |
public class MyPolyLinePoint { |
|
13 |
|
|
14 |
private Point point; |
|
15 |
|
|
16 |
private boolean arcMode; |
|
17 |
|
|
18 |
public MyPolyLinePoint(Point point, boolean mode){ |
|
19 |
this.point = point; |
|
20 |
this.arcMode = mode; |
|
21 |
} |
|
22 |
|
|
23 |
|
|
24 |
public Point getPoint() { |
|
25 |
return point; |
|
26 |
} |
|
27 |
|
|
28 |
|
|
29 |
public void setPoint(Point point) { |
|
30 |
this.point = point; |
|
31 |
} |
|
32 |
|
|
33 |
|
|
34 |
public boolean isArcMode() { |
|
35 |
return arcMode; |
|
36 |
} |
|
37 |
|
|
38 |
|
|
39 |
public void setArcMode(boolean arcMode) { |
|
40 |
this.arcMode = arcMode; |
|
41 |
} |
|
42 |
|
|
43 |
|
|
44 |
} |
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.polyline/pom.xml | ||
---|---|---|
1 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
2 |
<modelVersion>4.0.0</modelVersion> |
|
3 |
<parent> |
|
4 |
<groupId>org.gvsig</groupId> |
|
5 |
<artifactId>org.gvsig.vectorediting.lib.prov</artifactId> |
|
6 |
<version>1.0.0-SNAPSHOT</version> |
|
7 |
</parent> |
|
8 |
<artifactId>org.gvsig.vectorediting.lib.prov.polyline</artifactId> |
|
9 |
<name>org.gvsig.vectorediting.lib.prov.polyline</name> |
|
10 |
</project> |
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/pom.xml | ||
---|---|---|
11 | 11 |
<modules> |
12 | 12 |
<module>org.gvsig.vectorediting.lib.prov.insertpoint</module> |
13 | 13 |
<module>org.gvsig.vectorediting.lib.prov.circlecr</module> |
14 |
<module>org.gvsig.vectorediting.lib.prov.polyline</module> |
|
14 | 15 |
</modules> |
15 | 16 |
<dependencies> |
16 | 17 |
<dependency> |
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.api/src/main/java/org/gvsig/vectorediting/lib/api/EditingServiceParameter.java | ||
---|---|---|
29 | 29 |
* @return |
30 | 30 |
*/ |
31 | 31 |
public String getDescription(); |
32 |
|
|
32 |
|
|
33 |
/** |
|
34 |
* |
|
35 |
*/ |
|
36 |
public void setDescription(String newDescription); |
|
33 | 37 |
} |
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.spi/src/main/java/org/gvsig/vectorediting/lib/spi/EditingProvider.java | ||
---|---|---|
10 | 10 |
|
11 | 11 |
import org.gvsig.fmap.dal.exception.DataException; |
12 | 12 |
import org.gvsig.fmap.geom.Geometry; |
13 |
import org.gvsig.fmap.geom.GeometryException; |
|
13 | 14 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
15 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
|
14 | 16 |
import org.gvsig.fmap.geom.primitive.Point; |
15 | 17 |
import org.gvsig.tools.exception.BaseException; |
16 | 18 |
import org.gvsig.tools.service.spi.Provider; |
19 |
import org.gvsig.vectorediting.lib.api.DrawingStatus; |
|
17 | 20 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter; |
18 | 21 |
|
19 |
|
|
20 | 22 |
public interface EditingProvider extends Provider { |
21 | 23 |
|
22 | 24 |
/** |
23 | 25 |
* @return |
24 |
* |
|
25 | 26 |
*/ |
26 | 27 |
public EditingServiceParameter next(); |
27 | 28 |
|
28 | 29 |
/** |
29 |
* |
|
30 | 30 |
* @param mousePosition |
31 | 31 |
* @return |
32 |
* @throws CreateGeometryException |
|
33 |
* @throws BaseException |
|
32 |
* @throws CreateGeometryException
|
|
33 |
* @throws BaseException
|
|
34 | 34 |
*/ |
35 |
public DefaultDrawingStatus draw(Point mousePosition) throws BaseException;
|
|
35 |
public DrawingStatus draw(Point mousePosition) throws BaseException; |
|
36 | 36 |
|
37 | 37 |
/** |
38 | 38 |
* |
... | ... | |
40 | 40 |
public void stop(); |
41 | 41 |
|
42 | 42 |
/** |
43 |
* |
|
44 | 43 |
* @return |
45 | 44 |
*/ |
46 | 45 |
public List<EditingServiceParameter> getParameters(); |
47 | 46 |
|
48 | 47 |
/** |
49 |
* |
|
50 | 48 |
* @param param |
51 | 49 |
* @param value |
52 | 50 |
*/ |
53 | 51 |
public void value(Object value); |
54 | 52 |
|
55 | 53 |
/** |
56 |
* @throws CreateGeometryException |
|
57 |
* @throws DataException |
|
58 |
* |
|
54 |
* @throws CreateGeometryException |
|
55 |
* @throws DataException |
|
56 |
* @throws GeometryException |
|
57 |
* @throws GeometryOperationException |
|
59 | 58 |
*/ |
60 |
public void finish() throws CreateGeometryException, DataException;
|
|
59 |
public void finish() throws DataException, BaseException;
|
|
61 | 60 |
|
62 | 61 |
/** |
63 | 62 |
* |
... | ... | |
65 | 64 |
public void start(); |
66 | 65 |
|
67 | 66 |
/** |
68 |
* |
|
69 | 67 |
* @return |
70 | 68 |
*/ |
71 | 69 |
public String getName(); |
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.spi/src/main/java/org/gvsig/vectorediting/lib/spi/EditingProviderServices.java | ||
---|---|---|
12 | 12 |
import org.gvsig.fmap.dal.feature.Feature; |
13 | 13 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
14 | 14 |
import org.gvsig.fmap.geom.Geometry; |
15 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
|
16 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
|
17 | 15 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
16 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
|
17 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
|
18 | 18 |
import org.gvsig.fmap.geom.primitive.Arc; |
19 | 19 |
import org.gvsig.fmap.geom.primitive.Circle; |
20 | 20 |
import org.gvsig.fmap.geom.primitive.Curve; |
... | ... | |
28 | 28 |
* @param feature |
29 | 29 |
* @param featureStore |
30 | 30 |
*/ |
31 |
public void insertFeatureIntoFeatureStore(Feature feature, FeatureStore featureStore); |
|
31 |
public void insertFeatureIntoFeatureStore(Feature feature, |
|
32 |
FeatureStore featureStore); |
|
32 | 33 |
|
33 | 34 |
/** |
34 | 35 |
* @param geometry |
35 | 36 |
* @param featureStore |
36 | 37 |
*/ |
37 |
public void insertGeometryIntoFeatureStore(Geometry geometry, FeatureStore featureStore); |
|
38 |
public void insertGeometryIntoFeatureStore(Geometry geometry, |
|
39 |
FeatureStore featureStore); |
|
38 | 40 |
|
39 | 41 |
/** |
40 | 42 |
* @param feature |
41 | 43 |
* @param featureStore |
42 | 44 |
*/ |
43 |
public void deleteFeatureFromFeatureStore(Feature feature, FeatureStore featureStore); |
|
45 |
public void deleteFeatureFromFeatureStore(Feature feature, |
|
46 |
FeatureStore featureStore); |
|
44 | 47 |
|
45 | 48 |
/** |
46 | 49 |
* @param geometry |
47 | 50 |
* @param featureStore |
48 | 51 |
*/ |
49 |
public void deleteGeometryFromFeatureStore(Geometry geometry, FeatureStore featureStore); |
|
52 |
public void deleteGeometryFromFeatureStore(Geometry geometry, |
|
53 |
FeatureStore featureStore); |
|
50 | 54 |
|
51 | 55 |
/** |
52 | 56 |
* @param feature |
53 | 57 |
* @param featureStore |
54 | 58 |
*/ |
55 |
public void updateFeatureInFeatureStore(Feature feature, FeatureStore featureStore); |
|
59 |
public void updateFeatureInFeatureStore(Feature feature, |
|
60 |
FeatureStore featureStore); |
|
56 | 61 |
|
57 | 62 |
/** |
58 | 63 |
* @param geometry |
59 | 64 |
* @param featureStore |
60 | 65 |
*/ |
61 |
public void updateGeometryInFeatureStore(Geometry geometry, FeatureStore featureStore); |
|
66 |
public void updateGeometryInFeatureStore(Geometry geometry, |
|
67 |
FeatureStore featureStore); |
|
62 | 68 |
|
69 |
/** |
|
70 |
* Create a circle from a GeneralPath. If there is an error return |
|
71 |
* <code>null</code> and add the error to the log |
|
72 |
* |
|
73 |
* @param p1 |
|
74 |
* @param p2 |
|
75 |
* @return The circle |
|
76 |
* @throws CreateGeometryException |
|
77 |
* @throws DataException |
|
78 |
*/ |
|
79 |
public Circle createCircle(Point2D p1, Point2D p2, FeatureStore featureStore) |
|
80 |
throws CreateGeometryException, DataException; |
|
63 | 81 |
|
64 |
/** |
|
65 |
* Create a circle from a GeneralPath. If there is an error return |
|
66 |
* <code>null</code> and add the error to the log |
|
67 |
* |
|
68 |
* @param p1 |
|
69 |
* @param p2 |
|
70 |
* @return The circle |
|
71 |
* @throws CreateGeometryException |
|
72 |
* @throws DataException |
|
73 |
*/ |
|
74 |
public Circle createCircle(Point2D p1, Point2D p2, FeatureStore featureStore) throws CreateGeometryException, |
|
75 |
DataException; |
|
76 |
/** |
|
77 |
* Create a circle. If there is an error return <code>null</code> and add |
|
78 |
* the error to the log |
|
79 |
* |
|
80 |
* @param p1 |
|
81 |
* @param p2 |
|
82 |
* @return The circle |
|
83 |
* @throws CreateGeometryException |
|
84 |
* @throws DataException |
|
85 |
*/ |
|
86 |
public Circle createCircle(Point p1, Point p2, FeatureStore featureStore) throws CreateGeometryException, |
|
87 |
DataException; |
|
88 |
/** |
|
89 |
* Create a circle. If there is an error return <code>null</code> and add |
|
90 |
* the error to the log |
|
91 |
* |
|
92 |
* @param center |
|
93 |
* @param radius |
|
94 |
* @return The circle |
|
95 |
* @throws CreateGeometryException |
|
96 |
* @throws DataException |
|
97 |
*/ |
|
98 |
public Circle createCircle(Point center, double radius, |
|
99 |
FeatureStore featureStore) throws CreateGeometryException, |
|
100 |
DataException; |
|
82 |
/** |
|
83 |
* Create a circle. If there is an error return <code>null</code> and add the |
|
84 |
* error to the log |
|
85 |
* |
|
86 |
* @param p1 |
|
87 |
* @param p2 |
|
88 |
* @return The circle |
|
89 |
* @throws CreateGeometryException |
|
90 |
* @throws DataException |
|
91 |
*/ |
|
92 |
public Circle createCircle(Point p1, Point p2, FeatureStore featureStore) |
|
93 |
throws CreateGeometryException, DataException; |
|
101 | 94 |
|
102 |
/** |
|
103 |
* Create a circle. If there is an error return <code>null</code> and add |
|
104 |
* the error to the log |
|
105 |
* |
|
106 |
* @param center |
|
107 |
* @param radius |
|
108 |
* @param startAngle |
|
109 |
* in radians |
|
110 |
* @param angleExt |
|
111 |
* @return The circle |
|
112 |
* @throws org.gvsig.fmap.geom.exception.CreateGeometryException |
|
113 |
* @throws DataException |
|
114 |
*/ |
|
115 |
public Arc createArc(Point center, double radius, double startAngle, |
|
116 |
double angleExt, FeatureStore featureStore) |
|
117 |
throws CreateGeometryException, DataException; |
|
95 |
/** |
|
96 |
* Create a circle. If there is an error return <code>null</code> and add the |
|
97 |
* error to the log |
|
98 |
* |
|
99 |
* @param center |
|
100 |
* @param radius |
|
101 |
* @return The circle |
|
102 |
* @throws CreateGeometryException |
|
103 |
* @throws DataException |
|
104 |
*/ |
|
105 |
public Circle createCircle(Point center, double radius, |
|
106 |
FeatureStore featureStore) |
|
107 |
throws CreateGeometryException, DataException; |
|
118 | 108 |
|
119 |
/** |
|
120 |
* Create point. If there is an error return <code>null</code> and add the |
|
121 |
* error to the log |
|
122 |
* |
|
123 |
* @param x |
|
124 |
* The X coordinate |
|
125 |
* @param y |
|
126 |
* The y coordinate |
|
127 |
* @return The Point |
|
128 |
* @throws CreateGeometryException |
|
129 |
* @throws DataException |
|
130 |
*/ |
|
131 |
public Point createPoint(double x, double y, FeatureStore featureStore) |
|
132 |
throws CreateGeometryException, DataException; |
|
109 |
/** |
|
110 |
* Create a circle. If there is an error return <code>null</code> and add the |
|
111 |
* error to the log |
|
112 |
* |
|
113 |
* @param center |
|
114 |
* @param radius |
|
115 |
* @param startAngle in radians |
|
116 |
* @param angleExt |
|
117 |
* @return The circle |
|
118 |
* @throws org.gvsig.fmap.geom.exception.CreateGeometryException |
|
119 |
* @throws DataException |
|
120 |
*/ |
|
121 |
public Arc createArc(Point center, double radius, double startAngle, |
|
122 |
double angleExt, FeatureStore featureStore) |
|
123 |
throws CreateGeometryException, DataException; |
|
133 | 124 |
|
134 |
/** |
|
135 |
* Create line. If there is an error return <code>null</code> and add the |
|
136 |
* error to the log |
|
137 |
* |
|
138 |
* @param x1 |
|
139 |
* The X1 coordinate |
|
140 |
* @param y1 |
|
141 |
* The y1 coordinate |
|
142 |
* |
|
143 |
* @param x2 |
|
144 |
* The X2 coordinate |
Also available in: Unified diff