For all issues regarding the Forums use, please, refer to the Forum Rules.

Our Solutions

Need professional assistance?
Consider our:

Support Offerings

 

Need to speed up your development?
Have a look at our:

Samples & Tools

 

Need some functionality extending standard OCCT capabilities?
Check out our:

Adv. Components

Related pages

Error when trying to convert an Edge to a Geom_Curve

HASANI Kreshnik's picture
Forums: 

Hi,

I want to convert an Edge to a Geom_Curve. I try this code :

TopoDS_Edge anEdge = TopoDS::Edge(myAISContext->SelectedShape()) ;

Handle(Geom_Curve) myCurve = BRep_Tool::Curve(anEdge, First, Last);

Handle(Geom_BSplineCurve) myBSplCurve = Handle(Geom_BSplineCurve)::DownCast( myCurve);

I have the following compilation error :

C:\OpenCASCADE5.2\samples\standard\Mfc\Selection\src\AISSelectDoc.cpp(321) : error C2065: 'First' : undeclared identifier
C:\OpenCASCADE5.2\samples\standard\Mfc\Selection\src\AISSelectDoc.cpp(321) : error C2065: 'Last' : undeclared identifier

Can someone help me ?

Thanks in advance for your answer

Francois Lauzon's picture

Looks like you didn't declare First and Last,

Standard_Real First,Last;

for example...

HASANI Kreshnik's picture

Merci Francois,

Je suis nouveau en OCC et VC++ alors je me perds des fois sur des petits détail.

HASANI Kreshnik's picture

Hi,

What is First and Last ? What is their role ?

Thanks

ES's picture

you have to Handle(Geom_Curve) myCurve = BRep_Tool::Curve(anEdge);
to no limit edge.

HASANI Kreshnik's picture

Hi,

What is First and Last ? What is their role ?

Thanks

Rob Bachrach's picture

First and Last are filled in on output from the Curve function.
They contain the bounding parameters of the curve defining the edge.
So, if the edge is a circular arc, the curve is a circle and first and
last contain the parameters (angles) that trim the circle to the arc.

HASANI Kreshnik's picture

Thank you Bob.

I have always then same problem : I select an edge in GUI and I want to obtain the vertices of this edge or the BSpline description.
I obtain errors !

Thanks

Rob Bachrach's picture

Once you've defined First and Last as Standard_Real, does your
code then compile? What errors do you receive now?

HASANI Kreshnik's picture

Thanks Rob

My code :

Handle(Geom_Curve) myCurve = BRep_Tool::Curve(myEdge, First, Last);
Handle(Geom_BSplineCurve) myBSplCurve = GeomConvert::CurveToBSplineCurve(myCurve);

There are no compilation error but when I execute this part of code I've this error : 0093C336C:Standard_DomainError:No such curve.

Thanks

Rob Bachrach's picture

Look at the Exceptions documentation for GeomConvert::CurveToBSplineCurve. It states the reasons for a DomainError:

- if the curve C is infinite, or
- if C is a (complete) circle or ellipse, and Parameterisation is equal to Convert_TgtThetaOver2_1 or Convert_TgtThetaOver2_2.

Although it is possible that your problem is the later, I have a feeling your problem is the former (ie. the curve is infinite).
CurveToBSplineCurve only works on finite curves. The Curve function is probably returning an infinite curve (which is limited by First, Last). You may need to create a trimmed curve (Geom_TrimmedCurve) using the curve and parameters before converting to a BSpline.

HASANI Kreshnik's picture

How can I do ? The edge than I select is the edge of a cube.

Thanks.

Rob Bachrach's picture

In that case, your edge is almost certainly an infinite line trimmed by First and Last. Try:

Handle(Geom_Curve) myCurve = BRep_Tool::Curve(myEdge, First, Last);
Handle(Geom_TrimmedCurve) myTrimmed = new Geom_TrimmedCurve(myCurve, First, Last);
Handle(Geom_BSplineCurve) myBSplCurve = GeomConvert::CurveToBSplineCurve(myTrimmed);

HASANI Kreshnik's picture

I works. Thank you very much Rob. People like you are very important in the developpemnt world.