svn-gvsig-desktop / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / px / dxf / DxfBlock.java @ 2312
History | View | Annotate | Download (3.91 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.cresques.cts.ICoordTrans; |
32 |
import org.cresques.cts.IProjection; |
33 |
import org.cresques.geo.Projected; |
34 |
import org.cresques.geo.ViewPortData; |
35 |
import org.cresques.px.Extent; |
36 |
import org.cresques.px.IObjList; |
37 |
import org.cresques.px.PxObj; |
38 |
|
39 |
public class DxfBlock extends PxObj implements IObjList { |
40 |
IProjection proj = null;
|
41 |
Vector data = null; |
42 |
int flags = 0; |
43 |
String blkName = ""; |
44 |
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 |
|
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); } |
79 |
|
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(""); |
111 |
|
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 |
|
149 |
} |