Revision 10183

View differences:

trunk/libraries/libDwg/src/com/iver/cit/jdwglib/dwg/readers/DwgFileV14Reader.java
38 38
import java.nio.ByteBuffer;
39 39
import java.nio.ByteOrder;
40 40
import java.util.ArrayList;
41
import java.util.HashMap;
42 41
import java.util.List;
43
import java.util.Map;
44 42

  
45 43
import org.apache.log4j.Logger;
46 44

  
......
52 50
import com.iver.cit.jdwglib.dwg.DwgObjectFactory;
53 51
import com.iver.cit.jdwglib.dwg.DwgObjectOffset;
54 52
import com.iver.cit.jdwglib.dwg.DwgUtil;
53
import com.iver.cit.jdwglib.dwg.objects.DwgLwPolyline;
55 54

  
56 55
/**
57 56
 * The DwgFileV14Reader reads the DWG version 14 format
......
68 67
	private static Logger logger = Logger.
69 68
		getLogger(DwgFileV14Reader.class.getName());
70 69
	
70
	
71
	int numPolylinesWrong = 0;
72
	
71 73
	/**
72 74
	 * Reads the DWG version 15 format
73 75
	 * 
......
156 158
		byte[] data = new byte[size];
157 159
		bb.get(data);
158 160
		
159
		/*
160
		 * J.Morell hacia esto para leer los datos como int[]
161
		   int[] data = new int[size];
162
			for (int i=0; i < size; i++) {
163
				dataBytes[i] = bb.get();
164
				dataMachValString[i] = HexUtil.bytesToHex(new byte[]{dataBytes[i]});
165
				Integer dataMachValShort = Integer.decode("0x" + dataMachValString[i]);
166
				data[i] = dataMachValShort.byteValue();
167
				data[i] = ByteUtils.getUnsigned((byte)data[i]);
168
			}
169
		 * TODO Hace falta esto????
170
		 * 
171
		 * */
172 161
		int[] intData = DwgUtil.toIntArray(data);
173 162
		
174 163
		
......
1512 1501
	 * DWG file (using their object file obsets)
1513 1502
	 * */
1514 1503
	protected void readDwgObjects() {
1515
		Map vmap = new HashMap();
1516
		List dwgClasses = dwgFile.getDwgClasses();
1517
		for (int i = 0; i < dwgClasses.size(); i++){
1518
			DwgClass dwgClass = (DwgClass) dwgClasses.get(i);
1519
			vmap.put(new Integer(dwgClass.getClassNum()), dwgClass.getDxfName());
1520
			logger.info("Mapeando tipo "+dwgClass.getClassNum()+" con "+dwgClass.getDxfName());
1521
		}
1522 1504
		logger.info("Vamos a leer "+dwgFile.getDwgObjectOffsets().size()+" objetos");
1523 1505

  
1524 1506
		for (int i=0; i<dwgFile.getDwgObjectOffsets().size(); i++) {
1525 1507
			DwgObjectOffset doo = (DwgObjectOffset)dwgFile.getDwgObjectOffsets().get(i);
1526 1508
			DwgObject obj = readDwgObject(doo.getOffset(), i);
1527
			/*
1528
			azabala: las entidades DWG no implementadas no nos aportan nada
1529
			(aunque la sigo leyendo por si aparecen problemas de puntero de fichero)
1530
			No considero por tanto los DwgObject
1531
			if (obj != null) {
1532
                dwgFile.addDwgObject(obj);
1533
            }
1534
            */
1535 1509
			if(obj != null && obj.getClass() != DwgObject.class){
1536 1510
				dwgFile.addDwgObject(obj);
1537 1511
			}
1538 1512
		}//for
1513
		System.out.println("####LWPolyline erroneas:"+numPolylinesWrong+"####");
1514
		System.out.println("####################################");
1539 1515
	}
1540 1516
	
