Statistics
| Revision:

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

History | View | Annotate | Download (8.21 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.objects;
36

    
37
import java.awt.geom.Point2D;
38
import java.util.List;
39
import java.util.Map;
40

    
41
import com.iver.cit.gvsig.fmap.core.FPoint2D;
42
import com.iver.cit.gvsig.fmap.core.FPoint3D;
43
import com.iver.cit.gvsig.fmap.core.FShape;
44
import com.iver.cit.jdwglib.dwg.DwgFile;
45
import com.iver.cit.jdwglib.dwg.DwgHandleReference;
46
import com.iver.cit.jdwglib.dwg.DwgObject;
47
import com.iver.cit.jdwglib.dwg.IDwg2FMap;
48
import com.iver.cit.jdwglib.dwg.IDwg3DTestable;
49
import com.iver.cit.jdwglib.dwg.IDwgBlockMember;
50
import com.iver.cit.jdwglib.dwg.IDwgExtrusionable;
51
import com.iver.cit.jdwglib.util.AcadExtrusionCalculator;
52

    
53
/**
54
 * The DwgInsert class represents a DWG Insert
55
 * 
56
 * @author jmorell
57
 */
58
public class DwgInsert extends DwgObject
59
        implements IDwgExtrusionable, IDwg3DTestable,/* IDwg2FMap, */IDwgBlockMember {
60
        public DwgInsert(int index) {
61
                super(index);
62
        }
63
        private double[] insertionPoint;
64
        private double[] scale;
65
        private double rotation;
66
        private double[] extrusion;
67
        private DwgHandleReference blockHeaderHandle = null;
68
        private DwgHandleReference firstAttribHandle = null;
69
        private DwgHandleReference lastAttribHandle = null;
70
        private DwgHandleReference seqendHandle = null;
71
        
72
        /**
73
         * An insert could be nexted in other insert.
74
         * We wont process and insert two times.
75
         * */
76
        private boolean processed = false;
77
        
78
        
79
        public void dump(){
80
                System.out.println("<Insert>");
81
                System.out.println("<inspoint x="+insertionPoint[0]+
82
                                " y="+insertionPoint[1]+
83
                                " z="+insertionPoint[2]+">");
84
                System.out.println("<scale x="+scale[0]+
85
                                " y="+scale[1]+
86
                                " z="+scale[2]+">");
87
                System.out.println("<rotation rot="+rotation+" >");
88
                
89
                System.out.println("</Insert>");
90
                
91
        }
92

    
93
        /**
94
         * @return Returns the blockHeaderHandle.
95
         */
96
        public DwgHandleReference getBlockHeaderHandle() {
97
                return blockHeaderHandle;
98
        }
99
        /**
100
         * @param blockHeaderHandle The blockHeaderHandle to set.
101
         */
102
        public void setBlockHeaderHandle(DwgHandleReference blockHeaderHandle) {
103
                this.blockHeaderHandle = blockHeaderHandle;
104
        }
105
        /**
106
         * @return Returns the firstAttribHandle.
107
         */
108
        public DwgHandleReference getFirstAttribHandle() {
109
                return firstAttribHandle;
110
        }
111
        /**
112
         * @param firstAttribHandle The firstAttribHandle to set.
113
         */
114
        public void setFirstAttribHandle(DwgHandleReference firstAttribHandle) {
115
                this.firstAttribHandle = firstAttribHandle;
116
        }
117
        /**
118
         * @return Returns the insertionPoint.
119
         */
120
        public double[] getInsertionPoint() {
121
                return insertionPoint;
122
        }
123
        /**
124
         * @param insertionPoint The insertionPoint to set.
125
         */
126
        public void setInsertionPoint(double[] insertionPoint) {
127
                this.insertionPoint = insertionPoint;
128
        }
129
        /**
130
         * @return Returns the lastAttribHandle.
131
         */
132
        public DwgHandleReference getLastAttribHandle() {
133
                return lastAttribHandle;
134
        }
135
        /**
136
         * @param lastAttribHandle The lastAttribHandle to set.
137
         */
138
        public void setLastAttribHandle(DwgHandleReference lastAttribHandle) {
139
                this.lastAttribHandle = lastAttribHandle;
140
        }
141
        /**
142
         * @return Returns the rotation.
143
         */
144
        public double getRotation() {
145
                return rotation;
146
        }
147
        /**
148
         * @param rotation The rotation to set.
149
         */
150
        public void setRotation(double rotation) {
151
                this.rotation = rotation;
152
        }
153
        /**
154
         * @return Returns the scale.
155
         */
156
        public double[] getScale() {
157
                return scale;
158
        }
159
        /**
160
         * @param scale The scale to set.
161
         */
162
        public void setScale(double[] scale) {
163
                this.scale = scale;
164
        }
165
        /**
166
         * @return Returns the extrusion.
167
         */
168
        public double[] getExtrusion() {
169
                return extrusion;
170
        }
171
        /**
172
         * @param extrusion The extrusion to set.
173
         */
174
        public void setExtrusion(double[] extrusion) {
175
                this.extrusion = extrusion;
176
        }
177
        /**
178
         * @return Returns the seqendHandle.
179
         */
180
        public DwgHandleReference getSeqendHandle() {
181
                return seqendHandle;
182
        }
183
        /**
184
         * @param seqendHandle The seqendHandle to set.
185
         */
186
        public void setSeqendHandle(DwgHandleReference seqendHandle) {
187
                this.seqendHandle = seqendHandle;
188
        }
189

    
190
        /* (non-Javadoc)
191
         * @see com.iver.cit.jdwglib.dwg.IDwgExtrusionable#applyExtrussion()
192
         */
193
        public void applyExtrussion() {
194
                 double[] insertPoint = getInsertionPoint();
195
         double[] insertExt = getExtrusion();
196
         insertPoint = AcadExtrusionCalculator.extrude2(insertPoint, insertExt);
197
         setInsertionPoint(insertPoint);
198
        }
199
        /* (non-Javadoc)
200
         * @see com.iver.cit.jdwglib.dwg.IDwg3DTestable#has3DData()
201
         */
202
        public boolean has3DData() {
203
                return (getInsertionPoint()[2] != 0.0);
204
        }
205
        public double getZ() {
206
                return getInsertionPoint()[2];
207
        }
208
        public FShape toFMapGeometry(boolean is3DFile) {
209
                double[] p = getInsertionPoint();
210
//                Point2D point = new Point2D.Double(p[0], p[1]);
211
                FPoint2D fPoint;
212
                /*
213
                 * double[] scale = ((DwgInsert)entity).getScale(); double rot =
214
                 * ((DwgInsert)entity).getRotation(); int blockHandle =
215
                 * ((DwgInsert)entity).getBlockHeaderHandle();
216
                 */
217
                // manageInsert(dwgObjects, point, scale, rot, blockHandle, i,
218
                // auxRow);
219
                if (is3DFile) {
220
                        fPoint = new FPoint3D(p[0], p[1], p[2]);
221
                } else {
222
                        fPoint = new FPoint2D(p[0], p[1]);
223
                }
224
                return fPoint;
225
        }
226
        public String toFMapString(boolean is3DFile) {
227
                if(is3DFile)
228
                        return "FPoint3D";
229
                else
230
                        return "FPoint2D";
231
        }
232
        
233
        public String toString(){
234
                return "Insert";
235
        }
236
        public void transform2Block(double[] bPoint, Point2D insPoint, 
237
                        double[] scale, double rot, 
238
                        List dwgObjectsWithoutBlocks, Map handle_objWithoutBlocks, DwgFile callBack) {
239
                
240
                processed = true;
241
                
242
                double[] p = this.getInsertionPoint();
243
                Point2D point = new Point2D.Double(p[0], p[1]);
244
                
245
                double[] newScale = this.getScale();
246
                double newRot = this.getRotation();
247
                DwgHandleReference newBlockHandle = this.getBlockHeaderHandle();
248
                
249
                Point2D pointAux = new Point2D.Double(point.getX() - bPoint[0], point.getY() - bPoint[1]);
250
                double laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(rot) + (pointAux.getY()*scale[1])*(-1)*Math.sin(rot));
251
                double laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(rot) + (pointAux.getY()*scale[1])*Math.cos(rot));
252
                double laZ = p[2] * scale[2];
253
                
254
                Point2D newInsPoint = new Point2D.Double(laX, laY);
255
                newScale = new double[]{scale[0]*newScale[0], scale[1]*newScale[1], scale[2]*newScale[2]};
256
        newRot = newRot + rot;
257
        if (newRot<0) {
258
            newRot = newRot + (2*Math.PI);
259
        } else if (newRot>(2*Math.PI)) {
260
            newRot = newRot - (2*Math.PI);
261
        }
262
                
263
        callBack.manageInsert2(newInsPoint, 
264
                                                                newScale, 
265
                                                                newRot, 
266
                                                                newBlockHandle.getOffset(), 
267
                                                                dwgObjectsWithoutBlocks,
268
                                                                handle_objWithoutBlocks);
269
        }
270
        
271
        /* (non-Javadoc)
272
         * @see java.lang.Object#clone()
273
         */
274
        public Object clone(){
275
                DwgInsert obj = new DwgInsert(index);
276
                this.fill(obj);
277
                return obj;
278
        }
279
        
280
        protected void fill(DwgObject obj){
281
                super.fill(obj);
282
                DwgInsert myObj = (DwgInsert)obj;
283

    
284
                myObj.setBlockHeaderHandle(blockHeaderHandle);
285
                myObj.setExtrusion(extrusion);
286
                myObj.setFirstAttribHandle(firstAttribHandle);
287
                myObj.setInsertionPoint(insertionPoint);
288
                myObj.setLastAttribHandle(lastAttribHandle);
289
                myObj.setRotation(rotation);
290
                myObj.setScale(scale);
291
                myObj.setSeqendHandle(seqendHandle);
292
        }
293
        public boolean isProcessed() {
294
                return processed;
295
        }
296
        public void setProcessed(boolean processed) {
297
                this.processed = processed;
298
        }
299

    
300
}