forked from geodmms/xdgnjobs

?? ?
2008-05-13 2595f91f4aae3020cee3e0b4022aca6d9bc15fe6
update for EOFM-83
3 files modified
1 files added
483 ■■■■■ changed files
.gitattributes 1 ●●●● patch | view | raw | blame | history
xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/ArcElement.java 136 ●●●●● patch | view | raw | blame | history
xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/ElementType.java 173 ●●●●● patch | view | raw | blame | history
xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/EllipseElement.java 173 ●●●●● patch | view | raw | blame | history
.gitattributes
@@ -11,6 +11,7 @@
xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Dgn7fileReader.java svneol=native#text/plain
xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Element.java svneol=native#text/plain
xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/ElementType.java svneol=native#text/plain
xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/EllipseElement.java svneol=native#text/plain
xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/FrammeAttributeData.java svneol=native#text/plain
xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/GeometryConverter.java svneol=native#text/plain
xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/IElementHandler.java svneol=native#text/plain
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
xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/ElementType.java
@@ -215,162 +215,39 @@
    public boolean isComplexElement()
    {
        if (id == 2)
        {
            return true;
        }
        return id == 2 || id == 7 || id == 12 || id == 14 || id == 18 ||
                id == 19 || id == 106 || id == 107;
        if (id == 7)
        {
            return true;
        }
        if (id == 12)
        {
            return true;
        }
        if (id == 14)
        {
            return true;
        }
        if (id == 18)
        {
            return true;
        }
        if (id == 19)
        {
            return true;
        }
        if (id == 106)
        {
            return true;
        }
        if (id == 107)
        {
            return true;
        }
        return false;
    }
    public boolean isPointType()
    {
        if (id == 7)
        {
            return true;
        }
        return id == 7 || id == 17;
        if (id == 17)
        {
            return true;
        }
        return false;
    }
    public boolean isLineType()
    {
        if (id == 3)
        {
            return true;
        }
        return id == 3 || id == 4 || id == 11 || id == 12 || id == 16;
        if (id == 4)
        {
            return true;
        }
        if (id == 11)
        {
            return true;
        }
        if (id == 12)
        {
            return true;
        }
        if (id == 16)
        {
            return true;
        }
        return false;
    }
    public boolean isPolygonType()
    {
        if (id == 6)
        {
            return true;
        }
        return id == 6 || id == 14;
        if (id == 14)
        {
            return true;
        }
        return false;
    }
    public boolean isMultiPointType()
    {
        if (id == 3)
        {
            return true;
        }
        return id == 3 || id == 4 || id == 6 || id == 11 || id == 12 ||
                id == 13 || id == 14 || id == 15 || id == 16 || id == 22;
        if (id == 4)
        {
            return true;
        }
    }
        if (id == 6)
        {
            return true;
        }
        if (id == 11)
        {
            return true;
        }
        if (id == 12)
        {
            return true;
        }
        if (id == 13)
        {
            return true;
        }
        if (id == 14)
        {
            return true;
        }
        if (id == 15)
        {
            return true;
        }
        if (id == 16)
        {
            return true;
        }
        if (id == 22)
        {
            return true;
        }
        return false;
    public boolean isArcType()
    {
        return id == 15 || (id == 16);
    }
    /**
@@ -387,72 +264,58 @@
        {
        case 0 :
            t = NULL;
            break;
        case 3 :
            t = LINE;
            break;
        case 4 :
            t = LINESTRING;
            break;
        case 6 :
            t = SHAPE;
            break;
        case 7 :
            t = TEXTNODE;
            break;
        case 8 :
            t = IGDSDIGITIZER;
            break;
        case 9 :
            t = TCB;
            break;
        case 10 :
            t = LEVELSYMBOLOGY;
            break;
        case 12 :
            t = COMPLEXCHAIN;
            break;
        case 14 :
            t = COMPLEXSHAPE;
            break;
        case 15 :
            t = ELLIPSE;
            break;
        case 16 :
            t = ARC;
            break;
        case 17 :
            t = TEXT;
            break;
        default :
            t = UNDEFINED;
            break;
        }
@@ -467,62 +330,50 @@
        {
        case 3 :
            handler = LineElement.ElementHandler.getInstance();
            break;
        case 4 :
            handler = LineStringElement.ElementHandler.getInstance();
            break;
        case 6 :
            handler = ShapeElement.ElementHandler.getInstance();
            break;
        case 7 :
            handler = TextNodeElement.ElementHandler.getInstance();
            break;
        case 8 :
            handler = new Element.ElementHandler(this);
            break;
        case 9 :
            handler = new Element.ElementHandler(this);
            break;
        case 10 :
            handler = new Element.ElementHandler(this);
            break;
        case 12 :
            handler = ComplexChainElement.ElementHandler.getInstance();
            break;
        case 14 :
            handler = ComplexShapeElement.ElementHandler.getInstance();
            break;
        case 15 :
            handler = new Element.ElementHandler(this);
            handler = EllipseElement.ElementHandler.getInstance();
            break;
        case 16 :
            handler = ArcElement.ElementHandler.getInstance();
            break;
        case 17 :
            handler = TextElement.ElementHandler.getInstance();
            break;
        default :
xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/EllipseElement.java
New file
@@ -0,0 +1,173 @@
package com.ximple.io.dgn7;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
public class EllipseElement extends Element implements GeometryConverter
{
    public EllipseElement(short[] raw)
    {
        super(raw);
    }
    public double getStartAngle()
    {
        return 0.0;
    }
    public void setStartAngle(double value)
    {
    }
    public double getSweepAngle()
    {
        return 360.0;
    }
    public void setSweepAngle(double value)
    {
    }
    public double getPrimary()
    {
        short[] primary = new short[4];
        System.arraycopy(raw, 18, primary, 0, 4);
        return Utility.DGNToIEEEDouble(primary) / 1000.0;
    }
    public void setPrimary(double value)
    {
        double temp = value * 1000.0;
        short[] primary = Utility.IEEEDoubleToDGN(temp);
        System.arraycopy(primary, 0, raw, 18, 4);
    }
    public double getSecondary()
    {
        short[] secondary = new short[4];
        System.arraycopy(raw, 22, secondary, 0, 4);
        return Utility.DGNToIEEEDouble(secondary) / 1000.0;
    }
    public void setSecondary(double value)
    {
        double temp = value * 1000.0;
        short[] secondary = Utility.IEEEDoubleToDGN(temp);
        System.arraycopy(secondary, 0, raw, 22, 4);
    }
    public double getRotationAngle()
    {
        int rotation = (raw[26] << 16 & 0xffff0000);
        rotation += raw[27] & 0x0000ffff;
        return Utility.ConverIntToRotation(rotation);
    }
    public void setRotationAngle(double value)
    {
        int angle = Utility.ConverRotatioToInt(value);
        raw[26] = (short) (angle >> 16 & 0x0000ffff);
        raw[27] = (short) (angle & 0x0000ffff);
    }
    public Coordinate getOrigin()
    {
        short[] x = new short[4];
        System.arraycopy(raw, 28, x, 0, 4);
        double dx = Utility.ConverUnitToCoord((int) Utility.DGNToIEEEDouble(x));
        short[] y = new short[4];
        System.arraycopy(raw, 32, y, 0, 4);
        double dy = Utility.ConverUnitToCoord((int) Utility.DGNToIEEEDouble(y));
        return new Coordinate(dx, dy);
    }
    public void setOrigin(Coordinate value)
    {
        double temp = Utility.ConverCoordToUnit(value.x);
        short[] x = Utility.IEEEDoubleToDGN(temp);
        System.arraycopy(x, 0, raw, 28, 4);
        temp = Utility.ConverCoordToUnit(value.y);
        short[] y = Utility.IEEEDoubleToDGN(temp);
        System.arraycopy(y, 0, raw, 32, 4);
    }
    public Geometry toGeometry(GeometryFactory factory)
    {
        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
    {
        private static ElementHandler instance = null;
        public ElementHandler()
        {
            super(ElementType.ELLIPSE);
        }
        public static IElementHandler getInstance()
        {
            if (instance == null)
            {
                instance = new ElementHandler();
            }
            return instance;
        }
        protected Element createElement(short[] raw)
        {
            return new EllipseElement(raw);
        }
    }
}