Revision 2669 branches/CqCMSDvp/libraries/libCq CMS for java.old/src/org/cresques/px/dxf/DxfArc.java
DxfArc.java | ||
---|---|---|
1 | 1 |
/* |
2 | 2 |
* Cresques Mapping Suite. Graphic Library for constructing mapping applications. |
3 |
* |
|
4 |
* Copyright (C) 2004-5. |
|
5 | 3 |
* |
4 |
* Copyright (C) 2004-5. |
|
5 |
* |
|
6 | 6 |
* This program is free software; you can redistribute it and/or |
7 | 7 |
* modify it under the terms of the GNU General Public License |
8 | 8 |
* as published by the Free Software Foundation; either version 2 |
... | ... | |
18 | 18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
19 | 19 |
* |
20 | 20 |
* For more information, contact: |
21 |
*
|
|
21 |
* |
|
22 | 22 |
* cresques@gmail.com |
23 | 23 |
*/ |
24 | 24 |
package org.cresques.px.dxf; |
25 | 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 | 26 |
import org.cresques.cts.ICoordTrans; |
32 | 27 |
import org.cresques.cts.IProjection; |
28 |
|
|
33 | 29 |
import org.cresques.geo.ViewPortData; |
30 |
|
|
34 | 31 |
import org.cresques.io.DxfGroup; |
32 |
|
|
35 | 33 |
import org.cresques.px.Extent; |
36 | 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 |
|
|
37 | 41 |
/** |
38 | 42 |
* Entidad TEXT de AutoCAD |
39 | 43 |
* jmorell: Definici?n de atributos para arcos necesaria para el piloto de CAD y |
... | ... | |
41 | 45 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es>* @author administrador |
42 | 46 |
*/ |
43 | 47 |
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; |
|
48 |
final static Color baseColor = new Color(69, 106, 121); |
|
56 | 49 |
|
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; |
|
50 |
//Vector points = null; |
|
51 |
Point2D[] pts; |
|
52 |
GeneralPath gp = null; |
|
53 |
boolean closed = false; |
|
54 |
private Point2D centralPoint; |
|
55 |
private Point2D init; |
|
56 |
private Point2D end; |
|
57 |
private Point2D center; |
|
58 |
private double radius; |
|
59 |
private double initAngle; |
|
60 |
private double endAngle; |
|
61 |
private Color color = baseColor; //Color(255,214,132,255); |
|
73 | 62 |
|
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 |
}*/ |
|
63 |
public DxfArc(IProjection proj, DxfLayer layer, Point2D[] pts) { |
|
64 |
super(proj, layer); |
|
65 |
this.pts = pts; |
|
66 |
extent = new Extent(); |
|
160 | 67 |
|
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 |
} |
|
68 |
for (int i = 0; i < pts.length; i++) { |
|
69 |
extent.add(pts[i]); |
|
70 |
} |
|
71 |
} |
|
72 |
|
|
73 |
public Color c() { |
|
74 |
return color; |
|
75 |
} |
|
76 |
|
|
77 |
public Color c(Color color) { |
|
78 |
this.color = color; |
|
79 |
|
|
80 |
return color; |
|
81 |
} |
|
82 |
|
|
83 |
public void reProject(ICoordTrans rp) { |
|
84 |
Point2D[] savePts = pts; |
|
85 |
|
|
86 |
pts = new Point2D[savePts.length]; |
|
87 |
extent = new Extent(); |
|
88 |
|
|
89 |
Point2D ptDest = null; |
|
90 |
|
|
91 |
for (int i = 0; i < savePts.length; i++) { |
|
92 |
ptDest = rp.getPDest().createPoint(0.0, 0.0); |
|
93 |
ptDest = rp.convert((Point2D) savePts[i], ptDest); |
|
94 |
this.pts[i] = ptDest; |
|
95 |
extent.add(ptDest); |
|
96 |
} |
|
97 |
|
|
98 |
setProjection(rp.getPDest()); |
|
99 |
} |
|
100 |
|
|
101 |
public void draw(Graphics2D g, ViewPortData vp) { |
|
102 |
//System.out.println("Va a pintar un arc"); |
|
103 |
Color color = null; |
|
104 |
|
|
105 |
if (dxfColor == AcadColor.BYLAYER) { |
|
106 |
//g.setColor(layer.getColor()); |
|
107 |
color = layer.getColor(); |
|
108 |
} else { |
|
109 |
color = AcadColor.getColor(dxfColor); |
|
110 |
} |
|
111 |
|
|
112 |
//g.setColor(AcadColor.getColor(dxfColor)); |
|
113 |
newGP(vp); |
|
114 |
|
|
115 |
if (closed) { |
|
116 |
g.setColor(new Color(color.getRed(), color.getBlue(), |
|
117 |
color.getGreen(), 0x80)); |
|
118 |
g.fill(gp); |
|
119 |
} |
|
120 |
|
|
121 |
g.setColor(color); |
|
122 |
g.draw(gp); |
|
123 |
} |
|
124 |
|
|
125 |
private void newGP(ViewPortData vp) { |
|
126 |
//if (gp != null) return; |
|
127 |
gp = new GeneralPath(); |
|
128 |
|
|
129 |
Point2D pt0 = null; |
|
130 |
Point2D pt = null; |
|
131 |
Point2D pt1 = null; |
|
132 |
Point2D.Double ptTmp = new Point2D.Double(0.0, 0.0); |
|
133 |
|
|
134 |
//System.out.println("pts.length = " + pts.length); |
|
135 |
for (int i = 0; i < pts.length; i++) { |
|
136 |
pt1 = (Point2D) pts[i]; |
|
137 |
vp.mat.transform(pt1, ptTmp); |
|
138 |
|
|
139 |
if (pt0 == null) { |
|
140 |
pt0 = ptTmp; |
|
141 |
gp.moveTo((float) ptTmp.getX(), (float) ptTmp.getY()); |
|
142 |
} else { |
|
143 |
gp.lineTo((float) ptTmp.getX(), (float) ptTmp.getY()); |
|
144 |
} |
|
145 |
} |
|
146 |
|
|
147 |
if (closed) { |
|
148 |
gp.closePath(); |
|
149 |
} |
|
150 |
} |
|
151 |
|
|
152 |
/** |
|
153 |
* 050223, jmorell: Escritura de arcos en un fichero DXF2000. |
|
154 |
*/ |
|
155 |
public String toDxfString() { |
|
156 |
StringBuffer sb = null; |
|
157 |
sb = new StringBuffer(DxfGroup.toString(0, "ARC")); |
|
158 |
sb.append(DxfGroup.toString(5, getHandle())); |
|
159 |
sb.append(DxfGroup.toString(100, "AcDbEntity")); |
|
160 |
sb.append(DxfGroup.toString(8, layer.getName())); |
|
161 |
sb.append(DxfGroup.toString(62, dxfColor)); |
|
162 |
sb.append(DxfGroup.toString(100, "AcDbCircle")); |
|
163 |
sb.append(DxfGroup.toString(10, getCenter().getX(), 6)); |
|
164 |
sb.append(DxfGroup.toString(20, getCenter().getY(), 6)); |
|
165 |
sb.append(DxfGroup.toString(40, getRadius(), 6)); |
|
166 |
sb.append(DxfGroup.toString(100, "AcDbArc")); |
|
167 |
sb.append(DxfGroup.toString(50, getInitAngle(), 6)); |
|
168 |
sb.append(DxfGroup.toString(51, getEndAngle(), 6)); |
|
169 |
|
|
170 |
return sb.toString(); |
|
171 |
} |
|
172 |
|
|
173 |
/** |
|
174 |
* @return |
|
175 |
*/ |
|
176 |
public Point2D[] getPts() { |
|
177 |
return pts; |
|
178 |
} |
|
179 |
|
|
180 |
/** |
|
181 |
* @return |
|
182 |
*/ |
|
183 |
|
|
184 |
/*public GeneralPath getGeneralPath(ViewPort vp) { |
|
185 |
newGP(vp); |
|
186 |
return (GeneralPath) gp.clone(); |
|
187 |
}*/ |
|
188 |
|
|
189 |
/** |
|
190 |
* @return Returns the center. |
|
191 |
*/ |
|
192 |
public Point2D getCenter() { |
|
193 |
return center; |
|
194 |
} |
|
195 |
|
|
196 |
/** |
|
197 |
* @param center The center to set. |
|
198 |
*/ |
|
199 |
public void setCenter(Point2D center) { |
|
200 |
this.center = center; |
|
201 |
} |
|
202 |
|
|
203 |
/** |
|
204 |
* @return Returns the end. |
|
205 |
*/ |
|
206 |
public Point2D getEnd() { |
|
207 |
return end; |
|
208 |
} |
|
209 |
|
|
210 |
/** |
|
211 |
* @param end The end to set. |
|
212 |
*/ |
|
213 |
public void setEnd(Point2D end) { |
|
214 |
this.end = end; |
|
215 |
} |
|
216 |
|
|
217 |
/** |
|
218 |
* @return Returns the init. |
|
219 |
*/ |
|
220 |
public Point2D getInit() { |
|
221 |
return init; |
|
222 |
} |
|
223 |
|
|
224 |
/** |
|
225 |
* @param init The init to set. |
|
226 |
*/ |
|
227 |
public void setInit(Point2D init) { |
|
228 |
this.init = init; |
|
229 |
} |
|
230 |
|
|
231 |
/** |
|
232 |
* @return Returns the centralPoint. |
|
233 |
*/ |
|
234 |
public Point2D getCentralPoint() { |
|
235 |
return centralPoint; |
|
236 |
} |
|
237 |
|
|
238 |
/** |
|
239 |
* @param centralPoint The centralPoint to set. |
|
240 |
*/ |
|
241 |
public void setCentralPoint(Point2D centralPoint) { |
|
242 |
this.centralPoint = centralPoint; |
|
243 |
} |
|
244 |
|
|
245 |
/** |
|
246 |
* @return Returns the endAngle. |
|
247 |
*/ |
|
248 |
public double getEndAngle() { |
|
249 |
return endAngle; |
|
250 |
} |
|
251 |
|
|
252 |
/** |
|
253 |
* @param endAngle The endAngle to set. |
|
254 |
*/ |
|
255 |
public void setEndAngle(double endAngle) { |
|
256 |
this.endAngle = endAngle; |
|
257 |
} |
|
258 |
|
|
259 |
/** |
|
260 |
* @return Returns the initAngle. |
|
261 |
*/ |
|
262 |
public double getInitAngle() { |
|
263 |
return initAngle; |
|
264 |
} |
|
265 |
|
|
266 |
/** |
|
267 |
* @param initAngle The initAngle to set. |
|
268 |
*/ |
|
269 |
public void setInitAngle(double initAngle) { |
|
270 |
this.initAngle = initAngle; |
|
271 |
} |
|
272 |
|
|
273 |
/** |
|
274 |
* @return Returns the radius. |
|
275 |
*/ |
|
276 |
public double getRadius() { |
|
277 |
return radius; |
|
278 |
} |
|
279 |
|
|
280 |
/** |
|
281 |
* @param radius The radius to set. |
|
282 |
*/ |
|
283 |
public void setRadius(double radius) { |
|
284 |
this.radius = radius; |
|
285 |
} |
|
245 | 286 |
} |
Also available in: Unified diff