Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libDwg / src / com / iver / cit / jdwglib / dwg / objects / DwgArc.java @ 23458

History | View | Annotate | Download (7.63 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 org.gvsig.fmap.geom.Geometry;
43
import org.gvsig.fmap.geom.GeometryFactory;
44
import org.gvsig.fmap.geom.GeometryManager;
45
import org.gvsig.fmap.geom.util.UtilFunctions;
46

    
47
import com.iver.cit.jdwglib.dwg.DwgFile;
48
import com.iver.cit.jdwglib.dwg.DwgObject;
49
import com.iver.cit.jdwglib.dwg.IDwg2FMap;
50
import com.iver.cit.jdwglib.dwg.IDwg3DTestable;
51
import com.iver.cit.jdwglib.dwg.IDwgBlockMember;
52
import com.iver.cit.jdwglib.dwg.IDwgExtrusionable;
53
import com.iver.cit.jdwglib.util.AcadExtrusionCalculator;
54
import com.iver.cit.jdwglib.util.FMapUtil;
55
import com.iver.cit.jdwglib.util.GisModelCurveCalculator;
56

    
57
/**
58
 * The DwgArc class represents a DWG Arc
59
 *
60
 * @author jmorell
61
 */
62
public class DwgArc extends DwgObject
63
        implements IDwgExtrusionable, IDwg3DTestable, IDwg2FMap, IDwgBlockMember {
64

    
65
        private double[] center;
66
        private double radius;
67
        private double thickness;
68
        private double[] extrusion;
69
        private double initAngle;
70
        private double endAngle;
71

    
72
        public DwgArc(int index) {
73
                super(index);
74
        }
75

    
76

    
77
        /**
78
         * @return Returns the center.
79
         */
80
        public double[] getCenter() {
81
                return center;
82
        }
83
        /**
84
         * @param center The center to set.
85
         */
86
        public void setCenter(double[] center) {
87
                this.center = center;
88
        }
89
        /**
90
         * @return Returns the endAngle.
91
         */
92
        public double getEndAngle() {
93
                return endAngle;
94
        }
95
        /**
96
         * @param endAngle The endAngle to set.
97
         */
98
        public void setEndAngle(double endAngle) {
99
                this.endAngle = endAngle;
100
        }
101
        /**
102
         * @return Returns the initAngle.
103
         */
104
        public double getInitAngle() {
105
                return initAngle;
106
        }
107
        /**
108
         * @param initAngle The initAngle to set.
109
         */
110
        public void setInitAngle(double initAngle) {
111
                this.initAngle = initAngle;
112
        }
113
        /**
114
         * @return Returns the radius.
115
         */
116
        public double getRadius() {
117
                return radius;
118
        }
119
        /**
120
         * @param radius The radius to set.
121
         */
122
        public void setRadius(double radius) {
123
                this.radius = radius;
124
        }
125
    /**
126
     * @return Returns the extrusion.
127
     */
128
    public double[] getExtrusion() {
129
        return extrusion;
130
    }
131

    
132
        /**
133
         * @return Returns the thickness.
134
         */
135
        public double getThickness() {
136
                return thickness;
137
        }
138
        /**
139
         * @param thickness The thickness to set.
140
         */
141
        public void setThickness(double thickness) {
142
                this.thickness = thickness;
143
        }
144
        /**
145
         * @param extrusion The extrusion to set.
146
         */
147
        public void setExtrusion(double[] extrusion) {
148
                this.extrusion = extrusion;
149
        }
150

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

    
161
        }
162

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

    
170
        /* (non-Javadoc)
171
         * @see com.iver.cit.jdwglib.dwg.IDwg2FMap#toFMapGeometry()
172
         */
173
        public Geometry toFMapGeometry(boolean is3DFile) {
174
                GeometryFactory gFactory = GeometryManager.getInstance().getGeometryFactory();
175

    
176
                double[] center = getCenter();
177
                //FIXME: ¿qué hacer cuando llega un radio negativo?
178
                //        De momento, tomamos el valor absoluto del radio, pero
179
                //        ¿habría que modificar de alguna manera los angulos?
180
                double radius = Math.abs(getRadius());
181
                double angSt = getInitAngle();
182
                double angEnd = getEndAngle();
183
                double angExt = UtilFunctions.angleDistance(angSt, angEnd);
184
                if (is3DFile) {
185
                        return gFactory.createArc2DZ(new Point2D.Double(center[0], center[1]), radius, angSt, -angExt, center[2]);
186
                } else {
187
                        return gFactory.createArc(new Point2D.Double(center[0], center[1]), radius, angSt, -angExt );
188
                }
189
        }
190

    
191
        public String toString(){
192
                return "Arc";
193
        }
194

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

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

    
212
        public void transform2Block(double[] bPoint, Point2D insPoint, double[] scale, double rot,
213
                        List dwgObjectsWithoutBlocks, Map handleObjWithoutBlocks, DwgFile callBack) {
214
                //DwgArc transformedEntity = new DwgArc(getIndex());
215
                double[] center = this.getCenter();
216
                Point2D pointAux = new Point2D.Double(center[0] - bPoint[0], center[1] - bPoint[1]);
217
                double laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(rot) + (pointAux.getY()*scale[1])*(-1)*Math.sin(rot));
218
                double laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(rot) + (pointAux.getY()*scale[1])*Math.cos(rot));
