OCC复制Shape

void occQt::makeBox()
{
    
    // 新建BOX
    TopoDS_Shape aTopoBoxA = BRepPrimAPI_MakeBox(3.0, 4.0, 5.0).Shape();
    
    //复制shape
    BRepBuilderAPI_Copy aShapeCopy;
    aShapeCopy.Perform(aTopoBoxA);
    TopoDS_Shape aTopoBoxB = aShapeCopy.Shape();
    
    //平移,防止2个BOX重叠
    gp_Trsf aTrsf;
    aTrsf.SetTranslation(gp_Vec(4.0, 0.0, 0.0));
    aTopoBoxB.Move(TopLoc_Location(aTrsf));
    
    //显示BOX
    Handle(AIS_Shape) anAisBoxA = new AIS_Shape(aTopoBoxA);
    anAisBoxA->SetColor(Quantity_NOC_AZURE);
    
    Handle(AIS_Shape) anAisBoxB = new AIS_Shape(aTopoBoxB);
    anAisBoxB->SetColor(Quantity_NOC_AZURE);
    
    myOccView->getContext()->Display(anAisBoxA, Standard_True);
    myOccView->getContext()->Display(anAisBoxB, Standard_True);
    
    //删除所有shape
    //myOccView->getContext()->RemoveAll(Standard_True);
    
}

如果是 pcurve,需要手动处理

详见:https://dev.opencascade.org/content/how-properly-copy-topodsshape

int CopyEdgeAndPCurve(const TopoDS_Edge& srcEdge, TopoDS_Edge& newEdge)
{
    int count = 0;
    BRepBuilderAPI_Copy copier(srcEdge);
    newEdge = TopoDS::Edge(copier.Shape());
    
    BRep_ListOfCurveRepresentation& srcCurList = (*((Handle(BRep_TEdge)*)&srcEdge.TShape()))->ChangeCurves();
    BRep_ListIteratorOfListOfCurveRepresentation srcIter(srcCurList);
    BRep_ListOfCurveRepresentation& newCurList = (*((Handle(BRep_TEdge)*)&newEdge.TShape()))->ChangeCurves();
    
    while (srcIter.More())
    {
        const Handle(BRep_CurveRepresentation)& cr = srcIter.Value();
        try
        {
            cr->PCurve();
            newCurList.Append(cr);
            ++count;
        }
        catch(...)
        {
        }
        srcIter.Next();
    }
    return count;
}
posted @ 2022-09-26 17:08  david123102  阅读(405)  评论(0)    收藏  举报