Revision 10632

View differences:

trunk/libraries/libDwg/src/com/iver/cit/jdwglib/util/FMapUtil.java
4 4
 */
5 5
package com.iver.cit.jdwglib.util;
6 6

  
7
import java.awt.geom.Point2D;
7
import java.util.List;
8 8

  
9 9
import com.iver.cit.gvsig.fmap.core.FPolyline2D;
10 10
import com.iver.cit.gvsig.fmap.core.FPolyline3D;
......
26 26
	 * @return FPolyline3D This FPolyline3D is build using the array of Point3D
27 27
	 *         that is the argument of the method
28 28
	 */
29
	public static FPolyline3D points3DToFPolyline3D(double[][] pts) {
29
	public static FPolyline3D points3DToFPolyline3D(List pts) {
30 30
		GeneralPathX genPathX = new GeneralPathX();
31
		genPathX.moveTo(pts[0][0], pts[0][1]);
32
		for (int i = 1; i < pts.length; i++) {
33
			genPathX.lineTo(pts[i][0], pts[i][1]);
31
		genPathX.moveTo(((double[])pts.get(0))[0], 
32
				((double[])pts.get(0))[1]);
33
		for (int i = 1; i < pts.size(); i++) {
34
			genPathX.lineTo(((double[])pts.get(i))[0],
35
					((double[])pts.get(i))[1]);
34 36
		}
35
		double[] elevations = new double[pts.length];
36
		for (int i = 0; i < pts.length; i++) {
37
			elevations[i] = pts[i][2];
37
		double[] elevations = new double[pts.size()];
38
		for (int i = 0; i < pts.size(); i++) {
39
			elevations[i] = ((double[])pts.get(i))[2];
38 40
		}
39 41
		return new FPolyline3D(genPathX, elevations);
40 42
	}
......
49 51
	 * @return FPolyline2D This FPolyline2D is build using the array of Point2D
50 52
	 *         that is the argument of the method
51 53
	 */
52
	public static FPolyline2D points2DToFPolyline2D(Point2D[] pts) {
54
	public static FPolyline2D points2DToFPolyline2D(List pts) {
53 55
		GeneralPathX genPathX = new GeneralPathX();
54
		genPathX.moveTo(pts[0].getX(), pts[0].getY());
55
		for (int i = 1; i < pts.length; i++) {
56
			genPathX.lineTo(pts[i].getX(), pts[i].getY());
56
		genPathX.moveTo(((double[])pts.get(0))[0], ((double[])pts.get(0))[1]);
57
		for (int i = 1; i < pts.size(); i++) {
58
			genPathX.lineTo(((double[])pts.get(i))[0], 
59
					((double[])pts.get(i))[1]);
57 60
		}
58 61
		return new FPolyline2D(genPathX);
59 62
	}
trunk/libraries/libDwg/src/com/iver/cit/jdwglib/util/ArcFromBulgeCalculator.java
43 43
 * @author jmorell
44 44
 */
45 45
public class ArcFromBulgeCalculator {
46
	private Point2D coord1, coord2;
47
	private Point2D center;
46
	private double[] coord1, coord2;
47
	private double[] center;
48 48
	private double radio, empieza, acaba;
49 49
	private double bulge;
50 50
	private double d, dd, aci;
51
	private Point2D coordAux;
51
	private double[] coordAux;
52 52
	
53 53
	/**
54 54
	 * This method calculates an arc given by a start and end points and a bulge
......
57 57
	 * @param p2 End point of the arc given by a Point2D
58 58
	 * @param bulge Bulge of the arc given by a double value 
59 59
	 */
60
	public ArcFromBulgeCalculator(Point2D p1, Point2D p2, double bulge) {
60
	public ArcFromBulgeCalculator(double[] p1, double[] p2, double bulge) {
61 61
		this.bulge = bulge;
62 62
		if (bulge < 0.0) {
63 63
			coord1 = p2;
......
70 70
	}
71 71
	
72 72
	private void calParams() {
73
		d = Math.sqrt((coord2.getX()-coord1.getX())*(coord2.getX()-coord1.getX()) + (coord2.getY()-coord1.getY())*(coord2.getY()-coord1.getY()));
74
		coordAux = new Point2D.Double((coord1.getX()+coord2.getX())/2.0, (coord1.getY()+coord2.getY())/2.0);
73
		d = Math.sqrt((coord2[0]-coord1[0])*(coord2[0]-coord1[0]) + 
74
				(coord2[1]-coord1[1])*(coord2[1]-coord1[1]));
75
		coordAux = new double[]{(coord1[0]+coord2[0])/2.0, (coord1[1]+coord2[1])/2.0};
75 76
		double b = Math.abs(bulge);
76 77
		double beta = Math.atan(b);
77 78
		double alfa = beta*4.0;
78 79
		double landa = alfa/2.0;
79 80
		dd = (d/2.0)/(Math.tan(landa));
80 81
		radio = (d/2.0)/(Math.sin(landa));		
81
		aci = Math.atan((coord2.getX()-coord1.getX())/(coord2.getY()-coord1.getY()));
82
		aci = Math.atan((coord2[0]-coord1[0])/(coord2[1]-coord1[1]));
82 83
		double aciDegree = aci*180.0/Math.PI;
83
		if (coord2.getY() > coord1.getY()) {
84
		if (coord2[1] > coord1[1]) {
84 85
			aci += Math.PI;
85 86
			aciDegree = aci*180.0/Math.PI;
86 87
		}
87
		center = new Point2D.Double(coordAux.getX() + dd*Math.sin(aci+(Math.PI/2.0)), coordAux.getY() + dd*Math.cos(aci+(Math.PI/2.0)));
88
		center = new double[]{coordAux[0] + dd*Math.sin(aci+(Math.PI/2.0)), coordAux[1] + dd*Math.cos(aci+(Math.PI/2.0))};
88 89
		calEA(alfa);
89 90
	}
90 91
	
91 92
	private void calEA(double alfa){
92
		empieza = Math.atan2(coord1.getY()-center.getY(), coord1.getX()-center.getX());
93
		empieza = Math.atan2(coord1[1]-center[1], coord1[0]-center[0]);
93 94
		acaba = (empieza + alfa);
94 95
		empieza = empieza*180.0/Math.PI;
95 96
		acaba = acaba*180.0/Math.PI;
......
125 126
			addNode(arc, angulo);
126 127
		}
127 128
		Point2D aux = (Point2D)arc.get(arc.size()-1);
128
		double aux1 = Math.abs(aux.getX()-coord2.getX());
129
		double aux2 = Math.abs(aux.getY()-coord2.getY());
129
		double aux1 = Math.abs(aux.getX()-coord2[0]);
130
		double aux2 = Math.abs(aux.getY()-coord2[1]);
130 131
		return arc;
131 132
	}
132 133
	
......
154 155
	}
155 156
	
156 157
	private void addNode(Vector arc, double angulo) {
157
		double yy = center.getY() + radio * Math.sin(angulo*Math.PI/180.0);
158
		double xx = center.getX() + radio * Math.cos(angulo*Math.PI/180.0);		
158
		double yy = center[1] + radio * Math.sin(angulo*Math.PI/180.0);
159
		double xx = center[0] + radio * Math.cos(angulo*Math.PI/180.0);		
159 160
		arc.add(new Point2D.Double(xx,yy));
160 161
	}
161 162
}
trunk/libraries/libDwg/src/com/iver/cit/jdwglib/util/GisModelCurveCalculator.java
35 35
package com.iver.cit.jdwglib.util;
36 36

  
37 37
import java.awt.geom.Point2D;
38
import java.util.ArrayList;
39
import java.util.List;
38 40
import java.util.Vector;
39 41

  
40 42
/**
......
54 56
     * @param r double value that represents the radius of the circle
55 57
     * @return Point2D[] An array of Point2D that represents the shape of the circle
56 58
     */
57
	public static Point2D[] calculateGisModelCircle(Point2D c, double r) {
58
		Point2D[] pts = new Point2D[360];
59
	public static List calculateGisModelCircle(Point2D c, double r) {
60
		List pts = new ArrayList();
59 61
		int angulo = 0;
60 62
		for (angulo=0; angulo<360; angulo++) {
61
			pts[angulo] = new Point2D.Double(c.getX(), c.getY());
62
			pts[angulo].setLocation(pts[angulo].getX() + r * Math.sin(angulo*Math.PI/(double)180.0), pts[angulo].getY() + r * Math.cos(angulo*Math.PI/(double)180.0));
63
			double[] pt = new double[]{c.getX(), c.getY()};
64
			pt[0] = pt[0] + r * Math.sin(angulo*Math.PI/(double)180.0);
65
			pt[1] = pt[1] + r * Math.cos(angulo*Math.PI/(double)180.0);
66
			
67
			pts.add(pt);
63 68
		}
64 69
		return pts;
65 70
	}
......
75 80
	 * @param endAngle double value that represents the end angle of the ellipse arc
76 81
     * @return Point2D[] An array of Point2D that represents the shape of the ellipse
77 82
     */
78
	public static Point2D[] calculateGisModelEllipse(Point2D center, Point2D majorAxisVector, double axisRatio, double initAngle, double endAngle) {
83
	public static List calculateGisModelEllipse(Point2D center, Point2D majorAxisVector, double axisRatio, double initAngle, double endAngle) {
79 84
		Point2D majorPoint = new Point2D.Double(center.getX()+majorAxisVector.getX(), center.getY()+majorAxisVector.getY());
80
	    double orientation  = Math.atan(majorAxisVector.getY()/majorAxisVector.getX());
85
		double orientation  = Math.atan(majorAxisVector.getY()/majorAxisVector.getX());
81 86
	    double semiMajorAxisLength = center.distance(majorPoint);
82 87
		double semiMinorAxisLength = semiMajorAxisLength*axisRatio;
83 88
	    double eccentricity = Math.sqrt(1-((Math.pow(semiMinorAxisLength, 2))/(Math.pow(semiMajorAxisLength, 2))));
84 89
		int isa = (int)initAngle;
85 90
		int iea = (int)endAngle;
86 91
		double angulo;
87
		Point2D[] pts;
92
		List pts = new ArrayList();
88 93
		if (initAngle <= endAngle) {
89
			pts = new Point2D[(iea-isa)+2];
90 94
			angulo = initAngle;
91 95
			double r = semiMinorAxisLength/Math.sqrt(1-((Math.pow(eccentricity, 2))*(Math.pow(Math.cos(angulo*Math.PI/(double)180.0), 2))));
92 96
		    double x = r*Math.cos(angulo*Math.PI/(double)180.0);
93 97
		    double y = r*Math.sin(angulo*Math.PI/(double)180.0);
94 98
		    double xrot = x*Math.cos(orientation) - y*Math.sin(orientation);
95 99
		    double yrot = x*Math.sin(orientation) + y*Math.cos(orientation);
96
			pts[0] = new Point2D.Double(center.getX() + xrot, center.getY() + yrot);
100
			
101
			double[] pt = new double[]{center.getX() + xrot, center.getY() + yrot };
102
			pts.add(pt);
103
			
97 104
			for (int i=1; i<=(iea-isa)+1; i++) {
98 105
				angulo = (double)(isa+i);
99 106
				r = semiMinorAxisLength/Math.sqrt(1-((Math.pow(eccentricity, 2))*(Math.pow(Math.cos(angulo*Math.PI/(double)180.0), 2))));
......
101 108
			    y = r*Math.sin(angulo*Math.PI/(double)180.0);
102 109
			    xrot = x*Math.cos(orientation) - y*Math.sin(orientation);
103 110
			    yrot = x*Math.sin(orientation) + y*Math.cos(orientation);
104
			    pts[i] = new Point2D.Double(center.getX() + xrot, center.getY() + yrot);
111
			    
112
			    pt = new double[]{center.getX() + xrot, center.getY() + yrot};
113
			    pts.add(pt);
105 114
			}
115
			
106 116
			angulo = endAngle;
107 117
			r = semiMinorAxisLength/Math.sqrt(1-((Math.pow(eccentricity, 2))*(Math.pow(Math.cos(angulo*Math.PI/(double)180.0), 2))));
108 118
		    x = r*Math.cos(angulo*Math.PI/(double)180.0);
109 119
		    y = r*Math.sin(angulo*Math.PI/(double)180.0);
110 120
		    xrot = x*Math.cos(orientation) - y*Math.sin(orientation);
111 121
		    yrot = x*Math.sin(orientation) + y*Math.cos(orientation);
112
		    pts[(iea-isa)+1] = new Point2D.Double(center.getX() + xrot, center.getY() + yrot);
122
		    
123
		    
124
		    pt = new double[]{center.getX() + xrot, center.getY() + yrot};
125
		    pts.add(pt);
126
		    
113 127
		} else {
114
			pts = new Point2D[(360-isa)+iea+2];
115 128
			angulo = initAngle;
116 129
			double r = semiMinorAxisLength/Math.sqrt(1-((Math.pow(eccentricity, 2))*(Math.pow(Math.cos(angulo*Math.PI/(double)180.0), 2))));
117 130
		    double x = r*Math.cos(angulo*Math.PI/(double)180.0);
118 131
		    double y = r*Math.sin(angulo*Math.PI/(double)180.0);
119 132
		    double xrot = x*Math.cos(orientation) - y*Math.sin(orientation);
120 133
		    double yrot = x*Math.sin(orientation) + y*Math.cos(orientation);
121
		    pts[0] = new Point2D.Double(center.getX() + r*Math.cos(angulo*Math.PI/(double)180.0), center.getY() + r*Math.sin(angulo*Math.PI/(double)180.0));
122
			for (int i=1; i<=(360-isa); i++) {
134
		    
135
		  
136
			double[] pt = new double[]{center.getX() + r*Math.cos(angulo*Math.PI/(double)180.0), center.getY() + r*Math.sin(angulo*Math.PI/(double)180.0)};
137
		    pts.add(pt);
138
		    
139
		    for (int i=1; i<=(360-isa); i++) {
123 140
				angulo = (double)(isa+i);
124 141
				r = semiMinorAxisLength/Math.sqrt(1-((Math.pow(eccentricity, 2))*(Math.pow(Math.cos(angulo*Math.PI/(double)180.0), 2))));
125 142
			    x = r*Math.cos(angulo*Math.PI/(double)180.0);
126 143
			    y = r*Math.sin(angulo*Math.PI/(double)180.0);
127 144
			    xrot = x*Math.cos(orientation) - y*Math.sin(orientation);
128 145
			    yrot = x*Math.sin(orientation) + y*Math.cos(orientation);
129
			    pts[i] = new Point2D.Double(center.getX() + xrot, center.getY() + yrot);
146
			    
147
			    pt = new double[]{center.getX() + xrot, center.getY() + yrot};
148
			    pts.add(pt);
130 149
			}
150
		    
151
		    
131 152
			for (int i=(360-isa)+1; i<=(360-isa)+iea; i++) {
132 153
				angulo = (double)(i-(360-isa));
133 154
				r = semiMinorAxisLength/Math.sqrt(1-((Math.pow(eccentricity, 2))*(Math.pow(Math.cos(angulo*Math.PI/(double)180.0), 2))));
......
135 156
			    y = r*Math.sin(angulo*Math.PI/(double)180.0);
136 157
			    xrot = x*Math.cos(orientation) - y*Math.sin(orientation);
137 158
			    yrot = x*Math.sin(orientation) + y*Math.cos(orientation);
138
			    pts[i] = new Point2D.Double(center.getX() + xrot, center.getY() + yrot);
159
			    
160
			    pt = new double[]{center.getX() + xrot, center.getY() + yrot};
161
			    pts.add(pt);
162
			    
139 163
			}
164
			
140 165
			angulo = endAngle;
141 166
			r = semiMinorAxisLength/Math.sqrt(1-((Math.pow(eccentricity, 2))*(Math.pow(Math.cos(angulo*Math.PI/(double)180.0), 2))));
142 167
		    x = r*Math.cos(angulo*Math.PI/(double)180.0);
143 168
		    y = r*Math.sin(angulo*Math.PI/(double)180.0);
144 169
		    xrot = x*Math.cos(orientation) - y*Math.sin(orientation);
145 170
		    yrot = x*Math.sin(orientation) + y*Math.cos(orientation);
146
		    pts[(360-isa)+iea+1] = new Point2D.Double(center.getX() + xrot, center.getY() + yrot);
171
		    
172
		    pt = new double[]{center.getX() + xrot, center.getY() + yrot};
173
		    pts.add(pt);
147 174
		}
148 175
		return pts;
149 176
	}
......
158 185
	 * @param ea double value that represents the end angle of the arc
159 186
     * @return Point2D[] An array of Point2D that represents the shape of the arc
160 187
	 */
161
	public static Point2D[] calculateGisModelArc(Point2D c, double r, double sa, double ea) {
188
	public static List calculateGisModelArc(double[] center, double r, double sa, double ea) {
162 189
		int isa = (int)sa;
163 190
		int iea = (int)ea;
164 191
		double angulo;
165
		Point2D[] pts;
192
		List pts = new ArrayList();
166 193
		if (sa <= ea) {
167
			pts = new Point2D[(iea-isa)+2];
168 194
			angulo = sa;
169
			pts[0] = new Point2D.Double(c.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), c.getY() + r * Math.sin(angulo*Math.PI/(double)180.0));
170
			for (int i=1; i<=(iea-isa)+1; i++) {
195
			pts.add(new double[]{center[0] + r * Math.cos(angulo*Math.PI/(double)180.0), 
196
					center[1] + r * Math.sin(angulo*Math.PI/(double)180.0)});
197
			for (int i=1; i <= (iea-isa)+1; i++) {
171 198
				angulo = (double)(isa+i);
172
				pts[i] = new Point2D.Double(c.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), c.getY() + r * Math.sin(angulo*Math.PI/(double)180.0));
199
				double x = center[0] + r * Math.cos(angulo*Math.PI/(double)180.0);
200
				double y = center[1] + r * Math.sin(angulo*Math.PI/(double)180.0);
201
				pts.add(new double[]{x, y});
173 202
			}
174 203
			angulo = ea;
175
			pts[(iea-isa)+1] = new Point2D.Double(c.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), c.getY() + r * Math.sin(angulo*Math.PI/(double)180.0));
204
			double x = center[0] + r * Math.cos(angulo*Math.PI/(double)180.0);
205
			double y = center[1] + r * Math.sin(angulo*Math.PI/(double)180.0);
206
			pts.add(new double[]{x, y});
176 207
		} else {
177
			pts = new Point2D[(360-isa)+iea+2];
178 208
			angulo = sa;
179
			pts[0] = new Point2D.Double(c.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), c.getY() + r * Math.sin(angulo*Math.PI/(double)180.0));
180
			for (int i=1; i<=(360-isa); i++) {
209
			double x = center[0] + r * Math.cos(angulo*Math.PI/(double)180.0);
210
			double y = center[1] + r * Math.sin(angulo*Math.PI/(double)180.0);
211
			pts.add(new double[]{x, y});
212
			for (int i=1; i <= (360-isa); i++) {
181 213
				angulo = (double)(isa+i);
182
				pts[i] = new Point2D.Double(c.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), c.getY() + r * Math.sin(angulo*Math.PI/(double)180.0));
214
				x = center[0] + r * Math.cos(angulo*Math.PI/(double)180.0);
215
				y = center[1] + r * Math.sin(angulo*Math.PI/(double)180.0); 
216
				pts.add(new double[]{x, y});
183 217
			}
184
			for (int i=(360-isa)+1; i<=(360-isa)+iea; i++) {
218
			
219
			for (int i=( 360-isa)+1; i <= (360-isa)+iea; i++) {
185 220
				angulo = (double)(i-(360-isa));
186
				pts[i] = new Point2D.Double(c.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), c.getY() + r * Math.sin(angulo*Math.PI/(double)180.0));
221
				x = center[0] + r * Math.cos(angulo*Math.PI/(double)180.0);
222
				y = center[1] + r * Math.sin(angulo*Math.PI/(double)180.0);
223
				pts.add(new double[]{x, y});
187 224
			}
188 225
			angulo = ea;
189
			pts[(360-isa)+iea+1] = new Point2D.Double(c.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), c.getY() + r * Math.sin(angulo*Math.PI/(double)180.0));
226
			x = center[0] + r * Math.cos(angulo*Math.PI/(double)180.0);
227
			y = center[1] + r * Math.sin(angulo*Math.PI/(double)180.0);
228
			pts.add(new double[]{x, y});
190 229
		}
191 230
		return pts;
192 231
	}
......
200 239
	 * @param bulges Array of bulge parameters
201 240
	 * @return Polyline with a new set of arcs added and defined by the bulge parameters
202 241
	 */
203
	public static Point2D[] calculateGisModelBulge(Point2D[] newPts, double[] bulges) {
242
	public static List calculateGisModelBulge(List newPts, double[] bulges) {
204 243
		Vector ptspol = new Vector();
205
		Point2D init = new Point2D.Double();
206
		Point2D end = new Point2D.Double();
207
		for (int j=0; j<newPts.length; j++) {
208
			init = newPts[j];
209
			if (j!=newPts.length-1) end = newPts[j+1];
210
			if (bulges[j]==0 || j==newPts.length-1 || (init.getX()==end.getX() && init.getY()==end.getY())) {
244
		double[] init = null;
245
		double[] end = null;
246
		for (int j=0; j<newPts.size(); j++) {
247
			init = (double[]) newPts.get(j);
248
			if (j != newPts.size()-1) 
249
				end = (double[]) newPts.get(j+1);
250
			if (bulges[j]==0 || j== newPts.size()-1 || 
251
				(init[0] == end[0] && init[1] == end[1])) {
211 252
				ptspol.add(init);
212 253
			} else {
213 254
				ArcFromBulgeCalculator arcCalculator = new ArcFromBulgeCalculator(init, end, bulges[j]);
......
225 266
				}
226 267
			}
227 268
		}
228
		Point2D[] points = new Point2D[ptspol.size()];
269
		List points = new ArrayList();
229 270
		for (int j=0;j<ptspol.size();j++) {
230
			points[j] = (Point2D)ptspol.get(j);
271
			points.add(ptspol.get(j));
231 272
		}
232 273
		return points;
233 274
	}
trunk/libraries/libDwg/src/com/iver/cit/jdwglib/dwg/IDwgVertex.java
1
/*
2
 * Created on 04-mar-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-03-06 19:39:38  azabala
49
* Changes to adapt dwg 12 to general architecture
50
*
51
*
52
*/
53
package com.iver.cit.jdwglib.dwg;
54

  
55
/**
56
 * Base interface for all DWG vertices. 
57
 * 
58
 * @author azabala
59
 * 
60
 * */
61
public interface IDwgVertex {
62
	public double[] getPoint();
63
}
64

  
0 65

  
trunk/libraries/libDwg/src/com/iver/cit/jdwglib/dwg/DwgObjectFactory.java
45 45
 *
46 46
 * $Id$
47 47
 * $Log$
48
 * Revision 1.16  2007-03-02 20:31:22  azabala
48
 * Revision 1.17  2007-03-06 19:39:38  azabala
49
 * Changes to adapt dwg 12 to general architecture
50
 *
51
 * Revision 1.16  2007/03/02 20:31:22  azabala
49 52
 * *** empty log message ***
50 53
 *
51 54
 * Revision 1.15  2007/03/01 19:59:46  azabala
......
377 380
//		case 9: //It is a 3D quad
378 381
//			return new DwgTrace(index);
379 382
			
383
		case 11:
384
			return new DwgSolid(index);
380 385
		case 12:
381
			return new DwgSolid(index);
386
			return new DwgBlockHeader(index);
382 387
		case 13:
383
			return new DwgBlock(index);
388
			return new DwgEndblk(index);
384 389
		case 14:
385
			return new DwgEndblk(index);
390
			return new DwgInsert(index);
386 391
		case 15:
387
			return new DwgInsert(index);
392
			return new DwgAttdef(index);
388 393
		case 16:
389
			return new DwgAttdef(index);
390
		case 17:
391 394
			return new DwgAttrib(index);	
392
		case 18://no estoy seguro de q esto sea SbEnd
395
		case 17://no estoy seguro de q esto sea SbEnd
393 396
			return new DwgSeqend(index);
394
		case 20://polyline is a particular case. Creation responsability is of Reader
397
		case 19://polyline is a particular case. Creation responsability is of Reader
395 398
			return null;
396
		case 21://vertex like polyline
399
		case 20://vertex like polyline
397 400
			return null;
398
		case 23:
401
		case 22:
399 402
			return new DwgFace3D(index);
400
		case 24: //esto es Dim ??
403
		case 23: //esto es Dim ??
401 404
			return new DwgDimOrd(index);
402 405
//		case 25://no implementado
403 406
//			return new DwgVPort(index);
trunk/libraries/libDwg/src/com/iver/cit/jdwglib/dwg/readers/objreaders/v15/DwgLwPolylineReader15.java
5 5
package com.iver.cit.jdwglib.dwg.readers.objreaders.v15;
6 6

  
7 7
import java.awt.geom.Point2D;
8
import java.util.ArrayList;
8 9
import java.util.List;
9 10

  
10 11
import com.iver.cit.jdwglib.dwg.CorruptedDwgEntityException;
......
120 121
		    	//Plantear en la lista de PythonCAD
121 122
		    	if(numberOfPoints > 10000)
122 123
		    		throw new CorruptedDwgEntityException("LwPolyline corrupta");
123
		    	Point2D[] vertices = new Point2D[numberOfPoints];
124
		    	List vertices = new ArrayList();
124 125
		  	    val = DwgUtil.getRawDouble(data, bitPos);
125 126
		  	    bitPos = ((Integer) val.get(0)).intValue();
126 127
		  		double x0 = ((Double) val.get(1)).doubleValue();
......
128 129
		  		val = DwgUtil.getRawDouble(data, bitPos);
129 130
		  		bitPos = ((Integer) val.get(0)).intValue();
130 131
		  		double y0 = ((Double) val.get(1)).doubleValue();
131
		  		vertices[0] = new Point2D.Double(x0, y0);
132
		  	   
133 132
		  		
133
		  		vertices.add(new double[]{x0, y0});
134
		  		
135
		  		
134 136
		  		/*
135 137
		  		 * TODO azabala 
136 138
		  		 * Algunos metodos de DwgUtil lanzan excepciones inexperadas
......
158 160
		  			val = DwgUtil.getDefaultDouble(data, bitPos, y0);
159 161
		  			bitPos = ((Integer) val.get(0)).intValue();
160 162
		  			double y = ((Double) val.get(1)).doubleValue();
161
		  			vertices[i] = new Point2D.Double(x, y);
162 163
		  			
164
		  			vertices.add(new double[]{x, y});
165
		  			
163 166
		  			x0 = x;//se proporcionan como valores por defecto las coordenadas del pto anterior
164 167
		  			y0 = y;
165 168
		  		}
trunk/libraries/libDwg/src/com/iver/cit/jdwglib/dwg/readers/objreaders/v1314/DwgLwPolylineReader1314.java
5 5
package com.iver.cit.jdwglib.dwg.readers.objreaders.v1314;
6 6

  
7 7
import java.awt.geom.Point2D;
8
import java.util.ArrayList;
8 9
import java.util.List;
9 10

  
10 11
import com.iver.cit.jdwglib.dwg.CorruptedDwgEntityException;
......
107 108
		if(np > 0){
108 109
			if(np > 10000)
109 110
	    		throw new CorruptedDwgEntityException("LwPolyline corrupta");
110
			Point2D[] points = new Point2D[np];
111
			List points = new ArrayList();
111 112
			for(int i = 0; i < np; i++){
112 113
				val = DwgUtil.getRawDouble(data, bitPos);
113 114
				bitPos = ((Integer) val.get(0)).intValue();
......
117 118
				bitPos = ((Integer) val.get(0)).intValue();
118 119
				y = ((Double) val.get(1)).doubleValue();
119 120
				
120
				points[i] = new Point2D.Double(x, y);
121
				points.add(new double[]{x,y});
121 122
			}//for
122 123
			l.setVertices(points);
123 124
		}//if np
trunk/libraries/libDwg/src/com/iver/cit/jdwglib/dwg/readers/DwgFileV12Reader.java
55 55
import com.iver.cit.jdwglib.dwg.DwgHandleReference;
56 56
import com.iver.cit.jdwglib.dwg.DwgObject;
57 57
import com.iver.cit.jdwglib.dwg.DwgObjectFactory;
58
import com.iver.cit.jdwglib.dwg.DwgUtil;
58
import com.iver.cit.jdwglib.dwg.IDwgBlockMember;
59
import com.iver.cit.jdwglib.dwg.IDwgPolyline;
60
import com.iver.cit.jdwglib.dwg.IDwgVertex;
59 61
import com.iver.cit.jdwglib.dwg.objects.DwgArc;
60 62
import com.iver.cit.jdwglib.dwg.objects.DwgBlockHeader;
61 63
import com.iver.cit.jdwglib.dwg.objects.DwgCircle;
64
import com.iver.cit.jdwglib.dwg.objects.DwgEndblk;
62 65
import com.iver.cit.jdwglib.dwg.objects.DwgInsert;
63 66
import com.iver.cit.jdwglib.dwg.objects.DwgLayer;
64 67
import com.iver.cit.jdwglib.dwg.objects.DwgLine;
......
67 70
import com.iver.cit.jdwglib.dwg.objects.DwgPoint;
68 71
import com.iver.cit.jdwglib.dwg.objects.DwgPolyline2D;
69 72
import com.iver.cit.jdwglib.dwg.objects.DwgPolyline3D;
73
import com.iver.cit.jdwglib.dwg.objects.DwgSeqend;
70 74
import com.iver.cit.jdwglib.dwg.objects.DwgSolid;
71 75
import com.iver.cit.jdwglib.dwg.objects.DwgText;
72 76
import com.iver.cit.jdwglib.dwg.objects.DwgVertex2D;
73 77
import com.iver.cit.jdwglib.dwg.objects.DwgVertex3D;
74 78
import com.iver.cit.jdwglib.dwg.objects.DwgVertexPFace;
75 79
import com.iver.cit.jdwglib.dwg.objects.DwgVertexPFaceFace;
76
import com.iver.cit.jdwglib.util.ByteUtils;
77 80

  
78 81
/**
79 82
 * Reads version 12 dwg files.
......
104 107
	private boolean r13 = false;
105 108
	int index = 0;
106 109
	
110
	ArrayList blocks = new ArrayList();
111
	
112
	
113
	/**
114
	 * While DwgBlock is a DWG entity, readed from the DWG entities
115
	 * section, a Block is an entry in the BLOCK Section of DWG 12 format.
116
	 * 
117
	 * Block has block name attribute (like DwgBlock), but its most
118
	 * important attribute is its order in the Block section.
119
	 * 
120
	 * Inserts has a short number that we think is the order of its
121
	 * referred block in the block table (the only approach to fech
122
	 * the block of an insert)
123
	 * */
124
	class Block {
125
		/*
126
        |----------|--------------------------------------------|
127
        | 1        | This is an anonymous Block generated by    |
128
        |          | hatching, associative dimensioning, other  |
129
        |          | internal operations, or an application     |
130
        |----------|--------------------------------------------|
131
        | 2        | This Block has Attributes                  |
132
        |----------|--------------------------------------------|
133
        | 4        | This Block is an external reference (Xref) |
134
        |----------|--------------------------------------------|
135
        | 8        | not used                                   |
136
        |----------|--------------------------------------------|
137
        | 16       | This Block is externally dependent         |
138
        |----------|--------------------------------------------|
139
        | 32       | This is a resolved external reference, or  |
140
        |          | dependent of an external reference         |
141
        |----------|--------------------------------------------|
142
        | 64       | This definition is referenced              |
143
        +-------------------------------------------------------+
144
        */
145
		byte flag;
146
		String name;
147
		short used;
148
		
149
		byte b1;
150
		short w1;
151
		byte b2;
152
		short w3;
153
		short crc;
154
	}
155
	
107 156
	public DwgFileV12Reader(boolean isR13){
108 157
		r13 = isR13;
109 158
		readers.add(null);//0
......
117 166
		readers.add(new ArcReader());//8
118 167
		readers.add(new TraceReader());//9
119 168
		readers.add(null);//10
120
		readers.add(new SolidReader());//12
121
		readers.add(new BlkReader());//13
122
		readers.add(new EndBlkReader());//14
123
		readers.add(new InsertReader());//15
124
		readers.add(new AttDefReader());//16
125
		readers.add(new AttribReader());//17
126
		readers.add(new SbEndReader());//18
127
		readers.add(null);//19
128
		readers.add(new PlineReader());//20
129
		readers.add(new VertexReader());//21
130
		readers.add(null);//22
131
		readers.add(new Face3DReader());//23
132
		readers.add(new DimReader());//24
133
		readers.add(new VPortReader());//25
169
		readers.add(new SolidReader());//11
170
		readers.add(new BlkReader());//12
171
		readers.add(new EndBlkReader());//13
172
		readers.add(new InsertReader());//14
173
		readers.add(new AttDefReader());//15
174
		readers.add(new AttribReader());//16
175
		readers.add(new SbEndReader());//17
176
		readers.add(null);//18
177
		readers.add(new PlineReader());//19
178
		readers.add(new VertexReader());//20
179
		readers.add(null);//21
180
		readers.add(new Face3DReader());//22
181
		readers.add(new DimReader());//23
182
		readers.add(new VPortReader());//24
134 183
	}
135 184
	
136 185
	
......
219 268
			
220 269
			readBlockTable(blockTable);
221 270
			readLayerTable(layerTable);
222
			readStyleTable(styleTable);
223
			readLTypeTable(lineTypeTable);
224
			readViewTable(viewTable);
225
			readUcsTable(ucsTable);
226
			readVportTable(vportTable);
227
			readAppidTable(appidTable);
228
			readDimStyleTable(dimStyleTable);
271
			
272
//de momento nos saltamos estas tablas
273
//			readStyleTable(styleTable);
274
//			readLTypeTable(lineTypeTable);
275
//			readViewTable(viewTable);
276
//			readUcsTable(ucsTable);
277
//			readVportTable(vportTable);
278
//			readAppidTable(appidTable);
279
//			readDimStyleTable(dimStyleTable);
229 280
//			readP13Table(p13table);
230 281
			
231 282
			//luego lee entidades de bloque
......
631 682
		short size = layerTable.s1;
632 683
		int numR = layerTable.i1;
633 684
		int start = layerTable.i2;
685
		
686
		int begin = -1;
634 687
		int end = -1;
635
		bb.position(start);
636 688
		
637 689
		DwgLayer layer = null;
638
		
639
		
640 690
		for(int i = 0; i < numR; i++){
691
			begin = start + i * size;
692
			bb.position(begin);
693
			end = begin + size - 2;
641 694
			
642 695
			layer = new DwgLayer(index);
643 696
			index++;
644
			end = bb.position() + size;
697
			
645 698
			byte flag = bb.get();
646 699
			/*
647 700
			 +=====================================================+
......
668 721
			
669 722
			byte[] nameByte = new byte[32];
670 723
			bb.get(nameByte);
671
			String name = new String(nameByte);
724
			String name = new String(nameByte).trim();
672 725
			layer.setName(name);
673 726
			
674 727
			bb.order(ByteOrder.LITTLE_ENDIAN);
......
677 730
			layer.setColor(color);
678 731
			short style = bb.getShort();
679 732
			short crc = bb.getShort();
680
			
681
			int offset = end - bb.position();
682
			
733

  
683 734
			//TODO Vemos si el indice que ocupa la layer en la tabla
684 735
			//de layers se corresponde con el valor short de las entidades
685 736
			//graficas
686 737
			DwgHandleReference handle = new DwgHandleReference(0x5, i);
687 738
			layer.setHandle(handle);
688 739
			dwgFile.addDwgObject(layer);
740
			
741
			
742
			int offset = end - bb.position();
689 743
			if(offset > 0)
690 744
				bb.position(bb.position() + offset);
691 745
			
......
797 851
			double d40 = bb.getDouble();
798 852
			circle.setRadius(d40);
799 853
			
854
			double[] pt210 = null;
800 855
			if((opts & 0x1) > 0){
801
				double[] pt210 = getPoint(true);
802
				circle.setExtrusion(pt210);
856
				pt210 = getPoint(true);
857
				
858
			}else{
859
				pt210 = new double[]{0,0,1};
803 860
			}
804
			
861
			circle.setExtrusion(pt210);
805 862
			if((opts & 0x2) > 0){
806 863
				bb.order(ByteOrder.LITTLE_ENDIAN);
807 864
				double db38 = bb.getDouble();
......
929 986
			double d51 = bb.getDouble();
930 987
			arc.setEndAngle(51);
931 988
			
989
			double[] pt210 = null;
932 990
			if((opts & 0x1) > 0){
933
				double[] pt210 = getPoint(true);
991
				pt210 = getPoint(true);
934 992
				arc.setExtrusion(pt210);
993
			}else{
994
				pt210 = new double[]{1, 0, 0};
935 995
			}
936 996
			if((opts & 0x2) > 0){
937 997
				bb.order(ByteOrder.LITTLE_ENDIAN);
......
993 1053
				solid.getCorner3()[2] = db38;
994 1054
				solid.getCorner4()[2] = db38;
995 1055
			}
1056
			
1057
			solid.setExtrusion(new double[]{0, 0, 1});
996 1058
		}
997 1059
	}
998 1060
	
1061
	
1062
	private Block getBlock(String blockName){
1063
		for(int i = 0; i < blocks.size(); i++){
1064
			Block block = (Block) blocks.get(i);
1065
			if(block.name.equalsIgnoreCase(blockName)){
1066
				return block;
1067
			}
1068
		}
1069
		return null;
1070
	}
1071
	
1072
	
1073
	
999 1074
	class BlkReader implements EntityReader{
1000 1075
		public void read(ByteBuffer bb, byte flags, short opts, DwgObject dwgObj) {
1001 1076
			if(! (dwgObj instanceof DwgBlockHeader))
......
1007 1082
			blk.setBasePoint(pt10);
1008 1083
			String blockName = getString();
1009 1084
			
1085
			Block block = getBlock(blockName);
1086
			if(block == null){
1087
				System.out.println(blockName+" no encontrado en la tabla de bloques");
1088
			}
1089
			
1010 1090
			//TODO En DWG 12 no se distingue Block de BlockHeader, en ulteriores
1011 1091
			//versiones si
1012 1092
			//REVISAR EL CASO DE LOS BLOQUES
......
1068 1148
		}
1069 1149
	}
1070 1150
	class EndBlkReader implements EntityReader{
1071
		public void read(ByteBuffer bb, byte flags, short opts, DwgObject dwgObj) {}
1151
		public void read(ByteBuffer bb, byte flags, short opts, DwgObject dwgObj) {
1152
			System.out.println("endblk");
1153
		}
1072 1154
	}
1073 1155
	
1074 1156
	class InsertReader implements EntityReader{
......
1078 1160
			DwgInsert insert = (DwgInsert) dwgObj;
1079 1161
			
1080 1162
			bb.order(ByteOrder.nativeOrder());
1081
			short w1 = bb.getShort();
1163
			short w1 = bb.getShort();//Puede ser este el identificador de bloque???
1082 1164
			
1083
			
1084
			
1085 1165
			double[] pt10 = getPoint(false);
1086 1166
			insert.setInsertionPoint(pt10);
1087 1167
			
......
1131 1211
				double db45 = bb.getDouble();
1132 1212
				//row spacing
1133 1213
			}
1214
			insert.setExtrusion(new double[]{0, 0, 1});
1134 1215
		}
1135 1216
	}
1136 1217
	
......
1228 1309
			if((opts & 0x80) > 0){
1229 1310
				double[] p11 = getPoint(false);
1230 1311
			}
1231
			
1312
			double[] p210 = null;
1232 1313
			if((opts & 0x100) > 0){
1233
				double[] p210 = getPoint(true);
1314
				p210 = getPoint(true);
1315
			}else{
1316
				p210 = new double[]{0, 0, 1};
1234 1317
			}
1235 1318
			bb.order(ByteOrder.LITTLE_ENDIAN);
1236 1319
			if((opts & 0x200) > 0){
......
1365 1448
					((DwgPolyline2D)solution).setInitWidth(startW40);
1366 1449
				}
1367 1450
			}
1451
			
1452
			
1368 1453
			return solution;
1369 1454
		}
1370 1455
	}
......
1565 1650
		}
1566 1651
	}
1567 1652
	
1568
	
1569
	
1570 1653
	/**
1571 1654
	 * @param start
1572 1655
	 * @param end
......
1577 1660
		int emax = readers.size();
1578 1661
		EntityReader reader = null;
1579 1662
		
1663
		/*
1664
		 * it isnt null until well finish to read the vertices
1665
		 * of a given polyline (seqend found)
1666
		 * 
1667
		 */
1668
		IDwgPolyline currentPolyline = null;
1669
		
1670
		/*
1671
		 * Not null when a DwgBlock is found, it will be null
1672
		 * when a DwgEndBlk found. While this, all entities readed
1673
		 * will be added to currentBlock
1674
		 * */
1675
		DwgBlockHeader currentBlock = null;
1676
		
1580 1677
		while(ant < (end - 32)){
1581 1678
			bb.order(ByteOrder.LITTLE_ENDIAN);
1582 1679
			
......
1643 1740
							getInstance().
1644 1741
							create(kind, index);
1645 1742
				
1646
				DwgHandleReference hdl = null;
1647
				
1648
				
1649
				//TODO HANDLES. Tampoco se si en DWG 12 se leen 
1650
				//igual que en DWG 13 y posteriores		
1651
				if(handle != null){
1652
					int offset = handle.hashCode();
1653
					hdl = new DwgHandleReference(0, offset);
1654
				}else{
1655
					System.out.println("HANDLE A NULL");
1656
					bb.position(crcpos);
1657
					short crc = bb.getShort();
1658
					continue;
1659
				}
1660
				
1661 1743
				//TODO Idem con el espacio papel o el espacio modelo
1662 1744
				boolean paperSpace = false;
1663 1745
				if(paper != 0){
......
1668 1750
					entity = ((DefferedEntityReader)reader).getDwgObject(index);	
1669 1751
				}
1670 1752
				
1753
				if(entity instanceof IDwgPolyline){
1754
					currentPolyline = (IDwgPolyline) entity;
1755
				}
1756
				else if(entity instanceof DwgSeqend){
1757
					currentPolyline = null;
1758
				}else if(entity instanceof DwgBlockHeader){
1759
					currentBlock = (DwgBlockHeader) entity;
1760
				}else if(entity instanceof DwgEndblk){
1761
					currentBlock = null;
1762
				}
1763
				
1764
				DwgHandleReference hdl = null;
1765
				/*
1766
				In V12 format a handle has 2 bytes, while
1767
				in later formats a hande has 4 bytes. To avoid
1768
				rewriting a lot of code we are going to do some "tricks"
1769
				with handles.
1770
				*/
1771
				if(entity instanceof DwgBlockHeader){
1772
					/*
1773
					 * If entity is a block, in a later step we'll match
1774
					 * an insert with its block by handle.
1775
				     * In dwg 12 format, association insert-blocks is not
1776
				     * by handle (is from the order of the block in block table)
1777
				     * So here we use a little trick to avoid rewriting of
1778
				     * block and inserts management logic.
1779
					 * */
1780
					int order = -1;
1781
					DwgBlockHeader blk = (DwgBlockHeader) entity;
1782
					String blockName = blk.getName();
1783
					Block block = getBlock(blockName);
1784
					if(block != null){
1785
						order = blocks.indexOf(block);
1786
						hdl = new DwgHandleReference(0, order);
1787
					}else{
1788
						System.out.println("BLOQUE "+blockName+" NO EST? EN LA TABLA DE BLOQUES");
1789
						bb.position(crcpos);
1790
						short crc = bb.getShort();
1791
						continue;
1792
					}
1793
				}else{
1794
					if(handle != null){
1795
						int offset = handle.hashCode();
1796
						hdl = new DwgHandleReference(0, offset);
1797
					}else{
1798
						System.out.println("HANDLE A NULL");
1799
						bb.position(crcpos);
1800
						short crc = bb.getShort();
1801
						continue;
1802
					}
1803
				}
1804
				
1671 1805
				entity.setColor(color);
1672 1806
				entity.setType(type);//TODO Este type es el mismo que para DWG 13-14-2000?
1673 1807
				entity.setSizeInBits(lenght);//TODO Este size es el mismo que para DWG 13-14-2000?
......
1706 1840
				}
1707 1841
				short crc = bb.getShort();
1708 1842
				
1709
//				if(! paperSpace)//TODO solo a?adimos las entidades en espacio modelo????
1710
				dwgFile.addDwgObject(entity);
1711
				
1843
				if( (entity instanceof IDwgVertex) && (currentPolyline != null)){
1844
					currentPolyline.addVertex((IDwgVertex) entity);
1845
					
1846
				}else if( (entity instanceof IDwgBlockMember) && (currentBlock != null)){
1847
					currentBlock.addObject(entity);
1848
				} else{
1849
//					if(! paperSpace)//TODO solo a?adimos las entidades en espacio modelo????
1850
					dwgFile.addDwgObject(entity);
1851
				}
1712 1852
			}//if reader
1713 1853
			else{
1714 1854
				System.out.println("Reader a NULL. DWG 12 MAL LEIDO");
......
1856 1996
	//TODO Que se hacen con los registros que se leen???
1857 1997
	private void readBlockTable(Dwg12Table blockTable) {
1858 1998
		short size = blockTable.s1;
1859
		int numRecords = blockTable.i1;
1999
		int numRecords =  blockTable.i1;
1860 2000
		int start = blockTable.i2;
1861
		bb.position(start);
1862 2001
		
2002
		int begin = -1;
1863 2003
		int end = -1;
1864 2004
		
1865 2005
		for(int i = 0; i < numRecords; i++){
1866
			end = bb.position() + size;
2006
			
2007
			begin = start + i * size;
2008
			bb.position(begin);
2009
			
2010
			end = begin + size - 2;
2011
	
1867 2012
			byte flag = bb.get();
1868
			//TODO No estoy muy seguro de que esto sea
1869
			//igual que handle.read(32) en Python
1870 2013
			byte[] nameByte = new byte[32];
1871 2014
			bb.get(nameByte);
1872
			String name = new String(nameByte);
2015
			String name = new String(nameByte).trim();
1873 2016
			
1874 2017
			bb.order(ByteOrder.LITTLE_ENDIAN);
1875 2018
			
......
1877 2020
			byte b1 = bb.get();
1878 2021
			short w1 = bb.getShort();
1879 2022
			byte b2 = bb.get();
1880
			short w2 = bb.getShort();
2023
			
2024
			short w3 = bb.getShort();
1881 2025
			short crc = bb.getShort();
1882 2026
		
1883 2027
			int offset = end - bb.position();
1884 2028
			if(offset > 0)
1885 2029
				bb.position(bb.position() + end);
1886
		}
2030
			
2031
			Block block = new Block();
2032
			block.flag = flag;
2033
			block.name = name;
2034
			block.used = used;
2035
			block.b1 = b1;
2036
			block.w1 = w1;
2037
			block.b2 = b2;
2038
			block.w3 = w3;
2039
			block.crc = crc;
2040
			blocks.add(block);
2041
		}//for
1887 2042
		byte[] crc32 = new byte[32];
1888 2043
		bb.get(crc32);
1889 2044
	}
trunk/libraries/libDwg/src/com/iver/cit/jdwglib/dwg/IDwgPolyline.java
45 45
*
46 46
* $Id$
47 47
* $Log$
48
* Revision 1.3  2007-01-30 12:37:18  azabala
48
* Revision 1.4  2007-03-06 19:39:38  azabala
49
* Changes to adapt dwg 12 to general architecture
50
*
51
* Revision 1.3  2007/01/30 12:37:18  azabala
49 52
* *** empty log message ***
50 53
*
51 54
* Revision 1.2  2007/01/18 13:35:22  azabala
......
68 71
 * un Hashtable handle->dwgObject, no se pasar?
69 72
 * */
70 73
public interface IDwgPolyline {
71
//	public void calculateGisModel(List dwgObjs);
72 74
	public void calculateGisModel(DwgFile dwgFile);
75
	public void addVertex(IDwgVertex vertex);
73 76
}
74 77

  
trunk/libraries/libDwg/src/com/iver/cit/jdwglib/dwg/objects/DwgLwPolyline.java
35 35
package com.iver.cit.jdwglib.dwg.objects;
36 36

  
37 37
import java.awt.geom.Point2D;
38
import java.util.ArrayList;
38 39
import java.util.List;
39 40
import java.util.Map;
40 41

  
......
47 48
import com.iver.cit.jdwglib.dwg.IDwgBlockMember;
48 49
import com.iver.cit.jdwglib.dwg.IDwgExtrusionable;
49 50
import com.iver.cit.jdwglib.dwg.IDwgPolyline;
51
import com.iver.cit.jdwglib.dwg.IDwgVertex;
50 52
import com.iver.cit.jdwglib.util.AcadExtrusionCalculator;
51 53
import com.iver.cit.jdwglib.util.FMapUtil;
52 54
import com.iver.cit.jdwglib.util.GisModelCurveCalculator;
......
59 61
public class DwgLwPolyline extends DwgObject 
60 62
	implements IDwgPolyline, IDwgExtrusionable, 
61 63
	IDwg3DTestable, IDwg2FMap, IDwgBlockMember{
62
	public DwgLwPolyline(int index) {
63
		super(index);
64
		// TODO Auto-generated constructor stub
65
	}
64
	
66 65
	private int flag;
67 66
	private double constWidth;
68 67
	private double elevation;
69 68
	private double thickness;
70 69
	private double[] normal;
71
	private Point2D[] vertices;
70
	private List vertices;
72 71
	/*
73 72
	 *The bulge is the tangent of 1/4 of the included angle for the arc 
74 73
	 *between the selected vertex and the next vertex in the polyline's vertex list. 
......
83 82
	private double[][] widths;
84 83
	
85 84
	
85
	public DwgLwPolyline(int index) {
86
		super(index);
87
		vertices = new ArrayList();
88
	}
86 89
	/**
87 90
	 * @return Returns the bulges.
88 91
	 */
......
110 113
	/**
111 114
	 * @return Returns the vertices.
112 115
	 */
113
	public Point2D[] getVertices() {
116
	public List getVertices() {
114 117
		return vertices;
115 118
	}
116 119
	/**
117 120
	 * @param vertices The vertices to set.
118 121
	 */
119
	public void setVertices(Point2D[] vertices) {
122
	public void setVertices(List vertices) {
120 123
		this.vertices = vertices;
121 124
	}
122 125
    /**
......
215 218
		if (getVertices() == null)
216 219
			return;
217 220
		int flags = getFlag();
218
		Point2D[] pts = getVertices();
221
		List pts = getVertices();
219 222
		double[] bulges = getBulges();
220
		Point2D[] newPts = new Point2D[pts.length];
223
		List newPts = new ArrayList();
221 224
		double[] newBulges = null;
222 225
		if(bulges != null){
223 226
			newBulges = new double[bulges.length];
224 227
			System.arraycopy(bulges, 0, newBulges, 0, bulges.length);
225 228
		}else{
226
			bulges = new double[pts.length ];
229
			bulges = new double[pts.size() ];
227 230
			newBulges = new double[bulges.length];
228 231
			//dwg spec says numVertex (numSegments + 1)
229 232
			//TODO Check this
......
235 238
		// TODO: Aqu? pueden existir casos no contemplados ...
236 239
//        System.out.println("flags = " + flags);
237 240
        if (flags==512 || flags==776 || flags==768) {//closed
238
			newPts = new Point2D[pts.length+1];
239 241
			newBulges = new double[bulges.length+1];
240
			for (int j=0;j<pts.length;j++) {
241
				newPts[j] = (Point2D)pts[j];
242
			for (int j=0;j<pts.size();j++) {
243
				newPts.add(pts.get(j));
242 244
			}
243
			newPts[pts.length] = (Point2D)pts[0];
244
			newBulges[pts.length] = 0;
245
			newPts.add(pts.get(0));
246
			newBulges[pts.size()] = 0;
245 247
		} else {
246
			for (int j=0;j<pts.length;j++) {
247
				newPts[j] = (Point2D)pts[j];
248
			for (int j=0;j<pts.size();j++) {
249
				newPts.add(pts.get(j));
248 250
			}
249 251
		}
250
		if (pts.length>0) {
252
		if (newPts.size() > 0) {
251 253
			setBulges(newBulges);
252
			Point2D[] points = GisModelCurveCalculator.calculateGisModelBulge(newPts, newBulges);
254
			List points = GisModelCurveCalculator.calculateGisModelBulge(newPts, newBulges);
253 255
			setVertices(points);
254
		} else {
255
//			System.out.println("Encontrada polil?nea sin puntos ...");
256
			// TODO: No se debe mandar nunca una polil?nea sin puntos, si esto
257
			// ocurre es porque existe un error que hay que corregir ...
258
		}
256
		} 
257
//		if (pts.size() > 0) {
258
//			setBulges(newBulges);
259
//			List points = GisModelCurveCalculator.calculateGisModelBulge(newPts, newBulges);
260
//			setVertices(points);
261
//		} 
262
//		else {
263
////			System.out.println("Encontrada polil?nea sin puntos ...");
264
//			// TODO: No se debe mandar nunca una polil?nea sin puntos, si esto
265
//			// ocurre es porque existe un error que hay que corregir ...
266
//		}
259 267
	}
260 268
	/* (non-Javadoc)
261 269
	 * @see com.iver.cit.jdwglib.dwg.IDwgExtrusionable#applyExtrussion()
......
263 271
	public void applyExtrussion() {
264 272
		if (getVertices() == null)
265 273
			return;
266
		 Point2D[] vertices = getVertices();
274
		 List vertices = getVertices();
267 275
         double[] lwPolylineExt = getNormal();
268 276
         // Normals and Extrusions aren`t the same
269 277
         if (lwPolylineExt[0]==0 && lwPolylineExt[1]==0 && lwPolylineExt[2]==0) 
270 278
        	 lwPolylineExt[2] = 1.0;
271 279
         
272 280
         double elev = getElevation();
273
         double[][] lwPolylinePoints3D = new double[vertices.length][3];
274
         for (int j=0;j<vertices.length;j++) {
275
             lwPolylinePoints3D[j][0] = vertices[j].getX();
276
             lwPolylinePoints3D[j][1] = vertices[j].getY();
277
             lwPolylinePoints3D[j][2] = elev;
278
             lwPolylinePoints3D[j] = AcadExtrusionCalculator.extrude2(lwPolylinePoints3D[j], lwPolylineExt);
281
         List lwPolylinePoints3D = new ArrayList();
282
         for (int j=0;j<vertices.size();j++) {
283
        	 double[] point = new double[3];
284
             point[0] = ((double[])vertices.get(j))[0];
285
             point[1] = ((double[])vertices.get(j))[1];
286
             point[2] = elev;
287
             lwPolylinePoints3D.add(AcadExtrusionCalculator.
288
            		 extrude2(point, lwPolylineExt));
279 289
         }
280 290
         setElevation(elev);
281
         for (int j=0;j<vertices.length;j++) {
282
             vertices[j] = new Point2D.Double(lwPolylinePoints3D[j][0], lwPolylinePoints3D[j][1]);
291
         List newVertices = new ArrayList();
292
         for (int j=0;j<vertices.size();j++) {
293
        	 double[] point = (double[]) lwPolylinePoints3D.get(j);
294
             newVertices.add(new double[]{point[0], point[1]});
283 295
         }
284
         setVertices(vertices);
296
         setVertices(newVertices);
285 297
	}
286 298
	/* (non-Javadoc)
287 299
	 * @see com.iver.cit.jdwglib.dwg.IDwg3DTestable#has3DData()
......
294 306
	}
295 307
	public FShape toFMapGeometry(boolean is3DFile) {
296 308
		FPolyline2D lwpline = null;
297
		Point2D[] pts = getVertices();
309
		List pts = getVertices();
298 310
		double elev = getElevation();
299
		if (pts != null) {
311
		if (pts != null && pts.size() > 0) {
300 312
			
301 313
			if (is3DFile) {
302
				double[][] pline3D = new double[pts.length][3];
303
				for (int j = 0; j < pts.length; j++) {
304
					pline3D[j][0] = pts[j].getX();
305
					pline3D[j][1] = pts[j].getY();
306
					pline3D[j][2] = elev;
314
				List pline3D = new ArrayList();
315
				for (int j = 0; j < pts.size(); j++) {
316
					double[] pt = new double[3];
317
					pt[0] = ((double[])pts.get(j))[0];
318
					pt[1] = ((double[])pts.get(j))[1];
319
					pt[2] = elev;
320
					pline3D.add(pt);
307 321
				}
308 322
				lwpline = FMapUtil.points3DToFPolyline3D(pline3D);
309 323
			} else {
......
330 344
			List dwgObjectsWithoutBlocks, 
331 345
			Map handleObjWithoutBlocks, DwgFile callBack) {
332 346
		DwgLwPolyline transformedEntity = null;
333
		Point2D[] vertices = this.getVertices();
347
		List vertices = this.getVertices();
334 348
		if (vertices!=null) {
335
		    Point2D[] transformedVertices = new Point2D[vertices.length];
336
			for (int i=0;i<vertices.length;i++) {
337
			    Point2D pointAux = new Point2D.Double(vertices[i].getX() - bPoint[0], vertices[i].getY() - bPoint[1]);
338
				double laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(rot) + (pointAux.getY()*scale[1])*(-1)*Math.sin(rot));
339
				double laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(rot) + (pointAux.getY()*scale[1])*Math.cos(rot));
340
				transformedVertices[i] = new Point2D.Double(laX, laY);
349
		    List transformedVertices = new ArrayList();
350
			for (int i=0; i< vertices.size(); i++) {
351
				double[] point = (double[]) vertices.get(i);
352
				double[] pointAux = new double[]{point[0] - bPoint[0], 
353
							point[1] - bPoint[1]};
354
				double laX = insPoint.getX() + ((pointAux[0]*scale[0])*Math.cos(rot) + (pointAux[1]*scale[1])*(-1)*Math.sin(rot));
355
				double laY = insPoint.getY() + ((pointAux[0]*scale[0])*Math.sin(rot) + (pointAux[1]*scale[1])*Math.cos(rot));
356
				transformedVertices.add(new double[]{laX, laY});
341 357
			}
342 358
			transformedEntity = (DwgLwPolyline)this.clone();
343 359
			transformedEntity.setVertices(transformedVertices);
......
369 385
		myObj.setWidths(widths);
370 386

  
371 387
	}
388
	public void addVertex(IDwgVertex vertex) {
389
		vertices.add(vertex.getPoint());
390
		
391
	}
372 392

  
373 393
}
trunk/libraries/libDwg/src/com/iver/cit/jdwglib/dwg/objects/DwgCircle.java
35 35
package com.iver.cit.jdwglib.dwg.objects;
36 36

  
37 37
import java.awt.geom.Point2D;
38
import java.util.ArrayList;
38 39
import java.util.List;
39 40
import java.util.Map;
40 41

  
......
57 58
 */
58 59
public class DwgCircle extends DwgObject
59 60
	implements IDwgExtrusionable, IDwg3DTestable, IDwg2FMap, IDwgBlockMember{
60
	public DwgCircle(int index) {
61
		super(index);
62
		// TODO Auto-generated constructor stub
63
	}
61
	
64 62
	private double[] center;
65 63
	private double radius;
66 64
	private double thickness;
67 65
	private double[] extrusion;
68 66
	
67
	
68
	public DwgCircle(int index) {
69
		super(index);
70
	}
69 71
	/**
70 72
	 * @return Returns the center.
71 73
	 */
......
168 170
		double[] c = getCenter();
169 171
		Point2D center = new Point2D.Double(c[0], c[1]);
170 172
		double radius = getRadius();
171
		Point2D[] arc = GisModelCurveCalculator
173
		List arc = GisModelCurveCalculator
172 174
				.calculateGisModelCircle(center, radius);
173 175
		if (is3DFile) {
174
			double[][] arc3D = new double[arc.length][3];
175
			for (int j = 0; j < arc.length; j++) {
176
				arc3D[j][0] = arc[j].getX();
177
				arc3D[j][1] = arc[j].getY();
178
				arc3D[j][2] = c[2];
176
			List arc3D = new ArrayList();
177
			for (int j = 0; j < arc.size(); j++) {
178
				double[] pt2d = (double[]) arc.get(j);
179
				double[] pt3d = new double[]{ pt2d[0], pt2d[1], c[2] };
180
				arc3D.add(pt3d);
179 181
			}
180 182
			arcc = FMapUtil.points3DToFPolyline3D(arc3D);
181 183
		} else {
trunk/libraries/libDwg/src/com/iver/cit/jdwglib/dwg/objects/DwgMeshPolyline.java
45 45
*
46 46
* $Id$
47 47
* $Log$
48
* Revision 1.2  2007-03-02 20:31:22  azabala
48
* Revision 1.3  2007-03-06 19:39:38  azabala
49
* Changes to adapt dwg 12 to general architecture
50
*
51
* Revision 1.2  2007/03/02 20:31:22  azabala
49 52
* *** empty log message ***
50 53
*
51 54
* Revision 1.1  2007/03/01 19:58:53  azabala
......
64 67

  
65 68
import java.awt.geom.Point2D;
66 69
import java.util.ArrayList;
70
import java.util.List;
67 71

  
68 72
import com.iver.cit.gvsig.fmap.core.FShape;
69 73
import com.iver.cit.jdwglib.dwg.DwgFile;
......
71 75
import com.iver.cit.jdwglib.dwg.DwgObject;
72 76
import com.iver.cit.jdwglib.dwg.IDwg2FMap;
73 77
import com.iver.cit.jdwglib.dwg.IDwgPolyline;
78
import com.iver.cit.jdwglib.dwg.IDwgVertex;
74 79
import com.iver.cit.jdwglib.util.GisModelCurveCalculator;
75 80

  
76 81
/**
......
128 133
	/**
129 134
	 * Vertices of the mesh
130 135
	 * */
131
	private DwgVertexMesh[] vertices;
136
	private List vertices;
132 137
	
133 138
	
134 139
	
......
320 325
		return "Polyline MESH";
321 326
	}
322 327

  
323
	public DwgVertexMesh[] getVertices() {
328
	public List getVertices() {
324 329
		return vertices;
325 330
	}
326 331

  
327
	public void setVertices(DwgVertexMesh[] vertices) {
332
	public void setVertices(List vertices) {
328 333
		this.vertices = vertices;
329 334
	}
330 335

  
......
354 359
		
355 360
	}
356 361

  
362
	public void addVertex(IDwgVertex vertex) {
363
		vertices.add(vertex.getPoint());
364
		
365
	}
366

  
357 367
}
358 368

  
trunk/libraries/libDwg/src/com/iver/cit/jdwglib/dwg/objects/DwgPolyline2D.java
49 49
import com.iver.cit.jdwglib.dwg.IDwgBlockMember;
50 50
import com.iver.cit.jdwglib.dwg.IDwgExtrusionable;
51 51
import com.iver.cit.jdwglib.dwg.IDwgPolyline;
52
import com.iver.cit.jdwglib.dwg.IDwgVertex;
52 53
import com.iver.cit.jdwglib.util.AcadExtrusionCalculator;
53 54
import com.iver.cit.jdwglib.util.FMapUtil;
54 55
import com.iver.cit.jdwglib.util.GisModelCurveCalculator;
......
62 63
	implements IDwgPolyline, IDwgExtrusionable, IDwg3DTestable, IDwg2FMap, IDwgBlockMember{
63 64
	
64 65
	
65
	public DwgPolyline2D(int index) {
66
		super(index);
67
		// TODO Auto-generated constructor stub
68
	}
66
	
69 67
	private int flags;
70 68
	private int curveType;
71 69
	private double initWidth;
......
76 74
	private DwgHandleReference firstVertexHandle = null;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff