How to cancel a "BRepMesh_IncrementalMesh" operation?

Hi! First of all: Thanks a ton for your great work on this library!

I have been working on a project called OpenCascade.js over at Github which is a port of of OpenCascade to JavaScript + WebAssembly using Emscripten's Embind. It's probably not quite ready for prime time but I hope it will be eventually.

I'm now working on a simple application in which you can load a 3D model in the STEP file format and convert it to a tessellated 3D model in the GLTF file format. Here's how a simple prototype looks like: https://streamable.com/exd7xl

The whole process happens in two stages.
1: I load the STEP file using STEPCAFControl_Reader
2: I tessellate it using BRepMesh_IncrementalMesh and finally I export it as a GLB file using RWGltf_CafWriter.

Stage 1 is called once for reading the STEP file. This function can take between a few milliseconds and minutes, depending on the complexity of the model.
Stage 2 is called each time the user changes the quality level. This function can take between a few milliseconds and minutes, depending on the complexity of the model and the quality level.

I'm wondering how I would implement a cancellation feature for the second stage. I.e. if a user accidentally chooses a very high quality level and then decides after a few seconds that they don't want to wait for the function execution to complete.

I saw some discussion online and this pull request about a "User Break" feature, but I couldn't find more information on how to actually do it. Any help with this would be greatly appreciated.

Mikhail Sazonov's picture

The class BRepMesh_IncrementalMesh is equipped with Message_ProgressRange. So, you can pass it to make it possible to break operation any time. Please study the documentation in the file Message_ProgressIndicator.hxx about usage.
The example of implementation of descendant of progress indicator if the class Draw_ProgressIndicator.

Sebastian Alff's picture

Thanks a lot for your reply!
I think I'm starting to understand how this works. So, I need to create my own derived class from Message_ProgressIndicator (or use Draw_ProgressIndicator) for that to work?!

I'll do a bit more research and will share my results here when I make some progress.