Statistics
| Revision:

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

History | View | Annotate | Download (7.62 KB)

1
/* 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
import java.awt.geom.Point2D;
38
import java.util.ArrayList;
39
import java.util.List;
40
import java.util.Map;
41

    
42
import com.iver.cit.gvsig.fmap.core.FPolyline2D;
43
import com.iver.cit.gvsig.fmap.core.IGeometry;
44
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
45
import com.iver.cit.jdwglib.dwg.DwgFile;
46
import com.iver.cit.jdwglib.dwg.DwgObject;
47
import com.iver.cit.jdwglib.dwg.IDwg2FMap;
48
import com.iver.cit.jdwglib.dwg.IDwg3DTestable;
49
import com.iver.cit.jdwglib.dwg.IDwgBlockMember;
50
import com.iver.cit.jdwglib.dwg.IDwgExtrusionable;
51
import com.iver.cit.jdwglib.util.AcadExtrusionCalculator;
52
import com.iver.cit.jdwglib.util.FMapUtil;
53
import com.iver.cit.jdwglib.util.GisModelCurveCalculator;
54

    
55
/**
56
 * The DwgArc class represents a DWG Arc
57
 * 
58
 * @author jmorell
59
 */
60
public class DwgArc extends DwgObject 
61
        implements IDwgExtrusionable, IDwg3DTestable, IDwg2FMap, IDwgBlockMember {
62
        
63
        private double[] center;
64
        private double radius;
65
        private double thickness;
66
        private double[] extrusion;
67
        private double initAngle;
68
        private double endAngle;
69
        
70
        public DwgArc(int index) {
71
                super(index);
72
        }
73
        
74
        
75
        /**
76
         * @return Returns the center.
77
         */
78
        public double[] getCenter() {
79
                return center;
80
        }
81
        /**
82
         * @param center The center to set.
83
         */
84
        public void setCenter(double[] center) {
85
                this.center = center;
86
        }
87
        /**
88
         * @return Returns the endAngle.
89
         */
90
        public double getEndAngle() {
91
                return endAngle;
92
        }
93
        /**
94
         * @param endAngle The endAngle to set.
95
         */
96
        public void setEndAngle(double endAngle) {
97
                this.endAngle = endAngle;
98
        }
99
        /**
100
         * @return Returns the initAngle.
101
         */
102
        public double getInitAngle() {
103
                return initAngle;
104
        }
105
        /**
106
         * @param initAngle The initAngle to set.
107
         */
108
        public void setInitAngle(double initAngle) {
109
                this.initAngle = initAngle;
110
        }
111
        /**
112
         * @return Returns the radius.
113
         */
114
        public double getRadius() {
115
                return radius;
116
        }
117
        /**
118
         * @param radius The radius to set.
119
         */
120
        public void setRadius(double radius) {
121
                this.radius = radius;
122
        }
123
    /**
124
     * @return Returns the extrusion.
125
     */
126
    public double[] getExtrusion() {
127
        return extrusion;
128
    }
129
    
130
        /**
131
         * @return Returns the thickness.
132
         */
133
        public double getThickness() {
134
                return thickness;
135
        }
136
        /**
137
         * @param thickness The thickness to set.
138
         */
139
        public void setThickness(double thickness) {
140
                this.thickness = thickness;
141
        }
142
        /**
143
         * @param extrusion The extrusion to set.
144
         */
145
        public void setExtrusion(double[] extrusion) {
146
                this.extrusion = extrusion;
147
        }
148

    
149
        /* (non-Javadoc)
150
         * @see com.iver.cit.jdwglib.dwg.IDwgExtrusionable#applyExtrussion()
151
         */
152
        public void applyExtrussion() {
153
                 double[] arcCenter = getCenter();
154
         double[] arcExt = getExtrusion();
155
         arcCenter = AcadExtrusionCalculator.
156
                         extrude2(arcCenter, arcExt);
157
         setCenter(arcCenter);
158
                
159
        }
160

    
161
        /* (non-Javadoc)
162
         * @see com.iver.cit.jdwglib.dwg.IDwg3DTestable#has3DData()
163
         */
164
        public boolean has3DData() {
165
                return (getCenter()[2] != 0.0);
166
        }
167

    
168
        /* (non-Javadoc)
169
         * @see com.iver.cit.jdwglib.dwg.IDwg2FMap#toFMapGeometry()
170
         */
171
        public IGeometry toFMapGeometry(boolean is3DFile) {
172
                double[] center = getCenter();
173
                double radius = getRadius();
174
                double initAngle = Math.toDegrees(getInitAngle());
175
                double endAngle = Math.toDegrees(getEndAngle());
176
                List arc = GisModelCurveCalculator.calculateGisModelArc(
177
                                center, radius, initAngle, endAngle);
178
                FPolyline2D arcc;
179
                if (is3DFile) {
180
                        List arc3D = new ArrayList();
181
                        for (int j = 0; j < arc.size(); j++) {
182
                                double[] point = (double[]) arc.get(j);
183
                                double[] newP = new double[]{point[0], point[1], center[2]};
184
                                arc3D.add(newP);
185
                        }
186
                        arcc = FMapUtil.points3DToFPolyline3D(arc3D);
187
                        
188
                } else {
189
                        arcc = FMapUtil.points2DToFPolyline2D(arc);
190
                }
191
                return ShapeFactory.createGeometry(arcc);
192
        }
193
        
194
        public String toString(){
195
                return "Arc";
196
        }
197

    
198
        /* (non-Javadoc)
199
         * @see com.iver.cit.jdwglib.dwg.IDwg2FMap#toFMapString()
200
         */
201
        public String toFMapString(boolean is3dFile) {
202
                if(is3dFile)
203
                        return "FPolyline3D";
204
                else
205
                        return "FPolyline2D";
206
        }
207

    
208
        /* (non-Javadoc)
209
         * @see com.iver.cit.jdwglib.dwg.IDwg3DTestable#getZ()
210
         */
211
        public double getZ() {
212
                return getCenter()[2];
213
        }
214

    
215
        public void transform2Block(double[] bPoint, Point2D insPoint, double[] scale, double rot, 
216
                        List dwgObjectsWithoutBlocks, Map handleObjWithoutBlocks, DwgFile callBack) {
217
                //DwgArc transformedEntity = new DwgArc(getIndex());
218
                double[] center = this.getCenter();
219
                Point2D pointAux = new Point2D.Double(center[0] - bPoint[0], center[1] - bPoint[1]);
220
                double laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(rot) + (pointAux.getY()*scale[1])*(-1)*Math.sin(rot));
221
                double laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(rot) + (pointAux.getY()*scale[1])*Math.cos(rot));
