svn-gvsig-desktop / tags / Root_CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / px / dxf / DxfBlock.java @ 1732
History | View | Annotate | Download (3.08 KB)
1 | 44 | jmorell | package org.cresques.px.dxf; |
---|---|---|---|
2 | |||
3 | 57 | jmorell | import java.util.Vector; |
4 | import java.util.Iterator; |
||
5 | 44 | jmorell | import java.awt.Graphics2D; |
6 | 66 | jmorell | import java.awt.geom.Point2D; |
7 | |||
8 | 94 | luisw | import org.cresques.cts.ICoordTrans; |
9 | import org.cresques.cts.IProjection; |
||
10 | 57 | jmorell | import org.cresques.geo.Point3D; |
11 | import org.cresques.geo.Projected; |
||
12 | 44 | jmorell | import org.cresques.geo.Projection; |
13 | import org.cresques.geo.ReProjection; |
||
14 | 91 | luisw | import org.cresques.geo.ViewPortData; |
15 | 44 | jmorell | import org.cresques.px.Extent; |
16 | 96 | luisw | import org.cresques.px.IObjList; |
17 | 57 | jmorell | import org.cresques.px.PxObj; |
18 | 44 | jmorell | |
19 | 96 | luisw | public class DxfBlock extends PxObj implements IObjList { |
20 | 94 | luisw | IProjection proj = null;
|
21 | 96 | luisw | Vector data = null; |
22 | 57 | jmorell | int flags = 0; |
23 | String blkName = ""; |
||
24 | 71 | jmorell | Point2D bPoint = new Point2D.Double(); |
25 | 44 | jmorell | |
26 | 94 | luisw | public DxfBlock(IProjection proj) {
|
27 | 44 | jmorell | extent = new Extent();
|
28 | 96 | luisw | data = new Vector(); |
29 | 44 | jmorell | } |
30 | |||
31 | 96 | luisw | public IObjList getAt(Point2D pt) { |
32 | IObjList oList = new DxfEntityList(proj);
|
||
33 | Iterator iter = iterator();
|
||
34 | while (iter.hasNext()) {
|
||
35 | Extent.Has o = (Extent.Has) iter.next(); |
||
36 | if (o.getExtent().isAt(pt)) oList.add(o);
|
||
37 | } |
||
38 | return oList;
|
||
39 | 44 | jmorell | } |
40 | |||
41 | 96 | luisw | public Iterator iterator() { return data.iterator(); } |
42 | public int size() { return data.size(); } |
||
43 | |||
44 | public void add(Extent.Has obj) { |
||
45 | if (obj != null) { |
||
46 | extent.add(obj.getExtent()); |
||
47 | data.add(obj); |
||
48 | } |
||
49 | } |
||
50 | |||
51 | public void remove(Object obj) { data.remove(obj); } |
||
52 | |||
53 | public void clear() { |
||
54 | extent = new Extent();
|
||
55 | data.clear(); |
||
56 | } |
||
57 | |||
58 | public Extent.Has get(int i) { return (Extent.Has) data.get(i); } |
||
59 | |||
60 | 94 | luisw | public IProjection getProjection() { return proj; } |
61 | public void setProjection(IProjection p) { proj = p; } |
||
62 | public void reProject(ICoordTrans rp) { |
||
63 | 44 | jmorell | extent = new Extent();
|
64 | 57 | jmorell | PxObj o; |
65 | 96 | luisw | Iterator iter = iterator();
|
66 | 57 | jmorell | while (iter.hasNext()) {
|
67 | o = (PxObj) iter.next(); |
||
68 | ((Projected) o).reProject(rp); |
||
69 | extent.add(o.getExtent()); |
||
70 | } |
||
71 | 44 | jmorell | setProjection(rp.getPDest()); |
72 | } |
||
73 | |||
74 | 91 | luisw | public void draw(Graphics2D g, ViewPortData vp) { |
75 | 96 | luisw | Iterator iter = iterator();
|
76 | 57 | jmorell | Extent extent; |
77 | while (iter.hasNext()) {
|
||
78 | DxfEntity entity = (DxfEntity) iter.next(); |
||
79 | extent = entity.getExtent(); |
||
80 | if (vp.getExtent().minX()> extent.maxX()) continue; |
||
81 | if (vp.getExtent().minY()> extent.maxY()) continue; |
||
82 | if (vp.getExtent().maxX()< extent.minX()) continue; |
||
83 | if (vp.getExtent().maxY()< extent.minY()) continue; |
||
84 | if (!entity.layer.frozen)
|
||
85 | entity.draw(g, vp); |
||
86 | } |
||
87 | 44 | jmorell | } |
88 | 57 | jmorell | |
89 | public String toDxfString() { |
||
90 | StringBuffer sb = new StringBuffer(""); |
||
91 | 44 | jmorell | |
92 | 96 | luisw | Iterator iter = iterator();
|
93 | 57 | jmorell | Extent extent; |
94 | while (iter.hasNext()) {
|
||
95 | sb.append(((DxfEntity) iter.next()).toDxfString()); |
||
96 | } |
||
97 | return sb.toString();
|
||
98 | 44 | jmorell | } |
99 | 57 | jmorell | |
100 | 96 | luisw | public int getFlags() {return flags; } |
101 | 57 | jmorell | |
102 | 96 | luisw | public String getBlkName() { return blkName; } |
103 | 59 | jmorell | |
104 | 96 | luisw | public Vector getBlkElements() { return data; } |
105 | 72 | jmorell | |
106 | public void setBlkElements(Vector blkElements) { |
||
107 | 96 | luisw | data = blkElements; |
108 | 72 | jmorell | } |
109 | |||
110 | 57 | jmorell | public void setBlkName(String blkName) { |
111 | this.blkName = blkName;
|
||
112 | System.out.println("setBlkName: this.blkName = " + this.blkName); |
||
113 | } |
||
114 | |||
115 | 73 | jmorell | public void setBPoint(Point2D basePoint) { |
116 | 71 | jmorell | this.bPoint = basePoint;
|
117 | 73 | jmorell | System.out.println("setBPoint: this.bPoint = " + this.bPoint); |
118 | 57 | jmorell | } |
119 | |||
120 | public void setFlags(int flags) { |
||
121 | this.flags = flags;
|
||
122 | System.out.println("setFlags: this.flags = " + this.flags); |
||
123 | } |
||
124 | |||
125 | 44 | jmorell | } |