root / branches / v2_0_0_prep / libraries / libDXF / src / org / gvsig / dxf / px / dxf / DxfArc.java @ 29630
History | View | Annotate | Download (7.88 KB)
1 |
/*
|
---|---|
2 |
* Cresques Mapping Suite. Graphic Library for constructing mapping applications.
|
3 |
*
|
4 |
* Copyright (C) 2004-5.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
19 |
*
|
20 |
* For more information, contact:
|
21 |
*
|
22 |
* cresques@gmail.com
|
23 |
*/
|
24 |
package org.gvsig.dxf.px.dxf; |
25 |
|
26 |
import java.awt.Color; |
27 |
import java.awt.Graphics2D; |
28 |
import java.awt.geom.GeneralPath; |
29 |
import java.awt.geom.Point2D; |
30 |
|
31 |
import org.cresques.cts.ICoordTrans; |
32 |
import org.cresques.cts.IProjection; |
33 |
import org.cresques.geo.ViewPortData; |
34 |
import org.cresques.px.Extent; |
35 |
import org.gvsig.dxf.io.DxfGroup; |
36 |
|
37 |
|
38 |
/**
|
39 |
* Entidad ARC de un fichero DXF.
|
40 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es>
|
41 |
* @author jmorell
|
42 |
*/
|
43 |
public class DxfArc extends DxfEntity { |
44 |
final static Color baseColor = new Color(69, 106, 121); |
45 |
|
46 |
//Vector points = null;
|
47 |
Point2D[] pts; |
48 |
GeneralPath gp = null; |
49 |
boolean closed = false; |
50 |
private Point2D centralPoint; |
51 |
private Point2D init; |
52 |
private Point2D end; |
53 |
private Point2D center; |
54 |
private double radius; |
55 |
private double initAngle; |
56 |
private double endAngle; |
57 |
private Color color = baseColor; //Color(255,214,132,255); |
58 |
|
59 |
/**
|
60 |
* Constructor de DxfArc.
|
61 |
* @param proj, proyecci?n cartogr?fica en la que se encuentra el DxfArc.
|
62 |
* @param layer, capa del DXF en la que se encuentra el DxfArc.
|
63 |
* @param pts, puntos 2D que componen el DxfArc.
|
64 |
*/
|
65 |
public DxfArc(IProjection proj, DxfLayer layer, Point2D[] pts) { |
66 |
super(proj, layer);
|
67 |
this.pts = pts;
|
68 |
extent = new Extent();
|
69 |
|
70 |
for (int i = 0; i < pts.length; i++) { |
71 |
extent.add(pts[i]); |
72 |
} |
73 |
} |
74 |
|
75 |
/**
|
76 |
* Devuelve el color del DxfArc.
|
77 |
* @return Color
|
78 |
*/
|
79 |
public Color c() { |
80 |
return color;
|
81 |
} |
82 |
|
83 |
/**
|
84 |
* Establece el color del DxfArc.
|
85 |
* @param color
|
86 |
* @return Color
|
87 |
*/
|
88 |
public Color c(Color color) { |
89 |
this.color = color;
|
90 |
|
91 |
return color;
|
92 |
} |
93 |
|
94 |
/**
|
95 |
* Permite reproyectar un DxfArc dado un conjunto de coordenadas de transformaci?n.
|
96 |
* @param rp, coordenadas de transformaci?n.
|
97 |
*/
|
98 |
public void reProject(ICoordTrans rp) { |
99 |
Point2D[] savePts = pts; |
100 |
|
101 |
pts = new Point2D[savePts.length]; |
102 |
extent = new Extent();
|
103 |
|
104 |
Point2D ptDest = null; |
105 |
|
106 |
for (int i = 0; i < savePts.length; i++) { |
107 |
ptDest = rp.getPDest().createPoint(0.0, 0.0); |
108 |
ptDest = rp.convert((Point2D) savePts[i], ptDest);
|
109 |
this.pts[i] = ptDest;
|
110 |
extent.add(ptDest); |
111 |
} |
112 |
|
113 |
setProjection(rp.getPDest()); |
114 |
} |
115 |
|
116 |
/**
|
117 |
* Permite dibujar un DxfArc.
|
118 |
*/
|
119 |
public void draw(Graphics2D g, ViewPortData vp) { |
120 |
//System.out.println("Va a pintar un arc");
|
121 |
Color color = null; |
122 |
|
123 |
if (dxfColor == AcadColor.BYLAYER) {
|
124 |
//g.setColor(layer.getColor());
|
125 |
color = layer.getColor(); |
126 |
} else {
|
127 |
color = AcadColor.getColor(dxfColor); |
128 |
} |
129 |
|
130 |
//g.setColor(AcadColor.getColor(dxfColor));
|
131 |
newGP(vp); |
132 |
|
133 |
if (closed) {
|
134 |
g.setColor(new Color(color.getRed(), color.getBlue(), |
135 |
color.getGreen(), 0x80));
|
136 |
g.fill(gp); |
137 |
} |
138 |
|
139 |
g.setColor(color); |
140 |
g.draw(gp); |
141 |
} |
142 |
|
143 |
/**
|
144 |
* Permite generar un GeneralPath partiendo del array de Point2D que conforma el
|
145 |
* DxfArc.
|
146 |
* @param vp
|
147 |
*/
|
148 |
private void newGP(ViewPortData vp) { |
149 |
//if (gp != null) return;
|
150 |
gp = new GeneralPath(); |
151 |
|
152 |
Point2D pt0 = null; |
153 |
Point2D pt = null; |
154 |
Point2D pt1 = null; |
155 |
Point2D.Double ptTmp = new Point2D.Double(0.0, 0.0); |
156 |
|
157 |
//System.out.println("pts.length = " + pts.length);
|
158 |
for (int i = 0; i < pts.length; i++) { |
159 |
pt1 = (Point2D) pts[i];
|
160 |
vp.mat.transform(pt1, ptTmp); |
161 |
|
162 |
if (pt0 == null) { |
163 |
pt0 = ptTmp; |
164 |
gp.moveTo((float) ptTmp.getX(), (float) ptTmp.getY()); |
165 |
} else {
|
166 |
gp.lineTo((float) ptTmp.getX(), (float) ptTmp.getY()); |
167 |
} |
168 |
} |
169 |
|
170 |
if (closed) {
|
171 |
gp.closePath(); |
172 |
} |
173 |
} |
174 |
|
175 |
/**
|
176 |
* Permite la escritura de entidades DxfArc en un fichero DXF2000.
|
177 |
* @return String, la cadena que se escribir? en el fichero con la informaci?n
|
178 |
* del DxfArc.
|
179 |
*/
|
180 |
public String toDxfString() { |
181 |
StringBuffer sb = null; |
182 |
sb = new StringBuffer(DxfGroup.toString(0, "ARC")); |
183 |
sb.append(DxfGroup.toString(5, getHandle()));
|
184 |
sb.append(DxfGroup.toString(100, "AcDbEntity")); |
185 |
sb.append(DxfGroup.toString(8, layer.getName()));
|
186 |
sb.append(DxfGroup.toString(62, dxfColor));
|
187 |
sb.append(DxfGroup.toString(100, "AcDbCircle")); |
188 |
sb.append(DxfGroup.toString(10, getCenter().getX(), 6)); |
189 |
sb.append(DxfGroup.toString(20, getCenter().getY(), 6)); |
190 |
sb.append(DxfGroup.toString(40, getRadius(), 6)); |
191 |
sb.append(DxfGroup.toString(100, "AcDbArc")); |
192 |
sb.append(DxfGroup.toString(50, getInitAngle(), 6)); |
193 |
sb.append(DxfGroup.toString(51, getEndAngle(), 6)); |
194 |
|
195 |
return sb.toString();
|
196 |
} |
197 |
|
198 |
/**
|
199 |
* Devuelve el array de puntos que conforman el DxfArc.
|
200 |
* @return Point2D[], puntos del DxfArc.
|
201 |
*/
|
202 |
public Point2D[] getPts() { |
203 |
return pts;
|
204 |
} |
205 |
|
206 |
/**
|
207 |
* Devuelve el GeneralPath qie conforma el DxfArc.
|
208 |
* @return GeneralPath del DxfArc.
|
209 |
*/
|
210 |
/*public GeneralPath getGeneralPath(ViewPort vp) {
|
211 |
newGP(vp);
|
212 |
return (GeneralPath) gp.clone();
|
213 |
}*/
|
214 |
|
215 |
/**
|
216 |
* @return Returns the center.
|
217 |
*/
|
218 |
public Point2D getCenter() { |
219 |
return center;
|
220 |
} |
221 |
|
222 |
/**
|
223 |
* @param center The center to set.
|
224 |
*/
|
225 |
public void setCenter(Point2D center) { |
226 |
this.center = center;
|
227 |
} |
228 |
|
229 |
/**
|
230 |
* @return Returns the end.
|
231 |
*/
|
232 |
public Point2D getEnd() { |
233 |
return end;
|
234 |
} |
235 |
|
236 |
/**
|
237 |
* @param end The end to set.
|
238 |
*/
|
239 |
public void setEnd(Point2D end) { |
240 |
this.end = end;
|
241 |
} |
242 |
|
243 |
/**
|
244 |
* @return Returns the init.
|
245 |
*/
|
246 |
public Point2D getInit() { |
247 |
return init;
|
248 |
} |
249 |
|
250 |
/**
|
251 |
* @param init The init to set.
|
252 |
*/
|
253 |
public void setInit(Point2D init) { |
254 |
this.init = init;
|
255 |
} |
256 |
|
257 |
/**
|
258 |
* @return Returns the centralPoint.
|
259 |
*/
|
260 |
public Point2D getCentralPoint() { |
261 |
return centralPoint;
|
262 |
} |
263 |
|
264 |
/**
|
265 |
* @param centralPoint The centralPoint to set.
|
266 |
*/
|
267 |
public void setCentralPoint(Point2D centralPoint) { |
268 |
this.centralPoint = centralPoint;
|
269 |
} |
270 |
|
271 |
/**
|
272 |
* @return Returns the endAngle.
|
273 |
*/
|
274 |
public double getEndAngle() { |
275 |
return endAngle;
|
276 |
} |
277 |
|
278 |
/**
|
279 |
* @param endAngle The endAngle to set.
|
280 |
*/
|
281 |
public void setEndAngle(double endAngle) { |
282 |
this.endAngle = endAngle;
|
283 |
} |
284 |
|
285 |
/**
|
286 |
* @return Returns the initAngle.
|
287 |
*/
|
288 |
public double getInitAngle() { |
289 |
return initAngle;
|
290 |
} |
291 |
|
292 |
/**
|
293 |
* @param initAngle The initAngle to set.
|
294 |
*/
|
295 |
public void setInitAngle(double initAngle) { |
296 |
this.initAngle = initAngle;
|
297 |
} |
298 |
|
299 |
/**
|
300 |
* @return Returns the radius.
|
301 |
*/
|
302 |
public double getRadius() { |
303 |
return radius;
|
304 |
} |
305 |
|
306 |
/**
|
307 |
* @param radius The radius to set.
|
308 |
*/
|
309 |
public void setRadius(double radius) { |
310 |
this.radius = radius;
|
311 |
} |
312 |
} |