OpenCascade: brep read fails

531 views Asked by At

OpenCascade does not load some brep file but if I try to load with FreeCad they works. The code is:

#include <QCoreApplication>
#include <BRepTools.hxx>
#include <BRep_Builder.hxx>
#include <unistd.h>

int main(int argc, char *argv[])
{
    BRep_Builder brbp;
    QCoreApplication a(argc, argv);

    TopoDS_Shape entityOCC;
    bool ret = BRepTools::Read(entityOCC,Standard_CString("draw.brep"), brbp);
    if(ret == false)
    {
        printf("BREP read failed\n");fflush(0);
    }else{
        printf("CAD brep loaded\n");fflush(0);
    }
    if(entityOCC.IsNull())
    {
        printf("Null Shape\n");fflush(0);
    }
    return a.exec();
}

I am using OpenCascade Community edition 0.18.1-2.4 equivalent to 6.9.1

Edit:

When I execute the program I get an OpenCascade message: "Not a TShape table" But same file is opened with out problem with FreeCad.

2

There are 2 answers

0
Trick On

It may be that these brep files contain some utf-8 strings. Similar situations occur when i try reading some step file with OpenCascade.

0
Lahiru Dilshan On

Try using this.

Handle(DEBRepCascade_ConfigurationNode) aNode = new DEBRepCascade_ConfigurationNode();
// You can configure whatever you want
// aNode->InternalParameters.
Handle(DE_Provider) aProvider = aNode->BuildProvider();
// You can import or export
TCollection_AsciiString aPath = ...;
TopoDS_Shape aShape = ...;
Handle(TDocStd_Document) aDoc = ...;
// You be able to import or export in single style for all formats
// aProvider->Write(aPath, aDoc/aShape);
// aProvider->Read(aPath, aDoc/aShape);