svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libDwg / src / org / gvsig / dwg / lib / objects / DwgInsert.java @ 29001
History | View | Annotate | Download (8.76 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 java.awt.geom.Point2D; |
38 |
import java.util.ArrayList; |
39 |
import java.util.List; |
40 |
import java.util.Map; |
41 |
|
42 |
import org.gvsig.dwg.lib.DwgFile; |
43 |
import org.gvsig.dwg.lib.DwgHandleReference; |
44 |
import org.gvsig.dwg.lib.DwgObject; |
45 |
import org.gvsig.dwg.lib.IDwg3DTestable; |
46 |
import org.gvsig.dwg.lib.IDwgBlockMember; |
47 |
import org.gvsig.dwg.lib.IDwgExtrusionable; |
48 |
import org.gvsig.dwg.lib.util.AcadExtrusionCalculator; |
49 |
import org.gvsig.fmap.geom.Geometry; |
50 |
import org.gvsig.fmap.geom.GeometryLocator; |
51 |
import org.gvsig.fmap.geom.GeometryManager; |
52 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
53 |
import org.gvsig.fmap.geom.primitive.Point; |
54 |
|
55 |
|
56 |
/**
|
57 |
* The DwgInsert class represents a DWG Insert
|
58 |
*
|
59 |
* @author jmorell
|
60 |
*/
|
61 |
public class DwgInsert extends DwgObject |
62 |
implements IDwgExtrusionable, IDwg3DTestable,/* IDwg2FMap, */IDwgBlockMember { |
63 |
public DwgInsert(int index) { |
64 |
super(index);
|
65 |
} |
66 |
private double[] insertionPoint; |
67 |
private double[] scale; |
68 |
private double rotation; |
69 |
private double[] extrusion; |
70 |
private DwgHandleReference blockHeaderHandle = null; |
71 |
private DwgHandleReference firstAttribHandle = null; |
72 |
private DwgHandleReference lastAttribHandle = null; |
73 |
private DwgHandleReference seqendHandle = null; |
74 |
private ArrayList ownedObjectsHandles = new ArrayList(); //For R2004+ |
75 |
|
76 |
/**
|
77 |
* An insert could be nexted in other insert.
|
78 |
* We wont process and insert two times.
|
79 |
* */
|
80 |
private boolean processed = false; |
81 |
|
82 |
|
83 |
public void dump(){ |
84 |
System.out.println("<Insert>"); |
85 |
System.out.println("<inspoint x="+insertionPoint[0]+ |
86 |
" y="+insertionPoint[1]+ |
87 |
" z="+insertionPoint[2]+">"); |
88 |
System.out.println("<scale x="+scale[0]+ |
89 |
" y="+scale[1]+ |
90 |
" z="+scale[2]+">"); |
91 |
System.out.println("<rotation rot="+rotation+" >"); |
92 |
|
93 |
System.out.println("</Insert>"); |
94 |
|
95 |
} |
96 |
|
97 |
/**
|
98 |
* @return Returns the blockHeaderHandle.
|
99 |
*/
|
100 |
public DwgHandleReference getBlockHeaderHandle() {
|
101 |
return blockHeaderHandle;
|
102 |
} |
103 |
/**
|
104 |
* @param blockHeaderHandle The blockHeaderHandle to set.
|
105 |
*/
|
106 |
public void setBlockHeaderHandle(DwgHandleReference blockHeaderHandle) { |
107 |
this.blockHeaderHandle = blockHeaderHandle;
|
108 |
} |
109 |
/**
|
110 |
* @return Returns the firstAttribHandle.
|
111 |
*/
|
112 |
public DwgHandleReference getFirstAttribHandle() {
|
113 |
return firstAttribHandle;
|
114 |
} |
115 |
/**
|
116 |
* @param firstAttribHandle The firstAttribHandle to set.
|
117 |
*/
|
118 |
public void setFirstAttribHandle(DwgHandleReference firstAttribHandle) { |
119 |
this.firstAttribHandle = firstAttribHandle;
|
120 |
} |
121 |
/**
|
122 |
* @return Returns the insertionPoint.
|
123 |
*/
|
124 |
public double[] getInsertionPoint() { |
125 |
return insertionPoint;
|
126 |
} |
127 |
/**
|
128 |
* @param insertionPoint The insertionPoint to set.
|
129 |
*/
|
130 |
public void setInsertionPoint(double[] insertionPoint) { |
131 |
this.insertionPoint = insertionPoint;
|
132 |
} |
133 |
/**
|
134 |
* @return Returns the lastAttribHandle.
|
135 |
*/
|
136 |
public DwgHandleReference getLastAttribHandle() {
|
137 |
return lastAttribHandle;
|
138 |
} |
139 |
/**
|
140 |
* @param lastAttribHandle The lastAttribHandle to set.
|
141 |
*/
|
142 |
public void setLastAttribHandle(DwgHandleReference lastAttribHandle) { |
143 |
this.lastAttribHandle = lastAttribHandle;
|
144 |
} |
145 |
/**
|
146 |
* @return Returns the rotation.
|
147 |
*/
|
148 |
public double getRotation() { |
149 |
return rotation;
|
150 |
} |
151 |
/**
|
152 |
* @param rotation The rotation to set.
|
153 |
*/
|
154 |
public void setRotation(double rotation) { |
155 |
this.rotation = rotation;
|
156 |
} |
157 |
/**
|
158 |
* @return Returns the scale.
|
159 |
*/
|
160 |
public double[] getScale() { |
161 |
return scale;
|
162 |
} |
163 |
/**
|
164 |
* @param scale The scale to set.
|
165 |
*/
|
166 |
public void setScale(double[] scale) { |
167 |
this.scale = scale;
|
168 |
} |
169 |
/**
|
170 |
* @return Returns the extrusion.
|
171 |
*/
|
172 |
public double[] getExtrusion() { |
173 |
return extrusion;
|
174 |
} |
175 |
/**
|
176 |
* @param extrusion The extrusion to set.
|
177 |
*/
|
178 |
public void setExtrusion(double[] extrusion) { |
179 |
this.extrusion = extrusion;
|
180 |
} |
181 |
/**
|
182 |
* @return Returns the seqendHandle.
|
183 |
*/
|
184 |
public DwgHandleReference getSeqendHandle() {
|
185 |
return seqendHandle;
|
186 |
} |
187 |
/**
|
188 |
* @param seqendHandle The seqendHandle to set.
|
189 |
*/
|
190 |
public void setSeqendHandle(DwgHandleReference seqendHandle) { |
191 |
this.seqendHandle = seqendHandle;
|
192 |
} |
193 |
|
194 |
/**
|
195 |
* @return Returns the owned objects handles.
|
196 |
*/
|
197 |
public ArrayList getOwnedObjectsHandles() { |
198 |
return ownedObjectsHandles;
|
199 |
} |
200 |
/**
|
201 |
* @param objects The owned objects handles to set.
|
202 |
*/
|
203 |
public void setOwnedObjectsHandles(ArrayList handles) { |
204 |
this.ownedObjectsHandles = handles;
|
205 |
} |
206 |
/**
|
207 |
* Add a handle to the ownedBbjectsHandle vector
|
208 |
*
|
209 |
* @param handle handle
|
210 |
*/
|
211 |
public void addOwnedObjectHandle(DwgHandleReference handle) { |
212 |
this.ownedObjectsHandles.add(handle);
|
213 |
} |
214 |
|
215 |
|
216 |
/* (non-Javadoc)
|
217 |
* @see com.iver.cit.jdwglib.dwg.IDwgExtrusionable#applyExtrussion()
|
218 |
*/
|
219 |
public void applyExtrussion() { |
220 |
double[] insertPoint = getInsertionPoint(); |
221 |
double[] insertExt = getExtrusion(); |
222 |
insertPoint = AcadExtrusionCalculator.extrude2(insertPoint, insertExt); |
223 |
setInsertionPoint(insertPoint); |
224 |
} |
225 |
/* (non-Javadoc)
|
226 |
* @see com.iver.cit.jdwglib.dwg.IDwg3DTestable#has3DData()
|
227 |
*/
|
228 |
public boolean has3DData() { |
229 |
return (getInsertionPoint()[2] != 0.0); |
230 |
} |
231 |
public double getZ() { |
232 |
return getInsertionPoint()[2]; |
233 |
} |
234 |
public Geometry toFMapGeometry(boolean is3DFile) |
235 |
throws CreateGeometryException {
|
236 |
GeometryManager gMan = GeometryLocator.getGeometryManager(); |
237 |
double[] p = getInsertionPoint(); |
238 |
Point point = (Point) gMan.create(getGeometryType(), |
239 |
getGeometrySubType(is3DFile)); |
240 |
point.setCoordinates(p); |
241 |
return point;
|
242 |
|
243 |
} |
244 |
public String toFMapString(boolean is3DFile) { |
245 |
if(is3DFile) {
|
246 |
return "FPoint3D"; |
247 |
} else {
|
248 |
return "FPoint2D"; |
249 |
} |
250 |
} |
251 |
|
252 |
public String toString(){ |
253 |
return "Insert"; |
254 |
} |
255 |
public void transform2Block(double[] bPoint, Point2D insPoint, |
256 |
double[] scale, double rot, |
257 |
List dwgObjectsWithoutBlocks, Map handle_objWithoutBlocks, DwgFile callBack) { |
258 |
|
259 |
processed = true;
|
260 |
|
261 |
double[] p = this.getInsertionPoint(); |
262 |
Point2D point = new Point2D.Double(p[0], p[1]); |
263 |
|
264 |
double[] newScale = this.getScale(); |
265 |
double newRot = this.getRotation(); |
266 |
DwgHandleReference newBlockHandle = this.getBlockHeaderHandle();
|
267 |
|
268 |
Point2D pointAux = new Point2D.Double(point.getX() - bPoint[0], point.getY() - bPoint[1]); |
269 |
double laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(rot) + (pointAux.getY()*scale[1])*(-1)*Math.sin(rot)); |
270 |
double laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(rot) + (pointAux.getY()*scale[1])*Math.cos(rot)); |
271 |
double laZ = p[2] * scale[2]; |
272 |
|
273 |
Point2D newInsPoint = new Point2D.Double(laX, laY); |
274 |
newScale = new double[]{scale[0]*newScale[0], scale[1]*newScale[1], scale[2]*newScale[2]}; |
275 |
newRot = newRot + rot; |
276 |
if (newRot<0) { |
277 |
newRot = newRot + (2*Math.PI); |
278 |
} else if (newRot>(2*Math.PI)) { |
279 |
newRot = newRot - (2*Math.PI); |
280 |
} |
281 |
|
282 |
callBack.manageInsert2(newInsPoint, |
283 |
newScale, |
284 |
newRot, |
285 |
newBlockHandle.getOffset(), |
286 |
dwgObjectsWithoutBlocks, |
287 |
handle_objWithoutBlocks); |
288 |
} |
289 |
|
290 |
/* (non-Javadoc)
|
291 |
* @see java.lang.Object#clone()
|
292 |
*/
|
293 |
public Object clone(){ |
294 |
DwgInsert obj = new DwgInsert(index);
|
295 |
this.fill(obj);
|
296 |
return obj;
|
297 |
} |
298 |
|
299 |
protected void fill(DwgObject obj){ |
300 |
super.fill(obj);
|
301 |
DwgInsert myObj = (DwgInsert)obj; |
302 |
|
303 |
myObj.setBlockHeaderHandle(blockHeaderHandle); |
304 |
myObj.setExtrusion(extrusion); |
305 |
myObj.setFirstAttribHandle(firstAttribHandle); |
306 |
myObj.setInsertionPoint(insertionPoint); |
307 |
myObj.setLastAttribHandle(lastAttribHandle); |
308 |
myObj.setRotation(rotation); |
309 |
myObj.setScale(scale); |
310 |
myObj.setSeqendHandle(seqendHandle); |
311 |
} |
312 |
public boolean isProcessed() { |
313 |
return processed;
|
314 |
} |
315 |
public void setProcessed(boolean processed) { |
316 |
this.processed = processed;
|
317 |
} |
318 |
|
319 |
public int getGeometrySubType(boolean is3DFile) { |
320 |
if (is3DFile) {
|
321 |
return Geometry.SUBTYPES.GEOM3D;
|
322 |
} else {
|
323 |
return Geometry.SUBTYPES.GEOM2D;
|
324 |
} |
325 |
} |
326 |
|
327 |
public int getGeometryType() { |
328 |
return Geometry.TYPES.POINT;
|
329 |
} |
330 |
} |