0

I need to read simple step files (turning parts) with C++. Therefore I try to use Open Cascade. I already can open my step file and read the number of shapes in my file. Now I need to get the geometrical data (length, width, diameters..), but I dont know how it works, although I read all of the documentations. Is there anyone who already worked with Open Cascade and can help me with my Problem? I would be very happy, thank alot !!

That's my Code since then

#include <iostream>
#include <STEPControl_Reader.hxx>
#include <string>

using namespace std;


int main() {

STEPControl_Reader reader;
IFSelect_ReturnStatus stat = reader.ReadFile("C:\\Users\\Kelevradesktop.Kelevra-desktop\\Desktop\\Studienarbeit\\steptest.step");
IFSelect_PrintCount mode = IFSelect_ListByItem;
reader.PrintCheckLoad(false, mode);

Standard_Integer NbRoots = reader.NbRootsForTransfer();                      //Transfer whole file
Standard_Integer num = reader.TransferRoots();

Standard_Integer NbTrans = reader.TransferRoots();
TopoDS_Shape result = reader.OneShape();
TopoDS_Shape shape = reader.Shape();


cout << NbRoots << endl;
cout << NbTrans << endl;
cout << num << endl;

system("pause");

return 0;
}
LaserG
  • 11
  • 1
  • 1
  • Please mark the question as resolved if I helped you or add more information if something is still unclear. Thank you. – jaba Jul 13 '18 at 13:10

2 Answers2

4

Check the FreeCad source code. They use OpenCascade and can import step and iges. It should get you started. The function ImportStepParts(...) in https://github.com/FreeCAD/FreeCAD/blob/master/src/Mod/Part/App/ImportStep.cpp is what you search for.

jaba
  • 735
  • 7
  • 18
  • Thanks alot for your answer. I only use Open Cascade and C++. Is it necessary to change to FreeCAD and Python now? – LaserG Jul 06 '18 at 09:57
  • No but you can look in the .cpp code that you find in the link and see how they import step files. You can follow their way from the step file to the TopoDS_Shape shapes. – jaba Jul 06 '18 at 10:45
0

Use TopExpExplorer class to iterate through the objects (vertexes, edges, faces..) of a shape. An iterating example you can find in this tutorial.

Use GProp_GProps class to get properties of a shape. Example:

GProp_GProps propertiesSystemFace;
BRepGProp::VolumeProperties(shape, propertiesSystemFace);
double shapeVolume = propertiesSystemFace.Mass();
gp_Pnt centerOfMass = propertiesSystemFace.CentreOfMass();

Also you can convert TopoDS_Edge to curve object to get some other parameters according to the edge type:

BRepAdaptor_Curve adaptCrv = BRepAdaptor_Curve(edge);