Statistics
| Revision:

svn-gvsig-desktop / branches / v10 / libraries / libDwg / src / com / iver / cit / jdwglib / dwg / objects / DwgText.java @ 10847

History | View | Annotate | Download (9.32 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.IGeometry;
44
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
45
import com.iver.cit.jdwglib.dwg.DwgFile;
46
import com.iver.cit.jdwglib.dwg.DwgHandleReference;
47
import com.iver.cit.jdwglib.dwg.DwgObject;
48
import com.iver.cit.jdwglib.dwg.IDwg2FMap;
49
import com.iver.cit.jdwglib.dwg.IDwg3DTestable;
50
import com.iver.cit.jdwglib.dwg.IDwgBlockMember;
51
import com.iver.cit.jdwglib.dwg.IDwgExtrusionable;
52
import com.iver.cit.jdwglib.util.AcadExtrusionCalculator;
53

    
54
/**
55
 * The DwgText class represents a DWG Text
56
 * 
57
 * @author jmorell
58
 */
59
public class DwgText extends DwgObject 
60
                                        implements IDwgExtrusionable, 
61
                                        IDwg3DTestable, 
62
                                        IDwg2FMap,
63
                                        IDwgBlockMember{
64
        public DwgText(int index) {
65
                super(index);
66
                // TODO Auto-generated constructor stub
67
        }
68
        private int dataFlag;
69
        private double elevation;
70
        private Point2D insertionPoint;
71
        private Point2D alignmentPoint;
72
        private double[] extrusion;
73
        private double thickness;
74
        private double obliqueAngle;
75
        private double rotationAngle;
76
        private double height;
77
        private double widthFactor;
78
        private String text;
79
        private int generation;
80
        private int halign;
81
        private int valign;
82
        private DwgHandleReference styleHdl;
83
        
84
        /**
85
         * @return Returns the dataFlag.
86
         */
87
        public int getDataFlag() {
88
                return dataFlag;
89
        }
90
        /**
91
         * @param dataFlag The dataFlag to set.
92
         */
93
        public void setDataFlag(int dataFlag) {
94
                this.dataFlag = dataFlag;
95
        }
96
        /**
97
         * @return Returns the height.
98
         */
99
        public double getHeight() {
100
                return height;
101
        }
102
        /**
103
         * @param height The height to set.
104
         */
105
        public void setHeight(double height) {
106
                this.height = height;
107
        }
108
        /**
109
         * @return Returns the insertionPoint.
110
         */
111
        public Point2D getInsertionPoint() {
112
                return insertionPoint;
113
        }
114
        /**
115
         * @param insertionPoint The insertionPoint to set.
116
         */
117
        public void setInsertionPoint(Point2D insertionPoint) {
118
                this.insertionPoint = insertionPoint;
119
        }
120
        /**
121
         * @return Returns the rotationAngle.
122
         */
123
        public double getRotationAngle() {
124
                return rotationAngle;
125
        }
126
        
127
        public double getRotationAngleInDegrees(){
128
                int dflag = getDataFlag();
129
                if ((dflag & 0x8) == 0) {
130
                        double textRot = getRotationAngle();
131
                        return Math.toDegrees(textRot);
132
                } else {
133
                        return 0d;
134
                }
135
        }
136
        /**
137
         * @param rotationAngle The rotationAngle to set.
138
         */
139
        public void setRotationAngle(double rotationAngle) {
140
                this.rotationAngle = rotationAngle;
141
        }
142
        /**
143
         * @return Returns the text.
144
         */
145
        public String getText() {
146
                return text;
147
        }
148
        /**
149
         * @param text The text to set.
150
         */
151
        public void setText(String text) {
152
                this.text = text;
153
        }
154
        /**
155
         * @return Returns the elevation.
156
         */
157
        public double getElevation() {
158
                return elevation;
159
        }
160
        /**
161
         * @param elevation The elevation to set.
162
         */
163
        public void setElevation(double elevation) {
164
                this.elevation = elevation;
165
        }
166
        /**
167
         * @return Returns the thickness.
168
         */
169
        public double getThickness() {
170
                return thickness;
171
        }
172
        /**
173
         * @param thickness The thickness to set.
174
         */
175
        public void setThickness(double thickness) {
176
                this.thickness = thickness;
177
        }
178
    /**
179
     * @return Returns the extrusion.
180
     */
181
    public double[] getExtrusion() {
182
        return extrusion;
183
    }
184

    
185
        /**
186
         * @return Returns the alignmentPoint.
187
         */
188
        public Point2D getAlignmentPoint() {
189
                return alignmentPoint;
190
        }
191
        /**
192
         * @param alignmentPoint The alignmentPoint to set.
193
         */
194
        public void setAlignmentPoint(Point2D alignmentPoint) {
195
                this.alignmentPoint = alignmentPoint;
196
        }
197
        /**
198
         * @return Returns the generation.
199
         */
200
        public int getGeneration() {
201
                return generation;
202
        }
203
        /**
204
         * @param generation The generation to set.
205
         */
206
        public void setGeneration(int generation) {
207
                this.generation = generation;
208
        }
209
        /**
210
         * @return Returns the halign.
211
         */
212
        public int getHalign() {
213
                return halign;
214
        }
215
        /**
216
         * @param halign The halign to set.
217
         */
218
        public void setHalign(int halign) {
219
                this.halign = halign;
220
        }
221
        /**
222
         * @return Returns the obliqueAngle.
223
         */
224
        public double getObliqueAngle() {
225
                return obliqueAngle;
226
        }
227
        /**
228
         * @param obliqueAngle The obliqueAngle to set.
229
         */
230
        public void setObliqueAngle(double obliqueAngle) {
231
                this.obliqueAngle = obliqueAngle;
232
        }
233
        /**
234
         * @return Returns the valign.
235
         */
236
        public int getValign() {
237
                return valign;
238
        }
239
        /**
240
         * @param valign The valign to set.
241
         */
242
        public void setValign(int valign) {
243
                this.valign = valign;
244
        }
245
        /**
246
         * @return Returns the widthFactor.
247
         */
248
        public double getWidthFactor() {
249
                return widthFactor;
250
        }
251
        /**
252
         * @param widthFactor The widthFactor to set.
253
         */
254
        public void setWidthFactor(double widthFactor) {
255
                this.widthFactor = widthFactor;
256
        }
257
        /**
258
         * @param extrusion The extrusion to set.
259
         */
260
        public void setExtrusion(double[] extrusion) {
261
                this.extrusion = extrusion;
262
        }
263
        /* (non-Javadoc)
264
         * @see com.iver.cit.jdwglib.dwg.IDwgExtrusionable#applyExtrussion()
265
         */
266
        public void applyExtrussion() {
267
                 Point2D tpoint = getInsertionPoint();
268
         double elev = getElevation();
269
         double[] textPoint = new double[]{tpoint.getX(), tpoint.getY(), elev};
270
         double[] textExt = getExtrusion();
271
         textPoint = AcadExtrusionCalculator.extrude2(textPoint, textExt);
272
         setInsertionPoint(new Point2D.Double(textPoint[0], textPoint[1]));
273
         setElevation(elev);
274
        }
275
        /* (non-Javadoc)
276
         * @see com.iver.cit.jdwglib.dwg.IDwg3DTestable#has3DData()
277
         */
278
        public boolean has3DData() {
279
                return (getElevation() !=0.0);
280
        }
281
        public double getZ() {
282
                return getElevation();
283
        }
284
        public IGeometry toFMapGeometry(boolean is3DFile) {
285
                FPoint2D point = null;
286
                Point2D p = getInsertionPoint();
287
                double elev = 0.0;
288
                if ((getDataFlag() & 0x1) == 0)
289
                        elev = getElevation();
290
                if (is3DFile) {
291
                        point = new FPoint3D(p.getX(), p.getY(), elev);
292
                } else {
293
                        point = new FPoint2D(p.getX(), p.getY());
294
                }
295
                return ShapeFactory.createGeometry(point);
296
        }
297
        
298
        public String toFMapString(boolean is3DFile) {
299
                if(is3DFile)
300
                        return "FPoint3D";
301
                else
302
                        return "FPoint2D";
303
        }
304
        public String toString(){
305
                return "Text";
306
        }
307
        /**
308
         * @param styleHdl
309
         */
310
        public void setStyleHandle(DwgHandleReference styleHdl) {
311
                this.styleHdl = styleHdl;
312
        }
313

    
314
        /* (non-Javadoc)
315
         * @see java.lang.Object#clone()
316
         */
317
        public Object clone(){
318
                DwgText obj = new DwgText(index);
319
                this.fill(obj);
320
                return obj;
321
        }
322
        
323
        protected void fill(DwgObject obj){
324
                super.fill(obj);
325
                DwgText myObj = (DwgText)obj;
326

    
327
                myObj.setAlignmentPoint(alignmentPoint);
328
                myObj.setDataFlag(dataFlag);
329
                myObj.setElevation(elevation);
330
                myObj.setExtrusion(extrusion);
331
                myObj.setGeneration(generation);
332
                myObj.setHalign(halign);
333
                myObj.setHeight(height);
334
                myObj.setInsertionPoint(insertionPoint);
335
                myObj.setObliqueAngle(obliqueAngle);
336
                myObj.setRotationAngle(rotationAngle);
337
                myObj.setStyleHandle(styleHdl);
338
                myObj.setText(text);
339
                myObj.setThickness(thickness);
340
                myObj.setValign(valign);
341
                myObj.setWidthFactor(widthFactor);
342
        }
343
        
344
        //TODO Implement
345
        public void transform2Block(double[] bPoint, Point2D insPoint, double[] scale, double rot, List dwgObjectsWithoutBlocks, Map handle_objectsWithoutBlocks, DwgFile callBack) {
346
                 Point2D pointAux = new Point2D.Double(insertionPoint.getX() - bPoint[0], 
347
                                 insertionPoint.getY() - bPoint[1]);
348
                 double laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(rot) + (pointAux.getY()*scale[1])*(-1)*Math.sin(rot));
349
                 double laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(rot) + (pointAux.getY()*scale[1])*Math.cos(rot));
350

    
351
                 Point2D.Double newInsertionPoint = new Point2D.Double(laX, laY);
352
                 DwgText transformedEntity = (DwgText) this.clone();
353
                 transformedEntity.setInsertionPoint(newInsertionPoint);
354
                 
355
                 if(alignmentPoint != null){
356
                         pointAux = new Point2D.Double(alignmentPoint.getX() - bPoint[0], 
357
                                         alignmentPoint.getY() - bPoint[1]);
358
                         laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(rot) + (pointAux.getY()*scale[1])*(-1)*Math.sin(rot));
359
                         laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(rot) + (pointAux.getY()*scale[1])*Math.cos(rot));
360
                         Point2D.Double newAlignPoint = new Point2D.Double(laX, laY);
361
                         transformedEntity.setAlignmentPoint(newAlignPoint);
362
                 }
363
                 //TODO Transformar el resto de parametros en base a los datos del bloque
364
                 //altura, etc.
365
        }
366

    
367
}