svn-gvsig-desktop / tags / v1_1_Build_1001 / libraries / libCq CMS for java.old / src / org / cresques / px / dxf / DxfCircle.java @ 11984
History | View | Annotate | Download (6.41 KB)
1 | 35 | jmorell | /*
|
---|---|---|---|
2 | 2809 | nacho | * Cresques Mapping Suite. Graphic Library for constructing mapping applications.
|
3 | 35 | jmorell | *
|
4 | 2809 | nacho | * 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 | 35 | jmorell | */
|
24 | package org.cresques.px.dxf; |
||
25 | |||
26 | 2809 | nacho | import org.cresques.cts.ICoordTrans; |
27 | import org.cresques.cts.IProjection; |
||
28 | |||
29 | import org.cresques.geo.ViewPortData; |
||
30 | |||
31 | import org.cresques.io.DxfGroup; |
||
32 | |||
33 | import org.cresques.px.Extent; |
||
34 | |||
35 | 37 | jmorell | import java.awt.Color; |
36 | 35 | jmorell | import java.awt.Graphics2D; |
37 | 37 | jmorell | import java.awt.geom.GeneralPath; |
38 | 35 | jmorell | import java.awt.geom.Point2D; |
39 | |||
40 | |||
41 | /**
|
||
42 | 2809 | nacho | * Entidad CIRCLE de un fichero DXF.
|
43 | * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
|
||
44 | * @author jmorell
|
||
45 | 35 | jmorell | */
|
46 | public class DxfCircle extends DxfEntity { |
||
47 | 2809 | nacho | final static Color baseColor = new Color(69, 106, 121); |
48 | 35 | jmorell | |
49 | 2809 | nacho | //Vector points = null;
|
50 | Point2D[] pts; |
||
51 | GeneralPath gp = null; |
||
52 | boolean closed = true; |
||
53 | private Point2D center; |
||
54 | private double radius; |
||
55 | private Color color = baseColor; //Color(255,214,132,255); |
||
56 | |||
57 | /**
|
||
58 | * Constructor de DxfCircle.
|
||
59 | * @param proj, proyecci?n cartogr?fica en la que se encuentra el DxfCircle.
|
||
60 | * @param layer, capa del DXF en la que se encuentra el DxfCircle.
|
||
61 | * @param pts, puntos 2D que componen el DxfCircle.
|
||
62 | */
|
||
63 | public DxfCircle(IProjection proj, DxfLayer layer, Point2D[] pts) { |
||
64 | super(proj, layer);
|
||
65 | this.pts = pts;
|
||
66 | extent = new Extent();
|
||
67 | 37 | jmorell | |
68 | 2809 | nacho | for (int i = 0; i < pts.length; i++) { |
69 | extent.add(pts[i]); |
||
70 | } |
||
71 | } |
||
72 | |||
73 | /**
|
||
74 | * Devuelve el color del DxfCircle.
|
||
75 | * @return Color
|
||
76 | */
|
||
77 | public Color c() { |
||
78 | return color;
|
||
79 | } |
||
80 | |||
81 | /**
|
||
82 | * Establece el color del DxfCircle.
|
||
83 | * @param color
|
||
84 | * @return Color
|
||
85 | */
|
||
86 | public Color c(Color color) { |
||
87 | this.color = color;
|
||
88 | |||
89 | return color;
|
||
90 | } |
||
91 | |||
92 | /**
|
||
93 | * Permite reproyectar un DxfCircle dado un conjunto de coordenadas de transformaci?n.
|
||
94 | * @param rp, coordenadas de transformaci?n.
|
||
95 | */
|
||
96 | public void reProject(ICoordTrans rp) { |
||
97 | Point2D[] savePts = pts; |
||
98 | |||
99 | pts = new Point2D[savePts.length]; |
||
100 | extent = new Extent();
|
||
101 | |||
102 | Point2D ptDest = null; |
||
103 | |||
104 | for (int i = 0; i < savePts.length; i++) { |
||
105 | ptDest = rp.getPDest().createPoint(0.0, 0.0); |
||
106 | ptDest = rp.convert((Point2D) savePts[i], ptDest);
|
||
107 | this.pts[i] = ptDest;
|
||
108 | extent.add(ptDest); |
||
109 | } |
||
110 | |||
111 | setProjection(rp.getPDest()); |
||
112 | } |
||
113 | |||
114 | /**
|
||
115 | * Permite dibujar un DxfCircle.
|
||
116 | */
|
||
117 | public void draw(Graphics2D g, ViewPortData vp) { |
||
118 | //System.out.println("Va a pintar un circle");
|
||
119 | Color color = null; |
||
120 | |||
121 | if (dxfColor == AcadColor.BYLAYER) {
|
||
122 | //g.setColor(layer.getColor());
|
||
123 | color = layer.getColor(); |
||
124 | } else {
|
||
125 | //g.setColor(AcadColor.getColor(dxfColor));
|
||
126 | color = AcadColor.getColor(dxfColor); |
||
127 | } |
||
128 | |||
129 | newGP(vp); |
||
130 | |||
131 | if (closed) {
|
||
132 | g.setColor(new Color(color.getRed(), color.getBlue(), |
||
133 | color.getGreen(), 0x80));
|
||
134 | g.fill(gp); |
||
135 | } |
||
136 | |||
137 | g.setColor(color); |
||
138 | g.draw(gp); |
||
139 | } |
||
140 | |||
141 | /**
|
||
142 | * Permite generar un GeneralPath partiendo del array de Point2D que conforma el
|
||
143 | * DxfCircle.
|
||
144 | * @param vp
|
||
145 | */
|
||
146 | private void newGP(ViewPortData vp) { |
||
147 | //if (gp != null) return;
|
||
148 | gp = new GeneralPath(); |
||
149 | |||
150 | Point2D pt0 = null; |
||
151 | Point2D pt = null; |
||
152 | Point2D pt1 = null; |
||
153 | Point2D.Double ptTmp = new Point2D.Double(0.0, 0.0); |
||
154 | |||
155 | //System.out.println("pts.length = " + pts.length);
|
||
156 | for (int i = 0; i < pts.length; i++) { |
||
157 | pt1 = (Point2D) pts[i];
|
||
158 | vp.mat.transform(pt1, ptTmp); |
||
159 | |||
160 | if (pt0 == null) { |
||
161 | pt0 = ptTmp; |
||
162 | gp.moveTo((float) ptTmp.getX(), (float) ptTmp.getY()); |
||
163 | } else {
|
||
164 | gp.lineTo((float) ptTmp.getX(), (float) ptTmp.getY()); |
||
165 | } |
||
166 | } |
||
167 | |||
168 | if (closed) {
|
||
169 | gp.closePath(); |
||
170 | } |
||
171 | } |
||
172 | |||
173 | /**
|
||
174 | * Permite la escritura de entidades DxfCircle en un fichero DXF2000.
|
||
175 | * @return String, la cadena que se escribir? en el fichero con la informaci?n
|
||
176 | * del DxfCircle.
|
||
177 | */
|
||
178 | public String toDxfString() { |
||
179 | StringBuffer sb = null; |
||
180 | sb = new StringBuffer(DxfGroup.toString(0, "CIRCLE")); |
||
181 | sb.append(DxfGroup.toString(5, getHandle()));
|
||
182 | sb.append(DxfGroup.toString(100, "AcDbEntity")); |
||
183 | sb.append(DxfGroup.toString(8, layer.getName()));
|
||
184 | sb.append(DxfGroup.toString(62, dxfColor));
|
||
185 | sb.append(DxfGroup.toString(100, "AcDbCircle")); |
||
186 | sb.append(DxfGroup.toString(10, getCenter().getX(), 6)); |
||
187 | sb.append(DxfGroup.toString(20, getCenter().getY(), 6)); |
||
188 | 5404 | fjp | // sb.append(DxfGroup.toString(30, 0.0, 1));
|
189 | 2809 | nacho | sb.append(DxfGroup.toString(40, getRadius(), 6)); |
190 | |||
191 | return sb.toString();
|
||
192 | } |
||
193 | |||
194 | /**
|
||
195 | * Devuelve el array de puntos que conforman el DxfCircle.
|
||
196 | * @return Point2D[], puntos del DxfCircle.
|
||
197 | */
|
||
198 | public Point2D[] getPts() { |
||
199 | return pts;
|
||
200 | } |
||
201 | |||
202 | /**
|
||
203 | * Devuelve el GeneralPath qie conforma el DxfCircle.
|
||
204 | * @return GeneralPath del DxfCircle.
|
||
205 | */
|
||
206 | /*public GeneralPath getGeneralPath(ViewPort vp) {
|
||
207 | newGP(vp);
|
||
208 | return (GeneralPath) gp.clone();
|
||
209 | }*/
|
||
210 | |||
211 | /**
|
||
212 | * @return Returns the radius.
|
||
213 | */
|
||
214 | public double getRadius() { |
||
215 | return radius;
|
||
216 | } |
||
217 | |||
218 | /**
|
||
219 | * @param radius The radius to set.
|
||
220 | */
|
||
221 | public void setRadius(double radius) { |
||
222 | this.radius = radius;
|
||
223 | } |
||
224 | |||
225 | /**
|
||
226 | * @return Returns the center.
|
||
227 | */
|
||
228 | public Point2D getCenter() { |
||
229 | return center;
|
||
230 | } |
||
231 | |||
232 | /**
|
||
233 | * @param center The center to set.
|
||
234 | */
|
||
235 | public void setCenter(Point2D center) { |
||
236 | this.center = center;
|
||
237 | } |
||
238 | 35 | jmorell | } |