org.jgrasstools.gears.io.dxfdwg.libs.dwg.objects.DwgAttrib 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 DwgAttrib class represents a DWG Attrib
*
* @author jmorell
*/
public class DwgAttrib extends DwgObject {
private int dataFlag;
private double elevation;
private Point2D insertionPoint;
private Point2D alignmentPoint;
private double[] extrusion;
private double thickness;
private double obliqueAngle;
private double rotationAngle;
private double height;
private double widthFactor;
private String text;
private int generation;
private int halign;
private int valign;
private String tag;
private int fieldLength;
private int flags;
private String prompt;
private int styleHandle;
/**
* Read an Attrib 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 readDwgAttribV15(int[] data, int offset) throws Exception {
//System.out.println("readDwgAttdef() executed ...");
int bitPos = offset;
bitPos = readObjectHeaderV15(data, bitPos);
Vector v = DwgUtil.getRawChar(data, bitPos);
bitPos = ((Integer)v.get(0)).intValue();
int dflag = ((Integer)v.get(1)).intValue();
dataFlag = dflag;
if ((dflag & 0x1)==0) {
v = DwgUtil.getRawDouble(data, bitPos);
bitPos = ((Integer)v.get(0)).intValue();
double elev = ((Double)v.get(1)).doubleValue();
elevation = elev;
}
v = DwgUtil.getRawDouble(data, bitPos);
bitPos = ((Integer)v.get(0)).intValue();
double x1 = ((Double)v.get(1)).doubleValue();
v = DwgUtil.getRawDouble(data, bitPos);
bitPos = ((Integer)v.get(0)).intValue();
double y1 = ((Double)v.get(1)).doubleValue();
insertionPoint = new Point2D.Double(x1, y1);
double x=0, y=0, z=0;
if ((dflag & 0x2)==0) {
v = DwgUtil.getDefaultDouble(data, bitPos, x1);
bitPos = ((Integer)v.get(0)).intValue();
x = ((Double)v.get(1)).doubleValue();
v = DwgUtil.getDefaultDouble(data, bitPos, y1);
bitPos = ((Integer)v.get(0)).intValue();
y = ((Double)v.get(1)).doubleValue();
}
alignmentPoint = new Point2D.Double(x, y);
v = DwgUtil.testBit(data, bitPos);
bitPos = ((Integer)v.get(0)).intValue();
boolean flag = ((Boolean)v.get(1)).booleanValue();
if (flag) {
y = 0.0;
x = y;
z = 1.0;
} else {
v = DwgUtil.getBitDouble(data, bitPos);
bitPos = ((Integer)v.get(0)).intValue();
x = ((Double)v.get(1)).doubleValue();
v = DwgUtil.getBitDouble(data, bitPos);
bitPos = ((Integer)v.get(0)).intValue();
y = ((Double)v.get(1)).doubleValue();
v = DwgUtil.getBitDouble(data, bitPos);
bitPos = ((Integer)v.get(0)).intValue();
z = ((Double)v.get(1)).doubleValue();
}
extrusion = new double[]{x, y, z};
v = DwgUtil.testBit(data, bitPos);
bitPos = ((Integer)v.get(0)).intValue();
flag = ((Boolean)v.get(1)).booleanValue();
double th;
if (flag) {
th=0.0;
} else {
v = DwgUtil.getBitDouble(data, bitPos);
bitPos = ((Integer)v.get(0)).intValue();
th = ((Double)v.get(1)).doubleValue();
}
thickness = th;
if ((dflag & 0x4)==0) {
v = DwgUtil.getRawDouble(data, bitPos);
bitPos = ((Integer)v.get(0)).intValue();
double oblique = ((Double)v.get(1)).doubleValue();
obliqueAngle = oblique;
}
if ((dflag & 0x8)==0) {
v = DwgUtil.getRawDouble(data, bitPos);
bitPos = ((Integer)v.get(0)).intValue();
double rot = ((Double)v.get(1)).doubleValue();
rotationAngle = rot;
}
v = DwgUtil.getRawDouble(data, bitPos);
bitPos = ((Integer)v.get(0)).intValue();
double height = ((Double)v.get(1)).doubleValue();
this.height = height;
if ((dflag & 0x10)==0) {
v = DwgUtil.getRawDouble(data, bitPos);
bitPos = ((Integer)v.get(0)).intValue();
double width = ((Double)v.get(1)).doubleValue();
widthFactor = width;
}
v = DwgUtil.getTextString(data, bitPos);
bitPos = ((Integer)v.get(0)).intValue();
String text = (String)v.get(1);
this.text = text;
if ((dflag & 0x20)==0) {
v = DwgUtil.getBitShort(data, bitPos);
bitPos = ((Integer)v.get(0)).intValue();
int gen = ((Integer)v.get(1)).intValue();
generation = gen;
}
if ((dflag & 0x40)==0) {
v = DwgUtil.getBitShort(data, bitPos);
bitPos = ((Integer)v.get(0)).intValue();
int halign = ((Integer)v.get(1)).intValue();
this.halign = halign;
}
if ((dflag & 0x80)==0) {
v = DwgUtil.getBitShort(data, bitPos);
bitPos = ((Integer)v.get(0)).intValue();
int valign = ((Integer)v.get(1)).intValue();
this.valign = valign;
}
v = DwgUtil.getTextString(data, bitPos);
bitPos = ((Integer)v.get(0)).intValue();
String tag = (String)v.get(1);
this.tag = tag;
v = DwgUtil.getBitShort(data, bitPos);
bitPos = ((Integer)v.get(0)).intValue();
int fl = ((Integer)v.get(1)).intValue();
fieldLength = fl;
v = DwgUtil.getRawChar(data, bitPos);
bitPos = ((Integer)v.get(0)).intValue();
int flags = ((Integer)v.get(1)).intValue();
this.flags = flags;
bitPos = readObjectTailV15(data, bitPos);
v = DwgUtil.getHandle(data, bitPos);
bitPos = ((Integer)v.get(0)).intValue();
int[] handle = new int[v.size()-1];
for (int j=1;j