Geom2d.toShape() -> no 3D curve

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
Chris_G
Veteran
Posts: 2601
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Geom2d.toShape() -> no 3D curve

Post by Chris_G »

Hi,
I am experimenting with Part.Geom2d package.
It offers interesting possibilities like mapping edges ( or sketches ) on curved surfaces :
hello.jpg
hello.jpg (26.97 KiB) Viewed 1923 times
Unfortunately, the edges, once mapped on a surface, are not valid ( but visible in 3D view ).
Some operations fail on them later ( like mirroring ).
This piece of code shows the error :

Code: Select all

from FreeCAD import Base
import Part

obj = App.ActiveDocument.addObject("Part::Cylinder","Cylinder")
App.ActiveDocument.recompute()
shp = obj.Shape
elt = shp.Face1

l2d = Part.Geom2d.Line2dSegment(Base.Vector2d(0,0),Base.Vector2d(6.283185307179586,10.0))

edge = l2d.toShape(elt.Surface)
Part.show(edge)

edge.Curve
edge.check()
The returned errors are :

Code: Select all

>>> edge.Curve
Traceback (most recent call last):
  File "<input>", line 1, in <module>
TypeError: undefined curve type
>>> 
>>> edge.check()
StandardError: No 3D curve
Thanks,
Chris
wmayer
Founder
Posts: 20319
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Geom2d.toShape() -> no 3D curve

Post by wmayer »

I don't know the reason why check() raises the error nor how to fix it. But the raised exception with "Curve" is because internally OCC says it's of type "GeomAbs_OtherCurve" which is not a real curve type. For an edge built from a 2d edge I think the class BRepAdaptor_Curve requires the support face so that it creates a 3d curve. But then we cannot use the "Curve" attribute because we have to pass an argument.

So, to fix this we have to add a method getCurveFromFace(face)
User avatar
Chris_G
Veteran
Posts: 2601
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Geom2d.toShape() -> no 3D curve

Post by Chris_G »

Hi Werner,
Thanks for your answer.
Do you want me to make a bug report on mantis ?
I found a temporary workaround : the edges can be discretized, so they can be replaced by approximating BSpline curves.
Chris
wmayer
Founder
Posts: 20319
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Geom2d.toShape() -> no 3D curve

Post by wmayer »

Do you want me to make a bug report on mantis ?
You can do this so that we don't forget it. But for the check() error I guess the algorithm requires a 3d curve which when the "Curve" part is implemented should be doable:

Code: Select all

curve = edge.getCurveFromFace(face)
shape = curve.toShape()
shape.check()
wmayer
Founder
Posts: 20319
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Geom2d.toShape() -> no 3D curve

Post by wmayer »

wmayer wrote:I don't know the reason why check() raises the error nor how to fix it. But the raised exception with "Curve" is because internally OCC says it's of type "GeomAbs_OtherCurve" which is not a real curve type. For an edge built from a 2d edge I think the class BRepAdaptor_Curve requires the support face so that it creates a 3d curve. But then we cannot use the "Curve" attribute because we have to pass an argument.

So, to fix this we have to add a method getCurveFromFace(face)
I had a look at this and it seems something is wrong with the edge. The class BRepAdaptor_Curve is able to detect automatically the surface the edge is mapped to but later on the curve type is always set to GeomAbs_OtherCurve.

The only way how to continue from there is by discretizing the curve and then approximate a spline through the points.
User avatar
Chris_G
Veteran
Posts: 2601
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Geom2d.toShape() -> no 3D curve

Post by Chris_G »

wmayer wrote:I had a look at this and it seems something is wrong with the edge. The class BRepAdaptor_Curve is able to detect automatically the surface the edge is mapped to but later on the curve type is always set to GeomAbs_OtherCurve.
Do you mean that it is an OCC bug ?
wmayer wrote:The only way how to continue from there is by discretizing the curve and then approximate a spline through the points.
That sounds like a good workaround. I need to test if the resulting curves are good enough to create a face with Part.Face( Wire, Surface).
Thanks,
Chris
wmayer
Founder
Posts: 20319
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Geom2d.toShape() -> no 3D curve

Post by wmayer »

Do you mean that it is an OCC bug ?
Hard to say. At least when creating a line or a circle instead of the helix then the Curve attribute doesn't raise an error. What I found odd is that in TopoShape::makeLongHelix we do pretty much the same and there the curve is correctly detected as B-spline.
wmayer
Founder
Posts: 20319
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Geom2d.toShape() -> no 3D curve

Post by wmayer »

OK, I found a difference between TopoShape::makeLongHelix and Curve2dPy::toShape: it's the call of BRepLib::BuildCurves3d and when adding this the Curve is now correctly handled as a B-spline.
git commit 2dcbba9
User avatar
Chris_G
Veteran
Posts: 2601
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Geom2d.toShape() -> no 3D curve

Post by Chris_G »

Great !
Thanks a lot, Master Werner "BugKiller" Mayer :D
I guess this fixes both errors ( edge.Curve and edge.check() ) ?
The bug report is not necessary anymore ?
wmayer
Founder
Posts: 20319
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Geom2d.toShape() -> no 3D curve

Post by wmayer »

Yes, it fixes both issues. No need for a report.
Post Reply