Logical ideas for displaying model assembly information

Hi, everyone!

I have two questions. The first one is about assembly display.

I can read the assembly of the model through XDE, but I encountered a situation where when the assembly of the model only has 1, it will display the Solid or Compound of the model.ex:(CAD assistant display effect),Sometimes it will be the same number as Solid, and sometimes it will be different. I want to know why.

Another question is how do I get the number of Parts and what does Parts represent?

Thanks for your reply!

Dmitrii Pasukhin's picture

Parts means assembly part. It is flexible parts that connected to the assembly root with some transfromation. It is not compound itself, it is assembly consturction.

  Handle(XCafDoc_ShapeTool) aShTool = ...;
  TDF_Label aLabel = ...;
  if (!aShTool ->IsAssembly(aLabel ))
  {
    return;
  }
  const int aNbComponents = aShTool->NbComponents (aLabel, false);
  TDF_LabelSequence aComponents;
  aShTool->GetComponents(aLabel, aComponents, false);

Best regards, Dmitrii.

sunlin0oo's picture

Thanks for your reply!
I can read its root node a        (0)  through XDE. According to the code you provided, no assembly was detected, but in the CAD assistant it shows that it has 8 parts.

I traversed the related properties of Compounds and got the number to be 1.

Do you have any relevant thoughts and ideas?  

I uploaded the model data. If necessary, you can download it for testing.
Looking forward to your reply again!

Attachments: 
gkv311 n's picture

The number you see is correct - this IGES model has only one object. What is confusing is CAD Assistant behavior - it implicitly expands document (XCAFDoc_Editor::Expand()) if it contains only a single root.

pload XDE VISIALIZATION
ReadIges D Product_0.iges
XExpand D 0; # that does the trick
vinit View1
XDisplay D -dispMode 1 -explore
vfit

Note that for preserving model structure it is better using STEP format instead of archaic IGES.

sunlin0oo's picture

Thanks for your reply!

Due to my lack of technical knowledge, I do not understand what you are saying,There are a few points:

First, When you say that there is only one IGES object, you mean that the number of Compounds is one, right?

Second, According to your pseudocode, this is what I understand

// Creating empty XCAF document
    Handle(TDocStd_Document) anXdeDoc;
    Handle(TDocStd_Application) anXdeApp = new TDocStd_Application();
    anXdeApp->NewDocument("MDTV-XCAF", anXdeDoc);

    if (!aReader.Transfer(anXdeDoc))
    {
        std::cerr << "message from readIGES: "
            << "error" << std::endl;
        return false;
    }
    // Initialize an XDE Document (Shapes)==>GetRootsFromDocument
    TDF_Label aRootLabel = anXdeDoc->Main();
    XCAFDoc_Editor::Expand(aRootLabel);
    Handle(XCAFDoc_ShapeTool) ShapeTool = XCAFDoc_DocumentTool::ShapeTool(aRootLabel);
    TDF_LabelSequence rootLabels;
    ShapeTool->GetShapes(rootLabels);
    if (!aShapeTool->IsAssembly(aRootLabel))
    {
        return false;
    }
    const int aNbComponents = aShapeTool->NbComponents(aRootLabel, false);
    std::cout<<"aNbComponents" << aNbComponents << std::endl;

But, II still can't get the same number of Parts as in CAD assistant.

Last, The STEP model uses STEPCAFControl_Reader, and the IGES model uses IGESCAFControl_Reader. They should not affect each other, right?

Looking forward to your reply!

sunlin0oo's picture

Thanks for your reply, now i can get assembly name. Next, I will continue to advance other work!