From fe4bda7d456c106e1061afaa29d452e5553e9d96 Mon Sep 17 00:00:00 2001 From: ?? ? <ulysseskao@ximple.com.tw> Date: Wed, 14 May 2008 19:40:53 +0800 Subject: [PATCH] update for EOFM-83 --- xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/ArcElement.java | 75 ++++++++++++++++++++++--------------- 1 files changed, 44 insertions(+), 31 deletions(-) diff --git a/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/ArcElement.java b/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/ArcElement.java index 654688b..e54f755 100644 --- a/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/ArcElement.java +++ b/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/ArcElement.java @@ -1,6 +1,8 @@ package com.ximple.io.dgn7; -//~--- non-JDK imports -------------------------------------------------------- +import java.nio.ByteOrder; + +import org.apache.log4j.Logger; import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.Geometry; @@ -15,17 +17,16 @@ */ public class ArcElement extends Element implements GeometryConverter { - public ArcElement(short[] raw) + private static final Logger logger = Logger.getLogger(ArcElement.class); + + public ArcElement(byte[] raw) { super(raw); } public double getStartAngle() { - int angle = (raw[18] << 16 & 0xffff0000); - - angle |= raw[19] & 0x0000ffff; - + int angle = (raw[18] & 0x0000ffff) << 16 | (raw[19] & 0x0000ffff); return Utility.converIntToRotation(angle); } @@ -39,9 +40,9 @@ public double getSweepAngle() { - int angle = (raw[20] << 16 & 0xffff0000); - - angle |= raw[21] & 0x0000ffff; + int angle = (raw[20] & 0x0000ffff) << 16 | (raw[21] & 0x0000ffff); + if (angle < 0) + angle = -1 * (angle & 0x7fffffff); return Utility.converIntToRotation(angle); } @@ -49,6 +50,11 @@ public void setSweepAngle(double value) { int angle = Utility.converRotatioToInt(value); + if (angle < 0) + { + angle &= 0x7fffffff; + angle |= 0x80000000; + } raw[20] = (short) (angle >> 16 & 0x0000ffff); raw[21] = (short) (angle & 0x0000ffff); @@ -56,16 +62,18 @@ public double getPrimary() { - short[] primary = new short[4]; - - System.arraycopy(raw, 22, primary, 0, 4); - + rawBuffer.position(22 * 2); + ByteOrder bo = rawBuffer.order(); + rawBuffer.order(ByteOrder.BIG_ENDIAN); + byte[] primary = new byte[8]; + rawBuffer.get(primary); + rawBuffer.order(bo); return Utility.convertDGNToIEEEDouble(primary) / 1000.0; } public void setPrimary(double value) { - double temp = value * 1000.0; + double temp = value * 1000.0; short[] primary = Utility.convertIEEEDoubleToDGN(temp); System.arraycopy(primary, 0, raw, 22, 4); @@ -73,16 +81,18 @@ public double getSecondary() { - short[] secondary = new short[4]; - - System.arraycopy(raw, 26, secondary, 0, 4); - + rawBuffer.position(26 * 2); + ByteOrder bo = rawBuffer.order(); + rawBuffer.order(ByteOrder.BIG_ENDIAN); + byte[] secondary = new byte[8]; + rawBuffer.get(secondary); + rawBuffer.order(bo); return Utility.convertDGNToIEEEDouble(secondary) / 1000.0; } public void setSecondary(double value) { - double temp = value * 1000.0; + double temp = value * 1000.0; short[] secondary = Utility.convertIEEEDoubleToDGN(temp); System.arraycopy(secondary, 0, raw, 26, 4); @@ -91,7 +101,6 @@ public double getRotationAngle() { int rotation = (raw[30] << 16 & 0xffff0000); - rotation |= raw[31] & 0x0000ffff; return Utility.converIntToRotation(rotation); @@ -107,24 +116,26 @@ public Coordinate getOrigin() { - short[] x = new short[4]; + rawBuffer.position(32 * 2); + ByteOrder bo = rawBuffer.order(); + rawBuffer.order(ByteOrder.BIG_ENDIAN); + byte[] rawValue = new byte[8]; - System.arraycopy(raw, 32, x, 0, 4); + rawBuffer.get(rawValue); // x + double dx = Utility.converUnitToCoord(Utility.convertDGNToIEEEDouble(rawValue)); - double dx = Utility.converUnitToCoord((int) Utility.convertDGNToIEEEDouble(x)); - short[] y = new short[4]; + rawBuffer.get(rawValue); // y + double dy = Utility.converUnitToCoord(Utility.convertDGNToIEEEDouble(rawValue)); - System.arraycopy(raw, 36, y, 0, 4); - - double dy = Utility.converUnitToCoord((int) Utility.convertDGNToIEEEDouble(y)); + rawBuffer.order(bo); return new Coordinate(dx, dy); } public void setOrigin(Coordinate value) { - double temp = Utility.converCoordToUnit(value.x); - short[] x = Utility.convertIEEEDoubleToDGN(temp); + double temp = Utility.converCoordToUnit(value.x); + short[] x = Utility.convertIEEEDoubleToDGN(temp); System.arraycopy(x, 0, raw, 32, 4); temp = Utility.converCoordToUnit(value.y); @@ -136,7 +147,9 @@ public Geometry toGeometry(GeometryFactory factory) { - double temp = Math.abs(getStartAngle() - getSweepAngle()); + double start = getStartAngle(); + double end = getSweepAngle(); + double temp = Math.abs(start - end); temp /= 4; int pts = (temp < 3) ? 3 : (int) temp; return factory.createLineString(convertToLineString(pts)); @@ -190,7 +203,7 @@ return instance; } - protected Element createElement(short[] raw) + protected Element createElement(byte[] raw) { return new ArcElement(raw); } -- Gitblit v0.0.0-SNAPSHOT