1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #include <Standard_Stream.hxx>
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>
29 #include <BRepFilletAPI_MakeFillet.hxx>
30 #include <BRepCheck_Analyzer.hxx>
31 #include <BRep_Tool.hxx>
34 #include <TopoDS_Shape.hxx>
35 #include <TopoDS_Edge.hxx>
37 #include <TopExp_Explorer.hxx>
39 #include <Precision.hxx>
41 #include <StdFail_NotDone.hxx>
43 //=======================================================================
46 //=======================================================================
47 const Standard_GUID& GEOMImpl_FilletDriver::GetID()
49 static Standard_GUID aFilletDriver("FF1BBB41-5D14-4df2-980B-3A668264EA16");
54 //=======================================================================
55 //function : GEOMImpl_FilletDriver
57 //=======================================================================
58 GEOMImpl_FilletDriver::GEOMImpl_FilletDriver()
62 //=======================================================================
65 //=======================================================================
66 Standard_Integer GEOMImpl_FilletDriver::Execute(TFunction_Logbook& log) const
68 if (Label().IsNull()) return 0;
69 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
71 GEOMImpl_IFillet aCI (aFunction);
72 Standard_Integer aType = aFunction->GetType();
76 Handle(GEOM_Function) aRefShape = aCI.GetShape();
77 TopoDS_Shape aShapeBase = aRefShape->GetValue();
78 BRepFilletAPI_MakeFillet fill (aShapeBase);
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());
86 } else if (aType == FILLET_SHAPE_EDGES) {
87 int aLen = aCI.GetLength();
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));
96 } else if (aType == FILLET_SHAPE_FACES) {
97 int aLen = aCI.GetLength();
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()));
112 for (int i = 1; i <= fill.NbContours(); i++) {
113 fill.SetRadius(aCI.GetR(), i, 1);
116 if (!fill.IsDone()) {
117 StdFail_NotDone::Raise("Fillet can't be computed on the given shape with the given radius");
119 aShape = fill.Shape();
121 if (aShape.IsNull()) return 0;
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");
129 aFunction->SetValue(aShape);
131 log.SetTouched(Label());
137 //=======================================================================
138 //function : GEOMImpl_FilletDriver_Type_
140 //=======================================================================
141 Standard_EXPORT Handle_Standard_Type& GEOMImpl_FilletDriver_Type_()
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);
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),
156 (Standard_Address)_Ancestors,
157 (Standard_Address)NULL);
162 //=======================================================================
163 //function : DownCast
165 //=======================================================================
166 const Handle(GEOMImpl_FilletDriver) Handle(GEOMImpl_FilletDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
168 Handle(GEOMImpl_FilletDriver) _anOtherObject;
170 if (!AnObject.IsNull()) {
171 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_FilletDriver))) {
172 _anOtherObject = Handle(GEOMImpl_FilletDriver)((Handle(GEOMImpl_FilletDriver)&)AnObject);
176 return _anOtherObject ;