#include "FITKOCCModelOperSolid.h" // OCC base #include #include // 倒角/倒圆 #include #include // 特征移除。(填补孔洞/移除倒角/移除倒圆) #include // App #include "FITK_Kernel/FITKAppFramework/FITKAppFramework.h" #include "FITK_Kernel/FITKAppFramework/FITKGlobalData.h" // Geometry #include "FITKOCCVirtualTopoCreator.h" #include #include #include "FITK_Interface/FITKInterfaceGeometry/FITKGeoCommandList.h" #include "FITK_Interface/FITKInterfaceGeometry/FITKGeoInterfaceFactory.h" namespace OCC { // 倒角。 //@{ FITKOCCModelChamferSolid::FITKOCCModelChamferSolid() : OCCShapeAgent(this) { _shapeAgent = _occShapeAgent; } bool FITKOCCModelChamferSolid::update() { Interface::FITKGeoCommandList* geoCmdList = FITKGLODATA->getGeometryData(); // 获取被倒角的体模型。 Interface::FITKAbsGeoCommand* cmd = geoCmdList->getDataByID(m_solidCmdId); if (!cmd) { printLog(tr("Invalid input model !"), 3); return false; } // 旧版本对单独体进行操作。 //@{ // 获取体形状。 //@{ //OCC::FITKOCCTopoShape* vOCCShapeSolid = cmd->getShapeT(Interface::FITKGeoEnum::VTopoShapeType::VSSolid, m_solidVirtualId); //if (!vOCCShapeSolid) //{ // return false; //} //TopoDS_Solid topoSolid = TopoDS::Solid(vOCCShapeSolid->getTopoShape()); //if (topoSolid.IsNull()) //{ // return false; //} //@} //@} // 新版本对整个模型进行操作。 //@{ TopoDS_Shape* shape{ nullptr }; OCC::FITKAbstractOCCModel* occModel = cmd->getTShapeAgent(); if (occModel) { shape = occModel->getShape(); } //@} if (!shape) { return false; } if (m_dist <= 0) { return false; } // 创建倒角。 //@{ BRepFilletAPI_MakeChamfer mkChamfer(*shape); for (const int & vEdgeId : m_edgeVirtualIds) { OCC::FITKOCCTopoShape* vOCCShapeEdge = cmd->getShapeT(Interface::FITKGeoEnum::VTopoShapeType::VSEdge, vEdgeId); if (!vOCCShapeEdge) { continue; } TopoDS_Edge topoEdge = TopoDS::Edge(vOCCShapeEdge->getTopoShape()); if (topoEdge.IsNull()) { return false; } mkChamfer.Add(m_dist, topoEdge); } //@} // 异常处理。 try { mkChamfer.Build(); if (!mkChamfer.IsDone()) { printLog(tr("Invalid parameters !"), 3); return false; } const TopoDS_Shape & output= mkChamfer.Shape(); if (output.IsNull()) { printLog(tr("Invalid parameters !"), 3); return false; } // 更新形状。 _occShapeAgent->updateShape(output); } catch (...) { printLog(tr("Invalid parameters !"), 3); return false; } return true; } //@} // 倒圆。 //@{ FITKOCCModelFilletSolid::FITKOCCModelFilletSolid() : OCCShapeAgent(this) { _shapeAgent = _occShapeAgent; } bool FITKOCCModelFilletSolid::update() { Interface::FITKGeoCommandList* geoCmdList = FITKGLODATA->getGeometryData(); // 获取被倒圆的体模型。 Interface::FITKAbsGeoCommand* cmd = geoCmdList->getDataByID(m_solidCmdId); if (!cmd) { printLog(tr("Invalid input model !"), 3); return false; } // 旧版本对单独体进行操作。 //@{ // 获取体形状。 //@{ //OCC::FITKOCCTopoShape* vOCCShapeSolid = cmd->getShapeT(Interface::FITKGeoEnum::VTopoShapeType::VSSolid, m_solidVirtualId); //if (!vOCCShapeSolid) //{ // return false; //} //TopoDS_Solid topoSolid = TopoDS::Solid(vOCCShapeSolid->getTopoShape()); //if (topoSolid.IsNull()) //{ // return false; //} //@} //@} // 新版本对整个模型进行操作。 //@{ TopoDS_Shape* shape{ nullptr }; OCC::FITKAbstractOCCModel* occModel = cmd->getTShapeAgent(); if (occModel) { shape = occModel->getShape(); } //@} if (m_radius <= 0) { return false; } // 创建倒圆。 //@{ BRepFilletAPI_MakeFillet mkFillet(*shape); for (const int & vEdgeId : m_edgeVirtualIds) { OCC::FITKOCCTopoShape* vOCCShapeEdge = cmd->getShapeT(Interface::FITKGeoEnum::VTopoShapeType::VSEdge, vEdgeId); if (!vOCCShapeEdge) { continue; } TopoDS_Edge topoEdge = TopoDS::Edge(vOCCShapeEdge->getTopoShape()); if (topoEdge.IsNull()) { return false; } mkFillet.Add(m_radius, topoEdge); } //@} // 异常处理。 try { mkFillet.Build(); if (!mkFillet.IsDone()) { printLog(tr("Invalid parameters !"), 3); return false; } const TopoDS_Shape & output = mkFillet.Shape(); if (output.IsNull()) { printLog(tr("Invalid parameters !"), 3); return false; } // 更新形状。 _occShapeAgent->updateShape(output); } catch (...) { printLog(tr("Invalid parameters !"), 3); return false; } return true; } //@} // 移除特征。 //@{ bool FITKOCCDefeatureTool::Defeature(int cmdId, QList faceIds, TopoDS_Shape & outputShape) { Interface::FITKGeoCommandList* geoCmdList = FITKGLODATA->getGeometryData(); // 获取被移除特征的体模型。 Interface::FITKAbsGeoCommand* cmd = geoCmdList->getDataByID(cmdId); if (!cmd) { return false; } // 新版本对整个模型进行操作。 //@{ TopoDS_Shape* shape{ nullptr }; OCC::FITKAbstractOCCModel* occModel = cmd->getTShapeAgent(); if (occModel) { shape = occModel->getShape(); } //@} // 获取面形状。 //@{ TopTools_ListOfShape topoFaces; for (const int & vFaceId : faceIds) { OCC::FITKOCCTopoShape* vOCCShapeFace = cmd->getShapeT(Interface::FITKGeoEnum::VTopoShapeType::VSFace, vFaceId); if (!vOCCShapeFace) { return false; } TopoDS_Face topoFace = TopoDS::Face(vOCCShapeFace->getTopoShape()); if (topoFace.IsNull()) { return false; } topoFaces.Append(topoFace); } //@} // 移除特征。 //@{ try { BRepAlgoAPI_Defeaturing mkFillHole; mkFillHole.SetRunParallel(true); mkFillHole.SetToFillHistory(false); mkFillHole.SetShape(*shape); mkFillHole.AddFacesToRemove(topoFaces); mkFillHole.Build(); if (!mkFillHole.IsDone()) { return false; } outputShape = mkFillHole.Shape(); } catch (...) { return false; } //@} return true; } //@} // 移除特征。 //@{ FITKOCCModelDefeatureSolid::FITKOCCModelDefeatureSolid() : OCCShapeAgent(this) { _shapeAgent = _occShapeAgent; } bool FITKOCCModelDefeatureSolid::update() { // 移除特征。 TopoDS_Shape outputShape; bool flag = FITKOCCDefeatureTool::Defeature(m_solidCmdId, m_faceVirtualIds, outputShape); if (!flag) { printLog(tr("Invalid feature !"), 3); return false; } // 更新形状。 _occShapeAgent->updateShape(outputShape); return true; } //@} // 移除倒角。 //@{ FITKOCCModelRemoveChamferSolid::FITKOCCModelRemoveChamferSolid() : OCCShapeAgent(this) { _shapeAgent = _occShapeAgent; } bool FITKOCCModelRemoveChamferSolid::update() { // 移除特征。 TopoDS_Shape outputShape; bool flag = FITKOCCDefeatureTool::Defeature(m_solidCmdId, m_faceVirtualIds, outputShape); if (!flag) { printLog(tr("Invalid feature !"), 3); return false; } // 更新形状。 _occShapeAgent->updateShape(outputShape); return true; } //@} // 移除倒圆。 //@{ FITKOCCModelRemoveFilletSolid::FITKOCCModelRemoveFilletSolid() : OCCShapeAgent(this) { _shapeAgent = _occShapeAgent; } bool FITKOCCModelRemoveFilletSolid::update() { // 移除特征。 TopoDS_Shape outputShape; bool flag = FITKOCCDefeatureTool::Defeature(m_solidCmdId, m_faceVirtualIds, outputShape); if (!flag) { printLog(tr("Invalid feature !"), 3); return false; } // 更新形状。 _occShapeAgent->updateShape(outputShape); return true; } //@} // 填补孔洞。 //@{ FITKOCCModelFillHoleSolid::FITKOCCModelFillHoleSolid() : OCCShapeAgent(this) { _shapeAgent = _occShapeAgent; } bool FITKOCCModelFillHoleSolid::update() { // 移除特征。 TopoDS_Shape outputShape; bool flag = FITKOCCDefeatureTool::Defeature(m_solidCmdId, m_faceVirtualIds, outputShape); if (!flag) { printLog(tr("Invalid feature !"), 3); return false; } // 更新形状。 _occShapeAgent->updateShape(outputShape); return true; } //@} }