From 0acf7a49b2da4dd1873d64012ba360eaf51754f4 Mon Sep 17 00:00:00 2001
From: ?? ? <ulysseskao@ximple.com.tw>
Date: Thu, 15 May 2008 10:42:55 +0800
Subject: [PATCH] update for EOFM-83

---
 xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/EllipseElement.java      |   95 ++++++++++-----
 xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/TextNodeElement.java     |   20 ++-
 .gitattributes                                                                  |    2 
 xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/TcbElement.java          |    4 
 xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/ComplexChainElement.java |    4 
 xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/TextElement.java         |   18 ++-
 xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Element.java             |   15 +-
 xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/ShapeElement.java        |    2 
 xdgnjobs/ximple-dgnio/src/main/java/com/ximple/util/DgnUtility.java             |    6 
 xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/LineStringElement.java   |   16 +
 xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Dgn7fileReader.java      |   32 +++--
 xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/ArcElement.java          |   98 +++++++++------
 xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/ComplexShapeElement.java |    4 
 xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/LineElement.java         |   16 +
 14 files changed, 212 insertions(+), 120 deletions(-)

diff --git a/.gitattributes b/.gitattributes
index bffef52..369280b 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -26,7 +26,7 @@
 xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/TextElement.java svneol=native#text/plain
 xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/TextNodeElement.java svneol=native#text/plain
 xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/UserAttributeData.java svneol=native#text/plain
-xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Utility.java svneol=native#text/plain
+xdgnjobs/ximple-dgnio/src/main/java/com/ximple/util/DgnUtility.java svneol=native#text/plain
 xdgnjobs/ximple-dgnio/src/main/java/com/ximple/util/PrintfFormat.java svneol=native#text/plain
 xdgnjobs/ximple-dgnio/src/test/java/com/ximple/io/dgn7/Dgn7OracleReaderTest.java svneol=native#text/plain
 xdgnjobs/ximple-dgnio/src/test/java/com/ximple/io/dgn7/Dgn7TextElementReaderTest.java svneol=native#text/plain
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 e54f755..bd452df 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,12 +1,15 @@
 package com.ximple.io.dgn7;
 
 import java.nio.ByteOrder;
+import java.util.ArrayList;
 
 import org.apache.log4j.Logger;
 
 import com.vividsolutions.jts.geom.Coordinate;
 import com.vividsolutions.jts.geom.Geometry;
 import com.vividsolutions.jts.geom.GeometryFactory;
