I keep on playing with OpenCascade library. I am trying to visualize something on the screen. For that purpose, I am trying to mimic a simplified version of this example.
My Nim code (very ugly, I know) goes as follows:
import occt
#-----
# 1. Type definition
#------
type
OcctAisHello* = object of AIS_ViewController
myContext*:Handle[AISInteractiveContext]
myView*:Handle[V3d_View]
# Return context.
proc context(this:OcctAisHello):Handle[AIS_InteractiveContext] =
return this.myContext
# Return view.
proc view(this:OcctAisHello):Handle[V3d_View] =
return this.myView
# --------------------------------------
# 2. This is the constructor
# --------------------------------------
proc newOcctAisHello*():OcctAisHello =
# graphic driver setup
var aDisplay:Handle[Aspect_DisplayConnection] = newHandle( cnew newAspectDisplayConnection() )
var aDriverOpenGl:Handle[OpenGlGraphicDriver] = newHandle( cnew newOpenGlGraphicDriver(aDisplay) )
var aDriver:Handle[Graphic3d_GraphicDriver] = newHandle( cast[ptr Graphic3d_GraphicDriver](aDriverOpenGl.get) )
#var aDriver:Graphic3d_GraphicDriver = aDriverOpenGl.downcast
# viewer setup
var aViewer:Handle[V3d_Viewer] = newHandle( cnew newV3dViewer( aDriver ) )
`*`(aViewer).setDefaultLights()
`*`(aViewer).setLightOn()
# view setup
var myView = newHandle( cnew newV3dView(aViewer) )
var aWindow:Handle[Xw_Window] = newHandle( cnew newXwWindow(aDisplay, "OCCT Viewer", 100, 100, 512, 512) )
var aWinAspect:Handle[AspectWindow] = newHandle( cast[ptr AspectWindow](aWindow.get) )
# Atom aDelWinAtom = aDisplay->GetAtom (Aspect_XA_DELETE_WINDOW);
`*`(myView).setWindow(aWinAspect)
`*`(myView).setBackgroundColor( newQuantityColor(quantity_NOC_GRAY50) )
`*`(myView).triedronDisplay( aspectTOTP_LEFT_LOWER, newQuantityColor(quantity_NOC_WHITE), 0.1 )
`*`(myView).changeRenderingParams().renderResolutionScale = 2.0
# interactive context and demo scene
var myContext = newHandle( cnew newAISInteractiveContext(aViewer) )
result.myContext = myContext
result.myView = myView
#var aSolid:TopoDS_Solid = box(100.0,100.0,100.0).solid()
var mybox = box(1.0, 2.0, 3.0)
mybox.build()
var solid:TopoDS_Solid = mybox.solid()
if solid.isNull:
raise newException(ValueError, "Can't export null shape to STEP")
var aShape:TopoDS_Shape = solid
var aShapeAis:Handle[AIS_Shape] = newHandle( cnew newAISShape(aShape) )
var aShapePrs:Handle[AIS_InteractiveObject] = newHandle( cast[ptr AIS_InteractiveObject](aShapeAis.get) )
`*`(myContext).display(aShapeAis, AIS_Shaded.cint, 0, false)
`*`(myView).fitAll(0.01, false)
`*`(aWindow).map()
`*`(myView).reDraw()
# --------------------------------------
# 3. Here it is define the main function
# --------------------------------------
proc main =
var aViewer:OcctAisHello = newOcctAisHello()
# X11 event loop
var aWindow:Handle[Xw_Window] = newHandle( cast[ptr Xw_Window]( `*`(`*`(aViewer).view()).window) )
var aDispConn:Handle[Aspect_DisplayConnection] = `*`(`*`(`*`(aViewer.view()).viewer()).driver()).getDisplayConnection()
var anXDisplay:Display = `*`(aDispConn).getDisplay()[]
#while true:
# discard
main()
When I compile it, I get the error:
CC: stdlib_digitsutils.nim
CC: stdlib_dollars.nim
CC: stdlib_system.nim
CC: viewer04.nim
/home/jose/src/nimlang/occt.nim/examples/cache/@mviewer04.nim.cpp: In function 'tyObject_OcctAisHello__4FfLiMkIhaAMoZFVAV19cSg newOcctAisHello__viewer4852_24()':
/home/jose/src/nimlang/occt.nim/examples/cache/@mviewer04.nim.cpp:481:16: error: use of deleted function 'tyObject_OcctAisHello__4FfLiMkIhaAMoZFVAV19cSg::tyObject_OcctAisHello__4FfLiMkIhaAMoZFVAV19cSg(const tyObject_OcctAisHello__4FfLiMkIhaAMoZFVAV19cSg&)'
481 | return result;
| ^~~~~~
/home/jose/src/nimlang/occt.nim/examples/cache/@mviewer04.nim.cpp:89:8: note: 'tyObject_OcctAisHello__4FfLiMkIhaAMoZFVAV19cSg::tyObject_OcctAisHello__4FfLiMkIhaAMoZFVAV19cSg(const tyObject_OcctAisHello__4FfLiMkIhaAMoZFVAV19cSg&)' is implicitly deleted because the default definition would be ill-formed:
89 | struct tyObject_OcctAisHello__4FfLiMkIhaAMoZFVAV19cSg : public AIS_ViewController {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/jose/src/nimlang/occt.nim/examples/cache/@mviewer04.nim.cpp:89:8: error: use of deleted function 'AIS_ViewController::AIS_ViewController(const AIS_ViewController&)'
In file included from /home/jose/src/nimlang/occt.nim/examples/cache/@mviewer04.nim.cpp:8:
/usr/include/opencascade/AIS_ViewController.hxx:54:7: note: 'AIS_ViewController::AIS_ViewController(const AIS_ViewController&)' is implicitly deleted because the default definition would be ill-formed:
54 | class AIS_ViewController
| ^~~~~~~~~~~~~~~~~~
/usr/include/opencascade/AIS_ViewController.hxx:54:7: error: use of deleted function 'Aspect_VKeySet::Aspect_VKeySet(const Aspect_VKeySet&)'
In file included from /usr/include/opencascade/AIS_ViewController.hxx:17:
/usr/include/opencascade/Aspect_VKeySet.hxx:25:7: note: 'Aspect_VKeySet::Aspect_VKeySet(const Aspect_VKeySet&)' is implicitly deleted because the default definition would be ill-formed:
25 | class Aspect_VKeySet : public Standard_Transient
| ^~~~~~~~~~~~~~
compilation terminated due to -fmax-errors=3.
Error: execution of an external compiler program 'g++ -c -std=gnu++14 -funsigned-char -w -fmax-errors=3 -fpermissive -I/usr/include/opencascade/ -I/home/jose/.choosenim/toolchains/nim-1.6.6/lib -I/home/jose/src/nimlang/occt.nim/examples -o /home/jose/src/nimlang/occt.nim/examples/cache/@mviewer04.nim.cpp.o /home/jose/src/nimlang/occt.nim/examples/cache/@mviewer04.nim.cpp' failed with exit code: 1
This is a bit too cryptic for me.
The generated C++ code is here.
Any idea about what am I doing wrong?
I think you need to learn more about C++ language as long as you write C++ library wrapper yourself. If you use only Nim language or use a Nim library that wraps C++ library nicely and is written by C++ expert, you might not need to learn C++. But you are wrapping C++ library and got compile errors from backend C++ compiler.
Also, using a library correctly usually requires reading the manual of it. C++ library's manual are written for C++ programmer. So reading C++ library manual requires C++ knowledge.
C++ is old and popular. There are many books or web sites for learning C++. Learning C++ might takes some times but you should be able to fix errors faster yourself after learning C++. That would be better than using C++ libraries without knowing C++ and ask questions everytime you got C++ errors and wait for someone provides the answer.
I guess AIS_ViewController deleted its copy constructor in order to forbid copying it. But return result; requires copying result. I think you need to read a Open CASCADE manual/tutorial/user guides/etc to use that type correctly. https://dev.opencascade.org/doc/overview/html/index.html