Statistics
| Revision:

root / trunk / libraries / libDwg / src / com / iver / cit / jdwglib / dwg / objects / DwgEllipse.java @ 10356

History | View | Annotate | Download (7.84 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.List;
39
import java.util.Map;
40

    
41
import com.iver.cit.gvsig.fmap.core.FPolyline2D;
42
import com.iver.cit.gvsig.fmap.core.FShape;
43
import com.iver.cit.jdwglib.dwg.DwgFile;
44
import com.iver.cit.jdwglib.dwg.DwgObject;
45
import com.iver.cit.jdwglib.dwg.IDwg2FMap;
46
import com.iver.cit.jdwglib.dwg.IDwg3DTestable;
47
import com.iver.cit.jdwglib.dwg.IDwgBlockMember;
48
import com.iver.cit.jdwglib.util.FMapUtil;
49
import com.iver.cit.jdwglib.util.GisModelCurveCalculator;
50

    
51
/**
52
 * The DwgEllipse class represents a DWG Ellipse
53
 * 
54
 * @author jmorell
55
 */
56
public class DwgEllipse extends DwgObject 
57
        implements IDwg3DTestable, IDwg2FMap, IDwgBlockMember{
58
        public DwgEllipse(int index) {
59
                super(index);
60
                // TODO Auto-generated constructor stub
61
        }
62
        private double[] center;
63
        private double[] majorAxisVector;
64
        private double[] extrusion;
65
        private double axisRatio;
66
        private double initAngle;
67
        private double endAngle;
68
        
69
    /**
70
     * @return Returns the axisRatio.
71
     */
72
    public double getAxisRatio() {
73
        return axisRatio;
74
    }
75
    /**
76
     * @param axisRatio The axisRatio to set.
77
     */
78
    public void setAxisRatio(double axisRatio) {
79
        this.axisRatio = axisRatio;
80
    }
81
    /**
82
     * @return Returns the center.
83
     */
84
    public double[] getCenter() {
85
        return center;
86
    }
87
    /**
88
     * @param center The center to set.
89
     */
90
    public void setCenter(double[] center) {
91
        this.center = center;
92
    }
93
    /**
94
     * @return Returns the endAngle.
95
     */
96
    public double getEndAngle() {
97
        return endAngle;
98
    }
99
    /**
100
     * @param endAngle The endAngle to set.
101
     */
102
    public void setEndAngle(double endAngle) {
103
        this.endAngle = endAngle;
104
    }
105
    /**
106
     * @return Returns the initAngle.
107
     */
108
    public double getInitAngle() {
109
        return initAngle;
110
    }
111
    /**
112
     * @param initAngle The initAngle to set.
113
     */
114
    public void setInitAngle(double initAngle) {
115
        this.initAngle = initAngle;
116
    }
117
    /**
118
     * @return Returns the majorAxisVector.
119
     */
120
    public double[] getMajorAxisVector() {
121
        return majorAxisVector;
122
    }
123
    /**
124
     * @param majorAxisVector The majorAxisVector to set.
125
     */
126
    public void setMajorAxisVector(double[] majorAxisVector) {
127
        this.majorAxisVector = majorAxisVector;
128
    }
129
    /**
130
     * @return Returns the extrusion.
131
     */
132
    public double[] getExtrusion() {
133
        return extrusion;
134
    }
135
        /**
136
         * @param extrusion The extrusion to set.
137
         */
138
        public void setExtrusion(double[] extrusion) {
139
                this.extrusion = extrusion;
140
        }
141
        /* (non-Javadoc)
142
         * @see com.iver.cit.jdwglib.dwg.IDwg3DTestable#has3DData()
143
         */
144
        public boolean has3DData() {
145
                return (getCenter()[2] !=0.0);
146
        }
147
        /* (non-Javadoc)
148
         * @see com.iver.cit.jdwglib.dwg.IDwg3DTestable#getZ()
149
         */
150
        public double getZ() {
151
                return getCenter()[2];
152
        }
153
        /* (non-Javadoc)
154
         * @see com.iver.cit.jdwglib.dwg.IDwg2FMap#toFMapGeometry(boolean)
155
         */
156
        public FShape toFMapGeometry(boolean is3DFile) {
157
                FPolyline2D arcc;
158
                double[] c = getCenter();
159
                Point2D center = new Point2D.Double(c[0], c[1]);
160
                double[] majorAxisVector = getMajorAxisVector();
161
                Point2D mav = new Point2D.Double(majorAxisVector[0],
162
                                majorAxisVector[1]);
163
                double axisRatio = getAxisRatio();
164
                double initAngle = Math.toDegrees(getInitAngle());
165
                double endAngle = Math.toDegrees(getEndAngle());
166
                Point2D[] arc = GisModelCurveCalculator
167
                                .calculateGisModelEllipse(center, mav, axisRatio,
168
                                                initAngle, endAngle);
169
                if (is3DFile) {
170
                        double[][] arc3D = new double[arc.length][3];
171
                        for (int j = 0; j < arc.length; j++) {
172
                                arc3D[j][0] = arc[j].getX();
173
                                arc3D[j][1] = arc[j].getY();
174
                                arc3D[j][2] = c[2];
175
                        }
176
                        arcc = FMapUtil.points3DToFPolyline3D(arc3D);
177
                } else {
178
                        arcc = FMapUtil.points2DToFPolyline2D(arc);
179
                }
180
                return arcc;
181
        }
182
        
183
        /* (non-Javadoc)
184
         * @see com.iver.cit.jdwglib.dwg.IDwg2FMap#toFMapString(boolean)
185
         */
186
        public String toFMapString(boolean is3DFile) {
187
                if(is3DFile)
188
                        return "FPolyline3D";
189
                else
190
                        return "FPolyline2D";
191
        }
192
        
193
        public String toString(){
194
                return "Ellipse";
195
        }
196
        public void transform2Block(double[] bPoint, Point2D insPoint, 
197
                        double[] scale, double rot, 
198
                        List dwgObjectsWithoutBlocks, 
199
                        Map handleObjWithoutBlocks,
200
                        DwgFile callBack) {
201
                DwgEllipse transformedEntity = null;
202
                double[] center = this.getCenter();
203
                Point2D pointAux = new Point2D.Double(center[0] - bPoint[0], center[1] - bPoint[1]);
204
                double laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(rot) + (pointAux.getY()*scale[1])*(-1)*Math.sin(rot));
205
                double laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(rot) + (pointAux.getY()*scale[1])*Math.cos(rot));
206
                double laZ = center[2] * scale[2];
207
                double[] transformedCenter = new double[]{laX, laY, laZ};
208
                double[] majorAxisVector = this.getMajorAxisVector();
209
                double[] transformedMajorAxisVector = new double[]{majorAxisVector[0] * scale[0], majorAxisVector[1] * scale[1], majorAxisVector[2] * scale[2]};
210
                //TODO: Rotar un ?ngulo rot el vector majorAxisVector fijado en
211
                // center.
212
                double axisRatio = this.getAxisRatio();
213
                double transformedAxisRatio = axisRatio;
214
                double initAngle = this.getInitAngle();
215
                double endAngle = this.getEndAngle();
216
        double transformedInitAngle = initAngle + rot;
217
        if (transformedInitAngle<0) {
218
            transformedInitAngle = transformedInitAngle + (2*Math.PI);
219
        } else if (transformedInitAngle>(2*Math.PI)) {
220
            transformedInitAngle = transformedInitAngle - (2*Math.PI);
221
        }
222
        double transformedEndAngle = endAngle + rot;
223
        if (transformedEndAngle<0) {
224
            transformedEndAngle = transformedEndAngle + (2*Math.PI);
225
        } else if (transformedEndAngle>(2*Math.PI)) {
226
            transformedEndAngle = transformedEndAngle - (2*Math.PI);
227
        }
228
                transformedEntity = (DwgEllipse)this.clone();
229
                transformedEntity.setCenter(transformedCenter);
230
                transformedEntity.setMajorAxisVector(transformedMajorAxisVector);
231
                transformedEntity.setAxisRatio(transformedAxisRatio);
232
                transformedEntity.setInitAngle(transformedInitAngle);
233
                transformedEntity.setEndAngle(transformedEndAngle);
234
                dwgObjectsWithoutBlocks.add(transformedEntity);
235
                handleObjWithoutBlocks.put(new Integer(transformedEntity.getHandle().getOffset()), transformedEntity);
236
//                dwgObjectsWithoutBlocks.add(this);
237
        }
238
        /* (non-Javadoc)
239
         * @see java.lang.Object#clone()
240
         */
241
        public Object clone(){
242
                DwgEllipse obj = new DwgEllipse(index);
243
                this.fill(obj);
244
                return obj;
245
        }
246
        
247
        protected void fill(DwgObject obj){
248
                super.fill(obj);
249
                DwgEllipse myObj = (DwgEllipse)obj;
250

    
251
                myObj.setAxisRatio(axisRatio);
252
                myObj.setCenter(center);
253
                myObj.setEndAngle(endAngle);
254
                myObj.setExtrusion(extrusion);
255
                myObj.setInitAngle(initAngle);
256
                myObj.setMajorAxisVector(majorAxisVector);
257
                
258
        }
259

    
260
}