From 8713611a01ee773ff9630a0af084422a0765cb90 Mon Sep 17 00:00:00 2001
From: ?? ? <ulysseskao@ximple.com.tw>
Date: Sat, 17 May 2008 00:29:33 +0800
Subject: [PATCH] update for EOFM-91

---
 xdgnjobs/ximple-jobcarrier/src/main/resources/quartz_jobs.xml                                   |    2 
 xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/TextNodeElement.java                     |   38 ++---
 xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2ShpJob.java     |    4 
 xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/TextElement.java                         |  219 ++++++++++++++++++------------------
 xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/GeneralDgnConvertJobContext.java |   37 ++++++
 xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Element.java                             |   28 +---
 xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateTextStrategy.java        |   18 ---
 7 files changed, 171 insertions(+), 175 deletions(-)

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 1a19a06..be83dde 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
@@ -54,20 +54,16 @@
 
     public Envelope getRange()
     {
-        int lowCoorX = (int) ((raw[3] << 16) & 0xffff0000) + (raw[2] & 0x0000ffff);
-
+        int lowCoorX = ((raw[3] << 16) & 0xffff0000) + (raw[2] & 0x0000ffff);
         lowCoorX = DgnUtility.convertFromDGN(lowCoorX);
 
-        int lowCoorY = (int) ((raw[5] << 16) & 0xffff0000) + (raw[4] & 0x0000ffff);
-
+        int lowCoorY = ((raw[5] << 16) & 0xffff0000) + (raw[4] & 0x0000ffff);
         lowCoorY = DgnUtility.convertFromDGN(lowCoorY);
 
-        int highCoorX = (int) ((raw[9] << 16) & 0xffff0000) + (raw[8] & 0x0000ffff);
-
+        int highCoorX = ((raw[9] << 16) & 0xffff0000) + (raw[8] & 0x0000ffff);
         highCoorX = DgnUtility.convertFromDGN(highCoorX);
 
-        int highCoorY = (int) ((raw[11] << 16) & 0xffff0000) + (raw[10] & 0x0000ffff);
-
+        int highCoorY = ((raw[11] << 16) & 0xffff0000) + (raw[10] & 0x0000ffff);
         highCoorY = DgnUtility.convertFromDGN(highCoorY);
 
         return new Envelope(DgnUtility.converUnitToCoord(lowCoorX), DgnUtility.converUnitToCoord(highCoorX),
@@ -76,13 +72,7 @@
 
     public boolean isComponentElement()
     {
-        if ((short) ((raw[0] >>> 7) & 0x0001) == 1)
-        {
-            return true;
-        } else
-        {
-            return false;
-        }
+        return (short) ((raw[0] >>> 7) & 0x0001) == 1;
     }
 
     public boolean removeUserAttributeData(int iLinkageId)
@@ -97,13 +87,7 @@
 
     public boolean isDeleted()
     {
-        if ((short) ((raw[0] >>> 15) & 0x0001) == 1)
-        {
-            return true;
-        } else
-        {
-            return false;
-        }
+        return (short) ((raw[0] >>> 15) & 0x0001) == 1;
     }
 
     public int getColorIndex()
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 9630737..12093e3 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
@@ -1,11 +1,10 @@
 package com.ximple.io.dgn7;
 
-//~--- non-JDK imports --------------------------------------------------------
+import java.awt.geom.AffineTransform;
 
 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;
 
@@ -30,32 +29,33 @@
     //  Enter data field left justification
     public static final int ED_RIGHTJUSTIFICATION = 0;
 
-    //  Enter data field right justification
-    public static final int TXTJUST_CB = 0;
+    public static final int TXTJUST_LT = 0;    /* Left Top */
+    public static final int TXTJUST_LC = 1;    /* Left Center */
+    public static final int TXTJUST_LB = 2;    /* Left Bottom */
+    public static final int TXTJUST_LMT = 3;   /* Left Margin Top */
+    public static final int TXTJUST_LMC = 4;   /* Left Margin Center */
+    public static final int TXTJUST_LMB = 5;   /* Left Margin Bottom */
+    public static final int TXTJUST_CT = 6;    /* Center Top */
+    public static final int TXTJUST_CC = 7;    /* Center Center */
+    public static final int TXTJUST_CB = 8;    /* Center Bottom */
+    public static final int TXTJUST_RMT = 9;   /* Right Margin Top */
+    public static final int TXTJUST_RMC = 10;  /* Right Margin Center */
+    public static final int TXTJUST_RMB = 11;  /* Right Margin Bottom */
+    public static final int TXTJUST_RT = 12;   /* Right Top */
+    public static final int TXTJUST_RC = 13;   /* Right Center */
+    public static final int TXTJUST_RB = 14;   /* Right Bottom */
 
-    //  Center/bottom text justification.
-    public static final int TXTJUST_CC = 0;
-
-    //  Center/center text justification.
-    public static final int TXTJUST_CT = 0;
-
-    //  Center/top text justification.
-    public static final int TXTJUST_LB = 0;
-
-    //  Left/bottom text justification.
-    public static final int TXTJUST_LC = 0;
-
-    //  Left/center text justification.
-    public static final int TXTJUST_LT = 0;
-
-    //  Left/top text justification.
-    public static final int TXTJUST_RB = 0;
-
-    //  Right/bottom text justification.
-    public static final int TXTJUST_RC = 0;
-
-    //  Right/center text justification.
-    public static final int TXTJUST_RT = 0;
+    public static final int TXTJUST_LU = 15;   /* Left Cap */
+    public static final int TXTJUST_LD = 16;   /* Left Descender */
+    public static final int TXTJUST_LMU = 17;  /* Left Margin Cap */
+    public static final int TXTJUST_LMD = 18;  /* Left Margin Descender */
+    public static final int TXTJUST_CU = 19;   /* Center Cap */
+    public static final int TXTJUST_CD = 20;   /* Center Descender */
+    public static final int TXTJUST_RMU = 21;  /* Right Margin Cap */
+    public static final int TXTJUST_RMD = 22;  /* Right Margin Descender */
+    public static final int TXTJUST_RU = 23;   /* Right Cap */
+    public static final int TXTJUST_RD = 24;   /* Right Descender */
+    public static final int TXTJUST_NONE = 127;/* no justfication */
 
     public TextElement(byte[] raw)
     {
@@ -76,84 +76,6 @@
         double dy = DgnUtility.converUnitToCoord(y);
 
         return new Coordinate(dx, dy);
-    }
-
-    public Coordinate getUserOrigin()
-    {
-        Coordinate origin = getOrigin();
-        double x = origin.x;
-        double weight = getUserSetWeight();
-        double height = getUserSetHeight();
-        double angle = DgnUtility.converRotationToRadian(getRotationAngle());
-
-        x += weight * Math.cos(angle) - height * Math.sin(angle);
-
-        double y = origin.y;
-
-        y += weight * Math.cos(angle) - height * Math.sin(angle);
-
-        return new Coordinate(x, y);
-    }
-
-    private double getUserSetWeight()
-    {
-        int just = getJustification();
-        Envelope range = getRange();
-        double weight = (range.getWidth());
-
-        switch (just)
-        {
-        case 0:
-        case 1:
-        case 2:
-            weight = 0;
-
-            break;
-
-        case 6:
-        case 7:
-        case 8:
-            weight = weight / 2;
-
-            break;
-
-        case 12:
-        case 13:
-        case 14:
-            break;
-        }
-
-        return weight;
-    }
-
-    private double getUserSetHeight()
-    {
-        int just = getJustification();
-        double height = getTextHeight();
-
-        switch (just)
-        {
-        case 2:
-        case 8:
-        case 14:    // bottom
-            height = 0;
-
-            break;
-
-        case 1:
-        case 7:
-        case 13:    // center
-            height = height / 2;
-
-            break;
-
-        case 0:
-        case 6:
-        case 12:    // height
-            break;
-        }
-
-        return height;
     }
 
     public int getFontIndex()
@@ -211,10 +133,7 @@
 
     public double getRotationAngle()
     {
-        int totation = ((raw[23] << 16) & 0xffff0000);
-
-        totation += raw[24] & 0x0000ffff;
-
+        int totation = ((raw[23] & 0x0000ffff) << 16) | (raw[24] & 0x0000ffff);
         return DgnUtility.converIntToRotation(totation);
     }
 
@@ -269,6 +188,88 @@
         return factory.createPoint(getUserOrigin());
     }
 
+    private double getUserWidth()
+    {
+        int just = getJustification();
+        // Envelope range = getRange();         // case -1
+        // double width = (range.getWidth());   // case -1
+        // double width = this.getTextWidth() * this.getTextLength() * 1000.0; // case -2
+        double width = (this.getTextWidth() * this.getTextLength());
+
+        switch (just)
+        {
+        case TXTJUST_LT:
+        case TXTJUST_LC:
+        case TXTJUST_LB:
+            width = 0;
+            break;
+
+        case TXTJUST_CT:
+        case TXTJUST_CC:
+        case TXTJUST_CB:
+            width = width / 2;
+            break;
+
+        case TXTJUST_RT:
+        case TXTJUST_RC:
+        case TXTJUST_RB:
+            break;
+        }
+
+        return width;
+    }
+
+    private double getUserHeight()
+    {
+        int just = getJustification();
+        double height = getTextHeight();
+
+        switch (just)
+        {
+        case TXTJUST_LB:
+        case TXTJUST_CB:
+        case TXTJUST_RB:    // bottom
+            height = 0;
+            break;
+
+        case TXTJUST_LC:
+        case TXTJUST_CC:
+        case TXTJUST_RC:    // center
+            height = height / 2;
+            break;
+
+        case TXTJUST_LT:
+        case TXTJUST_CT:
+        case TXTJUST_RT:    // height
+            break;
+        }
+
+        return height;
+    }
+
+    public Coordinate getUserOrigin()
+    {
+        double width = getUserWidth();
+        double height = getUserHeight();
+        double angle = Math.toRadians(getRotationAngle());
+
+        AffineTransform at = new AffineTransform();
+        at.translate(width, height);
+        Coordinate p = getOrigin();
+        at.setToRotation(angle, p.x, p.y);
+        at.scale(1, 1);
+
+        double[] srcPt = new double[2];
+        double[] dstPt = new double[2];
+
+        srcPt[0] = p.x + width ;
+        srcPt[1] = p.y + height ;
+
+        at.transform(srcPt, 0, dstPt, 0, 1);
+
+        return new Coordinate(dstPt[0], dstPt[1]);
+    }
+
     public static class ElementHandler extends Element.ElementHandler
     {
         private static ElementHandler instance = null;
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 645b4cf..4b70f52 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
@@ -186,49 +186,47 @@
 
     public int getNumString()
     {
-        return (int) (raw[19] & 0x0000ffff);
+        return (raw[19] & 0x0000ffff);
     }
 
     public int getNodeNumber()
     {
-        return (int) (raw[20] & 0x0000ffff);
+        return (raw[20] & 0x0000ffff);
     }
 
     public int getMaxLength()
     {
-        return (int) (raw[21] & 0x00ff);
+        return (raw[21] & 0x00ff);
     }
 
     public int getMaxUsed()
     {
-        return (int) ((raw[21] >> 8) & 0x00ff);
+        return ((raw[21] >> 8) & 0x00ff);
     }
 
     public int getJustification()
     {
-        return (int) ((raw[22] >> 8) & 0x00ff);
+        return ((raw[22] >> 8) & 0x00ff);
     }
 
     public int getFontIndex()
     {
-        return (int) (raw[22] & 0x00ff);
+        return (raw[22] & 0x00ff);
     }
 
     public double getLineSpacing()
     {
         int lineSpace;
-
-        lineSpace = (int) ((raw[23] << 16) & 0xffff0000);
-        lineSpace += (raw[24] & 0x0000ffff);
+        lineSpace = ((raw[23] & 0x0000ffff) << 16) | (raw[24] & 0x0000ffff);
 
         return lineSpace;
     }
 
     public double getTextNodeLength()
     {
-        int lengthMult = -1;
+        int lengthMult;
 
-        lengthMult = (int) ((raw[25] << 16) & 0xffff0000);
+        lengthMult = ((raw[25] << 16) & 0xffff0000);
         lengthMult += (raw[26] & 0x0000ffff);
 
         return DgnUtility.converIntToDouble(lengthMult);
@@ -236,9 +234,9 @@
 
     public double getTextNodeHeight()
     {
-        int heightMult = -1;
+        int heightMult;
 
-        heightMult = (int) ((raw[27] << 16) & 0xffff0000);
+        heightMult = ((raw[27] << 16) & 0xffff0000);
         heightMult += (raw[28] & 0x0000ffff);
 
         return DgnUtility.converIntToDouble(heightMult);
@@ -246,8 +244,7 @@
 
     public double getRotationAngle()
     {
-        int rotation = (int) (raw[29] << 16 & 0xffff0000);
-
+        int rotation = (raw[29] << 16 & 0xffff0000);
         rotation += raw[30];
 
         return DgnUtility.converIntToRotation(rotation);
@@ -255,16 +252,11 @@
 
     public Coordinate getOrigin()
     {
-        int x = (int) ((raw[31] << 16) & 0xffff0000);
-
-        x += raw[32] & 0x0000ffff;
-
-        // return DgnUtility.convertFromDGN(x);
+        int x = ((raw[31] << 16) & 0xffff0000) | (raw[32] & 0x0000ffff);
         double dx = DgnUtility.converUnitToCoord(x);
-        int    y  = (int) ((raw[33] << 16) & 0xffff0000);
+        // return DgnUtility.convertFromDGN(x);
 
-        y += (raw[34] & 0x0000ffff);
-
+        int y  = ((raw[33] << 16) & 0xffff0000) | (raw[34] & 0x0000ffff);
         double dy = DgnUtility.converUnitToCoord(y);
 
         return new Coordinate(dx, dy);
diff --git a/xdgnjobs/ximple-jobcarrier/src/main/resources/quartz_jobs.xml b/xdgnjobs/ximple-jobcarrier/src/main/resources/quartz_jobs.xml
index 53991c5..4a2345d 100644
--- a/xdgnjobs/ximple-jobcarrier/src/main/resources/quartz_jobs.xml
+++ b/xdgnjobs/ximple-jobcarrier/src/main/resources/quartz_jobs.xml
@@ -46,7 +46,7 @@
         </entry>
         <entry>
           <key>CONVERTDB</key>
-          <value>true</value>
+          <value>false</value>
         </entry>
         <entry>
           <key>CONVERTFILE</key>
diff --git a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateTextStrategy.java b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateTextStrategy.java
index 0dd716a..ccc097b 100644
--- a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateTextStrategy.java
+++ b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateTextStrategy.java
@@ -81,15 +81,6 @@
         {
             TextElement txtElement = (TextElement) element;
             double angle = txtElement.getRotationAngle();
-            /*
-            if (angle != 0.0)
-            {
-                angle -= 270.0;
-                angle = -angle;
-                angle = ((angle < 0.0) ? (angle + 360.0) : angle);
-                angle = ((angle > 360.0) ? (angle - 360.0) : (angle));
-            }
-            */
             convertDecorator.setConverter(txtElement);
             Feature feature = featureType.create(new Object[]{
                     convertDecorator.toGeometry(geometryFactory),
@@ -121,15 +112,6 @@
             }
 
             double angle = nodeElement.getRotationAngle();
-            /*
-            if (angle != 0.0)
-            {
-                angle -= 270.0;
-                angle = -angle;
-                angle = ((angle < 0.0) ? (angle + 360.0) : angle);
-                angle = ((angle > 360.0) ? (angle - 360.0) : (angle));
-            }
-            */
             convertDecorator.setConverter(nodeElement);
             Feature feature = featureType.create(new Object[]{
                     convertDecorator.toGeometry(geometryFactory),
diff --git a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/GeneralDgnConvertJobContext.java b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/GeneralDgnConvertJobContext.java
index 798c86e..83cb074 100644
--- a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/GeneralDgnConvertJobContext.java
+++ b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/GeneralDgnConvertJobContext.java
@@ -27,6 +27,8 @@
 
 import com.vividsolutions.jts.geom.Geometry;
 import com.vividsolutions.jts.geom.GeometryFactory;
+import com.vividsolutions.jts.geom.Envelope;
+import com.vividsolutions.jts.geom.Coordinate;
 
 import com.ximple.eofms.util.DefaultColorTable;
 import com.ximple.io.dgn7.Element;
@@ -39,6 +41,7 @@
 import com.ximple.io.dgn7.ArcElement;
 import com.ximple.io.dgn7.EllipseElement;
 import com.ximple.io.dgn7.ComplexChainElement;
+import com.ximple.io.dgn7.TextNodeElement;
 
 public class GeneralDgnConvertJobContext extends AbstractDgnFileJobContext
 {
@@ -272,6 +275,7 @@
         {
             TextElement textElement = (TextElement) element;
             convertDecorator.setConverter(textElement);
+
             Geometry geom = convertDecorator.toGeometry(geometryFactory);
             double angle = textElement.getRotationAngle();
             if (geom != null)
@@ -291,6 +295,39 @@
                 logger.info("geometry is null." + element.toString());
             }
             return null;
+        } else if (element instanceof TextNodeElement)
+        {
+            TextNodeElement textNodeElement = (TextNodeElement) element;
+            convertDecorator.setConverter(textNodeElement);
+
+            Geometry geom = convertDecorator.toGeometry(geometryFactory);
+            double angle = textNodeElement.getRotationAngle();
+            String[] texts = textNodeElement.getTextArray();
+            StringBuffer sb = new StringBuffer();
+            for (String text : texts)
+            {
+                if (sb.length() != 0)
+                    sb.append("\n");
+                sb.append(text);
+            }
+
+            if (geom != null)
+            {
+                return featureType.create(new Object[]{
+                        geom,
+                        colorTable.getColorCode(textNodeElement.getColorIndex()),
+                        textNodeElement.getFontIndex(),
+                        textNodeElement.getJustification(),
+                        textNodeElement.getTextNodeHeight(),
+                        textNodeElement.getTextNodeLength(),
+                        angle,
+                        sb.toString()
+                });
+            } else
+            {
+                logger.info("geometry is null." + element.toString());
+            }
+            return null;
         } else if (element instanceof ShapeElement)
         {
             ShapeElement shapeElement = (ShapeElement) element;
diff --git a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2ShpJob.java b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2ShpJob.java
index 46f2df1..f51ef5a 100644
--- a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2ShpJob.java
+++ b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2ShpJob.java
@@ -146,8 +146,8 @@
     /**
      * Connectivity�ƻs�@�Ӫ����A�b�d�߹q�y��V�ɥΨӤ��OMS��Ʈw���q���s����(Connectivity)
      *
-     * @param jobContext
-     * @throws SQLException
+     * @param jobContext job context
+     * @throws SQLException sql exception
      */
     private void copyConnectivity(OracleConvertJobContext jobContext) throws SQLException
     {

--
Gitblit v0.0.0-SNAPSHOT