Revision 10435
trunk/libraries/libDwg/src/com/iver/cit/jdwglib/dwg/readers/DwgFileV12Reader.java | ||
---|---|---|
56 | 56 |
/** |
57 | 57 |
* Reads version 12 dwg files |
58 | 58 |
* |
59 |
* http://www.iwriteiam.nl/DWG12.html |
|
60 |
* |
|
59 | 61 |
* @author azabala |
60 | 62 |
* |
61 | 63 |
* TODO REVISAR TODOS LOS bb.getShort() y bb.getInt() pues puede que haya |
... | ... | |
195 | 197 |
readVportTable(vportTable); |
196 | 198 |
readAppidTable(appidTable); |
197 | 199 |
readDimStyleTable(dimStyleTable); |
198 |
readP13Table(p13table); |
|
200 |
// readP13Table(p13table);
|
|
199 | 201 |
|
200 | 202 |
//luego lee entidades de bloque |
201 | 203 |
readEntities(bsStart, bsEnd); |
... | ... | |
255 | 257 |
} |
256 | 258 |
|
257 | 259 |
|
260 |
private void readP13Table(Dwg12Table p13table) { |
|
261 |
// TODO Auto-generated method stub |
|
262 |
} |
|
263 |
|
|
264 |
|
|
265 |
|
|
266 |
private void readDimStyleTable(Dwg12Table dimStyleTable) { |
|
267 |
short size = dimStyleTable.s1; |
|
268 |
int numRecs = dimStyleTable.i1; |
|
269 |
int start = dimStyleTable.i2; |
|
270 |
int end = -1; |
|
271 |
bb.position(start); |
|
272 |
for(int i = 0; i < numRecs; i++){ |
|
273 |
end = bb.position() + size; |
|
274 |
|
|
275 |
byte flag = bb.get(); |
|
276 |
byte[] nameBytes = new byte[32]; |
|
277 |
bb.get(nameBytes); |
|
278 |
String name = new String(nameBytes); |
|
279 |
|
|
280 |
bb.order(ByteOrder.LITTLE_ENDIAN); |
|
281 |
short word = bb.getShort(); |
|
282 |
|
|
283 |
double[] d4048 = new double[9]; |
|
284 |
for(int j = 0; j < 9; j++){ |
|
285 |
d4048[j] = bb.getDouble(); |
|
286 |
} |
|
287 |
|
|
288 |
double[] d40145 = new double[6]; |
|
289 |
for(int j = 0; j < 6; j++){ |
|
290 |
d40145[j] = bb.getDouble(); |
|
291 |
} |
|
292 |
|
|
293 |
byte[] b7078 = new byte[7]; |
|
294 |
for(int j = 0; j < 7; j++){ |
|
295 |
b7078[j] = bb.get(); |
|
296 |
} |
|
297 |
|
|
298 |
byte[] b170175 = new byte[6]; |
|
299 |
for(int j = 0; j < 6; j++){ |
|
300 |
b170175[j] = bb.get(); |
|
301 |
} |
|
302 |
|
|
303 |
bb.order(ByteOrder.nativeOrder()); |
|
304 |
byte[] s3 = new byte[16]; |
|
305 |
bb.get(s3); |
|
306 |
|
|
307 |
byte[] s4 = new byte[16]; |
|
308 |
bb.get(s4); |
|
309 |
|
|
310 |
byte[] s5 = new byte[32]; |
|
311 |
bb.get(s5); |
|
312 |
|
|
313 |
byte[] s6 = new byte[32]; |
|
314 |
bb.get(s6); |
|
315 |
|
|
316 |
byte[] s7 = new byte[32]; |
|
317 |
bb.get(s6); |
|
318 |
|
|
319 |
bb.position(bb.position() + 3); |
|
320 |
|
|
321 |
bb.order(ByteOrder.LITTLE_ENDIAN); |
|
322 |
short w176 = bb.getShort(); |
|
323 |
short w177 = bb.getShort(); |
|
324 |
short w178 = bb.getShort(); |
|
325 |
|
|
326 |
double d146 = bb.getDouble(); |
|
327 |
double d147 = bb.getDouble(); |
|
328 |
|
|
329 |
|
|
330 |
int offset = end - bb.position(); |
|
331 |
if(offset > 0) |
|
332 |
bb.position(bb.position() + offset); |
|
333 |
|
|
334 |
bb.order(ByteOrder.LITTLE_ENDIAN); |
|
335 |
short crc = bb.getShort(); |
|
336 |
} |
|
337 |
byte[] crc32 = new byte[32]; |
|
338 |
bb.get(crc32); |
|
339 |
} |
|
340 |
|
|
341 |
|
|
342 |
|
|
343 |
private void readAppidTable(Dwg12Table appidTable) { |
|
344 |
short size = appidTable.s1; |
|
345 |
int numRecs = appidTable.i1; |
|
346 |
int start = appidTable.i2; |
|
347 |
int end = -1; |
|
348 |
bb.position(start); |
|
349 |
for(int i = 0; i < numRecs; i++){ |
|
350 |
end = bb.position() + size; |
|
351 |
|
|
352 |
byte flag = bb.get(); |
|
353 |
byte[] nameBytes = new byte[32]; |
|
354 |
bb.get(nameBytes); |
|
355 |
String name = new String(nameBytes); |
|
356 |
|
|
357 |
bb.order(ByteOrder.LITTLE_ENDIAN); |
|
358 |
short word = bb.getShort(); |
|
359 |
|
|
360 |
int offset = end - bb.position(); |
|
361 |
if(offset > 0) |
|
362 |
bb.position(bb.position() + offset); |
|
363 |
|
|
364 |
bb.order(ByteOrder.LITTLE_ENDIAN); |
|
365 |
short crc = bb.getShort(); |
|
366 |
} |
|
367 |
byte[] crc32 = new byte[32]; |
|
368 |
bb.get(crc32); |
|
369 |
} |
|
370 |
|
|
371 |
|
|
372 |
|
|
373 |
private void readVportTable(Dwg12Table vportTable) { |
|
374 |
short size = vportTable.s1; |
|
375 |
int numRecs = vportTable.i1; |
|
376 |
int start = vportTable.i2; |
|
377 |
int end = -1; |
|
378 |
bb.position(start); |
|
379 |
for(int i = 0; i < numRecs; i++){ |
|
380 |
end = bb.position() + size; |
|
381 |
|
|
382 |
byte flag = bb.get(); |
|
383 |
byte[] nameBytes = new byte[32]; |
|
384 |
bb.get(nameBytes); |
|
385 |
String name = new String(nameBytes); |
|
386 |
|
|
387 |
bb.order(ByteOrder.LITTLE_ENDIAN); |
|
388 |
short used = bb.getShort(); |
|
389 |
|
|
390 |
double[] pt10 = getPoint(false); |
|
391 |
double[] pt11 = getPoint(false); |
|
392 |
double[] pt17 = getPoint(false); |
|
393 |
double[] pt16 = getPoint(true); |
|
394 |
|
|
395 |
bb.order(ByteOrder.LITTLE_ENDIAN); |
|
396 |
|
|
397 |
double d50 = bb.getDouble(); |
|
398 |
double d40 = bb.getDouble(); |
|
399 |
|
|
400 |
double[] pt12 = getPoint(false); |
|
401 |
|
|
402 |
bb.order(ByteOrder.LITTLE_ENDIAN); |
|
403 |
double d41 = bb.getDouble(); |
|
404 |
double d42 = bb.getDouble(); |
|
405 |
double d43 = bb.getDouble(); |
|
406 |
double d44 = bb.getDouble(); |
|
407 |
|
|
408 |
short[] w7178 = new short[8]; |
|
409 |
for(int j = 0; j < 8; j++){ |
|
410 |
w7178[j] = bb.getShort(); |
|
411 |
} |
|
412 |
bb.order(ByteOrder.LITTLE_ENDIAN); |
|
413 |
double d51 = bb.getDouble(); |
|
414 |
|
|
415 |
double[] pt13 = getPoint(false); |
|
416 |
double[] pt14 = getPoint(false); |
|
417 |
double[] pt15 = getPoint(false); |
|
418 |
|
|
419 |
int offset = end - bb.position(); |
|
420 |
if(offset > 0) |
|
421 |
bb.position(bb.position() + offset); |
|
422 |
|
|
423 |
bb.order(ByteOrder.LITTLE_ENDIAN); |
|
424 |
short crc = bb.getShort(); |
|
425 |
} |
|
426 |
byte[] crc32 = new byte[32]; |
|
427 |
bb.get(crc32); |
|
428 |
} |
|
429 |
|
|
430 |
|
|
431 |
|
|
432 |
private void readUcsTable(Dwg12Table ucsTable) { |
|
433 |
short size = ucsTable.s1; |
|
434 |
int numRecs = ucsTable.i1; |
|
435 |
int start = ucsTable.i2; |
|
436 |
int end = -1; |
|
437 |
bb.position(start); |
|
438 |
for(int i = 0; i < numRecs; i++){ |
|
439 |
end = bb.position() + size; |
|
440 |
|
|
441 |
byte flag = bb.get(); |
|
442 |
byte[] nameBytes = new byte[32]; |
|
443 |
bb.get(nameBytes); |
|
444 |
String name = new String(nameBytes); |
|
445 |
|
|
446 |
bb.order(ByteOrder.LITTLE_ENDIAN); |
|
447 |
short used = bb.getShort(); |
|
448 |
|
|
449 |
double[] pt10 = getPoint(true); |
|
450 |
double[] pt11 = getPoint(true); |
|
451 |
double[] pt12 = getPoint(true); |
|
452 |
|
|
453 |
|
|
454 |
|
|
455 |
int offset = end - bb.position(); |
|
456 |
if(offset > 0) |
|
457 |
bb.position(bb.position() + offset); |
|
458 |
|
|
459 |
bb.order(ByteOrder.LITTLE_ENDIAN); |
|
460 |
short crc = bb.getShort(); |
|
461 |
} |
|
462 |
byte[] crc32 = new byte[32]; |
|
463 |
bb.get(crc32); |
|
464 |
|
|
465 |
|
|
466 |
} |
|
467 |
|
|
468 |
|
|
469 |
|
|
470 |
private void readViewTable(Dwg12Table viewTable) { |
|
471 |
short size = viewTable.s1; |
|
472 |
int numRecs = viewTable.i1; |
|
473 |
int start = viewTable.i2; |
|
474 |
int end = -1; |
|
475 |
bb.position(start); |
|
476 |
for(int i = 0; i < numRecs; i++){ |
|
477 |
end = bb.position() + size; |
|
478 |
|
|
479 |
byte flag = bb.get(); |
|
480 |
byte[] nameBytes = new byte[32]; |
|
481 |
bb.get(nameBytes); |
|
482 |
String name = new String(nameBytes); |
|
483 |
|
|
484 |
bb.order(ByteOrder.LITTLE_ENDIAN); |
|
485 |
short used = bb.getShort(); |
|
486 |
double db40 = bb.getDouble(); |
|
487 |
|
|
488 |
double[] pt10 = getPoint(false); |
|
489 |
|
|
490 |
bb.order(ByteOrder.LITTLE_ENDIAN); |
|
491 |
double db41 = bb.getDouble(); |
|
492 |
|
|
493 |
double[] pt11 = getPoint(true); |
|
494 |
|
|
495 |
double[] pt12 = getPoint(true); |
|
496 |
|
|
497 |
|
|
498 |
bb.order(ByteOrder.LITTLE_ENDIAN); |
|
499 |
short w71 = bb.getShort(); |
|
500 |
double db42 = bb.getDouble(); |
|
501 |
double db43 = bb.getDouble(); |
|
502 |
double db44 = bb.getDouble(); |
|
503 |
double db50 = bb.getDouble(); |
|
504 |
|
|
505 |
int offset = end - bb.position(); |
|
506 |
if(offset > 0) |
|
507 |
bb.position(bb.position() + offset); |
|
508 |
|
|
509 |
bb.order(ByteOrder.LITTLE_ENDIAN); |
|
510 |
short crc = bb.getShort(); |
|
511 |
|
|
512 |
|
|
513 |
} |
|
514 |
byte[] crc32 = new byte[32]; |
|
515 |
bb.get(crc32); |
|
516 |
} |
|
517 |
|
|
518 |
|
|
519 |
|
|
520 |
private void readLTypeTable(Dwg12Table lineTypeTable) { |
|
521 |
short size = lineTypeTable.s1; |
|
522 |
int numRecs = lineTypeTable.i1; |
|
523 |
int start = lineTypeTable.i2; |
|
524 |
int end = -1; |
|
525 |
bb.position(start); |
|
526 |
for(int i = 0; i < numRecs; i++){ |
|
527 |
end = bb.position() + size; |
|
528 |
byte flag = bb.get(); |
|
529 |
byte[] nameBytes = new byte[32]; |
|
530 |
bb.get(nameBytes); |
|
531 |
String name = new String(nameBytes); |
|
532 |
bb.order(ByteOrder.LITTLE_ENDIAN); |
|
533 |
short w1 = bb.getShort(); |
|
534 |
|
|
535 |
byte[] s1 = new byte[48]; |
|
536 |
bb.get(s1); |
|
537 |
String s1name = new String(s1); |
|
538 |
|
|
539 |
bb.order(ByteOrder.nativeOrder()); |
|
540 |
byte b1 = bb.get(); |
|
541 |
byte b2 = bb.get(); |
|
542 |
|
|
543 |
bb.order(ByteOrder.LITTLE_ENDIAN); |
|
544 |
double[] doubles = new double[13]; |
|
545 |
for(int j = 0; j < 13; j++){ |
|
546 |
doubles[j] = bb.getDouble(); |
|
547 |
} |
|
548 |
|
|
549 |
short crc = bb.getShort(); |
|
550 |
|
|
551 |
int offset = end - bb.position(); |
|
552 |
if(offset > 0) |
|
553 |
bb.position(bb.position() + offset); |
|
554 |
} |
|
555 |
byte[] crc32 = new byte[32]; |
|
556 |
bb.get(crc32); |
|
557 |
} |
|
558 |
|
|
559 |
|
|
560 |
|
|
258 | 561 |
/** |
259 | 562 |
* @param styleTable |
260 | 563 |
*/ |
... | ... | |
331 | 634 |
|
332 | 635 |
class LineReader implements EntityReader{ |
333 | 636 |
public void read(ByteBuffer bb, char flags, short opts) { |
637 |
|
|
638 |
boolean zflag = true; |
|
639 |
if( (flags & 0x4) > 0) |
|
640 |
zflag = false; |
|
641 |
|
|
642 |
double[] pt10 = getPoint(zflag); |
|
643 |
double[] pt11 = getPoint(zflag); |
|
644 |
|
|
645 |
if((opts & 0x1) > 0){ |
|
646 |
double[] pt210 = getPoint(true); |
|
647 |
} |
|
648 |
|
|
649 |
if((opts & 0x2) > 0){ |
|
650 |
bb.order(ByteOrder.LITTLE_ENDIAN); |
|
651 |
double db38 = bb.getDouble(); |
|
652 |
} |
|
334 | 653 |
} |
335 | 654 |
} |
336 | 655 |
|
656 |
|
|
657 |
|
|
337 | 658 |
class PointReader implements EntityReader{ |
338 | 659 |
public void read(ByteBuffer bb, char flags, short opts) { |
660 |
boolean zflag = true; |
|
661 |
if((flags & 0x4) > 0) |
|
662 |
zflag = false; |
|
663 |
double[] pt10 = getPoint(zflag); |
|
664 |
|
|
665 |
if((opts & 0x1) > 0){ |
|
666 |
double[] pt210 = getPoint(true); |
|
667 |
} |
|
668 |
|
|
669 |
if((opts & 0x2) > 0){ |
|
670 |
bb.order(ByteOrder.LITTLE_ENDIAN); |
|
671 |
double db38 = bb.getDouble(); |
|
672 |
} |
|
339 | 673 |
} |
340 | 674 |
} |
675 |
|
|
676 |
|
|
341 | 677 |
class CircleReader implements EntityReader{ |
342 | 678 |
public void read(ByteBuffer bb, char flags, short opts) { |
679 |
boolean zflag = true; |
|
680 |
if((flags & 0x4) > 0) |
|
681 |
zflag = false; |
|
682 |
double[] pt10 = getPoint(zflag); |
|
683 |
bb.order(ByteOrder.LITTLE_ENDIAN); |
|
684 |
double d40 = bb.getDouble(); |
|
685 |
|
|
686 |
if((opts & 0x1) > 0){ |
|
687 |
double[] pt210 = getPoint(true); |
|
688 |
} |
|
689 |
|
|
690 |
if((opts & 0x2) > 0){ |
|
691 |
bb.order(ByteOrder.LITTLE_ENDIAN); |
|
692 |
double db38 = bb.getDouble(); |
|
693 |
} |
|
343 | 694 |
} |
344 | 695 |
} |
696 |
|
|
697 |
|
|
698 |
|
|
345 | 699 |
class ShapeReader implements EntityReader{ |
346 | 700 |
public void read(ByteBuffer bb, char flags, short opts) { |
701 |
double[] pt10 = getPoint(false); |
|
702 |
bb.order(ByteOrder.LITTLE_ENDIAN); |
|
703 |
short w2 = bb.getShort(); |
|
704 |
if((opts & 0x1) > 0){ |
|
705 |
double[] pt210 = getPoint(true); |
|
706 |
} |
|
707 |
if((opts & 0x2) > 0){ |
|
708 |
bb.order(ByteOrder.LITTLE_ENDIAN); |
|
709 |
double db38 = bb.getDouble(); |
|
710 |
} |
|
347 | 711 |
} |
348 | 712 |
} |
713 |
|
|
714 |
public String getString(){ |
|
715 |
bb.order(ByteOrder.LITTLE_ENDIAN); |
|
716 |
short len = bb.getShort(); |
|
717 |
byte[] bytes = new byte[len]; |
|
718 |
bb.order(ByteOrder.nativeOrder()); |
|
719 |
bb.get(bytes); |
|
720 |
return new String(bytes); |
|
721 |
} |
|
349 | 722 |
class TextReader implements EntityReader{ |
350 | 723 |
public void read(ByteBuffer bb, char flags, short opts) { |
724 |
double[] pt10 = getPoint(false); |
|
725 |
bb.order(ByteOrder.LITTLE_ENDIAN); |
|
726 |
double db40 = bb.getDouble(); |
|
727 |
String text = getString(); |
|
728 |
if((opts & 0x1) > 0){ |
|
729 |
bb.order(ByteOrder.LITTLE_ENDIAN); |
|
730 |
double db50 = bb.getDouble(); |
|
731 |
} |
|
732 |
if((opts & 0x2) > 0){ |
|
733 |
double db41 = bb.getDouble(); |
|
734 |
} |
|
735 |
if((opts & 0x4) > 0){ |
|
736 |
double db51 = bb.getDouble(); |
|
737 |
} |
|
738 |
if((opts & 0x8) > 0){ |
|
739 |
byte b7 = bb.get(); |
|
740 |
} |
|
741 |
if((opts & 0x10) > 0){ |
|
742 |
byte b71 = bb.get(); |
|
743 |
} |
|
744 |
if((opts & 0x20) > 0){ |
|
745 |
byte b72 = bb.get(); |
|
746 |
} |
|
747 |
if((opts & 0x40) > 0){ |
|
748 |
double[] pt11 = getPoint(false); |
|
749 |
} |
|
750 |
if((opts & 0x100) > 0){ |
|
751 |
byte b73 = bb.get(); |
|
752 |
} |
|
351 | 753 |
} |
352 | 754 |
} |
755 |
|
|
756 |
|
|
353 | 757 |
class ArcReader implements EntityReader{ |
354 | 758 |
public void read(ByteBuffer bb, char flags, short opts) { |
759 |
double[] pt10 = getPoint(false); |
|
760 |
bb.order(ByteOrder.LITTLE_ENDIAN); |
|
761 |
double d40 = bb.getDouble(); |
|
762 |
double d50 = bb.getDouble(); |
|
763 |
double d51 = bb.getDouble(); |
|
764 |
if((opts & 0x1) > 0){ |
|
765 |
double[] pt210 = getPoint(true); |
|
766 |
} |
|
767 |
if((opts & 0x2) > 0){ |
|
768 |
bb.order(ByteOrder.LITTLE_ENDIAN); |
|
769 |
double db38 = bb.getDouble(); |
|
770 |
} |
|
355 | 771 |
} |
356 | 772 |
} |
357 | 773 |
|
774 |
|
|
775 |
|
|
358 | 776 |
class TraceReader implements EntityReader{ |
359 | 777 |
public void read(ByteBuffer bb, char flags, short opts) { |
778 |
double[] pt10 = getPoint(false); |
|
779 |
double[] pt11 = getPoint(false); |
|
780 |
double[] pt12 = getPoint(false); |
|
781 |
double[] pt13 = getPoint(false); |
|
782 |
if((opts & 0x1) > 0){ |
|
783 |
double[] pt210 = getPoint(true); |
|
784 |
} |
|
785 |
if((opts & 0x2) > 0){ |
|
786 |
bb.order(ByteOrder.LITTLE_ENDIAN); |
|
787 |
double db38 = bb.getDouble(); |
|
788 |
} |
|
360 | 789 |
} |
361 | 790 |
} |
362 | 791 |
|
363 | 792 |
class SolidReader implements EntityReader{ |
364 | 793 |
public void read(ByteBuffer bb, char flags, short opts) { |
794 |
double[] pt10 = getPoint(false); |
|
795 |
double[] pt11 = getPoint(false); |
|
796 |
double[] pt12 = getPoint(false); |
|
797 |
double[] pt13 = getPoint(false); |
|
798 |
double[] pt14 = getPoint(false); |
|
799 |
if((opts & 0x1) > 0){ |
|
800 |
double[] pt210 = getPoint(true); |
|
801 |
} |
|
802 |
if((opts & 0x2) > 0){ |
|
803 |
bb.order(ByteOrder.LITTLE_ENDIAN); |
|
804 |
double db38 = bb.getDouble(); |
|
805 |
} |
|
365 | 806 |
} |
366 | 807 |
} |
367 | 808 |
|
368 | 809 |
class BlkReader implements EntityReader{ |
369 | 810 |
public void read(ByteBuffer bb, char flags, short opts) { |
811 |
double[] pt10 = getPoint(false); |
|
812 |
String blockName = getString(); |
|
813 |
if((opts & 0x2) > 0) |
|
814 |
{ |
|
815 |
//puede ser que se trate de referencias |
|
816 |
//externas?? |
|
817 |
String s3 = getString(); |
|
818 |
} |
|
819 |
|
|
370 | 820 |
} |
371 | 821 |
} |
372 | 822 |
class EndBlkReader implements EntityReader{ |
373 | 823 |
public void read(ByteBuffer bb, char flags, short opts) { |
824 |
// |
|
374 | 825 |
} |
375 | 826 |
} |
376 | 827 |
|
377 | 828 |
class InsertReader implements EntityReader{ |
378 | 829 |
public void read(ByteBuffer bb, char flags, short opts) { |
830 |
|
|
831 |
/* |
|
832 |
def insert_reader(handle, flags, opts): |
|
833 |
print "insert_reader() ..." |
|
834 |
_w1 = struct.unpack('<h', handle.read(2))[0] |
|
835 |
print "word: %d" % _w1 |
|
836 |
_p10 = get_point(handle, False) |
|
837 |
print "point: " + str(_p10) |
|
838 |
if (opts & 0x1): |
|
839 |
_db41 = struct.unpack('<d', handle.read(8))[0] |
|
840 |
print "double: %g" % _db41 |
|
841 |
if (opts & 0x2): |
|
842 |
_db42 = struct.unpack('<d', handle.read(8))[0] |
|
843 |
print "double: %g" % _db42 |
|
844 |
if (opts & 0x4): |
|
845 |
_db43 = struct.unpack('<d', handle.read(8))[0] |
|
846 |
print "double: %g" % _db43 |
|
847 |
if (opts & 0x8): |
|
848 |
_db50 = struct.unpack('<d', handle.read(8))[0] |
|
849 |
print "double: %g" % _db50 |
|
850 |
if (opts & 0x10): |
|
851 |
_w70 = struct.unpack('<h', handle.read(2))[0] |
|
852 |
print "word: %d" % _w70 |
|
853 |
if (opts & 0x10): |
|
854 |
_w71 = struct.unpack('<h', handle.read(2))[0] |
|
855 |
print "word: %d" % _w71 |
|
856 |
if (opts & 0x40): |
|
857 |
_db44 = struct.unpack('<d', handle.read(8))[0] |
|
858 |
print "double: %g" % _db44 |
|
859 |
if (opts & 0x80): |
|
860 |
_db45 = struct.unpack('<d', handle.read(8))[0] |
|
861 |
print "double: %g" % _db45 |
|
862 |
*/ |
|
863 |
|
|
864 |
|
|
379 | 865 |
} |
380 | 866 |
} |
381 | 867 |
|
... | ... | |
656 | 1142 |
} |
657 | 1143 |
|
658 | 1144 |
public void readHeader(){ |
1145 |
bb.order(ByteOrder.LITTLE_ENDIAN); |
|
1146 |
short w1 = bb.getShort(); |
|
659 | 1147 |
|
1148 |
double[] inBase = getPoint(true); |
|
1149 |
double[] extMin = getPoint(true); |
|
1150 |
double[] extMax = getPoint(true); |
|
1151 |
double[] limMin = getPoint(false); |
|
1152 |
double[] limMax = getPoint(false); |
|
660 | 1153 |
|
1154 |
bb.order(ByteOrder.LITTLE_ENDIAN); |
|
1155 |
double vcx = bb.getDouble(); |
|
1156 |
double vcy = bb.getDouble(); |
|
1157 |
double d3 = bb.getDouble(); |
|
1158 |
double d4 = bb.getDouble(); |
|
661 | 1159 |
|
1160 |
byte b1 = bb.get(); |
|
1161 |
byte b2 = bb.get(); |
|
662 | 1162 |
|
663 |
/* |
|
664 |
def read_header(handle): |
|
665 |
print "read_header() ..." |
|
666 |
_w1 = struct.unpack("<h", handle.read(2))[0] |
|
667 |
print "word: %d" % _w1 |
|
668 |
_inbase = get_point(handle, True) |
|
669 |
print "inbase: " + str(_inbase) |
|
670 |
_extmin = get_point(handle, True) |
|
671 |
print "extmin: " + str(_extmin) |
|
672 |
_extmax = get_point(handle, True) |
|
673 |
print "extmax: " + str(_extmax) |
|
674 |
_limmin = get_point(handle, False) |
|
675 |
print "limmin: " + str(_limmin) |
|
676 |
_limmax = get_point(handle, False) |
|
677 |
print "limmax: " + str(_limmax) |
|
678 |
_vcx, _vcy, _d3, _d4 = struct.unpack("<dddd", handle.read(32)) |
|
679 |
print "view center: (%g, %g)" % (_vcx, _vcy) |
|
680 |
print "doubles: %g, %g" % (_d3, _d4) |
|
681 |
_b1, _b2 = struct.unpack("<BB", handle.read(2)) |
|
682 |
print "bytes: %#02x, %#02x" % (_b1, _b2) |
|
683 |
_sx, _sy = struct.unpack("<dd", handle.read(16)) |
|
684 |
print "snap units: (%g,%g)" % (_sx, _sy) |
|
685 |
_b56 = array.array('B') |
|
686 |
_b56.fromfile(handle, 56) |
|
687 |
print "56 bytes: " + str(_b56) |
|
688 |
_d7, _d8, _d9 = struct.unpack("<ddd", handle.read(24)) |
|
689 |
print "doubles: %g, %g, %g" % (_d7, _d8, _d9) |
|
690 |
_b18 = array.array('B') |
|
691 |
_b18.fromfile(handle, 18) |
|
692 |
print "18 bytes: " + str(_b18) |
|
693 |
_d10 = struct.unpack("<d", handle.read(8)) |
|
694 |
print "double: %g" % _d10 |
|
695 |
# |
|
696 |
# the following comes from the C code |
|
697 |
# |
|
698 |
_at = handle.tell() |
|
699 |
print "handle offset: %d [%#x]" % (_at, _at) |
|
700 |
_w2, _w3 = struct.unpack("<hh", handle.read(4)) |
|
701 |
print "word: %d, %d" % (_w2, _w3) |
|
702 |
_b44 = array.array('B') |
|
703 |
_b44.fromfile(handle, 44) |
|
704 |
print "44 bytes: " + str(_b44) |
|
705 |
_at = handle.tell() |
|
706 |
print "handle offset: %d [%#x]" % (_at, _at) |
|
707 |
_b354 = array.array('B') |
|
708 |
_b354.fromfile(handle, 354) |
|
709 |
print "354 more bytes read ..." |
|
710 |
if _b354[0:4] == [0x61,0x63,0x61,0x64]: # acad |
|
711 |
print "found 'acad' at start of 354 byte block" |
|
712 |
_at = handle.tell() |
|
713 |
print "handle offset: %d [%#x]" % (_at, _at) |
|
714 |
# |
|
715 |
# skip to 0x3ef - remainder of header is mysterious ... |
|
716 |
# |
|
717 |
handle.seek(0x3ef, 0) |
|
718 |
|
|
719 |
*/ |
|
1163 |
double sx = bb.getDouble(); |
|
1164 |
double sy = bb.getDouble(); |
|
1165 |
|
|
1166 |
bb.order(ByteOrder.nativeOrder()); |
|
1167 |
byte[] b56 = new byte[56]; |
|
1168 |
bb.get(b56); |
|
1169 |
|
|
1170 |
bb.order(ByteOrder.LITTLE_ENDIAN); |
|
1171 |
double d7 = bb.getDouble(); |
|
1172 |
double d8 = bb.getDouble(); |
|
1173 |
double d9 = bb.getDouble(); |
|
1174 |
|
|
1175 |
bb.order(ByteOrder.nativeOrder()); |
|
1176 |
byte[] b18 = new byte[18]; |
|
1177 |
bb.get(b18); |
|
1178 |
|
|
1179 |
bb.order(ByteOrder.LITTLE_ENDIAN); |
|
1180 |
double d10 = bb.getDouble(); |
|
1181 |
|
|
1182 |
int at = bb.position(); |
|
1183 |
|
|
1184 |
bb.order(ByteOrder.LITTLE_ENDIAN); |
|
1185 |
short w2 = bb.getShort(); |
|
1186 |
short w3 = bb.getShort(); |
|
1187 |
|
|
1188 |
bb.order(ByteOrder.nativeOrder()); |
|
1189 |
byte[] b44 = new byte[44]; |
|
1190 |
bb.get(b44); |
|
1191 |
|
|
1192 |
at = bb.position(); |
|
1193 |
|
|
1194 |
bb.order(ByteOrder.nativeOrder()); |
|
1195 |
byte[] b354 = new byte[354]; |
|
1196 |
bb.get(b354); |
|
1197 |
|
|
1198 |
if( (b354[0] == 0x61) && (b354[1] == 0x63) && (b354[2] == 0x61 ) && (b354[2] == 0x64 )) |
|
1199 |
System.out.println("Encontrada la cadena 'acad' al comienzo del bloque de 354 bytes"); |
|
1200 |
|
|
1201 |
bb.position(0x3ef); |
|
720 | 1202 |
} |
721 | 1203 |
|
722 | 1204 |
|
Also available in: Unified diff