root / trunk / libraries / libDwg / src / com / iver / cit / jdwglib / dwg / objects / DwgArc.java @ 10319
History | View | Annotate | Download (7.54 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.gvsig.fmap.core.FPolyline2D; |
42 |
import com.iver.cit.gvsig.fmap.core.FShape; |
43 |
import com.iver.cit.jdwglib.dwg.DwgFile; |
44 |
import com.iver.cit.jdwglib.dwg.DwgObject; |
45 |
import com.iver.cit.jdwglib.dwg.IDwg2FMap; |
46 |
import com.iver.cit.jdwglib.dwg.IDwg3DTestable; |
47 |
import com.iver.cit.jdwglib.dwg.IDwgBlockMember; |
48 |
import com.iver.cit.jdwglib.dwg.IDwgExtrusionable; |
49 |
import com.iver.cit.jdwglib.util.AcadExtrusionCalculator; |
50 |
import com.iver.cit.jdwglib.util.FMapUtil; |
51 |
import com.iver.cit.jdwglib.util.GisModelCurveCalculator; |
52 |
|
53 |
/**
|
54 |
* The DwgArc class represents a DWG Arc
|
55 |
*
|
56 |
* @author jmorell
|
57 |
*/
|
58 |
public class DwgArc extends DwgObject |
59 |
implements IDwgExtrusionable, IDwg3DTestable, IDwg2FMap, IDwgBlockMember {
|
60 |
|
61 |
private double[] center; |
62 |
private double radius; |
63 |
private double thickness; |
64 |
private double[] extrusion; |
65 |
private double initAngle; |
66 |
private double endAngle; |
67 |
|
68 |
public DwgArc(int index) { |
69 |
super(index);
|
70 |
} |
71 |
|
72 |
|
73 |
/**
|
74 |
* @return Returns the center.
|
75 |
*/
|
76 |
public double[] getCenter() { |
77 |
return center;
|
78 |
} |
79 |
/**
|
80 |
* @param center The center to set.
|
81 |
*/
|
82 |
public void setCenter(double[] center) { |
83 |
this.center = center;
|
84 |
} |
85 |
/**
|
86 |
* @return Returns the endAngle.
|
87 |
*/
|
88 |
public double getEndAngle() { |
89 |
return endAngle;
|
90 |
} |
91 |
/**
|
92 |
* @param endAngle The endAngle to set.
|
93 |
*/
|
94 |
public void setEndAngle(double endAngle) { |
95 |
this.endAngle = endAngle;
|
96 |
} |
97 |
/**
|
98 |
* @return Returns the initAngle.
|
99 |
*/
|
100 |
public double getInitAngle() { |
101 |
return initAngle;
|
102 |
} |
103 |
/**
|
104 |
* @param initAngle The initAngle to set.
|
105 |
*/
|
106 |
public void setInitAngle(double initAngle) { |
107 |
this.initAngle = initAngle;
|
108 |
} |
109 |
/**
|
110 |
* @return Returns the radius.
|
111 |
*/
|
112 |
public double getRadius() { |
113 |
return radius;
|
114 |
} |
115 |
/**
|
116 |
* @param radius The radius to set.
|
117 |
*/
|
118 |
public void setRadius(double radius) { |
119 |
this.radius = radius;
|
120 |
} |
121 |
/**
|
122 |
* @return Returns the extrusion.
|
123 |
*/
|
124 |
public double[] getExtrusion() { |
125 |
return extrusion;
|
126 |
} |
127 |
|
128 |
/**
|
129 |
* @return Returns the thickness.
|
130 |
*/
|
131 |
public double getThickness() { |
132 |
return thickness;
|
133 |
} |
134 |
/**
|
135 |
* @param thickness The thickness to set.
|
136 |
*/
|
137 |
public void setThickness(double thickness) { |
138 |
this.thickness = thickness;
|
139 |
} |
140 |
/**
|
141 |
* @param extrusion The extrusion to set.
|
142 |
*/
|
143 |
public void setExtrusion(double[] extrusion) { |
144 |
this.extrusion = extrusion;
|
145 |
} |
146 |
|
147 |
/* (non-Javadoc)
|
148 |
* @see com.iver.cit.jdwglib.dwg.IDwgExtrusionable#applyExtrussion()
|
149 |
*/
|
150 |
public void applyExtrussion() { |
151 |
double[] arcCenter = getCenter(); |
152 |
double[] arcExt = getExtrusion(); |
153 |
arcCenter = AcadExtrusionCalculator. |
154 |
extrude2(arcCenter, arcExt); |
155 |
setCenter(arcCenter); |
156 |
|
157 |
} |
158 |
|
159 |
/* (non-Javadoc)
|
160 |
* @see com.iver.cit.jdwglib.dwg.IDwg3DTestable#has3DData()
|
161 |
*/
|
162 |
public boolean has3DData() { |
163 |
return (getCenter()[2] != 0.0); |
164 |
} |
165 |
|
166 |
/* (non-Javadoc)
|
167 |
* @see com.iver.cit.jdwglib.dwg.IDwg2FMap#toFMapGeometry()
|
168 |
*/
|
169 |
public FShape toFMapGeometry(boolean is3DFile) { |
170 |
double[] c = getCenter(); |
171 |
Point2D center = new Point2D.Double(c[0], c[1]); |
172 |
double radius = getRadius();
|
173 |
double initAngle = Math.toDegrees(getInitAngle()); |
174 |
double endAngle = Math.toDegrees(getEndAngle()); |
175 |
Point2D[] arc = GisModelCurveCalculator.calculateGisModelArc( |
176 |
center, radius, initAngle, endAngle); |
177 |
FPolyline2D arcc; |
178 |
if (is3DFile) {
|
179 |
double[][] arc3D = new double[arc.length][3]; |
180 |
for (int j = 0; j < arc.length; j++) { |
181 |
arc3D[j][0] = arc[j].getX();
|
182 |
arc3D[j][1] = arc[j].getY();
|
183 |
arc3D[j][2] = c[2]; |
184 |
} |
185 |
arcc = FMapUtil.points3DToFPolyline3D(arc3D); |
186 |
|
187 |
} else {
|
188 |
arcc = FMapUtil.points2DToFPolyline2D(arc); |
189 |
} |
190 |
return arcc;
|
191 |
} |
192 |
|
193 |
public String toString(){ |
194 |
return "Arc"; |
195 |
} |
196 |
|
197 |
/* (non-Javadoc)
|
198 |
* @see com.iver.cit.jdwglib.dwg.IDwg2FMap#toFMapString()
|
199 |
*/
|
200 |
public String toFMapString(boolean is3dFile) { |
201 |
if(is3dFile)
|
202 |
return "FPolyline3D"; |
203 |
else
|
204 |
return "FPolyline2D"; |
205 |
} |
206 |
|
207 |
/* (non-Javadoc)
|
208 |
* @see com.iver.cit.jdwglib.dwg.IDwg3DTestable#getZ()
|
209 |
*/
|
210 |
public double getZ() { |
211 |
return getCenter()[2]; |
212 |
} |
213 |
|
214 |
public void transform2Block(double[] bPoint, Point2D insPoint, double[] scale, double rot, |
215 |
List dwgObjectsWithoutBlocks, Map handleObjWithoutBlocks, DwgFile callBack) { |
216 |
//DwgArc transformedEntity = new DwgArc(getIndex());
|
217 |
double[] center = this.getCenter(); |
218 |
Point2D pointAux = new Point2D.Double(center[0] - bPoint[0], center[1] - bPoint[1]); |
219 |
double laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(rot) + (pointAux.getY()*scale[1])*(-1)*Math.sin(rot)); |
220 |
double laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(rot) + (pointAux.getY()*scale[1])*Math.cos(rot)); |
221 |
double laZ = center[2] * scale[2]; |
222 |
double[] transformedCenter = new double[]{laX, laY, laZ}; |
223 |
double radius = this.getRadius(); |
224 |
double transformedRadius = radius * scale[0]; |
225 |
double initAngle = this.getInitAngle(); |
226 |
double endAngle = this.getEndAngle(); |
227 |
double transformedInitAngle = initAngle + rot;
|
228 |
if (transformedInitAngle<0) { |
229 |
transformedInitAngle = transformedInitAngle + (2*Math.PI); |
230 |
} else if (transformedInitAngle>(2*Math.PI)) { |
231 |
transformedInitAngle = transformedInitAngle - (2*Math.PI); |
232 |
} |
233 |
double transformedEndAngle = endAngle + rot;
|
234 |
if (transformedEndAngle<0) { |
235 |
transformedEndAngle = transformedEndAngle + (2*Math.PI); |
236 |
} else if (transformedEndAngle>(2*Math.PI)) { |
237 |
transformedEndAngle = transformedEndAngle - (2*Math.PI); |
238 |
} |
239 |
DwgArc transformedEntity = (DwgArc) this.clone();
|
240 |
transformedEntity.setCenter(transformedCenter); |
241 |
transformedEntity.setRadius(transformedRadius); |
242 |
transformedEntity.setInitAngle(transformedInitAngle); |
243 |
transformedEntity.setEndAngle(transformedEndAngle); |
244 |
transformedEntity.setHandle(this.getHandle());
|
245 |
|
246 |
|
247 |
|
248 |
|
249 |
|
250 |
|
251 |
dwgObjectsWithoutBlocks.add(transformedEntity); |
252 |
handleObjWithoutBlocks.put(new Integer(transformedEntity.getHandle().getOffset()), transformedEntity); |
253 |
|
254 |
// setCenter(transformedCenter);
|
255 |
// setRadius(transformedRadius);
|
256 |
// setInitAngle(transformedInitAngle);
|
257 |
// setEndAngle(transformedEndAngle);
|
258 |
// dwgObjectsWithoutBlocks.add(this);
|
259 |
} |
260 |
/* (non-Javadoc)
|
261 |
* @see java.lang.Object#clone()
|
262 |
*/
|
263 |
public Object clone(){ |
264 |
DwgArc obj = new DwgArc(index);
|
265 |
this.fill(obj);
|
266 |
return obj;
|
267 |
} |
268 |
|
269 |
protected void fill(DwgObject obj){ |
270 |
super.fill(obj);
|
271 |
DwgArc myObj = (DwgArc)obj; |
272 |
|
273 |
myObj.setCenter(center); |
274 |
myObj.setEndAngle(endAngle); |
275 |
myObj.setExtrusion(extrusion); |
276 |
myObj.setInitAngle(initAngle); |
277 |
myObj.setRadius(radius); |
278 |
myObj.setThickness(thickness); |
279 |
|
280 |
} |
281 |
|
282 |
} |