Revision 10820 trunk/libraries/libDwg/src/com/iver/cit/jdwglib/dwg/readers/DwgFileV12Reader.java

View differences:

DwgFileV12Reader.java
95 95
	private DwgFile dwgFile;
96 96
	private ByteBuffer bb;
97 97
	ArrayList readers = new ArrayList();
98
	/*
99
	 * En Python:
100
	 *  if _version != 'AC1009':
101
        if _version == 'AC1010':
102
            r13 = True
103
        else:
104
            print "unknown version"
105
	 * 
106
	 * */
107 98
	private boolean r13 = false;
108 99
	int index = 0;
109 100
	
......
198 189
			byte[] header = new byte[12];
199 190
			bb.get(header);
200 191
			String headerStr = new String(header);
201
			System.out.println(headerStr);
202 192
			
203 193
//		    (_b1, _w1, _w2, _w3, _b2) = struct.unpack("<BhhhB", handle.read(8))
204 194
			bb.order(ByteOrder.LITTLE_ENDIAN);
......
731 721
			short style = bb.getShort();
732 722
			short crc = bb.getShort();
733 723

  
734
			//TODO Vemos si el indice que ocupa la layer en la tabla
735
			//de layers se corresponde con el valor short de las entidades
736
			//graficas
737 724
			DwgHandleReference handle = new DwgHandleReference(0x5, i);
738 725
			layer.setHandle(handle);
739 726
			dwgFile.addDwgObject(layer);
......
1081 1068
			double[] pt10 = getPoint(false);
1082 1069
			blk.setBasePoint(pt10);
1083 1070
			String blockName = getString();
1084
			
1071
			blk.setName(blockName);
1085 1072
			Block block = getBlock(blockName);
1086 1073
			if(block == null){
1087 1074
				System.out.println(blockName+" no encontrado en la tabla de bloques");
1088 1075
			}
1089 1076
			
1090
			//TODO En DWG 12 no se distingue Block de BlockHeader, en ulteriores
1091
			//versiones si
1092
			//REVISAR EL CASO DE LOS BLOQUES
1093
			
1094
			
1095 1077
			if((opts & 0x2) > 0)
1096 1078
			{
1097 1079
				//puede ser que se trate de referencias
......
1149 1131
	}
1150 1132
	class EndBlkReader implements EntityReader{
1151 1133
		public void read(ByteBuffer bb, byte flags, short opts, DwgObject dwgObj) {
1152
			System.out.println("endblk");
1153 1134
		}
1154 1135
	}
1155 1136
	
......
1162 1143
			bb.order(ByteOrder.nativeOrder());
1163 1144
			short w1 = bb.getShort();//Puede ser este el identificador de bloque???
1164 1145
			
1146
			DwgHandleReference blockHandle = new 
1147
				DwgHandleReference(0x5, w1);
1148
			insert.setBlockHeaderHandle(blockHandle);
1149
			
1165 1150
			double[] pt10 = getPoint(false);
1166 1151
			insert.setInsertionPoint(pt10);
1167 1152
			
1168
			
1169 1153
			bb.order(ByteOrder.LITTLE_ENDIAN);
1170 1154
			
1171 1155
			double x = 0d, y = 0d, z = 0d;
......
1368 1352
		byte curveType75;
1369 1353
		
1370 1354
		
1355
		private void reset(){
1356
			flag70 = 0;
1357
			meshM71 = 0;
1358
			meshN72 = 0;
1359
			startW40 = 0;
1360
			smoothM73 = 0;
1361
			smoothN74 = 0;
1362
			curveType75 = 0;
1363
		}
1364
		
1371 1365
		public void read(ByteBuffer bb, byte flags, short opts, DwgObject dwgObj) {
1372 1366
			super.read(bb, flags, opts, dwgObj);
1373 1367
			
......
1449 1443
				}
1450 1444
			}
1451 1445
			
1446
			reset();
1452 1447
			
1453 1448
			return solution;
1454 1449
		}
......
1507 1502
		 * */
1508 1503
		byte vertexFlag70;
1509 1504
		
1505
		/**
1506
		 * If the vertex is a pfaceface vertex it hasnt real coordinates.
1507
		 * Instead it has an index for each vertex of the mesh's face
1508
		 * */
1509
		int[] pfacefaceIndex;
1510 1510
		
1511
		void reset(){
1512
			pt10 = null;
1513
			startWidth40 = 0;
1514
			endWidth41 = 0;
1515
			tangentDir50 = 0;
1516
			vertexFlag70 = 0;
1517
			pfacefaceIndex = null;
1511 1518
		
1519
		}
1520
		
1521
		/*
1522
		 * azabala
1523
		 * Nos estabamos encontrando con vertices muy raros
1524
		 * (e incluso con valores NaN) cuando el valor de opts
1525
		 * es 16872, si seguiamos al pie de la letra la especificaci?n
1526
		 * de http://www.iwriteiam.nl/DWG12.html o Pythoncad.
1527
		 * 
1528
		 * Haciendo un poco de ingenieria inversa hemos visto que
1529
		 * si opts==16872, hay que modificar el algoritmo 
1530
		 * */
1531
		
