From 2595f91f4aae3020cee3e0b4022aca6d9bc15fe6 Mon Sep 17 00:00:00 2001 From: ?? ? <ulysseskao@ximple.com.tw> Date: Tue, 13 May 2008 18:07:49 +0800 Subject: [PATCH] update for EOFM-83 --- xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/ArcElement.java | 136 ++++++++++++++++++++++++++++----------------- 1 files changed, 84 insertions(+), 52 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 0e0a507..70bd380 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 @@ -20,6 +20,40 @@ super(raw); } + public double getStartAngle() + { + int angle = (raw[18] << 16 & 0xffff0000); + + angle += raw[19] & 0x0000ffff; + + return Utility.ConverIntToRotation(angle); + } + + public void setStartAngle(double value) + { + int angle = Utility.ConverRotatioToInt(value); + + raw[18] = (short) (angle >>> 16 & 0x0000ffff); + raw[19] = (short) (angle & 0x0000ffff); + } + + public double getSweepAngle() + { + int angle = (raw[20] << 16 & 0xffff0000); + + angle += raw[21] & 0x0000ffff; + + return Utility.ConverIntToRotation(angle); + } + + public void setSweepAngle(double value) + { + int angle = Utility.ConverRotatioToInt(value); + + raw[20] = (short) (angle >> 16 & 0x0000ffff); + raw[21] = (short) (angle & 0x0000ffff); + } + public double getPrimary() { short[] primary = new short[4]; @@ -54,6 +88,23 @@ System.arraycopy(secondary, 0, raw, 26, 4); } + public double getRotationAngle() + { + int rotation = (raw[30] << 16 & 0xffff0000); + + rotation += raw[31] & 0x0000ffff; + + return Utility.ConverIntToRotation(rotation); + } + + public void setRotationAngle(double value) + { + int angle = Utility.ConverRotatioToInt(value); + + raw[30] = (short) (angle >> 16 & 0x0000ffff); + raw[31] = (short) (angle & 0x0000ffff); + } + public Coordinate getOrigin() { short[] x = new short[4]; @@ -83,60 +134,41 @@ System.arraycopy(y, 0, raw, 36, 4); } - public double getStartAngle() - { - int angle = (int) (raw[18] << 16 & 0xffff0000); - - angle += raw[19] & 0x0000ffff; - - return Utility.ConverIntToRotation(angle); - } - - public void setStartAngle(double value) - { - int angle = Utility.ConverRotatioToInt(value); - - raw[18] = (short) (angle >>> 16 & 0x0000ffff); - raw[19] = (short) (angle & 0x0000ffff); - } - - public double getSweepAngle() - { - int angle = (int) (raw[20] << 16 & 0xffff0000); - - angle += raw[21] & 0x0000ffff; - - return Utility.ConverIntToRotation(angle); - } - - public void setSweepAngle(double value) - { - int angle = Utility.ConverRotatioToInt(value); - - raw[20] = (short) (angle >> 16 & 0x0000ffff); - raw[21] = (short) (angle & 0x0000ffff); - } - - public double getRotationAngle() - { - int rotation = (int) (raw[30] << 16 & 0xffff0000); - - rotation += raw[31] & 0x0000ffff; - - return Utility.ConverIntToRotation(rotation); - } - - public void setRotationAngle(double value) - { - int angle = Utility.ConverRotatioToInt(value); - - raw[30] = (short) (angle >> 16 & 0x0000ffff); - raw[31] = (short) (angle & 0x0000ffff); - } - public Geometry toGeometry(GeometryFactory factory) { - return null; // To change body of implemented methods use File | Settings | File Templates. + double temp = Math.abs(getStartAngle() - getSweepAngle()); + temp /= 4; + int pts = (temp < 3) ? 3 : (int) temp; + return factory.createLineString(convertToLineString(pts)); + } + + private Coordinate[] convertToLineString(int pts) + { + Coordinate[] result = new Coordinate[pts]; + double beta = -getRotationAngle() / 180 * Math.PI; + double sinbeta = Math.sin(beta); + double cosbeta = Math.cos(beta); + double startAngle = getStartAngle(); + double endAngle = getSweepAngle(); + double steps = Math.abs(startAngle - endAngle) / pts; + int i = 0; + for (double current = startAngle; current < endAngle; current += steps) + { + if (i < pts) + { + Coordinate pt = new Coordinate(); + double alpha = current / 180 * Math.PI; + double sinalpha = Math.sin(alpha); + double cosalpha = Math.cos(alpha); + pt.x = getOrigin().x + (getPrimary() * cosalpha * cosbeta - + getSecondary() * sinalpha * sinbeta); + pt.y = getOrigin().y + (getPrimary() * cosalpha * sinbeta + + getSecondary() * sinalpha * cosbeta); + result[i] = pt; + i++; + } + } + return result; } public static class ElementHandler extends Element.ElementHandler -- Gitblit v0.0.0-SNAPSHOT