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 / EditVertexOperationUtils.java @ 575
History | View | Annotate | Download (3.12 KB)
1 |
package org.gvsig.vectorediting.lib.prov.editvertex.operation; |
---|---|
2 |
|
3 |
|
4 |
import java.util.HashMap; |
5 |
import java.util.Map; |
6 |
|
7 |
import org.slf4j.Logger; |
8 |
import org.slf4j.LoggerFactory; |
9 |
|
10 |
import org.gvsig.fmap.geom.Geometry; |
11 |
import org.gvsig.fmap.geom.primitive.Arc; |
12 |
import org.gvsig.fmap.geom.primitive.Circle; |
13 |
import org.gvsig.fmap.geom.primitive.Circumference; |
14 |
import org.gvsig.fmap.geom.primitive.Curve; |
15 |
import org.gvsig.fmap.geom.primitive.Ellipse; |
16 |
import org.gvsig.fmap.geom.primitive.EllipticArc; |
17 |
import org.gvsig.fmap.geom.primitive.FilledSpline; |
18 |
import org.gvsig.fmap.geom.primitive.OrientablePrimitive; |
19 |
import org.gvsig.fmap.geom.primitive.PeriEllipse; |
20 |
import org.gvsig.fmap.geom.primitive.Point; |
21 |
import org.gvsig.fmap.geom.primitive.Primitive; |
22 |
import org.gvsig.fmap.geom.primitive.Spline; |
23 |
import org.gvsig.fmap.geom.primitive.Surface; |
24 |
|
25 |
|
26 |
public class EditVertexOperationUtils { |
27 |
|
28 |
private static Logger logger = LoggerFactory.getLogger(EditVertexOperationUtils.class); |
29 |
|
30 |
private static Map<Integer, EditVertexOperation> operations = new HashMap<Integer, EditVertexOperation>(); |
31 |
|
32 |
private EditVertexOperationUtils() {
|
33 |
} |
34 |
|
35 |
public static void register(EditVertexOperation operation, int geometryType){ |
36 |
operations.put(geometryType, operation); |
37 |
} |
38 |
|
39 |
public static EditVertexOperation getOperation(Primitive geom) { |
40 |
Integer type = geom.getGeometryType().getType();
|
41 |
|
42 |
if(isPolygon(geom)){
|
43 |
type = Geometry.TYPES.POLYGON; |
44 |
} else if(isLine(geom)){ |
45 |
type = Geometry.TYPES.LINE; |
46 |
} |
47 |
EditVertexOperation operation = operations.get(type); |
48 |
|
49 |
return operation;
|
50 |
} |
51 |
|
52 |
private static boolean isPolygon(Geometry geometry) { |
53 |
|
54 |
if(!(geometry instanceof Surface)){ |
55 |
return false; |
56 |
} |
57 |
if(!isLineOrPolygon(geometry)){
|
58 |
return false; |
59 |
}; |
60 |
return true; |
61 |
} |
62 |
|
63 |
private static boolean isLine(Geometry geometry) { |
64 |
|
65 |
if(!(geometry instanceof Curve)){ |
66 |
return false; |
67 |
} |
68 |
if(!isLineOrPolygon(geometry)){
|
69 |
return false; |
70 |
}; |
71 |
return true; |
72 |
} |
73 |
|
74 |
private static boolean isLineOrPolygon(Geometry geometry) { |
75 |
if (geometry instanceof Ellipse) { |
76 |
return false; |
77 |
} |
78 |
if (geometry instanceof EllipticArc) { |
79 |
return false; |
80 |
} |
81 |
if (geometry instanceof Circle) { |
82 |
return false; |
83 |
} |
84 |
if (geometry instanceof FilledSpline) { |
85 |
return false; |
86 |
} |
87 |
if (geometry instanceof Arc) { |
88 |
return false; |
89 |
} |
90 |
if (geometry instanceof Spline) { |
91 |
return false; |
92 |
} |
93 |
if (geometry instanceof Circumference) { |
94 |
return false; |
95 |
} |
96 |
if (geometry instanceof PeriEllipse) { |
97 |
return false; |
98 |
} |
99 |
return true; |
100 |
} |
101 |
|
102 |
public static void setVertex(OrientablePrimitive geom, int index, Point p) { |
103 |
Point point = geom.getVertex(index);
|
104 |
int min = p.getDimension() < point.getDimension()?p.getDimension():point.getDimension();
|
105 |
for(int i=0; i<min; i++){ |
106 |
point.setCoordinateAt(i, p.getCoordinateAt(i)); |
107 |
} |
108 |
} |
109 |
|
110 |
} |