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