Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libDwg / src / org / gvsig / dwg / lib / objects / DwgMText.java @ 29001

History | View | Annotate | Download (7.35 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 org.gvsig.dwg.lib.DwgHandleReference;
38
import org.gvsig.dwg.lib.DwgObject;
39
import org.gvsig.dwg.lib.IDwg2FMap;
40
import org.gvsig.dwg.lib.IDwg3DTestable;
41
import org.gvsig.dwg.lib.IDwgExtrusionable;
42
import org.gvsig.dwg.lib.util.AcadExtrusionCalculator;
43
import org.gvsig.fmap.geom.Geometry;
44
import org.gvsig.fmap.geom.GeometryLocator;
45
import org.gvsig.fmap.geom.GeometryManager;
46
import org.gvsig.fmap.geom.exception.CreateGeometryException;
47
import org.gvsig.fmap.geom.primitive.Point;
48

    
49

    
50
/**
51
 * The DwgMText class represents a DWG MText
52
 *
53
 * @author jmorell, azabala
54
 */
55
public class DwgMText extends DwgObject
56
        implements IDwgExtrusionable, IDwg3DTestable, IDwg2FMap {
57
        public DwgMText(int index) {
58
                super(index);
59
                // TODO Auto-generated constructor stub
60
        }
61
        private double[] insertionPoint;
62
        private double[] extrusion;
63
        private double[] xAxisDirection;
64
        private double width;
65
        private double height;
66
        private int attachment;
67
        private int drawingDir;
68
        private double extHeight;
69
        private double extWidth;
70
        private String text;
71
        private int lineSpacingStyle;
72
        private double lineSpacingFactor;
73
        private DwgHandleReference styleHandle = null;
74

    
75

    
76
        /**
77
         * @return Returns the height.
78
         */
79
        public double getHeight() {
80
                return height;
81
        }
82
        /**
83
         * @param height The height to set.
84
         */
85
        public void setHeight(double height) {
86
                this.height = height;
87
        }
88
        /**
89
         * @return Returns the insertionPoint.
90
         */
91
        public double[] getInsertionPoint() {
92
                return insertionPoint;
93
        }
94
        /**
95
         * @param insertionPoint The insertionPoint to set.
96
         */
97
        public void setInsertionPoint(double[] insertionPoint) {
98
                this.insertionPoint = insertionPoint;
99
        }
100
        /**
101
         * @return Returns the text.
102
         */
103
        public String getText() {
104
                return text;
105
        }
106
        /**
107
         * @param text The text to set.
108
         */
109
        public void setText(String text) {
110
                this.text = text;
111
        }
112
        /**
113
         * @return Returns the width.
114
         */
115
        public double getWidth() {
116
                return width;
117
        }
118
        /**
119
         * @param width The width to set.
120
         */
121
        public void setWidth(double width) {
122
                this.width = width;
123
        }
124
    /**
125
     * @return Returns the extrusion.
126
     */
127
    public double[] getExtrusion() {
128
        return extrusion;
129
    }
130

    
131
    /**
132
         * @return Returns the attachment.
133
         */
134
        public int getAttachment() {
135
                return attachment;
136
        }
137
        /**
138
         * @param attachment The attachment to set.
139
         */
140
        public void setAttachment(int attachment) {
141
                this.attachment = attachment;
142
        }
143
        /**
144
         * @return Returns the drawingDir.
145
         */
146
        public int getDrawingDir() {
147
                return drawingDir;
148
        }
149
        /**
150
         * @param drawingDir The drawingDir to set.
151
         */
152
        public void setDrawingDir(int drawingDir) {
153
                this.drawingDir = drawingDir;
154
        }
155
        /**
156
         * @return Returns the extHeight.
157
         */
158
        public double getExtHeight() {
159
                return extHeight;
160
        }
161
        /**
162
         * @param extHeight The extHeight to set.
163
         */
164
        public void setExtHeight(double extHeight) {
165
                this.extHeight = extHeight;
166
        }
167
        /**
168
         * @return Returns the extWidth.
169
         */
170
        public double getExtWidth() {
171
                return extWidth;
172
        }
173
        /**
174
         * @param extWidth The extWidth to set.
175
         */
176
        public void setExtWidth(double extWidth) {
177
                this.extWidth = extWidth;
178
        }
179
        /**
180
         * @return Returns the lineSpacingFactor.
181
         */
182
        public double getLineSpacingFactor() {
183
                return lineSpacingFactor;
184
        }
185
        /**
186
         * @param lineSpacingFactor The lineSpacingFactor to set.
187
         */
188
        public void setLineSpacingFactor(double lineSpacingFactor) {
189
                this.lineSpacingFactor = lineSpacingFactor;
190
        }
191
        /**
192
         * @return Returns the lineSpacingStyle.
193
         */
194
        public int getLineSpacingStyle() {
195
                return lineSpacingStyle;
196
        }
197
        /**
198
         * @param lineSpacingStyle The lineSpacingStyle to set.
199
         */
200
        public void setLineSpacingStyle(int lineSpacingStyle) {
201
                this.lineSpacingStyle = lineSpacingStyle;
202
        }
203
        /**
204
         * @return Returns the styleHandle.
205
         */
206
        public DwgHandleReference getStyleHandle() {
207
                return styleHandle;
208
        }
209
        /**
210
         * @param styleHandle The styleHandle to set.
211
         */
212
        public void setStyleHandle(DwgHandleReference styleHandle) {
213
                this.styleHandle = styleHandle;
214
        }
215
        /**
216
         * @return Returns the xAxisDirection.
217
         */
218
        public double[] getXAxisDirection() {
219
                return xAxisDirection;
220
        }
221
        /**
222
         * @param axisDirection The xAxisDirection to set.
223
         */
224
        public void setXAxisDirection(double[] axisDirection) {
225
                xAxisDirection = axisDirection;
226
        }
227
        /**
228
         * @param extrusion The extrusion to set.
229
         */
230
        public void setExtrusion(double[] extrusion) {
231
                this.extrusion = extrusion;
232
        }
233
        /* (non-Javadoc)
234
         * @see com.iver.cit.jdwglib.dwg.IDwgExtrusionable#applyExtrussion()
235
         */
236
        public void applyExtrussion() {
237
                 double[] mtextPoint = getInsertionPoint();
238
         double[] mtextExt = getExtrusion();
239
         mtextPoint = AcadExtrusionCalculator.extrude2(mtextPoint, mtextExt);
240
         setInsertionPoint(mtextPoint);
241
        }
242
        /* (non-Javadoc)
243
         * @see com.iver.cit.jdwglib.dwg.IDwg3DTestable#has3DData()
244
         */
245
        public boolean has3DData() {
246
                return (getInsertionPoint()[2] != 0.0);
247
        }
248
        public double getZ() {
249
                return getInsertionPoint()[2];
250
        }
251

    
252
        public Geometry toFMapGeometry(boolean is3DFile) throws CreateGeometryException {
253
                GeometryManager gMan = GeometryLocator.getGeometryManager();
254
                double[] p = getInsertionPoint();
255
                Point point = (Point) gMan.create(getGeometryType(),
256
                                getGeometrySubType(is3DFile));
257
                point.setCoordinates(p);
258
                return point;
259
        }
260

    
261
        public String toFMapString(boolean is3DFile) {
262
                if(is3DFile) {
263
                        return "FPoint3D";
264
                } else {
265
                        return "FPoint2D";
266
                }
267
        }
268

    
269

    
270

    
271
        public String toString(){
272
                return "MText";
273
        }
274

    
275
        /* (non-Javadoc)
276
         * @see java.lang.Object#clone()
277
         */
278
        public Object clone(){
279
                DwgMText obj = new DwgMText(index);
280
                this.fill(obj);
281
                return obj;
282
        }
283

    
284
        protected void fill(DwgObject obj){
285
                super.fill(obj);
286
                DwgMText myObj = (DwgMText)obj;
287

    
288
                myObj.setAttachment(attachment);
289
                myObj.setDrawingDir(drawingDir);
290
                myObj.setExtHeight(extHeight);
291
                myObj.setExtrusion(extrusion);
292
                myObj.setExtWidth(extWidth);
293
                myObj.setHeight(extHeight);
294
                myObj.setInsertionPoint(insertionPoint);
295
                myObj.setLineSpacingFactor(lineSpacingFactor);
296
                myObj.setLineSpacingStyle(lineSpacingStyle);
297
                myObj.setStyleHandle(styleHandle);
298
                myObj.setText(text);
299
                myObj.setWidth(width);
300
                myObj.setXAxisDirection(xAxisDirection);
301
        }
302

    
303
        public int getGeometrySubType(boolean is3DFile) {
304
                if (is3DFile) {
305
                        return Geometry.SUBTYPES.GEOM3D;
306
                } else {
307
                        return Geometry.SUBTYPES.GEOM2D;
308
                }
309
        }
310

    
311
        public int getGeometryType() {
312
                return Geometry.TYPES.POINT;
313
        }
314

    
315
}