svn-gvsig-desktop / branches / Mobile_Compatible_Hito_1 / libDXF / src / org / cresques / px / dxf / DxfEntityList.java @ 21930
History | View | Annotate | Download (6.3 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.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 |
/**
|
41 |
* La clase DxfEntityList almacena un conjunto de objetos gr?ficos. Esta basada en
|
42 |
* FeatureCollection de .gml y .shp
|
43 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es>
|
44 |
*/
|
45 |
public class DxfEntityList extends PxObj implements IObjList.vector { |
46 |
IProjection proj = null;
|
47 |
private Vector data = null; |
48 |
|
49 |
/**
|
50 |
* Constructor de DxfEntityList.
|
51 |
* @param proj, Proyecci?n cartogr?fica en la que se encuentra la DxfEntityList.
|
52 |
*/
|
53 |
public DxfEntityList(IProjection proj) {
|
54 |
extent = new Extent();
|
55 |
data = new Vector(); |
56 |
} |
57 |
|
58 |
/**
|
59 |
* Permite a?adir un objeto gr?fico a la lista.
|
60 |
* @param obj, Objeto gr?fico que implemente el interface Extent.Has
|
61 |
*/
|
62 |
public void add(Extent.Has obj) { |
63 |
if (obj != null) { |
64 |
extent.add(obj.getExtent()); |
65 |
data.add(obj); |
66 |
} |
67 |
} |
68 |
|
69 |
/**
|
70 |
* Devuelve uno de los elementos de la lista de objetos gr?ficos.
|
71 |
* @param cnt, ?ndice del elemento de la lista que queremos obtener.
|
72 |
* @return Extent.Has, elemento gr?fico que queremos obtener.
|
73 |
*/
|
74 |
public Extent.Has get(int cnt) { |
75 |
return (Extent.Has) data.get(cnt);
|
76 |
} |
77 |
|
78 |
/**
|
79 |
* Devuelve los obhjetos gr?ficos de la lista cuyos extents contengan al
|
80 |
* punto que se le pasa como argumento.
|
81 |
* @param pt, punto para localizar los objetos gr?ficos.
|
82 |
* @return IObjList, Conjunto de objetos gr?ficos que contienen a pt.
|
83 |
*/
|
84 |
public IObjList getAt(Point2D pt) { |
85 |
IObjList oList = new DxfEntityList(proj);
|
86 |
Iterator iter = iterator();
|
87 |
|
88 |
while (iter.hasNext()) {
|
89 |
Extent.Has o = (Extent.Has) iter.next(); |
90 |
|
91 |
if (o.getExtent().isAt(pt)) {
|
92 |
oList.add(o); |
93 |
} |
94 |
} |
95 |
|
96 |
return oList;
|
97 |
} |
98 |
|
99 |
/**
|
100 |
* Devuelve un iterador para recorrer los elementos de la lista de objetos gr?ficos.
|
101 |
* @return Iterator, iterador.
|
102 |
*/
|
103 |
public Iterator iterator() { |
104 |
return data.iterator();
|
105 |
} |
106 |
|
107 |
/**
|
108 |
* Devuelve la cantidad de elementos que contiene la lista de objetos gr?ficos.
|
109 |
* @return int
|
110 |
*/
|
111 |
public int size() { |
112 |
return data.size();
|
113 |
} |
114 |
|
115 |
/**
|
116 |
* Permite eliminar un elemento de la lista de objetos gr?ficos.
|
117 |
* @param obj, Objeto que queremos eliminar.
|
118 |
*/
|
119 |
public void remove(Object obj) { |
120 |
data.remove(obj); |
121 |
} |
122 |
|
123 |
/**
|
124 |
* Permite vac?ar la lista de objetos gr?ficos.
|
125 |
*/
|
126 |
public void clear() { |
127 |
extent = new Extent();
|
128 |
data.clear(); |
129 |
} |
130 |
|
131 |
/**
|
132 |
* Devuelve la proyecci?n cartogr?fica en la que se encuentra la DxfEntityList.
|
133 |
* @return IProjection, proyecci?n cartogr?fica.
|
134 |
*/
|
135 |
public IProjection getProjection() {
|
136 |
return proj;
|
137 |
} |
138 |
|
139 |
/**
|
140 |
* Establece la proyecci?n cartogr?fica en la que se encuentra la DxfEntityList.
|
141 |
* @param p, Proyecci?n cartogr?fica.
|
142 |
*/
|
143 |
public void setProjection(IProjection p) { |
144 |
proj = p; |
145 |
} |
146 |
|
147 |
/**
|
148 |
* Permite cambiar la proyecci?n en la que se encuentra la DxfEntityList a
|
149 |
* trav?s de 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 las entidades que conforman la DxfEntityList.
|
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 && !entity.layer.isOff) {
|
195 |
entity.draw(g, vp); |
196 |
} |
197 |
} |
198 |
} |
199 |
|
200 |
/**
|
201 |
* Permite la escritura de entidades en un fichero DXF2000.
|
202 |
* @return String, la cadena que se escribir? en el fichero con la informaci?n
|
203 |
* de la correspondiente entidad.
|
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 |
} |