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