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