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_Fillet2dDriver.hxx>
24 #include <GEOMImpl_IFillet2d.hxx>
25 #include <GEOMImpl_Types.hxx>
26 #include <GEOMImpl_ILocalOperations.hxx>
27 #include <GEOM_Function.hxx>
29 #include <BRepFilletAPI_MakeFillet2d.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 <ShapeFix_ShapeTolerance.hxx>
40 #include <ShapeFix_Shape.hxx>
42 #include <Precision.hxx>
44 #include <StdFail_NotDone.hxx>
46 //=======================================================================
49 //=======================================================================
50 const Standard_GUID& GEOMImpl_Fillet2dDriver::GetID()
52 static Standard_GUID aFillet2dDriver("FF1AAB41-2A14-4df2-581B-3A568163BA46");
53 return aFillet2dDriver;
57 //=======================================================================
58 //function : GEOMImpl_Fillet2dDriver
60 //=======================================================================
61 GEOMImpl_Fillet2dDriver::GEOMImpl_Fillet2dDriver()
65 //=======================================================================
68 //=======================================================================
69 Standard_Integer GEOMImpl_Fillet2dDriver::Execute(TFunction_Logbook& log) const
71 if (Label().IsNull()) return 0;
72 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
74 GEOMImpl_IFillet2d aCI (aFunction);
78 Handle(GEOM_Function) aRefShape = aCI.GetShape();
79 TopoDS_Face aFaceShape = TopoDS::Face(aRefShape->GetValue());
81 if (aFaceShape.ShapeType() != TopAbs_FACE)
82 Standard_ConstructionError::Raise("Wrong arguments: two faces must be given");
84 BRepFilletAPI_MakeFillet2d fillet2d (aFaceShape);
86 int aLen = aCI.GetLength();
88 double rad = aCI.GetR();
89 for (; ind <= aLen; ind++) {
90 TopoDS_Shape aShapeVertex;
91 if (GEOMImpl_ILocalOperations::GetSubShape
92 (aFaceShape, aCI.GetVertex(ind), aShapeVertex)) {
93 fillet2d.AddFillet(TopoDS::Vertex(aShapeVertex), rad);
98 if (!fillet2d.IsDone()) {
99 StdFail_NotDone::Raise("2D Fillet can't be computed on the given shape with the given radius");
101 aShape = fillet2d.Shape();
103 if (aShape.IsNull()) return 0;
105 aFunction->SetValue(aShape);
106 log.SetTouched(Label());
112 //=======================================================================
113 //function : GEOMImpl_Fillet2dDriver_Type_
115 //=======================================================================
116 Standard_EXPORT Handle_Standard_Type& GEOMImpl_Fillet2dDriver_Type_()
119 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
120 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
121 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
122 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
123 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
124 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
127 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
128 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_Fillet2dDriver",
129 sizeof(GEOMImpl_Fillet2dDriver),
131 (Standard_Address)_Ancestors,
132 (Standard_Address)NULL);
137 //=======================================================================
138 //function : DownCast
140 //=======================================================================
141 const Handle(GEOMImpl_Fillet2dDriver) Handle(GEOMImpl_Fillet2dDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
143 Handle(GEOMImpl_Fillet2dDriver) _anOtherObject;
145 if (!AnObject.IsNull()) {
146 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_Fillet2dDriver))) {
147 _anOtherObject = Handle(GEOMImpl_Fillet2dDriver)((Handle(GEOMImpl_Fillet2dDriver)&)AnObject);
151 return _anOtherObject ;