svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libDwg / src / org / gvsig / dwg / lib / objects / DwgSpline.java @ 29001
History | View | Annotate | Download (7.81 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 org.gvsig.dwg.lib.DwgObject; |
38 |
import org.gvsig.dwg.lib.IDwg2FMap; |
39 |
import org.gvsig.dwg.lib.IDwg3DTestable; |
40 |
import org.gvsig.fmap.geom.Geometry; |
41 |
import org.gvsig.fmap.geom.GeometryLocator; |
42 |
import org.gvsig.fmap.geom.GeometryManager; |
43 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
44 |
import org.gvsig.fmap.geom.primitive.Point; |
45 |
import org.gvsig.fmap.geom.primitive.Spline; |
46 |
|
47 |
|
48 |
/**
|
49 |
* The DwgSpline class represents a DWG Spline
|
50 |
*
|
51 |
* @author jmorell
|
52 |
*/
|
53 |
public class DwgSpline extends DwgObject |
54 |
implements IDwg3DTestable, IDwg2FMap {
|
55 |
|
56 |
public DwgSpline(int index) { |
57 |
super(index);
|
58 |
} |
59 |
private int scenario; |
60 |
private int degree; |
61 |
private double fitTolerance; |
62 |
private double[] beginTanVector; |
63 |
private double[] endTanVector; |
64 |
private boolean rational; |
65 |
private boolean closed; |
66 |
private boolean periodic; |
67 |
private double knotTolerance; |
68 |
private double controlTolerance; |
69 |
private double[] knotPoints; |
70 |
private double[][] controlPoints; |
71 |
private double[] weights; |
72 |
private double[][] fitPoints; |
73 |
|
74 |
/**
|
75 |
* @return Returns the closed.
|
76 |
*/
|
77 |
public boolean isClosed() { |
78 |
return closed;
|
79 |
} |
80 |
/**
|
81 |
* @param closed The closed to set.
|
82 |
*/
|
83 |
public void setClosed(boolean closed) { |
84 |
this.closed = closed;
|
85 |
} |
86 |
/**
|
87 |
* @return Returns the controlPoints.
|
88 |
*/
|
89 |
public double[][] getControlPoints() { |
90 |
return controlPoints;
|
91 |
} |
92 |
/**
|
93 |
* @param controlPoints The controlPoints to set.
|
94 |
*/
|
95 |
public void setControlPoints(double[][] controlPoints) { |
96 |
this.controlPoints = controlPoints;
|
97 |
} |
98 |
/**
|
99 |
* @return Returns the fitPoints.
|
100 |
*/
|
101 |
public double[][] getFitPoints() { |
102 |
return fitPoints;
|
103 |
} |
104 |
/**
|
105 |
* @param fitPoints The fitPoints to set.
|
106 |
*/
|
107 |
public void setFitPoints(double[][] fitPoints) { |
108 |
this.fitPoints = fitPoints;
|
109 |
} |
110 |
/**
|
111 |
* @return Returns the knotPoints.
|
112 |
*/
|
113 |
public double[] getKnotPoints() { |
114 |
return knotPoints;
|
115 |
} |
116 |
/**
|
117 |
* @param knotPoints The knotPoints to set.
|
118 |
*/
|
119 |
public void setKnotPoints(double[] knotPoints) { |
120 |
this.knotPoints = knotPoints;
|
121 |
} |
122 |
/**
|
123 |
* @return Returns the scenario.
|
124 |
*/
|
125 |
public int getScenario() { |
126 |
return scenario;
|
127 |
} |
128 |
/**
|
129 |
* @param scenario The scenario to set.
|
130 |
*/
|
131 |
public void setScenario(int scenario) { |
132 |
this.scenario = scenario;
|
133 |
} |
134 |
|
135 |
/**
|
136 |
* @return Returns the beginTanVector.
|
137 |
*/
|
138 |
public double[] getBeginTanVector() { |
139 |
return beginTanVector;
|
140 |
} |
141 |
/**
|
142 |
* @param beginTanVector The beginTanVector to set.
|
143 |
*/
|
144 |
public void setBeginTanVector(double[] beginTanVector) { |
145 |
this.beginTanVector = beginTanVector;
|
146 |
} |
147 |
/**
|
148 |
* @return Returns the controlTolerance.
|
149 |
*/
|
150 |
public double getControlTolerance() { |
151 |
return controlTolerance;
|
152 |
} |
153 |
/**
|
154 |
* @param controlTolerance The controlTolerance to set.
|
155 |
*/
|
156 |
public void setControlTolerance(double controlTolerance) { |
157 |
this.controlTolerance = controlTolerance;
|
158 |
} |
159 |
/**
|
160 |
* @return Returns the degree.
|
161 |
*/
|
162 |
public int getDegree() { |
163 |
return degree;
|
164 |
} |
165 |
/**
|
166 |
* @param degree The degree to set.
|
167 |
*/
|
168 |
public void setDegree(int degree) { |
169 |
this.degree = degree;
|
170 |
} |
171 |
/**
|
172 |
* @return Returns the endTanVector.
|
173 |
*/
|
174 |
public double[] getEndTanVector() { |
175 |
return endTanVector;
|
176 |
} |
177 |
/**
|
178 |
* @param endTanVector The endTanVector to set.
|
179 |
*/
|
180 |
public void setEndTanVector(double[] endTanVector) { |
181 |
this.endTanVector = endTanVector;
|
182 |
} |
183 |
/**
|
184 |
* @return Returns the fitTolerance.
|
185 |
*/
|
186 |
public double getFitTolerance() { |
187 |
return fitTolerance;
|
188 |
} |
189 |
/**
|
190 |
* @param fitTolerance The fitTolerance to set.
|
191 |
*/
|
192 |
public void setFitTolerance(double fitTolerance) { |
193 |
this.fitTolerance = fitTolerance;
|
194 |
} |
195 |
/**
|
196 |
* @return Returns the knotTolerance.
|
197 |
*/
|
198 |
public double getKnotTolerance() { |
199 |
return knotTolerance;
|
200 |
} |
201 |
/**
|
202 |
* @param knotTolerance The knotTolerance to set.
|
203 |
*/
|
204 |
public void setKnotTolerance(double knotTolerance) { |
205 |
this.knotTolerance = knotTolerance;
|
206 |
} |
207 |
/**
|
208 |
* @return Returns the periodic.
|
209 |
*/
|
210 |
public boolean isPeriodic() { |
211 |
return periodic;
|
212 |
} |
213 |
/**
|
214 |
* @param periodic The periodic to set.
|
215 |
*/
|
216 |
public void setPeriodic(boolean periodic) { |
217 |
this.periodic = periodic;
|
218 |
} |
219 |
/**
|
220 |
* @return Returns the rational.
|
221 |
*/
|
222 |
public boolean isRational() { |
223 |
return rational;
|
224 |
} |
225 |
/**
|
226 |
* @param rational The rational to set.
|
227 |
*/
|
228 |
public void setRational(boolean rational) { |
229 |
this.rational = rational;
|
230 |
} |
231 |
/**
|
232 |
* @return Returns the weights.
|
233 |
*/
|
234 |
public double[] getWeights() { |
235 |
return weights;
|
236 |
} |
237 |
/**
|
238 |
* @param weights The weights to set.
|
239 |
*/
|
240 |
public void setWeights(double[] weights) { |
241 |
this.weights = weights;
|
242 |
} |
243 |
/* (non-Javadoc)
|
244 |
* @see com.iver.cit.jdwglib.dwg.IDwg3DTestable#has3DData()
|
245 |
*/
|
246 |
public boolean has3DData() { |
247 |
double[][] pts = getControlPoints(); |
248 |
if(pts == null) { |
249 |
return false; |
250 |
} |
251 |
double z = 0d; |
252 |
for (int j=0;j<pts.length;j++) { |
253 |
z = pts[j][2];
|
254 |
if (z != 0.0) { |
255 |
return true; |
256 |
} |
257 |
}//for
|
258 |
return false; |
259 |
} |
260 |
public double getZ() { |
261 |
return 0d; |
262 |
} |
263 |
/* (non-Javadoc)
|
264 |
* @see java.lang.Object#clone()
|
265 |
*/
|
266 |
public Object clone(){ |
267 |
DwgSpline obj = new DwgSpline(index);
|
268 |
this.fill(obj);
|
269 |
return obj;
|
270 |
} |
271 |
|
272 |
protected void fill(DwgObject obj){ |
273 |
super.fill(obj);
|
274 |
DwgSpline myObj = (DwgSpline)obj; |
275 |
|
276 |
myObj.setBeginTanVector(beginTanVector); |
277 |
myObj.setClosed(closed); |
278 |
myObj.setControlPoints(controlPoints); |
279 |
myObj.setControlTolerance(controlTolerance); |
280 |
myObj.setDegree(degree); |
281 |
myObj.setEndTanVector(endTanVector); |
282 |
myObj.setFitPoints(fitPoints); |
283 |
myObj.setFitTolerance(fitTolerance); |
284 |
myObj.setKnotPoints(knotPoints); |
285 |
myObj.setKnotTolerance(knotTolerance); |
286 |
myObj.setPeriodic(periodic); |
287 |
myObj.setRational(rational); |
288 |
myObj.setScenario(scenario); |
289 |
myObj.setWeights(weights); |
290 |
|
291 |
} |
292 |
public Geometry toFMapGeometry(boolean is3DFile) throws CreateGeometryException { |
293 |
//FIXME: Implementación provisional para ver si podemos leer SPLINES
|
294 |
//De momento creamos una polilinea cuando deberíamos crear un spline o un bspline
|
295 |
GeometryManager gMan = GeometryLocator.getGeometryManager(); |
296 |
Spline pline = null;
|
297 |
int subType = getGeometrySubType(is3DFile);
|
298 |
double elev = getZ();
|
299 |
double[][] points = getFitPoints(); |
300 |
if (points == null) { |
301 |
points = getControlPoints(); |
302 |
} |
303 |
|
304 |
|
305 |
if (points == null) { |
306 |
gMan.createNullGeometry(subType); |
307 |
} |
308 |
pline = (Spline) gMan.create(getGeometryType(), subType); |
309 |
Point point;
|
310 |
for (int i = 0; i < points.length; i++) { |
311 |
point = (Point) gMan.create(Geometry.TYPES.POINT, subType);
|
312 |
pline.addVertex(point); |
313 |
} |
314 |
return pline;
|
315 |
} |
316 |
|
317 |
public String toFMapString(boolean is3DFile) { |
318 |
if(is3DFile) {
|
319 |
return "FPolyline3D"; |
320 |
} else {
|
321 |
return "FPolyline2D"; |
322 |
} |
323 |
} |
324 |
public String toString(){ |
325 |
return "Spline"; |
326 |
} |
327 |
|
328 |
public int getGeometrySubType(boolean is3DFile) { |
329 |
if (is3DFile) {
|
330 |
return Geometry.SUBTYPES.GEOM3D;
|
331 |
} else {
|
332 |
return Geometry.SUBTYPES.GEOM2D;
|
333 |
} |
334 |
} |
335 |
|
336 |
public int getGeometryType() { |
337 |
// return Geometry.TYPES.SOLID; FIXME not implemented
|
338 |
return Geometry.TYPES.SPLINE;
|
339 |
} |
340 |
|
341 |
} |