Revision 11060

View differences:

trunk/extensions/extDwg/src/com/iver/cit/gvsig/drivers/dwg/fmapconverters/DwgPoint2FMapConverter.java
1
/*
2
 * Created on 02/04/2007
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
21
 *
22
 * For more information, contact:
23
 *
24
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib??ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33
 *
34
 *    or
35
 *
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 *
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
/* CVS MESSAGES:
45
*
46
* $Id$
47
* $Log$
48
* Revision 1.1  2007-04-04 17:48:53  azabala
49
* first version in cvs after libDwg<->libFMap disacopling
50
*
51
*
52
*/
53
package com.iver.cit.gvsig.drivers.dwg.fmapconverters;
54

  
55
import com.iver.cit.gvsig.fmap.core.FPoint2D;
56
import com.iver.cit.gvsig.fmap.core.FPoint3D;
57
import com.iver.cit.gvsig.fmap.core.IGeometry;
58
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
59
import com.iver.cit.jdwglib.dwg.DwgObject;
60
import com.iver.cit.jdwglib.dwg.objects.DwgPoint;
61

  
62
public class DwgPoint2FMapConverter implements IDwg2FMap {
63

  
64
	public IGeometry toFMapGeometry(DwgObject entity, boolean is3DFile) {
65
		DwgPoint dwpoint = (DwgPoint)entity;
66
		FPoint2D point = null;
67
		double[] p = dwpoint.getPoint();
68
		if (is3DFile) {
69
			point = new FPoint3D(p[0], p[1], p[2]);
70
		
71
		} else {
72
			point = new FPoint2D(p[0], p[1]);
73
		}
74
		return ShapeFactory.createGeometry(point);
75
	}
76
	
77
	public String toFMapString(boolean is3DFile) {
78
		if(is3DFile)
79
			return "FPoint3D";
80
		else
81
			return "FPoint2D";
82
	}
83

  
84
}
85

  
0 86

  
trunk/extensions/extDwg/src/com/iver/cit/gvsig/drivers/dwg/fmapconverters/DwgLwPline2FMapConverter.java
1
/*
2
 * Created on 02/04/2007
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
21
 *
22
 * For more information, contact:
23
 *
24
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib??ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33
 *
34
 *    or
35
 *
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 *
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
/* CVS MESSAGES:
45
*
46
* $Id$
47
* $Log$
48
* Revision 1.1  2007-04-04 17:48:53  azabala
49
* first version in cvs after libDwg<->libFMap disacopling
50
*
51
*
52
*/
53
package com.iver.cit.gvsig.drivers.dwg.fmapconverters;
54

  
55
import java.awt.geom.Point2D;
56
import java.util.ArrayList;
57
import java.util.List;
58

  
59
import com.iver.cit.gvsig.fmap.core.FPolyline2D;
60
import com.iver.cit.gvsig.fmap.core.IGeometry;
61
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
62
import com.iver.cit.jdwglib.dwg.DwgObject;
63
import com.iver.cit.jdwglib.dwg.objects.DwgLwPolyline;
64

  
65
public class DwgLwPline2FMapConverter implements IDwg2FMap {
66

  
67
	public IGeometry toFMapGeometry(DwgObject entity, boolean is3DFile) {
68
		DwgLwPolyline pline = (DwgLwPolyline)entity;
69
		FPolyline2D lwpline = null;
70
		List pts = pline.getVertices();
71
		double elev = pline.getElevation();
72
		if (pts != null && pts.size() > 0) {
73
			
74
			if (is3DFile) {
75
				List pline3D = new ArrayList();
76
				for (int j = 0; j < pts.size(); j++) {
77
					Object vertex = pts.get(j);
78
					double[] pt = new double[3];
79
					if(vertex instanceof double[]){
80
						double[] vertexArray = (double[])vertex;
81
						pt[0] = vertexArray[0];
82
						pt[1] = vertexArray[1];
83
					}else if(vertex instanceof Point2D){
84
						Point2D vertexPt = (Point2D)vertex;
85
						pt[0] = vertexPt.getX();
86
						pt[1] = vertexPt.getY();
87
					}
88
					pt[2] = elev;
89
					pline3D.add(pt);
90
				}
91
				lwpline = FMapUtil.points3DToFPolyline3D(pline3D);
92
			} else {
93
				lwpline = FMapUtil.points2DToFPolyline2D(pts);
94
			}
95
			return ShapeFactory.createGeometry(lwpline);
96
		}
97
		return null;
98
		
99
	}
100
	public String toFMapString(boolean is3DFile) {
101
		if(is3DFile)
102
			return "FPolyline3D";
103
		else
104
			return "FPolyline2D";
105
	}
106

  
107
}
108

  
0 109

  
trunk/extensions/extDwg/src/com/iver/cit/gvsig/drivers/dwg/fmapconverters/DwgSolid2FMapConverter.java
1
/*
2
 * Created on 02/04/2007
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
21
 *
22
 * For more information, contact:
23
 *
24
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib??ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33
 *
34
 *    or
35
 *
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 *
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
/* CVS MESSAGES:
45
*
46
* $Id$
47
* $Log$
48
* Revision 1.1  2007-04-04 17:48:53  azabala
49
* first version in cvs after libDwg<->libFMap disacopling
50
*
51
*
52
*/
53
package com.iver.cit.gvsig.drivers.dwg.fmapconverters;
54

  
55
import java.util.ArrayList;
56
import java.util.List;
57

  
58
import com.iver.cit.gvsig.fmap.core.FPolyline2D;
59
import com.iver.cit.gvsig.fmap.core.IGeometry;
60
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
61
import com.iver.cit.jdwglib.dwg.DwgObject;
62
import com.iver.cit.jdwglib.dwg.objects.DwgSolid;
63

  
64
public class DwgSolid2FMapConverter implements IDwg2FMap {
65

  
66
	public IGeometry toFMapGeometry(DwgObject entity, boolean is3DFile) {
67
		DwgSolid dwsolid = (DwgSolid)entity;
68
		FPolyline2D solid = null;
69
		double[] p1 = dwsolid.getCorner1();
70
		double[] p2 = dwsolid.getCorner2();
71
		double[] p3 = dwsolid.getCorner3();
72
		double[] p4 = dwsolid.getCorner4();
73
		double elev = dwsolid.getElevation();
74
		List pts = new ArrayList();
75
		
76
		if (is3DFile) {
77
			double[] p13d = new double[]{p1[0], p1[1], elev};
78
			double[] p23d = new double[]{p2[0], p2[1], elev};
79
			double[] p33d = new double[]{p3[0], p3[1], elev};
80
			double[] p43d = new double[]{p4[0], p4[1], elev};
81
			pts.add(p13d);
82
			pts.add(p23d);
83
			pts.add(p33d);
84
			pts.add(p43d);
85

  
86
			solid = FMapUtil.ptsTo3DPolygon(pts);
87
			
88
			
89
		} else {
90
			pts.add(p1);
91
			pts.add(p2);
92
			pts.add(p3);
93
			pts.add(p4);
94
			solid = FMapUtil.ptsTo2DPolygon(pts);
95
		}
96
		return ShapeFactory.createGeometry(solid);
97
		
98
	}
99
	public String toFMapString(boolean is3DFile) {
100
		if(is3DFile){
101
			return "FPolyline3D";
102
		}else{
103
			return "FPolyline2D";
104
		}
105
	}
106

  
107
}
108

  
0 109

  
trunk/extensions/extDwg/src/com/iver/cit/gvsig/drivers/dwg/fmapconverters/DwgEllipse2FMapConverter.java
1
/*
2
 * Created on 02/04/2007
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
21
 *
22
 * For more information, contact:
23
 *
24
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib??ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33
 *
34
 *    or
35
 *
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 *
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
/* CVS MESSAGES:
45
*
46
* $Id$
47
* $Log$
48
* Revision 1.1  2007-04-04 17:48:53  azabala
49
* first version in cvs after libDwg<->libFMap disacopling
50
*
51
*
52
*/
53
package com.iver.cit.gvsig.drivers.dwg.fmapconverters;
54

  
55
import java.awt.geom.Point2D;
56
import java.util.ArrayList;
57
import java.util.List;
58

  
59
import com.iver.cit.gvsig.fmap.core.FPolyline2D;
60
import com.iver.cit.gvsig.fmap.core.IGeometry;
61
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
62
import com.iver.cit.jdwglib.dwg.DwgObject;
63
import com.iver.cit.jdwglib.dwg.objects.DwgEllipse;
64
import com.iver.cit.jdwglib.util.GisModelCurveCalculator;
65

  
66
public class DwgEllipse2FMapConverter implements IDwg2FMap {
67

  
68
	/* (non-Javadoc)
69
	 * @see com.iver.cit.jdwglib.dwg.IDwg2FMap#toFMapGeometry(boolean)
70
	 */
71
	public IGeometry toFMapGeometry(DwgObject entity, boolean is3DFile) {
72
		DwgEllipse ellipse = (DwgEllipse)entity;
73
		FPolyline2D arcc;
74
		double[] c = ellipse.getCenter();
75
		Point2D center = new Point2D.Double(c[0], c[1]);
76
		double[] majorAxisVector = ellipse.getMajorAxisVector();
77
		Point2D mav = new Point2D.Double(majorAxisVector[0],
78
				majorAxisVector[1]);
79
		double axisRatio = ellipse.getAxisRatio();
80
		double initAngle = Math.toDegrees(ellipse.getInitAngle());
81
		double endAngle = Math.toDegrees(ellipse.getEndAngle());
82
		List arc = GisModelCurveCalculator
83
				.calculateGisModelEllipse(center, mav, axisRatio,
84
						initAngle, endAngle);
85
		if (is3DFile) {
86
			List arc3D = new ArrayList();
87
			for (int j = 0; j < arc.size(); j++) {
88
				double[] pt = (double[]) arc.get(j);
89
				double[] newPt = new double[]{ pt[0], pt[1], c[2]} ;
90
				arc3D.add(newPt);
91
			}
92
			arcc = FMapUtil.points3DToFPolyline3D(arc3D);
93
		} else {
94
			arcc = FMapUtil.points2DToFPolyline2D(arc);
95
		}
96
		return ShapeFactory.createGeometry(arcc);
97
	}
98
	
99
	/* (non-Javadoc)
100
	 * @see com.iver.cit.jdwglib.dwg.IDwg2FMap#toFMapString(boolean)
101
	 */
102
	public String toFMapString(boolean is3DFile) {
103
		if(is3DFile)
104
			return "FPolyline3D";
105
		else
106
			return "FPolyline2D";
107
	}
108

  
109
}
110

  
0 111

  
trunk/extensions/extDwg/src/com/iver/cit/gvsig/drivers/dwg/fmapconverters/IDwg2FMap.java
1
/*
2
 * Created on 09-ene-2007
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
21
 *
22
 * For more information, contact:
23
 *
24
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib??ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33
 *
34
 *    or
35
 *
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 *
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44

  
45
/* CVS MESSAGES:
46
*
47
* $Id$
48
* $Log$
49
* Revision 1.1  2007-04-04 17:48:53  azabala
50
* first version in cvs after libDwg<->libFMap disacopling
51
*
52
* Revision 1.3  2007/03/20 19:55:27  azabala
53
* source code cleaning
54
*
55
* Revision 1.2  2007/01/18 13:35:22  azabala
56
* Refactoring general para evitar dar tantas pasadas en la carga, y para incrementar
57
* la legibilidad del codigo (demasiados if-else-if en vez de usar polimorfismo)
58
*
59
* Revision 1.1  2007/01/12 19:29:58  azabala
60
* first version in cvs
61
*
62
*
63
*/
64
package com.iver.cit.gvsig.drivers.dwg.fmapconverters;
65

  
66
import com.iver.cit.gvsig.fmap.core.IGeometry;
67
import com.iver.cit.jdwglib.dwg.DwgObject;
68

  
69
/**
70
 * All dwg objects that are drawing entities
71
 * and that can be converted to a fmap geometry
72
 * implements this interface.
73
 * 
74
 * */
