2 #include <Standard_Stream.hxx>
4 #include <GEOMImpl_TorusDriver.hxx>
5 #include <GEOMImpl_ITorus.hxx>
6 #include <GEOMImpl_Types.hxx>
7 #include <GEOM_Function.hxx>
9 #include <BRepPrimAPI_MakeTorus.hxx>
10 #include <BRep_Tool.hxx>
12 #include <TopoDS_Shape.hxx>
13 #include <TopoDS_Edge.hxx>
14 #include <TopoDS_Vertex.hxx>
19 #include <Precision.hxx>
20 #include <StdFail_NotDone.hxx>
21 #include <Standard_TypeMismatch.hxx>
22 #include <Standard_ConstructionError.hxx>
24 //=======================================================================
27 //=======================================================================
28 const Standard_GUID& GEOMImpl_TorusDriver::GetID()
30 static Standard_GUID aTorusDriver("FF1BBB12-5D14-4df2-980B-3A668264EA16");
35 //=======================================================================
36 //function : GEOMImpl_TorusDriver
38 //=======================================================================
39 GEOMImpl_TorusDriver::GEOMImpl_TorusDriver()
43 //=======================================================================
46 //=======================================================================
47 Standard_Integer GEOMImpl_TorusDriver::Execute(TFunction_Logbook& log) const
49 if (Label().IsNull()) return 0;
50 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
52 GEOMImpl_ITorus aCI (aFunction);
53 Standard_Integer aType = aFunction->GetType();
57 if (aType == TORUS_RR) {
58 aShape = BRepPrimAPI_MakeTorus(aCI.GetRMajor(), aCI.GetRMinor()).Shape();
60 } else if (aType == TORUS_PNT_VEC_RR) {
61 Handle(GEOM_Function) aRefPoint = aCI.GetCenter();
62 Handle(GEOM_Function) aRefVector = aCI.GetVector();
63 TopoDS_Shape aShapePnt = aRefPoint->GetValue();
64 TopoDS_Shape aShapeVec = aRefVector->GetValue();
65 if (aShapePnt.ShapeType() != TopAbs_VERTEX) {
66 Standard_TypeMismatch::Raise("Torus Center must be a vertex");
68 if (aShapeVec.ShapeType() != TopAbs_EDGE) {
69 Standard_TypeMismatch::Raise("Torus Axis must be an edge");
72 gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt));
73 TopoDS_Edge anE = TopoDS::Edge(aShapeVec);
75 TopExp::Vertices(anE, V1, V2, Standard_True);
76 if (V1.IsNull() || V2.IsNull()) {
77 Standard_ConstructionError::Raise("Bad edge for the Torus Axis given");
80 gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
81 if (aV.Magnitude() < Precision::Confusion()) {
82 Standard_ConstructionError::Raise
83 ("End vertices of edge, defining the Torus Axis, are too close");
86 gp_Ax2 anAxes (aP, aV);
87 BRepPrimAPI_MakeTorus MT (anAxes, aCI.GetRMajor(), aCI.GetRMinor());
88 if (!MT.IsDone()) MT.Build();
89 if (!MT.IsDone()) StdFail_NotDone::Raise("Torus construction algorithm has failed");
94 if (aShape.IsNull()) return 0;
95 aFunction->SetValue(aShape);
97 log.SetTouched(Label());
103 //=======================================================================
104 //function : GEOMImpl_TorusDriver_Type_
106 //=======================================================================
107 Standard_EXPORT Handle_Standard_Type& GEOMImpl_TorusDriver_Type_()
110 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
111 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
112 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
113 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
114 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
115 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
118 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
119 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_TorusDriver",
120 sizeof(GEOMImpl_TorusDriver),
122 (Standard_Address)_Ancestors,
123 (Standard_Address)NULL);
128 //=======================================================================
129 //function : DownCast
131 //=======================================================================
132 const Handle(GEOMImpl_TorusDriver) Handle(GEOMImpl_TorusDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
134 Handle(GEOMImpl_TorusDriver) _anOtherObject;
136 if (!AnObject.IsNull()) {
137 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_TorusDriver))) {
138 _anOtherObject = Handle(GEOMImpl_TorusDriver)((Handle(GEOMImpl_TorusDriver)&)AnObject);
142 return _anOtherObject ;