Revision 2669 branches/CqCMSDvp/libraries/libCq CMS for java.old/src/org/cresques/px/dxf/DxfCircle.java
DxfCircle.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 el piloto de CAD e implementaci?n de |
... | ... | |
41 | 45 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es>* @author administrador |
42 | 46 |
*/ |
43 | 47 |
public class DxfCircle 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 = true; |
|
49 |
private Point2D center; |
|
50 |
private double radius; |
|
51 |
|
|
52 |
public DxfCircle(IProjection proj, DxfLayer layer, Point2D[] pts) { |
|
53 |
super(proj, layer); |
|
54 |
this.pts = pts; |
|
55 |
extent = new Extent(); |
|
56 |
for (int i=0; i<pts.length; i++) { |
|
57 |
extent.add(pts[i]); |
|
58 |
} |
|
59 |
} |
|
60 |
|
|
61 |
private Color color = baseColor; //Color(255,214,132,255); |
|
62 |
|
|
63 |
public Color c() {return color;} |
|
64 |
public Color c(Color color) {this.color = color; return color;} |
|
65 |
|
|
66 |
public void reProject(ICoordTrans rp) { |
|
67 |
Point2D [] savePts = pts; |
|
48 |
final static Color baseColor = new Color(69, 106, 121); |
|
68 | 49 |
|
69 |
pts = new Point2D[savePts.length]; |
|
70 |
extent = new Extent(); |
|
71 |
Point2D ptDest = null; |
|
72 |
for (int i=0; i<savePts.length; i++) { |
|
73 |
ptDest = rp.getPDest().createPoint(0.0,0.0); |
|
74 |
ptDest = rp.convert((Point2D) savePts[i], ptDest); |
|
75 |
this.pts[i] = ptDest; |
|
76 |
extent.add(ptDest); |
|
77 |
} |
|
78 |
setProjection(rp.getPDest()); |
|
79 |
} |
|
80 |
|
|
81 |
public void draw(Graphics2D g, ViewPortData vp) { |
|
82 |
//System.out.println("Va a pintar un circle"); |
|
83 |
Color color = null; |
|
84 |
if (dxfColor == AcadColor.BYLAYER) |
|
85 |
//g.setColor(layer.getColor()); |
|
86 |
color = layer.getColor(); |
|
87 |
else |
|
88 |
//g.setColor(AcadColor.getColor(dxfColor)); |
|
89 |
color = AcadColor.getColor(dxfColor); |
|
90 |
newGP(vp); |
|
91 |
if (closed) { |
|
92 |
g.setColor(new Color(color.getRed(), color.getBlue(), color.getGreen(), 0x80)); |
|
93 |
g.fill(gp); |
|
94 |
} |
|
95 |
g.setColor(color); |
|
96 |
g.draw(gp); |
|
97 |
} |
|
98 |
|
|
99 |
private void newGP(ViewPortData vp) { |
|
100 |
//if (gp != null) return; |
|
101 |
gp = new GeneralPath(); |
|
102 |
Point2D pt0 = null, pt=null, pt1=null; |
|
103 |
Point2D.Double ptTmp = new Point2D.Double(0.0, 0.0); |
|
104 |
//System.out.println("pts.length = " + pts.length); |
|
105 |
for (int i=0; i<pts.length; i++) { |
|
106 |
pt1 = (Point2D)pts[i]; |
|
107 |
vp.mat.transform(pt1, ptTmp); |
|
108 |
if (pt0 == null) { |
|
109 |
pt0 = ptTmp; |
|
110 |
gp.moveTo((float)ptTmp.getX(), (float)ptTmp.getY()); |
|
111 |
} else { |
|
112 |
gp.lineTo((float)ptTmp.getX(), (float)ptTmp.getY()); |
|
113 |
} |
|
114 |
} |
|
115 |
if (closed) { |
|
116 |
gp.closePath(); |
|
117 |
} |
|
118 |
} |
|
119 |
/** |
|
120 |
* Escritura de c?rculos en un DXF2000. |
|
121 |
*/ |
|
122 |
public String toDxfString() { |
|
123 |
StringBuffer sb = null; |
|
124 |
sb = new StringBuffer( DxfGroup.toString(0, "CIRCLE") ); |
|
125 |
sb.append( DxfGroup.toString(5, getHandle()) ); |
|
126 |
sb.append( DxfGroup.toString(100, "AcDbEntity") ); |
|
127 |
sb.append( DxfGroup.toString(8, layer.getName()) ); |
|
128 |
sb.append( DxfGroup.toString(62, dxfColor) ); |
|
129 |
sb.append( DxfGroup.toString(100, "AcDbCircle") ); |
|
130 |
sb.append( DxfGroup.toString(10, getCenter().getX(), 6)); |
|
131 |
sb.append( DxfGroup.toString(20, getCenter().getY(), 6) ); |
|
132 |
sb.append( DxfGroup.toString(40, getRadius(), 6) ); |
|
133 |
return sb.toString(); |
|
134 |
} |
|
135 |
/** |
|
136 |
* @return |
|
137 |
*/ |
|
138 |
public Point2D[] getPts() { |
|
139 |
return pts; |
|
140 |
} |
|
141 |
|
|
142 |
/** |
|
143 |
* @return |
|
144 |
*/ |
|
145 |
/*public GeneralPath getGeneralPath(ViewPort vp) { |
|
146 |
newGP(vp); |
|
147 |
return (GeneralPath) gp.clone(); |
|
148 |
}*/ |
|
50 |
//Vector points = null; |
|
51 |
Point2D[] pts; |
|
52 |
GeneralPath gp = null; |
|
53 |
boolean closed = true; |
|
54 |
private Point2D center; |
|
55 |
private double radius; |
|
56 |
private Color color = baseColor; //Color(255,214,132,255); |
|
149 | 57 |
|
150 |
/** |
|
151 |
* @return Returns the radius. |
|
152 |
*/ |
|
153 |
public double getRadius() { |
|
154 |
return radius; |
|
155 |
} |
|
156 |
/** |
|
157 |
* @param radius The radius to set. |
|
158 |
*/ |
|
159 |
public void setRadius(double radius) { |
|
160 |
this.radius = radius; |
|
161 |
} |
|
162 |
/** |
|
163 |
* @return Returns the center. |
|
164 |
*/ |
|
165 |
public Point2D getCenter() { |
|
166 |
return center; |
|
167 |
} |
|
168 |
/** |
|
169 |
* @param center The center to set. |
|
170 |
*/ |
|
171 |
public void setCenter(Point2D center) { |
|
172 |
this.center = center; |
|
173 |
} |
|
58 |
public DxfCircle(IProjection proj, DxfLayer layer, Point2D[] pts) { |
|
59 |
super(proj, layer); |
|
60 |
this.pts = pts; |
|
61 |
extent = new Extent(); |
|
62 |
|
|
63 |
for (int i = 0; i < pts.length; i++) { |
|
64 |
extent.add(pts[i]); |
|
65 |
} |
|
66 |
} |
|
67 |
|
|
68 |
public Color c() { |
|
69 |
return color; |
|
70 |
} |
|
71 |
|
|
72 |
public Color c(Color color) { |
|
73 |
this.color = color; |
|
74 |
|
|
75 |
return color; |
|
76 |
} |
|
77 |
|
|
78 |
public void reProject(ICoordTrans rp) { |
|
79 |
Point2D[] savePts = pts; |
|
80 |
|
|
81 |
pts = new Point2D[savePts.length]; |
|
82 |
extent = new Extent(); |
|
83 |
|
|
84 |
Point2D ptDest = null; |
|
85 |
|
|
86 |
for (int i = 0; i < savePts.length; i++) { |
|
87 |
ptDest = rp.getPDest().createPoint(0.0, 0.0); |
|
88 |
ptDest = rp.convert((Point2D) savePts[i], ptDest); |
|
89 |
this.pts[i] = ptDest; |
|
90 |
extent.add(ptDest); |
|
91 |
} |
|
92 |
|
|
93 |
setProjection(rp.getPDest()); |
|
94 |
} |
|
95 |
|
|
96 |
public void draw(Graphics2D g, ViewPortData vp) { |
|
97 |
//System.out.println("Va a pintar un circle"); |
|
98 |
Color color = null; |
|
99 |
|
|
100 |
if (dxfColor == AcadColor.BYLAYER) { |
|
101 |
//g.setColor(layer.getColor()); |
|
102 |
color = layer.getColor(); |
|
103 |
} else { |
|
104 |
//g.setColor(AcadColor.getColor(dxfColor)); |
|
105 |
color = AcadColor.getColor(dxfColor); |
|
106 |
} |
|
107 |
|
|
108 |
newGP(vp); |
|
109 |
|
|
110 |
if (closed) { |
|
111 |
g.setColor(new Color(color.getRed(), color.getBlue(), |
|
112 |
color.getGreen(), 0x80)); |
|
113 |
g.fill(gp); |
|
114 |
} |
|
115 |
|
|
116 |
g.setColor(color); |
|
117 |
g.draw(gp); |
|
118 |
} |
|
119 |
|
|
120 |
private void newGP(ViewPortData vp) { |
|
121 |
//if (gp != null) return; |
|
122 |
gp = new GeneralPath(); |
|
123 |
|
|
124 |
Point2D pt0 = null; |
|
125 |
Point2D pt = null; |
|
126 |
Point2D pt1 = null; |
|
127 |
Point2D.Double ptTmp = new Point2D.Double(0.0, 0.0); |
|
128 |
|
|
129 |
//System.out.println("pts.length = " + pts.length); |
|
130 |
for (int i = 0; i < pts.length; i++) { |
|
131 |
pt1 = (Point2D) pts[i]; |
|
132 |
vp.mat.transform(pt1, ptTmp); |
|
133 |
|
|
134 |
if (pt0 == null) { |
|
135 |
pt0 = ptTmp; |
|
136 |
gp.moveTo((float) ptTmp.getX(), (float) ptTmp.getY()); |
|
137 |
} else { |
|
138 |
gp.lineTo((float) ptTmp.getX(), (float) ptTmp.getY()); |
|
139 |
} |
|
140 |
} |
|
141 |
|
|
142 |
if (closed) { |
|
143 |
gp.closePath(); |
|
144 |
} |
|
145 |
} |
|
146 |
|
|
147 |
/** |
|
148 |
* Escritura de c?rculos en un DXF2000. |
|
149 |
*/ |
|
150 |
public String toDxfString() { |
|
151 |
StringBuffer sb = null; |
|
152 |
sb = new StringBuffer(DxfGroup.toString(0, "CIRCLE")); |
|
153 |
sb.append(DxfGroup.toString(5, getHandle())); |
|
154 |
sb.append(DxfGroup.toString(100, "AcDbEntity")); |
|
155 |
sb.append(DxfGroup.toString(8, layer.getName())); |
|
156 |
sb.append(DxfGroup.toString(62, dxfColor)); |
|
157 |
sb.append(DxfGroup.toString(100, "AcDbCircle")); |
|
158 |
sb.append(DxfGroup.toString(10, getCenter().getX(), 6)); |
|
159 |
sb.append(DxfGroup.toString(20, getCenter().getY(), 6)); |
|
160 |
sb.append(DxfGroup.toString(40, getRadius(), 6)); |
|
161 |
|
|
162 |
return sb.toString(); |
|
163 |
} |
|
164 |
|
|
165 |
/** |
|
166 |
* @return |
|
167 |
*/ |
|
168 |
public Point2D[] getPts() { |
|
169 |
return pts; |
|
170 |
} |
|
171 |
|
|
172 |
/** |
|
173 |
* @return |
|
174 |
*/ |
|
175 |
|
|
176 |
/*public GeneralPath getGeneralPath(ViewPort vp) { |
|
177 |
newGP(vp); |
|
178 |
return (GeneralPath) gp.clone(); |
|
179 |
}*/ |
|
180 |
|
|
181 |
/** |
|
182 |
* @return Returns the radius. |
|
183 |
*/ |
|
184 |
public double getRadius() { |
|
185 |
return radius; |
|
186 |
} |
|
187 |
|
|
188 |
/** |
|
189 |
* @param radius The radius to set. |
|
190 |
*/ |
|
191 |
public void setRadius(double radius) { |
|
192 |
this.radius = radius; |
|
193 |
} |
|
194 |
|
|
195 |
/** |
|
196 |
* @return Returns the center. |
|
197 |
*/ |
|
198 |
public Point2D getCenter() { |
|
199 |
return center; |
|
200 |
} |
|
201 |
|
|
202 |
/** |
|
203 |
* @param center The center to set. |
|
204 |
*/ |
|
205 |
public void setCenter(Point2D center) { |
|
206 |
this.center = center; |
|
207 |
} |
|
174 | 208 |
} |
Also available in: Unified diff