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