Revision 10539 branches/v10/libraries/libDwg/src/com/iver/cit/jdwglib/dwg/objects/DwgBlockHeader.java

View differences:

DwgBlockHeader.java
34 34
 */
35 35
package com.iver.cit.jdwglib.dwg.objects;
36 36

  
37
import java.util.ArrayList;
38 37
import java.util.Vector;
39 38

  
39
import com.iver.cit.jdwglib.dwg.DwgHandleReference;
40 40
import com.iver.cit.jdwglib.dwg.DwgObject;
41
import com.iver.cit.jdwglib.dwg.DwgUtil;
41
import com.iver.cit.jdwglib.dwg.IDwg3DTestable;
42 42

  
43 43
/**
44 44
 * The DwgBlockHeader class represents a DWG Block header
45 45
 * 
46
 * @author jmorell
46
 * @author jmorell, azabala
47 47
 */
48
public class DwgBlockHeader extends DwgObject {
48
public class DwgBlockHeader extends DwgObject implements IDwg3DTestable {
49 49
	private String name;
50 50
	private boolean flag64;
51 51
	private int xRefPlus;
52 52
	private boolean xdep;
53 53
	private boolean anonymous;
54 54
	private boolean hasAttrs;
55
	
56
	//TODO REVISAR COMO TRATAR UN BLOQUE CUANDO ES UNA REFERENCIA
57
	//EXTERNA (DwgFile.blockManagement() )
55 58
	private boolean blkIsXRef;
56 59
	private boolean xRefOverLaid;
57 60
	private boolean loaded;
......
59 62
	private String xRefPName;
60 63
	private String blockDescription;
61 64
	private int previewData;
62
	private int blockControlHandle;
63
	private int nullHandle;
64
	private int blockEntityHandle;
65
	private int firstEntityHandle;
66
	private int lastEntityHandle;
67
	private int endBlkEntityHandle;
68
	private Vector insertHandles;
69
	private int layoutHandle;
65
	
66
	private DwgHandleReference blockControlHandle;
67
	private DwgHandleReference nullHandle;
68
	private DwgHandleReference blockEntityHandle;
69
	private DwgHandleReference firstEntityHandle;
70
	private DwgHandleReference lastEntityHandle;
71
	private DwgHandleReference endBlkEntityHandle;
72
	
73
	
74
	private DwgHandleReference[] insertHandles;
75
	
76
	private DwgHandleReference layoutHandle;
70 77
	private Vector objects;
71 78
	
72 79
	/**
73 80
	 * Create new DwgBlockHeader object
74 81
	 */
75
	public DwgBlockHeader() {
82
	public DwgBlockHeader(int index) {
83
		super(index);
76 84
		objects = new Vector();
77 85
	}
86
	
78 87
	/**
79
	 * Read a Block header in the DWG format Version 15
80
	 * 
81
	 * @param data Array of unsigned bytes obtained from the DWG binary file
82
	 * @param offset The current bit offset where the value begins
83
	 * @throws Exception If an unexpected bit value is found in the DWG file. Occurs
84
	 * 		   when we are looking for LwPolylines.
85
	 */
86
	public void readDwgBlockHeaderV15(int[] data, int offset) throws Exception {
87
		int bitPos = offset;
88
		ArrayList v = DwgUtil.getBitLong(data, bitPos);
89
		bitPos = ((Integer)v.get(0)).intValue();
90
		int numReactors = ((Integer)v.get(1)).intValue();
91
		setNumReactors(numReactors);
92
		v = DwgUtil.getTextString(data, bitPos);
93
		bitPos = ((Integer)v.get(0)).intValue();
94
		String name = (String)v.get(1);
95
		this.name = name;
96
		v = DwgUtil.testBit(data, bitPos);
97
		bitPos = ((Integer)v.get(0)).intValue();
98
		boolean flag = ((Boolean)v.get(1)).booleanValue();
99
		flag64 = flag;
100
		v = DwgUtil.getBitShort(data, bitPos);
101
		bitPos = ((Integer)v.get(0)).intValue();
102
		int xrefplus1 = ((Integer)v.get(1)).intValue();
103
		xRefPlus = xrefplus1;
104
		v = DwgUtil.testBit(data, bitPos);
105
		bitPos = ((Integer)v.get(0)).intValue();
106
		boolean xdep = ((Boolean)v.get(1)).booleanValue();
107
		this.xdep = xdep;
108
		v = DwgUtil.testBit(data, bitPos);
109
		bitPos = ((Integer)v.get(0)).intValue();
110
		boolean anon = ((Boolean)v.get(1)).booleanValue();
111
		anonymous = anon;
112
		v = DwgUtil.testBit(data, bitPos);
113
		bitPos = ((Integer)v.get(0)).intValue();
114
		boolean hasatts = ((Boolean)v.get(1)).booleanValue();
115
		hasAttrs = hasatts;
116
		v = DwgUtil.testBit(data, bitPos);
117
		bitPos = ((Integer)v.get(0)).intValue();
118
		boolean bxref = ((Boolean)v.get(1)).booleanValue();
119
		blkIsXRef = bxref;
120
		v = DwgUtil.testBit(data, bitPos);
121
		bitPos = ((Integer)v.get(0)).intValue();
122
		boolean xover = ((Boolean)v.get(1)).booleanValue();
123
		xRefOverLaid = xover;
124
		v = DwgUtil.testBit(data, bitPos);
125
		bitPos = ((Integer)v.get(0)).intValue();
126
		boolean loaded = ((Boolean)v.get(1)).booleanValue();
127
		this.loaded = loaded;
128
		v = DwgUtil.getBitDouble(data, bitPos);
129
		bitPos = ((Integer)v.get(0)).intValue();
130
		double bx = ((Double)v.get(1)).doubleValue();
131
		v = DwgUtil.getBitDouble(data, bitPos);
132
		bitPos = ((Integer)v.get(0)).intValue();
133
		double by = ((Double)v.get(1)).doubleValue();
134
		v = DwgUtil.getBitDouble(data, bitPos);
135
		bitPos = ((Integer)v.get(0)).intValue();
136
		double bz = ((Double)v.get(1)).doubleValue();
137
		double[] coord = new double[]{bx, by, bz};
138
		basePoint = coord;
139
		v = DwgUtil.getTextString(data, bitPos);
140
		bitPos = ((Integer)v.get(0)).intValue();
141
		String pname = (String)v.get(1);
142
		xRefPName = pname;
143
		int icount = 0;
144
		while (true) {
145
			v = DwgUtil.getRawChar(data, bitPos);
146
			bitPos = ((Integer)v.get(0)).intValue();
147
			int val = ((Integer)v.get(1)).intValue();
148
			if (val==0) {
149
				break;
150
			}
151
			icount++;
152
		}
153
		v = DwgUtil.getTextString(data, bitPos);
154
		bitPos = ((Integer)v.get(0)).intValue();
155
		String desc = (String)v.get(1);
156
		blockDescription = desc;
157
		v = DwgUtil.getBitLong(data, bitPos);
158
		bitPos = ((Integer)v.get(0)).intValue();
159
		int pdsize = ((Integer)v.get(1)).intValue();
160
		if (pdsize>0) {
161
			int count = pdsize + icount;
162
			//int pdata = ((Integer)DwgUtil.getBits(data, count, bitPos)).intValue();
163
			//previewData = pdata;
164
			bitPos = bitPos + count;
165
		}
166
		v = DwgUtil.getHandle(data, bitPos);
167
		bitPos = ((Integer)v.get(0)).intValue();
168
		int[] handle = new int[v.size()-1];
169
	    for (int j=1;j<v.size();j++) {
170
		    handle[j-1] = ((Integer)v.get(j)).intValue();
171
	    }
172
	    ArrayList handleVect = new ArrayList();
173
	    for (int i=0;i<handle.length;i++) {
174
	    	handleVect.add(new Integer(handle[i]));
175
	    }
176
	    blockControlHandle = DwgUtil.handleBinToHandleInt(handleVect);
177
		for (int i=0;i<numReactors;i++) {
178
			v = DwgUtil.getHandle(data, bitPos);
179
			bitPos = ((Integer)v.get(0)).intValue();
180
			handle = new int[v.size()-1];
181
		    for (int j=1;j<v.size();j++) {
182
			    handle[j-1] = ((Integer)v.get(j)).intValue();
183
		    }
184
		}
185
		v = DwgUtil.getHandle(data, bitPos);
186
		bitPos = ((Integer)v.get(0)).intValue();
187
		handle = new int[v.size()-1];
188
	    for (int j=1;j<v.size();j++) {
189
		    handle[j-1] = ((Integer)v.get(j)).intValue();
190
	    }
191
		v = DwgUtil.getHandle(data, bitPos);
192
		bitPos = ((Integer)v.get(0)).intValue();
193
		handle = new int[v.size()-1];
194
	    for (int j=1;j<v.size();j++) {
195
		    handle[j-1] = ((Integer)v.get(j)).intValue();
196
	    }
197
	    handleVect = new ArrayList();
198
	    for (int i=0;i<handle.length;i++) {
199
	    	handleVect.add(new Integer(handle[i]));
200
	    }
201
	    nullHandle = DwgUtil.handleBinToHandleInt(handleVect);
202
		v = DwgUtil.getHandle(data, bitPos);
203
		bitPos = ((Integer)v.get(0)).intValue();
204
		handle = new int[v.size()-1];
205
	    for (int j=1;j<v.size();j++) {
206
		    handle[j-1] = ((Integer)v.get(j)).intValue();
207
	    }
208
	    handleVect = new ArrayList();
209
	    for (int i=0;i<handle.length;i++) {
210
	    	handleVect.add(new Integer(handle[i]));
211
	    }
212
	    blockEntityHandle = DwgUtil.handleBinToHandleInt(handleVect);
213
		if ((!bxref) && (!xover)) {
214
			v = DwgUtil.getHandle(data, bitPos);
215
			bitPos = ((Integer)v.get(0)).intValue();
216
			handle = new int[v.size()-1];
217
		    for (int j=1;j<v.size();j++) {
218
			    handle[j-1] = ((Integer)v.get(j)).intValue();
219
		    }
220
		    handleVect = new ArrayList();
221
		    for (int i=0;i<handle.length;i++) {
222
		    	handleVect.add(new Integer(handle[i]));
223
		    }
224
		    firstEntityHandle = DwgUtil.handleBinToHandleInt(handleVect);
225
			v = DwgUtil.getHandle(data, bitPos);
226
			bitPos = ((Integer)v.get(0)).intValue();
227
			handle = new int[v.size()-1];
228
		    for (int j=1;j<v.size();j++) {
229
			    handle[j-1] = ((Integer)v.get(j)).intValue();
230
		    }
231
		    handleVect = new ArrayList();
232
		    for (int i=0;i<handle.length;i++) {
233
		    	handleVect.add(new Integer(handle[i]));
234
		    }
235
		    lastEntityHandle = DwgUtil.handleBinToHandleInt(handleVect);
236
		}
237
		v = DwgUtil.getHandle(data, bitPos);
238
		bitPos = ((Integer)v.get(0)).intValue();
239
		handle = new int[v.size()-1];
240
	    for (int j=1;j<v.size();j++) {
241
		    handle[j-1] = ((Integer)v.get(j)).intValue();
242
	    }
243
	    handleVect = new ArrayList();
244
	    for (int i=0;i<handle.length;i++) {
245
	    	handleVect.add(new Integer(handle[i]));
246
	    }
247
	    endBlkEntityHandle = DwgUtil.handleBinToHandleInt(handleVect);
248
		if (icount>0) {
249
			Vector handles = new Vector();
250
			for (int i=0;i<icount;i++) {
251
				v = DwgUtil.getHandle(data, bitPos);
252
				bitPos = ((Integer)v.get(0)).intValue();
253
				handle = new int[v.size()-1];
254
			    for (int j=1;j<v.size();j++) {
255
				    handle[j-1] = ((Integer)v.get(j)).intValue();
256
			    }
257
				handles.add(handle);
258
			}
259
		    insertHandles = handles;
260
		}
261
		v = DwgUtil.getHandle(data, bitPos);
262
		bitPos = ((Integer)v.get(0)).intValue();
263
		handle = new int[v.size()-1];
264
	    for (int j=1;j<v.size();j++) {
265
		    handle[j-1] = ((Integer)v.get(j)).intValue();
266
	    }
267
	    handleVect = new ArrayList();
268
	    for (int i=0;i<handle.length;i++) {
269
	    	handleVect.add(new Integer(handle[i]));
270
	    }
271
	    layoutHandle = DwgUtil.handleBinToHandleInt(handleVect);
272
	}
273
	/**
274 88
	 * @return Returns the basePoint.
275 89
	 */
276 90
	public double[] getBasePoint() {
......
285 99
	/**
286 100
	 * @return Returns the firstEntityHandle.
287 101
	 */
288
	public int getFirstEntityHandle() {
102
	public DwgHandleReference getFirstEntityHandle() {
289 103
		return firstEntityHandle;
290 104
	}
291 105
	/**
292 106
	 * @param firstEntityHandle The firstEntityHandle to set.
293 107
	 */
294
	public void setFirstEntityHandle(int firstEntityHandle) {
108
	public void setFirstEntityHandle(DwgHandleReference firstEntityHandle) {
295 109
		this.firstEntityHandle = firstEntityHandle;
296 110
	}
297 111
	/**
298 112
	 * @return Returns the lastEntityHandle.
299 113
	 */
300
	public int getLastEntityHandle() {
114
	public DwgHandleReference getLastEntityHandle() {
301 115
		return lastEntityHandle;
302 116
	}
303 117
	/**
304 118
	 * @param lastEntityHandle The lastEntityHandle to set.
305 119
	 */
306
	public void setLastEntityHandle(int lastEntityHandle) {
120
	public void setLastEntityHandle(DwgHandleReference lastEntityHandle) {
307 121
		this.lastEntityHandle = lastEntityHandle;
308 122
	}
309 123
	/**
......
321 135
	/**
322 136
	 * @return Returns the blockEntityHandle.
323 137
	 */
324
	public int getBlockEntityHandle() {
138
	public DwgHandleReference getBlockEntityHandle() {
325 139
		return blockEntityHandle;
326 140
	}
327 141
	/**
328 142
	 * @param blockEntityHandle The blockEntityHandle to set.
329 143
	 */
330
	public void setBlockEntityHandle(int blockEntityHandle) {
144
	public void setBlockEntityHandle(DwgHandleReference blockEntityHandle) {
331 145
		this.blockEntityHandle = blockEntityHandle;
332 146
	}
333 147
	/**
......
357 171
	/**
358 172
	 * @return Returns the blockControlHandle.
359 173
	 */
360
	public int getBlockControlHandle() {
174
	public DwgHandleReference getBlockControlHandle() {
361 175
		return blockControlHandle;
362 176
	}
363 177
	/**
364 178
	 * @param blockControlHandle The blockControlHandle to set.
365 179
	 */
366
	public void setBlockControlHandle(int blockControlHandle) {
180
	public void setBlockControlHandle(DwgHandleReference blockControlHandle) {
367 181
		this.blockControlHandle = blockControlHandle;
368 182
	}
369 183
	/**
......
381 195
	/**
382 196
	 * @return Returns the endBlkEntityHandle.
383 197
	 */
384
	public int getEndBlkEntityHandle() {
198
	public DwgHandleReference getEndBlkEntityHandle() {
385 199
		return endBlkEntityHandle;
386 200
	}
387 201
	/**
388 202
	 * @param endBlkEntityHandle The endBlkEntityHandle to set.
389 203
	 */
390
	public void setEndBlkEntityHandle(int endBlkEntityHandle) {
204
	public void setEndBlkEntityHandle(DwgHandleReference endBlkEntityHandle) {
391 205
		this.endBlkEntityHandle = endBlkEntityHandle;
392 206
	}
393 207
	/**
......
417 231
	/**
418 232
	 * @return Returns the insertHandles.
419 233
	 */
420
	public Vector getInsertHandles() {
234
	public DwgHandleReference[] getInsertHandles() {
421 235
		return insertHandles;
422 236
	}
423 237
	/**
424 238
	 * @param insertHandles The insertHandles to set.
425 239
	 */
426
	public void setInsertHandles(Vector insertHandles) {
240
	public void setInsertHandles(DwgHandleReference[] insertHandles) {
427 241
		this.insertHandles = insertHandles;
428 242
	}
429 243
	/**
430 244
	 * @return Returns the layoutHandle.
431 245
	 */
432
	public int getLayoutHandle() {
246
	public DwgHandleReference getLayoutHandle() {
433 247
		return layoutHandle;
434 248
	}
435 249
	/**
436
	 * @param layoutHandle The layoutHandle to set.
250
	 * @param handle The layoutHandle to set.
437 251
	 */
438
	public void setLayoutHandle(int layoutHandle) {
439
		this.layoutHandle = layoutHandle;
252
	public void setLayoutHandle(DwgHandleReference handle) {
253
		this.layoutHandle = handle;
440 254
	}
441 255
	/**
442 256
	 * @return Returns the loaded.
......
453 267
	/**
454 268
	 * @return Returns the nullHandle.
455 269
	 */
456
	public int getNullHandle() {
270
	public DwgHandleReference getNullHandle() {
457 271
		return nullHandle;
458 272
	}
459 273
	/**
460 274
	 * @param nullHandle The nullHandle to set.
461 275
	 */
462
	public void setNullHandle(int nullHandle) {
276
	public void setNullHandle(DwgHandleReference nullHandle) {
463 277
		this.nullHandle = nullHandle;
464 278
	}
465 279
	/**
......
542 356
	public void addObject(DwgObject object) {
543 357
		this.objects.add(object);
544 358
	}
359
	/* (non-Javadoc)
360
	 * @see com.iver.cit.jdwglib.dwg.IDwg3DTestable#has3DData()
361
	 */
362
	public boolean has3DData() {
363
		return (getBasePoint()[2] != 0.0);
364
	}
365
	public double getZ() {
366
		return getBasePoint()[2];
367
	}
368
	public Object clone(){
369
		DwgBlockHeader obj = new DwgBlockHeader(index);
370
		this.fill(obj);
371
		return obj;
372
	}
373
	
374
	protected void fill(DwgObject obj){
375
		super.fill(obj);
376
		DwgBlockHeader myObj = (DwgBlockHeader)obj;
377

  
378
		myObj.setAnonymous(anonymous);
379
		myObj.setBasePoint(basePoint);
380
		myObj.setBlkIsXRef(blkIsXRef);
381
		myObj.setBlockControlHandle(blockControlHandle);
382
		myObj.setBlockDescription(blockDescription);
383
		myObj.setBlockEntityHandle(blockEntityHandle);
384
		myObj.setEndBlkEntityHandle(endBlkEntityHandle);
385
		myObj.setFirstEntityHandle(firstEntityHandle);
386
		myObj.setFlag64(flag64);
387
		myObj.setHasAttrs(hasAttrs);
388
		myObj.setInsertHandles(insertHandles);
389
		myObj.setLastEntityHandle(lastEntityHandle);
390
		myObj.setLayoutHandle(layoutHandle);
391
		myObj.setLoaded(loaded);
392
		myObj.setName(name);
393
		myObj.setNullHandle(nullHandle);
394
		myObj.setObjects(objects);
395
		myObj.setPreviewData(previewData);
396
		myObj.setXdep(xdep);
397
		myObj.setXRefOverLaid(xRefOverLaid);
398
		myObj.setXRefPlus(xRefPlus);
399
		myObj.setXRefPName(xRefPName);
400
	}
401

  
545 402
}

Also available in: Unified diff