root / trunk / libraries / libCq CMS for java.old / src / org / cresques / px / dxf / DxfEntityMaker.java @ 9
History | View | Annotate | Download (3.94 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.Projected; |
10 |
import org.cresques.geo.Projection; |
11 |
import org.cresques.geo.ReProjection; |
12 |
import org.cresques.io.DxfFile; |
13 |
import org.cresques.io.DxfGroup; |
14 |
import org.cresques.io.DxfGroupVector; |
15 |
import org.cresques.px.PxObj; |
16 |
|
17 |
/**
|
18 |
* Contructor de objetos Dxf
|
19 |
*
|
20 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es>
|
21 |
*/
|
22 |
|
23 |
public class DxfEntityMaker implements DxfFile.EntityFactory, Projected { |
24 |
Projection proj = null;
|
25 |
DxfEntity lastEntity = null;
|
26 |
DxfEntityList entities = null;
|
27 |
DxfLayerList layers = null;
|
28 |
|
29 |
public DxfEntityMaker (Projection proj) {
|
30 |
this.proj = proj;
|
31 |
layers = new DxfLayerList();
|
32 |
entities = new DxfEntityList(proj);
|
33 |
} |
34 |
|
35 |
public PxObj getObjects() { return entities; } |
36 |
|
37 |
public void createLayer(DxfGroupVector grp) throws Exception { |
38 |
DxfLayer layer = new DxfLayer(grp.getDataAsString(2), grp.getDataAsInt(62)); |
39 |
layer.ltype = grp.getDataAsString(6);
|
40 |
layer.flags = grp.getDataAsInt(70);
|
41 |
layers.add(layer); |
42 |
} |
43 |
|
44 |
public void createPolyline(DxfGroupVector grp) throws Exception { |
45 |
DxfLayer layer = layers.getByName(grp.getDataAsString(8));
|
46 |
DxfPolyline entity = new DxfPolyline(proj, layer);
|
47 |
if (grp.hasCode(62)) |
48 |
entity.dxfColor = grp.getDataAsInt(62);
|
49 |
lastEntity = entity; |
50 |
} |
51 |
public void endSeq() throws Exception { |
52 |
entities.add(lastEntity); |
53 |
lastEntity = null;
|
54 |
} |
55 |
public void addVertex(DxfGroupVector grp) throws Exception { |
56 |
double x = 0.0, y = 0.0; |
57 |
|
58 |
x = grp.getDataAsDouble(10);
|
59 |
y = grp.getDataAsDouble(20);
|
60 |
//System.out.println(x+","+y);
|
61 |
Point2D pt = proj.createPoint( x, y);
|
62 |
((DxfPolyline) lastEntity).add(pt); |
63 |
} |
64 |
public void createLwPolyline(DxfGroupVector grp) throws Exception { |
65 |
double x = 0.0, y = 0.0; |
66 |
DxfGroup g = null;
|
67 |
Point2D pt = null; |
68 |
|
69 |
DxfLayer layer = layers.getByName(grp.getDataAsString(8));
|
70 |
DxfLwPolyline entity = new DxfLwPolyline(proj, layer);
|
71 |
for (int i=0; i<grp.size(); i++) { |
72 |
g = (DxfGroup) grp.get(i); |
73 |
if (g.getCode() == 10) |
74 |
x = ((Float) g.getData()).doubleValue();
|
75 |
else if (g.getCode() == 20) { |
76 |
y = ((Float) g.getData()).doubleValue();
|
77 |
pt = proj.createPoint( x, y ); |
78 |
entity.add(pt); |
79 |
x = 0.0; y = 0.0; |
80 |
} |
81 |
} |
82 |
if (grp.hasCode(62)) |
83 |
entity.dxfColor = grp.getDataAsInt(62);
|
84 |
entities.add(entity); |
85 |
} |
86 |
|
87 |
public void createLine(DxfGroupVector grp) throws Exception { |
88 |
double x = 0.0, y = 0.0; |
89 |
DxfGroup g = null;
|
90 |
Point2D pt1 = null, pt2 = null; |
91 |
DxfLayer layer = layers.getByName(grp.getDataAsString(8));
|
92 |
|
93 |
x = grp.getDataAsDouble(10);
|
94 |
y = grp.getDataAsDouble(20);
|
95 |
pt1 = proj.createPoint(x, y); |
96 |
x = grp.getDataAsDouble(11);
|
97 |
y = grp.getDataAsDouble(21);
|
98 |
pt2 = proj.createPoint(x, y); |
99 |
DxfLine entity = new DxfLine(proj, layer, pt1, pt2);
|
100 |
if (grp.hasCode(62)) |
101 |
entity.dxfColor = grp.getDataAsInt(62);
|
102 |
entities.add(entity); |
103 |
} |
104 |
public void createText(DxfGroupVector grp) throws Exception { |
105 |
double x = 0.0, y = 0.0, h= 0.0, rot= 0.0; |
106 |
DxfGroup g = null;
|
107 |
Point2D pt1 = null, pt2 = null; |
108 |
String txt = null; |
109 |
DxfLayer layer = layers.getByName(grp.getDataAsString(8));
|
110 |
|
111 |
txt = grp.getDataAsString(1);
|
112 |
DxfText entity = new DxfText(proj, layer, txt);
|
113 |
|
114 |
entity.h = grp.getDataAsDouble(40);
|
115 |
x = grp.getDataAsDouble(10);
|
116 |
y = grp.getDataAsDouble(20);
|
117 |
entity.setPt1(proj.createPoint(x, y)); |
118 |
if (grp.hasCode(11)) { |
119 |
x = grp.getDataAsDouble(11);
|
120 |
y = grp.getDataAsDouble(21);
|
121 |
entity.setPt2(proj.createPoint(x, y)); |
122 |
} |
123 |
if (grp.hasCode(50)) |
124 |
entity.rot = grp.getDataAsDouble(50);
|
125 |
if (grp.hasCode(62)) |
126 |
entity.dxfColor = grp.getDataAsInt(62);
|
127 |
if (grp.hasCode(72)) |
128 |
entity.align = grp.getDataAsInt(72);
|
129 |
entities.add(entity); |
130 |
} |
131 |
public void createSolid(DxfGroupVector grp) throws Exception { |
132 |
DxfLayer layer = layers.getByName(grp.getDataAsString(8));
|
133 |
} |
134 |
|
135 |
public Projection getProjection() { return proj;} |
136 |
|
137 |
/**
|
138 |
* Cambia de proyeccion.
|
139 |
*
|
140 |
* @param rp
|
141 |
*/
|
142 |
public void reProject(ReProjection rp) { |
143 |
entities.reProject(rp); |
144 |
} |
145 |
} |
146 |
|
147 |
|
148 |
|