svn-gvsig-desktop / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / px / dxf / DxfEntityList.java @ 2669
History | View | Annotate | Download (3.93 KB)
1 | 2 | luisw | /*
|
---|---|---|---|
2 | 2312 | igbrotru | * Cresques Mapping Suite. Graphic Library for constructing mapping applications.
|
3 | 2249 | igbrotru | *
|
4 | 2669 | nacho | * Copyright (C) 2004-5.
|
5 | *
|
||
6 | 2249 | igbrotru | * 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 | 2669 | nacho | *
|
22 | 2312 | igbrotru | * cresques@gmail.com
|
23 | 2249 | igbrotru | */
|
24 | 2 | luisw | package org.cresques.px.dxf; |
25 | |||
26 | 94 | luisw | import org.cresques.cts.ICoordTrans; |
27 | import org.cresques.cts.IProjection; |
||
28 | 2669 | nacho | |
29 | 2 | luisw | import org.cresques.geo.Projected; |
30 | 91 | luisw | import org.cresques.geo.ViewPortData; |
31 | 2669 | nacho | |
32 | 2 | luisw | import org.cresques.px.Extent; |
33 | 96 | luisw | import org.cresques.px.IObjList; |
34 | 2 | luisw | import org.cresques.px.PxObj; |
35 | |||
36 | 2669 | nacho | import java.awt.Graphics2D; |
37 | import java.awt.geom.Point2D; |
||
38 | |||
39 | import java.util.Iterator; |
||
40 | import java.util.Vector; |
||
41 | |||
42 | |||
43 | 2 | luisw | /**
|
44 | * FeatureCollection de .gml y .shp
|
||
45 | * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
|
||
46 | */
|
||
47 | 99 | luisw | public class DxfEntityList extends PxObj implements IObjList.vector { |
48 | 2669 | nacho | IProjection proj = null;
|
49 | private Vector data = null; |
||
50 | 96 | luisw | |
51 | 2669 | nacho | public DxfEntityList(IProjection proj) {
|
52 | extent = new Extent();
|
||
53 | data = new Vector(); |
||
54 | } |
||
55 | 96 | luisw | |
56 | 2669 | nacho | public void add(Extent.Has obj) { |
57 | if (obj != null) { |
||
58 | extent.add(obj.getExtent()); |
||
59 | data.add(obj); |
||
60 | } |
||
61 | } |
||
62 | 14 | luisw | |
63 | 2669 | nacho | public Extent.Has get(int cnt) { |
64 | return (Extent.Has) data.get(cnt);
|
||
65 | } |
||
66 | |||
67 | public IObjList getAt(Point2D pt) { |
||
68 | IObjList oList = new DxfEntityList(proj);
|
||
69 | Iterator iter = iterator();
|
||
70 | |||
71 | while (iter.hasNext()) {
|
||
72 | Extent.Has o = (Extent.Has) iter.next(); |
||
73 | |||
74 | if (o.getExtent().isAt(pt)) {
|
||
75 | oList.add(o); |
||
76 | } |
||
77 | } |
||
78 | |||
79 | return oList;
|
||
80 | } |
||
81 | |||
82 | public Iterator iterator() { |
||
83 | return data.iterator();
|
||
84 | } |
||
85 | |||
86 | public int size() { |
||
87 | return data.size();
|
||
88 | } |
||
89 | |||
90 | public void remove(Object obj) { |
||
91 | data.remove(obj); |
||
92 | } |
||
93 | |||
94 | public void clear() { |
||
95 | extent = new Extent();
|
||
96 | data.clear(); |
||
97 | } |
||
98 | |||
99 | public IProjection getProjection() {
|
||
100 | return proj;
|
||
101 | } |
||
102 | |||
103 | public void setProjection(IProjection p) { |
||
104 | proj = p; |
||
105 | } |
||
106 | |||
107 | public void reProject(ICoordTrans rp) { |
||
108 | extent = new Extent();
|
||
109 | |||
110 | PxObj o; |
||
111 | Iterator iter = iterator();
|
||
112 | |||
113 | while (iter.hasNext()) {
|
||
114 | o = (PxObj) iter.next(); |
||
115 | ((Projected) o).reProject(rp); |
||
116 | extent.add(o.getExtent()); |
||
117 | } |
||
118 | |||
119 | setProjection(rp.getPDest()); |
||
120 | } |
||
121 | |||
122 | public void draw(Graphics2D g, ViewPortData vp) { |
||
123 | Iterator iter = iterator();
|
||
124 | Extent extent; |
||
125 | |||
126 | while (iter.hasNext()) {
|
||
127 | DxfEntity entity = (DxfEntity) iter.next(); |
||
128 | extent = entity.getExtent(); |
||
129 | |||
130 | if (vp.getExtent().minX() > extent.maxX()) {
|
||
131 | continue;
|
||
132 | } |
||
133 | |||
134 | if (vp.getExtent().minY() > extent.maxY()) {
|
||
135 | continue;
|
||
136 | } |
||
137 | |||
138 | if (vp.getExtent().maxX() < extent.minX()) {
|
||
139 | continue;
|
||
140 | } |
||
141 | |||
142 | if (vp.getExtent().maxY() < extent.minY()) {
|
||
143 | continue;
|
||
144 | } |
||
145 | |||
146 | if (!entity.layer.frozen && !entity.layer.isOff) {
|
||
147 | entity.draw(g, vp); |
||
148 | } |
||
149 | } |
||
150 | } |
||
151 | |||
152 | public String toDxfString() { |
||
153 | StringBuffer sb = new StringBuffer(""); |
||
154 | |||
155 | Iterator iter = iterator();
|
||
156 | Extent extent; |
||
157 | |||
158 | while (iter.hasNext()) {
|
||
159 | sb.append(((DxfEntity) iter.next()).toDxfString()); |
||
160 | } |
||
161 | |||
162 | return sb.toString();
|
||
163 | } |
||
164 | 2 | luisw | } |