Statistics
| Revision:

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

History | View | Annotate | Download (8.03 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

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

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