-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question] How to do deal with operators #3
Comments
My C++ is rusty, but this operator is an implicit conversion operator right? So For this case, you probably don't need csource "path/to/header.h":
type GC_MakeArcOfCircle* = object of CClass
type Geom_TrimmedCurve* = object of CClass
converter toGeom_TrimmedCurve*(self: GC_MakeArcOfCircle): var Geom_TrimmedCurve
{.importcpp:"(#)".} Then you use it like this: var test1 = GC_MakeArcOfCircle.init()
var test2: Geom_TrimmedCurve = test1 # implicit conversion happens here at both the Nim and C++ levels if you want a C++ reference variable, you might need something like let test2 {.cref.}: Geom_TrimmedCurve = test1 but currently |
No success yet. I have the following code:
import occt
import cinterop
let
myWidth = 50.0
myThickness = 20.0
myHeight = 70.0
aPnt1 = newPnt(-myWidth / 2.0, 0, 0)
aPnt2 = newPnt(-myWidth / 2.0, -myThickness / 4.0, 0)
aPnt3 = newPnt(0, -myThickness / 2.0, 0)
aPnt4 = newPnt(myWidth / 2.0, -myThickness / 4.0, 0)
aPnt5 = newPnt(myWidth / 2.0, 0, 0)
echo aPnt2
echo aPnt3
echo aPnt4
var aArcOfCircle = makeArcOfCircle(aPnt2, aPnt3, aPnt4)
import cinterop
import gp_Pnt
csource "Standard_Handle.hxx":
cnamespace opencascade:
type
handle*[T] = object of CClass
type
Handle = handle
csource "Geom_TrimmedCurve.hxx":
type
Geom_TrimmedCurve* = object of CClass
type
Handle_Geom_TrimmedCurve* = Handle[Geom_TrimmedCurve]
csource "GC_MakeArcOfCircle.hxx":
type
GC_MakeArcOfCircle* = object of CClass
gp_Circ* = object of CClass
converter toHandle_Geom_TrimmedCurve*(self: GC_MakeArcOfCircle): var Handle_Geom_TrimmedCurve {.importcpp:"(#)".}
proc makeArcOfCircle*(a,b,c:Pnt):GC_MakeArcOfCircle =#Handle_Geom_TrimmedCurve =
return GC_MakeArcOfCircle.init(a,b,c) An error is raised on the generated c++ code:
Where the cpp code is complaining about is:
N_LIB_PRIVATE N_NIMCALL(GC_MakeArcOfCircle, makeArcOfCircle__IyOEPhf5t8KHn5UprzMDPQ)(gp_Pnt* a, gp_Pnt* b, gp_Pnt* c) {
GC_MakeArcOfCircle result; //<--------- BLAMING LINE
nimfr_("makeArcOfCircle", "/home/jose/src/occt.nim/src/lib/gc.nim");
{ nimln_(29, "/home/jose/src/occt.nim/src/lib/gc.nim");
result = GC_MakeArcOfCircle((*a), (*b), (*c));
goto BeforeRet_;
}BeforeRet_: ;
popFrame();
return result;
}
/* section: NIM_merge_VARS */
N_LIB_PRIVATE NIM_CONST NF myWidth__4Dx1Z09bA3pua5C9aa1tzO9bg = 5.0000000000000000e+01;
N_LIB_PRIVATE NIM_CONST NF myThickness__jgfYRYDsoA1aSux3WNwLfA = 2.0000000000000000e+01;
N_LIB_PRIVATE NIM_CONST NF myHeight__9cE6D4OW0Dv9cPNqcUOfsMsQ = 7.0000000000000000e+01;
N_LIB_PRIVATE gp_Pnt aPnt1__6nbm5xlJ7PvXUKoJssDDjQ;
N_LIB_PRIVATE gp_Pnt aPnt2__Kk2fL5Mpd9cYsMZ47DXOCuQ;
N_LIB_PRIVATE gp_Pnt aPnt3__9czGtnL4XruNd3ShGqu9bjRQ;
N_LIB_PRIVATE gp_Pnt aPnt4__nocn09bSjOm249b6Cy9afk8kQ;
N_LIB_PRIVATE gp_Pnt aPnt5__kgutqiL8dpxwZe10yFf3Iw;
N_LIB_PRIVATE GC_MakeArcOfCircle aArcOfCircle__Uweq2PxKseJhRoJApFwnOw; //<----- BLAMING LINE
extern TFrame* framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw;
extern TFrame* framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw;
extern TFrame* framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw;
extern TFrame* framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw;
extern TFrame* framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw;
extern TFrame* framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw; I am a bit lost |
It worked with a couple of changes: csource "GC_MakeArcOfCircle.hxx":
type
GC_MakeArcOfCircle* = object of CClass
gp_Circ* = object of CClass
converter toHandle_Geom_TrimmedCurve*(self: GC_MakeArcOfCircle):Handle_Geom_TrimmedCurve {.importcpp:"(#)".}
proc makeArcOfCircle*(a,b,c:Pnt):Handle_Geom_TrimmedCurve =
return GC_MakeArcOfCircle.init(a,b,c) |
How should I deal with operators?
For instance, the following operator:
gets wrapped by c2nim as something like:
How would I use operators from cinterop.
The text was updated successfully, but these errors were encountered: