root / trunk / libraries / libDwg / src / com / iver / cit / jdwglib / dwg / objects / DwgInsert.java @ 10302
History | View | Annotate | Download (7.87 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.List; |
39 |
import java.util.Map; |
40 |
|
41 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
42 |
import com.iver.cit.gvsig.fmap.core.FPoint3D; |
43 |
import com.iver.cit.gvsig.fmap.core.FShape; |
44 |
import com.iver.cit.jdwglib.dwg.DwgFile; |
45 |
import com.iver.cit.jdwglib.dwg.DwgHandleReference; |
46 |
import com.iver.cit.jdwglib.dwg.DwgObject; |
47 |
import com.iver.cit.jdwglib.dwg.IDwg2FMap; |
48 |
import com.iver.cit.jdwglib.dwg.IDwg3DTestable; |
49 |
import com.iver.cit.jdwglib.dwg.IDwgBlockMember; |
50 |
import com.iver.cit.jdwglib.dwg.IDwgExtrusionable; |
51 |
import com.iver.cit.jdwglib.util.AcadExtrusionCalculator; |
52 |
|
53 |
/**
|
54 |
* The DwgInsert class represents a DWG Insert
|
55 |
*
|
56 |
* @author jmorell
|
57 |
*/
|
58 |
public class DwgInsert extends DwgObject |
59 |
implements IDwgExtrusionable, IDwg3DTestable, IDwg2FMap, IDwgBlockMember {
|
60 |
public DwgInsert(int index) { |
61 |
super(index);
|
62 |
} |
63 |
private double[] insertionPoint; |
64 |
private double[] scale; |
65 |
private double rotation; |
66 |
private double[] extrusion; |
67 |
private DwgHandleReference blockHeaderHandle = null; |
68 |
private DwgHandleReference firstAttribHandle = null; |
69 |
private DwgHandleReference lastAttribHandle = null; |
70 |
private DwgHandleReference seqendHandle = null; |
71 |
|
72 |
/**
|
73 |
* An insert could be nexted in other insert.
|
74 |
* We wont process and insert two times.
|
75 |
* */
|
76 |
private boolean processed = false; |
77 |
|
78 |
|
79 |
/**
|
80 |
* @return Returns the blockHeaderHandle.
|
81 |
*/
|
82 |
public DwgHandleReference getBlockHeaderHandle() {
|
83 |
return blockHeaderHandle;
|
84 |
} |
85 |
/**
|
86 |
* @param blockHeaderHandle The blockHeaderHandle to set.
|
87 |
*/
|
88 |
public void setBlockHeaderHandle(DwgHandleReference blockHeaderHandle) { |
89 |
this.blockHeaderHandle = blockHeaderHandle;
|
90 |
} |
91 |
/**
|
92 |
* @return Returns the firstAttribHandle.
|
93 |
*/
|
94 |
public DwgHandleReference getFirstAttribHandle() {
|
95 |
return firstAttribHandle;
|
96 |
} |
97 |
/**
|
98 |
* @param firstAttribHandle The firstAttribHandle to set.
|
99 |
*/
|
100 |
public void setFirstAttribHandle(DwgHandleReference firstAttribHandle) { |
101 |
this.firstAttribHandle = firstAttribHandle;
|
102 |
} |
103 |
/**
|
104 |
* @return Returns the insertionPoint.
|
105 |
*/
|
106 |
public double[] getInsertionPoint() { |
107 |
return insertionPoint;
|
108 |
} |
109 |
/**
|
110 |
* @param insertionPoint The insertionPoint to set.
|
111 |
*/
|
112 |
public void setInsertionPoint(double[] insertionPoint) { |
113 |
this.insertionPoint = insertionPoint;
|
114 |
} |
115 |
/**
|
116 |
* @return Returns the lastAttribHandle.
|
117 |
*/
|
118 |
public DwgHandleReference getLastAttribHandle() {
|
119 |
return lastAttribHandle;
|
120 |
} |
121 |
/**
|
122 |
* @param lastAttribHandle The lastAttribHandle to set.
|
123 |
*/
|
124 |
public void setLastAttribHandle(DwgHandleReference lastAttribHandle) { |
125 |
this.lastAttribHandle = lastAttribHandle;
|
126 |
} |
127 |
/**
|
128 |
* @return Returns the rotation.
|
129 |
*/
|
130 |
public double getRotation() { |
131 |
return rotation;
|
132 |
} |
133 |
/**
|
134 |
* @param rotation The rotation to set.
|
135 |
*/
|
136 |
public void setRotation(double rotation) { |
137 |
this.rotation = rotation;
|
138 |
} |
139 |
/**
|
140 |
* @return Returns the scale.
|
141 |
*/
|
142 |
public double[] getScale() { |
143 |
return scale;
|
144 |
} |
145 |
/**
|
146 |
* @param scale The scale to set.
|
147 |
*/
|
148 |
public void setScale(double[] scale) { |
149 |
this.scale = scale;
|
150 |
} |
151 |
/**
|
152 |
* @return Returns the extrusion.
|
153 |
*/
|
154 |
public double[] getExtrusion() { |
155 |
return extrusion;
|
156 |
} |
157 |
/**
|
158 |
* @param extrusion The extrusion to set.
|
159 |
*/
|
160 |
public void setExtrusion(double[] extrusion) { |
161 |
this.extrusion = extrusion;
|
162 |
} |
163 |
/**
|
164 |
* @return Returns the seqendHandle.
|
165 |
*/
|
166 |
public DwgHandleReference getSeqendHandle() {
|
167 |
return seqendHandle;
|
168 |
} |
169 |
/**
|
170 |
* @param seqendHandle The seqendHandle to set.
|
171 |
*/
|
172 |
public void setSeqendHandle(DwgHandleReference seqendHandle) { |
173 |
this.seqendHandle = seqendHandle;
|
174 |
} |
175 |
|
176 |
/* (non-Javadoc)
|
177 |
* @see com.iver.cit.jdwglib.dwg.IDwgExtrusionable#applyExtrussion()
|
178 |
*/
|
179 |
public void applyExtrussion() { |
180 |
double[] insertPoint = getInsertionPoint(); |
181 |
double[] insertExt = getExtrusion(); |
182 |
insertPoint = AcadExtrusionCalculator.CalculateAcadExtrusion(insertPoint, insertExt); |
183 |
setInsertionPoint(insertPoint); |
184 |
} |
185 |
/* (non-Javadoc)
|
186 |
* @see com.iver.cit.jdwglib.dwg.IDwg3DTestable#has3DData()
|
187 |
*/
|
188 |
public boolean has3DData() { |
189 |
return (getInsertionPoint()[2] != 0.0); |
190 |
} |
191 |
public double getZ() { |
192 |
return getInsertionPoint()[2]; |
193 |
} |
194 |
public FShape toFMapGeometry(boolean is3DFile) { |
195 |
double[] p = getInsertionPoint(); |
196 |
// Point2D point = new Point2D.Double(p[0], p[1]);
|
197 |
FPoint2D fPoint; |
198 |
/*
|
199 |
* double[] scale = ((DwgInsert)entity).getScale(); double rot =
|
200 |
* ((DwgInsert)entity).getRotation(); int blockHandle =
|
201 |
* ((DwgInsert)entity).getBlockHeaderHandle();
|
202 |
*/
|
203 |
// manageInsert(dwgObjects, point, scale, rot, blockHandle, i,
|
204 |
// auxRow);
|
205 |
if (is3DFile) {
|
206 |
fPoint = new FPoint3D(p[0], p[1], p[2]); |
207 |
} else {
|
208 |
fPoint = new FPoint2D(p[0], p[1]); |
209 |
} |
210 |
return fPoint;
|
211 |
} |
212 |
public String toFMapString(boolean is3DFile) { |
213 |
if(is3DFile)
|
214 |
return "FPoint3D"; |
215 |
else
|
216 |
return "FPoint2D"; |
217 |
} |
218 |
|
219 |
public String toString(){ |
220 |
return "Insert"; |
221 |
} |
222 |
public void transform2Block(double[] bPoint, Point2D insPoint, |
223 |
double[] scale, double rot, |
224 |
List dwgObjectsWithoutBlocks, Map handle_objWithoutBlocks, DwgFile callBack) { |
225 |
|
226 |
processed = true;
|
227 |
|
228 |
double[] p = this.getInsertionPoint(); |
229 |
Point2D point = new Point2D.Double(p[0], p[1]); |
230 |
|
231 |
double[] newScale = this.getScale(); |
232 |
double newRot = this.getRotation(); |
233 |
DwgHandleReference newBlockHandle = this.getBlockHeaderHandle();
|
234 |
|
235 |
Point2D pointAux = new Point2D.Double(point.getX() - bPoint[0], point.getY() - bPoint[1]); |
236 |
double laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(rot) + (pointAux.getY()*scale[1])*(-1)*Math.sin(rot)); |
237 |
double laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(rot) + (pointAux.getY()*scale[1])*Math.cos(rot)); |
238 |
double laZ = p[2] * scale[2]; |
239 |
|
240 |
Point2D newInsPoint = new Point2D.Double(laX, laY); |
241 |
newScale = new double[]{scale[0]*newScale[0], scale[1]*newScale[1], scale[2]*newScale[2]}; |
242 |
newRot = newRot + rot; |
243 |
if (newRot<0) { |
244 |
newRot = newRot + (2*Math.PI); |
245 |
} else if (newRot>(2*Math.PI)) { |
246 |
newRot = newRot - (2*Math.PI); |
247 |
} |
248 |
|
249 |
callBack.manageInsert(newInsPoint, |
250 |
newScale, |
251 |
newRot, |
252 |
newBlockHandle.getOffset(), |
253 |
dwgObjectsWithoutBlocks, |
254 |
handle_objWithoutBlocks); |
255 |
} |
256 |
|
257 |
/* (non-Javadoc)
|
258 |
* @see java.lang.Object#clone()
|
259 |
*/
|
260 |
public Object clone(){ |
261 |
DwgInsert obj = new DwgInsert(index);
|
262 |
this.fill(obj);
|
263 |
return obj;
|
264 |
} |
265 |
|
266 |
protected void fill(DwgObject obj){ |
267 |
super.fill(obj);
|
268 |
DwgInsert myObj = (DwgInsert)obj; |
269 |
|
270 |
myObj.setBlockHeaderHandle(blockHeaderHandle); |
271 |
myObj.setExtrusion(extrusion); |
272 |
myObj.setFirstAttribHandle(firstAttribHandle); |
273 |
myObj.setInsertionPoint(insertionPoint); |
274 |
myObj.setLastAttribHandle(lastAttribHandle); |
275 |
myObj.setRotation(rotation); |
276 |
myObj.setScale(scale); |
277 |
myObj.setSeqendHandle(seqendHandle); |
278 |
} |
279 |
public boolean isProcessed() { |
280 |
return processed;
|
281 |
} |
282 |
public void setProcessed(boolean processed) { |
283 |
this.processed = processed;
|
284 |
} |
285 |
|
286 |
} |