222
                double laZ = center[2] * scale[2];
223
                double[] transformedCenter = new double[]{laX, laY, laZ};
224
                double radius = this.getRadius();
225
                double transformedRadius = radius * scale[0];
226
                double initAngle = this.getInitAngle();
227
                double endAngle = this.getEndAngle();
228
                double transformedInitAngle = initAngle + rot;
229
                if (transformedInitAngle<0) {
230
                    transformedInitAngle = transformedInitAngle + (2*Math.PI);
231
                } else if (transformedInitAngle>(2*Math.PI)) {
232
                    transformedInitAngle = transformedInitAngle - (2*Math.PI);
233
                }
234
                double transformedEndAngle = endAngle + rot;
235
                if (transformedEndAngle<0) {
236
                    transformedEndAngle = transformedEndAngle + (2*Math.PI);
237
                } else if (transformedEndAngle>(2*Math.PI)) {
238
                    transformedEndAngle = transformedEndAngle - (2*Math.PI);
239
                }
240
                DwgArc transformedEntity = (DwgArc) this.clone();
241
                transformedEntity.setCenter(transformedCenter);
242
                transformedEntity.setRadius(transformedRadius);
243
                transformedEntity.setInitAngle(transformedInitAngle);
244
                transformedEntity.setEndAngle(transformedEndAngle);
245
                transformedEntity.setHandle(this.getHandle());
246
                
247
                
248
                
249
                
250
                
251
                
252
                dwgObjectsWithoutBlocks.add(transformedEntity);
253
                handleObjWithoutBlocks.put(new Integer(transformedEntity.getHandle().getOffset()), transformedEntity);
254
                
255
//                setCenter(transformedCenter);
256
//                setRadius(transformedRadius);
257
//                setInitAngle(transformedInitAngle);
258
//                setEndAngle(transformedEndAngle);
259
//                dwgObjectsWithoutBlocks.add(this);
260
        }
261
        /* (non-Javadoc)
262
         * @see java.lang.Object#clone()
263
         */
264
public Object clone(){
265
                DwgArc obj = new DwgArc(index);
266
                this.fill(obj);
267
                return obj;
268
        }
269
        
270
        protected void fill(DwgObject obj){
271
                super.fill(obj);
272
                DwgArc myObj = (DwgArc)obj;
273

    
274
                myObj.setCenter(center);
275
                myObj.setEndAngle(endAngle);
276
                myObj.setExtrusion(extrusion);
277
                myObj.setInitAngle(initAngle);
278
                myObj.setRadius(radius);
279
                myObj.setThickness(thickness);
280

    
281
        }
282

    
283
}