Statistics
| Revision:

root / trunk / libraries / libDwg / src-test / com / iver / cit / jdwglib / dwg / DwgFileTest.java @ 10361

History | View | Annotate | Download (11.6 KB)

1
package com.iver.cit.jdwglib.dwg;
2

    
3
import java.awt.geom.Point2D;
4
import java.io.File;
5
import java.io.FileInputStream;
6
import java.io.FileNotFoundException;
7
import java.io.IOException;
8
import java.net.URL;
9
import java.nio.ByteBuffer;
10
import java.nio.ByteOrder;
11
import java.nio.channels.FileChannel;
12
import java.util.LinkedList;
13
import java.util.List;
14

    
15
import com.iver.cit.jdwglib.dwg.readers.DwgFileV15Reader;
16
import com.iver.cit.jdwglib.dwg.readers.IDwgFileReader;
17
import com.iver.cit.jdwglib.util.AcadExtrusionCalculator;
18

    
19
import junit.framework.TestCase;
20

    
21
public class DwgFileTest extends TestCase {
22
        private File baseDataPath;
23

    
24
        protected void setUp() throws Exception {
25
                super.setUp();
26
                URL url = this.getClass().getResource("DwgFileTest_data");
27
                if (url == null) 
28
                        throw new Exception("Can't find 'DwgFileTest_data' dir");
29
                
30
                baseDataPath = new File(url.getFile());
31
                if (!baseDataPath.exists()) 
32
                        throw new Exception("Can't find 'DwgFileTest_data' dir");
33
                
34
        }
35

    
36
        protected void tearDown() throws Exception {
37
                super.tearDown();
38
        }
39
        public void test1() throws IOException, DwgVersionNotSupportedException {
40
//                String fileName = baseDataPath.getAbsolutePath()+"/Un punto.dwg";
41
//                DwgFile dwg = new DwgFile(fileName);
42
//
43
//                dwg.read();
44
//                dwg.calculateGisModelDwgPolylines();
45
//                dwg.blockManagement();
46
//                LinkedList dwgObjects = dwg.getDwgObjects();
47
        }
48
        
49
        public void test2() throws RuntimeException, CorruptedDwgEntityException{
50
        //Dwg Object that is supposed to be
51
        //an LWPOLYLINE in V14 version
52
                /*
53
        int[] data = new int[]{61,64,64,183,19,227,104,16
54
                            ,0,5,8,59,72,32,252,47,90,142,
55
                            234,145,50,10,71,11,213,36,229,
56
                            162,130,10,228,126,23,174,130,
57
                            145,50,15,98,141,196,244,229,
58
                            162,130,12,126,23,169,66,58,
59
                            145,50,12,47,90,138,68,229,
60
                            162,130,8,0,0,4,7,74,137,50,
61
                            15,177,66,231,252,221,162,130,
62
                            9,130,151,21,242,151,21,190,
63
                            8,21,8,56};
64
         */
65
//                int[] data = new int[]{62,128,64,71,99,
66
//                                                           40,48,0,5,8,27,72,
67
//                                                           100,126,23,169,68,
68
//                                                           178,105,50,13,114,
69
//                                                           63,11,82,165,162,130,
70
//                                                           13,114,63,11,210,138,
71
//                                                           105,50,8,173,114,59,
72
//                                                           138,205,162,130,15,98,
73
//                                                           141,192,241,58,105,50,
74
//                                                           11,51,51,52,178,229,162,
75
//                                                           130,14,110,102,98,97,234,
76
//                                                           105,50,11,51,51,52,179,21,
77
//                                                           162,130,10,149,192,240,42,
78
//                                                           162,105,50,14,189,27,131,
79
//                                                           107,69,162,130,14,31,169,
80
//                                                           66,227,74,105,50,9,240,86,
81
//                                                           185,27,117,162,130,11,59,
82
//                                                           51,51,52,234,105,50,13,114,
83
//                                                           63,11,83,85,162,130,9,74,228,
84
//                                                           126,22,186,105,50,11,51,51,50,
85
//                                                           51,53,162,130,11,137,232,82,190,
86
//                                                           58,105,50,9,74,228,122,147,13,162,
87
//                                                           130,11,137,232,82,189,106,105,50,9,
88
//                                                           74,228,122,146,213,162,130,9,74,228,122,20,202,105,50,12,126,23,171,194,173,162,130,12,126,23,169,68,178,105,50,13,114,63,11,82,165,162,130,9,130,151,22,10,136,182,8,21,8,120};
89
//        //1er intento: suponemos que la LWPOLYLINE cumple la especificaci?n
90
//        //a rajatabla
91
//        int bitPos = 0;
92
//        List val = DwgUtil.getBitShort(data, bitPos);
93
//        bitPos = ((Integer) val.get(0)).intValue();
94
//        int type = ((Integer) val.get(1)).intValue();
95
//        System.out.println("type = " + type);
96
//       
97
//        DwgHandleReference hr = new DwgHandleReference();
98
//        bitPos = hr.read(data, bitPos);
99
//        System.out.println("handle, code="+
100
//                    hr.getCode()+
101
//                    " ,offset="+
102
//                    hr.getOffset());
103
//       
104
//        //Ahora pasamos a la extended data
105
//        val = DwgUtil.getBitShort(data, bitPos);
106
//        bitPos = ((Integer) val.get(0)).intValue();
107
//        int extendedDataSize = ((Integer) val.get(1)).intValue();
108
//        System.out.println("EED size="+extendedDataSize);
109
//        //como el size es 0, me lo salto
110
//       
111
//        //ver si tiene datos graficos
112
//        val = DwgUtil.testBit(data, bitPos);
113
//        bitPos = ((Integer) val.get(0)).intValue();
114
//        boolean hasGraphicsData = ((Boolean) val.get(1))
115
//                .booleanValue();
116
//        System.out.println("graphics = "+hasGraphicsData);
117
//       
118
//        //como se que no hay graphics me lo salto
119
//        //tama?o en bits
120
//        val = DwgUtil.getRawLong(data, bitPos);
121
//        bitPos = ((Integer) val.get(0)).intValue();
122
//        int sizeInBits = ((Integer) val.get(1)).intValue();
123
//        System.out.println("sizeInBits = "+sizeInBits);
124
//        
125
//        /*
126
//         * Ahora, lo que viene es lo que en la spec se dice
127
//         * "Common entity data". Revisar bien pues PythonCAD no lo lee
128
//         * como en la spec.
129
//         * 
130
//         * pag 42.
131
//          R13-R14 Only:
132
//                  RL        :        Size of object data in bits
133
//                  6B        :        Flags (FEDCBA)
134
//                  6B        :        Common parameters (CCSSII)
135
//                  Segun esto, deberia leer 6 bits y 6 bits
136
//                  
137
//                  FLAGS
138
//                      Mas adelante (pag 43), dice:
139
//                      DC        :        This is the number of reactors attached to an 
140
//                      entity as a bitshort. 
141
//                      This feature may have been dormant in R13, 
142
//                      but it appears in R14, and in files saved as R13 by R14.
143
//                      
144
//                      Ahora bien, pythoncad las est? leyendo como bitLong
145
//                  ?En que quedamos, son 2 bits, 1 bitLong o 1 bitShort?
146
//                  TODO REVISAR
147
//                  
148
//                  COMMON PARAMETERS
149
//                  Al principio, dice que son 6 bits (CC, SS, II)
150
//                  pero luego dice (pag 43):
151
//                  CC        :        Color bitshort
152
//                  SS        :        Linetype scale bitdouble
153
//                  II        :        "Invisible" flag bitshort
154
//
155
//                        Pythoncad, en vez de como 2 bits, los est? leyendo
156
//                        como BitShort, BitDouble y BitShort
157
//                  
158
//         * */
159
//        
160
//        Integer mode = (Integer) DwgUtil.getBits(data, 2, bitPos);
161
//                bitPos += 2;
162
//                System.out.println("mode = "+mode);
163
//                
164
//        /*
165
//                val = DwgUtil.getBitLong(data, bitPos);
166
//                bitPos = ((Integer) val.get(0)).intValue();
167
//                int rnum = ((Integer) val.get(1)).intValue();
168
//                System.out.println("numReactors = "+rnum);
169
//*/
170
//                val = DwgUtil.getBitShort(data, bitPos);
171
//                bitPos = ((Integer) val.get(0)).intValue();
172
//                int rnum = ((Integer) val.get(1)).intValue();
173
//                System.out.println("numReactors = "+rnum);
174
//                
175
//                
176
//                val = DwgUtil.testBit(data, bitPos);
177
//                bitPos = ((Integer) val.get(0)).intValue();
178
//                boolean isLyrByLineType = ((Boolean) val.get(1)).booleanValue();
179
//                System.out.println("isLyrByLineType="+isLyrByLineType);
180
//                
181
//                val = DwgUtil.testBit(data, bitPos);
182
//                bitPos = ((Integer) val.get(0)).intValue();
183
//                boolean noLinks = ((Boolean) val.get(1)).booleanValue();
184
//                System.out.println("noLinks="+noLinks);
185
//
186
//                
187
//                val = DwgUtil.getBitShort(data, bitPos);
188
//                bitPos = ((Integer) val.get(0)).intValue();
189
//                int color = ((Integer) val.get(1)).intValue();
190
//                System.out.println("color="+color);
191
//                
192
//                
193
//                val = DwgUtil.getBitDouble(data, bitPos);
194
//                bitPos = ((Integer) val.get(0)).intValue();
195
//                float ltscale = ((Double) val.get(1)).floatValue();
196
//                System.out.println("ltscale="+ltscale);
197
//                
198
//                val = DwgUtil.getBitShort(data, bitPos);
199
//                bitPos = ((Integer) val.get(0)).intValue();
200
//                int invis = ((Integer) val.get(1)).intValue();
201
//                System.out.println("invis="+invis);
202
//                
203
//                val = DwgUtil.getBitShort(data, bitPos);
204
//                bitPos = ((Integer) val.get(0)).intValue();
205
//                int flag = ((Integer) val.get(1)).intValue();
206
//                System.out.println("flag="+flag);
207
//                
208
//                double dVal = 0d;
209
//                if((flag & 0x4) > 0){
210
//                        val = DwgUtil.getBitDouble(data, bitPos);
211
//                        bitPos = ((Integer) val.get(0)).intValue();
212
//                        dVal = ((Double) val.get(1)).doubleValue();
213
//                }
214
//                System.out.println("constWidth="+dVal);
215
//                
216
//                dVal = 0d;
217
//                if((flag & 0x8) > 0){
218
//                        val = DwgUtil.getBitDouble(data, bitPos);
219
//                        bitPos = ((Integer) val.get(0)).intValue();
220
//                        dVal = ((Double) val.get(1)).doubleValue();
221
//                }
222
//                System.out.println("elevation="+dVal);
223
//                
224
//                dVal = 0d;
225
//                if ((flag & 0x2) > 0){
226
//                        val = DwgUtil.getBitDouble(data, bitPos);
227
//                        bitPos = ((Integer) val.get(0)).intValue();
228
//                        dVal = ((Double) val.get(1)).doubleValue();
229
//                }
230
//                System.out.println("thickness="+dVal);
231
//                
232
//                double x, y, z ;
233
//                x = 0d;
234
//                y = 0d; 
235
//                z = 0d;
236
//                
237
//                if ((flag & 0x1) > 0){
238
//                        val = DwgUtil.getBitDouble(data, bitPos);
239
//                        bitPos = ((Integer) val.get(0)).intValue();
240
//                        x = ((Double) val.get(1)).doubleValue();
241
//                        
242
//                        val = DwgUtil.getBitDouble(data, bitPos);
243
//                        bitPos = ((Integer) val.get(0)).intValue();
244
//                        y = ((Double) val.get(1)).doubleValue();
245
//                        
246
//                        val = DwgUtil.getBitDouble(data, bitPos);
247
//                        bitPos = ((Integer) val.get(0)).intValue();
248
//                        z = ((Double) val.get(1)).doubleValue();
249
//                }
250
//                System.out.println("normal="+x+","+y+","+z);
251
//                
252
//                val = DwgUtil.getBitLong(data, bitPos);
253
//                bitPos = ((Integer) val.get(0)).intValue();
254
//                int np = ((Integer) val.get(1)).intValue();
255
//                System.out.println("numPoints="+np);
256
//                
257
//                int nb = 0;
258
//                if((flag & 0x10) > 0){
259
//                        val = DwgUtil.getBitLong(data, bitPos);
260
//                        bitPos = ((Integer) val.get(0)).intValue();
261
//                        nb = ((Integer) val.get(1)).intValue();
262
//                }
263
//                System.out.println("numBulges="+nb);
264
//                int nw = 0;
265
//                if((flag & 0x20) > 0){
266
//                        val = DwgUtil.getBitLong(data, bitPos);
267
//                        bitPos = ((Integer) val.get(0)).intValue();
268
//                        nw = ((Integer) val.get(1)).intValue();
269
//                }
270
//                System.out.println("numWidths="+nw);
271
//                if(np > 0){
272
//                        Point2D[] points = new Point2D[np];
273
//                        for(int i = 0; i < np; i++){
274
//                                val = DwgUtil.getRawDouble(data, bitPos);
275
//                                bitPos = ((Integer) val.get(0)).intValue();
276
//                                x = ((Double) val.get(1)).doubleValue();
277
//                                
278
//                                val = DwgUtil.getRawDouble(data, bitPos);
279
//                                bitPos = ((Integer) val.get(0)).intValue();
280
//                                y = ((Double) val.get(1)).doubleValue();
281
//                                
282
//                                points[i] = new Point2D.Double(x, y);
283
//                                System.out.println("Punto"+i+"="+x+","+y);
284
//                        }//for
285
//                }//if np
286
//                
287
//                if(nb > 0){
288
//                        double[] bulges = new double[nb];
289
//                        for(int i = 0; i < nb; i++){
290
//                                val = DwgUtil.getRawDouble(data, bitPos);
291
//                                bitPos = ((Integer) val.get(0)).intValue();
292
//                                bulges[i] = ((Double) val.get(1)).doubleValue();
293
//                                System.out.println("Bulge"+i+"="+bulges[i]);
294
//                        }//for
295
//                        
296
//                }//if nb
297
//                
298
//                if(nw > 0){
299
//                        double[][] widths = new double[nw][2];
300
//                        for(int i = 0; i < nw; i++){
301
//                                val = DwgUtil.getBitDouble(data, bitPos);
302
//                                bitPos = ((Integer) val.get(0)).intValue();
303
//                                double sw = ((Double) val.get(1)).doubleValue();
304
//                                
305
//                                val = DwgUtil.getBitDouble(data, bitPos);
306
//                                bitPos = ((Integer) val.get(0)).intValue();
307
//                                double ew = ((Double) val.get(1)).doubleValue();
308
//                                
309
//                                widths[i][0] = sw;
310
//                                widths[i][1] = ew;
311
//                                System.out.println("Width"+i+"="+sw+","+ew);
312
//                        }//for
313
//                }
314
     }
315
        
316
        public void test3(){
317
                //test of extrusion
318
                double[] coord = null;
319
                double[] extrusion = null;
320
                double[] extrusion2 = new double[]{0, 0, 1};
321
                
322
                coord = new double[]{790089.65, 4477974.75, 9.560000000114087};
323
                extrusion = new double[]{-0.5037965987025721, 0.07005064807841195, 0.8609772899673451};
324
                //1. algoritmo original, vector normal distinto
325
                double[] newCoord = AcadExtrusionCalculator.extrude(coord, extrusion); 
326
                newCoord = AcadExtrusionCalculator.extrude3(coord, extrusion); 
327
                
328
                //2? ahora con vector normal coincidente con eje Z
329
                newCoord = AcadExtrusionCalculator.extrude(coord, extrusion2); 
330
                newCoord = AcadExtrusionCalculator.extrude3(coord, extrusion2); 
331
        }
332
}