svn-gvsig-desktop / branches / Mobile_Compatible_Hito_1 / libDXF / src / org / cresques / px / dxf / DxfBlock.java @ 21930
History | View | Annotate | Download (7.57 KB)
1 | 21930 | csanchez | /*
|
---|---|---|---|
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.Graphics2D; |
||
27 | import java.awt.geom.Point2D; |
||
28 | import java.util.Iterator; |
||
29 | import java.util.Vector; |
||
30 | |||
31 | import org.gvsig.projection.cts.ICoordTrans; |
||
32 | import org.gvsig.projection.cts.IProjection; |
||
33 | import org.gvsig.projection.geo.Projected; |
||
34 | import org.gvsig.projection.geo.ViewPortData; |
||
35 | import org.gvsig.projection.px.Extent; |
||
36 | import org.gvsig.projection.px.IObjList; |
||
37 | import org.gvsig.projection.px.PxObj; |
||
38 | |||
39 | /**
|
||
40 | * Entidad BLOCK de un fichero DXF.
|
||
41 | * @author jmorell
|
||
42 | */
|
||
43 | public class DxfBlock extends PxObj implements IObjList { |
||
44 | IProjection proj = null;
|
||
45 | Vector data = null; |
||
46 | int flags = 0; |
||
47 | String blkName = ""; |
||
48 | Point2D bPoint = new Point2D.Double(); |
||
49 | |||
50 | /**
|
||
51 | * Constructor de DxfBlock.
|
||
52 | * @param proj, proyecci?n cartogr?fica en la que se encuentra el DxfBlock.
|
||
53 | */
|
||
54 | public DxfBlock(IProjection proj) {
|
||
55 | extent = new Extent();
|
||
56 | data = new Vector(); |
||
57 | } |
||
58 | |||
59 | /**
|
||
60 | * Devuelve los obhjetos gr?ficos de la lista cuyos extents contengan al
|
||
61 | * punto que se le pasa como argumento.
|
||
62 | * @param pt, punto para localizar los objetos gr?ficos.
|
||
63 | * @return IObjList, Conjunto de objetos gr?ficos que contienen a pt.
|
||
64 | */
|
||
65 | public IObjList getAt(Point2D pt) { |
||
66 | IObjList oList = new DxfEntityList(proj);
|
||
67 | Iterator iter = iterator();
|
||
68 | |||
69 | while (iter.hasNext()) {
|
||
70 | Extent.Has o = (Extent.Has) iter.next(); |
||
71 | |||
72 | if (o.getExtent().isAt(pt)) {
|
||
73 | oList.add(o); |
||
74 | } |
||
75 | } |
||
76 | |||
77 | return oList;
|
||
78 | } |
||
79 | |||
80 | /**
|
||
81 | * Devuelve un iterador para recorrer los elementos de la lista de objetos gr?ficos.
|
||
82 | * @return Iterator, iterador.
|
||
83 | */
|
||
84 | public Iterator iterator() { |
||
85 | return data.iterator();
|
||
86 | } |
||
87 | |||
88 | /**
|
||
89 | * Devuelve la cantidad de elementos que contiene la lista de objetos gr?ficos.
|
||
90 | * @return int
|
||
91 | */
|
||
92 | public int size() { |
||
93 | return data.size();
|
||
94 | } |
||
95 | |||
96 | /**
|
||
97 | * Permite a?adir un objeto gr?fico a la lista.
|
||
98 | * @param obj, Objeto gr?fico que implemente el interface Extent.Has
|
||
99 | */
|
||
100 | public void add(Extent.Has obj) { |
||
101 | if (obj != null) { |
||
102 | extent.add(obj.getExtent()); |
||
103 | data.add(obj); |
||
104 | } |
||
105 | } |
||
106 | |||
107 | /**
|
||
108 | * Permite eliminar un elemento de la lista de objetos gr?ficos.
|
||
109 | * @param obj, Objeto que queremos eliminar.
|
||
110 | */
|
||
111 | public void remove(Object obj) { |
||
112 | data.remove(obj); |
||
113 | } |
||
114 | |||
115 | /**
|
||
116 | * Permite vac?ar la lista de objetos gr?ficos.
|
||
117 | */
|
||
118 | public void clear() { |
||
119 | extent = new Extent();
|
||
120 | data.clear(); |
||
121 | } |
||
122 | |||
123 | /**
|
||
124 | * Devuelve uno de los elementos de la lista de objetos gr?ficos.
|
||
125 | * @param i, ?ndice del elemento de la lista que queremos obtener.
|
||
126 | * @return Extent.Has, elemento gr?fico que queremos obtener.
|
||
127 | */
|
||
128 | public Extent.Has get(int i) { |
||
129 | return (Extent.Has) data.get(i);
|
||
130 | } |
||
131 | |||
132 | /**
|
||
133 | * Devuelve la proyecci?n cartogr?fica en la que se encuentra el DxfBlock.
|
||
134 | * @return IProjection, proyecci?n cartogr?fica.
|
||
135 | */
|
||
136 | public IProjection getProjection() {
|
||
137 | return proj;
|
||
138 | } |
||
139 | |||
140 | /**
|
||
141 | * Establece la proyecci?n cartogr?fica en la que se encuentra el DxfBlock.
|
||
142 | * @param p, Proyecci?n cartogr?fica.
|
||
143 | */
|
||
144 | public void setProjection(IProjection p) { |
||
145 | proj = p; |
||
146 | } |
||
147 | |||
148 | /**
|
||
149 | * Permite reproyectar un DxfBlock dado un conjunto de coordenadas de transformaci?n.
|
||
150 | * @param rp, coordenadas de transformaci?n.
|
||
151 | */
|
||
152 | public void reProject(ICoordTrans rp) { |
||
153 | extent = new Extent();
|
||
154 | |||
155 | PxObj o; |
||
156 | Iterator iter = iterator();
|
||
157 | |||
158 | while (iter.hasNext()) {
|
||
159 | o = (PxObj) iter.next(); |
||
160 | ((Projected) o).reProject(rp); |
||
161 | extent.add(o.getExtent()); |
||
162 | } |
||
163 | |||
164 | setProjection(rp.getPDest()); |
||
165 | } |
||
166 | |||
167 | /**
|
||
168 | * Permite dibujar un DxfBlock.
|
||
169 | */
|
||
170 | public void draw(Graphics2D g, ViewPortData vp) { |
||
171 | Iterator iter = iterator();
|
||
172 | Extent extent; |
||
173 | |||
174 | while (iter.hasNext()) {
|
||
175 | DxfEntity entity = (DxfEntity) iter.next(); |
||
176 | extent = entity.getExtent(); |
||
177 | |||
178 | if (vp.getExtent().minX() > extent.maxX()) {
|
||
179 | continue;
|
||
180 | } |
||
181 | |||
182 | if (vp.getExtent().minY() > extent.maxY()) {
|
||
183 | continue;
|
||
184 | } |
||
185 | |||
186 | if (vp.getExtent().maxX() < extent.minX()) {
|
||
187 | continue;
|
||
188 | } |
||
189 | |||
190 | if (vp.getExtent().maxY() < extent.minY()) {
|
||
191 | continue;
|
||
192 | } |
||
193 | |||
194 | if (!entity.layer.frozen) {
|
||
195 | entity.draw(g, vp); |
||
196 | } |
||
197 | } |
||
198 | } |
||
199 | |||
200 | /**
|
||
201 | * Permite la escritura de entidades DxfBlock en un fichero DXF2000.
|
||
202 | * @return String, la cadena que se escribir? en el fichero con la informaci?n
|
||
203 | * del DxfBlock.
|
||
204 | */
|
||
205 | public String toDxfString() { |
||
206 | StringBuffer sb = new StringBuffer(""); |
||
207 | |||
208 | Iterator iter = iterator();
|
||
209 | Extent extent; |
||
210 | |||
211 | while (iter.hasNext()) {
|
||
212 | sb.append(((DxfEntity) iter.next()).toDxfString()); |
||
213 | } |
||
214 | |||
215 | return sb.toString();
|
||
216 | } |
||
217 | |||
218 | /**
|
||
219 | * Devuelve el estado de flags.
|
||
220 | * @return int
|
||
221 | */
|
||
222 | public int getFlags() { |
||
223 | return flags;
|
||
224 | } |
||
225 | |||
226 | /**
|
||
227 | * Devuelve el nombre del bloque.
|
||
228 | * @return String
|
||
229 | */
|
||
230 | public String getBlkName() { |
||
231 | return blkName;
|
||
232 | } |
||
233 | |||
234 | /**
|
||
235 | * Devuelve un Vector con los elementos que conforman el bloque.
|
||
236 | * @return Vector
|
||
237 | */
|
||
238 | public Vector getBlkElements() { |
||
239 | return data;
|
||
240 | } |
||
241 | |||
242 | /**
|
||
243 | * Establece los elementos que conforman el bloque.
|
||
244 | * @param blkElements
|
||
245 | */
|
||
246 | public void setBlkElements(Vector blkElements) { |
||
247 | data = blkElements; |
||
248 | } |
||
249 | |||
250 | /**
|
||
251 | * Establece el nombre del bloque.
|
||
252 | * @param blkName
|
||
253 | */
|
||
254 | public void setBlkName(String blkName) { |
||
255 | this.blkName = blkName;
|
||
256 | System.out.println("setBlkName: this.blkName = " + this.blkName); |
||
257 | } |
||
258 | |||
259 | /**
|
||
260 | * Establece el punto base del bloque.
|
||
261 | * @param basePoint
|
||
262 | */
|
||
263 | public void setBPoint(Point2D basePoint) { |
||
264 | this.bPoint = basePoint;
|
||
265 | System.out.println("setBPoint: this.bPoint = " + this.bPoint); |
||
266 | } |
||
267 | |||
268 | /**
|
||
269 | * Devuelve el punto base del bloque.
|
||
270 | * @return
|
||
271 | */
|
||
272 | public Point2D getBPoint() { |
||
273 | return bPoint;
|
||
274 | } |
||
275 | |||
276 | /**
|
||
277 | * Establece el estado de la variable flags.
|
||
278 | * @param flags
|
||
279 | */
|
||
280 | public void setFlags(int flags) { |
||
281 | this.flags = flags;
|
||
282 | } |
||
283 | } |