Salome HOME
0020230: Memory performance improvement.
[modules/geom.git] / src / GEOMImpl / GEOMImpl_Fillet2dDriver.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_Fillet2dDriver.hxx>
24 #include <GEOMImpl_IFillet2d.hxx>
25 #include <GEOMImpl_Types.hxx>
26 #include <GEOMImpl_ILocalOperations.hxx>
27 #include <GEOM_Function.hxx>
28
29 #include <BRepFilletAPI_MakeFillet2d.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 <ShapeFix_ShapeTolerance.hxx>
40 #include <ShapeFix_Shape.hxx>
41
42 #include <Precision.hxx>
43 #include <gp_Pnt.hxx>
44 #include <StdFail_NotDone.hxx>
45
46 //=======================================================================
47 //function : GetID
48 //purpose  :
49 //=======================================================================
50 const Standard_GUID& GEOMImpl_Fillet2dDriver::GetID()
51 {
52   static Standard_GUID aFillet2dDriver("FF1AAB41-2A14-4df2-581B-3A568163BA46");
53   return aFillet2dDriver;
54 }
55
56
57 //=======================================================================
58 //function : GEOMImpl_Fillet2dDriver
59 //purpose  :
60 //=======================================================================
61 GEOMImpl_Fillet2dDriver::GEOMImpl_Fillet2dDriver()
62 {
63 }
64
65 //=======================================================================
66 //function : Execute
67 //purpose  :
68 //=======================================================================
69 Standard_Integer GEOMImpl_Fillet2dDriver::Execute(TFunction_Logbook& log) const
70 {
71   if (Label().IsNull()) return 0;
72   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
73
74   GEOMImpl_IFillet2d aCI (aFunction);
75
76   TopoDS_Shape aShape;
77
78   Handle(GEOM_Function) aRefShape = aCI.GetShape();
79   TopoDS_Face aFaceShape = TopoDS::Face(aRefShape->GetValue());
80
81   if (aFaceShape.ShapeType() != TopAbs_FACE)
82     Standard_ConstructionError::Raise("Wrong arguments: two faces must be given");
83
84   BRepFilletAPI_MakeFillet2d fillet2d (aFaceShape);
85
86   int aLen = aCI.GetLength();
87   int ind = 1;
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);
94     }
95   }
96
97   fillet2d.Build();
98   if (!fillet2d.IsDone()) {
99     StdFail_NotDone::Raise("2D Fillet can't be computed on the given shape with the given radius");
100   }
101   aShape = fillet2d.Shape();
102
103   if (aShape.IsNull()) return 0;
104
105   aFunction->SetValue(aShape);
106   log.SetTouched(Label());
107
108   return 1;
109 }
110
111
112 //=======================================================================
113 //function :  GEOMImpl_Fillet2dDriver_Type_
114 //purpose  :
115 //=======================================================================
116 Standard_EXPORT Handle_Standard_Type& GEOMImpl_Fillet2dDriver_Type_()
117 {
118
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);
125
126
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),
130                                                          1,
131                                                          (Standard_Address)_Ancestors,
132                                                          (Standard_Address)NULL);
133
134   return _aType;
135 }
136
137 //=======================================================================
138 //function : DownCast
139 //purpose  :
140 //=======================================================================
141 const Handle(GEOMImpl_Fillet2dDriver) Handle(GEOMImpl_Fillet2dDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
142 {
143   Handle(GEOMImpl_Fillet2dDriver) _anOtherObject;
144
145   if (!AnObject.IsNull()) {
146      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_Fillet2dDriver))) {
147        _anOtherObject = Handle(GEOMImpl_Fillet2dDriver)((Handle(GEOMImpl_Fillet2dDriver)&)AnObject);
148      }
149   }
150
151   return _anOtherObject ;
152 }