1541 1517
	/**
......
1558 1534

  
1559 1535
	
1560 1536
	protected DwgObject readDwgObject(int offset, int index) {
1537
		DwgObject obj = null;
1561 1538
		try {
1562 1539
			bb.position(offset);
1563 1540
			int size = DwgUtil.getModularShort(bb);
1564 1541
			bb.order(ByteOrder.nativeOrder());
1565
			
1566
			//LITTLE ENDIAN es intel, mientras que el codigo Python hace
1567
			//una lectura con bytes de la maquina (en un equipo no intel 
1568
			//puede que no funcione
1569
//			TODO bb.order(ByteOrder.LITTLE_ENDIAN);
1570
			
1571 1542
			byte[] data = new byte[size];
1572
			
1573
			/*
1574
			 * TODO Ver si funciona lo mio (mas simple?)
1575
			String[] dataMachValString = new String[size];
1576
			int[] data = new int[size];
1577
			for (int i=0; i < size; i++) {
1578
				dataBytes[i] = bb.get();
1579
				dataMachValString[i] = HexUtil.bytesToHex(new byte[]{dataBytes[i]});
1580
				Integer dataMachValShort = Integer.decode("0x" + dataMachValString[i]);
1581
				data[i] = dataMachValShort.byteValue();
1582
				data[i] = ByteUtils.getUnsigned((byte)data[i]);
1583
			}
1584
			*/
1585 1543
			bb.get(data);
1586 1544
			int[] intData = DwgUtil.toIntArray(data);
1587
			
1588
		
1589 1545
			int bitPos = 0;
1590 1546
			List val = DwgUtil.getBitShort(intData, bitPos);
1591 1547
			bitPos = ((Integer)val.get(0)).intValue();
1592 1548
			int type = ((Integer)val.get(1)).intValue();
1593 1549
			
1594
			DwgObject obj = DwgObjectFactory.
1550
			obj = DwgObjectFactory.
1595 1551
								getInstance().
1596 1552
								create(type, index);
1597 1553
			obj.setVersion(dwgFile.getDwgVersion());
......
1663 1619
		    			dwg.setExtendedData(obj.getExtendedData());
1664 1620
		    			dwg.setSizeInBits(obj.getSizeInBits());
1665 1621
		    			dwg.setGraphicData(obj.getGraphicData());
1666
		    			readSpecificObject(dwg, intData, bitPos);
1667 1622
		    			obj = dwg;
1623
		    			readSpecificObject(obj, intData, bitPos);
1668 1624
		    			
1669 1625
		    			
1626
		    			
1670 1627
		    		}
1671 1628
		    	}//if type 500
1672 1629
		    	else{
......
1690 1647
	    } catch (Exception e) {
1691 1648
//	        logger.warn("Exception capturada. Probablemente se ha encontrado un" +
1692 1649
//	        		"objeto con type non fixed");
1650
	    	if(obj instanceof DwgLwPolyline){
1651
	    		numPolylinesWrong++;
1652
	    	}
1693 1653
	        e.printStackTrace();
1694 1654
	        return null;
1695 1655
	    }
trunk/libraries/libDwg/src/com/iver/cit/jdwglib/dwg/readers/DwgFileV15Reader.java
48 48
import com.iver.cit.jdwglib.dwg.DwgObjectFactory;
49 49
import com.iver.cit.jdwglib.dwg.DwgObjectOffset;
50 50
import com.iver.cit.jdwglib.dwg.DwgUtil;
51
import com.iver.cit.jdwglib.dwg.objects.DwgLwPolyline;
51 52

  
52 53
import freenet.support.HexUtil;
53 54

  
......
61 62

  
62 63
	protected ByteBuffer bb;
63 64

  
65
	private int numWrongPolylines;
66

  
64 67
	/**
65 68
	 * Reads the DWG version 15 format
66 69
	 * 
......
226 229
				dwgFile.addDwgObject(obj);
227 230
			}
228 231
		}
232
		System.out.println("####LWPolyline erroneas:"+numWrongPolylines+"####");
233
		System.out.println("####################################");
229 234
	}
230 235

  
231 236
	/**
......
450 455
//					System.out.println("Dwg Object desconocido:"+obj.getType());
451 456
		} catch (RuntimeException e) {
452 457
			e.printStackTrace();
458
			if(obj instanceof DwgLwPolyline){
459
				numWrongPolylines++;
460
			}
453 461
		} catch (CorruptedDwgEntityException e) {
454 462
			// TODO Auto-generated catch block
455 463
			e.printStackTrace();
464
			if(obj instanceof DwgLwPolyline){
465
				numWrongPolylines++;
466
			}
456 467
			return null;
457 468
			
458 469
		}

Also available in: Unified diff