Statistics
| Revision:

root / trunk / libraries / libDwg / src / com / iver / cit / jdwglib / dwg / objects / DwgArc.java @ 10632

History | View | Annotate | Download (7.54 KB)

1 2896 jmorell
/* jdwglib. Java Library for reading Dwg files.
2
 *
3
 * Author: Jose Morell Rama (jose.morell@gmail.com).
4
 * Port from the Pythoncad Dwg library by Art Haas.
5
 *
6
 * Copyright (C) 2005 Jose Morell, IVER TI S.A. and Generalitat Valenciana
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
21
 *
22
 * For more information, contact:
23
 *
24
 * Jose Morell (jose.morell@gmail.com)
25
 *
26
 * or
27
 *
28
 * IVER TI S.A.
29
 *  C/Salamanca, 50
30
 *  46005 Valencia
31
 *  Spain
32
 *  +34 963163400
33
 *  dac@iver.es
34
 */
35
package com.iver.cit.jdwglib.dwg.objects;
36
37 9825 azabala
import java.awt.geom.Point2D;
38 10632 azabala
import java.util.ArrayList;
39 9843 azabala
import java.util.List;
40 10240 azabala
import java.util.Map;
41 2896 jmorell
42 9825 azabala
import com.iver.cit.gvsig.fmap.core.FPolyline2D;
43
import com.iver.cit.gvsig.fmap.core.FShape;
44 9843 azabala
import com.iver.cit.jdwglib.dwg.DwgFile;
45 2896 jmorell
import com.iver.cit.jdwglib.dwg.DwgObject;
46 9825 azabala
import com.iver.cit.jdwglib.dwg.IDwg2FMap;
47
import com.iver.cit.jdwglib.dwg.IDwg3DTestable;
48 9843 azabala
import com.iver.cit.jdwglib.dwg.IDwgBlockMember;
49 9825 azabala
import com.iver.cit.jdwglib.dwg.IDwgExtrusionable;
50
import com.iver.cit.jdwglib.util.AcadExtrusionCalculator;
51
import com.iver.cit.jdwglib.util.FMapUtil;
52
import com.iver.cit.jdwglib.util.GisModelCurveCalculator;
53 2896 jmorell
54
/**
55
 * The DwgArc class represents a DWG Arc
56
 *
57
 * @author jmorell
58
 */
59 9825 azabala
public class DwgArc extends DwgObject
60 9843 azabala
        implements IDwgExtrusionable, IDwg3DTestable, IDwg2FMap, IDwgBlockMember {
61 9718 azabala
62 2896 jmorell
        private double[] center;
63
        private double radius;
64
        private double thickness;
65
        private double[] extrusion;
66
        private double initAngle;
67
        private double endAngle;
68
69 9718 azabala
        public DwgArc(int index) {
70
                super(index);
71
        }
72
73 9927 azabala
74 2896 jmorell
        /**
75
         * @return Returns the center.
76
         */
77
        public double[] getCenter() {
78
                return center;
79
        }
80
        /**
81
         * @param center The center to set.
82
         */
83
        public void setCenter(double[] center) {
84
                this.center = center;
85
        }
86
        /**
87
         * @return Returns the endAngle.
88
         */
89
        public double getEndAngle() {
90
                return endAngle;
91
        }
92
        /**
93
         * @param endAngle The endAngle to set.
94
         */
95
        public void setEndAngle(double endAngle) {
96
                this.endAngle = endAngle;
97
        }
98
        /**
99
         * @return Returns the initAngle.
100
         */
101
        public double getInitAngle() {
102
                return initAngle;
103
        }
104
        /**
105
         * @param initAngle The initAngle to set.
106
         */
107
        public void setInitAngle(double initAngle) {
108
                this.initAngle = initAngle;
109
        }
110
        /**
111
         * @return Returns the radius.
112
         */
113
        public double getRadius() {
114
                return radius;
115
        }
116
        /**
117
         * @param radius The radius to set.
118
         */
119
        public void setRadius(double radius) {
120
                this.radius = radius;
121
        }
122
    /**
123
     * @return Returns the extrusion.
124
     */
125
    public double[] getExtrusion() {
126
        return extrusion;
127
    }
128
129
        /**
130
         * @return Returns the thickness.
131
         */
132
        public double getThickness() {
133
                return thickness;
134
        }
135
        /**
136
         * @param thickness The thickness to set.
137
         */
138
        public void setThickness(double thickness) {
139
                this.thickness = thickness;
140
        }
141
        /**
142
         * @param extrusion The extrusion to set.
143
         */
144
        public void setExtrusion(double[] extrusion) {
145
                this.extrusion = extrusion;
146
        }
147 9825 azabala
148
        /* (non-Javadoc)
149
         * @see com.iver.cit.jdwglib.dwg.IDwgExtrusionable#applyExtrussion()
150
         */
151
        public void applyExtrussion() {
152
                 double[] arcCenter = getCenter();
153
         double[] arcExt = getExtrusion();
154
         arcCenter = AcadExtrusionCalculator.
155 10319 azabala
                         extrude2(arcCenter, arcExt);
156 9825 azabala
         setCenter(arcCenter);
157
158
        }
159
160
        /* (non-Javadoc)
161
         * @see com.iver.cit.jdwglib.dwg.IDwg3DTestable#has3DData()
162
         */
163
        public boolean has3DData() {
164
                return (getCenter()[2] != 0.0);
165
        }
166
167
        /* (non-Javadoc)
168
         * @see com.iver.cit.jdwglib.dwg.IDwg2FMap#toFMapGeometry()
169
         */
170
        public FShape toFMapGeometry(boolean is3DFile) {
171 10632 azabala
                double[] center = getCenter();
172 9825 azabala
                double radius = getRadius();
173
                double initAngle = Math.toDegrees(getInitAngle());
174
                double endAngle = Math.toDegrees(getEndAngle());
175 10632 azabala
                List arc = GisModelCurveCalculator.calculateGisModelArc(
176 9825 azabala
                                center, radius, initAngle, endAngle);
177
                FPolyline2D arcc;
178
                if (is3DFile) {
179 10632 azabala
                        List arc3D = new ArrayList();
180
                        for (int j = 0; j < arc.size(); j++) {
181
                                double[] point = (double[]) arc.get(j);
182
                                double[] newP = new double[]{point[0], point[1], center[2]};
183
                                arc3D.add(newP);
184 9825 azabala
                        }
185
                        arcc = FMapUtil.points3DToFPolyline3D(arc3D);
186
187
                } else {
188
                        arcc = FMapUtil.points2DToFPolyline2D(arc);
189
                }
190
                return arcc;
191
        }
192
193
        public String toString(){
194
                return "Arc";
195
        }
196
197
        /* (non-Javadoc)
198
         * @see com.iver.cit.jdwglib.dwg.IDwg2FMap#toFMapString()
199
         */
200
        public String toFMapString(boolean is3dFile) {
201
                if(is3dFile)
202
                        return "FPolyline3D";
203
                else
204
                        return "FPolyline2D";
205
        }
206
207
        /* (non-Javadoc)
208
         * @see com.iver.cit.jdwglib.dwg.IDwg3DTestable#getZ()
209
         */
210
        public double getZ() {
211
                return getCenter()[2];
212
        }
213 9843 azabala
214 10240 azabala
        public void transform2Block(double[] bPoint, Point2D insPoint, double[] scale, double rot,
215
                        List dwgObjectsWithoutBlocks, Map handleObjWithoutBlocks, DwgFile callBack) {
216 9977 azabala
                //DwgArc transformedEntity = new DwgArc(getIndex());
217
                double[] center = this.getCenter();
218
                Point2D pointAux = new Point2D.Double(center[0] - bPoint[0], center[1] - bPoint[1]);
219
                double laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(rot) + (pointAux.getY()*scale[1])*(-1)*Math.sin(rot));
220
                double laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(rot) + (pointAux.getY()*scale[1])*Math.cos(rot));
