Statistics
| Revision:

root / trunk / libraries / libDwg / src / com / iver / cit / jdwglib / dwg / objects / DwgText.java @ 10303

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

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

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

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

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

    
365
}