]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMImpl/GEOMImpl_FilletDriver.cxx
Salome HOME
ENV: Windows porting.
[modules/geom.git] / src / GEOMImpl / GEOMImpl_FilletDriver.cxx
1
2 #include <Standard_Stream.hxx>
3
4 #include <GEOMImpl_FilletDriver.hxx>
5 #include <GEOMImpl_IFillet.hxx>
6 #include <GEOMImpl_Types.hxx>
7 #include <GEOMImpl_ILocalOperations.hxx>
8 #include <GEOM_Function.hxx>
9
10 #include <BRepFilletAPI_MakeFillet.hxx>
11 #include <BRepCheck_Analyzer.hxx>
12 #include <BRep_Tool.hxx>
13
14 #include <TopoDS.hxx>
15 #include <TopoDS_Shape.hxx>
16 #include <TopoDS_Edge.hxx>
17 #include <TopAbs.hxx>
18 #include <TopExp_Explorer.hxx>
19
20 #include <Precision.hxx>
21 #include <gp_Pnt.hxx>
22 #include <StdFail_NotDone.hxx>
23
24 //=======================================================================
25 //function : GetID
26 //purpose  :
27 //=======================================================================
28 const Standard_GUID& GEOMImpl_FilletDriver::GetID()
29 {
30   static Standard_GUID aFilletDriver("FF1BBB41-5D14-4df2-980B-3A668264EA16");
31   return aFilletDriver;
32 }
33
34
35 //=======================================================================
36 //function : GEOMImpl_FilletDriver
37 //purpose  :
38 //=======================================================================
39 GEOMImpl_FilletDriver::GEOMImpl_FilletDriver()
40 {
41 }
42
43 //=======================================================================
44 //function : Execute
45 //purpose  :
46 //=======================================================================
47 Standard_Integer GEOMImpl_FilletDriver::Execute(TFunction_Logbook& log) const
48 {
49   if (Label().IsNull()) return 0;
50   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
51
52   GEOMImpl_IFillet aCI (aFunction);
53   Standard_Integer aType = aFunction->GetType();
54
55   TopoDS_Shape aShape;
56
57   Handle(GEOM_Function) aRefShape = aCI.GetShape();
58   TopoDS_Shape aShapeBase = aRefShape->GetValue();
59   BRepFilletAPI_MakeFillet fill (aShapeBase);
60
61   if (aType == FILLET_SHAPE_ALL) {
62     TopExp_Explorer Exp (aShapeBase, TopAbs_EDGE);
63     for (; Exp.More(); Exp.Next()) {
64       TopoDS_Edge E = TopoDS::Edge(Exp.Current());
65       fill.Add(E);
66     }
67   } else if (aType == FILLET_SHAPE_EDGES) {
68     int aLen = aCI.GetLength();
69     int ind = 1;
70     for (; ind <= aLen; ind++) {
71       TopoDS_Shape aShapeEdge;
72       if (GEOMImpl_ILocalOperations::GetSubShape
73           (aShapeBase, aCI.GetEdge(ind), aShapeEdge)) {
74         fill.Add(TopoDS::Edge(aShapeEdge));
75       }
76     }
77   } else if (aType == FILLET_SHAPE_FACES) {
78     int aLen = aCI.GetLength();
79     int ind = 1;
80     for (; ind <= aLen; ind++) {
81       TopoDS_Shape aShapeFace;
82       if (GEOMImpl_ILocalOperations::GetSubShape
83           (aShapeBase, aCI.GetFace(ind), aShapeFace)) {
84         TopExp_Explorer Exp (aShapeFace, TopAbs_EDGE);
85         for (; Exp.More(); Exp.Next()) {
86           fill.Add(TopoDS::Edge(Exp.Current()));
87         }
88       }
89     }
90   } else {
91   }
92
93   for (int i = 1; i <= fill.NbContours(); i++) {
94     fill.SetRadius(aCI.GetR(), i, i);
95   }
96   fill.Build();
97   if (!fill.IsDone()) {
98     StdFail_NotDone::Raise("Fillet can't be computed on the given shape with the given radius");
99   }
100   aShape = fill.Shape();
101
102   if (aShape.IsNull()) return 0;
103
104   // Check shape validity
105   BRepCheck_Analyzer ana (aShape, false);
106   if (!ana.IsValid()) {
107     StdFail_NotDone::Raise("Fillet algorithm have produced an invalid shape result");
108   }
109
110   aFunction->SetValue(aShape);
111
112   log.SetTouched(Label());
113
114   return 1;
115 }
116
117
118 //=======================================================================
119 //function :  GEOMImpl_FilletDriver_Type_
120 //purpose  :
121 //=======================================================================
122 Standard_EXPORT Handle_Standard_Type& GEOMImpl_FilletDriver_Type_()
123 {
124
125   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
126   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
127   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
128   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
129   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
130   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
131
132
133   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
134   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_FilletDriver",
135                                                          sizeof(GEOMImpl_FilletDriver),
136                                                          1,
137                                                          (Standard_Address)_Ancestors,
138                                                          (Standard_Address)NULL);
139
140   return _aType;
141 }
142
143 //=======================================================================
144 //function : DownCast
145 //purpose  :
146 //=======================================================================
147 const Handle(GEOMImpl_FilletDriver) Handle(GEOMImpl_FilletDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
148 {
149   Handle(GEOMImpl_FilletDriver) _anOtherObject;
150
151   if (!AnObject.IsNull()) {
152      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_FilletDriver))) {
153        _anOtherObject = Handle(GEOMImpl_FilletDriver)((Handle(GEOMImpl_FilletDriver)&)AnObject);
154      }
155   }
156
157   return _anOtherObject ;
158 }