Resetting the transformation will collapse the object into the origin.

Imported the step model and display in the viewer using following code

Handle(TDocStd_Document) anXdeDoc = reader->doc;
Handle(AIS_InteractiveContext) theCtx = m_pAISContext;
Handle(V3d_View) theView = m_pV3dView;
for (XCAFPrs_DocumentExplorer aDocExp(anXdeDoc,XCAFPrs_DocumentExplorerFlags_None);aDocExp.More(); aDocExp.Next())
	const XCAFPrs_DocumentNode& aNode = aDocExp.Current();
	if (aNode.IsAssembly) { continue; } 
	Handle(XCAFPrs_AISObject) aPrs =  new XCAFPrs_AISObject(aNode.RefLabel);
	aPrs->SetOwner(new TCollection_HAsciiString(aNode.Id));
	theCtx->Display(aPrs, AIS_Shaded, 0, false);
theView->FitAll(0.01, false);

The assembly displays correctly, but when I traverse through each component and try to perform a resetTransformation, all objects move to a single point, as shown in the picture.

Upon investigation, I found that I am applying the location using aPrs->SetLocalTransformation(aNode.Location);. Is there a way to avoid this so that when I reset the transformation, the objects will return to their original positions instead of collapsing to one point?

Dmitrii Pasukhin's picture

Hello, the issue based on the your way of getting ShLabe. AIS object can have a LocalTransformation or TopoDS_Shape location inside shape.

In your case you extract reference of the shape label. Reference in that case has no transformation. If you will use a current Label the transformation will be kept.

Additionally, I see that current approuch ignore the transformations of the parents. Looks like you need to reorginize the parsing logic. What is a goal for your? I recommend to extarct only FreeShapes and create a group of XSPrs_AISObj on each free shape.

Please take a look into

Or it can be possible to create your own class inherited from AIS_ColoredShape with option to update location of the input TopoDS_Shape.

Or you can update a shape inside with aPrs->SetShape(aPrs->Shape().Located(Location)); But it will be a problem with map of sup-shapes.

One of the solutions, you can update your own function of resetting transformations based on XCAF. Or you can update Locaion of the shape itself before creating an AIS object (document will be not valid after that operation for general visualization or reusing).

Best regards, Dmitrii.

rahulmulik9's picture

I have resolved this issue using following code

TopoDS_Shape shape = XCAFDoc_ShapeTool::GetShape(aNode.RefLabel).Located(aNode.Location, Standard_False);
Handle(AIS_Shape) mShape = new AIS_Shape(shape);
theCtx->Display(mShape, AIS_Shaded);


TopoDS_Shape shape = XCAFDoc_ShapeTool::GetShape(aNode.RefLabel).Located(aNode.Location, Standard_False);
Handle(AIS_ColoredShape) mShape = new AIS_ColoredShape(shape);
theCtx->Display(mShape, AIS_Shaded);

However, with this approach, the time required to import the model has increased by 3 hours.
This is also observed with other models.
Additionally, if I use this approach, I will need to extract materials or colors separately.
(Importing a step file. Open cascade version 7.7.0)

Dmitrii Pasukhin's picture

Your code generate a lot of leaves of shapes. Did you check just for free shapes(roots)?

  // collect sequence of labels to display
  Handle(XCAFDoc_ShapeTool) shapes = XCAFDoc_DocumentTool::ShapeTool (aDoc->Main());
  shapes->GetFreeShapes ( seq );
  for (const auto& aRoot: shapes)
	Handle(XCAFPrs_AISObject) aPrs =  new XCAFPrs_AISObject(aRoot);
	theCtx->Display(aPrs, AIS_Shaded, 0, false);

Best regards, Dmitrii.

rahulmulik9's picture

I tried this approach as well, but when iterating through each node to check whether it is an assembly or a part, some parts are incorrectly treated as assemblies. This happens because the material information for some parts is stored in sub-labels, causing issues and significantly increasing the processing time.

Can you provide an example to get each component so that I can properly fill the model tree based on the assembly-part relationship?