Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libDwg / src / com / iver / cit / jdwglib / util / FMapUtil.java @ 23234

History | View | Annotate | Download (4.05 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
                GeneralPathX genPathX = new GeneralPathX();
46

    
47
                Object firstVertex = pts.get(0);
48
                double[] coordinate = null;
49
                if(firstVertex instanceof double[])
50
                        coordinate = (double[])firstVertex;
51
                else if(firstVertex instanceof DwgVertexPFace){
52
                        DwgVertexPFace v = (DwgVertexPFace)firstVertex;
53
                        coordinate = v.getPoint();
54
                }else if(firstVertex instanceof Point2D){
55
                        Point2D point = (Point2D)firstVertex;
56
                        coordinate = new double[]{point.getX(), point.getY()};
57
                }
58
                genPathX.moveTo(coordinate[0],
59
                                                coordinate[1]);
60

    
61
                //TODO ESTE LIO SE DEBE A QUE EN ALGUNOS CASOS SE GUARDAN
62
                //double[] y en otros el IDwgVertex UNIFICAR
63
                for (int i = 1; i < pts.size(); i++) {
64
                        Object vertex = pts.get(i);
65
                        double[] vertexCoordinate = null;
66
                        if(vertex instanceof double[])
67
                                vertexCoordinate = (double[])vertex;
68
                        else if(vertex instanceof DwgVertexPFace){
69
                                DwgVertexPFace v = (DwgVertexPFace)vertex;
70
                                vertexCoordinate = v.getPoint();
71
                        }else if(vertex instanceof Point2D){
72
                                Point2D point = (Point2D)vertex;
73
                                vertexCoordinate = new double[]{point.getX(), point.getY()};
74
                        }
75
                        genPathX.lineTo(vertexCoordinate[0],
76
                                                        vertexCoordinate[1]);
77
                }
78
                return genPathX;
79
        }
80

    
81

    
82
        public static Geometry ptsTo3DPolygon(List pts){
83
                GeometryFactory gFactory = GeometryManager.getInstance().getGeometryFactory();
84
                GeneralPathX genPathX = getGeneralPathX(pts);
85
                double[] elevations = new double[pts.size()];
86
                for (int i = 0; i < pts.size(); i++) {
87
//                        TODO ESTE LIO SE DEBE A QUE EN ALGUNOS CASOS SE GUARDAN
88
                        //double[] y en otros el IDwgVertex UNIFICAR
89
                        Object vertex = pts.get(i);
90
                        double[] vertexCoordinate = null;
91
                        if(vertex instanceof double[])
92
                                vertexCoordinate = (double[])vertex;
93
                        else{
94
                                DwgVertexPFace v = (DwgVertexPFace)vertex;
95
                                vertexCoordinate = v.getPoint();
96
                        }
97
                        elevations[i] = vertexCoordinate[2];
98
                }
99
                return gFactory.createPolygon3D(genPathX, elevations);
100
        }
101
//        /**
102
//         * Method that changes a Point2D array to a FPolyline2D. Is useful to
103
//         * convert a polyline given by it points to a FPolyline2D, a polyline in the
104
//         * FMap model object
105
//         *
106
//         * @param pts
107
//         *            Array of Point2D that defines the polyline that will be
108
//         *            converted in a FPolyline2D
109
//         * @return FPolyline2D This FPolyline2D is build using the array of Point2D
110
//         *         that is the argument of the method
111
//         */
112
//        public static FPolyline2D points2DToFPolyline2D(List pts) {
113
//                GeneralPathX genPathX = getGeneralPathX(pts);
114
//                return new FPolyline2D(genPathX);
115
//        }
116

    
117
        public static Geometry ptsTo2DPolygon(List pts){
118
                GeometryFactory gFactory = GeometryManager.getInstance().getGeometryFactory();
119

    
120
                GeneralPathX genPathX = getGeneralPathX(pts);
121
                return gFactory.createPolygon2D(genPathX);
122
//                return new FPolygon2D(genPathX);
123
        }
124
}