svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libDwg / src / org / gvsig / dwg / lib / objects / DwgCircle.java @ 29001
History | View | Annotate | Download (7.12 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 org.gvsig.dwg.lib.objects; |
36 |
|
37 |
import java.awt.geom.Point2D; |
38 |
import java.util.List; |
39 |
import java.util.Map; |
40 |
|
41 |
import org.gvsig.dwg.lib.DwgFile; |
42 |
import org.gvsig.dwg.lib.DwgObject; |
43 |
import org.gvsig.dwg.lib.IDwg2FMap; |
44 |
import org.gvsig.dwg.lib.IDwg3DTestable; |
45 |
import org.gvsig.dwg.lib.IDwgBlockMember; |
46 |
import org.gvsig.dwg.lib.IDwgExtrusionable; |
47 |
import org.gvsig.dwg.lib.util.AcadExtrusionCalculator; |
48 |
import org.gvsig.fmap.geom.Geometry; |
49 |
import org.gvsig.fmap.geom.GeometryLocator; |
50 |
import org.gvsig.fmap.geom.GeometryManager; |
51 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
52 |
import org.gvsig.fmap.geom.primitive.Circle; |
53 |
import org.gvsig.fmap.geom.primitive.Point; |
54 |
|
55 |
|
56 |
/**
|
57 |
* The DwgCircle class represents a DWG Circle
|
58 |
*
|
59 |
* @author jmorell
|
60 |
*/
|
61 |
public class DwgCircle extends DwgObject |
62 |
implements IDwgExtrusionable, IDwg3DTestable, IDwg2FMap, IDwgBlockMember{
|
63 |
|
64 |
private double[] center; |
65 |
private double radius; |
66 |
private double thickness; |
67 |
private double[] extrusion; |
68 |
|
69 |
|
70 |
public DwgCircle(int index) { |
71 |
super(index);
|
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 radius.
|
87 |
*/
|
88 |
public double getRadius() { |
89 |
return radius;
|
90 |
} |
91 |
/**
|
92 |
* @param radius The radius to set.
|
93 |
*/
|
94 |
public void setRadius(double radius) { |
95 |
this.radius = radius;
|
96 |
} |
97 |
/**
|
98 |
* @return Returns the extrusion.
|
99 |
*/
|
100 |
public double[] getExtrusion() { |
101 |
return extrusion;
|
102 |
} |
103 |
/* (non-Javadoc)
|
104 |
* @see java.lang.Object#clone()
|
105 |
*/
|
106 |
// public Object clone() {
|
107 |
// DwgCircle dwgCircle = new DwgCircle(index);
|
108 |
// dwgCircle.setType(type);
|
109 |
// dwgCircle.setHandle(handle);
|
110 |
// dwgCircle.setVersion(version);
|
111 |
// dwgCircle.setMode(mode);
|
112 |
// dwgCircle.setLayerHandle(layerHandle);
|
113 |
// dwgCircle.setColor(color);
|
114 |
// dwgCircle.setNumReactors(numReactors);
|
115 |
// dwgCircle.setNoLinks(noLinks);
|
116 |
// dwgCircle.setLinetypeFlags(linetypeFlags);
|
117 |
// dwgCircle.setPlotstyleFlags(plotstyleFlags);
|
118 |
// dwgCircle.setSizeInBits(sizeInBits);
|
119 |
// dwgCircle.setExtendedData(extendedData);
|
120 |
// dwgCircle.setGraphicData(graphicData);
|
121 |
// //dwgCircle.setInsideBlock(insideBlock);
|
122 |
// dwgCircle.setCenter(center);
|
123 |
// dwgCircle.setRadius(radius);
|
124 |
// dwgCircle.setThickness(thickness);
|
125 |
// dwgCircle.setExtrusion(extrusion);
|
126 |
// return dwgCircle;
|
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 |
/* (non-Javadoc)
|
147 |
* @see com.iver.cit.jdwglib.dwg.IDwgExtrusionable#applyExtrussion()
|
148 |
*/
|
149 |
public void applyExtrussion() { |
150 |
double[] circleCenter = getCenter(); |
151 |
double[] circleExt = getExtrusion(); |
152 |
circleCenter = AcadExtrusionCalculator.extrude2(circleCenter, circleExt); |
153 |
setCenter(circleCenter); |
154 |
} |
155 |
/* (non-Javadoc)
|
156 |
* @see com.iver.cit.jdwglib.dwg.IDwg3DTestable#has3DData()
|
157 |
*/
|
158 |
public boolean has3DData() { |
159 |
return (getCenter()[2]!= 0.0) ; |
160 |
} |
161 |
/* (non-Javadoc)
|
162 |
* @see com.iver.cit.jdwglib.dwg.IDwg3DTestable#getZ()
|
163 |
*/
|
164 |
public double getZ() { |
165 |
return getCenter()[2]; |
166 |
} |
167 |
/* (non-Javadoc)
|
168 |
* @see com.iver.cit.jdwglib.dwg.IDwg2FMap#toFMapGeometry(boolean)
|
169 |
*/
|
170 |
public Geometry toFMapGeometry(boolean is3DFile) throws CreateGeometryException { |
171 |
GeometryManager gMan = GeometryLocator.getGeometryManager(); |
172 |
double[] c = getCenter(); |
173 |
//FIXME: ¿qué hacer cuando llega un radio negativo?
|
174 |
// De momento, tomamos el valor absoluto del radio, pero
|
175 |
// ¿habría que modificar de alguna manera los angulos?
|
176 |
double radius = Math.abs(getRadius()); |
177 |
Circle circle = (Circle) gMan.create(getGeometryType(), |
178 |
getGeometrySubType(is3DFile)); |
179 |
Point center = (Point) gMan.create(Geometry.TYPES.POINT, |
180 |
getGeometrySubType(is3DFile)); |
181 |
center.setCoordinates(c); |
182 |
circle.setPoints(center, radius); |
183 |
return circle;
|
184 |
} |
185 |
|
186 |
/* (non-Javadoc)
|
187 |
* @see com.iver.cit.jdwglib.dwg.IDwg2FMap#toFMapString(boolean)
|
188 |
*/
|
189 |
public String toFMapString(boolean is3DFile) { |
190 |
if(is3DFile) {
|
191 |
return "FPolyline3D"; |
192 |
} else {
|
193 |
return "FPolyline2D"; |
194 |
} |
195 |
} |
196 |
|
197 |
public String toString(){ |
198 |
return "Circle"; |
199 |
} |
200 |
public void transform2Block(double[] bPoint, Point2D insPoint, double[] scale, double rot, |
201 |
List dwgObjectsWithoutBlocks, Map handleObjWithoutBlocks, DwgFile callBack) { |
202 |
DwgCircle transformedEntity = null;
|
203 |
double[] center = this.getCenter(); |
204 |
Point2D pointAux = new Point2D.Double(center[0] - bPoint[0], center[1] - bPoint[1]); |
205 |
double laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(rot) + (pointAux.getY()*scale[1])*(-1)*Math.sin(rot)); |
206 |
double laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(rot) + (pointAux.getY()*scale[1])*Math.cos(rot)); |
207 |
double laZ = center[2] * scale[2]; |
208 |
double[] transformedCenter = new double[]{laX, laY, laZ}; |
209 |
double radius = this.getRadius(); |
210 |
double transformedRadius = radius * scale[0]; |
211 |
transformedEntity = (DwgCircle)this.clone();
|
212 |
transformedEntity.setCenter(transformedCenter); |
213 |
transformedEntity.setRadius(transformedRadius); |
214 |
dwgObjectsWithoutBlocks.add(transformedEntity); |
215 |
handleObjWithoutBlocks.put(new Integer(transformedEntity.getHandle().getOffset()), transformedEntity); |
216 |
// setCenter(transformedCenter);
|
217 |
// setRadius(transformedRadius);
|
218 |
// dwgObjectsWithoutBlocks.add(this);
|
219 |
} |
220 |
public Object clone(){ |
221 |
DwgCircle obj = new DwgCircle(index);
|
222 |
this.fill(obj);
|
223 |
return obj;
|
224 |
} |
225 |
|
226 |
protected void fill(DwgObject obj){ |
227 |
super.fill(obj);
|
228 |
DwgCircle myObj = (DwgCircle)obj; |
229 |
|
230 |
myObj.setCenter(center); |
231 |
myObj.setExtrusion(extrusion); |
232 |
myObj.setRadius(radius); |
233 |
myObj.setThickness(thickness); |
234 |
|
235 |
} |
236 |
public int getGeometrySubType(boolean is3DFile) { |
237 |
if (is3DFile) {
|
238 |
return Geometry.SUBTYPES.GEOM3D;
|
239 |
} else {
|
240 |
return Geometry.SUBTYPES.GEOM2D;
|
241 |
} |
242 |
} |
243 |
|
244 |
public int getGeometryType() { |
245 |
return Geometry.TYPES.CIRCLE;
|
246 |
} |
247 |
|
248 |
} |