root / trunk / libraries / libDwg / src / com / iver / cit / jdwglib / util / FMapUtil.java @ 10820
History | View | Annotate | Download (3.76 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 com.iver.cit.gvsig.fmap.core.FPolygon2D; |
11 |
import com.iver.cit.gvsig.fmap.core.FPolygon3D; |
12 |
import com.iver.cit.gvsig.fmap.core.FPolyline2D; |
13 |
import com.iver.cit.gvsig.fmap.core.FPolyline3D; |
14 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
15 |
import com.iver.cit.jdwglib.dwg.objects.DwgVertexPFace; |
16 |
|
17 |
/**
|
18 |
* @author alzabord
|
19 |
*
|
20 |
*/
|
21 |
public class FMapUtil { |
22 |
/**
|
23 |
* Method that changes a Point3D array to a FPolyline3D. Is useful to
|
24 |
* convert a polyline given by it points to a FPolyline3D, a polyline 3D in
|
25 |
* the FMap model object
|
26 |
*
|
27 |
* @param pts
|
28 |
* Array of Point3D that defines the polyline 3D that will be
|
29 |
* converted in a FPolyline3D
|
30 |
* @return FPolyline3D This FPolyline3D is build using the array of Point3D
|
31 |
* that is the argument of the method
|
32 |
*/
|
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){ |
43 |
GeneralPathX genPathX = new GeneralPathX();
|
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
|
61 |
for (int i = 1; i < pts.size(); i++) { |
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]);
|
75 |
} |
76 |
return genPathX;
|
77 |
} |
78 |
|
79 |
public static FPolygon3D ptsTo3DPolygon(List pts){ |
80 |
GeneralPathX genPathX = getGeneralPathX(pts); |
81 |
double[] elevations = new double[pts.size()]; |
82 |
for (int i = 0; i < pts.size(); i++) { |
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];
|
94 |
} |
95 |
return new FPolygon3D(genPathX, elevations); |
96 |
} |
97 |
/**
|
98 |
* Method that changes a Point2D array to a FPolyline2D. Is useful to
|
99 |
* convert a polyline given by it points to a FPolyline2D, a polyline in the
|
100 |
* FMap model object
|
101 |
*
|
102 |
* @param pts
|
103 |
* Array of Point2D that defines the polyline that will be
|
104 |
* converted in a FPolyline2D
|
105 |
* @return FPolyline2D This FPolyline2D is build using the array of Point2D
|
106 |
* that is the argument of the method
|
107 |
*/
|
108 |
public static FPolyline2D points2DToFPolyline2D(List pts) { |
109 |
GeneralPathX genPathX = getGeneralPathX(pts); |
110 |
return new FPolyline2D(genPathX); |
111 |
} |
112 |
|
113 |
public static FPolygon2D ptsTo2DPolygon(List pts){ |
114 |
GeneralPathX genPathX = getGeneralPathX(pts); |
115 |
return new FPolygon2D(genPathX); |
116 |
} |
117 |
} |