Statistics
| Revision:

root / trunk / org.gvsig.dwg / org.gvsig.dwg.lib / src / main / java / org / gvsig / dwg / lib / objects / DwgText.java @ 44

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

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

    
41
import org.gvsig.dwg.lib.DwgFile;
42
import org.gvsig.dwg.lib.DwgHandleReference;
43
import org.gvsig.dwg.lib.DwgObject;
44
import org.gvsig.dwg.lib.IDwg2FMap;
45
import org.gvsig.dwg.lib.IDwg3DTestable;
46
import org.gvsig.dwg.lib.IDwgBlockMember;
47
import org.gvsig.dwg.lib.IDwgExtrusionable;
48
import org.gvsig.dwg.lib.util.AcadExtrusionCalculator;
49
import org.gvsig.fmap.geom.Geometry;
50
import org.gvsig.fmap.geom.GeometryLocator;
51
import org.gvsig.fmap.geom.GeometryManager;
52
import org.gvsig.fmap.geom.exception.CreateGeometryException;
53
import org.gvsig.fmap.geom.primitive.Point;
54

    
55

    
56
/**
57
 * The DwgText class represents a DWG Text
58
 *
59
 * @author jmorell
60
 */
61
public class DwgText extends DwgObject
62
                                        implements IDwgExtrusionable,
63
                                        IDwg3DTestable,
64
                                        IDwg2FMap,
65
                                        IDwgBlockMember{
66
        public DwgText(int index) {
67
                super(index);
68
                // TODO Auto-generated constructor stub
69
        }
70
        private int dataFlag;
71
        private double elevation;
72
        private Point2D insertionPoint;
73
        private Point2D alignmentPoint;
74
        private double[] extrusion;
75
        private double thickness;
76
        private double obliqueAngle;
77
        private double rotationAngle;
78
        private double height;
79
        private double widthFactor;
80
        private String text;
81
        private int generation;
82
        private int halign;
83
        private int valign;
84
        private DwgHandleReference styleHdl;
85

    
86
        /**
87
         * @return Returns the dataFlag.
88
         */
89
        public int getDataFlag() {
90
                return dataFlag;
91
        }
92
        /**
93
         * @param dataFlag The dataFlag to set.
94
         */
95
        public void setDataFlag(int dataFlag) {
96
                this.dataFlag = dataFlag;
97
        }
98
        /**
99
         * @return Returns the height.
100
         */
101
        public double getHeight() {
102
                return height;
103
        }
104
        /**
105
         * @param height The height to set.
106
         */
107
        public void setHeight(double height) {
108
                this.height = height;
109
        }
110
        /**
111
         * @return Returns the insertionPoint.
112
         */
113
        public Point2D getInsertionPoint() {
114
                return insertionPoint;
115
        }
116
        /**
117
         * @param insertionPoint The insertionPoint to set.
118
         */
119
        public void setInsertionPoint(Point2D insertionPoint) {
120
                this.insertionPoint = insertionPoint;
121
        }
122
        /**
123
         * @return Returns the rotationAngle.
124
         */
125
        public double getRotationAngle() {
126
                return rotationAngle;
127
        }
128

    
129
        public double getRotationAngleInDegrees(){
130
                int dflag = getDataFlag();
131
                if ((dflag & 0x8) == 0) {
132
                        double textRot = getRotationAngle();
133
                        return Math.toDegrees(textRot);
134
                } else {
135
                        return 0d;
136
                }
137
        }
138
        /**
139
         * @param rotationAngle The rotationAngle to set.
140
         */
141
        public void setRotationAngle(double rotationAngle) {
142
                this.rotationAngle = rotationAngle;
143
        }
144
        /**
145
         * @return Returns the text.
146
         */
147
        public String getText() {
148
                return text;
149
        }
150
        /**
151
         * @param text The text to set.
152
         */
153
        public void setText(String text) {
154
                this.text = text;
155
        }
156
        /**
157
         * @return Returns the elevation.
158
         */
159
        public double getElevation() {
160
                return elevation;
161
        }
162
        /**
163
         * @param elevation The elevation to set.
164
         */
165
        public void setElevation(double elevation) {
166
                this.elevation = elevation;
167
        }
168
        /**
169
         * @return Returns the thickness.
170
         */
171
        public double getThickness() {
172
                return thickness;
173
        }
174
        /**
175
         * @param thickness The thickness to set.
176
         */
177
        public void setThickness(double thickness) {
178
                this.thickness = thickness;
179
        }
180
    /**
181
     * @return Returns the extrusion.
182
     */
183
    public double[] getExtrusion() {
184
        return extrusion;
185
    }
186

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

    
301
                }
