Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libCq CMS for java.old / src / org / cresques / px / dxf / DxfEntityMaker.java @ 20

History | View | Annotate | Download (4.82 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.Extent;
16
import org.cresques.px.PxObj;
17

    
18
/**
19
 * Contructor de objetos Dxf 
20
 * 
21
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
22
 */
23

    
24
public class DxfEntityMaker implements DxfFile.EntityFactory, Projected {
25
        Projection proj = null;
26
        DxfEntity lastEntity = null;
27
        DxfEntityList entities = null;
28
        DxfTable layers = null;
29
        
30
    double xtruX=0.0, xtruY=0.0, xtruZ=1.0;
31
    double x=Double.NaN, y=Double.NaN, z=Double.NaN;
32
        
33
        public DxfEntityMaker (Projection proj) {
34
                this.proj = proj;
35
                layers = new DxfTable();
36
                entities = new DxfEntityList(proj);
37
        }
38
        
39
        public PxObj getObjects() { return entities; }
40
        public Extent getExtent() { return entities.getExtent(); }
41

    
42
        public void createLayer(DxfGroupVector grp) throws Exception {
43
                DxfLayer layer = new DxfLayer(grp.getDataAsString(2), grp.getDataAsInt(62));
44
                layer.lType = grp.getDataAsString(6);
45
                layer.setFlags(grp.getDataAsInt(70));
46
                layers.add(layer);
47
        }
48
        
49
        public void createPolyline(DxfGroupVector grp) throws Exception {
50
                DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
51
                DxfPolyline entity = new DxfPolyline(proj, layer);
52
                
53
                if (grp.hasCode(10))
54
                        x = grp.getDataAsInt(10);
55
                if (grp.hasCode(20))
56
                        y = grp.getDataAsInt(20);
57
                if (grp.hasCode(30))
58
                        z = grp.getDataAsInt(30);
59
                if (grp.hasCode(210))
60
                        xtruX = grp.getDataAsInt(210);
61
                if (grp.hasCode(220))
62
                        xtruY = grp.getDataAsInt(220);
63
                if (grp.hasCode(230))
64
                        xtruZ = grp.getDataAsInt(230);
65
                if (grp.hasCode(62))
66
                        entity.dxfColor = grp.getDataAsInt(62);
67
                if (grp.hasCode(70))
68
                        entity.flags = grp.getDataAsInt(70);
69
                lastEntity = entity;
70
        }
71
        public void endSeq() throws Exception {
72
                entities.add(lastEntity);
73
                lastEntity = null;
74
        }
75
        public void addVertex(DxfGroupVector grp) throws Exception {
76
                double x = 0.0, y = 0.0;
77
                
78
                x  = grp.getDataAsDouble(10);
79
                y  = grp.getDataAsDouble(20);
80
                
81
                x = 
82
                
83
                //System.out.println(x+","+y);
84
                Point2D pt = proj.createPoint( x, y);
85
                ((DxfPolyline) lastEntity).add(pt);
86
        }
87
        public void createLwPolyline(DxfGroupVector grp) throws Exception {
88
                double x = 0.0, y = 0.0, elev=0.0;
89
                DxfGroup g = null;
90
                
91
                if (grp.hasCode(38))
92
                        elev = grp.getDataAsDouble(38);
93
                DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
94
                DxfLwPolyline entity = new DxfLwPolyline(proj, layer);
95
                for (int i=0; i<grp.size(); i++) {
96
                        g = (DxfGroup) grp.get(i);
97
                        if (g.getCode() == 10)
98
                                x = ((Float) g.getData()).doubleValue();
99
                        else if (g.getCode() == 20) {
100
                                y = ((Float) g.getData()).doubleValue();
101
                                //if (y <= 1.0) throw new Exception("Y == "+y);
102
                                entity.add( proj.createPoint( x, y ) );
103
                                x = 0.0; y = 0.0;
104
                        }
105
                }
106
                if (grp.hasCode(62))
107
                        entity.dxfColor = grp.getDataAsInt(62);
108
                if (grp.hasCode(70))
109
                        entity.flags = grp.getDataAsInt(70);
110
                entities.add(entity);
111
        }
112
        
113
        public void createLine(DxfGroupVector grp) throws Exception {
114
                double x = 0.0, y = 0.0;
115
                DxfGroup g = null;
116
                Point2D pt1 = null, pt2 = null;
117
                DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
118

    
119
                x = grp.getDataAsDouble(10);
120
                y = grp.getDataAsDouble(20);
121
                pt1 = proj.createPoint(x, y);
122
                x = grp.getDataAsDouble(11);
123
                y = grp.getDataAsDouble(21);
124
                pt2 = proj.createPoint(x, y);
125
                DxfLine entity = new DxfLine(proj, layer, pt1, pt2);
126
                if (grp.hasCode(62))
127
                        entity.dxfColor = grp.getDataAsInt(62);
128
                entities.add(entity);
129
        }
130
        public void createText(DxfGroupVector grp) throws Exception {
131
                double x = 0.0, y = 0.0, h= 0.0, rot= 0.0;
132
                DxfGroup g = null;
133
                Point2D pt1 = null, pt2 = null;
134
                String txt = null;
135
                DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
136

    
137
                txt = grp.getDataAsString(1);
138
                DxfText entity = new DxfText(proj, layer, txt);
139

    
140
                entity.h = grp.getDataAsDouble(40);
141
                x = grp.getDataAsDouble(10);
142
                y = grp.getDataAsDouble(20);
143
                entity.setPt1(proj.createPoint(x, y));
144
                if (grp.hasCode(11)) {
145
                        x = grp.getDataAsDouble(11);
146
                        y = grp.getDataAsDouble(21);
147
                        entity.setPt2(proj.createPoint(x, y));
148
                }
149
                if (grp.hasCode(50))
150
                        entity.rot = grp.getDataAsDouble(50);
151
                if (grp.hasCode(62))
152
                        entity.dxfColor = grp.getDataAsInt(62);
153
                if (grp.hasCode(72))
154
                        entity.align = grp.getDataAsInt(72);
155
                entities.add(entity);
156
        }
157
        public void createSolid(DxfGroupVector grp) throws Exception {
158
                DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
159
        }
160

    
161
        public Projection getProjection() { return proj;}
162

    
163
        /**
164
         * Cambia de proyeccion.
165
         * 
166
         * @param rp
167
         */
168
        public void reProject(ReProjection rp) {
169
                entities.reProject(rp);
170
        }
171
        public DxfEntityList getEntities() { return entities;}
172
        public DxfTable getLayers() { return layers;}
173

    
174
}
175

    
176

    
177