3 #include "GEOMImpl_TorusDriver.hxx"
4 #include "GEOMImpl_ITorus.hxx"
5 #include "GEOMImpl_Types.hxx"
6 #include "GEOM_Function.hxx"
8 #include <BRepPrimAPI_MakeTorus.hxx>
9 #include <BRep_Tool.hxx>
11 #include <TopoDS_Shape.hxx>
12 #include <TopoDS_Edge.hxx>
13 #include <TopoDS_Vertex.hxx>
18 #include <Precision.hxx>
19 #include <StdFail_NotDone.hxx>
20 #include <Standard_TypeMismatch.hxx>
21 #include <Standard_ConstructionError.hxx>
23 //=======================================================================
26 //=======================================================================
27 const Standard_GUID& GEOMImpl_TorusDriver::GetID()
29 static Standard_GUID aTorusDriver("FF1BBB12-5D14-4df2-980B-3A668264EA16");
34 //=======================================================================
35 //function : GEOMImpl_TorusDriver
37 //=======================================================================
38 GEOMImpl_TorusDriver::GEOMImpl_TorusDriver()
42 //=======================================================================
45 //=======================================================================
46 Standard_Integer GEOMImpl_TorusDriver::Execute(TFunction_Logbook& log) const
48 if (Label().IsNull()) return 0;
49 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
51 GEOMImpl_ITorus aCI (aFunction);
52 Standard_Integer aType = aFunction->GetType();
56 if (aType == TORUS_RR) {
57 aShape = BRepPrimAPI_MakeTorus(aCI.GetRMajor(), aCI.GetRMinor()).Shape();
59 } else if (aType == TORUS_PNT_VEC_RR) {
60 Handle(GEOM_Function) aRefPoint = aCI.GetCenter();
61 Handle(GEOM_Function) aRefVector = aCI.GetVector();
62 TopoDS_Shape aShapePnt = aRefPoint->GetValue();
63 TopoDS_Shape aShapeVec = aRefVector->GetValue();
64 if (aShapePnt.ShapeType() != TopAbs_VERTEX) {
65 Standard_TypeMismatch::Raise("Torus Center must be a vertex");
67 if (aShapeVec.ShapeType() != TopAbs_EDGE) {
68 Standard_TypeMismatch::Raise("Torus Axis must be an edge");
71 gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt));
72 TopoDS_Edge anE = TopoDS::Edge(aShapeVec);
74 TopExp::Vertices(anE, V1, V2, Standard_True);
75 if (V1.IsNull() || V2.IsNull()) {
76 Standard_ConstructionError::Raise("Bad edge for the Torus Axis given");
79 gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
80 if (aV.Magnitude() < Precision::Confusion()) {
81 Standard_ConstructionError::Raise
82 ("End vertices of edge, defining the Torus Axis, are too close");
85 gp_Ax2 anAxes (aP, aV);
86 BRepPrimAPI_MakeTorus MT (anAxes, aCI.GetRMajor(), aCI.GetRMinor());
87 if (!MT.IsDone()) MT.Build();
88 if (!MT.IsDone()) StdFail_NotDone::Raise("Torus construction algorithm has failed");
93 if (aShape.IsNull()) return 0;
94 aFunction->SetValue(aShape);
96 log.SetTouched(Label());
102 //=======================================================================
103 //function : GEOMImpl_TorusDriver_Type_
105 //=======================================================================
106 Standard_EXPORT Handle_Standard_Type& GEOMImpl_TorusDriver_Type_()
109 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
110 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
111 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
112 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
113 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
114 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
117 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
118 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_TorusDriver",
119 sizeof(GEOMImpl_TorusDriver),
121 (Standard_Address)_Ancestors,
122 (Standard_Address)NULL);
127 //=======================================================================
128 //function : DownCast
130 //=======================================================================
131 const Handle(GEOMImpl_TorusDriver) Handle(GEOMImpl_TorusDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
133 Handle(GEOMImpl_TorusDriver) _anOtherObject;
135 if (!AnObject.IsNull()) {
136 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_TorusDriver))) {
137 _anOtherObject = Handle(GEOMImpl_TorusDriver)((Handle(GEOMImpl_TorusDriver)&)AnObject);
141 return _anOtherObject ;