Statistics
| Revision:

svn-gvsig-desktop / branches / v10 / libraries / libDwg / src / com / iver / cit / jdwglib / dwg / readers / objreaders / v1314 / DwgLwPolylineReader1314.java @ 10847

History | View | Annotate | Download (4.41 KB)

1
/*
2
 * Created on 25-ene-2007 by azabala
3
 *
4
 */
5
package com.iver.cit.jdwglib.dwg.readers.objreaders.v1314;
6

    
7
import java.awt.geom.Point2D;
8
import java.util.ArrayList;
9
import java.util.List;
10

    
11
import com.iver.cit.jdwglib.dwg.CorruptedDwgEntityException;
12
import com.iver.cit.jdwglib.dwg.DwgObject;
13
import com.iver.cit.jdwglib.dwg.DwgUtil;
14
import com.iver.cit.jdwglib.dwg.objects.DwgLwPolyline;
15

    
16
/**
17
 * @author alzabord
18
 *
19
 * TODO To change the template for this generated type comment go to
20
 * Window - Preferences - Java - Code Style - Code Templates
21
 */
22
public class DwgLwPolylineReader1314 extends AbstractDwg1314Reader{
23

    
24
        /* (non-Javadoc)
25
         * @see com.iver.cit.jdwglib.dwg.readers.IDwgObjectReader#readSpecificObj(int[], int, com.iver.cit.jdwglib.dwg.DwgObject)
26
         */
27
        public void readSpecificObj(int[] data, int offset, DwgObject dwgObj) throws RuntimeException, CorruptedDwgEntityException {
28
                if(! (dwgObj instanceof DwgLwPolyline))
29
                    throw new RuntimeException("ArcReader 14 solo puede leer DwgLwPolyline");
30
                DwgLwPolyline l = (DwgLwPolyline) dwgObj;
31
                int bitPos = offset;
32
                
33
                bitPos = headTailReader.readObjectHeader(data, bitPos, l);
34
                
35
        
36
                List val = DwgUtil.getBitShort(data, bitPos);
37
                bitPos = ((Integer) val.get(0)).intValue();
38
                int flag = ((Integer) val.get(1)).intValue();
39
                l.setFlag(flag);
40
                
41
                double dVal = 0d;
42
                if((flag & 0x4) > 0){
43
                        val = DwgUtil.getBitDouble(data, bitPos);
44
                        bitPos = ((Integer) val.get(0)).intValue();
45
                        dVal = ((Double) val.get(1)).doubleValue();
46
                }
47
                l.setConstWidth(dVal);
48
                
49
                dVal = 0d;
50
                if((flag & 0x8) > 0){
51
                        val = DwgUtil.getBitDouble(data, bitPos);
52
                        bitPos = ((Integer) val.get(0)).intValue();
53
                        dVal = ((Double) val.get(1)).doubleValue();
54
                }
55
                l.setElevation(dVal);
56
                
57
                dVal = 0d;
58
                if ((flag & 0x2) > 0){
59
                        val = DwgUtil.getBitDouble(data, bitPos);
60
                        bitPos = ((Integer) val.get(0)).intValue();
61
                        dVal = ((Double) val.get(1)).doubleValue();
62
                }
63
                l.setThickness(dVal);
64
                
65
                double x, y, z ;
66
                x = 0d;
67
                y = 0d; 
68
                z = 0d;
69
                
70
                if ((flag & 0x1) > 0){
71
                        val = DwgUtil.getBitDouble(data, bitPos);
72
                        bitPos = ((Integer) val.get(0)).intValue();
73
                        x = ((Double) val.get(1)).doubleValue();
74
                        
75
                        val = DwgUtil.getBitDouble(data, bitPos);
76
                        bitPos = ((Integer) val.get(0)).intValue();
77
                        y = ((Double) val.get(1)).doubleValue();
78
                        
79
                        val = DwgUtil.getBitDouble(data, bitPos);
80
                        bitPos = ((Integer) val.get(0)).intValue();
81
                        z = ((Double) val.get(1)).doubleValue();
82
                }
83
                l.setNormal(new double[]{x, y, z});
84
                
85
                val = DwgUtil.getBitLong(data, bitPos);
86
                bitPos = ((Integer) val.get(0)).intValue();
87
                int np = ((Integer) val.get(1)).intValue();
88
                
89
                int nb = 0;
90
                if((flag & 0x10) > 0){
91
                        val = DwgUtil.getBitLong(data, bitPos);
92
                        bitPos = ((Integer) val.get(0)).intValue();
93
                        nb = ((Integer) val.get(1)).intValue();
94
                }
95
                if(nb > 10000)
96
                    throw new CorruptedDwgEntityException("LwPolyline corrupta");
97
                
98
                int nw = 0;
99
                if((flag & 0x20) > 0){
100
                        val = DwgUtil.getBitLong(data, bitPos);
101
                        bitPos = ((Integer) val.get(0)).intValue();
102
                        nw = ((Integer) val.get(1)).intValue();
103
                }
104
                
105
                if(nw > 10000)
106
                    throw new CorruptedDwgEntityException("LwPolyline corrupta");
107
                
108
                if(np > 0){
109
                        if(np > 10000)
110
                            throw new CorruptedDwgEntityException("LwPolyline corrupta");
111
                        List points = new ArrayList();
112
                        for(int i = 0; i < np; i++){
113
                                val = DwgUtil.getRawDouble(data, bitPos);
114
                                bitPos = ((Integer) val.get(0)).intValue();
115
                                x = ((Double) val.get(1)).doubleValue();
116
                                
117
                                val = DwgUtil.getRawDouble(data, bitPos);
118
                                bitPos = ((Integer) val.get(0)).intValue();
119
                                y = ((Double) val.get(1)).doubleValue();
120
                                
121
                                points.add(new double[]{x,y});
122
                        }//for
123
                        l.setVertices(points);
124
                }//if np
125
                
126
                if(nb > 0){
127
                        double[] bulges = new double[nb];
128
                        for(int i = 0; i < nb; i++){
129
                                val = DwgUtil.getRawDouble(data, bitPos);
130
                                bitPos = ((Integer) val.get(0)).intValue();
131
                                bulges[i] = ((Double) val.get(1)).doubleValue();
132
                        }//for
133
                        l.setBulges(bulges);
134
                }//if nb
135
                
136
                if(nw > 0){
137
                        double[][] widths = new double[nw][2];
138
                        for(int i = 0; i < nw; i++){
139
                                val = DwgUtil.getBitDouble(data, bitPos);
140
                                bitPos = ((Integer) val.get(0)).intValue();
141
                                double sw = ((Double) val.get(1)).doubleValue();
142
                                
143
                                val = DwgUtil.getBitDouble(data, bitPos);
144
                                bitPos = ((Integer) val.get(0)).intValue();
145
                                double ew = ((Double) val.get(1)).doubleValue();
146
                                
147
                                widths[i][0] = sw;
148
                                widths[i][1] = ew;
149
                        }//for
150
                        l.setWidths(widths);
151
                }
152
                bitPos = headTailReader.readObjectTailer(data, bitPos, l);
153
        }
154
}