Revision 9910 trunk/libraries/libDwg/src/com/iver/cit/jdwglib/dwg/readers/DwgFileV15Reader.java

View differences:

DwgFileV15Reader.java
77 77
 * 
78 78
 * @author jmorell
79 79
 */
80
public class DwgFileV15Reader implements DwgFileReader {
80
public class DwgFileV15Reader implements IDwgFileReader {
81 81
	protected DwgFile dwgFile;
82

  
82 83
	protected ByteBuffer bb;
83
	
84

  
84 85
	/**
85 86
	 * Reads the DWG version 15 format
86 87
	 * 
87
	 * @param dwgFile Represents the DWG file that we want to read
88
     * @throws IOException When DWG file path is wrong
88
	 * @param dwgFile
89
	 *            Represents the DWG file that we want to read
90
	 * @throws IOException
91
	 *             When DWG file path is wrong
89 92
	 */
90 93
	public void read(DwgFile dwgFile, ByteBuffer bb) throws IOException {
91 94
		this.dwgFile = dwgFile;
92 95
		this.bb = bb;
93
		
96

  
94 97
		readDwgSectionOffsets();
95 98
		try {
96
			readDwgObjectOffsets();		
99
			readDwgObjectOffsets();
97 100
			//readDwgClasses(bb);
98 101
		} catch (Exception e) {
99
//		    System.out.println("Error leyendo offsets y classes. Posible corrupci�n en" +
100
//		    		"el DWG file ...");
102
			//		    System.out.println("Error leyendo offsets y classes. Posible
103
			// corrupci�n en" +
104
			//		    		"el DWG file ...");
101 105
		}
102 106
		readDwgObjects();
103 107
	}
104
	
105
	
108

  
106 109
	/**
107 110
	 * It read the SECTIONS from the header of the DWG file
108
	 * */
111
	 */
109 112
	protected void readDwgSectionOffsets() {
110 113
		bb.position(19);
111 114
		bb.order(ByteOrder.LITTLE_ENDIAN);
112 115
		short codePage = bb.getShort();
113 116
		int count = bb.getInt();
114
		for (int i=0; i<count; i++) {
117
		for (int i = 0; i < count; i++) {
115 118
			byte rec = bb.get();
116 119
			int seek = bb.getInt();
117 120
			int size = bb.getInt();
118
			if (rec==0) {
121
			if (rec == 0) {
119 122
				dwgFile.addDwgSectionOffset("HEADERS", seek, size);
120
			} else if (rec==1) {
123
			} else if (rec == 1) {
121 124
				dwgFile.addDwgSectionOffset("CLASSES", seek, size);
122
			} else if (rec==2) {
125
			} else if (rec == 2) {
123 126
				dwgFile.addDwgSectionOffset("OBJECTS", seek, size);
124
			} else if (rec==3) {
127
			} else if (rec == 3) {
125 128
				dwgFile.addDwgSectionOffset("UNKNOWN", seek, size);
126
			} else if (rec==4) {
129
			} else if (rec == 4) {
127 130
				dwgFile.addDwgSectionOffset("R14DATA", seek, size);
128
			} else if (rec==5) {
131
			} else if (rec == 5) {
129 132
				dwgFile.addDwgSectionOffset("R14REC5", seek, size);
130 133
			} else {
131
//				System.out.println("ERROR: C�digo de n�mero de registro no soportado: " + rec);
134
				//				System.out.println("ERROR: C�digo de n�mero de registro
135
				// no soportado: " + rec);
132 136
			}
133 137
		}
134 138
	}
135
	
139

  
136 140
	/**
137
	 * OpenDWG spec says:
138
	 * This section -object map- is a table which gives the location of
139
	 * each object in the DWG file.
140
	 * This table is broken into sections. It is basically a list of
141
	 * handle/file loc pairs. It could be readed with this pseudocode:
141
	 * OpenDWG spec says: This section -object map- is a table which gives the
142
	 * location of each object in the DWG file. This table is broken into
143
	 * sections. It is basically a list of handle/file loc pairs. It could be
144
	 * readed with this pseudocode:
142 145
	 * 
143
	 *    Set lastHandle to all 0 and last loc to 0L.
144
	 *    Repeat until section size == 2
145
	 * 			section size = read short (in bigendian order)
146
	 * 			Repeat until out of data for this section
147
	 * 				offset of this handle form last handle as modular char
148
	 * 				offset of location in file from last location as modular char
149
	 * 			End repeat
150
	 * 	  End repeat
151
	 * 
152
	 * */
146
	 * Set lastHandle to all 0 and last loc to 0L. Repeat until section size ==
147
	 * 2 section size = read short (in bigendian order) Repeat until out of data
148
	 * for this section offset of this handle form last handle as modular char
149
	 * offset of location in file from last location as modular char End repeat
150
	 * End repeat
151
	 *  
152
	 */
153 153
	protected void readDwgObjectOffsets() throws Exception {
154 154
		int offset = dwgFile.getDwgSectionOffset("OBJECTS");
155 155
		bb.position(offset);
156 156
		while (true) {
157 157
			bb.order(ByteOrder.BIG_ENDIAN);
158 158
			/*
159
			 * We read the size of the next section.
160
			 * If size == 2, break (it is the last empty -except crc- section)
161
			 * */
159
			 * We read the size of the next section. If size == 2, break (it is
160
			 * the last empty -except crc- section)
161
			 */
162 162
			short size = bb.getShort();
163
			if (size==2) 
163
			if (size == 2)
164 164
				break;
165 165
			bb.order(ByteOrder.LITTLE_ENDIAN);
166 166
			byte[] dataBytes = new byte[size];
167
			for (int i=0; i<dataBytes.length; i++) {
167
			for (int i = 0; i < dataBytes.length; i++) {
168 168
				dataBytes[i] = bb.get();
169 169
			}
170 170
			int[] data = DwgUtil.bytesToMachineBytes(dataBytes);
171
			int lastHandle=0;
172
			int lastLoc=0;
173
			int bitPos=0;
174
			int bitMax= (size - 2) * 8;
171
			int lastHandle = 0;
172
			int lastLoc = 0;
173
			int bitPos = 0;
174
			int bitMax = (size - 2) * 8;
175 175
			while (bitPos < bitMax) {
176 176
				ArrayList v = DwgUtil.getModularChar(data, bitPos);
177
				bitPos = ((Integer)v.get(0)).intValue();
178
				lastHandle = lastHandle + ((Integer)v.get(1)).intValue();
177
				bitPos = ((Integer) v.get(0)).intValue();
178
				lastHandle = lastHandle + ((Integer) v.get(1)).intValue();
179 179
				v = DwgUtil.getModularChar(data, bitPos);
180
				bitPos = ((Integer)v.get(0)).intValue();
181
				lastLoc = lastLoc + ((Integer)v.get(1)).intValue();
180
				bitPos = ((Integer) v.get(0)).intValue();
181
				lastLoc = lastLoc + ((Integer) v.get(1)).intValue();
182 182
				dwgFile.addDwgObjectOffset(lastHandle, lastLoc);
183 183
			}//while
184 184
		}//while
185 185
	}
186
	
186

  
187 187
	/*
188 188
	 * Unused.
189 189
	 * 
190
	 * Dwg spec says that drawing entities (objects) that has not
191
	 * a fixed type must read its type from this section
190
	 * Dwg spec says that drawing entities (objects) that has not a fixed type
191
	 * must read its type from this section
192 192
	 * 
193
	 * 
194
	 * */
193
	 *  
194
	 */
195 195
	protected void readDwgClasses() throws Exception {
196 196
		int offset = dwgFile.getDwgSectionOffset("CLASSES");
197 197
		// Por ahora nos saltamos los 16 bytes de control
198
		bb.position(offset+16);
198
		bb.position(offset + 16);
199 199
		bb.order(ByteOrder.LITTLE_ENDIAN);
200 200
		int size = bb.getInt();
201 201
		byte[] dataBytes = new byte[size];
202
		for (int i=0; i<dataBytes.length; i++) {
202
		for (int i = 0; i < dataBytes.length; i++) {
203 203
			dataBytes[i] = bb.get();
204 204
		}
205 205
		int[] data = DwgUtil.bytesToMachineBytes(dataBytes);
206
		for (int i=0; i<data.length; i++) {
207
			data[i] = (byte)ByteUtils.getUnsigned((byte)data[i]);
206
		for (int i = 0; i < data.length; i++) {
207
			data[i] = (byte) ByteUtils.getUnsigned((byte) data[i]);
208 208
		}
209
		bb.position(bb.position()+2+16);
209
		bb.position(bb.position() + 2 + 16);
210 210
		int maxbit = size * 8;
211 211
		int bitPos = 0;
212
		while ((bitPos+8) < maxbit) {
212
		while ((bitPos + 8) < maxbit) {
213 213
			ArrayList v = DwgUtil.getBitShort(data, bitPos);
214
			bitPos = ((Integer)v.get(0)).intValue();
214
			bitPos = ((Integer) v.get(0)).intValue();
215 215
			v = DwgUtil.getBitShort(data, bitPos);
216
			bitPos = ((Integer)v.get(0)).intValue();
216
			bitPos = ((Integer) v.get(0)).intValue();
217 217
			v = DwgUtil.getTextString(data, bitPos);
218
			bitPos = ((Integer)v.get(0)).intValue();
218
			bitPos = ((Integer) v.get(0)).intValue();
219 219
			v = DwgUtil.getTextString(data, bitPos);
220
			bitPos = ((Integer)v.get(0)).intValue();
220
			bitPos = ((Integer) v.get(0)).intValue();
221 221
			v = DwgUtil.getTextString(data, bitPos);
222
			bitPos = ((Integer)v.get(0)).intValue();
222
			bitPos = ((Integer) v.get(0)).intValue();
223 223
			v = DwgUtil.testBit(data, bitPos);
224
			bitPos = ((Integer)v.get(0)).intValue();
224
			bitPos = ((Integer) v.get(0)).intValue();
225 225
			v = DwgUtil.getBitShort(data, bitPos);
226
			bitPos = ((Integer)v.get(0)).intValue();
226
			bitPos = ((Integer) v.get(0)).intValue();
227 227
		}
228 228
	}
229
	
230
	
229

  
231 230
	/**
232
	 * Reads all the object referenced in the object map section of the
233
	 * DWG file (using their object file obsets)
234
	 * */
231
	 * Reads all the object referenced in the object map section of the DWG file
232
	 * (using their object file obsets)
233
	 */
235 234
	protected void readDwgObjects() {
236
		for (int i=0; i<dwgFile.getDwgObjectOffsets().size(); i++) {
237
			DwgObjectOffset doo = (DwgObjectOffset)dwgFile.getDwgObjectOffsets().get(i);
235
		for (int i = 0; i < dwgFile.getDwgObjectOffsets().size(); i++) {
236
			DwgObjectOffset doo = (DwgObjectOffset) dwgFile
237
					.getDwgObjectOffsets().get(i);
238 238
			DwgObject obj = readDwgObject(doo.getOffset(), i);
239 239
			/*
240
			azabala: las entidades DWG no implementadas no nos aportan nada
241
			(aunque la sigo leyendo por si aparecen problemas de puntero de fichero)
242
			No considero por tanto los DwgObject
243
			if (obj != null) {
244
                dwgFile.addDwgObject(obj);
245
            }
246
            */
247
			if(obj != null && obj.getClass() != DwgObject.class){
240
			 * azabala: las entidades DWG no implementadas no nos aportan nada
241
			 * (aunque la sigo leyendo por si aparecen problemas de puntero de
242
			 * fichero) No considero por tanto los DwgObject if (obj != null) {
243
			 * dwgFile.addDwgObject(obj); }
244
			 */
245
			if (obj != null && obj.getClass() != DwgObject.class) {
248 246
				dwgFile.addDwgObject(obj);
249 247
			}
250 248
		}
251 249
	}
252
	
250

  
253 251
	/**
252
	 * Reads the header of an object in a DWG file Version 15
253
	 * 
254
	 * @param data
255
	 *            Array of unsigned bytes obtained from the DWG binary file
256
	 * @param offset
257
	 *            The current bit offset where the value begins
258
	 * @return int New offset
259
	 * @throws Exception
260
	 *             If an unexpected bit value is found in the DWG file. Occurs
261
	 *             when we are looking for LwPolylines.
262
	 */
263
	public int readObjectHeader(int[] data, int offset, DwgObject dwgObject)
264
			throws Exception {
265
		int bitPos = offset;
266
		Integer mode = (Integer) DwgUtil.getBits(data, 2, bitPos);
267
		bitPos = bitPos + 2;
268
		dwgObject.setMode(mode.intValue());
269

  
270
		ArrayList v = DwgUtil.getBitLong(data, bitPos);
271
		bitPos = ((Integer) v.get(0)).intValue();
272
		int rnum = ((Integer) v.get(1)).intValue();
273
		dwgObject.setNumReactors(rnum);
274

  
275
		v = DwgUtil.testBit(data, bitPos);
276
		bitPos = ((Integer) v.get(0)).intValue();
277
		boolean nolinks = ((Boolean) v.get(1)).booleanValue();
278
		dwgObject.setNoLinks(nolinks);
279

  
280
		v = DwgUtil.getBitShort(data, bitPos);
281
		bitPos = ((Integer) v.get(0)).intValue();
282
		int color = ((Integer) v.get(1)).intValue();
283
		dwgObject.setColor(color);
284

  
285
		v = DwgUtil.getBitDouble(data, bitPos);
286
		bitPos = ((Integer) v.get(0)).intValue();
287
		float ltscale = ((Double) v.get(1)).floatValue();
288

  
289
		Integer ltflag = (Integer) DwgUtil.getBits(data, 2, bitPos);
290
		bitPos = bitPos + 2;
291

  
292
		Integer psflag = (Integer) DwgUtil.getBits(data, 2, bitPos);
293
		bitPos = bitPos + 2;
294

  
295
		v = DwgUtil.getBitShort(data, bitPos);
296
		bitPos = ((Integer) v.get(0)).intValue();
297
		int invis = ((Integer) v.get(1)).intValue();
298

  
299
		v = DwgUtil.getRawChar(data, bitPos);
300
		bitPos = ((Integer) v.get(0)).intValue();
301
		int weight = ((Integer) v.get(1)).intValue();
302

  
303
		return bitPos;
304
	}
305

  
306
	/**
307
	 * Reads the tail of an object in a DWG file Version 15
308
	 * 
309
	 * @param data
310
	 *            Array of bytes obtained from the DWG binary file
311
	 * @param offset
312
	 *            Offset for this array of bytes
313
	 * @return int New offset
314
	 * @throws Exception
315
	 *             If an unexpected bit value is found in the DWG file. Occurs
316
	 *             when we are looking for LwPolylines.
317
	 */
318
	public int readObjectTailer(int[] data, int offset, DwgObject dwgObject)
319
			throws Exception {
320
		int bitPos = offset;
321
		ArrayList v = null;
322
		String cadena = "";
323
		/*
324
		 * Subentity ref handle. Esto se aplica sobre VERTEX, ATTRIB, SEQEND
325
		 */
326
		if (dwgObject.getMode() == 0x0) {
327
			v = DwgUtil.getHandle(data, bitPos);
328
			bitPos = ((Integer) v.get(0)).intValue();
329
			int[] sh = new int[v.size() - 1];
330
			for (int i = 1; i < v.size(); i++) {
331
				sh[i - 1] = ((Integer) v.get(i)).intValue();
332
			}
333
			ArrayList shv = new ArrayList();
334
			for (int i = 0; i < sh.length; i++) {
335
				shv.add(new Integer(sh[i]));
336
			}
337
			dwgObject.setSubEntityHandle(DwgUtil.handleBinToHandleInt(shv));
338
		}
339

  
340
		/*
341
		 * Reactors handles TODO No se est?n usando para setear nada en
342
		 * DwgObject
343
		 */
344
		for (int i = 0; i < dwgObject.getNumReactors(); i++) {
345
			v = DwgUtil.getHandle(data, bitPos);
346
			bitPos = ((Integer) v.get(0)).intValue();
347
			int[] handle = new int[v.size() - 1];
348
			for (int j = 1; j < v.size(); j++) {
349
				handle[j - 1] = ((Integer) v.get(j)).intValue();
350
			}
351
		}
352

  
353
		/*
354
		 * XDICOBJHANDLE
355
		 */
356
		v = DwgUtil.getHandle(data, bitPos);
357
		bitPos = ((Integer) v.get(0)).intValue();
358
		int[] xh = new int[v.size() - 1];
359
		for (int i = 1; i < v.size(); i++) {
360
			xh[i - 1] = ((Integer) v.get(i)).intValue();
361
		}
362
		ArrayList xhv = new ArrayList();
363
		for (int i = 0; i < xh.length; i++) {
364
			xhv.add(new Integer(xh[i]));
365
		}
366
		dwgObject.setXDicObjHandle(DwgUtil.handleBinToHandleInt(xhv));
367

  
368
		/*
369
		 * Layer Handle code
370
		 */
371
		v = DwgUtil.getHandle(data, bitPos);
372
		bitPos = ((Integer) v.get(0)).intValue();
373
		/*
374
		 * v ArrayList has the next structure: v[0] -> offset of the DWG file
375
		 * v[1] -> code of the layer handle v[2] -> counter (number of bytes)
376
		 * v[3] v[4] ...
377
		 */
378
		int[] lh = new int[v.size() - 1];
379
		cadena = "LAYER HANDLE = ";
380
		for (int i = 1; i < v.size(); i++) {
381
			lh[i - 1] = ((Integer) v.get(i)).intValue();
382
			cadena += lh[i - 1] + " ";
383
		}
384

  
385
		dwgObject.setLayerHandleCode(lh[0]);
386

  
387
		ArrayList lhv = new ArrayList();
388
		for (int i = 0; i < lh.length; i++) {
389
			lhv.add(new Integer(lh[i]));
390
		}
391
		int handle = DwgUtil.handleBinToHandleInt(lhv);
392
		dwgObject.setLayerHandle(handle);
393
		System.out.println(cadena + " ==> " + handle);
394

  
395
		if (!dwgObject.isNoLinks()) {
396
			v = DwgUtil.getHandle(data, bitPos);
397
			bitPos = ((Integer) v.get(0)).intValue();
398
			int[] prev = new int[v.size() - 1];
399
			ArrayList prevhv = new ArrayList();
400
			cadena = "PREVIOUS HANDLE = ";
401
			for (int i = 1; i < v.size(); i++) {
402
				prev[i - 1] = ((Integer) v.get(i)).intValue();
403
				prevhv.add(new Integer(prev[i - 1]));
404
				cadena += prev[i - 1] + " ";
405
			}
406
			System.out.println(cadena);
407
			dwgObject.setPreviousHandleCode(prev[0]);
408
			dwgObject.setPreviousHandle(DwgUtil.handleBinToHandleInt(prevhv));
409
			ArrayList nexthv = new ArrayList();
410
			v = DwgUtil.getHandle(data, bitPos);
411
			bitPos = ((Integer) v.get(0)).intValue();
412
			int[] next = new int[v.size() - 1];
413
			cadena = "NEXT HANDLE = ";
414
			for (int i = 1; i < v.size(); i++) {
415
				next[i - 1] = ((Integer) v.get(i)).intValue();
416
				nexthv.add(new Integer(next[i - 1]));
417
				cadena += next[i - 1] + " ";
418
			}
419
			System.out.println(cadena);
420
			dwgObject.setNextHandleCode(next[0]);
421
			dwgObject.setNextHandle(DwgUtil.handleBinToHandleInt(nexthv));
422
		}
423

  
424
		if (dwgObject.getLinetypeFlags() == 0x3) {
425
			v = DwgUtil.getHandle(data, bitPos);
426
			bitPos = ((Integer) v.get(0)).intValue();
427
			int[] lth = new int[v.size() - 1];
428
			for (int i = 1; i < v.size(); i++) {
429
				lth[i - 1] = ((Integer) v.get(i)).intValue();
430
			}
431
			//obj.setLinetype(lth);
432
		}
433

  
434
		if (dwgObject.getPlotstyleFlags() == 0x3) {
435
			v = DwgUtil.getHandle(data, bitPos);
436
			bitPos = ((Integer) v.get(0)).intValue();
437
			int[] pth = new int[v.size() - 1];
438
			for (int i = 1; i < v.size(); i++) {
439
				pth[i - 1] = ((Integer) v.get(i)).intValue();
440
			}
441
			//obj.setPlotstyle(pth);
442
		}
443
		return bitPos;
444
	}
445

  
446
	/**
254 447
	 * Return a dwg object from its index in the dwg file
255
	 * @param index of the requested dwg object in the dwg file
256 448
	 * 
257
	 * */
258
	public DwgObject getDwgObjectByIndex(int index){
259
		DwgObjectOffset doo = (DwgObjectOffset)dwgFile.getDwgObjectOffsets().get(index);
449
	 * @param index
450
	 *            of the requested dwg object in the dwg file
451
	 *  
452
	 */
453
	public DwgObject getDwgObjectByIndex(int index) {
454
		DwgObjectOffset doo = (DwgObjectOffset) dwgFile.getDwgObjectOffsets()
455
				.get(index);
260 456
		return readDwgObject(doo.getOffset(), index);
261 457
	}
262
	
458

  
263 459
	/**
264 460
	 * Reads a dwg drawing entity (dwg object) given its offset in the file
265
	 * */
266
	
267
	
461
	 */
462

  
268 463
	protected DwgObject readDwgObject(int offset, int index) {
269
	    try {
464
		try {
270 465
			bb.position(offset);
271 466
			int size = DwgUtil.getModularShort(bb);
272
			
467

  
273 468
			bb.order(ByteOrder.LITTLE_ENDIAN);
274 469
			byte[] dataBytes = new byte[size];
275 470
			String[] dataMachValString = new String[size];
276 471
			int[] data = new int[size];
277
			for (int i=0; i < size; i++) {
472
			for (int i = 0; i < size; i++) {
278 473
				dataBytes[i] = bb.get();
279
				dataMachValString[i] = HexUtil.bytesToHex(new byte[]{dataBytes[i]});
280
				Integer dataMachValShort = Integer.decode("0x" + dataMachValString[i]);
474
				dataMachValString[i] = HexUtil
475
						.bytesToHex(new byte[] { dataBytes[i] });
476
				Integer dataMachValShort = Integer.decode("0x"
477
						+ dataMachValString[i]);
281 478
				data[i] = dataMachValShort.byteValue();
282
				data[i] = ByteUtils.getUnsigned((byte)data[i]);
479
				data[i] = ByteUtils.getUnsigned((byte) data[i]);
283 480
			}
284
			
285
			
481

  
286 482
			int bitPos = 0;
287 483
			ArrayList v = DwgUtil.getBitShort(data, bitPos);
288
			bitPos = ((Integer)v.get(0)).intValue();
289
			int type = ((Integer)v.get(1)).intValue();
290
			
291
			DwgObject obj = DwgObjectFactory.
292
								getInstance().
293
								create(type, index);
294
		   
295
				    
296
		    v = DwgUtil.getRawLong(data, bitPos);
297
		    bitPos = ((Integer)v.get(0)).intValue();
298
		    int objBSize = ((Integer)v.get(1)).intValue();
299
		    obj.setSizeInBits(objBSize);
300
		    
301
	  
302
		    ArrayList entityHandle = new ArrayList();
303
		    v = DwgUtil.getHandle(data, bitPos);
304
		    bitPos = ((Integer)v.get(0)).intValue();
305
		    for (int i=1;i<v.size();i++) {
306
		    	entityHandle.add(v.get(i));
307
		    }
308
		    obj.setHandle(DwgUtil.
309
		    		handleBinToHandleInt(entityHandle));
310
		   	    
311
		    v = DwgUtil.readExtendedData(data, bitPos);
312
		    bitPos = ((Integer)v.get(0)).intValue();
313
		    ArrayList extData = (ArrayList)v.get(1);
314
		    obj.setExtendedData(extData);
315
		    
316
		   	        
317
		    boolean gflag = false;
318
	    	gflag = obj.isGraphicsFlag();   	
319
	    	if (gflag) {
320
	    		//lee un flag boolean
321
		    	v = DwgUtil.testBit(data, bitPos);
322
			    bitPos = ((Integer)v.get(0)).intValue();
323
			    boolean val = ((Boolean)v.get(1)).booleanValue();
324
			   //si hay imagen asociada, se lee por completo
325
			    if (val) {
326
			    	v = DwgUtil.getRawLong(data, bitPos);
327
				    bitPos = ((Integer)v.get(0)).intValue();
328
				    size = ((Integer)v.get(1)).intValue();
329
				    int bgSize = size*8;
330
					Integer giData = (Integer)DwgUtil.getBits(data, bgSize, bitPos);
484
			bitPos = ((Integer) v.get(0)).intValue();
485
			int type = ((Integer) v.get(1)).intValue();
486

  
487
			DwgObject obj = DwgObjectFactory.getInstance().create(type, index);
488

  
489
			v = DwgUtil.getRawLong(data, bitPos);
490
			bitPos = ((Integer) v.get(0)).intValue();
491
			int objBSize = ((Integer) v.get(1)).intValue();
492
			obj.setSizeInBits(objBSize);
493

  
494
			ArrayList entityHandle = new ArrayList();
495
			v = DwgUtil.getHandle(data, bitPos);
496
			bitPos = ((Integer) v.get(0)).intValue();
497
			for (int i = 1; i < v.size(); i++) {
498
				entityHandle.add(v.get(i));
499
			}
500
			obj.setHandle(DwgUtil.handleBinToHandleInt(entityHandle));
501

  
502
			v = DwgUtil.readExtendedData(data, bitPos);
503
			bitPos = ((Integer) v.get(0)).intValue();
504
			ArrayList extData = (ArrayList) v.get(1);
505
			obj.setExtendedData(extData);
506

  
507
			boolean gflag = false;
508
			gflag = obj.isGraphicsFlag();
509
			if (gflag) {
510
				//lee un flag boolean
511
				v = DwgUtil.testBit(data, bitPos);
512
				bitPos = ((Integer) v.get(0)).intValue();
513
				boolean val = ((Boolean) v.get(1)).booleanValue();
514
				//si hay imagen asociada, se lee por completo
515
				if (val) {
516
					v = DwgUtil.getRawLong(data, bitPos);
517
					bitPos = ((Integer) v.get(0)).intValue();
518
					size = ((Integer) v.get(1)).intValue();
519
					int bgSize = size * 8;
520
					Integer giData = (Integer) DwgUtil.getBits(data, bgSize,
521
							bitPos);
331 522
					obj.setGraphicData(giData.intValue());
332 523
					bitPos = bitPos + bgSize;
333
			    }
334
		    }
335
	    	
524
				}
525
			}
526

  
336 527
			readSpecificObject(obj, data, bitPos);
337
		    return obj;
338
	    } catch (Exception e) {
339
//	        System.out.println("Exception capturada. Probablemente se ha encontrado un" +
340
//	        		"objeto con type non fixed");
341
	        //e.printStackTrace();
342
	        return null;
343
	    }
528
			return obj;
529
		} catch (Exception e) {
530
			//	        System.out.println("Exception capturada. Probablemente se ha
531
			// encontrado un" +
532
			//	        		"objeto con type non fixed");
533
			//e.printStackTrace();
534
			return null;
535
		}
344 536
	}
345
	
537

  
346 538
	/*
347
	 * TODO Esto est? pesimamente dise?ado.
348
	 * Cada objeto DwgObject debe tener un metodo
349
	 * readSpecificObject(data,bitPos)
350
	 * 
351
	 * */
352
	protected void readSpecificObject(DwgObject obj, int[] data, int bitPos) throws Exception {
353
		if (obj.getType()==0x11) {
354
			((DwgArc)obj).readDwgArcV15(data, bitPos);
355
		} else if (obj.getType()==0x12) {
356
			((DwgCircle)obj).readDwgCircleV15(data, bitPos);
357
		} else if (obj.getType()==0x13) {
358
			((DwgLine)obj).readDwgLineV15(data, bitPos);
359
		} else if (obj.getType()==0x1B) {
360
			((DwgPoint)obj).readDwgPointV15(data, bitPos);
361
		} else if (obj.getType()==0x0F) {
362
			((DwgPolyline2D)obj).readDwgPolyline2DV15(data, bitPos);
363
		} else if (obj.getType()==0x10) {
364
			((DwgPolyline3D)obj).readDwgPolyline3DV15(data, bitPos);
365
		} else if (obj.getType()==0x0A) {
366
			((DwgVertex2D)obj).readDwgVertex2DV15(data, bitPos);
367
		} else if (obj.getType()==0x0B) {
368
			((DwgVertex3D)obj).readDwgVertex3DV15(data, bitPos);
369
		} else if (obj.getType()==0x6) {
370
			((DwgSeqend)obj).readDwgSeqendV15(data, bitPos);
371
		} else if (obj.getType()==0x1) {
372
			((DwgText)obj).readDwgTextV15(data, bitPos);
373
		} else if (obj.getType()==0x2) {
374
			((DwgAttrib)obj).readDwgAttribV15(data, bitPos);
375
		} else if (obj.getType()==0x3) {
376
			((DwgAttdef)obj).readDwgAttdefV15(data, bitPos);
377
		} else if (obj.getType()==0x4) {
378
			((DwgBlock)obj).readDwgBlockV15(data, bitPos);
379
		} else if (obj.getType()==0x5) {
380
			((DwgEndblk)obj).readDwgEndblkV15(data, bitPos);
381
		} else if (obj.getType()==0x30) {
382
			((DwgBlockControl)obj).readDwgBlockControlV15(data, bitPos);
383
		} else if (obj.getType()==0x31) {
384
			((DwgBlockHeader)obj).readDwgBlockHeaderV15(data, bitPos);
385
		} else if (obj.getType()==0x32) {
386
			((DwgLayerControl)obj).readDwgLayerControlV15(data, bitPos);
387
		} else if (obj.getType()==0x33) {
388
			((DwgLayer)obj).readDwgLayerV15(data, bitPos);
389
		} else if (obj.getType()==0x7) {
390
			((DwgInsert)obj).readDwgInsertV15(data, bitPos);
391
		} else if (obj.getType()==0x2C) {
392
			((DwgMText)obj).readDwgMTextV15(data, bitPos);
393
		} else if (obj.getType()==0x1F) {
394
			((DwgSolid)obj).readDwgSolidV15(data, bitPos);
395
		} else if (obj.getType()==0x23) {
396
			((DwgEllipse)obj).readDwgEllipseV15(data, bitPos);
397
		} else if (obj.getType()==0x24) {
398
			((DwgSpline)obj).readDwgSplineV15(data, bitPos);
399
		} else if (obj.getType()==0x14) {
539
	 * TODO Esto est? pesimamente dise?ado. Cada objeto DwgObject debe tener un
540
	 * metodo readSpecificObject(data,bitPos)
541
	 *  
542
	 */
543
	protected void readSpecificObject(DwgObject obj, int[] data, int bitPos)
544
			throws Exception {
545
		if (obj.getType() == 0x11) {
546
			((DwgArc) obj).readDwgArcV15(data, bitPos);
547
		} else if (obj.getType() == 0x12) {
548
			((DwgCircle) obj).readDwgCircleV15(data, bitPos);
549
		} else if (obj.getType() == 0x13) {
550
			((DwgLine) obj).readDwgLineV15(data, bitPos);
551
		} else if (obj.getType() == 0x1B) {
552
			((DwgPoint) obj).readDwgPointV15(data, bitPos);
553
		} else if (obj.getType() == 0x0F) {
554
			((DwgPolyline2D) obj).readDwgPolyline2DV15(data, bitPos);
555
		} else if (obj.getType() == 0x10) {
556
			((DwgPolyline3D) obj).readDwgPolyline3DV15(data, bitPos);
557
		} else if (obj.getType() == 0x0A) {
558
			((DwgVertex2D) obj).readDwgVertex2DV15(data, bitPos);
559
		} else if (obj.getType() == 0x0B) {
560
			((DwgVertex3D) obj).readDwgVertex3DV15(data, bitPos);
561
		} else if (obj.getType() == 0x6) {
562
			((DwgSeqend) obj).readDwgSeqendV15(data, bitPos);
563
		} else if (obj.getType() == 0x1) {
564
			((DwgText) obj).readDwgTextV15(data, bitPos);
565
		} else if (obj.getType() == 0x2) {
566
			((DwgAttrib) obj).readDwgAttribV15(data, bitPos);
567
		} else if (obj.getType() == 0x3) {
568
			((DwgAttdef) obj).readDwgAttdefV15(data, bitPos);
569
		} else if (obj.getType() == 0x4) {
570
			((DwgBlock) obj).readDwgBlockV15(data, bitPos);
571
		} else if (obj.getType() == 0x5) {
572
			((DwgEndblk) obj).readDwgEndblkV15(data, bitPos);
573
		} else if (obj.getType() == 0x30) {
574
			((DwgBlockControl) obj).readDwgBlockControlV15(data, bitPos);
575
		} else if (obj.getType() == 0x31) {
576
			((DwgBlockHeader) obj).readDwgBlockHeaderV15(data, bitPos);
577
		} else if (obj.getType() == 0x32) {
578
			((DwgLayerControl) obj).readDwgLayerControlV15(data, bitPos);
579
		} else if (obj.getType() == 0x33) {
580
			((DwgLayer) obj).readDwgLayerV15(data, bitPos);
581
		} else if (obj.getType() == 0x7) {
582
			((DwgInsert) obj).readDwgInsertV15(data, bitPos);
583
		} else if (obj.getType() == 0x2C) {
584
			((DwgMText) obj).readDwgMTextV15(data, bitPos);
585
		} else if (obj.getType() == 0x1F) {
586
			((DwgSolid) obj).readDwgSolidV15(data, bitPos);
587
		} else if (obj.getType() == 0x23) {
588
			((DwgEllipse) obj).readDwgEllipseV15(data, bitPos);
589
		} else if (obj.getType() == 0x24) {
590
			((DwgSpline) obj).readDwgSplineV15(data, bitPos);
591
		} else if (obj.getType() == 0x14) {
400 592
			//System.out.println("... detectado un dim del tipo 0x14 ...");
401
		} else if (obj.getType()==0x15) {
593
		} else if (obj.getType() == 0x15) {
402 594
			//System.out.println("... detectado un dim del tipo 0x15 ...");
403
			//((DwgLinearDimension)obj).readDwgLinearDimensionV15(data, bitPos);
404
		} else if (obj.getType()==0x16) {
595
			//((DwgLinearDimension)obj).readDwgLinearDimensionV15(data,
596
			// bitPos);
597
		} else if (obj.getType() == 0x16) {
405 598
			//System.out.println("... detectado un dim del tipo 0x16 ...");
406
		} else if (obj.getType()==0x17) {
599
		} else if (obj.getType() == 0x17) {
407 600
			//System.out.println("... detectado un dim del tipo 0x17 ...");
408
		} else if (obj.getType()==0x18) {
601
		} else if (obj.getType() == 0x18) {
409 602
			//System.out.println("... detectado un dim del tipo 0x18 ...");
410
		} else if (obj.getType()==0x19) {
603
		} else if (obj.getType() == 0x19) {
411 604
			//System.out.println("... detectado un dim del tipo 0x19 ...");
412
		} else if (obj.getType()==0x1A) {
605
		} else if (obj.getType() == 0x1A) {
413 606
			//System.out.println("... detectado un dim del tipo 0x1A ...");
414
		} else if (obj.getType()==0x4D) {
415
			((DwgLwPolyline)obj).readDwgLwPolylineV15(data, bitPos);
416
		} else if (obj.getType()==0x4E) {
417
			((DwgLwPolyline)obj).readDwgLwPolylineV15(data, bitPos);
418
		} else if (obj.getType()==0x4F) {
419
			((DwgLwPolyline)obj).readDwgLwPolylineV15(data, bitPos);
420
		} else if (obj.getType()==0x50) {
421
			((DwgLwPolyline)obj).readDwgLwPolylineV15(data, bitPos);
422
		} else if (obj.getType()==0x51) {
423
			((DwgLwPolyline)obj).readDwgLwPolylineV15(data, bitPos);
424
		} else if (obj.getType()==0x52) {
425
			((DwgLwPolyline)obj).readDwgLwPolylineV15(data, bitPos);
426
		} else if (obj.getType()==0x53) {
427
			((DwgLwPolyline)obj).readDwgLwPolylineV15(data, bitPos);
607
		} else if (obj.getType() == 0x4D) {
608
			((DwgLwPolyline) obj).readDwgLwPolylineV15(data, bitPos);
609
		} else if (obj.getType() == 0x4E) {
610
			((DwgLwPolyline) obj).readDwgLwPolylineV15(data, bitPos);
611
		} else if (obj.getType() == 0x4F) {
612
			((DwgLwPolyline) obj).readDwgLwPolylineV15(data, bitPos);
613
		} else if (obj.getType() == 0x50) {
614
			((DwgLwPolyline) obj).readDwgLwPolylineV15(data, bitPos);
615
		} else if (obj.getType() == 0x51) {
616
			((DwgLwPolyline) obj).readDwgLwPolylineV15(data, bitPos);
617
		} else if (obj.getType() == 0x52) {
618
			((DwgLwPolyline) obj).readDwgLwPolylineV15(data, bitPos);
619
		} else if (obj.getType() == 0x53) {
620
			((DwgLwPolyline) obj).readDwgLwPolylineV15(data, bitPos);
428 621
		} else {
429
			//System.out.println("Tipo de objeto pendiente de implementaci�n");
622
			//System.out.println("Tipo de objeto pendiente de
623
			// implementaci�n");
430 624
		}
431 625
	}
432
}
626
}

Also available in: Unified diff