219
                double laZ = center[2] * scale[2];
220
                double[] transformedCenter = new double[]{laX, laY, laZ};
221
                double radius = this.getRadius();
222
                double transformedRadius = radius * scale[0];
223
                double initAngle = this.getInitAngle();
224
                double endAngle = this.getEndAngle();
225
                double transformedInitAngle = initAngle + rot;
226
                if (transformedInitAngle<0) {
227
                    transformedInitAngle = transformedInitAngle + (2*Math.PI);
228
                } else if (transformedInitAngle>(2*Math.PI)) {
229
                    transformedInitAngle = transformedInitAngle - (2*Math.PI);
230
                }
231
                double transformedEndAngle = endAngle + rot;
232
                if (transformedEndAngle<0) {
233
                    transformedEndAngle = transformedEndAngle + (2*Math.PI);
234
                } else if (transformedEndAngle>(2*Math.PI)) {
235
                    transformedEndAngle = transformedEndAngle - (2*Math.PI);
236
                }
237
                DwgArc transformedEntity = (DwgArc) this.clone();
238
                transformedEntity.setCenter(transformedCenter);
239
                transformedEntity.setRadius(transformedRadius);
240
                transformedEntity.setInitAngle(transformedInitAngle);
241
                transformedEntity.setEndAngle(transformedEndAngle);
242
                transformedEntity.setHandle(this.getHandle());
243

    
244
                dwgObjectsWithoutBlocks.add(transformedEntity);
245
                handleObjWithoutBlocks.put(new Integer(transformedEntity.getHandle().getOffset()), transformedEntity);
246

    
247
//                setCenter(transformedCenter);
248
//                setRadius(transformedRadius);
249
//                setInitAngle(transformedInitAngle);
250
//                setEndAngle(transformedEndAngle);
251
//                dwgObjectsWithoutBlocks.add(this);
252
        }
253
        /* (non-Javadoc)
254
         * @see java.lang.Object#clone()
255
         */
256
public Object clone(){
257
                DwgArc obj = new DwgArc(index);
258
                this.fill(obj);
259
                return obj;
260
        }
261

    
262
        protected void fill(DwgObject obj){
263
                super.fill(obj);
264
                DwgArc myObj = (DwgArc)obj;
265

    
266
                myObj.setCenter(center);
267
                myObj.setEndAngle(endAngle);
268
                myObj.setExtrusion(extrusion);
269
                myObj.setInitAngle(initAngle);
270
                myObj.setRadius(radius);
271
                myObj.setThickness(thickness);
272

    
273
        }
274

    
275
}