svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libDwg / src / com / iver / cit / jdwglib / util / FMapUtil.java @ 23458
History | View | Annotate | Download (4.16 KB)
1 |
/*
|
---|---|
2 |
* Created on 18-ene-2007 by azabala
|
3 |
*
|
4 |
*/
|
5 |
package com.iver.cit.jdwglib.util; |
6 |
|
7 |
import java.awt.geom.Point2D; |
8 |
import java.util.List; |
9 |
|
10 |
import org.gvsig.fmap.geom.Geometry; |
11 |
import org.gvsig.fmap.geom.GeometryFactory; |
12 |
import org.gvsig.fmap.geom.GeometryManager; |
13 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
14 |
import org.gvsig.fmap.geom.primitive.Surface; |
15 |
import org.gvsig.fmap.geom.primitive.Surface2DZ; |
16 |
|
17 |
import com.iver.cit.jdwglib.dwg.objects.DwgVertexPFace; |
18 |
|
19 |
/**
|
20 |
* @author alzabord
|
21 |
*
|
22 |
*/
|
23 |
public class FMapUtil { |
24 |
// /**
|
25 |
// * Method that changes a Point3D array to a FPolyline3D. Is useful to
|
26 |
// * convert a polyline given by it points to a FPolyline3D, a polyline 3D in
|
27 |
// * the FMap model object
|
28 |
// *
|
29 |
// * @param pts
|
30 |
// * Array of Point3D that defines the polyline 3D that will be
|
31 |
// * converted in a FPolyline3D
|
32 |
// * @return FPolyline3D This FPolyline3D is build using the array of Point3D
|
33 |
// * that is the argument of the method
|
34 |
// */
|
35 |
// public static FPolyline3D points3DToFPolyline3D(List pts) {
|
36 |
// GeneralPathX genPathX = getGeneralPathX(pts);
|
37 |
// double[] elevations = new double[pts.size()];
|
38 |
// for (int i = 0; i < pts.size(); i++) {
|
39 |
// elevations[i] = ((double[])pts.get(i))[2];
|
40 |
// }
|
41 |
// return new FPolyline3D(genPathX, elevations);
|
42 |
// }
|
43 |
|
44 |
private static GeneralPathX getGeneralPathX(List pts){ |
45 |
if(pts == null || pts.size()==0){ |
46 |
return null; |
47 |
} |
48 |
|
49 |
Object firstVertex = pts.get(0); |
50 |
|
51 |
if(firstVertex == null){ |
52 |
return null; |
53 |
} |
54 |
GeneralPathX genPathX = new GeneralPathX();
|
55 |
|
56 |
double[] coordinate = null; |
57 |
if(firstVertex instanceof double[]) |
58 |
coordinate = (double[])firstVertex; |
59 |
else if(firstVertex instanceof DwgVertexPFace){ |
60 |
DwgVertexPFace v = (DwgVertexPFace)firstVertex; |
61 |
coordinate = v.getPoint(); |
62 |
}else if(firstVertex instanceof Point2D){ |
63 |
Point2D point = (Point2D)firstVertex; |
64 |
coordinate = new double[]{point.getX(), point.getY()}; |
65 |
} |
66 |
genPathX.moveTo(coordinate[0],
|
67 |
coordinate[1]);
|
68 |
|
69 |
//TODO ESTE LIO SE DEBE A QUE EN ALGUNOS CASOS SE GUARDAN
|
70 |
//double[] y en otros el IDwgVertex UNIFICAR
|
71 |
for (int i = 1; i < pts.size(); i++) { |
72 |
Object vertex = pts.get(i);
|
73 |
double[] vertexCoordinate = null; |
74 |
if(vertex instanceof double[]) |
75 |
vertexCoordinate = (double[])vertex; |
76 |
else if(vertex instanceof DwgVertexPFace){ |
77 |
DwgVertexPFace v = (DwgVertexPFace)vertex; |
78 |
vertexCoordinate = v.getPoint(); |
79 |
}else if(vertex instanceof Point2D){ |
80 |
Point2D point = (Point2D)vertex; |
81 |
vertexCoordinate = new double[]{point.getX(), point.getY()}; |
82 |
} |
83 |
genPathX.lineTo(vertexCoordinate[0],
|
84 |
vertexCoordinate[1]);
|
85 |
} |
86 |
return genPathX;
|
87 |
} |
88 |
|
89 |
|
90 |
public static Geometry ptsTo3DPolygon(List pts){ |
91 |
GeometryFactory gFactory = GeometryManager.getInstance().getGeometryFactory(); |
92 |
GeneralPathX genPathX = getGeneralPathX(pts); |
93 |
double[] elevations = new double[pts.size()]; |
94 |
for (int i = 0; i < pts.size(); i++) { |
95 |
// TODO ESTE LIO SE DEBE A QUE EN ALGUNOS CASOS SE GUARDAN
|
96 |
//double[] y en otros el IDwgVertex UNIFICAR
|
97 |
Object vertex = pts.get(i);
|
98 |
double[] vertexCoordinate = null; |
99 |
if(vertex instanceof double[]) |
100 |
vertexCoordinate = (double[])vertex; |
101 |
else{
|
102 |
DwgVertexPFace v = (DwgVertexPFace)vertex; |
103 |
vertexCoordinate = v.getPoint(); |
104 |
} |
105 |
elevations[i] = vertexCoordinate[2];
|
106 |
} |
107 |
return gFactory.createPolygon3D(genPathX, elevations);
|
108 |
} |
109 |
// /**
|
110 |
// * Method that changes a Point2D array to a FPolyline2D. Is useful to
|
111 |
// * convert a polyline given by it points to a FPolyline2D, a polyline in the
|
112 |
// * FMap model object
|
113 |
// *
|
114 |
// * @param pts
|
115 |
// * Array of Point2D that defines the polyline that will be
|
116 |
// * converted in a FPolyline2D
|
117 |
// * @return FPolyline2D This FPolyline2D is build using the array of Point2D
|
118 |
// * that is the argument of the method
|
119 |
// */
|
120 |
// public static FPolyline2D points2DToFPolyline2D(List pts) {
|
121 |
// GeneralPathX genPathX = getGeneralPathX(pts);
|
122 |
// return new FPolyline2D(genPathX);
|
123 |
// }
|
124 |
|
125 |
public static Geometry ptsTo2DPolygon(List pts){ |
126 |
GeometryFactory gFactory = GeometryManager.getInstance().getGeometryFactory(); |
127 |
|
128 |
GeneralPathX genPathX = getGeneralPathX(pts); |
129 |
return gFactory.createPolygon2D(genPathX);
|
130 |
// return new FPolygon2D(genPathX);
|
131 |
} |
132 |
} |