donalffons / opencascade.js-examples

example repository for opencascade.js

Home Page:https://ocjs.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Casting Handle_Geom_BSplineCurve down to Handle_Geom_Curve

opened this issue · comments

Hey guys, amazing effort, thanks a lot for making this happen, it's groundbreaking for web based CAD ecosystem!

I've started adding some experimental features to my platform based on OCC by following your examples and got stuck with something super basic, or so I thought...

I'm using v1.1.4 of opencascade.js and so far everything worked fine, I have basic solids drawn in our babylonjs based app, but I began implementing BSpline method, this is an excerpt from the code:

const geomCurveHandle = new occ.GeomAPI_PointsToBSpline_2(ptList, 3, 8, occ.GeomAbs_Shape.GeomAbs_C2, 1.0e-3).Curve();
const edge = new occ.BRepBuilderAPI_MakeEdge_24(geomCurveHandle).Edge();
return new occ.BRepBuilderAPI_MakeWire_1(edge).Wire();

and I get the following exception

Expected null or instance of Handle_Geom_Curve, got an instance of Handle_Geom_BSplineCurve

How do I DownCast the handle type in javascript from BSplineCurve to Curve? Any tip would be appreciated!

Ok, so after looking at examples closer I got it working ;) This is the code

const geomCurveHandle = new occ.GeomAPI_PointsToBSpline_2(ptList, 3, 8, occ.GeomAbs_Shape.GeomAbs_C2, 1.0e-3).Curve();
const edge = new occ.BRepBuilderAPI_MakeEdge_24(new occ.Handle_Geom_Curve_2(geomCurveHandle.get())).Edge();
return new occ.BRepBuilderAPI_MakeWire_1(edge).Wire();

this did the trick

new occ.Handle_Geom_Curve_2(geomCurveHandle.get())

Awesome, thanks for sharing your solution!