Statistics
| Revision:

root / trunk / libraries / libDwg / src / com / iver / cit / jdwglib / dwg / DwgObject.java @ 10820

History | View | Annotate | Download (9.66 KB)

1
/* jdwglib. Java Library for reading Dwg files.
2
 * 
3
 * Author: Jose Morell Rama (jose.morell@gmail.com).
4
 * Port from the Pythoncad Dwg library by Art Haas.
5
 *
6
 * Copyright (C) 2005 Jose Morell, 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
 * Jose Morell (jose.morell@gmail.com)
25
 * 
26
 * or
27
 *
28
 * IVER TI S.A.
29
 *  C/Salamanca, 50
30
 *  46005 Valencia
31
 *  Spain
32
 *  +34 963163400
33
 *  dac@iver.es
34
 */
35
package com.iver.cit.jdwglib.dwg;
36

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

    
40
import com.iver.cit.jdwglib.dwg.objects.DwgBlockHeader;
41

    
42
/**
43
 * The DwgObject class represents a DWG object
44
 * 
45
 * @author jmorell
46
 */
47
public class DwgObject implements Cloneable{
48
        protected int type;
49

    
50
        protected DwgHandleReference handle;
51

    
52
        protected String version;
53

    
54
        protected int mode;
55

    
56
        /**
57
         * code of the layer handle
58
         */
59
        //protected int layerHandleCode;
60

    
61
        /**
62
         * layer handle as an integer
63
         */
64
        protected DwgHandleReference layerHandle;
65

    
66
        protected int color;
67

    
68
        protected int numReactors;
69

    
70
        protected boolean noLinks;
71

    
72
        protected int linetypeFlags;
73

    
74
        protected int plotstyleFlags;
75

    
76
        protected int sizeInBits;
77

    
78
        protected List extendedData;
79

    
80
        protected int graphicData;
81

    
82
        protected DwgHandleReference plotStyleHandle = null;
83

    
84
        protected DwgHandleReference subEntityHandle = null;
85

    
86
        protected DwgHandleReference xDicObjHandle = null;
87

    
88
        protected boolean graphicsFlag;
89
        
90
        /**
91
         * Index of the dwg object in the object's map section
92
         *  
93
         */
94
        protected int index = 0;
95

    
96
        /*
97
         * Previous and Next Handle (this stuff has allowed us to solve the problem
98
         * of layer handles
99
         */
100
        private DwgHandleReference nextHandle = null;
101

    
102
        private DwgHandleReference previousHandle = null;
103

    
104
        //private ArrayList reactorsHandlesCodes = new ArrayList();
105

    
106
        private ArrayList reactorsHandles = new ArrayList();
107

    
108
        public DwgObject(int index) {
109
                this.index = index;
110
        }
111

    
112
        public void setNextHandle(DwgHandleReference hr) {
113
                this.nextHandle = hr;
114

    
115
        }
116

    
117
        public void setPreviousHandle(DwgHandleReference hr) {
118
                this.previousHandle = hr;
119
        }
120

    
121
        /* 
122
        public void setReactorsHandles(ArrayList reactorsHandles) {
123
                this.reactorsHandlesCodes=reactorsHandles;
124
        }
125
        */
126

    
127
        public void addReactorHandle(DwgHandleReference hr) {
128
                if (this.reactorsHandles == null){
129
                        this.reactorsHandles = new ArrayList();
130
                }
131
                this.reactorsHandles.add(hr);
132
        }
133

    
134

    
135
        public DwgHandleReference getNextHandle() {
136
                return this.nextHandle;
137

    
138
        }
139

    
140
        public DwgHandleReference getPreviousHandle() {
141
                return this.previousHandle;
142
        }
143

    
144
        public ArrayList getReactorsHandles() {
145
                return this.reactorsHandles;
146
        }
147

    
148
        //TODO Todo esto no vale si handle puede tomar valor -1
149
        public boolean hasLayerHandle() {
150
                return this.layerHandle != null;
151
        }
152
        public boolean hasNextHandle() {
153
                return this.nextHandle != null;
154
        }
155

    
156
        public boolean hasPreviousHandle() {
157
                return this.previousHandle != null;
158
        }
159

    
160
        public boolean hasSubEntityHandle(){
161
                return this.subEntityHandle != null;
162
        }
163

    
164
        public boolean hasXDicObjHandle(){
165
                return this.xDicObjHandle != null;
166
        }
167

    
168
        public boolean hasReactorsHandles(){
169
                return this.reactorsHandles.size() != 0;
170
        }
171

    
172
        public int reactorsHandlesQuantity(){
173
                return this.reactorsHandles.size();
174
        }
175

    
176
        public int getIndex() {
177
                return index;
178
        }
179

    
180
        /**
181
         * @return Returns the sizeInBits.
182
         */
183
        public int getSizeInBits() {
184
                return sizeInBits;
185
        }
186

    
187
        /**
188
         * @param sizeInBits
189
         *            The sizeInBits to set.
190
         */
191
        public void setSizeInBits(int sizeInBits) {
192
                this.sizeInBits = sizeInBits;
193
        }
194

    
195
        /**
196
         * @return Returns the extendedData.
197
         */
198
        public List getExtendedData() {
199
                return extendedData;
200
        }
201

    
202
        /**
203
         * @param extData
204
         *            The extendedData to set.
205
         */
206
        public void setExtendedData(List extData) {
207
                this.extendedData = extData;
208
        }
209

    
210
        /**
211
         * @return Returns the graphicData.
212
         */
213
        public int getGraphicData() {
214
                return graphicData;
215
        }
216

    
217
        /**
218
         * @param graphicData
219
         *            The graphicData to set.
220
         */
221
        public void setGraphicData(int graphicData) {
222
                this.graphicData = graphicData;
223
        }
224

    
225
        /**
226
         * @return Returns the version.
227
         */
228
        public String getVersion() {
229
                return version;
230
        }
231

    
232
        /**
233
         * @param linetypeFlags
234
         *            The linetypeFlags to set.
235
         */
236
        public void setLinetypeFlags(int linetypeFlags) {
237
                this.linetypeFlags = linetypeFlags;
238
        }
239

    
240
        /**
241
         * @param plotstyleFlags
242
         *            The plotstyleFlags to set.
243
         */
244
        public void setPlotstyleFlags(int plotstyleFlags) {
245
                this.plotstyleFlags = plotstyleFlags;
246
        }
247

    
248
        /**
249
         * @return Returns the subEntityHandle.
250
         */
251
        public DwgHandleReference getSubEntityHandle() {
252
                return subEntityHandle;
253
        }
254

    
255
        /**
256
         * @param subEntityHandle
257
         *            The subEntityHandle to set.
258
         */
259
        public void setSubEntityHandle(DwgHandleReference subEntityHandle) {
260
                this.subEntityHandle = subEntityHandle;
261
        }
262

    
263
        /**
264
         * @return Returns the xDicObjHandle.
265
         */
266
        public DwgHandleReference getXDicObjHandle() {
267
                return xDicObjHandle;
268
        }
269

    
270
        /**
271
         * @param dicObjHandle
272
         *            The xDicObjHandle to set.
273
         */
274
        public void setXDicObjHandle(DwgHandleReference dicObjHandle) {
275
                xDicObjHandle = dicObjHandle;
276
        }
277

    
278
        /**
279
         * @return Returns the color.
280
         */
281
        public int getColor() {
282
                return color;
283
        }
284

    
285
        /**
286
         * @param color
287
         *            The color to set.
288
         */
289
        public void setColor(int color) {
290
                this.color = color;
291
        }
292

    
293
        /**
294
         * @return Returns the handle.
295
         */
296
        public DwgHandleReference getHandle() {
297
                return handle;
298
        }
299

    
300
        /**
301
         * @param handle
302
         *            The handle to set.
303
         */
304
        public void setHandle(DwgHandleReference handle) {
305
                this.handle = handle;
306
        }
307

    
308
        /**
309
         * @return Returns the layerHandle.
310
         */
311
        public DwgHandleReference getLayerHandle() {
312
                return layerHandle;
313
        }
314

    
315
        /**
316
         * @param layerHandle
317
         *            The layerHandle to set.
318
         */
319
        public void setLayerHandle(DwgHandleReference layerHandle) {
320
                this.layerHandle = layerHandle;
321
        }
322

    
323
        /**
324
         * @return Returns the mode.
325
         */
326
        public int getMode() {
327
                return mode;
328
        }
329

    
330
        /**
331
         * @param mode
332
         *            The mode to set.
333
         */
334
        public void setMode(int mode) {
335
                this.mode = mode;
336
        }
337

    
338
        /**
339
         * @return Returns the noLinks.
340
         */
341
        public boolean isNoLinks() {
342
                return noLinks;
343
        }
344

    
345
        /**
346
         * @param noLinks
347
         *            The noLinks to set.
348
         */
349
        public void setNoLinks(boolean noLinks) {
350
                this.noLinks = noLinks;
351
        }
352

    
353
        /**
354
         * @return Returns the numReactors.
355
         */
356
        public int getNumReactors() {
357
                return numReactors;
358
        }
359

    
360
        /**
361
         * @param numReactors
362
         *            The numReactors to set.
363
         */
364
        public void setNumReactors(int numReactors) {
365
                this.numReactors = numReactors;
366
        }
367

    
368
        /**
369
         * @return Returns the type.
370
         */
371
        public int getType() {
372
                return type;
373
        }
374

    
375
        /**
376
         * @param type
377
         *            The type to set.
378
         */
379
        public void setType(int type) {
380
                this.type = type;
381
        }
382

    
383
        /**
384
         * @return Returns the linetypeFlags.
385
         */
386
        public int getLinetypeFlags() {
387
                return linetypeFlags;
388
        }
389

    
390
        /**
391
         * @return Returns the plotstyleFlags.
392
         */
393
        public int getPlotstyleFlags() {
394
                return plotstyleFlags;
395
        }
396

    
397
        /**
398
         * @param version
399
         *            The version to set.
400
         */
401
        public void setVersion(String version) {
402
                this.version = version;
403
        }
404

    
405
        /**
406
         * @return Returns the graphicsFlag.
407
         */
408
        public boolean isGraphicsFlag() {
409
                return graphicsFlag;
410
        }
411

    
412
        /**
413
         * @param graphicsFlag
414
         *            The graphicsFlag to set.
415
         */
416
        public void setGraphicsFlag(boolean graphicsFlag) {
417
                this.graphicsFlag = graphicsFlag;
418
        }
419

    
420
        /*
421
         * This property exists in 13-14 versions, but not in 2000 version
422
         */
423
        private boolean lyrByLineType = false;
424

    
425
        public void setLyrByLineType(boolean lyrByLineType) {
426
                this.lyrByLineType = lyrByLineType;
427
        }
428

    
429
        public boolean isLyrByLineType() {
430
                return lyrByLineType;
431
        }
432

    
433
        public void setPlotStyleHandle(DwgHandleReference hr) {
434
                this.plotStyleHandle = hr;
435

    
436
        }
437
        
438
        public boolean hasPlotStyleHandle() {
439
                return this.plotStyleHandle != null;
440
        }
441

    
442
        /*
443
         * Esto solo se usa para la version 13-14
444
         */
445
        private DwgHandleReference lineTypeHandle = null;
446

    
447
        /**
448
         * Sets the handle of the line type of this drawing entity.
449
         * 
450
         * TODO Ver si conviene guardar tambien el handleCode de este handle
451
         * 
452
         * @param handle2
453
         */
454
        public void setLineTypeHandle(DwgHandleReference hr) {
455
                this.lineTypeHandle = hr;
456

    
457
        }
458

    
459
        public DwgHandleReference getLineTypeHandle() {
460
                return this.lineTypeHandle;
461
        }
462
        
463
        public boolean hasLineTypeHandle() {
464
                return this.lineTypeHandle != null;
465
        }
466

    
467
        
468
        public Object clone(){
469
                DwgObject obj = new DwgObject(this.index);
470
                this.fill(obj);
471
                return obj;
472
        }
473
        
474
        protected void fill(DwgObject obj){
475

    
476
                obj.setColor(color);
477
                obj.setExtendedData(extendedData);
478
                obj.setGraphicData(graphicData);
479
                obj.setGraphicsFlag(graphicsFlag);
480
                obj.setHandle(handle);
481
                obj.setLayerHandle(layerHandle);
482
                obj.setLinetypeFlags(linetypeFlags);
483
                obj.setLineTypeHandle(lineTypeHandle);
484
                obj.setLyrByLineType(lyrByLineType);
485
                obj.setMode(mode);
486
                obj.setNextHandle(nextHandle);
487
                obj.setNoLinks(noLinks);
488
                obj.setNumReactors(numReactors);
489
                obj.setPlotstyleFlags(plotstyleFlags);
490
                obj.setPlotStyleHandle(plotStyleHandle);
491
                obj.setPreviousHandle(previousHandle);
492
                obj.setSizeInBits(sizeInBits);
493
                obj.setSubEntityHandle(subEntityHandle);
494
                obj.setType(type);
495
                obj.setVersion(version);
496
                obj.setXDicObjHandle(xDicObjHandle);
497

    
498
        }
499
}