Salome HOME
dcebfc6306217f3abf4cd46974238ac335ac775d
[modules/geom.git] / src / GEOMImpl / GEOMImpl_FilletDriver.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20
21 #include <Standard_Stream.hxx>
22
23 #include <GEOMImpl_FilletDriver.hxx>
24 #include <GEOMImpl_IFillet.hxx>
25 #include <GEOMImpl_Types.hxx>
26 #include <GEOMImpl_ILocalOperations.hxx>
27 #include <GEOM_Function.hxx>
28
29 #include <BRepFilletAPI_MakeFillet.hxx>
30 #include <BRepCheck_Analyzer.hxx>
31 #include <BRep_Tool.hxx>
32
33 #include <TopoDS.hxx>
34 #include <TopoDS_Shape.hxx>
35 #include <TopoDS_Edge.hxx>
36 #include <TopAbs.hxx>
37 #include <TopExp_Explorer.hxx>
38
39 #include <Precision.hxx>
40 #include <gp_Pnt.hxx>
41 #include <StdFail_NotDone.hxx>
42
43 //=======================================================================
44 //function : GetID
45 //purpose  :
46 //=======================================================================
47 const Standard_GUID& GEOMImpl_FilletDriver::GetID()
48 {
49   static Standard_GUID aFilletDriver("FF1BBB41-5D14-4df2-980B-3A668264EA16");
50   return aFilletDriver;
51 }
52
53
54 //=======================================================================
55 //function : GEOMImpl_FilletDriver
56 //purpose  :
57 //=======================================================================
58 GEOMImpl_FilletDriver::GEOMImpl_FilletDriver()
59 {
60 }
61
62 //=======================================================================
63 //function : Execute
64 //purpose  :
65 //=======================================================================
66 Standard_Integer GEOMImpl_FilletDriver::Execute(TFunction_Logbook& log) const
67 {
68   if (Label().IsNull()) return 0;
69   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
70
71   GEOMImpl_IFillet aCI (aFunction);
72   Standard_Integer aType = aFunction->GetType();
73
74   TopoDS_Shape aShape;
75
76   Handle(GEOM_Function) aRefShape = aCI.GetShape();
77   TopoDS_Shape aShapeBase = aRefShape->GetValue();
78   BRepFilletAPI_MakeFillet fill (aShapeBase);
79
80   if (aType == FILLET_SHAPE_ALL) {
81     TopExp_Explorer Exp (aShapeBase, TopAbs_EDGE);
82     for (; Exp.More(); Exp.Next()) {
83       TopoDS_Edge E = TopoDS::Edge(Exp.Current());
84       fill.Add(E);
85     }
86   } else if (aType == FILLET_SHAPE_EDGES) {
87     int aLen = aCI.GetLength();
88     int ind = 1;
89     for (; ind <= aLen; ind++) {
90       TopoDS_Shape aShapeEdge;
91       if (GEOMImpl_ILocalOperations::GetSubShape
92           (aShapeBase, aCI.GetEdge(ind), aShapeEdge)) {
93         fill.Add(TopoDS::Edge(aShapeEdge));
94       }
95     }
96   } else if (aType == FILLET_SHAPE_FACES) {
97     int aLen = aCI.GetLength();
98     int ind = 1;
99     for (; ind <= aLen; ind++) {
100       TopoDS_Shape aShapeFace;
101       if (GEOMImpl_ILocalOperations::GetSubShape
102           (aShapeBase, aCI.GetFace(ind), aShapeFace)) {
103         TopExp_Explorer Exp (aShapeFace, TopAbs_EDGE);
104         for (; Exp.More(); Exp.Next()) {
105           fill.Add(TopoDS::Edge(Exp.Current()));
106         }
107       }
108     }
109   } else {
110   }
111
112   for (int i = 1; i <= fill.NbContours(); i++) {
113     fill.SetRadius(aCI.GetR(), i, i);
114   }
115   fill.Build();
116   if (!fill.IsDone()) {
117     StdFail_NotDone::Raise("Fillet can't be computed on the given shape with the given radius");
118   }
119   aShape = fill.Shape();
120
121   if (aShape.IsNull()) return 0;
122
123   // Check shape validity
124   BRepCheck_Analyzer ana (aShape, false);
125   if (!ana.IsValid()) {
126     StdFail_NotDone::Raise("Fillet algorithm have produced an invalid shape result");
127   }
128
129   aFunction->SetValue(aShape);
130
131   log.SetTouched(Label());
132
133   return 1;
134 }
135
136
137 //=======================================================================
138 //function :  GEOMImpl_FilletDriver_Type_
139 //purpose  :
140 //=======================================================================
141 Standard_EXPORT Handle_Standard_Type& GEOMImpl_FilletDriver_Type_()
142 {
143
144   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
145   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
146   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
147   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
148   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
149   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
150
151
152   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
153   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_FilletDriver",
154                                                          sizeof(GEOMImpl_FilletDriver),
155                                                          1,
156                                                          (Standard_Address)_Ancestors,
157                                                          (Standard_Address)NULL);
158
159   return _aType;
160 }
161
162 //=======================================================================
163 //function : DownCast
164 //purpose  :
165 //=======================================================================
166 const Handle(GEOMImpl_FilletDriver) Handle(GEOMImpl_FilletDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
167 {
168   Handle(GEOMImpl_FilletDriver) _anOtherObject;
169
170   if (!AnObject.IsNull()) {
171      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_FilletDriver))) {
172        _anOtherObject = Handle(GEOMImpl_FilletDriver)((Handle(GEOMImpl_FilletDriver)&)AnObject);
173      }
174   }
175
176   return _anOtherObject ;
177 }