svn-gvsig-desktop / trunk / libraries / libCq CMS for java.old / src / org / cresques / px / dxf / DxfEntityMaker.java @ 28
History | View | Annotate | Download (5.4 KB)
1 |
/*
|
---|---|
2 |
* Created on 04-may-2004
|
3 |
*/
|
4 |
|
5 |
package org.cresques.px.dxf; |
6 |
|
7 |
import java.awt.geom.Point2D; |
8 |
|
9 |
import org.cresques.geo.Point3D; |
10 |
import org.cresques.geo.Projected; |
11 |
import org.cresques.geo.Projection; |
12 |
import org.cresques.geo.ReProjection; |
13 |
import org.cresques.io.DxfFile; |
14 |
import org.cresques.io.DxfGroup; |
15 |
import org.cresques.io.DxfGroupVector; |
16 |
import org.cresques.px.Extent; |
17 |
import org.cresques.px.PxObj; |
18 |
|
19 |
/**
|
20 |
* Contructor de objetos Dxf
|
21 |
*
|
22 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es>
|
23 |
*/
|
24 |
|
25 |
public class DxfEntityMaker implements DxfFile.EntityFactory, Projected { |
26 |
Projection proj = null;
|
27 |
DxfEntity lastEntity = null;
|
28 |
DxfEntityList entities = null;
|
29 |
DxfTable layers = null;
|
30 |
|
31 |
double xtruX=0.0, xtruY=0.0, xtruZ=1.0; |
32 |
//double x=Double.NaN, y=Double.NaN, z=Double.NaN;
|
33 |
|
34 |
int polylineFlag = 0; |
35 |
Point2D firstPt = new Point2D.Double(); |
36 |
|
37 |
public DxfEntityMaker (Projection proj) {
|
38 |
this.proj = proj;
|
39 |
layers = new DxfTable();
|
40 |
entities = new DxfEntityList(proj);
|
41 |
} |
42 |
|
43 |
public PxObj getObjects() { return entities; } |
44 |
public Extent getExtent() { return entities.getExtent(); } |
45 |
|
46 |
public void createLayer(DxfGroupVector grp) throws Exception { |
47 |
DxfLayer layer = new DxfLayer(grp.getDataAsString(2), grp.getDataAsInt(62)); |
48 |
layer.lType = grp.getDataAsString(6);
|
49 |
layer.setFlags(grp.getDataAsInt(70));
|
50 |
layers.add(layer); |
51 |
} |
52 |
|
53 |
public void createPolyline(DxfGroupVector grp) throws Exception { |
54 |
DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
55 |
DxfPolyline entity = new DxfPolyline(proj, layer);
|
56 |
|
57 |
/*if (grp.hasCode(10))
|
58 |
x = grp.getDataAsDouble(10);
|
59 |
if (grp.hasCode(20))
|
60 |
y = grp.getDataAsDouble(20);
|
61 |
if (grp.hasCode(30))
|
62 |
z = grp.getDataAsDouble(30);*/
|
63 |
if (grp.hasCode(62)) |
64 |
entity.dxfColor = grp.getDataAsInt(62);
|
65 |
if (grp.hasCode(70)) |
66 |
entity.flags = grp.getDataAsInt(70);
|
67 |
if (grp.hasCode(210)) |
68 |
xtruX = grp.getDataAsDouble(210);
|
69 |
if (grp.hasCode(220)) |
70 |
xtruY = grp.getDataAsDouble(220);
|
71 |
if (grp.hasCode(230)) |
72 |
xtruZ = grp.getDataAsDouble(230);
|
73 |
// compruebo flags
|
74 |
if ((entity.flags & 0x01) == 0x01) { |
75 |
entity.closed = true;
|
76 |
} |
77 |
lastEntity = entity; |
78 |
} |
79 |
public void endSeq() throws Exception { |
80 |
entities.add(lastEntity); |
81 |
lastEntity = null;
|
82 |
xtruX = 0.0;
|
83 |
xtruY = 0.0;
|
84 |
xtruZ = 1.0;
|
85 |
} |
86 |
public void addVertex(DxfGroupVector grp) throws Exception { |
87 |
double x = 0.0, y = 0.0, z = 0.0; |
88 |
|
89 |
x = grp.getDataAsDouble(10);
|
90 |
y = grp.getDataAsDouble(20);
|
91 |
if (grp.hasCode(30)) z = grp.getDataAsDouble(30); |
92 |
Point3D point_in = new Point3D(x, y, z);
|
93 |
Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
|
94 |
Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
|
95 |
x = point_out.getX(); |
96 |
y = point_out.getY(); |
97 |
|
98 |
//System.out.println(x+","+y);
|
99 |
Point2D pt = proj.createPoint( x, y);
|
100 |
((DxfPolyline) lastEntity).add(pt); |
101 |
|
102 |
if (((DxfPolyline)lastEntity).pts.size() == 1) { |
103 |
firstPt = pt; |
104 |
} |
105 |
|
106 |
} |
107 |
public void createLwPolyline(DxfGroupVector grp) throws Exception { |
108 |
double x = 0.0, y = 0.0, elev=0.0; |
109 |
DxfGroup g = null;
|
110 |
|
111 |
if (grp.hasCode(38)) |
112 |
elev = grp.getDataAsDouble(38);
|
113 |
DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
114 |
DxfLwPolyline entity = new DxfLwPolyline(proj, layer);
|
115 |
for (int i=0; i<grp.size(); i++) { |
116 |
g = (DxfGroup) grp.get(i); |
117 |
if (g.getCode() == 10) |
118 |
x = ((Float) g.getData()).doubleValue();
|
119 |
else if (g.getCode() == 20) { |
120 |
y = ((Float) g.getData()).doubleValue();
|
121 |
//if (y <= 1.0) throw new Exception("Y == "+y);
|
122 |
entity.add( proj.createPoint( x, y ) ); |
123 |
x = 0.0; y = 0.0; |
124 |
} |
125 |
} |
126 |
if (grp.hasCode(62)) |
127 |
entity.dxfColor = grp.getDataAsInt(62);
|
128 |
if (grp.hasCode(70)) |
129 |
entity.flags = grp.getDataAsInt(70);
|
130 |
entities.add(entity); |
131 |
} |
132 |
|
133 |
public void createLine(DxfGroupVector grp) throws Exception { |
134 |
double x = 0.0, y = 0.0; |
135 |
DxfGroup g = null;
|
136 |
Point2D pt1 = null, pt2 = null; |
137 |
DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
138 |
|
139 |
x = grp.getDataAsDouble(10);
|
140 |
y = grp.getDataAsDouble(20);
|
141 |
pt1 = proj.createPoint(x, y); |
142 |
x = grp.getDataAsDouble(11);
|
143 |
y = grp.getDataAsDouble(21);
|
144 |
pt2 = proj.createPoint(x, y); |
145 |
DxfLine entity = new DxfLine(proj, layer, pt1, pt2);
|
146 |
if (grp.hasCode(62)) |
147 |
entity.dxfColor = grp.getDataAsInt(62);
|
148 |
entities.add(entity); |
149 |
} |
150 |
public void createText(DxfGroupVector grp) throws Exception { |
151 |
double x = 0.0, y = 0.0, h= 0.0, rot= 0.0; |
152 |
DxfGroup g = null;
|
153 |
Point2D pt1 = null, pt2 = null; |
154 |
String txt = null; |
155 |
DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
156 |
|
157 |
txt = grp.getDataAsString(1);
|
158 |
DxfText entity = new DxfText(proj, layer, txt);
|
159 |
|
160 |
entity.h = grp.getDataAsDouble(40);
|
161 |
x = grp.getDataAsDouble(10);
|
162 |
y = grp.getDataAsDouble(20);
|
163 |
entity.setPt1(proj.createPoint(x, y)); |
164 |
if (grp.hasCode(11)) { |
165 |
x = grp.getDataAsDouble(11);
|
166 |
y = grp.getDataAsDouble(21);
|
167 |
entity.setPt2(proj.createPoint(x, y)); |
168 |
} |
169 |
if (grp.hasCode(50)) |
170 |
entity.rot = grp.getDataAsDouble(50);
|
171 |
if (grp.hasCode(62)) |
172 |
entity.dxfColor = grp.getDataAsInt(62);
|
173 |
if (grp.hasCode(72)) |
174 |
entity.align = grp.getDataAsInt(72);
|
175 |
entities.add(entity); |
176 |
} |
177 |
public void createSolid(DxfGroupVector grp) throws Exception { |
178 |
DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
179 |
} |
180 |
|
181 |
public Projection getProjection() { return proj;} |
182 |
|
183 |
/**
|
184 |
* Cambia de proyeccion.
|
185 |
*
|
186 |
* @param rp
|
187 |
*/
|
188 |
public void reProject(ReProjection rp) { |
189 |
entities.reProject(rp); |
190 |
} |
191 |
public DxfEntityList getEntities() { return entities;} |
192 |
public DxfTable getLayers() { return layers;} |
193 |
|
194 |
} |
195 |
|
196 |
|
197 |
|