OCCT in QtQuick (QML)

Quaoar

Administrator
Staff member
@JSlyadne might want to comment on this. I do not know the details, but Qml+AIS definitely deserves a separate discussion as it unlocks the development of nice UI/UX not limited by the constraints of classical Qt. Another example here is OCC CADProcessor.
 

JSlyadne

Administrator
Staff member
Hello,

By any means did someone managed to create an AIS_Viewer using QtQuick and it's QML file ?

I actually don't know QtQuick but it seems quite nice so having an example code would be interesting.

It is possible since OpenCascade company is using it for creating app on Android :


This may be a good track to explore:

Hello Jojain,

We prefer QtQuick + Qml for UI development over the last few years already. This technology allows implementing a brand look-and-feel in a much simpler and convenient way in comparison to Qt Widgets.

The sample application provided by Open Cascade company seems to be a good point to start if you need a 3D viewer to occupy the whole application window. The code given there can be mostly reused for desktop applications as well as the approach is the same for all platforms. To put the long story short, the principle is that:
  • On the C++ level create an instance of QQuickItem class where you are going to initialize AIS and V3d stuff.
  • When the beforeSynchronizing() event is triggered, the OCCT view, viewer and context should be initialized.
  • The rendering itself must be done inside the handler of beforeRendering() event. The Qt/Qml triggeres this event to let the custom code to be performed before it redraws the UI item. Keep eyes open on the fact that rendering is done in a dedicated thread so be careful with read/write access to the data source - make sure it's thread-safe.
  • Register the instance of QQuickItem created at the first step for QmlEngine using the dedicated qmlRegisterType() method.
  • Place the instance of just registered class somewhere in the Qml part of your application, for example, inside the ApplicationWindow{}.
In case if the AIS renderer should draw the scene on just a piece of application area - not the whole window - then the Android sample isn't the solution. Here you'll need to utilize another approach and deal with frame buffer rendering.

You might want to experiment a bit with QtQuick and OCCT and put here the more narrow down questions how to overcome one or another problem. Good luck and fun!
 

Jojain

CAD practitioner
T
Hello Jojain,

We prefer QtQuick + Qml for UI development over the last few years already. This technology allows implementing a brand look-and-feel in a much simpler and convenient way in comparison to Qt Widgets.

The sample application provided by Open Cascade company seems to be a good point to start if you need a 3D viewer to occupy the whole application window. The code given there can be mostly reused for desktop applications as well as the approach is the same for all platforms. To put the long story short, the principle is that:
  • On the C++ level create an instance of QQuickItem class where you are going to initialize AIS and V3d stuff.
  • When the beforeSynchronizing() event is triggered, the OCCT view, viewer and context should be initialized.
  • The rendering itself must be done inside the handler of beforeRendering() event. The Qt/Qml triggeres this event to let the custom code to be performed before it redraws the UI item. Keep eyes open on the fact that rendering is done in a dedicated thread so be careful with read/write access to the data source - make sure it's thread-safe.
  • Register the instance of QQuickItem created at the first step for QmlEngine using the dedicated qmlRegisterType() method.
  • Place the instance of just registered class somewhere in the Qml part of your application, for example, inside the ApplicationWindow{}.
In case if the AIS renderer should draw the scene on just a piece of application area - not the whole window - then the Android sample isn't the solution. Here you'll need to utilize another approach and deal with frame buffer rendering.

You might want to experiment a bit with QtQuick and OCCT and put here the more narrow down questions how to overcome one or another problem. Good luck and fun!
Thank you JSlyadne, this is useful information.

This is not on top on my priorities right now so I might not try experimenting on it any time soon but I will post my updates when I have some.

I actually don't know how to code in C++ (even though it would be useful) so I might try this with Python backend instead.

Thank you :)
 

kndpeng

CAD practitioner
Hello Jojain,

We prefer QtQuick + Qml for UI development over the last few years already. This technology allows implementing a brand look-and-feel in a much simpler and convenient way in comparison to Qt Widgets.

The sample application provided by Open Cascade company seems to be a good point to start if you need a 3D viewer to occupy the whole application window. The code given there can be mostly reused for desktop applications as well as the approach is the same for all platforms. To put the long story short, the principle is that:
  • On the C++ level create an instance of QQuickItem class where you are going to initialize AIS and V3d stuff.
  • When the beforeSynchronizing() event is triggered, the OCCT view, viewer and context should be initialized.
  • The rendering itself must be done inside the handler of beforeRendering() event. The Qt/Qml triggeres this event to let the custom code to be performed before it redraws the UI item. Keep eyes open on the fact that rendering is done in a dedicated thread so be careful with read/write access to the data source - make sure it's thread-safe.
  • Register the instance of QQuickItem created at the first step for QmlEngine using the dedicated qmlRegisterType() method.
  • Place the instance of just registered class somewhere in the Qml part of your application, for example, inside the ApplicationWindow{}.
In case if the AIS renderer should draw the scene on just a piece of application area - not the whole window - then the Android sample isn't the solution. Here you'll need to utilize another approach and deal with frame buffer rendering.

You might want to experiment a bit with QtQuick and OCCT and put here the more narrow down questions how to overcome one or another problem. Good luck and fun!
I use opencascade +qml(QQuickItem), but it always display left bottom corner.
How to bind frame buffer rendering according QQuickItem xy(is not zero)coordinates?
 

JSlyadne

Administrator
Staff member
I use opencascade +qml(QQuickItem), but it always display left bottom corner.
How to bind frame buffer rendering according QQuickItem xy(is not zero)coordinates?
Hello kndpeng,

Could you please elaborate more on the issue you face as I'm not sure I got it. Providing a piece of code could help as well.
 
Top