About importing step files and finding out the faces or shapes of related parts

sjwa

Active CAD practitioner
Hello, Quaoar and other friends
I have a problem in my work now
I'm new to opencascade. I haven't been here for long
I watched your video on YouTube about exporting step files. It was great
However, when selecting faces and sub components to draw colors, this operation is completed under the condition that the label and other attributes are known
When I read the official MFC routine of opencascade, I saw the source code related to import
I found that they can extract noodles and do some operations
I would like to ask how to operate this? Or give me a direction?
I'd like to ask you for advice
Thank you
 

Attachments

  • 1660095678130.png
    1660095678130.png
    83.8 KB · Views: 11

JSlyadne

Administrator
Staff member
Hello, Quaoar and other friends
I have a problem in my work now
I'm new to opencascade. I haven't been here for long
I watched your video on YouTube about exporting step files. It was great
However, when selecting faces and sub components to draw colors, this operation is completed under the condition that the label and other attributes are known
When I read the official MFC routine of opencascade, I saw the source code related to import
I found that they can extract noodles and do some operations
I would like to ask how to operate this? Or give me a direction?
I'd like to ask you for advice
Thank you
Hey sjwa! I'm a bit lost what the problem is actually. Could you please describe the workflow you're working on and indicate where the problem is there?
 

sjwa

Active CAD practitioner
Hey sjwa! I'm a bit lost what the problem is actually. Could you please describe the workflow you're working on and indicate where the problem is there?
thank you for your reply
Actually my English is not very good
My question is actually this:
Importing a part file, how to extract sub-parts in the part, such as faces and edges?
Is it through XDE document?
Thank you for your tolerance
 

JSlyadne

Administrator
Staff member
Could you please also clarify what file's format - step, bep, iges, other - you import?
 

sjwa

Active CAD practitioner
Hi JSlyadne
The file format is STEP
But just now, I seem to have made it work, but I'm not sure
You can now use the name property in an XDE Document to find out which facet it is
I'm thinking maybe I can achieve my goal by playing with XDE
thanks for your reply
 

sjwa

Active CAD practitioner
Great to hear you advanced on your way. However, just in case, I leave a link to the code of lesson dedicated to XDE - maybe you'll find smth interesting there. Here it is https://gitlab.com/ssv/lessons/-/tree/master/Lesson12_XDE.
by the way,JSlyadne
One more question for you:
I imported a STEP formatted file and I can get the properties in the XDE document
According to my hints in the official documentation of opencascade
I can only seem to get four properties about Shape:
Name, Centroid, Volume, Area
So I want to get information such as the radius of the circle on one of the components in the part, how can I do it?

 

JSlyadne

Administrator
Staff member
Hello sjwa,

You should do the following:

1. Expode the shape on edges. Utilize TopExp_Explorer for that.
2. Find out a circle among all the edges. Utilize BRepAdaptor_Curve for that.
3. Get all properties you need from the resulted gp_Circ.
 

sjwa

Active CAD practitioner
Hello sjwa,

You should do the following:

1. Expode the shape on edges. Utilize TopExp_Explorer for that.
2. Find out a circle among all the edges. Utilize BRepAdaptor_Curve for that.
3. Get all properties you need from the resulted gp_Circ.
it worked, thank you
 

sjwa

Active CAD practitioner
I'm so sorry, but there's another small question
When I use the following code to find the label corresponding to a face in the shape
An error occurred, the label corresponding to the face could not be found
How can I find the label corresponding to a face?
thank you
Hello sjwa,

You should do the following:

1. Expode the shape on edges. Utilize TopExp_Explorer for that.
2. Find out a circle among all the edges. Utilize BRepAdaptor_Curve for that.
3. Get all properties you need from the resulted gp_Circ.
void getLabelFromShape(Handle(XCAFDoc_ShapeTool) &myAssembly, TopoDS_Shape & aShape) {

TDF_Label aLabel;
Standard_Boolean s_b = myAssembly->FindShape(aShape, aLabel, Standard_False);
if (s_b) {
std::cout << "find shape done" << std::endl;
if (aLabel.IsNull())
{
std::cout << "label is null" << std::endl;
}
else {
std::cout << "find label" << std::endl;
}
}
else
{
std::cout << "find shape fail" << std::endl;
}

}

The result of running is:
find shape fail
 

JSlyadne

Administrator
Staff member
I'm so sorry, but there's another small question
When I use the following code to find the label corresponding to a face in the shape
An error occurred, the label corresponding to the face could not be found
How can I find the label corresponding to a face?
thank you

void getLabelFromShape(Handle(XCAFDoc_ShapeTool) &myAssembly, TopoDS_Shape & aShape) {

TDF_Label aLabel;
Standard_Boolean s_b = myAssembly->FindShape(aShape, aLabel, Standard_False);
if (s_b) {
std::cout << "find shape done" << std::endl;
if (aLabel.IsNull())
{
std::cout << "label is null" << std::endl;
}
else {
std::cout << "find label" << std::endl;
}
}
else
{
std::cout << "find shape fail" << std::endl;
}

}

The result of running is:
find shape fail
XCAF document immitates the structure of STEP file, so that, only STEP entities representing assembly nodes and parts/solids will get the dedicated labels in OCAF document. Worth to mention that I omit GD&T entities and other metadata saying that. It's also possible to store sub-shapes in STEP which will also get a separate label in OCAF document after the translation, but such STEP files are rare case.

So, I suppose the reason why the label can't be found in OCAF document is that it doesn't present in the STEP file as a separate entity.
 

sjwa

Active CAD practitioner
XCAF document immitates the structure of STEP file, so that, only STEP entities representing assembly nodes and parts/solids will get the dedicated labels in OCAF document. Worth to mention that I omit GD&T entities and other metadata saying that. It's also possible to store sub-shapes in STEP which will also get a separate label in OCAF document after the translation, but such STEP files are rare case.

So, I suppose the reason why the label can't be found in OCAF document is that it doesn't present in the STEP file as a separate entity.
ok, i figured it out, thanks for the help you keep answering
I'm trying to find the center coordinates with BRepAdaptor's class
Thanks for your reply, it was very helpful for me
 
Top