302
                return point;
303
        }
304

    
305
        public String toFMapString(boolean is3DFile) {
306
                if(is3DFile) {
307
                        return "FPoint3D";
308
                } else {
309
                        return "FPoint2D";
310
                }
311
        }
312
        public String toString(){
313
                return "Text";
314
        }
315
        /**
316
         * @param styleHdl
317
         */
318
        public void setStyleHandle(DwgHandleReference styleHdl) {
319
                this.styleHdl = styleHdl;
320
        }
321

    
322
        /* (non-Javadoc)
323
         * @see java.lang.Object#clone()
324
         */
325
        public Object clone(){
326
                DwgText obj = new DwgText(index);
327
                this.fill(obj);
328
                return obj;
329
        }
330

    
331
        protected void fill(DwgObject obj){
332
                super.fill(obj);
333
                DwgText myObj = (DwgText)obj;
334

    
335
                myObj.setAlignmentPoint(alignmentPoint);
336
                myObj.setDataFlag(dataFlag);
337
                myObj.setElevation(elevation);
338
                myObj.setExtrusion(extrusion);
339
                myObj.setGeneration(generation);
340
                myObj.setHalign(halign);
341
                myObj.setHeight(height);
342
                myObj.setInsertionPoint(insertionPoint);
343
                myObj.setObliqueAngle(obliqueAngle);
344
                myObj.setRotationAngle(rotationAngle);
345
                myObj.setStyleHandle(styleHdl);
346
                myObj.setText(text);
347
                myObj.setThickness(thickness);
348
                myObj.setValign(valign);
349
                myObj.setWidthFactor(widthFactor);
350
        }
351

    
352
        //TODO Implement
353
        public void transform2Block(double[] bPoint, Point2D insPoint, double[] scale, double rot, List dwgObjectsWithoutBlocks, Map handle_objectsWithoutBlocks, DwgFile callBack) {
354
                 Point2D pointAux = new Point2D.Double(insertionPoint.getX() - bPoint[0],
355
                                 insertionPoint.getY() - bPoint[1]);
356
                 double laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(rot) + (pointAux.getY()*scale[1])*(-1)*Math.sin(rot));
357
                 double laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(rot) + (pointAux.getY()*scale[1])*Math.cos(rot));
358

    
359
                 Point2D.Double newInsertionPoint = new Point2D.Double(laX, laY);
360
                 DwgText transformedEntity = (DwgText) this.clone();
361
                 transformedEntity.setInsertionPoint(newInsertionPoint);
362

    
363
                 if(alignmentPoint != null){
364
                         pointAux = new Point2D.Double(alignmentPoint.getX() - bPoint[0],
365
                                         alignmentPoint.getY() - bPoint[1]);
366
                         laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(rot) + (pointAux.getY()*scale[1])*(-1)*Math.sin(rot));
367
                         laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(rot) + (pointAux.getY()*scale[1])*Math.cos(rot));
368
                         Point2D.Double newAlignPoint = new Point2D.Double(laX, laY);
369
                         transformedEntity.setAlignmentPoint(newAlignPoint);
370
                 }
371
                 //TODO Transformar el resto de parametros en base a los datos del bloque
372
                 //altura, etc.
373
        }
374

    
375
        public int getGeometryType() {
376
                return Geometry.TYPES.POINT;
377
        }
378

    
379
}