Statistics
| Revision:

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

History | View | Annotate | Download (7.96 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.util.FMapUtil;
51
import com.iver.cit.jdwglib.util.GisModelCurveCalculator;
52

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

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

    
262
}