forked from geodmms/xdgnjobs

?? ?
2008-05-07 10445847ed1bfa5755127e828b603a3cdd49c5e3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package com.ximple.io.dgn7;
 
//~--- non-JDK imports --------------------------------------------------------
 
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
 
/**
 * ArcElement
 *
 * @author Ulysses
 * @version 0.1
 * @since 2006/5/26 下午 06:41:45
 */
public class ArcElement extends Element implements GeometryConverter
{
    public ArcElement(short[] raw)
    {
        super(raw);
    }
 
    public double getPrimary()
    {
        short[] primary = new short[4];
 
        System.arraycopy(raw, 22, 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, 22, 4);
    }
 
    public double getSecondary()
    {
        short[] secondary = new short[4];
 
        System.arraycopy(raw, 26, 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, 26, 4);
    }
 
    public Coordinate getOrigin()
    {
        short[] x = new short[4];
 
        System.arraycopy(raw, 32, x, 0, 4);
 
        double  dx = Utility.ConverUnitToCoord((int) Utility.DGNToIEEEDouble(x));
        short[] y  = new short[4];
 
        System.arraycopy(raw, 36, 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, 32, 4);
        temp = Utility.ConverCoordToUnit(value.y);
 
        short[] y = Utility.IEEEDoubleToDGN(temp);
 
        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.
    }
 
    public static class ElementHandler extends Element.ElementHandler
    {
        private static ElementHandler instance = null;
 
        public ElementHandler()
        {
            super(ElementType.ARC);
        }
 
        public static IElementHandler getInstance()
        {
            if (instance == null)
            {
                instance = new ElementHandler();
            }
 
            return instance;
        }
 
        protected Element createElement(short[] raw)
        {
            return new ArcElement(raw);
        }
    }
}