Statistics
| Revision:

root / trunk / libraries / libDwg / src / com / iver / cit / jdwglib / dwg / objects / DwgSolid.java @ 10240

History | View | Annotate | Download (9.44 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.FPolyline2D;
42
import com.iver.cit.gvsig.fmap.core.FShape;
43
import com.iver.cit.jdwglib.dwg.DwgFile;
44
import com.iver.cit.jdwglib.dwg.DwgObject;
45
import com.iver.cit.jdwglib.dwg.IDwg2FMap;
46
import com.iver.cit.jdwglib.dwg.IDwg3DTestable;
47
import com.iver.cit.jdwglib.dwg.IDwgBlockMember;
48
import com.iver.cit.jdwglib.dwg.IDwgExtrusionable;
49
import com.iver.cit.jdwglib.util.AcadExtrusionCalculator;
50
import com.iver.cit.jdwglib.util.FMapUtil;
51

    
52
/**
53
 * The DwgSolid class represents a DWG Solid
54
 * 
55
 * @author jmorell, azabala
56
 */
57
public class DwgSolid extends DwgObject 
58
        implements IDwgExtrusionable, IDwg3DTestable, IDwg2FMap, IDwgBlockMember{
59
        public DwgSolid(int index) {
60
                super(index);
61
                // TODO Auto-generated constructor stub
62
        }
63
        private double thickness;
64
        private double elevation;
65
        private double[] corner1;
66
        private double[] corner2;
67
        private double[] corner3;
68
        private double[] corner4;
69
        private double[] extrusion;
70
        
71
        /**
72
         * Read a Solid in the DWG format Version 15
73
         * 
74
         * @param data Array of unsigned bytes obtained from the DWG binary file
75
         * @param offset The current bit offset where the value begins
76
         * @throws Exception If an unexpected bit value is found in the DWG file. Occurs
77
         *                    when we are looking for LwPolylines.
78
         */
79
        public void readDwgSolidV15(int[] data, int offset) throws Exception {
80
                
81
        }
82
        /**
83
         * @return Returns the corner1.
84
         */
85
        public double[] getCorner1() {
86
                return corner1;
87
        }
88
        /**
89
         * @param corner1 The corner1 to set.
90
         */
91
        public void setCorner1(double[] corner1) {
92
                this.corner1 = corner1;
93
        }
94
        /**
95
         * @return Returns the corner2.
96
         */
97
        public double[] getCorner2() {
98
                return corner2;
99
        }
100
        /**
101
         * @param corner2 The corner2 to set.
102
         */
103
        public void setCorner2(double[] corner2) {
104
                this.corner2 = corner2;
105
        }
106
        /**
107
         * @return Returns the corner3.
108
         */
109
        public double[] getCorner3() {
110
                return corner3;
111
        }
112
        /**
113
         * @param corner3 The corner3 to set.
114
         */
115
        public void setCorner3(double[] corner3) {
116
                this.corner3 = corner3;
117
        }
118
        /**
119
         * @return Returns the corner4.
120
         */
121
        public double[] getCorner4() {
122
                return corner4;
123
        }
124
        /**
125
         * @param corner4 The corner4 to set.
126
         */
127
        public void setCorner4(double[] corner4) {
128
                this.corner4 = corner4;
129
        }
130
    /**
131
     * @return Returns the elevation.
132
     */
133
    public double getElevation() {
134
        return elevation;
135
    }
136
    /**
137
     * @param elevation The elevation to set.
138
     */
139
    public void setElevation(double elevation) {
140
        this.elevation = elevation;
141
    }
142
    /**
143
     * @return Returns the extrusion.
144
     */
145
    public double[] getExtrusion() {
146
        return extrusion;
147
    }
148
        /* (non-Javadoc)
149
         * @see java.lang.Object#clone()
150
         */
151
//        public Object clone() {
152
//                DwgSolid dwgSolid = new DwgSolid(index);
153
//                dwgSolid.setType(type);
154
//                dwgSolid.setHandle(handle);
155
//                dwgSolid.setVersion(version);
156
//                dwgSolid.setMode(mode);
157
//                dwgSolid.setLayerHandle(layerHandle);
158
//                dwgSolid.setColor(color);
159
//                dwgSolid.setNumReactors(numReactors);
160
//                dwgSolid.setNoLinks(noLinks);
161
//                dwgSolid.setLinetypeFlags(linetypeFlags);
162
//                dwgSolid.setPlotstyleFlags(plotstyleFlags);
163
//                dwgSolid.setSizeInBits(sizeInBits);
164
//                dwgSolid.setExtendedData(extendedData);
165
//                dwgSolid.setGraphicData(graphicData);
166
//                //dwgSolid.setInsideBlock(insideBlock);
167
//                dwgSolid.setThickness(thickness);
168
//                dwgSolid.setElevation(elevation);
169
//                dwgSolid.setCorner1(corner1);
170
//                dwgSolid.setCorner2(corner2);
171
//                dwgSolid.setCorner3(corner3);
172
//                dwgSolid.setCorner4(corner4);
173
//                dwgSolid.setExtrusion(extrusion);
174
//                return dwgSolid;
175
//        }
176
        /**
177
         * @return Returns the thickness.
178
         */
179
        public double getThickness() {
180
                return thickness;
181
        }
182
        /**
183
         * @param thickness The thickness to set.
184
         */
185
        public void setThickness(double thickness) {
186
                this.thickness = thickness;
187
        }
188
        /**
189
         * @param extrusion The extrusion to set.
190
         */
191
        public void setExtrusion(double[] extrusion) {
192
                this.extrusion = extrusion;
193
        }
194
        /* (non-Javadoc)
195
         * @see com.iver.cit.jdwglib.dwg.IDwgExtrusionable#applyExtrussion()
196
         */
197
        public void applyExtrussion() {
198
                 double[] corner1 = getCorner1();
199
         double[] corner2 = getCorner2();
200
         double[] corner3 = getCorner3();
201
         double[] corner4 = getCorner4();
202
         double[] solidExt = getExtrusion();
203
         corner1 = AcadExtrusionCalculator.CalculateAcadExtrusion(corner1, solidExt);
204
         setCorner1(corner1);
205
         setCorner2(corner2);
206
         setCorner3(corner3);
207
         setCorner4(corner4);
208
        }
209
        /* (non-Javadoc)
210
         * @see com.iver.cit.jdwglib.dwg.IDwg3DTestable#has3DData()
211
         */
212
        public boolean has3DData() {
213
                return (getElevation() != 0.0);
214
        }
215
        public double getZ() {
216
                return getElevation();
217
        }
218
        public FShape toFMapGeometry(boolean is3DFile) {
219
                FPolyline2D solid = null;
220
                double[] p1 = getCorner1();
221
                double[] p2 = getCorner2();
222
                double[] p3 = getCorner3();
223
                double[] p4 = getCorner4();
224
                double elev = getElevation();
225
                Point2D[] pts = new Point2D[] {
226
                                new Point2D.Double(p1[0], p1[1]),
227
                                new Point2D.Double(p2[0], p2[1]),
228
                                new Point2D.Double(p4[0], p4[1]),
229
                                new Point2D.Double(p3[0], p3[1]),
230
                                new Point2D.Double(p1[0], p1[1]) 
231
                };
232
                
233
                if (is3DFile) {
234
                        double[][] pline3D = new double[pts.length][3];
235
                        for (int j = 0; j < pts.length; j++) {
236
                                pline3D[j][0] = pts[j].getX();
237
                                pline3D[j][1] = pts[j].getY();
238
                                pline3D[j][2] = elev;
239
                        }
240
                        solid = FMapUtil.points3DToFPolyline3D(pline3D);
241
                        
242
                } else {
243
                        solid = FMapUtil.points2DToFPolyline2D(pts);
244
                }
245
                return solid;
246
                
247
        }
248
        public String toFMapString(boolean is3DFile) {
249
                if(is3DFile){
250
                        return "FPolyline3D";
251
                }else{
252
                        return "FPolyline2D";
253
                }
254
        }
255
        
256
        public String toString(){
257
                return "Solid";
258
        }
259
        public void transform2Block(double[] bPoint, Point2D insPoint, double[] scale, double rot, 
260
                        List dwgObjectsWithoutBlocks, 
261
                        Map handleObjWithoutBlocks,
262
                        DwgFile callBack) {
263
                DwgSolid transformedEntity = null;
264
                double[] corner1 = this.getCorner1();
265
                double[] corner2 = this.getCorner2();
266
                double[] corner3 = this.getCorner3();
267
                double[] corner4 = this.getCorner4();
268
                Point2D pointAux = new Point2D.Double(corner1[0] - bPoint[0], corner1[1] - bPoint[1]);
269
                double laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(rot) + (pointAux.getY()*scale[1])*(-1)*Math.sin(rot));
270
                double laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(rot) + (pointAux.getY()*scale[1])*Math.cos(rot));
271
                double[] transformedP1 = new double[]{laX, laY};
272
                pointAux = new Point2D.Double(corner2[0] - bPoint[0], corner2[1] - bPoint[1]);
273
                laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(rot) + (pointAux.getY()*scale[1])*(-1)*Math.sin(rot));
