root / trunk / org.gvsig.dwg / org.gvsig.dwg.lib / src / main / java / org / gvsig / dwg / lib / objects / DwgMText.java @ 5
History | View | Annotate | Download (7.53 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.dwg.lib.util.FMapUtil; |
44 |
import org.gvsig.fmap.geom.Geometry; |
45 |
import org.gvsig.fmap.geom.GeometryLocator; |
46 |
import org.gvsig.fmap.geom.GeometryManager; |
47 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
48 |
import org.gvsig.fmap.geom.primitive.Point; |
49 |
|
50 |
|
51 |
/**
|
52 |
* The DwgMText class represents a DWG MText
|
53 |
*
|
54 |
* @author jmorell, azabala
|
55 |
*/
|
56 |
public class DwgMText extends DwgObject |
57 |
implements IDwgExtrusionable, IDwg3DTestable, IDwg2FMap {
|
58 |
public DwgMText(int index) { |
59 |
super(index);
|
60 |
// TODO Auto-generated constructor stub
|
61 |
} |
62 |
private double[] insertionPoint; |
63 |
private double[] extrusion; |
64 |
private double[] xAxisDirection; |
65 |
private double width; |
66 |
private double height; |
67 |
private int attachment; |
68 |
private int drawingDir; |
69 |
private double extHeight; |
70 |
private double extWidth; |
71 |
private String text; |
72 |
private int lineSpacingStyle; |
73 |
private double lineSpacingFactor; |
74 |
private DwgHandleReference styleHandle = null; |
75 |
|
76 |
|
77 |
/**
|
78 |
* @return Returns the height.
|
79 |
*/
|
80 |
public double getHeight() { |
81 |
return height;
|
82 |
} |
83 |
/**
|
84 |
* @param height The height to set.
|
85 |
*/
|
86 |
public void setHeight(double height) { |
87 |
this.height = height;
|
88 |
} |
89 |
/**
|
90 |
* @return Returns the insertionPoint.
|
91 |
*/
|
92 |
public double[] getInsertionPoint() { |
93 |
return insertionPoint;
|
94 |
} |
95 |
/**
|
96 |
* @param insertionPoint The insertionPoint to set.
|
97 |
*/
|
98 |
public void setInsertionPoint(double[] insertionPoint) { |
99 |
this.insertionPoint = insertionPoint;
|
100 |
} |
101 |
/**
|
102 |
* @return Returns the text.
|
103 |
*/
|
104 |
public String getText() { |
105 |
return text;
|
106 |
} |
107 |
/**
|
108 |
* @param text The text to set.
|
109 |
*/
|
110 |
public void setText(String text) { |
111 |
this.text = text;
|
112 |
} |
113 |
/**
|
114 |
* @return Returns the width.
|
115 |
*/
|
116 |
public double getWidth() { |
117 |
return width;
|
118 |
} |
119 |
/**
|
120 |
* @param width The width to set.
|
121 |
*/
|
122 |
public void setWidth(double width) { |
123 |
this.width = width;
|
124 |
} |
125 |
/**
|
126 |
* @return Returns the extrusion.
|
127 |
*/
|
128 |
public double[] getExtrusion() { |
129 |
return extrusion;
|
130 |
} |
131 |
|
132 |
/**
|
133 |
* @return Returns the attachment.
|
134 |
*/
|
135 |
public int getAttachment() { |
136 |
return attachment;
|
137 |
} |
138 |
/**
|
139 |
* @param attachment The attachment to set.
|
140 |
*/
|
141 |
public void setAttachment(int attachment) { |
142 |
this.attachment = attachment;
|
143 |
} |
144 |
/**
|
145 |
* @return Returns the drawingDir.
|
146 |
*/
|
147 |
public int getDrawingDir() { |
148 |
return drawingDir;
|
149 |
} |
150 |
/**
|
151 |
* @param drawingDir The drawingDir to set.
|
152 |
*/
|
153 |
public void setDrawingDir(int drawingDir) { |
154 |
this.drawingDir = drawingDir;
|
155 |
} |
156 |
/**
|
157 |
* @return Returns the extHeight.
|
158 |
*/
|
159 |
public double getExtHeight() { |
160 |
return extHeight;
|
161 |
} |
162 |
/**
|
163 |
* @param extHeight The extHeight to set.
|
164 |
*/
|
165 |
public void setExtHeight(double extHeight) { |
166 |
this.extHeight = extHeight;
|
167 |
} |
168 |
/**
|
169 |
* @return Returns the extWidth.
|
170 |
*/
|
171 |
public double getExtWidth() { |
172 |
return extWidth;
|
173 |
} |
174 |
/**
|
175 |
* @param extWidth The extWidth to set.
|
176 |
*/
|
177 |
public void setExtWidth(double extWidth) { |
178 |
this.extWidth = extWidth;
|
179 |
} |
180 |
/**
|
181 |
* @return Returns the lineSpacingFactor.
|
182 |
*/
|
183 |
public double getLineSpacingFactor() { |
184 |
return lineSpacingFactor;
|
185 |
} |
186 |
/**
|
187 |
* @param lineSpacingFactor The lineSpacingFactor to set.
|
188 |
*/
|
189 |
public void setLineSpacingFactor(double lineSpacingFactor) { |
190 |
this.lineSpacingFactor = lineSpacingFactor;
|
191 |
} |
192 |
/**
|
193 |
* @return Returns the lineSpacingStyle.
|
194 |
*/
|
195 |
public int getLineSpacingStyle() { |
196 |
return lineSpacingStyle;
|
197 |
} |
198 |
/**
|
199 |
* @param lineSpacingStyle The lineSpacingStyle to set.
|
200 |
*/
|
201 |
public void setLineSpacingStyle(int lineSpacingStyle) { |
202 |
this.lineSpacingStyle = lineSpacingStyle;
|
203 |
} |
204 |
/**
|
205 |
* @return Returns the styleHandle.
|
206 |
*/
|
207 |
public DwgHandleReference getStyleHandle() {
|
208 |
return styleHandle;
|
209 |
} |
210 |
/**
|
211 |
* @param styleHandle The styleHandle to set.
|
212 |
*/
|
213 |
public void setStyleHandle(DwgHandleReference styleHandle) { |
214 |
this.styleHandle = styleHandle;
|
215 |
} |
216 |
/**
|
217 |
* @return Returns the xAxisDirection.
|
218 |
*/
|
219 |
public double[] getXAxisDirection() { |
220 |
return xAxisDirection;
|
221 |
} |
222 |
/**
|
223 |
* @param axisDirection The xAxisDirection to set.
|
224 |
*/
|
225 |
public void setXAxisDirection(double[] axisDirection) { |
226 |
xAxisDirection = axisDirection; |
227 |
} |
228 |
/**
|
229 |
* @param extrusion The extrusion to set.
|
230 |
*/
|
231 |
public void setExtrusion(double[] extrusion) { |
232 |
this.extrusion = extrusion;
|
233 |
} |
234 |
/* (non-Javadoc)
|
235 |
* @see com.iver.cit.jdwglib.dwg.IDwgExtrusionable#applyExtrussion()
|
236 |
*/
|
237 |
public void applyExtrussion() { |
238 |
double[] mtextPoint = getInsertionPoint(); |
239 |
double[] mtextExt = getExtrusion(); |
240 |
mtextPoint = AcadExtrusionCalculator.extrude2(mtextPoint, mtextExt); |
241 |
setInsertionPoint(mtextPoint); |
242 |
} |
243 |
/* (non-Javadoc)
|
244 |
* @see com.iver.cit.jdwglib.dwg.IDwg3DTestable#has3DData()
|
245 |
*/
|
246 |
public boolean has3DData() { |
247 |
return (getInsertionPoint()[2] != 0.0); |
248 |
} |
249 |
public double getZ() { |
250 |
return getInsertionPoint()[2]; |
251 |
} |
252 |
|
253 |
public Geometry toFMapGeometry(boolean is3DFile) throws CreateGeometryException { |
254 |
GeometryManager gMan = GeometryLocator.getGeometryManager(); |
255 |
double[] p = getInsertionPoint(); |
256 |
Point point = (Point) gMan.create(getGeometryType(), |
257 |
getGeometrySubType(is3DFile)); |
258 |
point.setCoordinates(p); |
259 |
return point;
|
260 |
} |
261 |
|
262 |
public String toFMapString(boolean is3DFile) { |
263 |
if(is3DFile) {
|
264 |
return "FPoint3D"; |
265 |
} else {
|
266 |
return "FPoint2D"; |
267 |
} |
268 |
} |
269 |
|
270 |
|
271 |
|
272 |
public String toString(){ |
273 |
return "MText"; |
274 |
} |
275 |
|
276 |
/* (non-Javadoc)
|
277 |
* @see java.lang.Object#clone()
|
278 |
*/
|
279 |
public Object clone(){ |
280 |
DwgMText obj = new DwgMText(index);
|
281 |
this.fill(obj);
|
282 |
return obj;
|
283 |
} |
284 |
|
285 |
protected void fill(DwgObject obj){ |
286 |
super.fill(obj);
|
287 |
DwgMText myObj = (DwgMText)obj; |
288 |
|
289 |
myObj.setAttachment(attachment); |
290 |
myObj.setDrawingDir(drawingDir); |
291 |
myObj.setExtHeight(extHeight); |
292 |
myObj.setExtrusion(extrusion); |
293 |
myObj.setExtWidth(extWidth); |
294 |
myObj.setHeight(extHeight); |
295 |
myObj.setInsertionPoint(insertionPoint); |
296 |
myObj.setLineSpacingFactor(lineSpacingFactor); |
297 |
myObj.setLineSpacingStyle(lineSpacingStyle); |
298 |
myObj.setStyleHandle(styleHandle); |
299 |
myObj.setText(text); |
300 |
myObj.setWidth(width); |
301 |
myObj.setXAxisDirection(xAxisDirection); |
302 |
} |
303 |
|
304 |
public int getGeometryType() { |
305 |
return Geometry.TYPES.POINT;
|
306 |
} |
307 |
|
308 |
} |