Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libDwg / src / com / iver / cit / jdwglib / dwg / objects / DwgMText.java @ 23641

History | View | Annotate | Download (7.09 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

    
39
import org.gvsig.fmap.geom.Geometry;
40
import org.gvsig.fmap.geom.GeometryFactory;
41
import org.gvsig.fmap.geom.GeometryManager;
42

    
43
import com.iver.cit.jdwglib.dwg.DwgHandleReference;
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.IDwgExtrusionable;
48
import com.iver.cit.jdwglib.util.AcadExtrusionCalculator;
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) {
253
                GeometryFactory gFactory = GeometryManager.getInstance().getGeometryFactory();
254
                double[] p = getInsertionPoint();
255
                double elev = 0.0;
256
                if (is3DFile) {
257
                        return gFactory.createPoint3D(p[0], p[1], p[2]);
258

    
259
                } else {
260
                        return gFactory.createPoint2D(p[0], p[1]);
261
                }
262
        }
263

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

    
271

    
272

    
273
        public String toString(){
274
                return "MText";
275
        }
276

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

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

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

    
305
}