Revision 29001 branches/v2_0_0_prep/libraries/libDwg/src/org/gvsig/dwg/lib/objects/DwgSpline.java
DwgSpline.java | ||
---|---|---|
34 | 34 |
*/ |
35 | 35 |
package org.gvsig.dwg.lib.objects; |
36 | 36 |
|
37 |
import java.awt.geom.Point2D; |
|
38 |
import java.util.ArrayList; |
|
39 |
|
|
40 | 37 |
import org.gvsig.dwg.lib.DwgObject; |
41 | 38 |
import org.gvsig.dwg.lib.IDwg2FMap; |
42 | 39 |
import org.gvsig.dwg.lib.IDwg3DTestable; |
43 |
import org.gvsig.dwg.lib.util.FMapUtil; |
|
44 | 40 |
import org.gvsig.fmap.geom.Geometry; |
45 |
import org.gvsig.fmap.geom.GeometryFactory;
|
|
41 |
import org.gvsig.fmap.geom.GeometryLocator;
|
|
46 | 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; |
|
47 | 46 |
|
48 | 47 |
|
49 | 48 |
/** |
... | ... | |
246 | 245 |
*/ |
247 | 246 |
public boolean has3DData() { |
248 | 247 |
double[][] pts = getControlPoints(); |
249 |
if(pts == null) |
|
248 |
if(pts == null) {
|
|
250 | 249 |
return false; |
250 |
} |
|
251 | 251 |
double z = 0d; |
252 | 252 |
for (int j=0;j<pts.length;j++) { |
253 | 253 |
z = pts[j][2]; |
254 |
if (z != 0.0) |
|
254 |
if (z != 0.0) {
|
|
255 | 255 |
return true; |
256 |
} |
|
256 | 257 |
}//for |
257 | 258 |
return false; |
258 | 259 |
} |
... | ... | |
288 | 289 |
myObj.setWeights(weights); |
289 | 290 |
|
290 | 291 |
} |
291 |
public Geometry toFMapGeometry(boolean is3DFile) { |
|
292 |
public Geometry toFMapGeometry(boolean is3DFile) throws CreateGeometryException {
|
|
292 | 293 |
//FIXME: Implementación provisional para ver si podemos leer SPLINES |
293 | 294 |
//De momento creamos una polilinea cuando deberíamos crear un spline o un bspline |
294 |
GeometryFactory gFactory = GeometryManager.getInstance().getGeometryFactory(); |
|
295 |
Geometry pline = null; |
|
295 |
GeometryManager gMan = GeometryLocator.getGeometryManager(); |
|
296 |
Spline pline = null; |
|
297 |
int subType = getGeometrySubType(is3DFile); |
|
296 | 298 |
double elev = getZ(); |
297 | 299 |
double[][] points = getFitPoints(); |
298 | 300 |
if (points == null) { |
299 | 301 |
points = getControlPoints(); |
300 | 302 |
} |
301 | 303 |
|
302 |
Point2D[] aPoints = new Point2D[points.length]; |
|
303 |
for (int i=0; i < points.length; i++){ |
|
304 |
aPoints[i] = new Point2D.Double(points[i][0],points[i][1]); |
|
305 |
} |
|
306 | 304 |
|
307 |
if (points != null) { |
|
308 |
if (is3DFile) { |
|
309 |
pline = gFactory.createSpline2DZ(aPoints, elev); |
|
310 |
} else { |
|
311 |
pline = gFactory.createSpline2D(aPoints); |
|
312 |
} |
|
305 |
if (points == null) { |
|
306 |
gMan.createNullGeometry(subType); |
|
313 | 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 | 314 |
return pline; |
315 | 315 |
} |
316 | 316 |
|
317 | 317 |
public String toFMapString(boolean is3DFile) { |
318 |
if(is3DFile) |
|
318 |
if(is3DFile) {
|
|
319 | 319 |
return "FPolyline3D"; |
320 |
else
|
|
320 |
} else {
|
|
321 | 321 |
return "FPolyline2D"; |
322 |
} |
|
322 | 323 |
} |
323 | 324 |
public String toString(){ |
324 | 325 |
return "Spline"; |
325 | 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 |
|
|
326 | 341 |
} |
Also available in: Unified diff