root / trunk / libraries / libDwg / src / com / iver / cit / jdwglib / dwg / DwgHandleReference.java @ 10054
History | View | Annotate | Download (3.19 KB)
1 |
/* jdwglib. Java Library for reading Dwg files.
|
---|---|
2 |
*
|
3 |
* Author: Equipo de desarrollo de gvSIG.
|
4 |
* Port from the Pythoncad Dwg library by Art Haas.
|
5 |
*
|
6 |
* Copyright (C) 2007 IVER TI S.A. and Generalitat Valenciana
|
7 |
*
|
8 |
* This program is free software; you can redistribute it and/or
|
9 |
* modify it under the terms of the GNU General Public License
|
10 |
* as published by the Free Software Foundation; either version 2
|
11 |
* of the License, or (at your option) any later version.
|
12 |
*
|
13 |
* This program is distributed in the hope that it will be useful,
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
* GNU General Public License for more details.
|
17 |
*
|
18 |
* You should have received a copy of the GNU General Public License
|
19 |
* along with this program; if not, write to the Free Software
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
21 |
*
|
22 |
* For more information, contact:
|
23 |
*
|
24 |
* IVER TI S.A.
|
25 |
* C/Salamanca, 50
|
26 |
* 46005 Valencia
|
27 |
* Spain
|
28 |
* +34 963163400
|
29 |
* dac@iver.es
|
30 |
*/package com.iver.cit.jdwglib.dwg; |
31 |
|
32 |
import java.util.ArrayList; |
33 |
|
34 |
import com.iver.cit.gvsig.fmap.drivers.dgn.ByteUtils; |
35 |
|
36 |
public class DwgHandleReference { |
37 |
|
38 |
private Integer code=null; |
39 |
private Integer offset=null; |
40 |
|
41 |
public DwgHandleReference(int code, int offset){ |
42 |
this.code=new Integer(code); |
43 |
this.offset=new Integer(offset); |
44 |
} |
45 |
|
46 |
public DwgHandleReference(){
|
47 |
} |
48 |
|
49 |
public void setCode(int code){ |
50 |
this.code = new Integer(code); |
51 |
} |
52 |
|
53 |
public void setOffset(int offset){ |
54 |
this.offset=new Integer(offset); |
55 |
} |
56 |
|
57 |
public int getCode(){ |
58 |
return this.code.intValue(); |
59 |
} |
60 |
|
61 |
public int getOffset(){ |
62 |
return this.offset.intValue(); |
63 |
} |
64 |
/**
|
65 |
* Read a pair of int values (the HandleCode and HandleOffset of a handle of a DWG object)
|
66 |
* from a group of unsigned bytes and initializes the properties.
|
67 |
*
|
68 |
* @param data Array of unsigned bytes obtained from the DWG binary file
|
69 |
* @param offset The current bit offset where the value begins
|
70 |
* @throws Exception If an unexpected bit value is found in the DWG file. Occurs
|
71 |
* when we are looking for LwPolylines.
|
72 |
* @return int Represents the new offset.
|
73 |
*
|
74 |
* */
|
75 |
|
76 |
public int read(int[] data, int offset) throws RuntimeException, CorruptedDwgEntityException{ |
77 |
ArrayList v = new ArrayList(); |
78 |
int code = ((Integer)DwgUtil.getBits(data, 4, offset)).intValue(); |
79 |
int counter = ((Integer)DwgUtil.getBits(data, 4, (offset + 4))).intValue(); |
80 |
int read = 8; |
81 |
ArrayList hlist = new ArrayList(); |
82 |
if (counter>0) { |
83 |
int hlen = counter * 8; |
84 |
Object handle = DwgUtil.getBits(data, hlen, (offset + 8)); |
85 |
read = read + hlen; |
86 |
if (hlen > 8) { |
87 |
byte[] handleBytes = (byte[])handle; |
88 |
int[] handleInts = new int[handleBytes.length]; |
89 |
// Hacerlos unsigned ...
|
90 |
for (int i=0; i<handleBytes.length; i++) { |
91 |
handleInts[i] = ByteUtils.getUnsigned(handleBytes[i]); |
92 |
} |
93 |
for (int i=0; i<handleInts.length; i++) { |
94 |
hlist.add(new Integer(handleInts[i])); |
95 |
} |
96 |
} else {
|
97 |
hlist.add(handle); |
98 |
} |
99 |
} |
100 |
v.add(new Integer(code)); |
101 |
v.add(new Integer(counter)); |
102 |
for (int i=0;i<hlist.size();i++) { |
103 |
v.add(hlist.get(i)); |
104 |
} |
105 |
setCode(code); |
106 |
setOffset(DwgUtil.handleBinToHandleInt(v)); |
107 |
return offset+read;
|
108 |
} |
109 |
|
110 |
} |