Loading files and selecting shapes

Hi all,

I managed to read IGES files with OCC and Qt, with the following basic code :

Handle(TopTools_HSequenceOfShape) sequence;
IGESControl_Reader reader;
int status = reader.ReadFile((Standard_CString)cad_file_name.latin1());

if (status == IFSelect_RetDone)
{
sequence = new TopTools_HSequenceOfShape ();
reader.TransferRoots ();
sequence->Append (reader.OneShape ());
}
else
throw QString ("Error");
return sequence;

This code works fine to load IGES files, but the resulting model is a one big shape, and i am able just to select the whole model, no particular shapes.
I have tried to configure the selection mode of the corresponding InteractiveObject to mode 4(selection of faces), but it does not work.

For the moment, I have found a solution, but I don't know if it is a good one. I read differently the IGES file, trying to iterate on all the shapes of the file, without using IGESControl_Reader->OneShape () :

Handle(TopTools_HSequenceOfShape) sequence;
IGESControl_Reader reader;
int status = reader.ReadFile((Standard_CString)_cad_file_name.latin1());

if (status == IFSelect_RetDone)
{
sequence = new TopTools_HSequenceOfShape ();
reader.TransferRoots ();
int count_of_shapes = reader.NbShapes ();

for (int i = 1; i {
for (TopoDS_Iterator it (reader.Shape (i));
it.More (); it.Next ())
sequence->Append (it.Value ());
sequence->Append (reader.Shape (i));
}
}
else
throw QString ("Error");
return sequence;

With this code, all the shapes of the resulting model are selectable, although the selection behaves bizarrely(I have to avoid some area of a shape if I want to select it).
Maybe some shapes are duplicated due to the code above.

Does someone have a better solution?

Thanks a lot.

Balkos's picture

try this:

IGESToBRep_Reader Reader;
Handle(TopTools_HSequenceOfShape) sequence;
Standard_Integer status = Reader.LoadFile(fName);

if (!status)
{
sequence = new TopTools_HSequenceOfShape ();
Reader.TransferRoots();
for (int i=1;i<=Reader.NbShapes();i++)
sequence->Append (reader.Shape (i));
}

Best regards

Hugues Delorme's picture

Hi,

This works fine on most IGES files. However, I have some IGES files whose the above code does not work. When loading these problematic IGES files with this code, I can't select particular surfaces of the loaded piece, just able to select the whole piece or nothing. But if I use the "redondant" loading code I posted, the problem is solved. I don't understand why. Can someone have a look at those IGES files I have? Just tell me in a reply of this message and I will send you the file.

Thanks for your help.

Patrik Mueller's picture

Hi,

how about using the ShapeFix classes after reading the file?

Regards,

Patrik