svn-gvsig-desktop / branches / v02_desarrollo / libraries / libCq CMS for java.old / src / org / cresques / px / dxf / DxfArc.java @ 1607
History | View | Annotate | Download (5.21 KB)
1 |
/*
|
---|---|
2 |
* Created on 09-may-2004
|
3 |
*
|
4 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es>
|
5 |
*/
|
6 |
package org.cresques.px.dxf; |
7 |
|
8 |
import java.awt.Color; |
9 |
import java.awt.Graphics2D; |
10 |
import java.awt.geom.GeneralPath; |
11 |
import java.awt.geom.Point2D; |
12 |
|
13 |
import org.cresques.cts.ICoordTrans; |
14 |
import org.cresques.cts.IProjection; |
15 |
import org.cresques.geo.ViewPortData; |
16 |
import org.cresques.io.DxfGroup; |
17 |
import org.cresques.px.Extent; |
18 |
|
19 |
/**
|
20 |
* Entidad TEXT de AutoCAD
|
21 |
* jmorell: Definici?n de atributos para arcos necesaria para el piloto de CAD y
|
22 |
* implementaci?n de su escritura en formato DXF2000.
|
23 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es>* @author administrador
|
24 |
*/
|
25 |
public class DxfArc extends DxfEntity { |
26 |
final static Color baseColor = new Color(69, 106, 121); |
27 |
//Vector points = null;
|
28 |
Point2D [] pts; |
29 |
GeneralPath gp = null; |
30 |
boolean closed = false; |
31 |
private Point2D centralPoint; |
32 |
private Point2D init; |
33 |
private Point2D end; |
34 |
private Point2D center; |
35 |
private double radius; |
36 |
private double initAngle; |
37 |
private double endAngle; |
38 |
|
39 |
public DxfArc(IProjection proj, DxfLayer layer, Point2D[] pts) { |
40 |
super(proj, layer);
|
41 |
this.pts = pts;
|
42 |
extent = new Extent();
|
43 |
for (int i=0; i<pts.length; i++) { |
44 |
extent.add(pts[i]); |
45 |
} |
46 |
} |
47 |
|
48 |
private Color color = baseColor; //Color(255,214,132,255); |
49 |
|
50 |
public Color c() {return color;} |
51 |
public Color c(Color color) {this.color = color; return color;} |
52 |
|
53 |
public void reProject(ICoordTrans rp) { |
54 |
Point2D [] savePts = pts; |
55 |
|
56 |
pts = new Point2D[savePts.length]; |
57 |
extent = new Extent();
|
58 |
Point2D ptDest = null; |
59 |
for (int i=0; i<savePts.length; i++) { |
60 |
ptDest = rp.getPDest().createPoint(0.0,0.0); |
61 |
ptDest = rp.convert((Point2D) savePts[i], ptDest);
|
62 |
this.pts[i] = ptDest;
|
63 |
extent.add(ptDest); |
64 |
} |
65 |
setProjection(rp.getPDest()); |
66 |
} |
67 |
|
68 |
public void draw(Graphics2D g, ViewPortData vp) { |
69 |
//System.out.println("Va a pintar un arc");
|
70 |
|
71 |
Color color = null; |
72 |
|
73 |
if (dxfColor == AcadColor.BYLAYER)
|
74 |
//g.setColor(layer.getColor());
|
75 |
color = layer.getColor(); |
76 |
else
|
77 |
color = AcadColor.getColor(dxfColor); |
78 |
//g.setColor(AcadColor.getColor(dxfColor));
|
79 |
newGP(vp); |
80 |
if (closed) {
|
81 |
g.setColor(new Color(color.getRed(), color.getBlue(), color.getGreen(), 0x80)); |
82 |
g.fill(gp); |
83 |
} |
84 |
g.setColor(color); |
85 |
g.draw(gp); |
86 |
} |
87 |
|
88 |
private void newGP(ViewPortData vp) { |
89 |
//if (gp != null) return;
|
90 |
gp = new GeneralPath(); |
91 |
Point2D pt0 = null, pt=null, pt1=null; |
92 |
Point2D.Double ptTmp = new Point2D.Double(0.0, 0.0); |
93 |
System.out.println("pts.length = " + pts.length); |
94 |
for (int i=0; i<pts.length; i++) { |
95 |
pt1 = (Point2D)pts[i];
|
96 |
vp.mat.transform(pt1, ptTmp); |
97 |
if (pt0 == null) { |
98 |
pt0 = ptTmp; |
99 |
gp.moveTo((float)ptTmp.getX(), (float)ptTmp.getY()); |
100 |
} else {
|
101 |
gp.lineTo((float)ptTmp.getX(), (float)ptTmp.getY()); |
102 |
} |
103 |
} |
104 |
if (closed) {
|
105 |
gp.closePath(); |
106 |
} |
107 |
} |
108 |
|
109 |
/**
|
110 |
* 050223, jmorell: Escritura de arcos en un fichero DXF2000.
|
111 |
*/
|
112 |
public String toDxfString() { |
113 |
StringBuffer sb = null; |
114 |
sb = new StringBuffer( DxfGroup.toString(0, "ARC") ); |
115 |
sb.append( DxfGroup.toString(5, getHandle()) );
|
116 |
sb.append( DxfGroup.toString(100, "AcDbEntity") ); |
117 |
sb.append( DxfGroup.toString(8, layer.getName()) );
|
118 |
sb.append( DxfGroup.toString(62, dxfColor) );
|
119 |
sb.append( DxfGroup.toString(100, "AcDbCircle") ); |
120 |
sb.append( DxfGroup.toString(10, getCenter().getX(), 6)); |
121 |
sb.append( DxfGroup.toString(20, getCenter().getY(), 6) ); |
122 |
sb.append( DxfGroup.toString(40, getRadius(), 6) ); |
123 |
sb.append( DxfGroup.toString(100, "AcDbArc") ); |
124 |
sb.append( DxfGroup.toString(50, getInitAngle(), 6) ); |
125 |
sb.append( DxfGroup.toString(51, getEndAngle(), 6) ); |
126 |
return sb.toString();
|
127 |
} |
128 |
/**
|
129 |
* @return
|
130 |
*/
|
131 |
public Point2D[] getPts() { |
132 |
return pts;
|
133 |
} |
134 |
|
135 |
/**
|
136 |
* @return
|
137 |
*/
|
138 |
/*public GeneralPath getGeneralPath(ViewPort vp) {
|
139 |
newGP(vp);
|
140 |
return (GeneralPath) gp.clone();
|
141 |
}*/
|
142 |
|
143 |
/**
|
144 |
* @return Returns the center.
|
145 |
*/
|
146 |
public Point2D getCenter() { |
147 |
return center;
|
148 |
} |
149 |
/**
|
150 |
* @param center The center to set.
|
151 |
*/
|
152 |
public void setCenter(Point2D center) { |
153 |
this.center = center;
|
154 |
} |
155 |
/**
|
156 |
* @return Returns the end.
|
157 |
*/
|
158 |
public Point2D getEnd() { |
159 |
return end;
|
160 |
} |
161 |
/**
|
162 |
* @param end The end to set.
|
163 |
*/
|
164 |
public void setEnd(Point2D end) { |
165 |
this.end = end;
|
166 |
} |
167 |
/**
|
168 |
* @return Returns the init.
|
169 |
*/
|
170 |
public Point2D getInit() { |
171 |
return init;
|
172 |
} |
173 |
/**
|
174 |
* @param init The init to set.
|
175 |
*/
|
176 |
public void setInit(Point2D init) { |
177 |
this.init = init;
|
178 |
} |
179 |
/**
|
180 |
* @return Returns the centralPoint.
|
181 |
*/
|
182 |
public Point2D getCentralPoint() { |
183 |
return centralPoint;
|
184 |
} |
185 |
/**
|
186 |
* @param centralPoint The centralPoint to set.
|
187 |
*/
|
188 |
public void setCentralPoint(Point2D centralPoint) { |
189 |
this.centralPoint = centralPoint;
|
190 |
} |
191 |
/**
|
192 |
* @return Returns the endAngle.
|
193 |
*/
|
194 |
public double getEndAngle() { |
195 |
return endAngle;
|
196 |
} |
197 |
/**
|
198 |
* @param endAngle The endAngle to set.
|
199 |
*/
|
200 |
public void setEndAngle(double endAngle) { |
201 |
this.endAngle = endAngle;
|
202 |
} |
203 |
/**
|
204 |
* @return Returns the initAngle.
|
205 |
*/
|
206 |
public double getInitAngle() { |
207 |
return initAngle;
|
208 |
} |
209 |
/**
|
210 |
* @param initAngle The initAngle to set.
|
211 |
*/
|
212 |
public void setInitAngle(double initAngle) { |
213 |
this.initAngle = initAngle;
|
214 |
} |
215 |
/**
|
216 |
* @return Returns the radius.
|
217 |
*/
|
218 |
public double getRadius() { |
219 |
return radius;
|
220 |
} |
221 |
/**
|
222 |
* @param radius The radius to set.
|
223 |
*/
|
224 |
public void setRadius(double radius) { |
225 |
this.radius = radius;
|
226 |
} |
227 |
} |