Salome HOME
Update copyright
[modules/geom.git] / src / GEOMImpl / GEOMImpl_Fillet2dDriver.cxx
1 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include <Standard_Stream.hxx>
21
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>
27
28 #include <BRepFilletAPI_MakeFillet2d.hxx>
29 #include <BRepCheck_Analyzer.hxx>
30 #include <BRep_Tool.hxx>
31
32 #include <TopoDS.hxx>
33 #include <TopoDS_Shape.hxx>
34 #include <TopoDS_Edge.hxx>
35 #include <TopAbs.hxx>
36 #include <TopExp_Explorer.hxx>
37
38 #include <ShapeFix_ShapeTolerance.hxx>
39 #include <ShapeFix_Shape.hxx>
40
41 #include <Precision.hxx>
42 #include <gp_Pnt.hxx>
43 #include <StdFail_NotDone.hxx>
44
45 //=======================================================================
46 //function : GetID
47 //purpose  :
48 //=======================================================================
49 const Standard_GUID& GEOMImpl_Fillet2dDriver::GetID()
50 {
51   static Standard_GUID aFillet2dDriver("FF1AAB41-2A14-4df2-581B-3A568163BA46");
52   return aFillet2dDriver;
53 }
54
55
56 //=======================================================================
57 //function : GEOMImpl_Fillet2dDriver
58 //purpose  :
59 //=======================================================================
60 GEOMImpl_Fillet2dDriver::GEOMImpl_Fillet2dDriver()
61 {
62 }
63
64 //=======================================================================
65 //function : Execute
66 //purpose  :
67 //=======================================================================
68 Standard_Integer GEOMImpl_Fillet2dDriver::Execute(TFunction_Logbook& log) const
69 {
70   if (Label().IsNull()) return 0;
71   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
72
73   GEOMImpl_IFillet2d aCI (aFunction);
74
75   TopoDS_Shape aShape;
76
77   Handle(GEOM_Function) aRefShape = aCI.GetShape();
78   TopoDS_Face aFaceShape = TopoDS::Face(aRefShape->GetValue());
79
80   if (aFaceShape.ShapeType() != TopAbs_FACE)
81     Standard_ConstructionError::Raise("Wrong arguments: two faces must be given");
82
83   BRepFilletAPI_MakeFillet2d fillet2d (aFaceShape);
84
85   int aLen = aCI.GetLength();
86   int ind = 1;
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);
93     }
94   }
95
96   fillet2d.Build();
97   if (!fillet2d.IsDone()) {
98     StdFail_NotDone::Raise("2D Fillet can't be computed on the given shape with the given radius");
99   }
100   aShape = fillet2d.Shape();
101
102   if (aShape.IsNull()) return 0;
103
104   aFunction->SetValue(aShape);
105   log.SetTouched(Label());
106
107   return 1;
108 }
109
110
111 //=======================================================================
112 //function :  GEOMImpl_Fillet2dDriver_Type_
113 //purpose  :
114 //=======================================================================
115 Standard_EXPORT Handle_Standard_Type& GEOMImpl_Fillet2dDriver_Type_()
116 {
117
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);
124
125
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),
129                                                          1,
130                                                          (Standard_Address)_Ancestors,
131                                                          (Standard_Address)NULL);
132
133   return _aType;
134 }
135
136 //=======================================================================
137 //function : DownCast
138 //purpose  :
139 //=======================================================================
140 const Handle(GEOMImpl_Fillet2dDriver) Handle(GEOMImpl_Fillet2dDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
141 {
142   Handle(GEOMImpl_Fillet2dDriver) _anOtherObject;
143
144   if (!AnObject.IsNull()) {
145      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_Fillet2dDriver))) {
146        _anOtherObject = Handle(GEOMImpl_Fillet2dDriver)((Handle(GEOMImpl_Fillet2dDriver)&)AnObject);
147      }
148   }
149
150   return _anOtherObject ;
151 }