Statistics
| Revision:

root / trunk / extensions / extDwg / src / com / iver / cit / gvsig / drivers / dwg / fmapconverters / FMapUtil.java @ 11063

History | View | Annotate | Download (3.81 KB)

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