Revision 29001 branches/v2_0_0_prep/libraries/libDwg/src-test/org/gvsig/dwg/lib/DwgFileTest.java

View differences:

DwgFileTest.java
1 1
package org.gvsig.dwg.lib;
2 2

  
3
import java.awt.geom.Point2D;
4 3
import java.io.File;
5
import java.io.FileInputStream;
6
import java.io.FileNotFoundException;
7 4
import java.io.IOException;
8 5
import java.net.URL;
9
import java.nio.ByteBuffer;
10
import java.nio.ByteOrder;
11
import java.nio.channels.FileChannel;
12
import java.util.LinkedList;
13
import java.util.List;
14 6

  
15
import org.gvsig.dwg.lib.CorruptedDwgEntityException;
16
import org.gvsig.dwg.lib.DwgVersionNotSupportedException;
17
import org.gvsig.dwg.lib.readers.DwgFileV15Reader;
18
import org.gvsig.dwg.lib.readers.IDwgFileReader;
19
import org.gvsig.dwg.lib.util.AcadExtrusionCalculator;
20

  
21

  
22 7
import junit.framework.TestCase;
23 8

  
24 9
public class DwgFileTest extends TestCase {
......
26 11

  
27 12
	protected void setUp() throws Exception {
28 13
		super.setUp();
29
		URL url = this.getClass().getResource("DwgFileTest_data");
30
		if (url == null) 
31
			throw new Exception("Can't find 'DwgFileTest_data' dir");
32
		
14
		URL url = this.getClass().getResource("data");
15
		if (url == null) {
16
			throw new Exception("Can't find 'data' dir");
17
		}
18

  
33 19
		baseDataPath = new File(url.getFile());
34
		if (!baseDataPath.exists()) 
35
			throw new Exception("Can't find 'DwgFileTest_data' dir");
36
		
20
		if (!baseDataPath.exists()) {
21
			throw new Exception("Can't find 'data' dir");
22
		}
23

  
37 24
	}
38 25

  
39 26
	protected void tearDown() throws Exception {
......
48 35
//		dwg.blockManagement();
49 36
//		LinkedList dwgObjects = dwg.getDwgObjects();
50 37
	}
51
	
38

  
52 39
	public void test2() throws RuntimeException, CorruptedDwgEntityException{
53 40
        //Dwg Object that is supposed to be
54 41
        //an LWPOLYLINE in V14 version
......
96 83
//        bitPos = ((Integer) val.get(0)).intValue();
97 84
//        int type = ((Integer) val.get(1)).intValue();
98 85
//        System.out.println("type = " + type);
99
//       
86
//
100 87
//        DwgHandleReference hr = new DwgHandleReference();
101 88
//        bitPos = hr.read(data, bitPos);
102 89
//        System.out.println("handle, code="+
103 90
//                    hr.getCode()+
104 91
//                    " ,offset="+
105 92
//                    hr.getOffset());
106
//       
93
//
107 94
//        //Ahora pasamos a la extended data
108 95
//        val = DwgUtil.getBitShort(data, bitPos);
109 96
//        bitPos = ((Integer) val.get(0)).intValue();
110 97
//        int extendedDataSize = ((Integer) val.get(1)).intValue();
111 98
//        System.out.println("EED size="+extendedDataSize);
112 99
//        //como el size es 0, me lo salto
113
//       
100
//
114 101
//        //ver si tiene datos graficos
115 102
//        val = DwgUtil.testBit(data, bitPos);
116 103
//        bitPos = ((Integer) val.get(0)).intValue();
117 104
//        boolean hasGraphicsData = ((Boolean) val.get(1))
118 105
//                .booleanValue();
119 106
//        System.out.println("graphics = "+hasGraphicsData);
120
//       
107
//
121 108
//        //como se que no hay graphics me lo salto
122 109
//        //tama?o en bits
123 110
//        val = DwgUtil.getRawLong(data, bitPos);
124 111
//        bitPos = ((Integer) val.get(0)).intValue();
125 112
//        int sizeInBits = ((Integer) val.get(1)).intValue();
126 113
//        System.out.println("sizeInBits = "+sizeInBits);
127
//        
114
//
128 115
//        /*
129 116
//         * Ahora, lo que viene es lo que en la spec se dice
130 117
//         * "Common entity data". Revisar bien pues PythonCAD no lo lee
131 118
//         * como en la spec.
132
//         * 
119
//         *
133 120
//         * pag 42.
134 121
//          R13-R14 Only:
135 122
//          	RL	:	Size of object data in bits
136 123
//          	6B	:	Flags (FEDCBA)
137 124
//          	6B	:	Common parameters (CCSSII)
138 125
//          	Segun esto, deberia leer 6 bits y 6 bits
139
//          	
126
//
140 127
//          	FLAGS
141 128
//	      	Mas adelante (pag 43), dice:
142
//	      	DC	:	This is the number of reactors attached to an 
143
//	      	entity as a bitshort. 
144
//	      	This feature may have been dormant in R13, 
129
//	      	DC	:	This is the number of reactors attached to an
130
//	      	entity as a bitshort.
131
//	      	This feature may have been dormant in R13,
145 132
//	      	but it appears in R14, and in files saved as R13 by R14.
146
//	      	
133
//
147 134
//	      	Ahora bien, pythoncad las est? leyendo como bitLong
148 135
//          	?En que quedamos, son 2 bits, 1 bitLong o 1 bitShort?
149 136
//          	TODO REVISAR
150
//          	
137
//
151 138
//          	COMMON PARAMETERS
152 139
//          	Al principio, dice que son 6 bits (CC, SS, II)
153 140
//          	pero luego dice (pag 43):
......
157 144
//
158 145
//			Pythoncad, en vez de como 2 bits, los est? leyendo
159 146
//			como BitShort, BitDouble y BitShort
160
//          	
147
//
161 148
//         * */
162
//        
149
//
163 150
//        Integer mode = (Integer) DwgUtil.getBits(data, 2, bitPos);
164 151
//		bitPos += 2;
165 152
//		System.out.println("mode = "+mode);
166
//		
153
//
167 154
//	/*
168 155
//		val = DwgUtil.getBitLong(data, bitPos);
169 156
//		bitPos = ((Integer) val.get(0)).intValue();
......
174 161
//		bitPos = ((Integer) val.get(0)).intValue();
175 162
//		int rnum = ((Integer) val.get(1)).intValue();
176 163
//		System.out.println("numReactors = "+rnum);
177
//		
178
//		
164
//
165
//
179 166
//		val = DwgUtil.testBit(data, bitPos);
180 167
//		bitPos = ((Integer) val.get(0)).intValue();
181 168
//		boolean isLyrByLineType = ((Boolean) val.get(1)).booleanValue();
182 169
//		System.out.println("isLyrByLineType="+isLyrByLineType);
183
//		
170
//
184 171
//		val = DwgUtil.testBit(data, bitPos);
185 172
//		bitPos = ((Integer) val.get(0)).intValue();
186 173
//		boolean noLinks = ((Boolean) val.get(1)).booleanValue();
187 174
//		System.out.println("noLinks="+noLinks);
188 175
//
189
//		
176
//
190 177
//		val = DwgUtil.getBitShort(data, bitPos);
191 178
//		bitPos = ((Integer) val.get(0)).intValue();
192 179
//		int color = ((Integer) val.get(1)).intValue();
193 180
//		System.out.println("color="+color);
194
//		
195
//		
181
//
182
//
196 183
//		val = DwgUtil.getBitDouble(data, bitPos);
197 184
//		bitPos = ((Integer) val.get(0)).intValue();
198 185
//		float ltscale = ((Double) val.get(1)).floatValue();
199 186
//		System.out.println("ltscale="+ltscale);
200
//		
187
//
201 188
//		val = DwgUtil.getBitShort(data, bitPos);
202 189
//		bitPos = ((Integer) val.get(0)).intValue();
203 190
//		int invis = ((Integer) val.get(1)).intValue();
204 191
//		System.out.println("invis="+invis);
205
//		
192
//
206 193
//		val = DwgUtil.getBitShort(data, bitPos);
207 194
//		bitPos = ((Integer) val.get(0)).intValue();
208 195
//		int flag = ((Integer) val.get(1)).intValue();
209 196
//		System.out.println("flag="+flag);
210
//		
197
//
211 198
//		double dVal = 0d;
212 199
//		if((flag & 0x4) > 0){
213 200
//			val = DwgUtil.getBitDouble(data, bitPos);
......
215 202
//			dVal = ((Double) val.get(1)).doubleValue();
216 203
//		}
217 204
//		System.out.println("constWidth="+dVal);
218
//		
205
//
219 206
//		dVal = 0d;
220 207
//		if((flag & 0x8) > 0){
221 208
//			val = DwgUtil.getBitDouble(data, bitPos);
......
223 210
//			dVal = ((Double) val.get(1)).doubleValue();
224 211
//		}
225 212
//		System.out.println("elevation="+dVal);
226
//		
213
//
227 214
//		dVal = 0d;
228 215
//		if ((flag & 0x2) > 0){
229 216
//			val = DwgUtil.getBitDouble(data, bitPos);
......
231 218
//			dVal = ((Double) val.get(1)).doubleValue();
232 219
//		}
233 220
//		System.out.println("thickness="+dVal);
234
//		
221
//
235 222
//		double x, y, z ;
236 223
//		x = 0d;
237
//		y = 0d; 
224
//		y = 0d;
238 225
//		z = 0d;
239
//		
226
//
240 227
//		if ((flag & 0x1) > 0){
241 228
//			val = DwgUtil.getBitDouble(data, bitPos);
242 229
//			bitPos = ((Integer) val.get(0)).intValue();
243 230
//			x = ((Double) val.get(1)).doubleValue();
244
//			
231
//
245 232
//			val = DwgUtil.getBitDouble(data, bitPos);
246 233
//			bitPos = ((Integer) val.get(0)).intValue();
247 234
//			y = ((Double) val.get(1)).doubleValue();
248
//			
235
//
249 236
//			val = DwgUtil.getBitDouble(data, bitPos);
250 237
//			bitPos = ((Integer) val.get(0)).intValue();
251 238
//			z = ((Double) val.get(1)).doubleValue();
252 239
//		}
253 240
//		System.out.println("normal="+x+","+y+","+z);
254
//		
241
//
255 242
//		val = DwgUtil.getBitLong(data, bitPos);
256 243
//		bitPos = ((Integer) val.get(0)).intValue();
257 244
//		int np = ((Integer) val.get(1)).intValue();
258 245
//		System.out.println("numPoints="+np);
259
//		
246
//
260 247
//		int nb = 0;
261 248
//		if((flag & 0x10) > 0){
262 249
//			val = DwgUtil.getBitLong(data, bitPos);
......
277 264
//				val = DwgUtil.getRawDouble(data, bitPos);
278 265
//				bitPos = ((Integer) val.get(0)).intValue();
279 266
//				x = ((Double) val.get(1)).doubleValue();
280
//				
267
//
281 268
//				val = DwgUtil.getRawDouble(data, bitPos);
282 269
//				bitPos = ((Integer) val.get(0)).intValue();
283 270
//				y = ((Double) val.get(1)).doubleValue();
284
//				
271
//
285 272
//				points[i] = new Point2D.Double(x, y);
286 273
//				System.out.println("Punto"+i+"="+x+","+y);
287 274
//			}//for
288 275
//		}//if np
289
//		
276
//
290 277
//		if(nb > 0){
291 278
//			double[] bulges = new double[nb];
292 279
//			for(int i = 0; i < nb; i++){
......
295 282
//				bulges[i] = ((Double) val.get(1)).doubleValue();
296 283
//				System.out.println("Bulge"+i+"="+bulges[i]);
297 284
//			}//for
298
//			
285
//
299 286
//		}//if nb
300
//		
287
//
301 288
//		if(nw > 0){
302 289
//			double[][] widths = new double[nw][2];
303 290
//			for(int i = 0; i < nw; i++){
304 291
//				val = DwgUtil.getBitDouble(data, bitPos);
305 292
//				bitPos = ((Integer) val.get(0)).intValue();
306 293
//				double sw = ((Double) val.get(1)).doubleValue();
307
//				
294
//
308 295
//				val = DwgUtil.getBitDouble(data, bitPos);
309 296
//				bitPos = ((Integer) val.get(0)).intValue();
310 297
//				double ew = ((Double) val.get(1)).doubleValue();
311
//				
298
//
312 299
//				widths[i][0] = sw;
313 300
//				widths[i][1] = ew;
314 301
//				System.out.println("Width"+i+"="+sw+","+ew);
315 302
//			}//for
316 303
//		}
317 304
     }
318
	
305

  
319 306
	public void test3(){
320 307
		//test of extrusion
321 308
		double[] coord = null;
322 309
		double[] extrusion = null;
323 310
		double[] extrusion2 = new double[]{0, 0, 1};
324
		
311

  
325 312
		coord = new double[]{790089.65, 4477974.75, 9.560000000114087};
326 313
		extrusion = new double[]{-0.5037965987025721, 0.07005064807841195, 0.8609772899673451};
327 314
		//1. algoritmo original, vector normal distinto
328
//		double[] newCoord = AcadExtrusionCalculator.extrude(coord, extrusion); 
329
//		newCoord = AcadExtrusionCalculator.extrude3(coord, extrusion); 
330
//		
315
//		double[] newCoord = AcadExtrusionCalculator.extrude(coord, extrusion);
316
//		newCoord = AcadExtrusionCalculator.extrude3(coord, extrusion);
317
//
331 318
		//2? ahora con vector normal coincidente con eje Z
332
//		newCoord = AcadExtrusionCalculator.extrude(coord, extrusion2); 
333
//		newCoord = AcadExtrusionCalculator.extrude3(coord, extrusion2); 
319
//		newCoord = AcadExtrusionCalculator.extrude(coord, extrusion2);
320
//		newCoord = AcadExtrusionCalculator.extrude3(coord, extrusion2);
334 321
	}
335 322
}

Also available in: Unified diff