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>
20 #include <Precision.hxx>
21 #include <StdFail_NotDone.hxx>
22 #include <Standard_TypeMismatch.hxx>
23 #include <Standard_ConstructionError.hxx>
25 //=======================================================================
28 //=======================================================================
29 const Standard_GUID& GEOMImpl_RevolutionDriver::GetID()
31 static Standard_GUID aRevolutionDriver("FF1BBB18-5D14-4df2-980B-3A668264EA16");
32 return aRevolutionDriver;
36 //=======================================================================
37 //function : GEOMImpl_RevolutionDriver
39 //=======================================================================
40 GEOMImpl_RevolutionDriver::GEOMImpl_RevolutionDriver()
44 //=======================================================================
47 //=======================================================================
48 Standard_Integer GEOMImpl_RevolutionDriver::Execute(TFunction_Logbook& log) const
50 if (Label().IsNull()) return 0;
51 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
53 GEOMImpl_IRevolution aCI (aFunction);
54 Standard_Integer aType = aFunction->GetType();
58 if (aType == REVOLUTION_BASE_AXIS_ANGLE) {
59 Handle(GEOM_Function) aRefBase = aCI.GetBase();
60 Handle(GEOM_Function) aRefAxis = aCI.GetAxis();
61 TopoDS_Shape aShapeBase = aRefBase->GetValue();
62 TopoDS_Shape aShapeAxis = aRefAxis->GetValue();
63 if (aShapeAxis.ShapeType() != TopAbs_EDGE) {
64 Standard_TypeMismatch::Raise("Revolution Axis must be an edge");
67 TopoDS_Edge anE = TopoDS::Edge(aShapeAxis);
69 TopExp::Vertices(anE, V1, V2, Standard_True);
70 if (V1.IsNull() || V2.IsNull()) {
71 Standard_ConstructionError::Raise("Bad edge for the Revolution Axis given");
74 gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
75 if (aV.Magnitude() < Precision::Confusion()) {
76 Standard_ConstructionError::Raise
77 ("End vertices of edge, defining the Revolution Axis, are too close");
80 if (aShapeBase.ShapeType() == TopAbs_VERTEX) {
81 gp_Lin aL(BRep_Tool::Pnt(V1), gp_Dir(aV));
82 Standard_Real d = aL.Distance(BRep_Tool::Pnt(TopoDS::Vertex(aShapeBase)));
83 if (d < Precision::Confusion()) {
84 Standard_ConstructionError::Raise("Vertex to be rotated is too close to Revolution Axis");
88 gp_Ax1 anAxis (BRep_Tool::Pnt(V1), aV);
89 BRepPrimAPI_MakeRevol MR (aShapeBase, anAxis, aCI.GetAngle(), Standard_False);
90 if (!MR.IsDone()) MR.Build();
91 if (!MR.IsDone()) StdFail_NotDone::Raise("Revolution algorithm has failed");
96 if (aShape.IsNull()) return 0;
97 aFunction->SetValue(aShape);
99 log.SetTouched(Label());
105 //=======================================================================
106 //function : GEOMImpl_RevolutionDriver_Type_
108 //=======================================================================
109 Standard_EXPORT Handle_Standard_Type& GEOMImpl_RevolutionDriver_Type_()
112 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
113 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
114 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
115 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
116 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
117 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
120 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
121 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_RevolutionDriver",
122 sizeof(GEOMImpl_RevolutionDriver),
124 (Standard_Address)_Ancestors,
125 (Standard_Address)NULL);
130 //=======================================================================
131 //function : DownCast
133 //=======================================================================
134 const Handle(GEOMImpl_RevolutionDriver) Handle(GEOMImpl_RevolutionDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
136 Handle(GEOMImpl_RevolutionDriver) _anOtherObject;
138 if (!AnObject.IsNull()) {
139 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_RevolutionDriver))) {
140 _anOtherObject = Handle(GEOMImpl_RevolutionDriver)((Handle(GEOMImpl_RevolutionDriver)&)AnObject);
144 return _anOtherObject ;