svn-gvsig-desktop / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / px / dxf / DxfCircle.java @ 2312
History | View | Annotate | Download (4.62 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 el piloto de CAD e implementaci?n de
|
40 |
* la escritura en formato DXF2000.
|
41 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es>* @author administrador
|
42 |
*/
|
43 |
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; |
68 |
|
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 |
}*/
|
149 |
|
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 |
} |
174 |
} |