221 9843 azabala
                double laZ = center[2] * scale[2];
222
                double[] transformedCenter = new double[]{laX, laY, laZ};
223 9977 azabala
                double radius = this.getRadius();
224 9843 azabala
                double transformedRadius = radius * scale[0];
225 9977 azabala
                double initAngle = this.getInitAngle();
226
                double endAngle = this.getEndAngle();
227
                double transformedInitAngle = initAngle + rot;
228
                if (transformedInitAngle<0) {
229
                    transformedInitAngle = transformedInitAngle + (2*Math.PI);
230
                } else if (transformedInitAngle>(2*Math.PI)) {
231
                    transformedInitAngle = transformedInitAngle - (2*Math.PI);
232
                }
233
                double transformedEndAngle = endAngle + rot;
234
                if (transformedEndAngle<0) {
235
                    transformedEndAngle = transformedEndAngle + (2*Math.PI);
236
                } else if (transformedEndAngle>(2*Math.PI)) {
237
                    transformedEndAngle = transformedEndAngle - (2*Math.PI);
238
                }
239 10064 azabala
                DwgArc transformedEntity = (DwgArc) this.clone();
240
                transformedEntity.setCenter(transformedCenter);
241
                transformedEntity.setRadius(transformedRadius);
242
                transformedEntity.setInitAngle(transformedInitAngle);
243
                transformedEntity.setEndAngle(transformedEndAngle);
244
                transformedEntity.setHandle(this.getHandle());
245 10054 azabala
246 10064 azabala
247
248
249
250
251
                dwgObjectsWithoutBlocks.add(transformedEntity);
252 10240 azabala
                handleObjWithoutBlocks.put(new Integer(transformedEntity.getHandle().getOffset()), transformedEntity);
253 10064 azabala
254
//                setCenter(transformedCenter);
255
//                setRadius(transformedRadius);
256
//                setInitAngle(transformedInitAngle);
257
//                setEndAngle(transformedEndAngle);
258
//                dwgObjectsWithoutBlocks.add(this);
259 9843 azabala
        }
260 10174 fdiaz
        /* (non-Javadoc)
261
         * @see java.lang.Object#clone()
262
         */
263
public Object clone(){
264
                DwgArc obj = new DwgArc(index);
265
                this.fill(obj);
266
                return obj;
267
        }
268
269
        protected void fill(DwgObject obj){
270
                super.fill(obj);
271
                DwgArc myObj = (DwgArc)obj;
272
273
                myObj.setCenter(center);
274
                myObj.setEndAngle(endAngle);
275
                myObj.setExtrusion(extrusion);
276
                myObj.setInitAngle(initAngle);
277
                myObj.setRadius(radius);
278
                myObj.setThickness(thickness);
279
280
        }
281
282 2896 jmorell
}