Tue, 07/09/2024 - 12:59
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->SetLocalTransformation(aNode.Location); aPrs->SetOwner(new TCollection_HAsciiString(aNode.Id)); theCtx->Display(aPrs, AIS_Shaded, 0, false); } theView->FitAll(0.01, false); theView->Redraw(); theView->Update();
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?
Attachments:
Tue, 07/09/2024 - 13:25
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 https://github.com/Open-Cascade-SAS/OCCT/blob/IR/src/XDEDRAW/XDEDRAW.cxx...
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.
Wed, 07/10/2024 - 09:33
I have resolved this issue using following code
OR
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)
Wed, 07/10/2024 - 09:40
Your code generate a lot of leaves of shapes. Did you check just for free shapes(roots)?
Best regards, Dmitrii.
Thu, 07/11/2024 - 08:31
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?