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

org.jgrasstools.gears.io.dxfdwg.libs.dwg.objects.DwgLwPolyline 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.objects;

import java.awt.geom.Point2D;
import java.util.Vector;

import org.jgrasstools.gears.io.dxfdwg.libs.dwg.DwgObject;
import org.jgrasstools.gears.io.dxfdwg.libs.dwg.DwgUtil;

/**
 * The DwgLwPolyline class represents a DWG LwPolyline
 * 
 * @author jmorell
 */
public class DwgLwPolyline extends DwgObject {
	private int flag;
	private double constWidth;
	private double elevation;
	private double thickness;
	private double[] normal;
	private Point2D[] vertices;
	private double[] bulges;
	private double[][] widths;
	
	/**
	 * Read a LwPolyline in the DWG format Version 15
	 * 
	 * @param data Array of unsigned bytes obtained from the DWG binary file
	 * @param offset The current bit offset where the value begins
	 * @throws Exception If an unexpected bit value is found in the DWG file. Occurs
	 * 		   when we are looking for LwPolylines.
	 */
	public void readDwgLwPolylineV15(int[] data, int offset) throws Exception {
		//System.out.println("DwgLwPolyline.readDwgLwPolyline() executed ...");
		int bitPos = offset;
		bitPos = readObjectHeaderV15(data, bitPos);
		Vector v = DwgUtil.getBitShort(data, bitPos);
		bitPos = ((Integer)v.get(0)).intValue();
		int flag = ((Integer)v.get(1)).intValue();
		this.flag = flag;
		// Condici�n emp�rica. Si flag es menor que cero no se trata de LwPolylines ...
		if (flag>=0) {
			double constWidth = 0.0;
			if ((flag & 0x4)>0) {
				v = DwgUtil.getBitDouble(data, bitPos);
				bitPos = ((Integer)v.get(0)).intValue();
				constWidth = ((Double)v.get(1)).doubleValue();
			}
			this.constWidth = constWidth;
			double elev = 0.0;
			if ((flag & 0x8)>0) {
				v = DwgUtil.getBitDouble(data, bitPos);
				bitPos = ((Integer)v.get(0)).intValue();
				elev = ((Double)v.get(1)).doubleValue();
			}
			elevation = elev;
			double thickness = 0.0;
			if ((flag & 0x2)>0) {
				v = DwgUtil.getBitDouble(data, bitPos);
				bitPos = ((Integer)v.get(0)).intValue();
				thickness = ((Double)v.get(1)).doubleValue();
			}
			this.thickness = thickness;
			double nx = 0.0, ny = 0.0, nz = 0.0;
			if ((flag & 0x1)>0) {
				v = DwgUtil.getBitDouble(data, bitPos);
				bitPos = ((Integer)v.get(0)).intValue();
				nx = ((Double)v.get(1)).doubleValue();
				v = DwgUtil.getBitDouble(data, bitPos);
				bitPos = ((Integer)v.get(0)).intValue();
				ny = ((Double)v.get(1)).doubleValue();
				v = DwgUtil.getBitDouble(data, bitPos);
				bitPos = ((Integer)v.get(0)).intValue();
				nz = ((Double)v.get(1)).doubleValue();
			}
			normal = new double[]{nx, ny, nz};
			v = DwgUtil.getBitLong(data, bitPos);
			bitPos = ((Integer)v.get(0)).intValue();
			int np = ((Integer)v.get(1)).intValue();
			// TODO: Condici�n emp�rica. Si hay m�s de 10000 puntos no se trata de LwPolylines.
		    // Este tema hay que revisarlo porque si pueden existir LwPolylines con m�s de
		    // 10000 v�rtices ...
            // Se han encontrado lwplines con np = 0. Estas lwplines tambin ser ignoradas.
			if (np>0 && np<10000) {
				long nb = 0;
				if ((flag & 0x10)>0) {
					v = DwgUtil.getBitLong(data, bitPos);
					bitPos = ((Integer)v.get(0)).intValue();
					nb = ((Integer)v.get(1)).intValue();
				}
				long nw = 0;
				if ((flag & 0x20)>0) {
					v = DwgUtil.getBitLong(data, bitPos);
					bitPos = ((Integer)v.get(0)).intValue();
					nw = ((Integer)v.get(1)).intValue();
				}
                //System.out.println("np = " + np);
				Point2D[] vertices = new Point2D[np];
				v = DwgUtil.getRawDouble(data, bitPos);
				bitPos = ((Integer)v.get(0)).intValue();
				double vx = ((Double)v.get(1)).doubleValue();
				v = DwgUtil.getRawDouble(data, bitPos);
				bitPos = ((Integer)v.get(0)).intValue();
				double vy = ((Double)v.get(1)).doubleValue();
				vertices[0] = new Point2D.Double(vx, vy);
				for (int i=1; i<(np); i++) {
					v = DwgUtil.getDefaultDouble(data, bitPos, vx);
					bitPos = ((Integer)v.get(0)).intValue();
					double x = ((Double)v.get(1)).doubleValue();
					v = DwgUtil.getDefaultDouble(data, bitPos, vy);
					bitPos = ((Integer)v.get(0)).intValue();
					double y = ((Double)v.get(1)).doubleValue();
					vertices[i] = new Point2D.Double(x, y);
					vx = x;
					vy = y;
				}
				this.vertices = vertices;
				double[] bulges = new double[0];
				if (nb>0) {
					bulges = new double[(int)nb];
					for (int i=0; i0) {
					double[][] widths = new double[(int)nw][2];
					for (int i=0; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy