Revision 10821

View differences:

trunk/libraries/libDwg/src-test/com/iver/cit/jdwglib/dwg/DwgFileTest.java
1 1
package com.iver.cit.jdwglib.dwg;
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 6
import java.util.List;
14 7

  
15
import com.iver.cit.jdwglib.dwg.readers.DwgFileV15Reader;
16
import com.iver.cit.jdwglib.dwg.readers.IDwgFileReader;
17
import com.iver.cit.jdwglib.util.AcadExtrusionCalculator;
18

  
19 8
import junit.framework.TestCase;
20 9

  
10
import com.iver.cit.jdwglib.dwg.objects.DwgPFacePolyline;
11

  
21 12
public class DwgFileTest extends TestCase {
22 13
	private File baseDataPath;
23 14

  
24 15
	protected void setUp() throws Exception {
25 16
		super.setUp();
26 17
		URL url = this.getClass().getResource("DwgFileTest_data");
27
		if (url == null) 
18
		if (url == null)
28 19
			throw new Exception("Can't find 'DwgFileTest_data' dir");
29
		
20

  
30 21
		baseDataPath = new File(url.getFile());
31
		if (!baseDataPath.exists()) 
22
		if (!baseDataPath.exists())
32 23
			throw new Exception("Can't find 'DwgFileTest_data' dir");
33
		
24

  
34 25
	}
35 26

  
36 27
	protected void tearDown() throws Exception {
37 28
		super.tearDown();
38 29
	}
30

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

  
315 41
	/*
316
	  0
317
LWPOLYLINE
318
  5
319
67A3
320
330
321
14B33
322
100
323
AcDbEntity
324
  8
325
51
326
  6
327
Continuous
328
 62
329
     1
330
100
331
AcDbPolyline
332
 90
333
        2
334
 70
335
     0
336
 43
337
0.05
338
 38
339
3687388.508636616
340
 10
341
2615813.541238185
342
 20
343
31.11
344
 10
345
2615809.722835378
346
 20
347
31.13
348
210
349
0.7097208274403748
350
220
351
0.704483035350994
352
230
353
0.0 
42
	 * 0 LWPOLYLINE 5 67A3 330 14B33 100 AcDbEntity 8 51 6 Continuous 62 1 100
43
	 * AcDbPolyline 90 2 70 0 43 0.05 38 3687388.508636616 10 2615813.541238185
44
	 * 20 31.11 10 2615809.722835378 20 31.13 210 0.7097208274403748 220
45
	 * 0.704483035350994 230 0.0
46
	 * 
47
	 */
48
	// test of extrusion
49
	public void test3() {
50
		// test of extrusion
51
		// double[] coord = null;
52
		// double[] extrusion = null;
53
		// double[] extrusion2 = new double[]{0, 0, 1};
354 54

  
355
	 * */
356
	public void test3(){
357
		//test of extrusion
358
//		double[] coord = null;
359
//		double[] extrusion = null;
360
//		double[] extrusion2 = new double[]{0, 0, 1};
361
		
362
//	
55
		//	
363 56
	}
364
	
365
	//test of DWG 12 format
366
	public void test4() throws IOException, DwgVersionNotSupportedException{
367
		String fileName = baseDataPath.getAbsolutePath()+"/torre02_12.dwg";
57

  
58
	// test of DWG 12 format
59
	public void test4() throws IOException, DwgVersionNotSupportedException {
60
		String fileName = baseDataPath.getAbsolutePath() + "/TORRE03.DWG";
368 61
		DwgFile dwg = new DwgFile(fileName);
369 62
		dwg.read();
370 63
		dwg.calculateGisModelDwgPolylines();
371
		dwg.blockManagement2();
64
		//antes de los bloques
372 65
		List dwgObjects = dwg.getDwgObjects();
66
		dwg.blockManagement2();
67
		//despues de los bloques
68
		dwgObjects = dwg.getDwgObjects();
69
		for(int i = 0; i < dwgObjects.size(); i++){
70
			DwgObject o = (DwgObject) dwgObjects.get(i);
71
			if(o instanceof IDwg2FMap){
72
				((IDwg2FMap)o).toFMapGeometry(true);
73
			}
74
		}
373 75
	}
76

  
77

  
78
	// test of block transform
79
	public void test5() {
80
		// datos del bloque
81
//		double[] insertionPoint = new double[] { 775183.239, 4453869.608, 0 };
82
//		double[] scale = new double[] { 0.20, 0.20, 5.512 };
83
//		double rotation = 0.2;
84
//		double[] basePoint = new double[] { 0, 0, 0 };
85
//
86
//		double[] p1 = new double[] { -4.7, 2.3, 0 };
87
//		double[] p2 = new double[] { -3.75, 0.6, 0 };
88
//		double[] p3 = new double[] { -1.8, -0.15, 0 };
89
//		double[] p4 = new double[] { 0, 0, 0 };
90
//
91
//		// a) Metodo actual
92
//		Point2D p11 = new Point2D.Double(p1[0], p1[1]);
93
//		Point2D p21 = new Point2D.Double(p2[0], p2[1]);
94
//		Point2D p31 = new Point2D.Double(p3[0], p3[1]);
95
//		Point2D p41 = new Point2D.Double(p4[0], p4[1]);
96
//
97
//		java.awt.geom.AffineTransform affineTrans = new java.awt.geom.AffineTransform();
98
//		affineTrans.translate(insertionPoint[0], insertionPoint[1]);
99
//		affineTrans.rotate(rotation);
100
//		affineTrans.scale(scale[0], scale[1]);
101
//
102
//		Point2D newP2d1 = affineTrans.transform(p11, null);
103
//		Point2D newP2d2 = affineTrans.transform(p21, null);
104
//		Point2D newP2d3 = affineTrans.transform(p31, null);
105
//		Point2D newP2d4 = affineTrans.transform(p41, null);
106
		
107
		
108
		
109
//        com.iver.cit.jdwglib.util.Matrix4D scaleMat = new com.iver.cit.jdwglib.util.Matrix4D(scale[0], 0.0F, 0.0F, 0.0F, 
110
//        								0.0F, scale[1], 0.0F, 0.0F, 
111
//        								0.0F, 0.0F, scale[2], 0.0F, 
112
//        								0.0F, 0.0F, 0.0F, 1.0F);
113
//        com.iver.cit.jdwglib.util.Matrix4D rotationMat = 
114
//        	new com.iver.cit.jdwglib.util.Matrix4D();
115
//        rotationMat.zrot(rotation);
116
//        com.iver.cit.jdwglib.util.Matrix4D aaaMat =  
117
//        	new com.iver.cit.jdwglib.util.Matrix4D();
118
//        com.iver.cit.jdwglib.util.Matrix4D translationMat = 
119
//        	new com.iver.cit.jdwglib.util.Matrix4D();
120
//        translationMat.translate(new com.iver.cit.jdwglib.util.Vector3D(insertionPoint[0], 
121
//        																insertionPoint[1], 
122
//        																insertionPoint[2]));
123
//          
124
//        com.iver.cit.jdwglib.util.Matrix4D trafo = aaaMat.
125
//			        					mult(translationMat.
126
//			        					mult(rotationMat.
127
//			        					mult(scaleMat)));
128
//        
129
//        Point3D a1 = new Point3D(p1[0], p1[1], p1[2]);
130
//        trafo.transform(a1);
131
//        Point3D a2 = new Point3D(p2[0], p2[1], p2[2]);
132
//        trafo.transform(a2);
133
//        Point3D a3 = new Point3D(p3[0], p3[1], p3[2]);
134
//        trafo.transform(a3);
135
//        Point3D a4 = new Point3D(p4[0], p4[1], p4[2]);
136
//        trafo.transform(a4);
137
               
138
	}
139
	
140
	
141

  
374 142
}

Also available in: Unified diff