svn-gvsig-desktop / trunk / libraries / libDwg / src / com / iver / cit / jdwglib / dwg / objects / DwgAttrib.java @ 2896
History | View | Annotate | Download (12.3 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.Vector; |
39 |
|
40 |
import com.iver.cit.jdwglib.dwg.DwgObject; |
41 |
import com.iver.cit.jdwglib.dwg.DwgUtil; |
42 |
|
43 |
/**
|
44 |
* The DwgAttrib class represents a DWG Attrib
|
45 |
*
|
46 |
* @author jmorell
|
47 |
*/
|
48 |
public class DwgAttrib extends DwgObject { |
49 |
private int dataFlag; |
50 |
private double elevation; |
51 |
private Point2D insertionPoint; |
52 |
private Point2D alignmentPoint; |
53 |
private double[] extrusion; |
54 |
private double thickness; |
55 |
private double obliqueAngle; |
56 |
private double rotationAngle; |
57 |
private double height; |
58 |
private double widthFactor; |
59 |
private String text; |
60 |
private int generation; |
61 |
private int halign; |
62 |
private int valign; |
63 |
private String tag; |
64 |
private int fieldLength; |
65 |
private int flags; |
66 |
private String prompt; |
67 |
private int styleHandle; |
68 |
|
69 |
/**
|
70 |
* Read an Attrib in the DWG format Version 15
|
71 |
*
|
72 |
* @param data Array of unsigned bytes obtained from the DWG binary file
|
73 |
* @param offset The current bit offset where the value begins
|
74 |
* @throws Exception If an unexpected bit value is found in the DWG file. Occurs
|
75 |
* when we are looking for LwPolylines.
|
76 |
*/
|
77 |
public void readDwgAttribV15(int[] data, int offset) throws Exception { |
78 |
//System.out.println("readDwgAttdef() executed ...");
|
79 |
int bitPos = offset;
|
80 |
bitPos = readObjectHeaderV15(data, bitPos); |
81 |
Vector v = DwgUtil.getRawChar(data, bitPos);
|
82 |
bitPos = ((Integer)v.get(0)).intValue(); |
83 |
int dflag = ((Integer)v.get(1)).intValue(); |
84 |
dataFlag = dflag; |
85 |
if ((dflag & 0x1)==0) { |
86 |
v = DwgUtil.getRawDouble(data, bitPos); |
87 |
bitPos = ((Integer)v.get(0)).intValue(); |
88 |
double elev = ((Double)v.get(1)).doubleValue(); |
89 |
elevation = elev; |
90 |
} |
91 |
v = DwgUtil.getRawDouble(data, bitPos); |
92 |
bitPos = ((Integer)v.get(0)).intValue(); |
93 |
double x1 = ((Double)v.get(1)).doubleValue(); |
94 |
v = DwgUtil.getRawDouble(data, bitPos); |
95 |
bitPos = ((Integer)v.get(0)).intValue(); |
96 |
double y1 = ((Double)v.get(1)).doubleValue(); |
97 |
insertionPoint = new Point2D.Double(x1, y1); |
98 |
double x=0, y=0, z=0; |
99 |
if ((dflag & 0x2)==0) { |
100 |
v = DwgUtil.getDefaultDouble(data, bitPos, x1); |
101 |
bitPos = ((Integer)v.get(0)).intValue(); |
102 |
x = ((Double)v.get(1)).doubleValue(); |
103 |
v = DwgUtil.getDefaultDouble(data, bitPos, y1); |
104 |
bitPos = ((Integer)v.get(0)).intValue(); |
105 |
y = ((Double)v.get(1)).doubleValue(); |
106 |
} |
107 |
alignmentPoint = new Point2D.Double(x, y); |
108 |
v = DwgUtil.testBit(data, bitPos); |
109 |
bitPos = ((Integer)v.get(0)).intValue(); |
110 |
boolean flag = ((Boolean)v.get(1)).booleanValue(); |
111 |
if (flag) {
|
112 |
y = 0.0;
|
113 |
x = y; |
114 |
z = 1.0;
|
115 |
} else {
|
116 |
v = DwgUtil.getBitDouble(data, bitPos); |
117 |
bitPos = ((Integer)v.get(0)).intValue(); |
118 |
x = ((Double)v.get(1)).doubleValue(); |
119 |
v = DwgUtil.getBitDouble(data, bitPos); |
120 |
bitPos = ((Integer)v.get(0)).intValue(); |
121 |
y = ((Double)v.get(1)).doubleValue(); |
122 |
v = DwgUtil.getBitDouble(data, bitPos); |
123 |
bitPos = ((Integer)v.get(0)).intValue(); |
124 |
z = ((Double)v.get(1)).doubleValue(); |
125 |
} |
126 |
extrusion = new double[]{x, y, z}; |
127 |
v = DwgUtil.testBit(data, bitPos); |
128 |
bitPos = ((Integer)v.get(0)).intValue(); |
129 |
flag = ((Boolean)v.get(1)).booleanValue(); |
130 |
double th;
|
131 |
if (flag) {
|
132 |
th=0.0;
|
133 |
} else {
|
134 |
v = DwgUtil.getBitDouble(data, bitPos); |
135 |
bitPos = ((Integer)v.get(0)).intValue(); |
136 |
th = ((Double)v.get(1)).doubleValue(); |
137 |
} |
138 |
thickness = th; |
139 |
if ((dflag & 0x4)==0) { |
140 |
v = DwgUtil.getRawDouble(data, bitPos); |
141 |
bitPos = ((Integer)v.get(0)).intValue(); |
142 |
double oblique = ((Double)v.get(1)).doubleValue(); |
143 |
obliqueAngle = oblique; |
144 |
} |
145 |
if ((dflag & 0x8)==0) { |
146 |
v = DwgUtil.getRawDouble(data, bitPos); |
147 |
bitPos = ((Integer)v.get(0)).intValue(); |
148 |
double rot = ((Double)v.get(1)).doubleValue(); |
149 |
rotationAngle = rot; |
150 |
} |
151 |
v = DwgUtil.getRawDouble(data, bitPos); |
152 |
bitPos = ((Integer)v.get(0)).intValue(); |
153 |
double height = ((Double)v.get(1)).doubleValue(); |
154 |
this.height = height;
|
155 |
if ((dflag & 0x10)==0) { |
156 |
v = DwgUtil.getRawDouble(data, bitPos); |
157 |
bitPos = ((Integer)v.get(0)).intValue(); |
158 |
double width = ((Double)v.get(1)).doubleValue(); |
159 |
widthFactor = width; |
160 |
} |
161 |
v = DwgUtil.getTextString(data, bitPos); |
162 |
bitPos = ((Integer)v.get(0)).intValue(); |
163 |
String text = (String)v.get(1); |
164 |
this.text = text;
|
165 |
if ((dflag & 0x20)==0) { |
166 |
v = DwgUtil.getBitShort(data, bitPos); |
167 |
bitPos = ((Integer)v.get(0)).intValue(); |
168 |
int gen = ((Integer)v.get(1)).intValue(); |
169 |
generation = gen; |
170 |
} |
171 |
if ((dflag & 0x40)==0) { |
172 |
v = DwgUtil.getBitShort(data, bitPos); |
173 |
bitPos = ((Integer)v.get(0)).intValue(); |
174 |
int halign = ((Integer)v.get(1)).intValue(); |
175 |
this.halign = halign;
|
176 |
} |
177 |
if ((dflag & 0x80)==0) { |
178 |
v = DwgUtil.getBitShort(data, bitPos); |
179 |
bitPos = ((Integer)v.get(0)).intValue(); |
180 |
int valign = ((Integer)v.get(1)).intValue(); |
181 |
this.valign = valign;
|
182 |
} |
183 |
v = DwgUtil.getTextString(data, bitPos); |
184 |
bitPos = ((Integer)v.get(0)).intValue(); |
185 |
String tag = (String)v.get(1); |
186 |
this.tag = tag;
|
187 |
v = DwgUtil.getBitShort(data, bitPos); |
188 |
bitPos = ((Integer)v.get(0)).intValue(); |
189 |
int fl = ((Integer)v.get(1)).intValue(); |
190 |
fieldLength = fl; |
191 |
v = DwgUtil.getRawChar(data, bitPos); |
192 |
bitPos = ((Integer)v.get(0)).intValue(); |
193 |
int flags = ((Integer)v.get(1)).intValue(); |
194 |
this.flags = flags;
|
195 |
bitPos = readObjectTailV15(data, bitPos); |
196 |
v = DwgUtil.getHandle(data, bitPos); |
197 |
bitPos = ((Integer)v.get(0)).intValue(); |
198 |
int[] handle = new int[v.size()-1]; |
199 |
for (int j=1;j<v.size();j++) { |
200 |
handle[j-1] = ((Integer)v.get(j)).intValue(); |
201 |
} |
202 |
Vector handleVect = new Vector(); |
203 |
for (int i=0;i<handle.length;i++) { |
204 |
handleVect.add(new Integer(handle[i])); |
205 |
} |
206 |
styleHandle = DwgUtil.handleBinToHandleInt(handleVect); |
207 |
} |
208 |
/**
|
209 |
* @return Returns the elevation.
|
210 |
*/
|
211 |
public double getElevation() { |
212 |
return elevation;
|
213 |
} |
214 |
/**
|
215 |
* @param elevation The elevation to set.
|
216 |
*/
|
217 |
public void setElevation(double elevation) { |
218 |
this.elevation = elevation;
|
219 |
} |
220 |
/**
|
221 |
* @return Returns the extrusion.
|
222 |
*/
|
223 |
public double[] getExtrusion() { |
224 |
return extrusion;
|
225 |
} |
226 |
/**
|
227 |
* @return Returns the insertionPoint.
|
228 |
*/
|
229 |
public Point2D getInsertionPoint() { |
230 |
return insertionPoint;
|
231 |
} |
232 |
/**
|
233 |
* @param insertionPoint The insertionPoint to set.
|
234 |
*/
|
235 |
public void setInsertionPoint(Point2D insertionPoint) { |
236 |
this.insertionPoint = insertionPoint;
|
237 |
} |
238 |
/* (non-Javadoc)
|
239 |
* @see java.lang.Object#clone()
|
240 |
*/
|
241 |
public Object clone() { |
242 |
DwgAttrib dwgAttrib = new DwgAttrib();
|
243 |
dwgAttrib.setType(type); |
244 |
dwgAttrib.setHandle(handle); |
245 |
dwgAttrib.setVersion(version); |
246 |
dwgAttrib.setMode(mode); |
247 |
dwgAttrib.setLayerHandle(layerHandle); |
248 |
dwgAttrib.setColor(color); |
249 |
dwgAttrib.setNumReactors(numReactors); |
250 |
dwgAttrib.setNoLinks(noLinks); |
251 |
dwgAttrib.setLinetypeFlags(linetypeFlags); |
252 |
dwgAttrib.setPlotstyleFlags(plotstyleFlags); |
253 |
dwgAttrib.setSizeInBits(sizeInBits); |
254 |
dwgAttrib.setExtendedData(extendedData); |
255 |
dwgAttrib.setGraphicData(graphicData); |
256 |
//dwgAttrib.setInsideBlock(insideBlock);
|
257 |
dwgAttrib.setDataFlag(dataFlag); |
258 |
dwgAttrib.setElevation(elevation); |
259 |
dwgAttrib.setInsertionPoint(insertionPoint); |
260 |
dwgAttrib.setAlignmentPoint(alignmentPoint); |
261 |
dwgAttrib.setExtrusion(extrusion); |
262 |
dwgAttrib.setThickness(thickness); |
263 |
dwgAttrib.setObliqueAngle(obliqueAngle); |
264 |
dwgAttrib.setRotationAngle(rotationAngle); |
265 |
dwgAttrib.setHeight(height); |
266 |
dwgAttrib.setWidthFactor(widthFactor); |
267 |
dwgAttrib.setText(text); |
268 |
dwgAttrib.setGeneration(generation); |
269 |
dwgAttrib.setHalign(halign); |
270 |
dwgAttrib.setValign(valign); |
271 |
dwgAttrib.setTag(tag); |
272 |
dwgAttrib.setFieldLength(fieldLength); |
273 |
dwgAttrib.setFlags(flags); |
274 |
dwgAttrib.setPrompt(prompt); |
275 |
dwgAttrib.setStyleHandle(styleHandle); |
276 |
return dwgAttrib;
|
277 |
} |
278 |
/**
|
279 |
* @return Returns the alignmentPoint.
|
280 |
*/
|
281 |
public Point2D getAlignmentPoint() { |
282 |
return alignmentPoint;
|
283 |
} |
284 |
/**
|
285 |
* @param alignmentPoint The alignmentPoint to set.
|
286 |
*/
|
287 |
public void setAlignmentPoint(Point2D alignmentPoint) { |
288 |
this.alignmentPoint = alignmentPoint;
|
289 |
} |
290 |
/**
|
291 |
* @return Returns the dataFlag.
|
292 |
*/
|
293 |
public int getDataFlag() { |
294 |
return dataFlag;
|
295 |
} |
296 |
/**
|
297 |
* @param dataFlag The dataFlag to set.
|
298 |
*/
|
299 |
public void setDataFlag(int dataFlag) { |
300 |
this.dataFlag = dataFlag;
|
301 |
} |
302 |
/**
|
303 |
* @return Returns the fieldLength.
|
304 |
*/
|
305 |
public int getFieldLength() { |
306 |
return fieldLength;
|
307 |
} |
308 |
/**
|
309 |
* @param fieldLength The fieldLength to set.
|
310 |
*/
|
311 |
public void setFieldLength(int fieldLength) { |
312 |
this.fieldLength = fieldLength;
|
313 |
} |
314 |
/**
|
315 |
* @return Returns the flags.
|
316 |
*/
|
317 |
public int getFlags() { |
318 |
return flags;
|
319 |
} |
320 |
/**
|
321 |
* @param flags The flags to set.
|
322 |
*/
|
323 |
public void setFlags(int flags) { |
324 |
this.flags = flags;
|
325 |
} |
326 |
/**
|
327 |
* @return Returns the generation.
|
328 |
*/
|
329 |
public int getGeneration() { |
330 |
return generation;
|
331 |
} |
332 |
/**
|
333 |
* @param generation The generation to set.
|
334 |
*/
|
335 |
public void setGeneration(int generation) { |
336 |
this.generation = generation;
|
337 |
} |
338 |
/**
|
339 |
* @return Returns the halign.
|
340 |
*/
|
341 |
public int getHalign() { |
342 |
return halign;
|
343 |
} |
344 |
/**
|
345 |
* @param halign The halign to set.
|
346 |
*/
|
347 |
public void setHalign(int halign) { |
348 |
this.halign = halign;
|
349 |
} |
350 |
/**
|
351 |
* @return Returns the height.
|
352 |
*/
|
353 |
public double getHeight() { |
354 |
return height;
|
355 |
} |
356 |
/**
|
357 |
* @param height The height to set.
|
358 |
*/
|
359 |
public void setHeight(double height) { |
360 |
this.height = height;
|
361 |
} |
362 |
/**
|
363 |
* @return Returns the obliqueAngle.
|
364 |
*/
|
365 |
public double getObliqueAngle() { |
366 |
return obliqueAngle;
|
367 |
} |
368 |
/**
|
369 |
* @param obliqueAngle The obliqueAngle to set.
|
370 |
*/
|
371 |
public void setObliqueAngle(double obliqueAngle) { |
372 |
this.obliqueAngle = obliqueAngle;
|
373 |
} |
374 |
/**
|
375 |
* @return Returns the prompt.
|
376 |
*/
|
377 |
public String getPrompt() { |
378 |
return prompt;
|
379 |
} |
380 |
/**
|
381 |
* @param prompt The prompt to set.
|
382 |
*/
|
383 |
public void setPrompt(String prompt) { |
384 |
this.prompt = prompt;
|
385 |
} |
386 |
/**
|
387 |
* @return Returns the rotationAngle.
|
388 |
*/
|
389 |
public double getRotationAngle() { |
390 |
return rotationAngle;
|
391 |
} |
392 |
/**
|
393 |
* @param rotationAngle The rotationAngle to set.
|
394 |
*/
|
395 |
public void setRotationAngle(double rotationAngle) { |
396 |
this.rotationAngle = rotationAngle;
|
397 |
} |
398 |
/**
|
399 |
* @return Returns the styleHandle.
|
400 |
*/
|
401 |
public int getStyleHandle() { |
402 |
return styleHandle;
|
403 |
} |
404 |
/**
|
405 |
* @param styleHandle The styleHandle to set.
|
406 |
*/
|
407 |
public void setStyleHandle(int styleHandle) { |
408 |
this.styleHandle = styleHandle;
|
409 |
} |
410 |
/**
|
411 |
* @return Returns the tag.
|
412 |
*/
|
413 |
public String getTag() { |
414 |
return tag;
|
415 |
} |
416 |
/**
|
417 |
* @param tag The tag to set.
|
418 |
*/
|
419 |
public void setTag(String tag) { |
420 |
this.tag = tag;
|
421 |
} |
422 |
/**
|
423 |
* @return Returns the text.
|
424 |
*/
|
425 |
public String getText() { |
426 |
return text;
|
427 |
} |
428 |
/**
|
429 |
* @param text The text to set.
|
430 |
*/
|
431 |
public void setText(String text) { |
432 |
this.text = text;
|
433 |
} |
434 |
/**
|
435 |
* @return Returns the thickness.
|
436 |
*/
|
437 |
public double getThickness() { |
438 |
return thickness;
|
439 |
} |
440 |
/**
|
441 |
* @param thickness The thickness to set.
|
442 |
*/
|
443 |
public void setThickness(double thickness) { |
444 |
this.thickness = thickness;
|
445 |
} |
446 |
/**
|
447 |
* @return Returns the valign.
|
448 |
*/
|
449 |
public int getValign() { |
450 |
return valign;
|
451 |
} |
452 |
/**
|
453 |
* @param valign The valign to set.
|
454 |
*/
|
455 |
public void setValign(int valign) { |
456 |
this.valign = valign;
|
457 |
} |
458 |
/**
|
459 |
* @return Returns the widthFactor.
|
460 |
*/
|
461 |
public double getWidthFactor() { |
462 |
return widthFactor;
|
463 |
} |
464 |
/**
|
465 |
* @param widthFactor The widthFactor to set.
|
466 |
*/
|
467 |
public void setWidthFactor(double widthFactor) { |
468 |
this.widthFactor = widthFactor;
|
469 |
} |
470 |
/**
|
471 |
* @param extrusion The extrusion to set.
|
472 |
*/
|
473 |
public void setExtrusion(double[] extrusion) { |
474 |
this.extrusion = extrusion;
|
475 |
} |
476 |
} |