274
                laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(rot) + (pointAux.getY()*scale[1])*Math.cos(rot));
275
                double[] transformedP2 = new double[]{laX, laY};
276
                pointAux = new Point2D.Double(corner3[0] - bPoint[0], corner3[1] - bPoint[1]);
277
                laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(rot) + (pointAux.getY()*scale[1])*(-1)*Math.sin(rot));
278
                laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(rot) + (pointAux.getY()*scale[1])*Math.cos(rot));
279
                double[] transformedP3 = new double[]{laX, laY};
280
                pointAux = new Point2D.Double(corner4[0] - bPoint[0], corner4[1] - bPoint[1]);
281
                laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(rot) + (pointAux.getY()*scale[1])*(-1)*Math.sin(rot));
282
                laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(rot) + (pointAux.getY()*scale[1])*Math.cos(rot));
283
                double[] transformedP4 = new double[]{laX, laY};
284
                transformedEntity = (DwgSolid)this.clone();
285
                transformedEntity.setCorner1(transformedP1);
286
                transformedEntity.setCorner2(transformedP2);
287
                transformedEntity.setCorner3(transformedP3);
288
                transformedEntity.setCorner4(transformedP4);
289
                transformedEntity.setElevation(this.getElevation() * scale[2]);
290
                dwgObjectsWithoutBlocks.add(transformedEntity);
291
                handleObjWithoutBlocks.put(new Integer(transformedEntity.getHandle().getOffset()), transformedEntity);
292
        }
293
        
294
        public Object clone(){
295
                DwgSolid obj = new DwgSolid(index);
296
                this.fill(obj);
297
                return obj;
298
        }
299
        
300
        protected void fill(DwgObject obj){
301
                super.fill(obj);
302
                DwgSolid myObj = (DwgSolid)obj;
303

    
304
                myObj.setCorner1(corner1);
305
                myObj.setCorner2(corner2);
306
                myObj.setCorner3(corner3);
307
                myObj.setCorner4(corner4);
308
                myObj.setElevation(elevation);
309
                myObj.setExtrusion(extrusion);
310
                myObj.setThickness(thickness);
311

    
312
        }
313

    
314
}