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