75
/*
76
 * TODO
77
 * Esta solucion tiene el problema de que es mas simple
78
 * (cada entidad dwg se ocupa de su conversion a fmap),pero acopla
79
 * libDwg con fmap 
80
 * (una clase Dwg2FMap lo desacoplar?a, pero llenar?a el codigo de
81
 * infinitos if(dwg instanceof ...) else if.....
82
 * 
83
 * */
84
public interface IDwg2FMap {
85
	public IGeometry toFMapGeometry(DwgObject entity, boolean is3DFile);
86
	public String toFMapString(boolean is3DFile);
87
	public String toString();
88
}
89

  
0 90

  
trunk/extensions/extDwg/src/com/iver/cit/gvsig/drivers/dwg/fmapconverters/DwgCircle2FMapConverter.java
1
/*
2
 * Created on 02/04/2007
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
21
 *
22
 * For more information, contact:
23
 *
24
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib??ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33
 *
34
 *    or
35
 *
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 *
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
/* CVS MESSAGES:
45
*
46
* $Id$
47
* $Log$
48
* Revision 1.1  2007-04-04 17:48:53  azabala
49
* first version in cvs after libDwg<->libFMap disacopling
50
*
51
*
52
*/
53
package com.iver.cit.gvsig.drivers.dwg.fmapconverters;
54

  
55
import java.awt.geom.Point2D;
56
import java.util.ArrayList;
57
import java.util.List;
58

  
59
import com.iver.cit.gvsig.fmap.core.FPolyline2D;
60
import com.iver.cit.gvsig.fmap.core.IGeometry;
61
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
62
import com.iver.cit.jdwglib.dwg.DwgObject;
63
import com.iver.cit.jdwglib.dwg.objects.DwgCircle;
64
import com.iver.cit.jdwglib.util.GisModelCurveCalculator;
65

  
66
public class DwgCircle2FMapConverter implements IDwg2FMap {
67

  
68
	/* (non-Javadoc)
69
	 * @see com.iver.cit.jdwglib.dwg.IDwg2FMap#toFMapGeometry(boolean)
70
	 */
71
	public IGeometry toFMapGeometry(DwgObject entity, boolean is3DFile) {
72
		DwgCircle circle = (DwgCircle)entity;
73
		FPolyline2D arcc;
74
		double[] c = circle.getCenter();
75
		Point2D center = new Point2D.Double(c[0], c[1]);
76
		double radius = circle.getRadius();
77
		List arc = GisModelCurveCalculator
78
				.calculateGisModelCircle(center, radius);
79
		if (is3DFile) {
80
			List arc3D = new ArrayList();
81
			for (int j = 0; j < arc.size(); j++) {
82
				double[] pt2d = (double[]) arc.get(j);
83
				double[] pt3d = new double[]{ pt2d[0], pt2d[1], c[2] };
84
				arc3D.add(pt3d);
85
			}
86
			arcc = FMapUtil.points3DToFPolyline3D(arc3D);
87
		} else {
88
			arcc = FMapUtil.points2DToFPolyline2D(arc);
89
		}
90
		
91
		return ShapeFactory.createGeometry(arcc);
92
	}
93
	/* (non-Javadoc)
94
	 * @see com.iver.cit.jdwglib.dwg.IDwg2FMap#toFMapString(boolean)
95
	 */
96
	public String toFMapString(boolean is3DFile) {
97
		if(is3DFile)
98
			return "FPolyline3D";
99
		else
100
			return "FPolyline2D";
101
	}
102

  
103
}
104

  
0 105

  
trunk/extensions/extDwg/src/com/iver/cit/gvsig/drivers/dwg/fmapconverters/DwgMText2FMapConverter.java
1
/*
2
 * Created on 02/04/2007
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
21
 *
22
 * For more information, contact:
23
 *
24
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib??ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33
 *
34
 *    or
35
 *
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 *
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
/* CVS MESSAGES:
45
*
46
* $Id$
47
* $Log$
48
* Revision 1.1  2007-04-04 17:48:53  azabala
49
* first version in cvs after libDwg<->libFMap disacopling
50
*
51
*
52
*/
53
package com.iver.cit.gvsig.drivers.dwg.fmapconverters;
54

  
55
import com.iver.cit.gvsig.fmap.core.FPoint2D;
56
import com.iver.cit.gvsig.fmap.core.FPoint3D;
57
import com.iver.cit.gvsig.fmap.core.IGeometry;
58
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
59
import com.iver.cit.jdwglib.dwg.DwgObject;
60
import com.iver.cit.jdwglib.dwg.objects.DwgMText;
61

  
62
public class DwgMText2FMapConverter implements IDwg2FMap {
63

  
64
	public IGeometry toFMapGeometry(DwgObject entity, boolean is3DFile) {
65
		DwgMText mtext = (DwgMText)entity;
66
		FPoint2D fPoint = null;
67
		double[] p = mtext.getInsertionPoint();
68
		if (is3DFile) {
69
			fPoint = new FPoint3D(p[0], p[1], p[2]);
70
		} else {
71
			fPoint = new FPoint2D(p[0], p[1]);
72
		}
73
		return ShapeFactory.createGeometry(fPoint);
74
	}
75
	
76
	public String toFMapString(boolean is3DFile) {
77
		if(is3DFile)
78
			return "FPoint3D";
79
		else
80
			return "FPoint2D";
81
	}
82

  
83
}
84

  
0 85

  
trunk/extensions/extDwg/src/com/iver/cit/gvsig/drivers/dwg/fmapconverters/DwgPolyline2D2FMapConverter.java
1
/*
2
 * Created on 02/04/2007
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
21
 *
22
 * For more information, contact:
23
 *
24
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib??ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33
 *
34
 *    or
35
 *
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 *
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
/* CVS MESSAGES:
45
*
46
* $Id$
47
* $Log$
48
* Revision 1.1  2007-04-04 17:48:53  azabala
49
* first version in cvs after libDwg<->libFMap disacopling
50
*
51
*
52
*/
53
package com.iver.cit.gvsig.drivers.dwg.fmapconverters;
54

  
55
import java.util.ArrayList;
56
import java.util.List;
57

  
58
import com.iver.cit.gvsig.fmap.core.FPolyline2D;
59
import com.iver.cit.gvsig.fmap.core.IGeometry;
60
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
61
import com.iver.cit.jdwglib.dwg.DwgObject;
62
import com.iver.cit.jdwglib.dwg.objects.DwgPolyline2D;
63

  
64
public class DwgPolyline2D2FMapConverter implements IDwg2FMap {
65

  
66
	/* (non-Javadoc)
67
	 * @see com.iver.cit.jdwglib.dwg.IDwg2FMap#toFMapGeometry(boolean)
68
	 */
69
	public IGeometry toFMapGeometry(DwgObject entity, boolean is3DFile) {
70
		DwgPolyline2D pline2d = (DwgPolyline2D)entity;
71
		FPolyline2D pline = null;
72
		List points = pline2d.getPts();
73
		double elev = pline2d.getElevation();
74
		
75
		if (points != null && points.size() > 0) {
76
			if (is3DFile) {
77
				List pline3D = new ArrayList();
78
				for (int j = 0; j < points.size(); j++) {
79
					double[] point = new double[3];
80
					List vertices = pline2d.getPts();
81
					point[0] = ((double[])vertices.get(j))[0];
82
					point[1] = ((double[])vertices.get(j))[1];
83
					point[2] = elev;
84
					pline3D.add(point);
85
				}
86
				pline = FMapUtil.points3DToFPolyline3D(pline3D);
87
			} else {
88
				pline = FMapUtil.points2DToFPolyline2D(points);
89
			}
90
			return ShapeFactory.createGeometry(pline);
91
		}
92
		return null;
93
	}
94
	/* (non-Javadoc)
95
	 * @see com.iver.cit.jdwglib.dwg.IDwg2FMap#toFMapString(boolean)
96
	 */
97
	public String toFMapString(boolean is3DFile) {
98
		if(is3DFile)
99
			return "FPolyline3D";
100
		else
101
			return "FPolyline2D";
102
	}
103

  
104
}
105

  
0 106

  
trunk/extensions/extDwg/src/com/iver/cit/gvsig/drivers/dwg/fmapconverters/FMapUtil.java
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
	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
}
0 126

  
trunk/extensions/extDwg/src/com/iver/cit/gvsig/drivers/dwg/fmapconverters/DwgPolyline3D2FMapConverter.java
1
/*
2
 * Created on 02/04/2007
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
21
 *
22
 * For more information, contact:
23
 *
24
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib??ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33
 *
34
 *    or
35
 *
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 *
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
/* CVS MESSAGES:
45
*
46
* $Id$
47
* $Log$
48
* Revision 1.1  2007-04-04 17:48:53  azabala
49
* first version in cvs after libDwg<->libFMap disacopling
50
*
51
*
52
*/
53
package com.iver.cit.gvsig.drivers.dwg.fmapconverters;
54

  
55
import java.util.ArrayList;
56
import java.util.List;
57

  
58
import com.iver.cit.gvsig.fmap.core.FPolyline2D;
59
import com.iver.cit.gvsig.fmap.core.IGeometry;
60
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
61
import com.iver.cit.jdwglib.dwg.DwgObject;
62
import com.iver.cit.jdwglib.dwg.objects.DwgPolyline3D;
63

  
64
public class DwgPolyline3D2FMapConverter implements IDwg2FMap {
65

  
66
	/* (non-Javadoc)
67
	 * @see com.iver.cit.jdwglib.dwg.IDwg2FMap#toFMapGeometry(boolean)
68
	 */
69
	public IGeometry toFMapGeometry(DwgObject entity, boolean is3DFile) {
70
		DwgPolyline3D pline3d = (DwgPolyline3D)entity;
71
		FPolyline2D pline = null;
72
		List points3D = pline3d.getPts();
73
		if (points3D != null && points3D.size() > 0) {
74
			if (is3DFile) {
75
				pline = FMapUtil.points3DToFPolyline3D(points3D);
76
			} else {
77
				List points2D = new ArrayList();
78
				for (int j = 0; j < points3D.size(); j++) {
79
					double[] pt3d = (double[]) points3D.get(j);
80
					double[] pt  = new double[]{pt3d[0],
81
							pt3d[1]};
82
					points2D.add(pt);
83
				}
84
				pline = FMapUtil.points2DToFPolyline2D(points2D);
85
			}//if
86
			return  ShapeFactory.createGeometry(pline);
87
		}//if
88
		return null;
89
	
90
	}
91
	/* (non-Javadoc)
92
	 * @see com.iver.cit.jdwglib.dwg.IDwg2FMap#toFMapString(boolean)
93
	 */
94
	public String toFMapString(boolean is3DFile) {
95
		if(is3DFile)
96
			return "FPolyline3D";
97
		else
98
			return "FPolyline2D";
99
	}
100

  
101
}
102

  
0 103

  
trunk/extensions/extDwg/src/com/iver/cit/gvsig/drivers/dwg/fmapconverters/DwgText2FMapConverter.java
1
/*
2
 * Created on 02/04/2007
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
21
 *
22
 * For more information, contact:
23
 *
24
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib??ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33
 *
34
 *    or
35
 *
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 *
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
/* CVS MESSAGES:
45
*
46
* $Id$
47
* $Log$
48
* Revision 1.1  2007-04-04 17:48:53  azabala
49
* first version in cvs after libDwg<->libFMap disacopling
50
*
51
*
52
*/
53
package com.iver.cit.gvsig.drivers.dwg.fmapconverters;
54

  
55
import java.awt.geom.Point2D;
56

  
57
import com.iver.cit.gvsig.fmap.core.FPoint2D;
58
import com.iver.cit.gvsig.fmap.core.FPoint3D;
59
import com.iver.cit.gvsig.fmap.core.IGeometry;
60
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
61
import com.iver.cit.jdwglib.dwg.DwgObject;
62
import com.iver.cit.jdwglib.dwg.objects.DwgText;
63

  
64
public class DwgText2FMapConverter implements IDwg2FMap {
65

  
66
	public IGeometry toFMapGeometry(DwgObject entity, boolean is3DFile) {
67
		DwgText dwtext = (DwgText)entity;
68
		FPoint2D point = null;
69
		Point2D p = dwtext.getInsertionPoint();
70
		double elev = 0.0;
71
		if ((dwtext.getDataFlag() & 0x1) == 0)
72
			elev = dwtext.getElevation();
73
		if (is3DFile) {
74
			point = new FPoint3D(p.getX(), p.getY(), elev);
75
		} else {
76
			point = new FPoint2D(p.getX(), p.getY());
77
		}
78
		return ShapeFactory.createGeometry(point);
79
	}
80
	
81
	public String toFMapString(boolean is3DFile) {
82
		if(is3DFile)
83
			return "FPoint3D";
84
		else
85
			return "FPoint2D";
86
	}
87

  
88
}
89

  
0 90

  
trunk/extensions/extDwg/src/com/iver/cit/gvsig/drivers/dwg/fmapconverters/DwgArc2FMapConverter.java
1
/*
2
 * Created on 02/04/2007
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
21
 *
22
 * For more information, contact:
23
 *
24
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib??ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33
 *
34
 *    or
35
 *
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 *
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
/* CVS MESSAGES:
45
*
46
* $Id$
47
* $Log$
48
* Revision 1.1  2007-04-04 17:48:53  azabala
49
* first version in cvs after libDwg<->libFMap disacopling
50
*
51
*
52
*/
53
package com.iver.cit.gvsig.drivers.dwg.fmapconverters;
54

  
55
import java.util.ArrayList;
56
import java.util.List;
57

  
58
import com.iver.cit.gvsig.fmap.core.FPolyline2D;
59
import com.iver.cit.gvsig.fmap.core.IGeometry;
60
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
61
import com.iver.cit.jdwglib.dwg.DwgObject;
62
import com.iver.cit.jdwglib.dwg.objects.DwgArc;
63
import com.iver.cit.jdwglib.util.GisModelCurveCalculator;
64

  
65
public class DwgArc2FMapConverter implements IDwg2FMap {
66

  
67
	/* (non-Javadoc)
68
	 * @see com.iver.cit.jdwglib.dwg.IDwg2FMap#toFMapGeometry()
69
	 */
70
	public IGeometry toFMapGeometry(DwgObject entity, boolean is3DFile) {
71
		DwgArc arc = (DwgArc) entity;
72
		double[] center = arc.getCenter();
73
		double radius = arc.getRadius();
74
		double initAngle = Math.toDegrees(arc.getInitAngle());
75
		double endAngle = Math.toDegrees(arc.getEndAngle());
76
		List arcs = GisModelCurveCalculator.calculateGisModelArc(
77
				center, radius, initAngle, endAngle);
78
		FPolyline2D arcc;
79
		if (is3DFile) {
80
			List arc3D = new ArrayList();
81
			for (int j = 0; j < arcs.size(); j++) {
82
				double[] point = (double[]) arcs.get(j);
83
				double[] newP = new double[]{point[0], point[1], center[2]};
84
				arc3D.add(newP);
85
			}
86
			arcc = FMapUtil.points3DToFPolyline3D(arc3D);
87
			
88
		} else {
89
			arcc = FMapUtil.points2DToFPolyline2D(arcs);
90
		}
91
		return ShapeFactory.createGeometry(arcc);
92
	}
93

  
94
	/* (non-Javadoc)
95
	 * @see com.iver.cit.jdwglib.dwg.IDwg2FMap#toFMapString()
96
	 */
97
	public String toFMapString(boolean is3dFile) {
98
		if(is3dFile)
99
			return "FPolyline3D";
100
		else
101
			return "FPolyline2D";
102
	}
103

  
104
}
105

  
0 106

  
trunk/extensions/extDwg/src/com/iver/cit/gvsig/drivers/dwg/fmapconverters/DwgPFacePline2FMapConverter.java
1
/*
2
 * Created on 02/04/2007
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
21
 *
22
 * For more information, contact:
23
 *
24
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib??ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33
 *
34
 *    or
35
 *
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 *
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
/* CVS MESSAGES:
45
*
46
* $Id$
47
* $Log$
48
* Revision 1.1  2007-04-04 17:48:53  azabala
49
* first version in cvs after libDwg<->libFMap disacopling
50
*
51
*
52
*/
53
package com.iver.cit.gvsig.drivers.dwg.fmapconverters;
54

  
55
import java.util.ArrayList;
56

  
57
import com.iver.cit.gvsig.fmap.core.FGeometryCollection;
58
import com.iver.cit.gvsig.fmap.core.FPolygon3D;
59
import com.iver.cit.gvsig.fmap.core.IGeometry;
60
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
61
import com.iver.cit.jdwglib.dwg.DwgObject;
62
import com.iver.cit.jdwglib.dwg.objects.DwgPFacePolyline;
63
import com.iver.cit.jdwglib.dwg.objects.DwgVertexPFaceFace;
64

  
65
public class DwgPFacePline2FMapConverter implements IDwg2FMap {
66

  
67
	public IGeometry toFMapGeometry(DwgObject entity, boolean is3DFile) {
68
		DwgPFacePolyline pline = (DwgPFacePolyline)entity;
69
		FGeometryCollection solution = null;
70
		IGeometry[] geometries = null;
71
		if(pline.getVertices() != null && pline.getFaces() != null){
72
			if(pline.getVertices().size() == 0 || pline.getFaces().size() == 0){
73
				return solution;
74
			}
75
			ArrayList geomList = new ArrayList();
76
			int numFaces = pline.getFaces().size();
77
			for(int i = 0; i < numFaces; i++){
78
				DwgVertexPFaceFace face = (DwgVertexPFaceFace) pline.getFaces().get(i);
79
				int[] verticesId = face.getVerticesidx();
80
				ArrayList pts = new ArrayList();
81
				boolean lastWasInvisible = true;
82
				for(int j = 0; j < DwgPFacePolyline.NUM_VERTEX_OF_FACE; j++){
83
					if(verticesId[j] > 0){
84
	                    if(lastWasInvisible){
85
	                        pts.clear();
86
	                        lastWasInvisible = false;
87
	                    }
88
	                    // the index is 1-based
89
	                    try{
90
	                    pts.add(pline.getVertices().get(verticesId[j] -1));
91
	                    }catch(Throwable t){
92
	                    	t.printStackTrace();
93
	                    }
94
	                    
95
	                } else if(verticesId[j] < 0 && !lastWasInvisible){
96
	                    lastWasInvisible = true;
97
	                    pts.add(pline.getVertices().get( (verticesId[j] * -1) -1));
98
	                }	
99
				}// for j
100
				
101
				FPolygon3D polygon = FMapUtil.ptsTo3DPolygon(pts);
102
				IGeometry geom = ShapeFactory.createGeometry(polygon);
103
				geomList.add(geom);
104
				
105
				
106
// if(!lastWasInvisible){
107
// if(vertex[nrV] < 0){
108
// line.addPoint(knot[-vertex[nrV] - 1]);
109
// } else{
110
// line.addPoint(knot[vertex[nrV] - 1]);
111
// }
112
// set.addDrawable(line);
113
// }
114
	           
115
			}// for i
116
			geometries = new IGeometry[geomList.size()];
117
			geomList.toArray(geometries);
118
			solution = new FGeometryCollection(geometries);
119
		}
120
		return solution;
121
		
122
	}
123
	/*
124
	 * (non-Javadoc)
125
	 * 
126
	 * @see com.iver.cit.jdwglib.dwg.IDwg2FMap#toFMapString(boolean)
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff