3 #include "GEOMImpl_RevolutionDriver.hxx"
4 #include "GEOMImpl_IRevolution.hxx"
5 #include "GEOMImpl_Types.hxx"
6 #include "GEOM_Function.hxx"
8 #include <BRepPrimAPI_MakeRevol.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_RevolutionDriver::GetID()
29 static Standard_GUID aRevolutionDriver("FF1BBB18-5D14-4df2-980B-3A668264EA16");
30 return aRevolutionDriver;
34 //=======================================================================
35 //function : GEOMImpl_RevolutionDriver
37 //=======================================================================
38 GEOMImpl_RevolutionDriver::GEOMImpl_RevolutionDriver()
42 //=======================================================================
45 //=======================================================================
46 Standard_Integer GEOMImpl_RevolutionDriver::Execute(TFunction_Logbook& log) const
48 if (Label().IsNull()) return 0;
49 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
51 GEOMImpl_IRevolution aCI (aFunction);
52 Standard_Integer aType = aFunction->GetType();
56 if (aType == REVOLUTION_BASE_AXIS_ANGLE) {
57 Handle(GEOM_Function) aRefBase = aCI.GetBase();
58 Handle(GEOM_Function) aRefAxis = aCI.GetAxis();
59 TopoDS_Shape aShapeBase = aRefBase->GetValue();
60 TopoDS_Shape aShapeAxis = aRefAxis->GetValue();
61 if (aShapeAxis.ShapeType() != TopAbs_EDGE) {
62 Standard_TypeMismatch::Raise("Revolution Axis must be an edge");
65 TopoDS_Edge anE = TopoDS::Edge(aShapeAxis);
67 TopExp::Vertices(anE, V1, V2, Standard_True);
68 if (V1.IsNull() || V2.IsNull()) {
69 Standard_ConstructionError::Raise("Bad edge for the Revolution Axis given");
72 gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
73 if (aV.Magnitude() < Precision::Confusion()) {
74 Standard_ConstructionError::Raise
75 ("End vertices of edge, defining the Revolution Axis, are too close");
78 gp_Ax1 anAxis (BRep_Tool::Pnt(V1), aV);
79 BRepPrimAPI_MakeRevol MR (aShapeBase, anAxis, aCI.GetAngle(), Standard_False);
80 if (!MR.IsDone()) MR.Build();
81 if (!MR.IsDone()) StdFail_NotDone::Raise("Revolution algorithm has failed");
86 if (aShape.IsNull()) return 0;
87 aFunction->SetValue(aShape);
89 log.SetTouched(Label());
95 //=======================================================================
96 //function : GEOMImpl_RevolutionDriver_Type_
98 //=======================================================================
99 Standard_EXPORT Handle_Standard_Type& GEOMImpl_RevolutionDriver_Type_()
102 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
103 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
104 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
105 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
106 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
107 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
110 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
111 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_RevolutionDriver",
112 sizeof(GEOMImpl_RevolutionDriver),
114 (Standard_Address)_Ancestors,
115 (Standard_Address)NULL);
120 //=======================================================================
121 //function : DownCast
123 //=======================================================================
124 const Handle(GEOMImpl_RevolutionDriver) Handle(GEOMImpl_RevolutionDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
126 Handle(GEOMImpl_RevolutionDriver) _anOtherObject;
128 if (!AnObject.IsNull()) {
129 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_RevolutionDriver))) {
130 _anOtherObject = Handle(GEOMImpl_RevolutionDriver)((Handle(GEOMImpl_RevolutionDriver)&)AnObject);
134 return _anOtherObject ;