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