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 |
}
|