Salome HOME
Merge with version on tag OCC-V2_1_0d
[modules/geom.git] / src / GEOMImpl / GEOMImpl_RevolutionDriver.cxx
1
2 using namespace std;
3 #include "GEOMImpl_RevolutionDriver.hxx"
4 #include "GEOMImpl_IRevolution.hxx"
5 #include "GEOMImpl_Types.hxx"
6 #include "GEOM_Function.hxx"
7
8 #include <BRepPrimAPI_MakeRevol.hxx>
9 #include <BRep_Tool.hxx>
10 #include <TopoDS.hxx>
11 #include <TopoDS_Shape.hxx>
12 #include <TopoDS_Edge.hxx>
13 #include <TopoDS_Vertex.hxx>
14 #include <TopAbs.hxx>
15 #include <TopExp.hxx>
16
17 #include <gp_Pnt.hxx>
18 #include <Precision.hxx>
19 #include <StdFail_NotDone.hxx>
20 #include <Standard_TypeMismatch.hxx>
21 #include <Standard_ConstructionError.hxx>
22
23 //=======================================================================
24 //function : GetID
25 //purpose  :
26 //======================================================================= 
27 const Standard_GUID& GEOMImpl_RevolutionDriver::GetID()
28 {
29   static Standard_GUID aRevolutionDriver("FF1BBB18-5D14-4df2-980B-3A668264EA16");
30   return aRevolutionDriver; 
31 }
32
33
34 //=======================================================================
35 //function : GEOMImpl_RevolutionDriver
36 //purpose  : 
37 //=======================================================================
38 GEOMImpl_RevolutionDriver::GEOMImpl_RevolutionDriver() 
39 {
40 }
41
42 //=======================================================================
43 //function : Execute
44 //purpose  :
45 //======================================================================= 
46 Standard_Integer GEOMImpl_RevolutionDriver::Execute(TFunction_Logbook& log) const
47 {
48   if (Label().IsNull()) return 0;    
49   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
50
51   GEOMImpl_IRevolution aCI (aFunction);
52   Standard_Integer aType = aFunction->GetType();
53
54   TopoDS_Shape aShape;
55
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");
63     }
64
65     TopoDS_Edge anE = TopoDS::Edge(aShapeAxis);
66     TopoDS_Vertex V1, V2;
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");
70     }
71
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");
76     }
77
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");
82     aShape = MR.Shape();
83   } else {
84   }
85
86   if (aShape.IsNull()) return 0;
87   aFunction->SetValue(aShape);
88
89   log.SetTouched(Label()); 
90
91   return 1;    
92 }
93
94
95 //=======================================================================
96 //function :  GEOMImpl_RevolutionDriver_Type_
97 //purpose  :
98 //======================================================================= 
99 Standard_EXPORT Handle_Standard_Type& GEOMImpl_RevolutionDriver_Type_()
100 {
101
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);
108  
109
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),
113                                                          1,
114                                                          (Standard_Address)_Ancestors,
115                                                          (Standard_Address)NULL);
116
117   return _aType;
118 }
119
120 //=======================================================================
121 //function : DownCast
122 //purpose  :
123 //======================================================================= 
124 const Handle(GEOMImpl_RevolutionDriver) Handle(GEOMImpl_RevolutionDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
125 {
126   Handle(GEOMImpl_RevolutionDriver) _anOtherObject;
127
128   if (!AnObject.IsNull()) {
129      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_RevolutionDriver))) {
130        _anOtherObject = Handle(GEOMImpl_RevolutionDriver)((Handle(GEOMImpl_RevolutionDriver)&)AnObject);
131      }
132   }
133
134   return _anOtherObject ;
135 }