1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include <Standard_Stream.hxx>
22 #include <GEOMImpl_Fillet2dDriver.hxx>
23 #include <GEOMImpl_IFillet2d.hxx>
24 #include <GEOMImpl_Types.hxx>
25 #include <GEOMImpl_ILocalOperations.hxx>
26 #include <GEOM_Function.hxx>
28 #include <BRepFilletAPI_MakeFillet2d.hxx>
29 #include <BRepCheck_Analyzer.hxx>
30 #include <BRep_Tool.hxx>
33 #include <TopoDS_Shape.hxx>
34 #include <TopoDS_Edge.hxx>
36 #include <TopExp_Explorer.hxx>
38 #include <ShapeFix_ShapeTolerance.hxx>
39 #include <ShapeFix_Shape.hxx>
41 #include <Precision.hxx>
43 #include <StdFail_NotDone.hxx>
45 //=======================================================================
48 //=======================================================================
49 const Standard_GUID& GEOMImpl_Fillet2dDriver::GetID()
51 static Standard_GUID aFillet2dDriver("FF1AAB41-2A14-4df2-581B-3A568163BA46");
52 return aFillet2dDriver;
56 //=======================================================================
57 //function : GEOMImpl_Fillet2dDriver
59 //=======================================================================
60 GEOMImpl_Fillet2dDriver::GEOMImpl_Fillet2dDriver()
64 //=======================================================================
67 //=======================================================================
68 Standard_Integer GEOMImpl_Fillet2dDriver::Execute(TFunction_Logbook& log) const
70 if (Label().IsNull()) return 0;
71 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
73 GEOMImpl_IFillet2d aCI (aFunction);
77 Handle(GEOM_Function) aRefShape = aCI.GetShape();
78 TopoDS_Face aFaceShape = TopoDS::Face(aRefShape->GetValue());
80 if (aFaceShape.ShapeType() != TopAbs_FACE)
81 Standard_ConstructionError::Raise("Wrong arguments: two faces must be given");
83 BRepFilletAPI_MakeFillet2d fillet2d (aFaceShape);
85 int aLen = aCI.GetLength();
87 double rad = aCI.GetR();
88 for (; ind <= aLen; ind++) {
89 TopoDS_Shape aShapeVertex;
90 if (GEOMImpl_ILocalOperations::GetSubShape
91 (aFaceShape, aCI.GetVertex(ind), aShapeVertex)) {
92 fillet2d.AddFillet(TopoDS::Vertex(aShapeVertex), rad);
97 if (!fillet2d.IsDone()) {
98 StdFail_NotDone::Raise("2D Fillet can't be computed on the given shape with the given radius");
100 aShape = fillet2d.Shape();
102 if (aShape.IsNull()) return 0;
104 aFunction->SetValue(aShape);
105 log.SetTouched(Label());
111 //=======================================================================
112 //function : GEOMImpl_Fillet2dDriver_Type_
114 //=======================================================================
115 Standard_EXPORT Handle_Standard_Type& GEOMImpl_Fillet2dDriver_Type_()
118 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
119 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
120 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
121 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
122 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
123 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
126 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
127 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_Fillet2dDriver",
128 sizeof(GEOMImpl_Fillet2dDriver),
130 (Standard_Address)_Ancestors,
131 (Standard_Address)NULL);
136 //=======================================================================
137 //function : DownCast
139 //=======================================================================
140 const Handle(GEOMImpl_Fillet2dDriver) Handle(GEOMImpl_Fillet2dDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
142 Handle(GEOMImpl_Fillet2dDriver) _anOtherObject;
144 if (!AnObject.IsNull()) {
145 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_Fillet2dDriver))) {
146 _anOtherObject = Handle(GEOMImpl_Fillet2dDriver)((Handle(GEOMImpl_Fillet2dDriver)&)AnObject);
150 return _anOtherObject ;