+
+import com.ximple.util.DgnUtility;
 
 /**
  * ArcElement
@@ -27,12 +30,12 @@
     public double getStartAngle()
     {
         int angle = (raw[18] & 0x0000ffff) << 16 | (raw[19] & 0x0000ffff);
-        return Utility.converIntToRotation(angle);
+        return DgnUtility.converIntToRotation(angle);
     }
 
     public void setStartAngle(double value)
     {
-        int angle = Utility.converRotatioToInt(value);
+        int angle = DgnUtility.converRotatioToInt(value);
 
         raw[18] = (short) (angle >>> 16 & 0x0000ffff);
         raw[19] = (short) (angle & 0x0000ffff);
@@ -44,12 +47,12 @@
         if (angle < 0)
             angle = -1 * (angle & 0x7fffffff);
 
-        return Utility.converIntToRotation(angle);
+        return DgnUtility.converIntToRotation(angle);
     }
 
     public void setSweepAngle(double value)
     {
-        int angle = Utility.converRotatioToInt(value);
+        int angle = DgnUtility.converRotatioToInt(value);
         if (angle < 0)
         {
             angle &= 0x7fffffff;
@@ -68,13 +71,13 @@
         byte[] primary = new byte[8];
         rawBuffer.get(primary);
         rawBuffer.order(bo);
-        return Utility.convertDGNToIEEEDouble(primary) / 1000.0;
+        return DgnUtility.convertDGNToIEEEDouble(primary) / 1000.0;
     }
 
     public void setPrimary(double value)
     {
         double temp = value * 1000.0;
-        short[] primary = Utility.convertIEEEDoubleToDGN(temp);
+        short[] primary = DgnUtility.convertIEEEDoubleToDGN(temp);
 
         System.arraycopy(primary, 0, raw, 22, 4);
     }
@@ -87,13 +90,13 @@
         byte[] secondary = new byte[8];
         rawBuffer.get(secondary);
         rawBuffer.order(bo);
-        return Utility.convertDGNToIEEEDouble(secondary) / 1000.0;
+        return DgnUtility.convertDGNToIEEEDouble(secondary) / 1000.0;
     }
 
     public void setSecondary(double value)
     {
         double temp = value * 1000.0;
-        short[] secondary = Utility.convertIEEEDoubleToDGN(temp);
+        short[] secondary = DgnUtility.convertIEEEDoubleToDGN(temp);
 
         System.arraycopy(secondary, 0, raw, 26, 4);
     }
@@ -103,12 +106,12 @@
         int rotation = (raw[30] << 16 & 0xffff0000);
         rotation |= raw[31] & 0x0000ffff;
 
-        return Utility.converIntToRotation(rotation);
+        return DgnUtility.converIntToRotation(rotation);
     }
 
     public void setRotationAngle(double value)
     {
-        int angle = Utility.converRotatioToInt(value);
+        int angle = DgnUtility.converRotatioToInt(value);
 
         raw[30] = (short) (angle >> 16 & 0x0000ffff);
         raw[31] = (short) (angle & 0x0000ffff);
@@ -122,10 +125,10 @@
         byte[] rawValue = new byte[8];
 
         rawBuffer.get(rawValue); // x
-        double dx = Utility.converUnitToCoord(Utility.convertDGNToIEEEDouble(rawValue));
+        double dx = DgnUtility.converUnitToCoord(DgnUtility.convertDGNToIEEEDouble(rawValue));
 
         rawBuffer.get(rawValue); // y
-        double dy = Utility.converUnitToCoord(Utility.convertDGNToIEEEDouble(rawValue));
+        double dy = DgnUtility.converUnitToCoord(DgnUtility.convertDGNToIEEEDouble(rawValue));
 
         rawBuffer.order(bo);
 
@@ -134,22 +137,21 @@
 
     public void setOrigin(Coordinate value)
     {
-        double temp = Utility.converCoordToUnit(value.x);
-        short[] x = Utility.convertIEEEDoubleToDGN(temp);
+        double temp = DgnUtility.converCoordToUnit(value.x);
+        short[] x = DgnUtility.convertIEEEDoubleToDGN(temp);
 
         System.arraycopy(x, 0, raw, 32, 4);
-        temp = Utility.converCoordToUnit(value.y);
+        temp = DgnUtility.converCoordToUnit(value.y);
 
-        short[] y = Utility.convertIEEEDoubleToDGN(temp);
+        short[] y = DgnUtility.convertIEEEDoubleToDGN(temp);
 
         System.arraycopy(y, 0, raw, 36, 4);
     }
 
     public Geometry toGeometry(GeometryFactory factory)
     {
-        double start = getStartAngle();
-        double end = getSweepAngle();
-        double temp = Math.abs(start - end);
+        double sweep = getSweepAngle();
+        double temp = Math.abs(sweep);
         temp /= 4;
         int pts = (temp < 3) ? 3 : (int) temp;
         return factory.createLineString(convertToLineString(pts));
@@ -157,31 +159,49 @@
 
     private Coordinate[] convertToLineString(int pts)
     {
-        Coordinate[] result = new Coordinate[pts];
-        double beta = Utility.converRotationToRadian(-getRotationAngle());
-        double sinbeta = Math.sin(beta);
-        double cosbeta = Math.cos(beta);
+        ArrayList<Coordinate> result = new ArrayList<Coordinate>();
+        double beta = DgnUtility.converRotationToRadian(-getRotationAngle());
         double startAngle = getStartAngle();
-        double endAngle = getSweepAngle();
-        double steps = Math.abs(startAngle - endAngle) / pts;
-        int i = 0;
-        for (double current = startAngle; current < endAngle; current += steps)
+        double sweepAngle = getSweepAngle();
+        double endAngle = startAngle + sweepAngle;
+        double steps = sweepAngle / pts;
+        double current;
+        if (sweepAngle < 0)
         {
-            if (i < pts)
+            for (current = startAngle; current > endAngle; current += steps)
             {
-                Coordinate pt = new Coordinate();
-                double alpha = Utility.converRotationToRadian(current);
-                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++;
+                Coordinate pt = computePointOnArcByAngle(beta, current);
+                result.add(pt);
+            }
+
+        } else
+        {
+            for (current = startAngle; current < endAngle; current += steps)
+            {
+                Coordinate pt = computePointOnArcByAngle(beta, current);
+                result.add(pt);
             }
         }
-        return result;
+
+        Coordinate pt = computePointOnArcByAngle(beta, endAngle);
+        result.add(pt);
+
+        return result.toArray(new Coordinate[result.size()]);
+    }
+
+    private Coordinate computePointOnArcByAngle(double beta, double current)
+    {
+        double sinbeta = Math.sin(beta);
+        double cosbeta = Math.cos(beta);
+        Coordinate pt = new Coordinate();
+        double alpha = DgnUtility.converRotationToRadian(current);
+        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);
+        return pt;
     }
 
     public static class ElementHandler extends Element.ElementHandler
diff --git a/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/ComplexChainElement.java b/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/ComplexChainElement.java
index c229b96..f7150d6 100644
--- a/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/ComplexChainElement.java
+++ b/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/ComplexChainElement.java
@@ -8,6 +8,8 @@
 import java.util.List;
 import java.util.ListIterator;
 
+import org.apache.log4j.Logger;
+
 import com.vividsolutions.jts.geom.Geometry;
 import com.vividsolutions.jts.geom.GeometryCollection;
 import com.vividsolutions.jts.geom.GeometryFactory;
@@ -21,6 +23,8 @@
  */
 public class ComplexChainElement extends Element implements ComplexElement, GeometryConverter
 {
+    private static final Logger logger = Logger.getLogger(ComplexChainElement.class);
+
     protected ArrayList list = new ArrayList();
 
     public ComplexChainElement(byte[] raw)
diff --git a/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/ComplexShapeElement.java b/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/ComplexShapeElement.java
index b4b808e..a5491c9 100644
--- a/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/ComplexShapeElement.java
+++ b/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/ComplexShapeElement.java
@@ -8,6 +8,8 @@
 import java.util.List;
 import java.util.ListIterator;
 
+import org.apache.log4j.Logger;
+
 import com.vividsolutions.jts.geom.Geometry;
 import com.vividsolutions.jts.geom.GeometryCollection;
 import com.vividsolutions.jts.geom.GeometryFactory;
@@ -21,6 +23,8 @@
  */
 public class ComplexShapeElement extends Element implements ComplexElement, GeometryConverter
 {
+    private static final Logger logger = Logger.getLogger(ComplexShapeElement.class);
+
     ArrayList list = new ArrayList();
 
     public ComplexShapeElement(byte[] raw)
diff --git a/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Dgn7fileReader.java b/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Dgn7fileReader.java
index 35da5be..668e289 100644
--- a/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Dgn7fileReader.java
+++ b/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Dgn7fileReader.java
@@ -2,7 +2,6 @@
 
 //~--- JDK imports ------------------------------------------------------------
 
-import javax.swing.*;
 import java.io.EOFException;
 import java.io.File;
 import java.io.FileInputStream;
@@ -12,11 +11,15 @@
 import java.nio.MappedByteBuffer;
 import java.nio.channels.FileChannel;
 import java.nio.channels.ReadableByteChannel;
+import javax.swing.JFileChooser;
+import javax.swing.JFrame;
 
 import org.apache.log4j.LogManager;
 import org.apache.log4j.Logger;
 
 import com.vividsolutions.jts.geom.GeometryFactory;
+
+import com.ximple.util.DgnUtility;
 
 
 /**
@@ -28,7 +31,8 @@
  */
 public class Dgn7fileReader
 {
-    private static final Logger logger = LogManager.getLogger("com.isimple.glyphjump.io.dgn7");
+    private static final Logger logger = LogManager.getLogger(Dgn7fileReader.class);
+
     private Dgn7fileHeader      header;
     private ReadableByteChannel channel;
     ByteBuffer                  buffer;
@@ -252,33 +256,33 @@
         {
             int lowCoorX = buffer.getInt();
 
-            lowCoorX    = Utility.convertFromDGN(lowCoorX);
-            record.minX = Utility.converUnitToCoord(lowCoorX);
+            lowCoorX    = DgnUtility.convertFromDGN(lowCoorX);
+            record.minX = DgnUtility.converUnitToCoord(lowCoorX);
 
             int lowCoorY = buffer.getInt();
 
-            lowCoorY    = Utility.convertFromDGN(lowCoorY);
-            record.minY = Utility.converUnitToCoord(lowCoorY);
+            lowCoorY    = DgnUtility.convertFromDGN(lowCoorY);
+            record.minY = DgnUtility.converUnitToCoord(lowCoorY);
 
             int lowCoorZ = buffer.getInt();
 
-            lowCoorZ    = Utility.convertFromDGN(lowCoorZ);
-            record.minZ = Utility.converUnitToCoord(lowCoorZ);
+            lowCoorZ    = DgnUtility.convertFromDGN(lowCoorZ);
+            record.minZ = DgnUtility.converUnitToCoord(lowCoorZ);
 
             int highCoorX = buffer.getInt();
 
-            highCoorX   = Utility.convertFromDGN(highCoorX);
-            record.maxX = Utility.converUnitToCoord(highCoorX);
+            highCoorX   = DgnUtility.convertFromDGN(highCoorX);
+            record.maxX = DgnUtility.converUnitToCoord(highCoorX);
 
             int highCoorY = buffer.getInt();
 
-            highCoorY   = Utility.convertFromDGN(highCoorY);
-            record.maxY = Utility.converUnitToCoord(highCoorY);
+            highCoorY   = DgnUtility.convertFromDGN(highCoorY);
+            record.maxY = DgnUtility.converUnitToCoord(highCoorY);
 
             int highCoorZ = buffer.getInt();
 
-            highCoorZ   = Utility.convertFromDGN(highCoorZ);
-            record.maxZ = Utility.converUnitToCoord(highCoorZ);
+            highCoorZ   = DgnUtility.convertFromDGN(highCoorZ);
+            record.maxZ = DgnUtility.converUnitToCoord(highCoorZ);
         }
 
         buffer.reset();
diff --git a/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Element.java b/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Element.java
index 10e6852..78c9bee 100644
--- a/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Element.java
+++ b/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Element.java
@@ -5,11 +5,12 @@
 import java.nio.BufferUnderflowException;
 import java.nio.ByteBuffer;
 import java.nio.ByteOrder;
-import java.nio.ShortBuffer;
 import java.util.ArrayList;
 import java.util.List;
 
 import com.vividsolutions.jts.geom.Envelope;
+
+import com.ximple.util.DgnUtility;
 
 /**
  * Record
@@ -55,22 +56,22 @@
     {
         int lowCoorX = (int) ((raw[3] << 16) & 0xffff0000) + (raw[2] & 0x0000ffff);
 
-        lowCoorX = Utility.convertFromDGN(lowCoorX);
+        lowCoorX = DgnUtility.convertFromDGN(lowCoorX);
 
         int lowCoorY = (int) ((raw[5] << 16) & 0xffff0000) + (raw[4] & 0x0000ffff);
 
-        lowCoorY = Utility.convertFromDGN(lowCoorY);
+        lowCoorY = DgnUtility.convertFromDGN(lowCoorY);
 
         int highCoorX = (int) ((raw[9] << 16) & 0xffff0000) + (raw[8] & 0x0000ffff);
 
-        highCoorX = Utility.convertFromDGN(highCoorX);
+        highCoorX = DgnUtility.convertFromDGN(highCoorX);
 
         int highCoorY = (int) ((raw[11] << 16) & 0xffff0000) + (raw[10] & 0x0000ffff);
 
-        highCoorY = Utility.convertFromDGN(highCoorY);
+        highCoorY = DgnUtility.convertFromDGN(highCoorY);
 
-        return new Envelope(Utility.converUnitToCoord(lowCoorX), Utility.converUnitToCoord(highCoorX),
-                            Utility.converUnitToCoord(lowCoorY), Utility.converUnitToCoord(highCoorY));
+        return new Envelope(DgnUtility.converUnitToCoord(lowCoorX), DgnUtility.converUnitToCoord(highCoorX),
+                            DgnUtility.converUnitToCoord(lowCoorY), DgnUtility.converUnitToCoord(highCoorY));
     }
 
     public boolean isComponentElement()
diff --git a/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/EllipseElement.java b/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/EllipseElement.java
index 57a4d89..044d57a 100644
--- a/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/EllipseElement.java
+++ b/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/EllipseElement.java
@@ -1,13 +1,20 @@
 package com.ximple.io.dgn7;
 
 import java.nio.ByteOrder;
+import java.util.ArrayList;
+
+import org.apache.log4j.Logger;
 
 import com.vividsolutions.jts.geom.Coordinate;
 import com.vividsolutions.jts.geom.Geometry;
 import com.vividsolutions.jts.geom.GeometryFactory;
 
+import com.ximple.util.DgnUtility;
+
 public class EllipseElement extends Element implements GeometryConverter
 {
+    private static final Logger logger = Logger.getLogger(EllipseElement.class);
+
     public EllipseElement(byte[] raw)
     {
         super(raw);
@@ -39,13 +46,13 @@
         byte[] primary = new byte[8];
         rawBuffer.get(primary);
         rawBuffer.order(bo);
-        return Utility.convertDGNToIEEEDouble(primary) / 1000.0;
+        return DgnUtility.convertDGNToIEEEDouble(primary) / 1000.0;
     }
 
     public void setPrimary(double value)
     {
         double temp = value * 1000.0;
-        short[] primary = Utility.convertIEEEDoubleToDGN(temp);
+        short[] primary = DgnUtility.convertIEEEDoubleToDGN(temp);
 
         System.arraycopy(primary, 0, raw, 18, 4);
     }
@@ -58,13 +65,13 @@
         byte[] secondary = new byte[8];
         rawBuffer.get(secondary);
         rawBuffer.order(bo);
-        return Utility.convertDGNToIEEEDouble(secondary) / 1000.0;
+        return DgnUtility.convertDGNToIEEEDouble(secondary) / 1000.0;
     }
 
     public void setSecondary(double value)
     {
         double temp = value * 1000.0;
-        short[] secondary = Utility.convertIEEEDoubleToDGN(temp);
+        short[] secondary = DgnUtility.convertIEEEDoubleToDGN(temp);
 
         System.arraycopy(secondary, 0, raw, 22, 4);
     }
@@ -74,12 +81,12 @@
         int rotation = (raw[26] << 16 & 0xffff0000);
         rotation |= raw[27] & 0x0000ffff;
 
-        return Utility.converIntToRotation(rotation);
+        return DgnUtility.converIntToRotation(rotation);
     }
 
     public void setRotationAngle(double value)
     {
-        int angle = Utility.converRotatioToInt(value);
+        int angle = DgnUtility.converRotatioToInt(value);
 
         raw[26] = (short) (angle >> 16 & 0x0000ffff);
         raw[27] = (short) (angle & 0x0000ffff);
@@ -93,10 +100,10 @@
         byte[] rawValue = new byte[8];
 
         rawBuffer.get(rawValue); // x
-        double dx = Utility.converUnitToCoord(Utility.convertDGNToIEEEDouble(rawValue));
+        double dx = DgnUtility.converUnitToCoord(DgnUtility.convertDGNToIEEEDouble(rawValue));
 
         rawBuffer.get(rawValue); // y
-        double dy = Utility.converUnitToCoord(Utility.convertDGNToIEEEDouble(rawValue));
+        double dy = DgnUtility.converUnitToCoord(DgnUtility.convertDGNToIEEEDouble(rawValue));
 
         rawBuffer.order(bo);
 
@@ -105,13 +112,13 @@
 
     public void setOrigin(Coordinate value)
     {
-        double temp = Utility.converCoordToUnit(value.x);
-        short[] x = Utility.convertIEEEDoubleToDGN(temp);
+        double temp = DgnUtility.converCoordToUnit(value.x);
+        short[] x = DgnUtility.convertIEEEDoubleToDGN(temp);
 
         System.arraycopy(x, 0, raw, 28, 4);
-        temp = Utility.converCoordToUnit(value.y);
+        temp = DgnUtility.converCoordToUnit(value.y);
 
-        short[] y = Utility.convertIEEEDoubleToDGN(temp);
+        short[] y = DgnUtility.convertIEEEDoubleToDGN(temp);
 
         System.arraycopy(y, 0, raw, 32, 4);
     }
@@ -126,31 +133,55 @@
 
     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);
+        ArrayList<Coordinate> result = new ArrayList<Coordinate>();
+        double beta = DgnUtility.converRotationToRadian(-getRotationAngle());
         double startAngle = getStartAngle();
-        double endAngle = getSweepAngle();
-        double steps = Math.abs(startAngle - endAngle) / pts;
-        int i = 0;
-        for (double current = startAngle; current < endAngle; current += steps)
+        double sweepAngle = getSweepAngle();
+        double endAngle = startAngle + sweepAngle;
+        double steps = sweepAngle / pts;
+        double current;
+        if (sweepAngle < 0)
         {
-            if (i < pts)
+            for (current = startAngle; current > endAngle; current += steps)
             {
-                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++;
+                Coordinate pt = computePointOnArcByAngle(beta, current);
+                result.add(pt);
+            }
+
+        } else
+        {
+            for (current = startAngle; current < endAngle; current += steps)
+            {
+                Coordinate pt = computePointOnArcByAngle(beta, current);
+                result.add(pt);
             }
         }
-        return result;
+
+        Coordinate pt = computePointOnArcByAngle(beta, endAngle);
+        result.add(pt);
+
+        if (!result.get(0).equals(result.get(result.size() - 1)))
+        {
+            result.add(result.get(0));
+        }
+
+        return result.toArray(new Coordinate[result.size()]);
+    }
+
+
+    private Coordinate computePointOnArcByAngle(double beta, double current)
+    {
+        double sinbeta = Math.sin(beta);
+        double cosbeta = Math.cos(beta);
+        Coordinate pt = new Coordinate();
+        double alpha = DgnUtility.converRotationToRadian(current);
+        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);
+        return pt;
     }
 
     public static class ElementHandler extends Element.ElementHandler
diff --git a/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/LineElement.java b/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/LineElement.java
index 9efdcfa..6c2fd0e 100644
--- a/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/LineElement.java
+++ b/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/LineElement.java
@@ -2,9 +2,13 @@
 
 //~--- non-JDK imports --------------------------------------------------------
 
+import org.apache.log4j.Logger;
+
 import com.vividsolutions.jts.geom.Coordinate;
 import com.vividsolutions.jts.geom.Geometry;
 import com.vividsolutions.jts.geom.GeometryFactory;
+
+import com.ximple.util.DgnUtility;
 
 /**
  * LineElement
@@ -15,6 +19,8 @@
  */
 public class LineElement extends Element implements GeometryConverter
 {
+    private static final Logger logger = Logger.getLogger(LineElement.class);
+
     public LineElement(byte[] raw)
     {
         super(raw);
@@ -31,8 +37,8 @@
         int endY = ((raw[24] << 16) & 0xffff0000) | (raw[25] & 0x0000ffff);
 
 
-        double x = Utility.converUnitToCoord(endX);
-        double y = Utility.converUnitToCoord(endY);
+        double x = DgnUtility.converUnitToCoord(endX);
+        double y = DgnUtility.converUnitToCoord(endY);
 
         return new Coordinate(x, y);
     }
@@ -52,12 +58,12 @@
         int startX = ((raw[18] << 16) & 0xffff0000);
         startX = startX + (raw[19] & 0x0000ffff);
 
-        double x      = Utility.converUnitToCoord(startX);
+        double x      = DgnUtility.converUnitToCoord(startX);
         int    startY = ((raw[20] << 16) & 0xffff0000);
 
         startY = startY + (raw[21] & 0x0000ffff);
 
-        double y = Utility.converUnitToCoord(startY);
+        double y = DgnUtility.converUnitToCoord(startY);
 
         return new Coordinate(x, y);
     }
@@ -74,7 +80,7 @@
         Coordinate p1 = getStartPoint();
         Coordinate p2 = getEndPoint();
 
-        return Utility.getLength(p1.x, p1.y, p2.x, p2.y);
+        return DgnUtility.getLength(p1.x, p1.y, p2.x, p2.y);
     }
 
     public Coordinate pointAtDistance(double dDistance, double dTolerance)
diff --git a/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/LineStringElement.java b/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/LineStringElement.java
index 307f8c0..1a40f95 100644
--- a/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/LineStringElement.java
+++ b/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/LineStringElement.java
@@ -2,9 +2,13 @@
 
 //~--- non-JDK imports --------------------------------------------------------
 
+import org.apache.log4j.Logger;
+
 import com.vividsolutions.jts.geom.Coordinate;
 import com.vividsolutions.jts.geom.Geometry;
 import com.vividsolutions.jts.geom.GeometryFactory;
+
+import com.ximple.util.DgnUtility;
 
 /**
  * LineStringElement
@@ -15,6 +19,8 @@
  */
 public class LineStringElement extends Element implements GeometryConverter
 {
+    private static final Logger logger = Logger.getLogger(LineStringElement.class);
+
     public LineStringElement(byte[] raw)
     {
         super(raw);
@@ -67,7 +73,7 @@
             Coordinate p1 = vset[i - 1];
             Coordinate p2 = vset[i];
 
-            result += Utility.getLength(p1.x, p1.y, p2.x, p2.y);
+            result += DgnUtility.getLength(p1.x, p1.y, p2.x, p2.y);
         }
 
         return result;
@@ -106,12 +112,12 @@
 
         x += (int) (raw[20 + (4 * index)] & 0x0000ffff);
 
-        return Utility.converUnitToCoord(x);
+        return DgnUtility.converUnitToCoord(x);
     }
 
     protected void setX(int index, double dx)
     {
-        int newVal = Utility.converCoordToUnit(dx);
+        int newVal = DgnUtility.converCoordToUnit(dx);
 
         raw[19 + (4 * index)] = (short) (newVal >> 16 & 0x0000ffff);
         raw[20 + (4 * index)] = (short) (newVal & 0x0000ffff);
@@ -128,12 +134,12 @@
 
         y = y + (int) (raw[22 + (4 * index)] & 0x0000ffff);
 
-        return Utility.converUnitToCoord(y);
+        return DgnUtility.converUnitToCoord(y);
     }
 
     protected void setY(int index, double dy)
     {
-        int newVal = Utility.converCoordToUnit(dy);
+        int newVal = DgnUtility.converCoordToUnit(dy);
 
         raw[21 + (4 * index)] = (short) ((newVal >> 16) & 0x0000ffff);
         raw[22 + (4 * index)] = (short) (newVal & 0x0000ffff);
diff --git a/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/ShapeElement.java b/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/ShapeElement.java
index 6f7bda6..945d11e 100644
--- a/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/ShapeElement.java
+++ b/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/ShapeElement.java
@@ -15,7 +15,7 @@
  */
 public class ShapeElement extends LineStringElement implements GeometryConverter
 {
-    static final Logger logger = Logger.getLogger(ShapeElement.class);
+    private static final Logger logger = Logger.getLogger(ShapeElement.class);
 
     public ShapeElement(byte[] raw)
     {
diff --git a/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/TcbElement.java b/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/TcbElement.java
index fa05e9f..2a2e165 100644
--- a/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/TcbElement.java
+++ b/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/TcbElement.java
@@ -1,5 +1,7 @@
 package com.ximple.io.dgn7;
 
+import org.apache.log4j.Logger;
+
 /**
  * TcbElement
  *
@@ -9,6 +11,8 @@
  */
 public class TcbElement extends Element
 {
+    private static final Logger logger = Logger.getLogger(TcbElement.class);
+
     public TcbElement(byte[] raw)
     {
         super(raw);
diff --git a/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/TextElement.java b/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/TextElement.java
index a013d5a..9630737 100644
--- a/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/TextElement.java
+++ b/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/TextElement.java
@@ -2,10 +2,14 @@
 
 //~--- non-JDK imports --------------------------------------------------------
 
+import org.apache.log4j.Logger;
+
 import com.vividsolutions.jts.geom.Coordinate;
 import com.vividsolutions.jts.geom.Envelope;
 import com.vividsolutions.jts.geom.Geometry;
 import com.vividsolutions.jts.geom.GeometryFactory;
+
+import com.ximple.util.DgnUtility;
 
 /**
  * TextElement
@@ -16,6 +20,8 @@
  */
 public class TextElement extends Element implements GeometryConverter
 {
+    private static final Logger logger = Logger.getLogger(TextElement.class);
+
     public static final int ED_CENTERJUSTIFICATION = 0;
 
     //  Enter data field center justification
@@ -62,12 +68,12 @@
 
         x += raw[26] & 0x0000ffff;
 
-        double dx = Utility.converUnitToCoord(x);
+        double dx = DgnUtility.converUnitToCoord(x);
         int y = (raw[27] << 16 & 0xffff0000);
 
         y += raw[28] & 0x0000ffff;
 
-        double dy = Utility.converUnitToCoord(y);
+        double dy = DgnUtility.converUnitToCoord(y);
 
         return new Coordinate(dx, dy);
     }
@@ -78,7 +84,7 @@
         double x = origin.x;
         double weight = getUserSetWeight();
         double height = getUserSetHeight();
-        double angle = Utility.converRotationToRadian(getRotationAngle());
+        double angle = DgnUtility.converRotationToRadian(getRotationAngle());
 
         x += weight * Math.cos(angle) - height * Math.sin(angle);
 
@@ -186,7 +192,7 @@
 
         height += raw[22] & 0x0000ffff;
 
-        return Utility.converIntToDouble(height);
+        return DgnUtility.converIntToDouble(height);
     }
 
     public double getTextWidth()
@@ -195,7 +201,7 @@
 
         length += raw[20] & 0x0000ffff;
 
-        return Utility.converIntToDouble(length);
+        return DgnUtility.converIntToDouble(length);
     }
 
     public int getJustification()
@@ -209,7 +215,7 @@
 
         totation += raw[24] & 0x0000ffff;
 
-        return Utility.converIntToRotation(totation);
+        return DgnUtility.converIntToRotation(totation);
     }
 
     public boolean isChinese()
diff --git a/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/TextNodeElement.java b/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/TextNodeElement.java
index eef53c2..645b4cf 100644
--- a/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/TextNodeElement.java
+++ b/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/TextNodeElement.java
@@ -8,9 +8,13 @@
 import java.util.List;
 import java.util.ListIterator;
 
+import org.apache.log4j.Logger;
+
 import com.vividsolutions.jts.geom.Coordinate;
 import com.vividsolutions.jts.geom.Geometry;
 import com.vividsolutions.jts.geom.GeometryFactory;
+
+import com.ximple.util.DgnUtility;
 
 /**
  * TextNodeElement
@@ -21,7 +25,9 @@
  */
 public class TextNodeElement extends Element implements ComplexElement, GeometryConverter
 {
-    ArrayList list = new ArrayList();
+    private static final Logger logger = Logger.getLogger(TextElement.class);
+
+    private ArrayList list = new ArrayList();
 
     public TextNodeElement(byte[] raw)
     {
@@ -225,7 +231,7 @@
         lengthMult = (int) ((raw[25] << 16) & 0xffff0000);
         lengthMult += (raw[26] & 0x0000ffff);
 
-        return Utility.converIntToDouble(lengthMult);
+        return DgnUtility.converIntToDouble(lengthMult);
     }
 
     public double getTextNodeHeight()
@@ -235,7 +241,7 @@
         heightMult = (int) ((raw[27] << 16) & 0xffff0000);
         heightMult += (raw[28] & 0x0000ffff);
 
-        return Utility.converIntToDouble(heightMult);
+        return DgnUtility.converIntToDouble(heightMult);
     }
 
     public double getRotationAngle()
@@ -244,7 +250,7 @@
 
         rotation += raw[30];
 
-        return Utility.converIntToRotation(rotation);
+        return DgnUtility.converIntToRotation(rotation);
     }
 
     public Coordinate getOrigin()
@@ -253,13 +259,13 @@
 
         x += raw[32] & 0x0000ffff;
 
-        // return Utility.convertFromDGN(x);
-        double dx = Utility.converUnitToCoord(x);
+        // return DgnUtility.convertFromDGN(x);
+        double dx = DgnUtility.converUnitToCoord(x);
         int    y  = (int) ((raw[33] << 16) & 0xffff0000);
 
         y += (raw[34] & 0x0000ffff);
 
-        double dy = Utility.converUnitToCoord(y);
+        double dy = DgnUtility.converUnitToCoord(y);
 
         return new Coordinate(dx, dy);
     }
diff --git a/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Utility.java b/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/util/DgnUtility.java
similarity index 97%
rename from xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Utility.java
rename to xdgnjobs/ximple-dgnio/src/main/java/com/ximple/util/DgnUtility.java
index 25f8254..012e150 100644
--- a/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Utility.java
+++ b/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/util/DgnUtility.java
@@ -1,4 +1,4 @@
-package com.ximple.io.dgn7;
+package com.ximple.util;
 
 import java.nio.ByteBuffer;
 import java.nio.ByteOrder;
@@ -14,9 +14,9 @@
  * @version 0.1
  * @since 2006/5/18 �U�� 01:33:00
  */
-public final class Utility
+public final class DgnUtility
 {
-    private static final Logger logger = Logger.getLogger(Utility.class);
+    private static final Logger logger = Logger.getLogger(DgnUtility.class);
 
     public static double converIntToDouble(int src)
     {

--
Gitblit v0.0.0-SNAPSHOT