Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libDwg / src / org / gvsig / dwg / lib / DwgObject.java @ 34899

History | View | Annotate | Download (10.6 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 org.gvsig.dwg.lib;
36

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

    
40
import org.gvsig.dwg.lib.util.FMapUtil;
41
import org.gvsig.fmap.geom.Geometry;
42

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

    
51
        protected DwgHandleReference handle;
52

    
53
        protected String version;
54

    
55
        protected int mode;
56

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

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

    
67
        protected int color;
68

    
69
        protected int numReactors;
70

    
71
        protected boolean noLinks;
72

    
73
        protected int linetypeFlags;
74

    
75
        protected int plotstyleFlags;
76

    
77
        protected int sizeInBits;
78

    
79
        protected List extendedData;
80

    
81
        protected int graphicData;
82
        
83
        protected int address;
84

    
85
        protected DwgHandleReference plotStyleHandle = null;
86

    
87
        protected DwgHandleReference subEntityHandle = null;
88

    
89
        protected DwgHandleReference xDicObjHandle = null;
90

    
91
        protected boolean graphicsFlag;
92
        protected boolean xDicObjFlag;
93
        protected boolean avanzarFlag=false;
94
        
95
        /**
96
         * Index of the dwg object in the object's map section
97
         *  
98
         */
99
        protected int index = 0;
100

    
101
        /*
102
         * Previous and Next Handle (this stuff has allowed us to solve the problem
103
         * of layer handles
104
         */
105
        private DwgHandleReference nextHandle = null;
106

    
107
        private DwgHandleReference previousHandle = null;
108

    
109
        //private ArrayList reactorsHandlesCodes = new ArrayList();
110

    
111
        private ArrayList reactorsHandles = new ArrayList();
112

    
113
        private boolean insertar = false;
114
        
115
        
116
        public DwgObject(int index) {
117
                this.index = index;
118
        }
119
        
120
        public void inserta(){
121
                this.insertar=true;
122
        }
123
        
124
        public boolean insertar(){
125
                return this.insertar;
126
        }
127
        
128
        public void setAddress(int address){
129
                this.address=address;
130
        }
131
        
132
        public int getAddress(){
133
                return this.address;
134
        }
135

    
136
        public void setNextHandle(DwgHandleReference hr) {
137
                this.nextHandle = hr;
138

    
139
        }
140

    
141
        public void setPreviousHandle(DwgHandleReference hr) {
142
                this.previousHandle = hr;
143
        }
144

    
145
        /* 
146
        public void setReactorsHandles(ArrayList reactorsHandles) {
147
                this.reactorsHandlesCodes=reactorsHandles;
148
        }
149
        */
150
        
151
        
152
        public void setAvanzar(boolean avanza){
153
                this.avanzarFlag=avanza;
154
        }
155
        public boolean getAvanzar(){
156
                return this.avanzarFlag;
157
        }
158
        
159
        
160
        
161
        
162

    
163
        public void addReactorHandle(DwgHandleReference hr) {
164
                if (this.reactorsHandles == null){
165
                        this.reactorsHandles = new ArrayList();
166
                }
167
                this.reactorsHandles.add(hr);
168
        }
169

    
170

    
171
        public DwgHandleReference getNextHandle() {
172
                return this.nextHandle;
173

    
174
        }
175

    
176
        public DwgHandleReference getPreviousHandle() {
177
                return this.previousHandle;
178
        }
179

    
180
        public ArrayList getReactorsHandles() {
181
                return this.reactorsHandles;
182
        }
183

    
184
        //TODO Todo esto no vale si handle puede tomar valor -1
185
        public boolean hasLayerHandle() {
186
                return this.layerHandle != null;
187
        }
188
        public boolean hasNextHandle() {
189
                return this.nextHandle != null;
190
        }
191

    
192
        public boolean hasPreviousHandle() {
193
                return this.previousHandle != null;
194
        }
195

    
196
        public boolean hasSubEntityHandle(){
197
                return this.subEntityHandle != null;
198
        }
199

    
200
        public boolean hasXDicObjHandle(){
201
                return this.xDicObjHandle != null;
202
        }
203

    
204
        public boolean hasReactorsHandles(){
205
                return this.reactorsHandles.size() != 0;
206
        }
207

    
208
        public int reactorsHandlesQuantity(){
209
                return this.reactorsHandles.size();
210
        }
211

    
212
        public int getIndex() {
213
                return index;
214
        }
215

    
216
        /**
217
         * @return Returns the sizeInBits.
218
         */
219
        public int getSizeInBits() {
220
                return sizeInBits;
221
        }
222

    
223
        /**
224
         * @param sizeInBits
225
         *            The sizeInBits to set.
226
         */
227
        public void setSizeInBits(int sizeInBits) {
228
                this.sizeInBits = sizeInBits;
229
        }
230

    
231
        /**
232
         * @return Returns the extendedData.
233
         */
234
        public List getExtendedData() {
235
                return extendedData;
236
        }
237

    
238
        /**
239
         * @param extData
240
         *            The extendedData to set.
241
         */
242
        public void setExtendedData(List extData) {
243
                this.extendedData = extData;
244
        }
245

    
246
        /**
247
         * @return Returns the graphicData.
248
         */
249
        public int getGraphicData() {
250
                return graphicData;
251
        }
252

    
253
        /**
254
         * @param graphicData
255
         *            The graphicData to set.
256
         */
257
        public void setGraphicData(int graphicData) {
258
                this.graphicData = graphicData;
259
        }
260

    
261
        /**
262
         * @return Returns the version.
263
         */
264
        public String getVersion() {
265
                return version;
266
        }
267

    
268
        /**
269
         * @param linetypeFlags
270
         *            The linetypeFlags to set.
271
         */
272
        public void setLinetypeFlags(int linetypeFlags) {
273
                this.linetypeFlags = linetypeFlags;
274
        }
275

    
276
        /**
277
         * @param plotstyleFlags
278
         *            The plotstyleFlags to set.
279
         */
280
        public void setPlotstyleFlags(int plotstyleFlags) {
281
                this.plotstyleFlags = plotstyleFlags;
282
        }
283

    
284
        /**
285
         * @return Returns the subEntityHandle.
286
         */
287
        public DwgHandleReference getSubEntityHandle() {
288
                return subEntityHandle;
289
        }
290

    
291
        /**
292
         * @param subEntityHandle
293
         *            The subEntityHandle to set.
294
         */
295
        public void setSubEntityHandle(DwgHandleReference subEntityHandle) {
296
                this.subEntityHandle = subEntityHandle;
297
        }
298

    
299
        /**
300
         * @return Returns the xDicObjHandle.
301
         */
302
        public DwgHandleReference getXDicObjHandle() {
303
                return xDicObjHandle;
304
        }
305

    
306
        /**
307
         * @param dicObjHandle
308
         *            The xDicObjHandle to set.
309
         */
310
        public void setXDicObjHandle(DwgHandleReference dicObjHandle) {
311
                xDicObjHandle = dicObjHandle;
312
        }
313

    
314
        /**
315
         * @return Returns the color.
316
         */
317
        public int getColor() {
318
                return color;
319
        }
320

    
321
        /**
322
         * @param color
323
         *            The color to set.
324
         */
325
        public void setColor(int color) {
326
                this.color = color;
327
        }
328

    
329
        /**
330
         * @return Returns the handle.
331
         */
332
        public DwgHandleReference getHandle() {
333
                return handle;
334
        }
335

    
336
        /**
337
         * @param handle
338
         *            The handle to set.
339
         */
340
        public void setHandle(DwgHandleReference handle) {
341
                this.handle = handle;
342
        }
343

    
344
        /**
345
         * @return Returns the layerHandle.
346
         */
347
        public DwgHandleReference getLayerHandle() {
348
                return layerHandle;
349
        }
350

    
351
        /**
352
         * @param layerHandle
353
         *            The layerHandle to set.
354
         */
355
        public void setLayerHandle(DwgHandleReference layerHandle) {
356
                this.layerHandle = layerHandle;
357
        }
358

    
359
        /**
360
         * @return Returns the mode.
361
         */
362
        public int getMode() {
363
                return mode;
364
        }
365

    
366
        /**
367
         * @param mode
368
         *            The mode to set.
369
         */
370
        public void setMode(int mode) {
371
                this.mode = mode;
372
        }
373

    
374
        /**
375
         * @return Returns the noLinks.
376
         */
377
        public boolean isNoLinks() {
378
                return noLinks;
379
        }
380

    
381
        /**
382
         * @param noLinks
383
         *            The noLinks to set.
384
         */
385
        public void setNoLinks(boolean noLinks) {
386
                this.noLinks = noLinks;
387
        }
388

    
389
        /**
390
         * @return Returns the numReactors.
391
         */
392
        public int getNumReactors() {
393
                return numReactors;
394
        }
395

    
396
        /**
397
         * @param numReactors
398
         *            The numReactors to set.
399
         */
400
        public void setNumReactors(int numReactors) {
401
                this.numReactors = numReactors;
402
        }
403

    
404
        /**
405
         * @return Returns the type.
406
         */
407
        public int getType() {
408
                return type;
409
        }
410

    
411
        /**
412
         * @param type
413
         *            The type to set.
414
         */
415
        public void setType(int type) {
416
                this.type = type;
417
        }
418

    
419
        /**
420
         * @return Returns the linetypeFlags.
421
         */
422
        public int getLinetypeFlags() {
423
                return linetypeFlags;
424
        }
425

    
426
        /**
427
         * @return Returns the plotstyleFlags.
428
         */
429
        public int getPlotstyleFlags() {
430
                return plotstyleFlags;
431
        }
432

    
433
        /**
434
         * @param version
435
         *            The version to set.
436
         */
437
        public void setVersion(String version) {
438
                this.version = version;
439
        }
440

    
441
        /**
442
         * @return Returns the graphicsFlag.
443
         */
444
        public boolean isGraphicsFlag() {
445
                return graphicsFlag;
446
        }
447

    
448
        /**
449
         * @param graphicsFlag
450
         *            The graphicsFlag to set.
451
         */
452
        public void setGraphicsFlag(boolean graphicsFlag) {
453
                this.graphicsFlag = graphicsFlag;
454
        }
455
        
456
        
457
        /**
458
         * @return Returns the xDicObjFlag.
459
         */
460
        public boolean isXDicObjFlag() {
461
                return xDicObjFlag;
462
        }
463

    
464
        /**
465
         * @param xDicObjFlag
466
         *            The xDicObjFlag to set.
467
         */
468
        public void setXDicObjFlag(boolean xDicObjFlag) {
469
                this.xDicObjFlag = xDicObjFlag;
470
        }
471

    
472
        /*
473
         * This property exists in 13-14 versions, but not in 2000 version
474
         */
475
        private boolean lyrByLineType = false;
476

    
477
        public void setLyrByLineType(boolean lyrByLineType) {
478
                this.lyrByLineType = lyrByLineType;
479
        }
480

    
481
        public boolean isLyrByLineType() {
482
                return lyrByLineType;
483
        }
484

    
485
        public void setPlotStyleHandle(DwgHandleReference hr) {
486
                this.plotStyleHandle = hr;
487

    
488
        }
489
        
490
        public boolean hasPlotStyleHandle() {
491
                return this.plotStyleHandle != null;
492
        }
493

    
494
        /*
495
         * Esto solo se usa para la version 13-14
496
         */
497
        private DwgHandleReference lineTypeHandle = null;
498

    
499
        /**
500
         * Sets the handle of the line type of this drawing entity.
501
         * 
502
         * TODO Ver si conviene guardar tambien el handleCode de este handle
503
         * 
504
         * @param handle2
505
         */
506
        public void setLineTypeHandle(DwgHandleReference hr) {
507
                this.lineTypeHandle = hr;
508

    
509
        }
510

    
511
        public DwgHandleReference getLineTypeHandle() {
512
                return this.lineTypeHandle;
513
        }
514
        
515
        public boolean hasLineTypeHandle() {
516
                return this.lineTypeHandle != null;
517
        }
518

    
519
        
520
        public Object clone(){
521
                DwgObject obj = new DwgObject(this.index);
522
                this.fill(obj);
523
                return obj;
524
        }
525
        
526
        protected void fill(DwgObject obj){
527

    
528
                obj.setColor(color);
529
                obj.setExtendedData(extendedData);
530
                obj.setGraphicData(graphicData);
531
                obj.setGraphicsFlag(graphicsFlag);
532
                obj.setHandle(handle);
533
                obj.setLayerHandle(layerHandle);
534
                obj.setLinetypeFlags(linetypeFlags);
535
                obj.setLineTypeHandle(lineTypeHandle);
536
                obj.setLyrByLineType(lyrByLineType);
537
                obj.setMode(mode);
538
                obj.setNextHandle(nextHandle);
539
                obj.setNoLinks(noLinks);
540
                obj.setNumReactors(numReactors);
541
                obj.setPlotstyleFlags(plotstyleFlags);
542
                obj.setPlotStyleHandle(plotStyleHandle);
543
                obj.setPreviousHandle(previousHandle);
544
                obj.setSizeInBits(sizeInBits);
545
                obj.setSubEntityHandle(subEntityHandle);
546
                obj.setType(type);
547
                obj.setVersion(version);
548
                obj.setXDicObjHandle(xDicObjHandle);
549
        }
550
        
551
   public int getGeometrySubType(boolean is3DFile) {
552
        if (is3DFile) {
553
            return Geometry.SUBTYPES.GEOM3D;
554
        } else {
555
            return Geometry.SUBTYPES.GEOM2D;
556
        }
557
    }
558
}