2 #include <Standard_Stream.hxx>
4 #include <GEOMImpl_RevolutionDriver.hxx>
5 #include <GEOMImpl_IRevolution.hxx>
6 #include <GEOMImpl_Types.hxx>
7 #include <GEOM_Function.hxx>
9 #include <BRepPrimAPI_MakeRevol.hxx>
10 #include <BRep_Tool.hxx>
12 #include <TopoDS_Shape.hxx>
13 #include <TopoDS_Edge.hxx>
14 #include <TopoDS_Vertex.hxx>
21 #include <Precision.hxx>
22 #include <StdFail_NotDone.hxx>
23 #include <Standard_TypeMismatch.hxx>
24 #include <Standard_ConstructionError.hxx>
26 //=======================================================================
29 //=======================================================================
30 const Standard_GUID& GEOMImpl_RevolutionDriver::GetID()
32 static Standard_GUID aRevolutionDriver("FF1BBB18-5D14-4df2-980B-3A668264EA16");
33 return aRevolutionDriver;
37 //=======================================================================
38 //function : GEOMImpl_RevolutionDriver
40 //=======================================================================
41 GEOMImpl_RevolutionDriver::GEOMImpl_RevolutionDriver()
45 //=======================================================================
48 //=======================================================================
49 Standard_Integer GEOMImpl_RevolutionDriver::Execute(TFunction_Logbook& log) const
51 if (Label().IsNull()) return 0;
52 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
54 GEOMImpl_IRevolution aCI (aFunction);
55 Standard_Integer aType = aFunction->GetType();
59 if (aType == REVOLUTION_BASE_AXIS_ANGLE) {
60 Handle(GEOM_Function) aRefBase = aCI.GetBase();
61 Handle(GEOM_Function) aRefAxis = aCI.GetAxis();
62 TopoDS_Shape aShapeBase = aRefBase->GetValue();
63 TopoDS_Shape aShapeAxis = aRefAxis->GetValue();
64 if (aShapeAxis.ShapeType() != TopAbs_EDGE) {
65 Standard_TypeMismatch::Raise("Revolution Axis must be an edge");
68 TopoDS_Edge anE = TopoDS::Edge(aShapeAxis);
70 TopExp::Vertices(anE, V1, V2, Standard_True);
71 if (V1.IsNull() || V2.IsNull()) {
72 Standard_ConstructionError::Raise("Bad edge for the Revolution Axis given");
75 gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
76 if (aV.Magnitude() < Precision::Confusion()) {
77 Standard_ConstructionError::Raise
78 ("End vertices of edge, defining the Revolution Axis, are too close");
81 if (aShapeBase.ShapeType() == TopAbs_VERTEX) {
82 gp_Lin aL(BRep_Tool::Pnt(V1), gp_Dir(aV));
83 Standard_Real d = aL.Distance(BRep_Tool::Pnt(TopoDS::Vertex(aShapeBase)));
84 if (d < Precision::Confusion()) {
85 Standard_ConstructionError::Raise("Vertex to be rotated is too close to Revolution Axis");
89 gp_Ax1 anAxis (BRep_Tool::Pnt(V1), aV);
90 BRepPrimAPI_MakeRevol MR (aShapeBase, anAxis, aCI.GetAngle(), Standard_False);
91 if (!MR.IsDone()) MR.Build();
92 if (!MR.IsDone()) StdFail_NotDone::Raise("Revolution algorithm has failed");
97 if (aShape.IsNull()) return 0;
98 aFunction->SetValue(aShape);
100 log.SetTouched(Label());
106 //=======================================================================
107 //function : GEOMImpl_RevolutionDriver_Type_
109 //=======================================================================
110 Standard_EXPORT Handle_Standard_Type& GEOMImpl_RevolutionDriver_Type_()
113 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
114 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
115 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
116 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
117 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
118 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
121 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
122 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_RevolutionDriver",
123 sizeof(GEOMImpl_RevolutionDriver),
125 (Standard_Address)_Ancestors,
126 (Standard_Address)NULL);
131 //=======================================================================
132 //function : DownCast
134 //=======================================================================
135 const Handle(GEOMImpl_RevolutionDriver) Handle(GEOMImpl_RevolutionDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
137 Handle(GEOMImpl_RevolutionDriver) _anOtherObject;
139 if (!AnObject.IsNull()) {
140 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_RevolutionDriver))) {
141 _anOtherObject = Handle(GEOMImpl_RevolutionDriver)((Handle(GEOMImpl_RevolutionDriver)&)AnObject);
145 return _anOtherObject ;