How to secure fillet building


I have the following code :

BRepOffsetAPI_Sewing sew;
// loop for creating faces/surfaces
for( ..... ) {
// faces/surfaces creation
// adding faces/surfaces to sew

// create a shape from sew
TopoDS_Shape body = sew.SewedShape();

// applying fillets on edges
BRepFilletAPI_MakeFillet mkFillet(body);
TopExp_Explorer aEdgeExplorer(body , TopAbs_EDGE);
while( aEdgeExplorer.More() ) {
TopoDS_Edge aEdge = TopoDS::Edge(aEdgeExplorer.Current());
mkFillet.Add(15.0, aEdge);
body = mkFillet.Shape();

How can I secure this code? If a fillet cannot be build on Edge (ie fillet is too big for connected faces), I don't want my app crashes.

Thank you for answer.
Best regards.

Rob Bachrach's picture

Although OCC does occasionally crash, it is rare. It is usually pretty good about throwing exceptions or setting status flags where appropriate. First, you should definitely check IsDone() on your mkFillet object before retrieving the shape (this is defined in the base class BRepBuilderAPI_Command). Second, you should probably surround all your OCC code in a try...catch block.

try {
catch (Standard_Failure) {
Handle(Standard_Failure) E = Standard_Failure::Caught();
cout << E->DynamicType()->Name() << ":" << E->GetMessageString() << endl;