Statistics
| Revision:

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

History | View | Annotate | Download (7.87 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.FShape;
44
import com.iver.cit.jdwglib.dwg.DwgFile;
45
import com.iver.cit.jdwglib.dwg.DwgObject;
46
import com.iver.cit.jdwglib.dwg.IDwg2FMap;
47
import com.iver.cit.jdwglib.dwg.IDwg3DTestable;
48
import com.iver.cit.jdwglib.dwg.IDwgBlockMember;
49
import com.iver.cit.jdwglib.util.FMapUtil;
50
import com.iver.cit.jdwglib.util.GisModelCurveCalculator;
51

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

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

    
261
}