Revision 10820 trunk/libraries/libDwg/src/com/iver/cit/jdwglib/util/FMapUtil.java
FMapUtil.java | ||
---|---|---|
4 | 4 |
*/ |
5 | 5 |
package com.iver.cit.jdwglib.util; |
6 | 6 |
|
7 |
import java.awt.geom.Point2D; |
|
7 | 8 |
import java.util.List; |
8 | 9 |
|
10 |
import com.iver.cit.gvsig.fmap.core.FPolygon2D; |
|
11 |
import com.iver.cit.gvsig.fmap.core.FPolygon3D; |
|
9 | 12 |
import com.iver.cit.gvsig.fmap.core.FPolyline2D; |
10 | 13 |
import com.iver.cit.gvsig.fmap.core.FPolyline3D; |
11 | 14 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
15 |
import com.iver.cit.jdwglib.dwg.objects.DwgVertexPFace; |
|
12 | 16 |
|
13 | 17 |
/** |
14 | 18 |
* @author alzabord |
... | ... | |
27 | 31 |
* that is the argument of the method |
28 | 32 |
*/ |
29 | 33 |
public static FPolyline3D points3DToFPolyline3D(List pts) { |
34 |
GeneralPathX genPathX = getGeneralPathX(pts); |
|
35 |
double[] elevations = new double[pts.size()]; |
|
36 |
for (int i = 0; i < pts.size(); i++) { |
|
37 |
elevations[i] = ((double[])pts.get(i))[2]; |
|
38 |
} |
|
39 |
return new FPolyline3D(genPathX, elevations); |
|
40 |
} |
|
41 |
|
|
42 |
private static GeneralPathX getGeneralPathX(List pts){ |
|
30 | 43 |
GeneralPathX genPathX = new GeneralPathX(); |
31 |
genPathX.moveTo(((double[])pts.get(0))[0], |
|
32 |
((double[])pts.get(0))[1]); |
|
44 |
|
|
45 |
Object firstVertex = pts.get(0); |
|
46 |
double[] coordinate = null; |
|
47 |
if(firstVertex instanceof double[]) |
|
48 |
coordinate = (double[])firstVertex; |
|
49 |
else if(firstVertex instanceof DwgVertexPFace){ |
|
50 |
DwgVertexPFace v = (DwgVertexPFace)firstVertex; |
|
51 |
coordinate = v.getPoint(); |
|
52 |
}else if(firstVertex instanceof Point2D){ |
|
53 |
Point2D point = (Point2D)firstVertex; |
|
54 |
coordinate = new double[]{point.getX(), point.getY()}; |
|
55 |
} |
|
56 |
genPathX.moveTo(coordinate[0], |
|
57 |
coordinate[1]); |
|
58 |
|
|
59 |
//TODO ESTE LIO SE DEBE A QUE EN ALGUNOS CASOS SE GUARDAN |
|
60 |
//double[] y en otros el IDwgVertex UNIFICAR |
|
33 | 61 |
for (int i = 1; i < pts.size(); i++) { |
34 |
genPathX.lineTo(((double[])pts.get(i))[0], |
|
35 |
((double[])pts.get(i))[1]); |
|
62 |
Object vertex = pts.get(i); |
|
63 |
double[] vertexCoordinate = null; |
|
64 |
if(vertex instanceof double[]) |
|
65 |
vertexCoordinate = (double[])vertex; |
|
66 |
else if(vertex instanceof DwgVertexPFace){ |
|
67 |
DwgVertexPFace v = (DwgVertexPFace)vertex; |
|
68 |
vertexCoordinate = v.getPoint(); |
|
69 |
}else if(firstVertex instanceof Point2D){ |
|
70 |
Point2D point = (Point2D)vertex; |
|
71 |
vertexCoordinate = new double[]{point.getX(), point.getY()}; |
|
72 |
} |
|
73 |
genPathX.lineTo(vertexCoordinate[0], |
|
74 |
vertexCoordinate[1]); |
|
36 | 75 |
} |
76 |
return genPathX; |
|
77 |
} |
|
78 |
|
|
79 |
public static FPolygon3D ptsTo3DPolygon(List pts){ |
|
80 |
GeneralPathX genPathX = getGeneralPathX(pts); |
|
37 | 81 |
double[] elevations = new double[pts.size()]; |
38 | 82 |
for (int i = 0; i < pts.size(); i++) { |
39 |
elevations[i] = ((double[])pts.get(i))[2]; |
|
83 |
// TODO ESTE LIO SE DEBE A QUE EN ALGUNOS CASOS SE GUARDAN |
|
84 |
//double[] y en otros el IDwgVertex UNIFICAR |
|
85 |
Object vertex = pts.get(i); |
|
86 |
double[] vertexCoordinate = null; |
|
87 |
if(vertex instanceof double[]) |
|
88 |
vertexCoordinate = (double[])vertex; |
|
89 |
else{ |
|
90 |
DwgVertexPFace v = (DwgVertexPFace)vertex; |
|
91 |
vertexCoordinate = v.getPoint(); |
|
92 |
} |
|
93 |
elevations[i] = vertexCoordinate[2]; |
|
40 | 94 |
} |
41 |
return new FPolyline3D(genPathX, elevations);
|
|
95 |
return new FPolygon3D(genPathX, elevations);
|
|
42 | 96 |
} |
43 | 97 |
/** |
44 | 98 |
* Method that changes a Point2D array to a FPolyline2D. Is useful to |
... | ... | |
52 | 106 |
* that is the argument of the method |
53 | 107 |
*/ |
54 | 108 |
public static FPolyline2D points2DToFPolyline2D(List pts) { |
55 |
GeneralPathX genPathX = new GeneralPathX(); |
|
56 |
genPathX.moveTo(((double[])pts.get(0))[0], ((double[])pts.get(0))[1]); |
|
57 |
for (int i = 1; i < pts.size(); i++) { |
|
58 |
genPathX.lineTo(((double[])pts.get(i))[0], |
|
59 |
((double[])pts.get(i))[1]); |
|
60 |
} |
|
109 |
GeneralPathX genPathX = getGeneralPathX(pts); |
|
61 | 110 |
return new FPolyline2D(genPathX); |
62 | 111 |
} |
112 |
|
|
113 |
public static FPolygon2D ptsTo2DPolygon(List pts){ |
|
114 |
GeneralPathX genPathX = getGeneralPathX(pts); |
|
115 |
return new FPolygon2D(genPathX); |
|
116 |
} |
|
63 | 117 |
} |
Also available in: Unified diff