Wrong located assemblies

I handle a TDocStd_Document like this:
I can display them without an issue if my toplevel assembly does not contain subassemblies but if it contains subassemblies, the subassembles childs are located correct (if they are not assemblies again :)) but located correct respective to top level assembly.

Please help .

TreeNode<OCCData> myclass::getRoot(const Handle_TDocStd_Document& doc) {
    shapeTool = XCAFDoc_DocumentTool::ShapeTool(doc->Main());
    colorTool = XCAFDoc_DocumentTool::ColorTool(doc->Main());

    TDF_LabelSequence rootLabels;
    shapeTool->GetFreeShapes(rootLabels);

    OCCData occData;
    TreeNode<OCCData> rootNode(occData);
    for (int i = 1; i <= rootLabels.Length(); ++i) {

        rootNode.getValue().Label = rootLabels.Value(i);;

        rootNode.getValue().Location = shapeTool->GetLocation(rootNode.getValue().Label);

        rootNode.getValue().topoShape = shapeTool->GetShape(rootNode.getValue().Label).Located(rootNode.getValue().Location);

        rootNode.getValue().shape = new AIS_Shape(rootNode.getValue().topoShape);

        if (shapeTool->IsAssembly(rootNode.getValue().Label)) {
            TDF_LabelSequence sequence;
            shapeTool->GetComponents(rootNode.getValue().Label, sequence);
            for(TDF_Label childLabel : sequence){

                rootNode.addChild(getChildren(rootNode, childLabel, rootNode.getValue().Location));
            }
        }

    }
    return rootNode;
}

TreeNode<OCCData>
myclass::getChildren(TreeNode<OCCData> arg_node, const TDF_Label &arg_label, TopLoc_Location arg_location) {

    if (shapeTool->IsAssembly(arg_label)){

        OCCData occData;
        TreeNode<OCCData> childNode(occData);

        childNode.getValue().Label = arg_label;

        childNode.getValue().Location = TopLoc_Location(shapeTool->GetLocation(childNode.getValue().Label).Transformation() * arg_location.Transformation());
        childNode.getValue().topoShape = shapeTool->GetShape(childNode.getValue().Label).Located(childNode.getValue().Location);
        childNode.getValue().shape = new AIS_Shape(childNode.getValue().topoShape);

        TDF_LabelSequence labelSequence;
        shapeTool->GetComponents(arg_label, labelSequence);

        for (const TDF_Label& childLabel : labelSequence ) {
            childNode.addChild(getChildren(childNode, childLabel, childNode.getValue().Location));
        }
        return childNode;
    }
    else if(shapeTool->IsReference(arg_label)){

        TDF_Label referredLabel;
        shapeTool->GetReferredShape(arg_label, referredLabel);
        return getChildren(arg_node, referredLabel, shapeTool->GetLocation(arg_label));
    }
    else{

        OCCData occData;
        TreeNode<OCCData> childNode(occData, &arg_node);
        childNode.getValue().Label = arg_label;

        childNode.getValue().Location = TopLoc_Location(shapeTool->GetLocation(childNode.getValue().Label).Transformation() * arg_location.Transformation());

        childNode.getValue().topoShape = shapeTool->GetShape(childNode.getValue().Label).Located(childNode.getValue().Location);
        childNode.getValue().shape = new AIS_Shape(childNode.getValue().topoShape);

        myViewerWidget->getContext()->Display(childNode.getValue().shape, false);

        return childNode;

    }


}
Kirill Gavrilov's picture

I don't think that gp_Trsf multiplication order is correct here - it looks reversed:

childNode.getValue().Location =
  TopLoc_Location(shapeTool->GetLocation(childNode.getValue().Label).Transformation()
  * arg_location.Transformation());

Also, consider taking a look onto XDisplay command implementation in Draw Harness (XDEDRAW_XDisplayTool in src/XDEDRAW/XDEDRAW.cxx), or to tool XCAFPrs_DocumentExplorer.