Salome HOME
Merge with version on tag OCC-V2_1_0d
[modules/geom.git] / src / GEOMImpl / GEOMImpl_FilletDriver.cxx
1
2 using namespace std;
3 #include "GEOMImpl_FilletDriver.hxx"
4 #include "GEOMImpl_IFillet.hxx"
5 #include "GEOMImpl_Types.hxx"
6 #include "GEOMImpl_ILocalOperations.hxx"
7 #include "GEOM_Function.hxx"
8
9 #include <BRepFilletAPI_MakeFillet.hxx>
10 #include <BRepCheck_Analyzer.hxx>
11 #include <BRep_Tool.hxx>
12
13 #include <TopoDS.hxx>
14 #include <TopoDS_Shape.hxx>
15 #include <TopoDS_Edge.hxx>
16 #include <TopAbs.hxx>
17 #include <TopExp_Explorer.hxx>
18
19 #include <Precision.hxx>
20 #include <gp_Pnt.hxx>
21 #include <StdFail_NotDone.hxx>
22
23 //=======================================================================
24 //function : GetID
25 //purpose  :
26 //=======================================================================
27 const Standard_GUID& GEOMImpl_FilletDriver::GetID()
28 {
29   static Standard_GUID aFilletDriver("FF1BBB41-5D14-4df2-980B-3A668264EA16");
30   return aFilletDriver;
31 }
32
33
34 //=======================================================================
35 //function : GEOMImpl_FilletDriver
36 //purpose  :
37 //=======================================================================
38 GEOMImpl_FilletDriver::GEOMImpl_FilletDriver()
39 {
40 }
41
42 //=======================================================================
43 //function : Execute
44 //purpose  :
45 //=======================================================================
46 Standard_Integer GEOMImpl_FilletDriver::Execute(TFunction_Logbook& log) const
47 {
48   if (Label().IsNull()) return 0;
49   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
50
51   GEOMImpl_IFillet aCI (aFunction);
52   Standard_Integer aType = aFunction->GetType();
53
54   TopoDS_Shape aShape;
55
56   Handle(GEOM_Function) aRefShape = aCI.GetShape();
57   TopoDS_Shape aShapeBase = aRefShape->GetValue();
58   BRepFilletAPI_MakeFillet fill (aShapeBase);
59
60   if (aType == FILLET_SHAPE_ALL) {
61     TopExp_Explorer Exp (aShapeBase, TopAbs_EDGE);
62     for (; Exp.More(); Exp.Next()) {
63       TopoDS_Edge E = TopoDS::Edge(Exp.Current());
64       fill.Add(E);
65     }
66   } else if (aType == FILLET_SHAPE_EDGES) {
67     int aLen = aCI.GetLength();
68     int ind = 1;
69     for (; ind <= aLen; ind++) {
70       TopoDS_Shape aShapeEdge;
71       if (GEOMImpl_ILocalOperations::GetSubShape
72           (aShapeBase, aCI.GetEdge(ind), aShapeEdge)) {
73         fill.Add(TopoDS::Edge(aShapeEdge));
74       }
75     }
76   } else if (aType == FILLET_SHAPE_FACES) {
77     int aLen = aCI.GetLength();
78     int ind = 1;
79     for (; ind <= aLen; ind++) {
80       TopoDS_Shape aShapeFace;
81       if (GEOMImpl_ILocalOperations::GetSubShape
82           (aShapeBase, aCI.GetFace(ind), aShapeFace)) {
83         TopExp_Explorer Exp (aShapeFace, TopAbs_EDGE);
84         for (; Exp.More(); Exp.Next()) {
85           fill.Add(TopoDS::Edge(Exp.Current()));
86         }
87       }
88     }
89   } else {
90   }
91
92   for (int i = 1; i <= fill.NbContours(); i++) {
93     fill.SetRadius(aCI.GetR(), i, i);
94   }
95   fill.Build();
96   if (!fill.IsDone()) {
97     StdFail_NotDone::Raise("Fillet can't be computed on the given shape with the given radius");
98   }
99   aShape = fill.Shape();
100
101   if (aShape.IsNull()) return 0;
102
103   // Check shape validity
104   BRepCheck_Analyzer ana (aShape, false);
105   if (!ana.IsValid()) {
106     StdFail_NotDone::Raise("Fillet algorithm have produced an invalid shape result");
107   }
108
109   aFunction->SetValue(aShape);
110
111   log.SetTouched(Label());
112
113   return 1;
114 }
115
116
117 //=======================================================================
118 //function :  GEOMImpl_FilletDriver_Type_
119 //purpose  :
120 //=======================================================================
121 Standard_EXPORT Handle_Standard_Type& GEOMImpl_FilletDriver_Type_()
122 {
123
124   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
125   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
126   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
127   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
128   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
129   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
130
131
132   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
133   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_FilletDriver",
134                                                          sizeof(GEOMImpl_FilletDriver),
135                                                          1,
136                                                          (Standard_Address)_Ancestors,
137                                                          (Standard_Address)NULL);
138
139   return _aType;
140 }
141
142 //=======================================================================
143 //function : DownCast
144 //purpose  :
145 //=======================================================================
146 const Handle(GEOMImpl_FilletDriver) Handle(GEOMImpl_FilletDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
147 {
148   Handle(GEOMImpl_FilletDriver) _anOtherObject;
149
150   if (!AnObject.IsNull()) {
151      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_FilletDriver))) {
152        _anOtherObject = Handle(GEOMImpl_FilletDriver)((Handle(GEOMImpl_FilletDriver)&)AnObject);
153      }
154   }
155
156   return _anOtherObject ;
157 }