root / trunk / libraries / libDwg / src / com / iver / cit / jdwglib / dwg / objects / DwgLine.java @ 10319
History | View | Annotate | Download (8.18 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.FPolyline2D; |
42 |
import com.iver.cit.gvsig.fmap.core.FShape; |
43 |
import com.iver.cit.jdwglib.dwg.DwgFile; |
44 |
import com.iver.cit.jdwglib.dwg.DwgObject; |
45 |
import com.iver.cit.jdwglib.dwg.IDwg2FMap; |
46 |
import com.iver.cit.jdwglib.dwg.IDwg3DTestable; |
47 |
import com.iver.cit.jdwglib.dwg.IDwgBlockMember; |
48 |
import com.iver.cit.jdwglib.dwg.IDwgExtrusionable; |
49 |
import com.iver.cit.jdwglib.util.AcadExtrusionCalculator; |
50 |
import com.iver.cit.jdwglib.util.FMapUtil; |
51 |
|
52 |
/**
|
53 |
* The DwgLine class represents a DWG Line
|
54 |
*
|
55 |
* @author jmorell, azabala
|
56 |
*/
|
57 |
public class DwgLine extends DwgObject |
58 |
implements IDwgExtrusionable, IDwg3DTestable, IDwg2FMap, IDwgBlockMember{
|
59 |
public DwgLine(int index) { |
60 |
super(index);
|
61 |
// TODO Auto-generated constructor stub
|
62 |
} |
63 |
private double[] p1; |
64 |
private double[] p2; |
65 |
private double thickness; |
66 |
private double[] extrusion; |
67 |
private boolean zflag = false; |
68 |
|
69 |
/**
|
70 |
* @return Returns the p1.
|
71 |
*/
|
72 |
public double[] getP1() { |
73 |
return p1;
|
74 |
} |
75 |
/**
|
76 |
* @param p1 The p1 to set.
|
77 |
*/
|
78 |
public void setP1(double[] p1) { |
79 |
this.p1 = p1;
|
80 |
} |
81 |
/**
|
82 |
* @return Returns the p2.
|
83 |
*/
|
84 |
public double[] getP2() { |
85 |
return p2;
|
86 |
} |
87 |
/**
|
88 |
* @param p2 The p2 to set.
|
89 |
*/
|
90 |
public void setP2(double[] p2) { |
91 |
this.p2 = p2;
|
92 |
} |
93 |
/**
|
94 |
* @return Returns the extrusion.
|
95 |
*/
|
96 |
public double[] getExtrusion() { |
97 |
return extrusion;
|
98 |
} |
99 |
/**
|
100 |
* @param extrusion The extrusion to set.
|
101 |
*/
|
102 |
public void setExtrusion(double[] extrusion) { |
103 |
this.extrusion = extrusion;
|
104 |
} |
105 |
/**
|
106 |
* @return Returns the thickness.
|
107 |
*/
|
108 |
public double getThickness() { |
109 |
return thickness;
|
110 |
} |
111 |
/**
|
112 |
* @param thickness The thickness to set.
|
113 |
*/
|
114 |
public void setThickness(double thickness) { |
115 |
this.thickness = thickness;
|
116 |
} |
117 |
/* (non-Javadoc)
|
118 |
* @see java.lang.Object#clone()
|
119 |
*/
|
120 |
// public Object clone() {
|
121 |
// DwgLine dwgLine = new DwgLine(index);
|
122 |
// dwgLine.setType(type);
|
123 |
// dwgLine.setHandle(handle);
|
124 |
// dwgLine.setVersion(version);
|
125 |
// dwgLine.setMode(mode);
|
126 |
// dwgLine.setLayerHandle(layerHandle);
|
127 |
// dwgLine.setColor(color);
|
128 |
// dwgLine.setNumReactors(numReactors);
|
129 |
// dwgLine.setNoLinks(noLinks);
|
130 |
// dwgLine.setLinetypeFlags(linetypeFlags);
|
131 |
// dwgLine.setPlotstyleFlags(plotstyleFlags);
|
132 |
// dwgLine.setSizeInBits(sizeInBits);
|
133 |
// dwgLine.setExtendedData(extendedData);
|
134 |
// dwgLine.setGraphicData(graphicData);
|
135 |
// //dwgLine.setInsideBlock(insideBlock);
|
136 |
// dwgLine.setP1(p1);
|
137 |
// dwgLine.setP2(p2);
|
138 |
// dwgLine.setThickness(thickness);
|
139 |
// dwgLine.setExtrusion(extrusion);
|
140 |
// dwgLine.setSubEntityHandle(subEntityHandle);
|
141 |
// return dwgLine;
|
142 |
// }
|
143 |
/**
|
144 |
* @return Returns the zflag.
|
145 |
*/
|
146 |
public boolean isZflag() { |
147 |
return zflag;
|
148 |
} |
149 |
/**
|
150 |
* @param zflag The zflag to set.
|
151 |
*/
|
152 |
public void setZflag(boolean zflag) { |
153 |
this.zflag = zflag;
|
154 |
} |
155 |
/* (non-Javadoc)
|
156 |
* @see com.iver.cit.jdwglib.dwg.IDwgExtrusionable#applyExtrussion()
|
157 |
*/
|
158 |
public void applyExtrussion() { |
159 |
double[] lineP1 = getP1(); |
160 |
double[] lineP2 = getP2(); |
161 |
boolean zflag = isZflag();
|
162 |
if (zflag) {
|
163 |
// elev = 0.0;
|
164 |
lineP1 = new double[]{lineP1[0], lineP1[1], 0.0}; |
165 |
lineP2 = new double[]{lineP2[0], lineP2[1], 0.0}; |
166 |
} |
167 |
double[] lineExt = getExtrusion(); |
168 |
lineP1 = AcadExtrusionCalculator.extrude2(lineP1, lineExt); |
169 |
lineP2 = AcadExtrusionCalculator.extrude2(lineP2, lineExt); |
170 |
setP1(lineP1); |
171 |
setP2(lineP2); |
172 |
} |
173 |
/* (non-Javadoc)
|
174 |
* @see com.iver.cit.jdwglib.dwg.IDwg3DTestable#has3DData()
|
175 |
*/
|
176 |
public boolean has3DData() { |
177 |
if (!isZflag()) {
|
178 |
double z1 = getP1()[2]; |
179 |
double z2 = getP2()[2]; |
180 |
if (z1!=0.0 || z2!=0.0) |
181 |
return true; |
182 |
}//TODO y si zflag vale true? REVISAR
|
183 |
return false; |
184 |
} |
185 |
public double getZ() { |
186 |
double[] p1 = getP1(); |
187 |
double[] p2 = getP2(); |
188 |
if(isZflag()){
|
189 |
if (p1[2] == p2[2]) |
190 |
return p1[2]; |
191 |
else
|
192 |
return 0d; |
193 |
} else {
|
194 |
return 0d; |
195 |
} |
196 |
} |
197 |
public FShape toFMapGeometry(boolean is3DFile) { |
198 |
FPolyline2D line = null;
|
199 |
double[] p1 = getP1(); |
200 |
Point2D point1 = new Point2D.Double(p1[0], p1[1]); |
201 |
double[] p2 = getP2(); |
202 |
Point2D point2 = new Point2D.Double(p2[0], p2[1]); |
203 |
Point2D[] lin = new Point2D[] { point1, point2 }; |
204 |
if (is3DFile && isZflag()) {
|
205 |
double[][] lin3D = new double[2][3]; |
206 |
lin3D[0][0] = lin[0].getX(); |
207 |
lin3D[0][1] = lin[0].getY(); |
208 |
lin3D[0][2] = p1[2]; |
209 |
lin3D[1][0] = lin[1].getX(); |
210 |
lin3D[1][1] = lin[1].getY(); |
211 |
lin3D[1][2] = p2[2]; |
212 |
line = FMapUtil.points3DToFPolyline3D(lin3D); |
213 |
} else if (is3DFile && ! isZflag()) { |
214 |
double[][] lin3D = new double[2][3]; |
215 |
lin3D[0][0] = lin[0].getX(); |
216 |
lin3D[0][1] = lin[0].getY(); |
217 |
lin3D[0][2] = 0.0; |
218 |
lin3D[1][0] = lin[1].getX(); |
219 |
lin3D[1][1] = lin[1].getY(); |
220 |
lin3D[1][2] = 0.0; |
221 |
line = FMapUtil.points3DToFPolyline3D(lin3D); |
222 |
} else {
|
223 |
line = FMapUtil.points2DToFPolyline2D(lin); |
224 |
} |
225 |
return line;
|
226 |
|
227 |
} |
228 |
public String toFMapString(boolean is3DFile) { |
229 |
if(is3DFile){
|
230 |
return "FPolyline3D"; |
231 |
}else{
|
232 |
return "FPolyline2D"; |
233 |
} |
234 |
} |
235 |
|
236 |
public String toString(){ |
237 |
return "Line"; |
238 |
} |
239 |
public void transform2Block(double[] bPoint, Point2D insPoint, |
240 |
double[] scale, double rot, |
241 |
List dwgObjectsWithoutBlocks,
|
242 |
Map handleObjWithoutBlocks,
|
243 |
DwgFile callBack) { |
244 |
DwgLine transformedEntity = null;
|
245 |
double[] p1 = this.getP1(); |
246 |
double[] p2 = this.getP2(); |
247 |
Point2D pointAux = new Point2D.Double(p1[0] - bPoint[0], p1[1] - bPoint[1]); |
248 |
double laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(rot) + (pointAux.getY()*scale[1])*(-1)*Math.sin(rot)); |
249 |
double laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(rot) + (pointAux.getY()*scale[1])*Math.cos(rot)); |
250 |
double[] transformedP1 = null; |
251 |
if (this.isZflag()) { |
252 |
double laZ = p1[2] * scale[2]; |
253 |
transformedP1 = new double[]{laX, laY, laZ}; |
254 |
} else {
|
255 |
transformedP1 = new double[]{laX, laY}; |
256 |
} |
257 |
//double[] transformedP1 = new double[]{laX, laY};
|
258 |
pointAux = new Point2D.Double(p2[0] - bPoint[0], p2[1] - bPoint[1]); |
259 |
laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(rot) + (pointAux.getY()*scale[1])*(-1)*Math.sin(rot)); |
260 |
laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(rot) + (pointAux.getY()*scale[1])*Math.cos(rot)); |
261 |
double[] transformedP2 = null; |
262 |
if (this.isZflag()) { |
263 |
double laZ = p2[2] * scale[2]; |
264 |
transformedP2 = new double[]{laX, laY, laZ}; |
265 |
} else {
|
266 |
transformedP2 = new double[]{laX, laY}; |
267 |
} |
268 |
//double[] transformedP2 = new double[]{laX, laY};
|
269 |
transformedEntity = (DwgLine)this.clone();
|
270 |
transformedEntity.setP1(transformedP1); |
271 |
transformedEntity.setP2(transformedP2); |
272 |
dwgObjectsWithoutBlocks.add(transformedEntity); |
273 |
handleObjWithoutBlocks.put(new Integer(transformedEntity.getHandle().getOffset()), transformedEntity); |
274 |
// dwgObjectsWithoutBlocks.add(this);
|
275 |
} |
276 |
public Object clone(){ |
277 |
DwgLine dwgLine = new DwgLine(index);
|
278 |
this.fill(dwgLine);
|
279 |
return dwgLine;
|
280 |
} |
281 |
|
282 |
protected void fill(DwgObject obj){ |
283 |
super.fill(obj);
|
284 |
DwgLine myObj = (DwgLine)obj; |
285 |
|
286 |
myObj.setExtrusion(extrusion); |
287 |
myObj.setP1(p1); |
288 |
myObj.setP2(p2); |
289 |
myObj.setThickness(thickness); |
290 |
|
291 |
} |
292 |
|
293 |
} |