How to connect Label with IMPORT geometry?

Dear All,

As OCAF example has demonstrated how to create a TDF_Label and Redo/Undo mechanism from a new created geometry using OCC functions. I wonder if anybody can tell how to create the same TDF_Label and Redo/Undo mechanism from the imported geometry (such as from Brep, IGES). I know that there must be lot of experts out there. Please share your experiences to novices like me.

Thanks in advance!

Sergey Ruin's picture

Hello,

Just try the following example: 1.Read a BRep shape stored in file "filename.brep" 2.Set it under label 0:1:1 3. Undo the operation 2.

Imagine you have an instance of Handle(TDocStd_Document) theDocument;

//Setting number of possible Undo's = 10

theDocument->SetUndoLimit(10);

//Import BRep shape

BRep_Builder aBuilder;

TopoDS_Shape aShape;

BRepTools::Read(aShape,"filename.brep", aBuilder);

//Now "aShape" contains a shape from file "filename.brep"

//Get the "main" label of document 0:1

TDF_Label aMainLabel = theDocument->Main();

//Close the previous transaction if any and open a new one

theDocument->NewCommand();

TDF_Label aTargetLabel = aMainLabel.FindChild(1, Standard_True);

//Set "aShape" under label "aTargetLabel"

TDataStd_Shape::Set(aTargetLabel, aShape);

//Close the previous transaction if any and open a new one

theDocument->NewCommand();

//Undo the addition of "aShape"

theDocument->Undo();

That is all

Best Regards

Sergey