Revision 2669 branches/CqCMSDvp/libraries/libCq CMS for java.old/src/org/cresques/px/dxf/DxfBlock.java
DxfBlock.java | ||
---|---|---|
1 | 1 |
/* |
2 | 2 |
* Cresques Mapping Suite. Graphic Library for constructing mapping applications. |
3 |
* |
|
4 |
* Copyright (C) 2004-5. |
|
5 | 3 |
* |
4 |
* Copyright (C) 2004-5. |
|
5 |
* |
|
6 | 6 |
* This program is free software; you can redistribute it and/or |
7 | 7 |
* modify it under the terms of the GNU General Public License |
8 | 8 |
* as published by the Free Software Foundation; either version 2 |
... | ... | |
18 | 18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
19 | 19 |
* |
20 | 20 |
* For more information, contact: |
21 |
*
|
|
21 |
* |
|
22 | 22 |
* cresques@gmail.com |
23 | 23 |
*/ |
24 | 24 |
package org.cresques.px.dxf; |
25 | 25 |
|
26 |
import java.awt.Graphics2D; |
|
27 |
import java.awt.geom.Point2D; |
|
28 |
import java.util.Iterator; |
|
29 |
import java.util.Vector; |
|
30 |
|
|
31 | 26 |
import org.cresques.cts.ICoordTrans; |
32 | 27 |
import org.cresques.cts.IProjection; |
28 |
|
|
33 | 29 |
import org.cresques.geo.Projected; |
34 | 30 |
import org.cresques.geo.ViewPortData; |
31 |
|
|
35 | 32 |
import org.cresques.px.Extent; |
36 | 33 |
import org.cresques.px.IObjList; |
37 | 34 |
import org.cresques.px.PxObj; |
38 | 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 |
|
|
39 | 43 |
public class DxfBlock extends PxObj implements IObjList { |
40 |
IProjection proj = null;
|
|
41 |
Vector data = null;
|
|
42 |
int flags = 0;
|
|
44 |
IProjection proj = null;
|
|
45 |
Vector data = null;
|
|
46 |
int flags = 0;
|
|
43 | 47 |
String blkName = ""; |
44 | 48 |
Point2D bPoint = new Point2D.Double(); |
45 |
|
|
46 |
public DxfBlock(IProjection proj) { |
|
47 |
extent = new Extent(); |
|
48 |
data = new Vector(); |
|
49 |
} |
|
50 |
|
|
51 |
public IObjList getAt(Point2D pt) { |
|
52 |
IObjList oList = new DxfEntityList(proj); |
|
53 |
Iterator iter = iterator(); |
|
54 |
while (iter.hasNext()) { |
|
55 |
Extent.Has o = (Extent.Has) iter.next(); |
|
56 |
if (o.getExtent().isAt(pt)) oList.add(o); |
|
57 |
} |
|
58 |
return oList; |
|
59 |
} |
|
60 |
|
|
61 |
public Iterator iterator() { return data.iterator(); } |
|
62 |
public int size() { return data.size(); } |
|
63 |
|
|
64 |
public void add(Extent.Has obj) { |
|
65 |
if (obj != null) { |
|
66 |
extent.add(obj.getExtent()); |
|
67 |
data.add(obj); |
|
68 |
} |
|
69 |
} |
|
70 |
|
|
71 |
public void remove(Object obj) { data.remove(obj); } |
|
72 | 49 |
|
73 |
public void clear() { |
|
74 |
extent = new Extent(); |
|
75 |
data.clear(); |
|
76 |
} |
|
77 |
|
|
78 |
public Extent.Has get(int i) { return (Extent.Has) data.get(i); } |
|
50 |
public DxfBlock(IProjection proj) { |
|
51 |
extent = new Extent(); |
|
52 |
data = new Vector(); |
|
53 |
} |
|
79 | 54 |
|
80 |
public IProjection getProjection() { return proj; } |
|
81 |
public void setProjection(IProjection p) { proj = p; } |
|
82 |
public void reProject(ICoordTrans rp) { |
|
83 |
extent = new Extent(); |
|
84 |
PxObj o; |
|
85 |
Iterator iter = iterator(); |
|
86 |
while (iter.hasNext()) { |
|
87 |
o = (PxObj) iter.next(); |
|
88 |
((Projected) o).reProject(rp); |
|
89 |
extent.add(o.getExtent()); |
|
90 |
} |
|
91 |
setProjection(rp.getPDest()); |
|
92 |
} |
|
93 |
|
|
94 |
public void draw(Graphics2D g, ViewPortData vp) { |
|
95 |
Iterator iter = iterator(); |
|
96 |
Extent extent; |
|
97 |
while (iter.hasNext()) { |
|
98 |
DxfEntity entity = (DxfEntity) iter.next(); |
|
99 |
extent = entity.getExtent(); |
|
100 |
if (vp.getExtent().minX()> extent.maxX()) continue; |
|
101 |
if (vp.getExtent().minY()> extent.maxY()) continue; |
|
102 |
if (vp.getExtent().maxX()< extent.minX()) continue; |
|
103 |
if (vp.getExtent().maxY()< extent.minY()) continue; |
|
104 |
if (!entity.layer.frozen) |
|
105 |
entity.draw(g, vp); |
|
106 |
} |
|
107 |
} |
|
108 |
|
|
109 |
public String toDxfString() { |
|
110 |
StringBuffer sb = new StringBuffer(""); |
|
55 |
public IObjList getAt(Point2D pt) { |
|
56 |
IObjList oList = new DxfEntityList(proj); |
|
57 |
Iterator iter = iterator(); |
|
111 | 58 |
|
112 |
Iterator iter = iterator(); |
|
113 |
Extent extent; |
|
114 |
while (iter.hasNext()) { |
|
115 |
sb.append(((DxfEntity) iter.next()).toDxfString()); |
|
116 |
} |
|
117 |
return sb.toString(); |
|
118 |
} |
|
119 |
|
|
120 |
public int getFlags() {return flags; } |
|
121 |
|
|
122 |
public String getBlkName() { return blkName; } |
|
123 |
|
|
124 |
public Vector getBlkElements() { return data; } |
|
125 |
|
|
126 |
public void setBlkElements(Vector blkElements) { |
|
127 |
data = blkElements; |
|
128 |
} |
|
129 |
|
|
130 |
public void setBlkName(String blkName) { |
|
131 |
this.blkName = blkName; |
|
132 |
System.out.println("setBlkName: this.blkName = " + this.blkName); |
|
133 |
} |
|
134 |
|
|
135 |
public void setBPoint(Point2D basePoint) { |
|
136 |
this.bPoint = basePoint; |
|
137 |
System.out.println("setBPoint: this.bPoint = " + this.bPoint); |
|
138 |
} |
|
139 |
|
|
140 |
public Point2D getBPoint() { |
|
141 |
return bPoint; |
|
142 |
} |
|
143 |
|
|
144 |
public void setFlags(int flags) { |
|
145 |
this.flags = flags; |
|
146 |
System.out.println("setFlags: this.flags = " + this.flags); |
|
147 |
} |
|
148 |
|
|
59 |
while (iter.hasNext()) { |
|
60 |
Extent.Has o = (Extent.Has) iter.next(); |
|
61 |
|
|
62 |
if (o.getExtent().isAt(pt)) { |
|
63 |
oList.add(o); |
|
64 |
} |
|
65 |
} |
|
66 |
|
|
67 |
return oList; |
|
68 |
} |
|
69 |
|
|
70 |
public Iterator iterator() { |
|
71 |
return data.iterator(); |
|
72 |
} |
|
73 |
|
|
74 |
public int size() { |
|
75 |
return data.size(); |
|
76 |
} |
|
77 |
|
|
78 |
public void add(Extent.Has obj) { |
|
79 |
if (obj != null) { |
|
80 |
extent.add(obj.getExtent()); |
|
81 |
data.add(obj); |
|
82 |
} |
|
83 |
} |
|
84 |
|
|
85 |
public void remove(Object obj) { |
|
86 |
data.remove(obj); |
|
87 |
} |
|
88 |
|
|
89 |
public void clear() { |
|
90 |
extent = new Extent(); |
|
91 |
data.clear(); |
|
92 |
} |
|
93 |
|
|
94 |
public Extent.Has get(int i) { |
|
95 |
return (Extent.Has) data.get(i); |
|
96 |
} |
|
97 |
|
|
98 |
public IProjection getProjection() { |
|
99 |
return proj; |
|
100 |
} |
|
101 |
|
|
102 |
public void setProjection(IProjection p) { |
|
103 |
proj = p; |
|
104 |
} |
|
105 |
|
|
106 |
public void reProject(ICoordTrans rp) { |
|
107 |
extent = new Extent(); |
|
108 |
|
|
109 |
PxObj o; |
|
110 |
Iterator iter = iterator(); |
|
111 |
|
|
112 |
while (iter.hasNext()) { |
|
113 |
o = (PxObj) iter.next(); |
|
114 |
((Projected) o).reProject(rp); |
|
115 |
extent.add(o.getExtent()); |
|
116 |
} |
|
117 |
|
|
118 |
setProjection(rp.getPDest()); |
|
119 |
} |
|
120 |
|
|
121 |
public void draw(Graphics2D g, ViewPortData vp) { |
|
122 |
Iterator iter = iterator(); |
|
123 |
Extent extent; |
|
124 |
|
|
125 |
while (iter.hasNext()) { |
|
126 |
DxfEntity entity = (DxfEntity) iter.next(); |
|
127 |
extent = entity.getExtent(); |
|
128 |
|
|
129 |
if (vp.getExtent().minX() > extent.maxX()) { |
|
130 |
continue; |
|
131 |
} |
|
132 |
|
|
133 |
if (vp.getExtent().minY() > extent.maxY()) { |
|
134 |
continue; |
|
135 |
} |
|
136 |
|
|
137 |
if (vp.getExtent().maxX() < extent.minX()) { |
|
138 |
continue; |
|
139 |
} |
|
140 |
|
|
141 |
if (vp.getExtent().maxY() < extent.minY()) { |
|
142 |
continue; |
|
143 |
} |
|
144 |
|
|
145 |
if (!entity.layer.frozen) { |
|
146 |
entity.draw(g, vp); |
|
147 |
} |
|
148 |
} |
|
149 |
} |
|
150 |
|
|
151 |
public String toDxfString() { |
|
152 |
StringBuffer sb = new StringBuffer(""); |
|
153 |
|
|
154 |
Iterator iter = iterator(); |
|
155 |
Extent extent; |
|
156 |
|
|
157 |
while (iter.hasNext()) { |
|
158 |
sb.append(((DxfEntity) iter.next()).toDxfString()); |
|
159 |
} |
|
160 |
|
|
161 |
return sb.toString(); |
|
162 |
} |
|
163 |
|
|
164 |
public int getFlags() { |
|
165 |
return flags; |
|
166 |
} |
|
167 |
|
|
168 |
public String getBlkName() { |
|
169 |
return blkName; |
|
170 |
} |
|
171 |
|
|
172 |
public Vector getBlkElements() { |
|
173 |
return data; |
|
174 |
} |
|
175 |
|
|
176 |
public void setBlkElements(Vector blkElements) { |
|
177 |
data = blkElements; |
|
178 |
} |
|
179 |
|
|
180 |
public void setBlkName(String blkName) { |
|
181 |
this.blkName = blkName; |
|
182 |
System.out.println("setBlkName: this.blkName = " + this.blkName); |
|
183 |
} |
|
184 |
|
|
185 |
public void setBPoint(Point2D basePoint) { |
|
186 |
this.bPoint = basePoint; |
|
187 |
System.out.println("setBPoint: this.bPoint = " + this.bPoint); |
|
188 |
} |
|
189 |
|
|
190 |
public Point2D getBPoint() { |
|
191 |
return bPoint; |
|
192 |
} |
|
193 |
|
|
194 |
public void setFlags(int flags) { |
|
195 |
this.flags = flags; |
|
196 |
System.out.println("setFlags: this.flags = " + this.flags); |
|
197 |
} |
|
149 | 198 |
} |
Also available in: Unified diff