void occQt::makeTorus() { gp_Ax2 anAxis; anAxis.SetLocation(gp_Pnt(0.0, 40.0, 0.0)); TopoDS_Shape aTopoTorus = BRepPrimAPI_MakeTorus(anAxis, 3.0, 1.0); Handle_AIS_Shape anAisTorus = new AIS_Shape(aTopoTorus); anAisTorus->SetColor(Quantity_NOC_YELLOW); anAxis.SetLocation(gp_Pnt(8.0, 40.0, 0.0)); TopoDS_Shape aTopoElbow = BRepPrimAPI_MakeTorus(anAxis, 3.0, 1.0, M_PI_2); Handle_AIS_Shape anAisElbow = new AIS_Shape(aTopoElbow); anAisElbow->SetColor(Quantity_NOC_THISTLE); mContext->Display(anAisTorus); mContext->Display(anAisElbow); }
//======================================================================= //function : Execute //purpose : //======================================================================= Standard_Integer GEOMImpl_TorusDriver::Execute(TFunction_Logbook& log) const { if (Label().IsNull()) return 0; Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label()); GEOMImpl_ITorus aCI (aFunction); Standard_Integer aType = aFunction->GetType(); TopoDS_Shape aShape; if (aType == TORUS_RR) { aShape = BRepPrimAPI_MakeTorus(aCI.GetRMajor(), aCI.GetRMinor()).Shape(); } else if (aType == TORUS_PNT_VEC_RR) { Handle(GEOM_Function) aRefPoint = aCI.GetCenter(); Handle(GEOM_Function) aRefVector = aCI.GetVector(); TopoDS_Shape aShapePnt = aRefPoint->GetValue(); TopoDS_Shape aShapeVec = aRefVector->GetValue(); if (aShapePnt.ShapeType() != TopAbs_VERTEX) { Standard_TypeMismatch::Raise("Torus Center must be a vertex"); } if (aShapeVec.ShapeType() != TopAbs_EDGE) { Standard_TypeMismatch::Raise("Torus Axis must be an edge"); } gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt)); TopoDS_Edge anE = TopoDS::Edge(aShapeVec); TopoDS_Vertex V1, V2; TopExp::Vertices(anE, V1, V2, Standard_True); if (V1.IsNull() || V2.IsNull()) { Standard_ConstructionError::Raise("Bad edge for the Torus Axis given"); } gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2)); if (aV.Magnitude() < Precision::Confusion()) { Standard_ConstructionError::Raise ("End vertices of edge, defining the Torus Axis, are too close"); } gp_Ax2 anAxes (aP, aV); BRepPrimAPI_MakeTorus MT (anAxes, aCI.GetRMajor(), aCI.GetRMinor()); if (!MT.IsDone()) MT.Build(); if (!MT.IsDone()) StdFail_NotDone::Raise("Torus construction algorithm has failed"); aShape = MT.Shape(); } else { } if (aShape.IsNull()) return 0; aFunction->SetValue(aShape); log.SetTouched(Label()); return 1; }