root / trunk / libraries / libDwg / src / com / iver / cit / jdwglib / dwg / objects / DwgSolid.java @ 10632
History | View | Annotate | Download (9.63 KB)
1 | 2896 | jmorell | /* 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 | 9830 | azabala | import java.awt.geom.Point2D; |
38 | 10632 | azabala | import java.util.ArrayList; |
39 | 9843 | azabala | import java.util.List; |
40 | 10240 | azabala | import java.util.Map; |
41 | 2896 | jmorell | |
42 | 9830 | azabala | import com.iver.cit.gvsig.fmap.core.FPolyline2D; |
43 | import com.iver.cit.gvsig.fmap.core.FShape; |
||
44 | 9843 | azabala | import com.iver.cit.jdwglib.dwg.DwgFile; |
45 | 2896 | jmorell | import com.iver.cit.jdwglib.dwg.DwgObject; |
46 | 9830 | azabala | import com.iver.cit.jdwglib.dwg.IDwg2FMap; |
47 | 9825 | azabala | import com.iver.cit.jdwglib.dwg.IDwg3DTestable; |
48 | 9843 | azabala | import com.iver.cit.jdwglib.dwg.IDwgBlockMember; |
49 | 9825 | azabala | import com.iver.cit.jdwglib.dwg.IDwgExtrusionable; |
50 | import com.iver.cit.jdwglib.util.AcadExtrusionCalculator; |
||
51 | 9830 | azabala | import com.iver.cit.jdwglib.util.FMapUtil; |
52 | 2896 | jmorell | |
53 | /**
|
||
54 | * The DwgSolid class represents a DWG Solid
|
||
55 | *
|
||
56 | 9830 | azabala | * @author jmorell, azabala
|
57 | 2896 | jmorell | */
|
58 | 9825 | azabala | public class DwgSolid extends DwgObject |
59 | 9843 | azabala | implements IDwgExtrusionable, IDwg3DTestable, IDwg2FMap, IDwgBlockMember{
|
60 | 9718 | azabala | public DwgSolid(int index) { |
61 | super(index);
|
||
62 | // TODO Auto-generated constructor stub
|
||
63 | } |
||
64 | 2896 | jmorell | private double thickness; |
65 | private double elevation; |
||
66 | private double[] corner1; |
||
67 | private double[] corner2; |
||
68 | private double[] corner3; |
||
69 | private double[] corner4; |
||
70 | private double[] extrusion; |
||
71 | |||
72 | /**
|
||
73 | * Read a Solid in the DWG format Version 15
|
||
74 | *
|
||
75 | * @param data Array of unsigned bytes obtained from the DWG binary file
|
||
76 | * @param offset The current bit offset where the value begins
|
||
77 | * @throws Exception If an unexpected bit value is found in the DWG file. Occurs
|
||
78 | * when we are looking for LwPolylines.
|
||
79 | */
|
||
80 | public void readDwgSolidV15(int[] data, int offset) throws Exception { |
||
81 | 9947 | azabala | |
82 | 2896 | jmorell | } |
83 | /**
|
||
84 | * @return Returns the corner1.
|
||
85 | */
|
||
86 | public double[] getCorner1() { |
||
87 | return corner1;
|
||
88 | } |
||
89 | /**
|
||
90 | * @param corner1 The corner1 to set.
|
||
91 | */
|
||
92 | public void setCorner1(double[] corner1) { |
||
93 | this.corner1 = corner1;
|
||
94 | } |
||
95 | /**
|
||
96 | * @return Returns the corner2.
|
||
97 | */
|
||
98 | public double[] getCorner2() { |
||
99 | return corner2;
|
||
100 | } |
||
101 | /**
|
||
102 | * @param corner2 The corner2 to set.
|
||
103 | */
|
||
104 | public void setCorner2(double[] corner2) { |
||
105 | this.corner2 = corner2;
|
||
106 | } |
||
107 | /**
|
||
108 | * @return Returns the corner3.
|
||
109 | */
|
||
110 | public double[] getCorner3() { |
||
111 | return corner3;
|
||
112 | } |
||
113 | /**
|
||
114 | * @param corner3 The corner3 to set.
|
||
115 | */
|
||
116 | public void setCorner3(double[] corner3) { |
||
117 | this.corner3 = corner3;
|
||
118 | } |
||
119 | /**
|
||
120 | * @return Returns the corner4.
|
||
121 | */
|
||
122 | public double[] getCorner4() { |
||
123 | return corner4;
|
||
124 | } |
||
125 | /**
|
||
126 | * @param corner4 The corner4 to set.
|
||
127 | */
|
||
128 | public void setCorner4(double[] corner4) { |
||
129 | this.corner4 = corner4;
|
||
130 | } |
||
131 | /**
|
||
132 | * @return Returns the elevation.
|
||
133 | */
|
||
134 | public double getElevation() { |
||
135 | return elevation;
|
||
136 | } |
||
137 | /**
|
||
138 | * @param elevation The elevation to set.
|
||
139 | */
|
||
140 | public void setElevation(double elevation) { |
||
141 | this.elevation = elevation;
|
||
142 | } |
||
143 | /**
|
||
144 | * @return Returns the extrusion.
|
||
145 | */
|
||
146 | public double[] getExtrusion() { |
||
147 | return extrusion;
|
||
148 | } |
||
149 | /* (non-Javadoc)
|
||
150 | * @see java.lang.Object#clone()
|
||
151 | */
|
||
152 | 10174 | fdiaz | // public Object clone() {
|
153 | // DwgSolid dwgSolid = new DwgSolid(index);
|
||
154 | // dwgSolid.setType(type);
|
||
155 | // dwgSolid.setHandle(handle);
|
||
156 | // dwgSolid.setVersion(version);
|
||
157 | // dwgSolid.setMode(mode);
|
||
158 | // dwgSolid.setLayerHandle(layerHandle);
|
||
159 | // dwgSolid.setColor(color);
|
||
160 | // dwgSolid.setNumReactors(numReactors);
|
||
161 | // dwgSolid.setNoLinks(noLinks);
|
||
162 | // dwgSolid.setLinetypeFlags(linetypeFlags);
|
||
163 | // dwgSolid.setPlotstyleFlags(plotstyleFlags);
|
||
164 | // dwgSolid.setSizeInBits(sizeInBits);
|
||
165 | // dwgSolid.setExtendedData(extendedData);
|
||
166 | // dwgSolid.setGraphicData(graphicData);
|
||
167 | // //dwgSolid.setInsideBlock(insideBlock);
|
||
168 | // dwgSolid.setThickness(thickness);
|
||
169 | // dwgSolid.setElevation(elevation);
|
||
170 | // dwgSolid.setCorner1(corner1);
|
||
171 | // dwgSolid.setCorner2(corner2);
|
||
172 | // dwgSolid.setCorner3(corner3);
|
||
173 | // dwgSolid.setCorner4(corner4);
|
||
174 | // dwgSolid.setExtrusion(extrusion);
|
||
175 | // return dwgSolid;
|
||
176 | // }
|
||
177 | 2896 | jmorell | /**
|
178 | * @return Returns the thickness.
|
||
179 | */
|
||
180 | public double getThickness() { |
||
181 | return thickness;
|
||
182 | } |
||
183 | /**
|
||
184 | * @param thickness The thickness to set.
|
||
185 | */
|
||
186 | public void setThickness(double thickness) { |
||
187 | this.thickness = thickness;
|
||
188 | } |
||
189 | /**
|
||
190 | * @param extrusion The extrusion to set.
|
||
191 | */
|
||
192 | public void setExtrusion(double[] extrusion) { |
||
193 | this.extrusion = extrusion;
|
||
194 | } |
||
195 | 9825 | azabala | /* (non-Javadoc)
|
196 | * @see com.iver.cit.jdwglib.dwg.IDwgExtrusionable#applyExtrussion()
|
||
197 | */
|
||
198 | public void applyExtrussion() { |
||
199 | double[] corner1 = getCorner1(); |
||
200 | double[] corner2 = getCorner2(); |
||
201 | double[] corner3 = getCorner3(); |
||
202 | double[] corner4 = getCorner4(); |
||
203 | double[] solidExt = getExtrusion(); |
||
204 | 10319 | azabala | corner1 = AcadExtrusionCalculator.extrude2(corner1, solidExt); |
205 | 10511 | azabala | corner2 = AcadExtrusionCalculator.extrude2(corner2, solidExt); |
206 | corner3 = AcadExtrusionCalculator.extrude2(corner3, solidExt); |
||
207 | corner4 = AcadExtrusionCalculator.extrude2(corner4, solidExt); |
||
208 | |||
209 | |||
210 | 9825 | azabala | setCorner1(corner1); |
211 | setCorner2(corner2); |
||
212 | setCorner3(corner3); |
||
213 | setCorner4(corner4); |
||
214 | } |
||
215 | /* (non-Javadoc)
|
||
216 | * @see com.iver.cit.jdwglib.dwg.IDwg3DTestable#has3DData()
|
||
217 | */
|
||
218 | public boolean has3DData() { |
||
219 | return (getElevation() != 0.0); |
||
220 | } |
||
221 | 9830 | azabala | public double getZ() { |
222 | return getElevation();
|
||
223 | } |
||
224 | public FShape toFMapGeometry(boolean is3DFile) { |
||
225 | FPolyline2D solid = null;
|
||
226 | double[] p1 = getCorner1(); |
||
227 | double[] p2 = getCorner2(); |
||
228 | double[] p3 = getCorner3(); |
||
229 | double[] p4 = getCorner4(); |
||
230 | double elev = getElevation();
|
||
231 | 10632 | azabala | List pts = new ArrayList(); |
232 | 9830 | azabala | |
233 | if (is3DFile) {
|
||
234 | 10632 | azabala | double[] p13d = new double[]{p1[0], p1[1], elev}; |
235 | double[] p23d = new double[]{p2[0], p2[1], elev}; |
||
236 | double[] p33d = new double[]{p3[0], p3[1], elev}; |
||
237 | double[] p43d = new double[]{p4[0], p4[1], elev}; |
||
238 | pts.add(p13d); |
||
239 | pts.add(p23d); |
||
240 | pts.add(p33d); |
||
241 | pts.add(p43d); |
||
242 | |||
243 | solid = FMapUtil.points3DToFPolyline3D(pts); |
||
244 | 9830 | azabala | |
245 | } else {
|
||
246 | 10632 | azabala | pts.add(p1); |
247 | pts.add(p2); |
||
248 | pts.add(p3); |
||
249 | pts.add(p4); |
||
250 | 9830 | azabala | solid = FMapUtil.points2DToFPolyline2D(pts); |
251 | } |
||
252 | return solid;
|
||
253 | |||
254 | } |
||
255 | public String toFMapString(boolean is3DFile) { |
||
256 | if(is3DFile){
|
||
257 | return "FPolyline3D"; |
||
258 | }else{
|
||
259 | return "FPolyline2D"; |
||
260 | } |
||
261 | } |
||
262 | |||
263 | public String toString(){ |
||
264 | return "Solid"; |
||
265 | } |
||
266 | 10240 | azabala | public void transform2Block(double[] bPoint, Point2D insPoint, double[] scale, double rot, |
267 | List dwgObjectsWithoutBlocks,
|
||
268 | Map handleObjWithoutBlocks,
|
||
269 | DwgFile callBack) { |
||
270 | 10064 | azabala | DwgSolid transformedEntity = null;
|
271 | 9977 | azabala | double[] corner1 = this.getCorner1(); |
272 | double[] corner2 = this.getCorner2(); |
||
273 | double[] corner3 = this.getCorner3(); |
||
274 | double[] corner4 = this.getCorner4(); |
||
275 | Point2D pointAux = new Point2D.Double(corner1[0] - bPoint[0], corner1[1] - bPoint[1]); |
||
276 | double laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(rot) + (pointAux.getY()*scale[1])*(-1)*Math.sin(rot)); |
||
277 | double laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(rot) + (pointAux.getY()*scale[1])*Math.cos(rot)); |
||
278 | 9843 | azabala | double[] transformedP1 = new double[]{laX, laY}; |
279 | 9977 | azabala | pointAux = new Point2D.Double(corner2[0] - bPoint[0], corner2[1] - bPoint[1]); |
280 | laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(rot) + (pointAux.getY()*scale[1])*(-1)*Math.sin(rot)); |
||
281 | laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(rot) + (pointAux.getY()*scale[1])*Math.cos(rot)); |
||
282 | 9843 | azabala | double[] transformedP2 = new double[]{laX, laY}; |
283 | 9977 | azabala | pointAux = new Point2D.Double(corner3[0] - bPoint[0], corner3[1] - bPoint[1]); |
284 | laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(rot) + (pointAux.getY()*scale[1])*(-1)*Math.sin(rot)); |
||
285 | laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(rot) + (pointAux.getY()*scale[1])*Math.cos(rot)); |
||
286 | 9843 | azabala | double[] transformedP3 = new double[]{laX, laY}; |
287 | 9977 | azabala | pointAux = new Point2D.Double(corner4[0] - bPoint[0], corner4[1] - bPoint[1]); |
288 | laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(rot) + (pointAux.getY()*scale[1])*(-1)*Math.sin(rot)); |
||
289 | laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(rot) + (pointAux.getY()*scale[1])*Math.cos(rot)); |
||
290 | 9843 | azabala | double[] transformedP4 = new double[]{laX, laY}; |
291 | 10064 | azabala | transformedEntity = (DwgSolid)this.clone();
|
292 | transformedEntity.setCorner1(transformedP1); |
||
293 | transformedEntity.setCorner2(transformedP2); |
||
294 | transformedEntity.setCorner3(transformedP3); |
||
295 | transformedEntity.setCorner4(transformedP4); |
||
296 | transformedEntity.setElevation(this.getElevation() * scale[2]); |
||
297 | dwgObjectsWithoutBlocks.add(transformedEntity); |
||
298 | 10240 | azabala | handleObjWithoutBlocks.put(new Integer(transformedEntity.getHandle().getOffset()), transformedEntity); |
299 | 9843 | azabala | } |
300 | 10174 | fdiaz | |
301 | public Object clone(){ |
||
302 | DwgSolid obj = new DwgSolid(index);
|
||
303 | this.fill(obj);
|
||
304 | return obj;
|
||
305 | } |
||
306 | |||
307 | protected void fill(DwgObject obj){ |
||
308 | super.fill(obj);
|
||
309 | DwgSolid myObj = (DwgSolid)obj; |
||
310 | |||
311 | myObj.setCorner1(corner1); |
||
312 | myObj.setCorner2(corner2); |
||
313 | myObj.setCorner3(corner3); |
||
314 | myObj.setCorner4(corner4); |
||
315 | myObj.setElevation(elevation); |
||
316 | myObj.setExtrusion(extrusion); |
||
317 | myObj.setThickness(thickness); |
||
318 | |||
319 | } |
||
320 | |||
321 | 2896 | jmorell | } |