gvsig-vectorediting / org.gvsig.vectorediting / trunk / org.gvsig.vectorediting / org.gvsig.vectorediting.lib / org.gvsig.vectorediting.lib.prov / org.gvsig.vectorediting.lib.prov.editvertex / src / main / java / org / gvsig / vectorediting / lib / prov / editvertex / operation / FilledSplineEditVertexOperation.java @ 575
History | View | Annotate | Download (4.75 KB)
1 |
package org.gvsig.vectorediting.lib.prov.editvertex.operation; |
---|---|
2 |
|
3 |
import java.util.ArrayList; |
4 |
import java.util.List; |
5 |
|
6 |
import org.gvsig.fmap.geom.Geometry; |
7 |
import org.gvsig.fmap.geom.GeometryLocator; |
8 |
import org.gvsig.fmap.geom.GeometryManager; |
9 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
10 |
import org.gvsig.fmap.geom.primitive.FilledSpline; |
11 |
import org.gvsig.fmap.geom.primitive.OrientablePrimitive; |
12 |
import org.gvsig.fmap.geom.primitive.Point; |
13 |
import org.gvsig.fmap.geom.primitive.Primitive; |
14 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
15 |
import org.gvsig.vectorediting.lib.spi.DefaultDrawingStatus; |
16 |
import org.gvsig.vectorediting.lib.spi.EditingProviderLocator; |
17 |
import org.gvsig.vectorediting.lib.spi.EditingProviderManager; |
18 |
|
19 |
public class FilledSplineEditVertexOperation implements EditVertexOperation { |
20 |
|
21 |
public FilledSplineEditVertexOperation() {
|
22 |
// TODO Auto-generated constructor stub
|
23 |
} |
24 |
|
25 |
public Geometry insertVertex(Primitive geom, int index) |
26 |
throws CreateGeometryException {
|
27 |
if (index == 0) { |
28 |
return geom;
|
29 |
} |
30 |
GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
31 |
FilledSpline result = |
32 |
(FilledSpline) geometryManager.create(Geometry.TYPES.FILLEDSPLINE,geom.getGeometryType().getSubType()); |
33 |
|
34 |
FilledSpline filledSpline = (FilledSpline) geom; |
35 |
int numVertices = filledSpline.getNumVertices();
|
36 |
|
37 |
Point antPoint = null; |
38 |
for (int i = 0; i < numVertices; i++) { |
39 |
Point point = filledSpline.getVertex(i);
|
40 |
if (i == index) {
|
41 |
result.addVertex(geometryManager.createPoint( |
42 |
(point.getX() + antPoint.getX()) / 2,
|
43 |
(point.getY() + antPoint.getY()) / 2, geom
|
44 |
.getGeometryType().getSubType())); |
45 |
|
46 |
} |
47 |
result.addVertex(point); |
48 |
antPoint = point; |
49 |
} |
50 |
return result;
|
51 |
} |
52 |
|
53 |
public Geometry removeVertex(Primitive geom, int index) |
54 |
throws CreateGeometryException {
|
55 |
if (index < 0) { |
56 |
return geom;
|
57 |
} |
58 |
GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
59 |
FilledSpline result = |
60 |
(FilledSpline) geometryManager.create(Geometry.TYPES.SPLINE,geom.getGeometryType().getSubType()); |
61 |
|
62 |
FilledSpline filledSpline = (FilledSpline) geom; |
63 |
int numVertices = filledSpline.getNumVertices();
|
64 |
|
65 |
for (int i = 0; i < numVertices; i++) { |
66 |
Point point = filledSpline.getVertex(i);
|
67 |
if (i == index) {
|
68 |
continue;
|
69 |
} |
70 |
result.addVertex(point); |
71 |
} |
72 |
return result;
|
73 |
} |
74 |
|
75 |
public Geometry moveVertex(Primitive geom, int index, Point point) { |
76 |
FilledSpline result = (FilledSpline) geom.cloneGeometry(); |
77 |
int numVertices = result.getNumVertices();
|
78 |
if (result.getVertex(0).equals(result.getVertex(numVertices - 1))) { |
79 |
if (index == 0 || index == (result.getNumVertices() - 1)) { |
80 |
EditVertexOperationUtils.setVertex(result, 0, point);
|
81 |
EditVertexOperationUtils.setVertex(result, |
82 |
result.getNumVertices() - 1, (Point)point.cloneGeometry()); |
83 |
return result;
|
84 |
} |
85 |
} |
86 |
EditVertexOperationUtils.setVertex(result, index, point); |
87 |
return result;
|
88 |
} |
89 |
|
90 |
public List<Point> getVertexesList(Primitive geom) { |
91 |
ArrayList<Point> vertexList = new ArrayList<Point>(); |
92 |
if (geom instanceof OrientablePrimitive) { |
93 |
OrientablePrimitive orientable = (OrientablePrimitive) geom; |
94 |
orientable.getNumVertices(); |
95 |
for (int i = 0; i < orientable.getNumVertices(); i++) { |
96 |
vertexList.add(orientable.getVertex(i)); |
97 |
} |
98 |
} |
99 |
return vertexList;
|
100 |
} |
101 |
|
102 |
public int getNumVertex(Primitive geom) { |
103 |
if (geom instanceof OrientablePrimitive) { |
104 |
OrientablePrimitive orientable = (OrientablePrimitive) geom; |
105 |
return orientable.getNumVertices();
|
106 |
} |
107 |
return 0; |
108 |
} |
109 |
|
110 |
public boolean canInsertVertex(Primitive geom, int index) { |
111 |
if (index == 0) { |
112 |
return false; |
113 |
} |
114 |
return true; |
115 |
} |
116 |
|
117 |
public boolean canRemoveVertex(Primitive geom, int index) { |
118 |
return true; |
119 |
} |
120 |
|
121 |
public boolean canMoveVertex(int index, Point point) { |
122 |
return true; |
123 |
} |
124 |
|
125 |
public void addToDrawingStatus(DefaultDrawingStatus drawingStatus, |
126 |
Primitive primitive) { |
127 |
EditingProviderManager editingProviderManager = |
128 |
EditingProviderLocator.getProviderManager(); |
129 |
ISymbol lineSymbolEditing = |
130 |
editingProviderManager.getSymbol("polygon-symbol-editing");
|
131 |
drawingStatus.addStatus(primitive, lineSymbolEditing, "");
|
132 |
} |
133 |
|
134 |
} |