root / trunk / extensions / extDwg / src / com / iver / cit / gvsig / drivers / dwg / fmapconverters / FMapUtil.java @ 11060
History | View | Annotate | Download (3.92 KB)
1 | 11060 | azabala | /*
|
---|---|---|---|
2 | * Created on 18-ene-2007 by azabala
|
||
3 | *
|
||
4 | */
|
||
5 | package com.iver.cit.gvsig.drivers.dwg.fmapconverters; |
||
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 | private static FMapUtil _instance = new FMapUtil(); |
||
24 | |||
25 | public static FMapUtil getInstance(){ |
||
26 | return _instance;
|
||
27 | } |
||
28 | |||
29 | private FMapUtil(){};
|
||
30 | /**
|
||
31 | * Method that changes a Point3D array to a FPolyline3D. Is useful to
|
||
32 | * convert a polyline given by it points to a FPolyline3D, a polyline 3D in
|
||
33 | * the FMap model object
|
||
34 | *
|
||
35 | * @param pts
|
||
36 | * Array of Point3D that defines the polyline 3D that will be
|
||
37 | * converted in a FPolyline3D
|
||
38 | * @return FPolyline3D This FPolyline3D is build using the array of Point3D
|
||
39 | * that is the argument of the method
|
||
40 | */
|
||
41 | public static FPolyline3D points3DToFPolyline3D(List pts) { |
||
42 | GeneralPathX genPathX = getGeneralPathX(pts); |
||
43 | double[] elevations = new double[pts.size()]; |
||
44 | for (int i = 0; i < pts.size(); i++) { |
||
45 | elevations[i] = ((double[])pts.get(i))[2]; |
||
46 | } |
||
47 | return new FPolyline3D(genPathX, elevations); |
||
48 | } |
||
49 | |||
50 | private static GeneralPathX getGeneralPathX(List pts){ |
||
51 | GeneralPathX genPathX = new GeneralPathX();
|
||
52 | |||
53 | Object firstVertex = pts.get(0); |
||
54 | double[] coordinate = null; |
||
55 | if(firstVertex instanceof double[]) |
||
56 | coordinate = (double[])firstVertex; |
||
57 | else if(firstVertex instanceof DwgVertexPFace){ |
||
58 | DwgVertexPFace v = (DwgVertexPFace)firstVertex; |
||
59 | coordinate = v.getPoint(); |
||
60 | }else if(firstVertex instanceof Point2D){ |
||
61 | Point2D point = (Point2D)firstVertex; |
||
62 | coordinate = new double[]{point.getX(), point.getY()}; |
||
63 | } |
||
64 | genPathX.moveTo(coordinate[0],
|
||
65 | coordinate[1]);
|
||
66 | |||
67 | //TODO ESTE LIO SE DEBE A QUE EN ALGUNOS CASOS SE GUARDAN
|
||
68 | //double[] y en otros el IDwgVertex UNIFICAR
|
||
69 | for (int i = 1; i < pts.size(); i++) { |
||
70 | Object vertex = pts.get(i);
|
||
71 | double[] vertexCoordinate = null; |
||
72 | if(vertex instanceof double[]) |
||
73 | vertexCoordinate = (double[])vertex; |
||
74 | else if(vertex instanceof DwgVertexPFace){ |
||
75 | DwgVertexPFace v = (DwgVertexPFace)vertex; |
||
76 | vertexCoordinate = v.getPoint(); |
||
77 | }else if(firstVertex instanceof Point2D){ |
||
78 | Point2D point = (Point2D)vertex; |
||
79 | vertexCoordinate = new double[]{point.getX(), point.getY()}; |
||
80 | } |
||
81 | genPathX.lineTo(vertexCoordinate[0],
|
||
82 | vertexCoordinate[1]);
|
||
83 | } |
||
84 | return genPathX;
|
||
85 | } |
||
86 | |||
87 | public static FPolygon3D ptsTo3DPolygon(List pts){ |
||
88 | GeneralPathX genPathX = getGeneralPathX(pts); |
||
89 | double[] elevations = new double[pts.size()]; |
||
90 | for (int i = 0; i < pts.size(); i++) { |
||
91 | // TODO ESTE LIO SE DEBE A QUE EN ALGUNOS CASOS SE GUARDAN
|
||
92 | //double[] y en otros el IDwgVertex UNIFICAR
|
||
93 | Object vertex = pts.get(i);
|
||
94 | double[] vertexCoordinate = null; |
||
95 | if(vertex instanceof double[]) |
||
96 | vertexCoordinate = (double[])vertex; |
||
97 | else{
|
||
98 | DwgVertexPFace v = (DwgVertexPFace)vertex; |
||
99 | vertexCoordinate = v.getPoint(); |
||
100 | } |
||
101 | elevations[i] = vertexCoordinate[2];
|
||
102 | } |
||
103 | return new FPolygon3D(genPathX, elevations); |
||
104 | } |
||
105 | /**
|
||
106 | * Method that changes a Point2D array to a FPolyline2D. Is useful to
|
||
107 | * convert a polyline given by it points to a FPolyline2D, a polyline in the
|
||
108 | * FMap model object
|
||
109 | *
|
||
110 | * @param pts
|
||
111 | * Array of Point2D that defines the polyline that will be
|
||
112 | * converted in a FPolyline2D
|
||
113 | * @return FPolyline2D This FPolyline2D is build using the array of Point2D
|
||
114 | * that is the argument of the method
|
||
115 | */
|
||
116 | public static FPolyline2D points2DToFPolyline2D(List pts) { |
||
117 | GeneralPathX genPathX = getGeneralPathX(pts); |
||
118 | return new FPolyline2D(genPathX); |
||
119 | } |
||
120 | |||
121 | public static FPolygon2D ptsTo2DPolygon(List pts){ |
||
122 | GeneralPathX genPathX = getGeneralPathX(pts); |
||
123 | return new FPolygon2D(genPathX); |
||
124 | } |
||
125 | } |