1512 1532
		public void read(ByteBuffer bb, byte flags, short opts, DwgObject dwgObj) {
1513 1533
			super.read(bb, flags, opts, dwgObj);
1514
			pt10 = getPoint(false);
1515
			bb.order(ByteOrder.LITTLE_ENDIAN);
1516
			if((opts & 0x1) > 0){
1517
				startWidth40 = bb.getDouble();
1534
			if(opts != 16872){
1535
				int position = bb.position();
1536
				pt10 = getPoint(false);
1537
if(pt10[0] < 0 || pt10[0] < 600000 || pt10[0] > 800000){
1538
System.currentTimeMillis();
1539
}
1540
				bb.order(ByteOrder.LITTLE_ENDIAN);
1541
				if((opts & 0x1) > 0){
1542
					startWidth40 = bb.getDouble();
1543
				}
1544
				if((opts & 0x2) > 0){
1545
					endWidth41 = bb.getDouble();
1546
				}
1547
				if((opts & 0x4) > 0){
1548
					tangentDir50 = bb.getDouble();
1549
				}
1550
				if((opts & 0x8) > 0){
1551
					vertexFlag70 = bb.get();
1552
				}
1553
			}else{
1554
				//if opts == 16872 (decimal) we invert the
1555
				//order of the reading
1556
				bb.order(ByteOrder.LITTLE_ENDIAN);
1557
				if((opts & 0x1) > 0){
1558
					startWidth40 = bb.getDouble();
1559
				}
1560
				if((opts & 0x2) > 0){
1561
					endWidth41 = bb.getDouble();
1562
				}
1563
				if((opts & 0x4) > 0){
1564
					tangentDir50 = bb.getDouble();
1565
				}
1566
				if((opts & 0x8) > 0){
1567
					vertexFlag70 = bb.get();
1568
				}
1569
				int p1 = bb.getShort();
1570
				int p2 = bb.getShort();
1571
				int p3 = bb.getShort();
1572
				int p4 = bb.getShort();
1573
				
1574
				pfacefaceIndex = new int[]{p1,p2,p3,p4};
1518 1575
			}
1519
			if((opts & 0x2) > 0){
1520
				endWidth41 = bb.getDouble();
1521
			}
1522
			if((opts & 0x4) > 0){
1523
				tangentDir50 = bb.getDouble();
1524
			}
1525
			if((opts & 0x8) > 0){
1526
				vertexFlag70 = bb.get();
1527
			}
1576
			
1577
			
1578
			
1528 1579
		}
1529 1580

  
1530 1581
		DwgObject getDwgObject(int index) {
......
1547 1598
					 	The vertex indexes that define the mesh are given by 71, 
1548 1599
					 	72, 73, and 74 groups, the values of which are integers 
1549 1600
					 	specifying one of the previously defined vertices by 
1550
					 	index. If the index is negative, the edge that begins with 
1551
					 	that vertex is invisible. The first zero vertex marks the 
1552
					 	end of the vertices of the face. Since the 71 through 74 
1601
					 	index. 
1602
					 	If the index is negative, the edge that begins with 
1603
					 	that vertex is invisible. 
1604
					 	
1605
					 	The first zero vertex marks the 
1606
					 	end of the vertices of the face. 
1607
					 	
1608
					 	Since the 71 through 74 
1553 1609
					 	groups are optional fields with default values of zero, 
1554 1610
					 	they are present in DXF only if nonzero."
1611
					 	
1555 1612
					 But DWG 12 spec doesnt say anything about 71,72,73 and
1556 1613
					 74 fields for VERTEX.	
1557 1614
					 * */
1558 1615
					solution = new DwgVertexPFaceFace(index);
1616
					((DwgVertexPFaceFace)solution).setVerticesidx(pfacefaceIndex);
1559 1617
				}
1560 1618
			}else if( (vertexFlag70 & POLYLINE_3D) != 0){
1561 1619
				solution = new DwgVertex3D(index);
......
1566 1624
				((DwgVertex2D)solution).setPoint(pt10);
1567 1625
				((DwgVertex2D)solution).setFlags(vertexFlag70);
1568 1626
			}
1627
			
1628
			reset();
1569 1629
			return solution;
1570 1630
		}
1571 1631
	}
......
1843 1903
				if( (entity instanceof IDwgVertex) && (currentPolyline != null)){
1844 1904
					currentPolyline.addVertex((IDwgVertex) entity);
1845 1905
					
1846
				}else if( (entity instanceof IDwgBlockMember) && (currentBlock != null)){
1906
				}else if( (entity instanceof IDwgBlockMember) && 
1907
						!(entity instanceof IDwgVertex) &&
1908
						(currentBlock != null)){
1909
					//In DWG 12 vertex is not part of Block.
1910
					//its part of a polyline (which is part of a block)
1847 1911
					currentBlock.addObject(entity);
1848 1912
				} else{
1849 1913
//					if(! paperSpace)//TODO solo a?adimos las entidades en espacio modelo????
......
2048 2112
		short w1 = bb.getShort();
2049 2113
		double[] inBase = getPoint(true);
2050 2114
		double[] extMin = getPoint(true);
2115
		dwgFile.setHeader("MSPACE_EXTMIN", extMin);
2051 2116
		double[] extMax = getPoint(true);
2117
		dwgFile.setHeader("MSPACE_EXTMAX", extMax);
2052 2118
		double[] limMin = getPoint(false);
2053 2119
		double[] limMax = getPoint(false);
2054 2120
		
......
2102 2168
		bb.position(0x3ef);
2103 2169
	}
2104 2170
	
2105
	
2106
	
2107
	
2108
	
2109 2171
	class Dwg12Table{
2110 2172
		short s1;
2111 2173
		int i1;

Also available in: Unified diff