All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jgrasstools.gears.io.dxfdwg.libs.dwg.DwgFileV15Reader Maven / Gradle / Ivy

The newest version!
/*
 * JGrass - Free Open Source Java GIS http://www.jgrass.org 
 * (C) HydroloGIS - www.hydrologis.com 
 * 
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Library General Public License as published by the Free
 * Software Foundation; either version 2 of the License, or (at your option) any
 * later version.
 * 
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU Library General Public License
 * along with this library; if not, write to the Free Foundation, Inc., 59
 * Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */
package org.jgrasstools.gears.io.dxfdwg.libs.dwg;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.channels.FileChannel;
import java.util.Vector;

import org.jgrasstools.gears.io.dxfdwg.libs.dwg.objects.DwgArc;
import org.jgrasstools.gears.io.dxfdwg.libs.dwg.objects.DwgAttdef;
import org.jgrasstools.gears.io.dxfdwg.libs.dwg.objects.DwgAttrib;
import org.jgrasstools.gears.io.dxfdwg.libs.dwg.objects.DwgBlock;
import org.jgrasstools.gears.io.dxfdwg.libs.dwg.objects.DwgBlockControl;
import org.jgrasstools.gears.io.dxfdwg.libs.dwg.objects.DwgBlockHeader;
import org.jgrasstools.gears.io.dxfdwg.libs.dwg.objects.DwgCircle;
import org.jgrasstools.gears.io.dxfdwg.libs.dwg.objects.DwgEllipse;
import org.jgrasstools.gears.io.dxfdwg.libs.dwg.objects.DwgEndblk;
import org.jgrasstools.gears.io.dxfdwg.libs.dwg.objects.DwgInsert;
import org.jgrasstools.gears.io.dxfdwg.libs.dwg.objects.DwgLayer;
import org.jgrasstools.gears.io.dxfdwg.libs.dwg.objects.DwgLayerControl;
import org.jgrasstools.gears.io.dxfdwg.libs.dwg.objects.DwgLine;
import org.jgrasstools.gears.io.dxfdwg.libs.dwg.objects.DwgLinearDimension;
import org.jgrasstools.gears.io.dxfdwg.libs.dwg.objects.DwgLwPolyline;
import org.jgrasstools.gears.io.dxfdwg.libs.dwg.objects.DwgMText;
import org.jgrasstools.gears.io.dxfdwg.libs.dwg.objects.DwgPoint;
import org.jgrasstools.gears.io.dxfdwg.libs.dwg.objects.DwgPolyline2D;
import org.jgrasstools.gears.io.dxfdwg.libs.dwg.objects.DwgPolyline3D;
import org.jgrasstools.gears.io.dxfdwg.libs.dwg.objects.DwgSeqend;
import org.jgrasstools.gears.io.dxfdwg.libs.dwg.objects.DwgSolid;
import org.jgrasstools.gears.io.dxfdwg.libs.dwg.objects.DwgSpline;
import org.jgrasstools.gears.io.dxfdwg.libs.dwg.objects.DwgText;
import org.jgrasstools.gears.io.dxfdwg.libs.dwg.objects.DwgVertex2D;
import org.jgrasstools.gears.io.dxfdwg.libs.dwg.objects.DwgVertex3D;
import org.jgrasstools.gears.io.dxfdwg.libs.dwg.utils.ByteUtils;
import org.jgrasstools.gears.io.dxfdwg.libs.dwg.utils.HexUtil;


/**
 * The DwgFileV15Reader reads the DWG version 15 format
 * 
 * @author jmorell
 */
public class DwgFileV15Reader extends DwgFileReader {
	private DwgFile dwgFile;
	
	/**
	 * Reads the DWG version 15 format
	 * 
	 * @param dwgFile Represents the DWG file that we want to read
     * @throws IOException When DWG file path is wrong
	 */
	public void read(DwgFile dwgFile) throws IOException {
		System.out.println("DwgFileV15Reader.read() executed ...");
		this.dwgFile = dwgFile;
		File f = new File(dwgFile.getFileName());
		FileInputStream fis = new FileInputStream(f);
		FileChannel fc = fis.getChannel();
		long s = fc.size();
		ByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, s);
		readDwgSectionOffsets(bb);
		try {
			readDwgObjectOffsets(bb);
			//readDwgClasses(bb);
		} catch (Exception e) {
		    System.out.println("Error leyendo offsets y classes. Posible corrupci�n en" +
		    		"el DWG file ...");
		}
		long t1 = System.currentTimeMillis();
		readDwgObjects(bb);
		long t2 = System.currentTimeMillis();
		System.out.println("Tiempo empleado por readDwgObjects() = " + (t2-t1));
	}
	
	private void readDwgSectionOffsets(ByteBuffer bb) {
		bb.position(19);
		bb.order(ByteOrder.LITTLE_ENDIAN);
		short codePage = bb.getShort();
		int count = bb.getInt();
		for (int i=0; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy