Revision 10539 branches/v10/libraries/libDwg/src/com/iver/cit/jdwglib/dwg/objects/DwgPoint.java
DwgPoint.java | ||
---|---|---|
34 | 34 |
*/ |
35 | 35 |
package com.iver.cit.jdwglib.dwg.objects; |
36 | 36 |
|
37 |
import java.util.ArrayList; |
|
38 |
|
|
37 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
|
38 |
import com.iver.cit.gvsig.fmap.core.FPoint3D; |
|
39 |
import com.iver.cit.gvsig.fmap.core.FShape; |
|
39 | 40 |
import com.iver.cit.jdwglib.dwg.DwgObject; |
40 |
import com.iver.cit.jdwglib.dwg.DwgUtil; |
|
41 |
import com.iver.cit.jdwglib.dwg.IDwg2FMap; |
|
42 |
import com.iver.cit.jdwglib.dwg.IDwg3DTestable; |
|
43 |
import com.iver.cit.jdwglib.dwg.IDwgExtrusionable; |
|
44 |
import com.iver.cit.jdwglib.util.AcadExtrusionCalculator; |
|
41 | 45 |
|
42 | 46 |
/** |
43 | 47 |
* The DwgPoint class represents a DWG Point |
44 | 48 |
* |
45 | 49 |
* @author jmorell |
46 | 50 |
*/ |
47 |
public class DwgPoint extends DwgObject { |
|
51 |
public class DwgPoint extends DwgObject |
|
52 |
implements/* IDwgExtrusionable,*/ IDwg3DTestable, IDwg2FMap{ |
|
53 |
public DwgPoint(int index) { |
|
54 |
super(index); |
|
55 |
// TODO Auto-generated constructor stub |
|
56 |
} |
|
48 | 57 |
private double[] point; |
49 | 58 |
private double thickness; |
50 | 59 |
private double[] extrusion; |
51 | 60 |
private double xAxisAngle; |
52 | 61 |
|
53 | 62 |
/** |
54 |
* Read a Point in the DWG format Version 15 |
|
55 |
* |
|
56 |
* @param data Array of unsigned bytes obtained from the DWG binary file |
|
57 |
* @param offset The current bit offset where the value begins |
|
58 |
* @throws Exception If an unexpected bit value is found in the DWG file. Occurs |
|
59 |
* when we are looking for LwPolylines. |
|
60 |
*/ |
|
61 |
public void readDwgPointV15(int[] data, int offset) throws Exception { |
|
62 |
int bitPos = offset; |
|
63 |
bitPos = readObjectHeaderV15(data, bitPos); |
|
64 |
ArrayList v = DwgUtil.getBitDouble(data, bitPos); |
|
65 |
bitPos = ((Integer)v.get(0)).intValue(); |
|
66 |
double x = ((Double)v.get(1)).doubleValue(); |
|
67 |
v = DwgUtil.getBitDouble(data, bitPos); |
|
68 |
bitPos = ((Integer)v.get(0)).intValue(); |
|
69 |
double y = ((Double)v.get(1)).doubleValue(); |
|
70 |
v = DwgUtil.getBitDouble(data, bitPos); |
|
71 |
bitPos = ((Integer)v.get(0)).intValue(); |
|
72 |
double z = ((Double)v.get(1)).doubleValue(); |
|
73 |
double[] coord = new double[]{x, y, z}; |
|
74 |
point = coord; |
|
75 |
v = DwgUtil.testBit(data, bitPos); |
|
76 |
bitPos = ((Integer)v.get(0)).intValue(); |
|
77 |
boolean flag = ((Boolean)v.get(1)).booleanValue(); |
|
78 |
double val; |
|
79 |
if (flag) { |
|
80 |
val=0.0; |
|
81 |
} else { |
|
82 |
v = DwgUtil.getBitDouble(data, bitPos); |
|
83 |
bitPos = ((Integer)v.get(0)).intValue(); |
|
84 |
val = ((Double)v.get(1)).doubleValue(); |
|
85 |
} |
|
86 |
thickness = val; |
|
87 |
v = DwgUtil.testBit(data, bitPos); |
|
88 |
bitPos = ((Integer)v.get(0)).intValue(); |
|
89 |
flag = ((Boolean)v.get(1)).booleanValue(); |
|
90 |
if (flag) { |
|
91 |
x = y = 0.0; |
|
92 |
z = 1.0; |
|
93 |
} else { |
|
94 |
v = DwgUtil.getBitDouble(data, bitPos); |
|
95 |
bitPos = ((Integer)v.get(0)).intValue(); |
|
96 |
x = ((Double)v.get(1)).doubleValue(); |
|
97 |
v = DwgUtil.getBitDouble(data, bitPos); |
|
98 |
bitPos = ((Integer)v.get(0)).intValue(); |
|
99 |
y = ((Double)v.get(1)).doubleValue(); |
|
100 |
v = DwgUtil.getBitDouble(data, bitPos); |
|
101 |
bitPos = ((Integer)v.get(0)).intValue(); |
|
102 |
z = ((Double)v.get(1)).doubleValue(); |
|
103 |
} |
|
104 |
coord = new double[]{x, y, z}; |
|
105 |
extrusion = coord; |
|
106 |
v = DwgUtil.getBitDouble(data, bitPos); |
|
107 |
bitPos = ((Integer)v.get(0)).intValue(); |
|
108 |
val = ((Double)v.get(1)).doubleValue(); |
|
109 |
xAxisAngle = val; |
|
110 |
bitPos = readObjectTailV15(data, bitPos); |
|
111 |
} |
|
112 |
/** |
|
113 | 63 |
* @return Returns the point. |
114 | 64 |
*/ |
115 | 65 |
public double[] getPoint() { |
... | ... | |
157 | 107 |
public void setXAxisAngle(double axisAngle) { |
158 | 108 |
xAxisAngle = axisAngle; |
159 | 109 |
} |
110 |
|
|
160 | 111 |
/* (non-Javadoc) |
112 |
* @see com.iver.cit.jdwglib.dwg.IDwgExtrusionable#applyExtrussion() |
|
113 |
*/ |
|
114 |
public void applyExtrussion() { |
|
115 |
double[] point = getPoint(); |
|
116 |
double[] pointExt = getExtrusion(); |
|
117 |
point = AcadExtrusionCalculator.extrude2(point, pointExt); |
|
118 |
setPoint(point); |
|
119 |
} |
|
120 |
/* (non-Javadoc) |
|
121 |
* @see com.iver.cit.jdwglib.dwg.IDwg3DTestable#has3DData() |
|
122 |
*/ |
|
123 |
public boolean has3DData() { |
|
124 |
return getPoint()[2] != 0.0; |
|
125 |
} |
|
126 |
/* (non-Javadoc) |
|
127 |
* @see com.iver.cit.jdwglib.dwg.IDwg3DTestable#getZ() |
|
128 |
*/ |
|
129 |
public double getZ() { |
|
130 |
return getPoint()[2]; |
|
131 |
} |
|
132 |
public FShape toFMapGeometry(boolean is3DFile) { |
|
133 |
FPoint2D point = null; |
|
134 |
double[] p = getPoint(); |
|
135 |
if (is3DFile) { |
|
136 |
point = new FPoint3D(p[0], p[1], p[2]); |
|
137 |
|
|
138 |
} else { |
|
139 |
point = new FPoint2D(p[0], p[1]); |
|
140 |
} |
|
141 |
return point; |
|
142 |
} |
|
143 |
|
|
144 |
public String toFMapString(boolean is3DFile) { |
|
145 |
if(is3DFile) |
|
146 |
return "FPoint3D"; |
|
147 |
else |
|
148 |
return "FPoint2D"; |
|
149 |
} |
|
150 |
|
|
151 |
public String toString(){ |
|
152 |
return "Point"; |
|
153 |
} |
|
154 |
|
|
155 |
/* (non-Javadoc) |
|
161 | 156 |
* @see java.lang.Object#clone() |
162 | 157 |
*/ |
163 |
public Object clone() { |
|
164 |
DwgPoint dwgPoint = new DwgPoint(); |
|
165 |
dwgPoint.setType(type); |
|
166 |
dwgPoint.setHandle(handle); |
|
167 |
dwgPoint.setVersion(version); |
|
168 |
dwgPoint.setMode(mode); |
|
169 |
dwgPoint.setLayerHandle(layerHandle); |
|
170 |
dwgPoint.setColor(color); |
|
171 |
dwgPoint.setNumReactors(numReactors); |
|
172 |
dwgPoint.setNoLinks(noLinks); |
|
173 |
dwgPoint.setLinetypeFlags(linetypeFlags); |
|
174 |
dwgPoint.setPlotstyleFlags(plotstyleFlags); |
|
175 |
dwgPoint.setSizeInBits(sizeInBits); |
|
176 |
dwgPoint.setExtendedData(extendedData); |
|
177 |
dwgPoint.setGraphicData(graphicData); |
|
178 |
//dwgPoint.setInsideBlock(insideBlock); |
|
179 |
dwgPoint.setPoint(point); |
|
180 |
dwgPoint.setThickness(thickness); |
|
181 |
dwgPoint.setXAxisAngle(xAxisAngle); |
|
182 |
dwgPoint.setExtrusion(extrusion); |
|
183 |
return dwgPoint; |
|
158 |
public Object clone(){ |
|
159 |
DwgPoint obj = new DwgPoint(index); |
|
160 |
this.fill(obj); |
|
161 |
return obj; |
|
184 | 162 |
} |
163 |
|
|
164 |
protected void fill(DwgObject obj){ |
|
165 |
super.fill(obj); |
|
166 |
DwgPoint myObj = (DwgPoint)obj; |
|
167 |
|
|
168 |
myObj.setExtrusion(extrusion); |
|
169 |
myObj.setPoint(point); |
|
170 |
myObj.setThickness(thickness); |
|
171 |
myObj.setXAxisAngle(xAxisAngle); |
|
172 |
} |
|
173 |
|
|
185 | 174 |
} |
Also available in: Unified diff