root / trunk / libraries / libDwg / src / com / iver / cit / jdwglib / dwg / objects / DwgCircle.java @ 10632
History | View | Annotate | Download (6.85 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.dwg.IDwgExtrusionable; |
50 |
import com.iver.cit.jdwglib.util.AcadExtrusionCalculator; |
51 |
import com.iver.cit.jdwglib.util.FMapUtil; |
52 |
import com.iver.cit.jdwglib.util.GisModelCurveCalculator; |
53 |
|
54 |
/**
|
55 |
* The DwgCircle class represents a DWG Circle
|
56 |
*
|
57 |
* @author jmorell
|
58 |
*/
|
59 |
public class DwgCircle extends DwgObject |
60 |
implements IDwgExtrusionable, IDwg3DTestable, IDwg2FMap, IDwgBlockMember{
|
61 |
|
62 |
private double[] center; |
63 |
private double radius; |
64 |
private double thickness; |
65 |
private double[] extrusion; |
66 |
|
67 |
|
68 |
public DwgCircle(int index) { |
69 |
super(index);
|
70 |
} |
71 |
/**
|
72 |
* @return Returns the center.
|
73 |
*/
|
74 |
public double[] getCenter() { |
75 |
return center;
|
76 |
} |
77 |
/**
|
78 |
* @param center The center to set.
|
79 |
*/
|
80 |
public void setCenter(double[] center) { |
81 |
this.center = center;
|
82 |
} |
83 |
/**
|
84 |
* @return Returns the radius.
|
85 |
*/
|
86 |
public double getRadius() { |
87 |
return radius;
|
88 |
} |
89 |
/**
|
90 |
* @param radius The radius to set.
|
91 |
*/
|
92 |
public void setRadius(double radius) { |
93 |
this.radius = radius;
|
94 |
} |
95 |
/**
|
96 |
* @return Returns the extrusion.
|
97 |
*/
|
98 |
public double[] getExtrusion() { |
99 |
return extrusion;
|
100 |
} |
101 |
/* (non-Javadoc)
|
102 |
* @see java.lang.Object#clone()
|
103 |
*/
|
104 |
// public Object clone() {
|
105 |
// DwgCircle dwgCircle = new DwgCircle(index);
|
106 |
// dwgCircle.setType(type);
|
107 |
// dwgCircle.setHandle(handle);
|
108 |
// dwgCircle.setVersion(version);
|
109 |
// dwgCircle.setMode(mode);
|
110 |
// dwgCircle.setLayerHandle(layerHandle);
|
111 |
// dwgCircle.setColor(color);
|
112 |
// dwgCircle.setNumReactors(numReactors);
|
113 |
// dwgCircle.setNoLinks(noLinks);
|
114 |
// dwgCircle.setLinetypeFlags(linetypeFlags);
|
115 |
// dwgCircle.setPlotstyleFlags(plotstyleFlags);
|
116 |
// dwgCircle.setSizeInBits(sizeInBits);
|
117 |
// dwgCircle.setExtendedData(extendedData);
|
118 |
// dwgCircle.setGraphicData(graphicData);
|
119 |
// //dwgCircle.setInsideBlock(insideBlock);
|
120 |
// dwgCircle.setCenter(center);
|
121 |
// dwgCircle.setRadius(radius);
|
122 |
// dwgCircle.setThickness(thickness);
|
123 |
// dwgCircle.setExtrusion(extrusion);
|
124 |
// return dwgCircle;
|
125 |
// }
|
126 |
/**
|
127 |
* @return Returns the thickness.
|
128 |
*/
|
129 |
public double getThickness() { |
130 |
return thickness;
|
131 |
} |
132 |
/**
|
133 |
* @param thickness The thickness to set.
|
134 |
*/
|
135 |
public void setThickness(double thickness) { |
136 |
this.thickness = thickness;
|
137 |
} |
138 |
/**
|
139 |
* @param extrusion The extrusion to set.
|
140 |
*/
|
141 |
public void setExtrusion(double[] extrusion) { |
142 |
this.extrusion = extrusion;
|
143 |
} |
144 |
/* (non-Javadoc)
|
145 |
* @see com.iver.cit.jdwglib.dwg.IDwgExtrusionable#applyExtrussion()
|
146 |
*/
|
147 |
public void applyExtrussion() { |
148 |
double[] circleCenter = getCenter(); |
149 |
double[] circleExt = getExtrusion(); |
150 |
circleCenter = AcadExtrusionCalculator.extrude2(circleCenter, circleExt); |
151 |
setCenter(circleCenter); |
152 |
} |
153 |
/* (non-Javadoc)
|
154 |
* @see com.iver.cit.jdwglib.dwg.IDwg3DTestable#has3DData()
|
155 |
*/
|
156 |
public boolean has3DData() { |
157 |
return (getCenter()[2]!= 0.0) ; |
158 |
} |
159 |
/* (non-Javadoc)
|
160 |
* @see com.iver.cit.jdwglib.dwg.IDwg3DTestable#getZ()
|
161 |
*/
|
162 |
public double getZ() { |
163 |
return getCenter()[2]; |
164 |
} |
165 |
/* (non-Javadoc)
|
166 |
* @see com.iver.cit.jdwglib.dwg.IDwg2FMap#toFMapGeometry(boolean)
|
167 |
*/
|
168 |
public FShape toFMapGeometry(boolean is3DFile) { |
169 |
FPolyline2D arcc; |
170 |
double[] c = getCenter(); |
171 |
Point2D center = new Point2D.Double(c[0], c[1]); |
172 |
double radius = getRadius();
|
173 |
List arc = GisModelCurveCalculator
|
174 |
.calculateGisModelCircle(center, radius); |
175 |
if (is3DFile) {
|
176 |
List arc3D = new ArrayList(); |
177 |
for (int j = 0; j < arc.size(); j++) { |
178 |
double[] pt2d = (double[]) arc.get(j); |
179 |
double[] pt3d = new double[]{ pt2d[0], pt2d[1], c[2] }; |
180 |
arc3D.add(pt3d); |
181 |
} |
182 |
arcc = FMapUtil.points3DToFPolyline3D(arc3D); |
183 |
} else {
|
184 |
arcc = FMapUtil.points2DToFPolyline2D(arc); |
185 |
} |
186 |
|
187 |
return arcc;
|
188 |
} |
189 |
/* (non-Javadoc)
|
190 |
* @see com.iver.cit.jdwglib.dwg.IDwg2FMap#toFMapString(boolean)
|
191 |
*/
|
192 |
public String toFMapString(boolean is3DFile) { |
193 |
if(is3DFile)
|
194 |
return "FPolyline3D"; |
195 |
else
|
196 |
return "FPolyline2D"; |
197 |
} |
198 |
|
199 |
public String toString(){ |
200 |
return "Circle"; |
201 |
} |
202 |
public void transform2Block(double[] bPoint, Point2D insPoint, double[] scale, double rot, |
203 |
List dwgObjectsWithoutBlocks, Map handleObjWithoutBlocks, DwgFile callBack) { |
204 |
DwgCircle transformedEntity = null;
|
205 |
double[] center = this.getCenter(); |
206 |
Point2D pointAux = new Point2D.Double(center[0] - bPoint[0], center[1] - bPoint[1]); |
207 |
double laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(rot) + (pointAux.getY()*scale[1])*(-1)*Math.sin(rot)); |
208 |
double laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(rot) + (pointAux.getY()*scale[1])*Math.cos(rot)); |
209 |
double laZ = center[2] * scale[2]; |
210 |
double[] transformedCenter = new double[]{laX, laY, laZ}; |
211 |
double radius = this.getRadius(); |
212 |
double transformedRadius = radius * scale[0]; |
213 |
transformedEntity = (DwgCircle)this.clone();
|
214 |
transformedEntity.setCenter(transformedCenter); |
215 |
transformedEntity.setRadius(transformedRadius); |
216 |
dwgObjectsWithoutBlocks.add(transformedEntity); |
217 |
handleObjWithoutBlocks.put(new Integer(transformedEntity.getHandle().getOffset()), transformedEntity); |
218 |
// setCenter(transformedCenter);
|
219 |
// setRadius(transformedRadius);
|
220 |
// dwgObjectsWithoutBlocks.add(this);
|
221 |
} |
222 |
public Object clone(){ |
223 |
DwgCircle obj = new DwgCircle(index);
|
224 |
this.fill(obj);
|
225 |
return obj;
|
226 |
} |
227 |
|
228 |
protected void fill(DwgObject obj){ |
229 |
super.fill(obj);
|
230 |
DwgCircle myObj = (DwgCircle)obj; |
231 |
|
232 |
myObj.setCenter(center); |
233 |
myObj.setExtrusion(extrusion); |
234 |
myObj.setRadius(radius); |
235 |
myObj.setThickness(thickness); |
236 |
|
237 |
} |
238 |
|
239 |
} |