Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libDwg / src / com / iver / cit / jdwglib / dwg / objects / DwgCircle.java @ 11058

History | View | Annotate | Download (5.68 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.jdwglib.dwg.DwgFile;
42
import com.iver.cit.jdwglib.dwg.DwgObject;
43
import com.iver.cit.jdwglib.dwg.IDwg3DTestable;
44
import com.iver.cit.jdwglib.dwg.IDwgBlockMember;
45
import com.iver.cit.jdwglib.dwg.IDwgExtrusionable;
46
import com.iver.cit.jdwglib.util.AcadExtrusionCalculator;
47

    
48
/**
49
 * The DwgCircle class represents a DWG Circle
50
 * 
51
 * @author jmorell
52
 */
53
public class DwgCircle extends DwgObject
54
        implements IDwgExtrusionable, IDwg3DTestable,  IDwgBlockMember{
55
        
56
        private double[] center;
57
        private double radius;
58
        private double thickness;
59
        private double[] extrusion;
60
        
61
        
62
        public DwgCircle(int index) {
63
                super(index);
64
        }
65
        /**
66
         * @return Returns the center.
67
         */
68
        public double[] getCenter() {
69
                return center;
70
        }
71
        /**
72
         * @param center The center to set.
73
         */
74
        public void setCenter(double[] center) {
75
                this.center = center;
76
        }
77
        /**
78
         * @return Returns the radius.
79
         */
80
        public double getRadius() {
81
                return radius;
82
        }
83
        /**
84
         * @param radius The radius to set.
85
         */
86
        public void setRadius(double radius) {
87
                this.radius = radius;
88
        }
89
    /**
90
     * @return Returns the extrusion.
91
     */
92
    public double[] getExtrusion() {
93
        return extrusion;
94
    }
95
        /* (non-Javadoc)
96
         * @see java.lang.Object#clone()
97
         */
98
//        public Object clone() {
99
//                DwgCircle dwgCircle = new DwgCircle(index);
100
//                dwgCircle.setType(type);
101
//                dwgCircle.setHandle(handle);
102
//                dwgCircle.setVersion(version);
103
//                dwgCircle.setMode(mode);
104
//                dwgCircle.setLayerHandle(layerHandle);
105
//                dwgCircle.setColor(color);
106
//                dwgCircle.setNumReactors(numReactors);
107
//                dwgCircle.setNoLinks(noLinks);
108
//                dwgCircle.setLinetypeFlags(linetypeFlags);
109
//                dwgCircle.setPlotstyleFlags(plotstyleFlags);
110
//                dwgCircle.setSizeInBits(sizeInBits);
111
//                dwgCircle.setExtendedData(extendedData);
112
//                dwgCircle.setGraphicData(graphicData);
113
//                //dwgCircle.setInsideBlock(insideBlock);
114
//                dwgCircle.setCenter(center);
115
//                dwgCircle.setRadius(radius);
116
//                dwgCircle.setThickness(thickness);
117
//                dwgCircle.setExtrusion(extrusion);
118
//                return dwgCircle;
119
//        }
120
        /**
121
         * @return Returns the thickness.
122
         */
123
        public double getThickness() {
124
                return thickness;
125
        }
126
        /**
127
         * @param thickness The thickness to set.
128
         */
129
        public void setThickness(double thickness) {
130
                this.thickness = thickness;
131
        }
132
        /**
133
         * @param extrusion The extrusion to set.
134
         */
135
        public void setExtrusion(double[] extrusion) {
136
                this.extrusion = extrusion;
137
        }
138
        /* (non-Javadoc)
139
         * @see com.iver.cit.jdwglib.dwg.IDwgExtrusionable#applyExtrussion()
140
         */
141
        public void applyExtrussion() {
142
                 double[] circleCenter = getCenter();
143
         double[] circleExt = getExtrusion();
144
         circleCenter = AcadExtrusionCalculator.extrude2(circleCenter, circleExt);
145
         setCenter(circleCenter);
146
        }
147
        /* (non-Javadoc)
148
         * @see com.iver.cit.jdwglib.dwg.IDwg3DTestable#has3DData()
149
         */
150
        public boolean has3DData() {
151
                return (getCenter()[2]!= 0.0) ;
152
        }
153
        /* (non-Javadoc)
154
         * @see com.iver.cit.jdwglib.dwg.IDwg3DTestable#getZ()
155
         */
156
        public double getZ() {
157
                return getCenter()[2];
158
        }
159

    
160
        
161
        
162
        public String toString(){
163
                return "Circle";
164
        }
165
        public void transform2Block(double[] bPoint, Point2D insPoint, double[] scale, double rot, 
166
                        List dwgObjectsWithoutBlocks, Map handleObjWithoutBlocks, DwgFile callBack) {
167
                DwgCircle transformedEntity = null;
168
                double[] center = this.getCenter();
169
                Point2D pointAux = new Point2D.Double(center[0] - bPoint[0], center[1] - bPoint[1]);
170
                double laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(rot) + (pointAux.getY()*scale[1])*(-1)*Math.sin(rot));
171
                double laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(rot) + (pointAux.getY()*scale[1])*Math.cos(rot));
172
                double laZ = center[2] * scale[2];
173
                double[] transformedCenter = new double[]{laX, laY, laZ};
174
                double radius = this.getRadius();
175
                double transformedRadius = radius * scale[0];
176
                transformedEntity = (DwgCircle)this.clone();
177
                transformedEntity.setCenter(transformedCenter);
178
                transformedEntity.setRadius(transformedRadius);
179
                dwgObjectsWithoutBlocks.add(transformedEntity);
180
                handleObjWithoutBlocks.put(new Integer(transformedEntity.getHandle().getOffset()), transformedEntity);
181
//                setCenter(transformedCenter);
182
//                setRadius(transformedRadius);
183
//                dwgObjectsWithoutBlocks.add(this);
184
        }
185
        public Object clone(){
186
                DwgCircle obj = new DwgCircle(index);
187
                this.fill(obj);
188
                return obj;
189
        }
190
        
191
        protected void fill(DwgObject obj){
192
                super.fill(obj);
193
                DwgCircle myObj = (DwgCircle)obj;
194

    
195
                myObj.setCenter(center);
196
                myObj.setExtrusion(extrusion);
197
                myObj.setRadius(radius);
198
                myObj.setThickness(thickness);
199

    
200
        }
201

    
202
}