About .brep write

Hi everyone,

Is there a way to write multiple TopoDS_Shapes into one .brep file?

if so, How can t be done?

Thanks in advance

Zoltan Gaal's picture

Solution1: We had a similar problem. We just simply duplicated the classes and added the required functionality (Note: we wrote other informations too into the brep files)

Solution2: I think if you write to / read from a string stream instead of filestream, with a simple wrapper class the desired functionality can be added. (As far as I remeber the brep writer accepts streams too instead of a filename. We had some problems under Visual Studio b/c of the linking of the std (iostream.h vs. iostream.h) or something like that. - The recompilation of OC solved the problem. )

Solution 3: create a compound of the objects and write them out as a single object. When reading, use a simple TopExp_Iterator(?) to divide up the object.

Dean's picture

Hi Gaal,
Thanks for the solutions, I am thinking of using solution 3. but as much as I've known was that the TopExp_Iterator can only be defined to find one type of TopoDS_Shape. If I have many different types of TopoDS_Shape; when I loaded them, how am I able to determian how what types of TopoDS_Shape they were?

Thanks for your help

Zoltan Gaal's picture

There's an iterator who retreaves only the children of a TopoDS_Shape : TopoDS_Iterator. So if you collected the shapes into a compound you'll got s/g like:
compound - S1
-S2 ...
The iterator will return the S1,..,Sn shapes.

Actually i've never tried it before, but i think it must work.

good luck: Zoli

Tom Smith's picture

Hi there,

I have make it works. but not build them as a compound. I basically took the read and write out of breptools class. and rewrite my own calss. It is easy, and it works very well. however, it is kind of slow when it is reading and writing. any suggestions?


Bearloga's picture

Hi Tom,

Nevertheless, I think the best way is to pack shapes into a compound and write it once. In such way you will avoid duplication if your shapes share some data. E.g., if a shape was got by translation/rotation of another shape then it shares all the data and adds only the transformation matrix. It is obvious that when you write all shapes in one compound all shared data are written only once.


Dean's picture

Hi everyone,

I have done this, and this is really easy, but it works only under the debug mode. when I switch it to the release mode, it crashes. of course I have done the similar method when the file is readed. and there were no problems at all. Anyone knows the problem? Please help(I do not use ocaf stuff here tho)

Thank you

filebuf fic;
ostream os(&fic);

if (!fic.open(fileName, ios::out)) return Standard_False;

BRepTools_ShapeSet SS;

//Save the number of objects
CString num;
int real_num=s_Seq->Length();

float result=(float) real_num/10;

if(result>=1 && result<=9)

//Save label names
CString head="DBRep_DrawableShape";
CString newline="\n";

CString labelName;

for(int i=0;i<=s_Seq->Length()-1;i++)
head= head+"*" +labelName+newline;
char *tmp = new char[];
strcpy(tmp, head);

for (i=1;i<=s_Seq->Length();i++)
os << tmp;
os << "DBRep_DrawableShape\n";

Forum supervisor's picture

Hello Dean,

The problem you encounter could be caused by using both debug and release libraries during runtime. Try to check that all libraries loaded during execution are compiled in the same mode as your main executable.

Best regards,
Forum supervisor

Dean's picture

How do I check the loaded libraries during execution in debug or release mode?

Thanks in advance

QbProg's picture

I had the same problem too, seems like it's a problem with ostreams. Are you using a re-compiled version of OCC?

I think it's a problem between VC++ 6 streams and new streams... don't know!

If you don't find any solution, try to recompile OCC.