0024002: Overall code and build procedure refactoring -- automatic
[occt.git] / src / BRepFilletAPI / BRepFilletAPI_MakeChamfer.cxx
1 // Created on: 1995-06-22
2 // Created by: Flore Lantheaume
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 #include <BRepFilletAPI_MakeChamfer.hxx>
19 #include <ChFiDS_Spine.hxx>
20 #include <StdFail_NotDone.hxx>
21 #include <TopExp_Explorer.hxx>
22 #include <TopoDS_Edge.hxx>
23 #include <TopoDS_Face.hxx>
24 #include <TopoDS_Shape.hxx>
25 #include <TopoDS_Vertex.hxx>
26 #include <TopOpeBRepBuild_HBuilder.hxx>
27 #include <TopOpeBRepDS_HDataStructure.hxx>
28 #include <TopTools_ListIteratorOfListOfShape.hxx>
29
30 //=======================================================================
31 //function : BRepFilletAPI_MakeChamfer
32 //purpose  : 
33 //=======================================================================
34 BRepFilletAPI_MakeChamfer::BRepFilletAPI_MakeChamfer(const TopoDS_Shape &S):myBuilder(S)
35 {
36 }
37
38
39
40 //=======================================================================
41 //function : Add
42 //purpose  : 
43 //=======================================================================
44
45 void BRepFilletAPI_MakeChamfer::Add(const TopoDS_Edge &E )
46 {
47   myBuilder.Add(E);
48 }
49
50
51
52 //=======================================================================
53 //function : Add
54 //purpose  : 
55 //=======================================================================
56
57 void BRepFilletAPI_MakeChamfer::Add(const Standard_Real Dis, 
58                               const TopoDS_Edge &E,
59                               const TopoDS_Face &F)
60 {
61   myBuilder.Add(Dis, E, F);
62 }
63
64
65 //=======================================================================
66 //function : SetDist
67 //purpose  : 
68 //=======================================================================
69
70 void BRepFilletAPI_MakeChamfer::SetDist(const Standard_Real Dis, 
71                                   const Standard_Integer IC,
72                                   const TopoDS_Face &F)
73 {
74   myBuilder.SetDist(Dis, IC, F);
75 }
76
77 //=======================================================================
78 //function : GetDist
79 //purpose  : 
80 //================================================================
81
82 void BRepFilletAPI_MakeChamfer::GetDist(const Standard_Integer IC,
83                                   Standard_Real&         Dis) const
84 {
85   myBuilder.GetDist(IC, Dis);
86
87 }
88
89 //=======================================================================
90 //function : Add
91 //purpose  : 
92 //=======================================================================
93
94 void BRepFilletAPI_MakeChamfer::Add(const Standard_Real Dis1, 
95                               const Standard_Real Dis2,
96                               const TopoDS_Edge &E,
97                               const TopoDS_Face &F)
98 {
99   myBuilder.Add(Dis1,Dis2,E,F);
100 }
101
102
103 //=======================================================================
104 //function : SetDists
105 //purpose  : 
106 //=======================================================================
107
108 void BRepFilletAPI_MakeChamfer::SetDists(const Standard_Real Dis1, 
109                                    const Standard_Real Dis2,
110                                    const Standard_Integer IC,
111                                    const TopoDS_Face &F)
112 {
113   myBuilder.SetDists(Dis1,Dis2,IC,F);
114 }
115
116 //=======================================================================
117 //function : Dists
118 //purpose  : 
119 //================================================================
120
121 void BRepFilletAPI_MakeChamfer::Dists(const Standard_Integer IC,
122                                 Standard_Real&         Dis1, 
123                                 Standard_Real&         Dis2) const
124 {
125   Standard_Real temp1, temp2;
126   myBuilder.Dists(IC,temp1,temp2);
127   Dis1 = temp1;
128   Dis2 = temp2;
129
130 }
131
132
133 //=======================================================================
134 //function : Add
135 //purpose  : 
136 //=======================================================================
137
138 void BRepFilletAPI_MakeChamfer::AddDA(const Standard_Real Dis, 
139                                 const Standard_Real Angle,
140                                 const TopoDS_Edge &E,
141                                 const TopoDS_Face &F)
142 {
143   myBuilder.AddDA(Dis, Angle, E, F);
144 }
145
146 //=======================================================================
147 //function : SetDist
148 //purpose  : 
149 //=======================================================================
150
151 void BRepFilletAPI_MakeChamfer::SetDistAngle(const Standard_Real Dis, 
152                                        const Standard_Real Angle,
153                                        const Standard_Integer IC,
154                                        const TopoDS_Face &F)
155 {
156   myBuilder.SetDistAngle(Dis, Angle, IC, F);
157 }
158
159 //=======================================================================
160 //function : GetDistAngle
161 //purpose  : 
162 //================================================================
163
164 void BRepFilletAPI_MakeChamfer::GetDistAngle(const Standard_Integer IC,
165                                        Standard_Real&         Dis, 
166                                        Standard_Real&         Angle,
167                                        Standard_Boolean&      DisOnFace1) const
168 {
169   myBuilder.GetDistAngle(IC, Dis, Angle, DisOnFace1);
170
171 }
172
173 //=======================================================================
174 //function : IsSymetric
175 //purpose  : 
176 //===============================================================
177
178 Standard_Boolean BRepFilletAPI_MakeChamfer::IsSymetric(const Standard_Integer IC) const
179 {
180   ChFiDS_ChamfMethod ChamfMeth =  myBuilder.IsChamfer(IC);
181   Standard_Boolean ret = Standard_False;
182
183   if (ChamfMeth == ChFiDS_Sym) ret = Standard_True;
184
185   return ret;
186 }
187
188
189 //=======================================================================
190 //function : IsTwoDistances
191 //purpose  : 
192 //===============================================================
193
194 Standard_Boolean BRepFilletAPI_MakeChamfer::IsTwoDistances(const Standard_Integer IC) const
195 {
196   ChFiDS_ChamfMethod ChamfMeth =  myBuilder.IsChamfer(IC);
197   Standard_Boolean ret = Standard_False;
198
199   if (ChamfMeth == ChFiDS_TwoDist) ret = Standard_True;
200
201   return ret;
202 }
203
204
205
206 //=======================================================================
207 //function : IsDistanceAngle
208 //purpose  : 
209 //===============================================================
210
211 Standard_Boolean BRepFilletAPI_MakeChamfer::IsDistanceAngle(const Standard_Integer IC) const
212 {
213   ChFiDS_ChamfMethod ChamfMeth =  myBuilder.IsChamfer(IC);
214   Standard_Boolean ret = Standard_False;
215
216   if (ChamfMeth == ChFiDS_DistAngle) ret = Standard_True;
217
218   return ret;
219 }
220
221
222
223 //=======================================================================
224 //function : ResetContour
225 //purpose  : 
226 //===============================================================
227
228 void BRepFilletAPI_MakeChamfer::ResetContour(const Standard_Integer IC)
229 {
230   myBuilder.ResetContour(IC);
231 }
232
233
234 //=======================================================================
235 //function : NbContours
236 //purpose  : 
237 //=======================================================================
238
239 Standard_Integer BRepFilletAPI_MakeChamfer::NbContours()const
240 {
241   return myBuilder.NbElements();
242 }
243
244
245
246 //=======================================================================
247 //function : Contour
248 //purpose  : 
249 //=======================================================================
250
251 Standard_Integer BRepFilletAPI_MakeChamfer::Contour(const TopoDS_Edge &E)const
252 {
253   return myBuilder.Contains(E);
254 }
255
256
257
258 //=======================================================================
259 //function : NbEdges
260 //purpose  : 
261 //=======================================================================
262
263 Standard_Integer BRepFilletAPI_MakeChamfer::NbEdges(const Standard_Integer I)const
264
265 {
266   const Handle(ChFiDS_Spine)& Spine = myBuilder.Value(I);
267   return (Spine->NbEdges());
268 }
269
270
271 //=======================================================================
272 //function : Edge
273 //purpose  : 
274 //=======================================================================
275
276 const TopoDS_Edge& BRepFilletAPI_MakeChamfer::Edge(const Standard_Integer I,
277                                              const Standard_Integer J)const
278 {
279   const Handle(ChFiDS_Spine)& Spine = myBuilder.Value(I);
280   const TopoDS_Edge& E = Spine->Edges(J);
281   return E;
282 }
283
284 //=======================================================================
285 //function : Remove
286 //purpose  : 
287 //=======================================================================
288
289 void BRepFilletAPI_MakeChamfer::Remove(const TopoDS_Edge& E)
290 {
291   myBuilder.Remove(E);
292 }
293
294 //=======================================================================
295 //function : Length
296 //purpose  : 
297 //=======================================================================
298
299 Standard_Real BRepFilletAPI_MakeChamfer::Length(const Standard_Integer IC)const
300 {
301   return myBuilder.Length(IC);
302 }
303
304 //=======================================================================
305 //function : FirstVertex
306 //purpose  : 
307 //=======================================================================
308
309 TopoDS_Vertex BRepFilletAPI_MakeChamfer::FirstVertex(const Standard_Integer IC)const
310 {
311   return myBuilder.FirstVertex(IC);
312 }
313
314
315 //=======================================================================
316 //function : LastVertex
317 //purpose  : 
318 //=======================================================================
319
320 TopoDS_Vertex BRepFilletAPI_MakeChamfer::LastVertex(const Standard_Integer IC)const
321 {
322   return myBuilder.LastVertex(IC);
323 }
324
325
326 //=======================================================================
327 //function : Abscissa
328 //purpose  : 
329 //=======================================================================
330
331 Standard_Real BRepFilletAPI_MakeChamfer::Abscissa(const Standard_Integer IC,
332                                            const TopoDS_Vertex& V)const
333 {
334   return myBuilder.Abscissa(IC,V);
335 }
336
337
338 //=======================================================================
339 //function : RelativeAbscissa
340 //purpose  : 
341 //=======================================================================
342
343 Standard_Real BRepFilletAPI_MakeChamfer::RelativeAbscissa(const Standard_Integer IC,
344                                                    const TopoDS_Vertex& V)const
345 {
346   return myBuilder.RelativeAbscissa(IC,V);
347 }
348
349 //=======================================================================
350 //function : ClosedAndTangent
351 //purpose  : 
352 //=======================================================================
353
354 Standard_Boolean BRepFilletAPI_MakeChamfer::ClosedAndTangent
355 (const Standard_Integer IC)const
356 {
357   return myBuilder.ClosedAndTangent(IC);
358 }
359
360
361 //=======================================================================
362 //function : Closed
363 //purpose  : 
364 //=======================================================================
365
366 Standard_Boolean BRepFilletAPI_MakeChamfer::Closed
367 (const Standard_Integer IC)const
368 {
369   return myBuilder.Closed(IC);
370 }
371
372 //=======================================================================
373 //function : Builder
374 //purpose  : 
375 //=======================================================================
376
377 Handle(TopOpeBRepBuild_HBuilder) BRepFilletAPI_MakeChamfer::Builder()const 
378 {
379   return myBuilder.Builder();
380 }
381
382 //=======================================================================
383 //function : Build
384 //purpose  : 
385 //=======================================================================
386
387 void BRepFilletAPI_MakeChamfer::Build()
388 {
389   myBuilder.Compute();
390   if (myBuilder.IsDone()){
391     Done();
392     myShape = myBuilder.Shape();
393       
394       //creation of the Map.
395     TopExp_Explorer ex;
396     for (ex.Init(myShape, TopAbs_FACE); ex.More(); ex.Next()) {
397       myMap.Add(ex.Current());
398     }
399   }
400 }
401
402 //=======================================================================
403 //function : Reset
404 //purpose  : 
405 //=======================================================================
406
407 void BRepFilletAPI_MakeChamfer::Reset()
408 {
409   NotDone();
410   myBuilder.Reset();
411   myMap.Clear();
412 }
413
414 //=======================================================================
415 //function : Generated
416 //purpose  : 
417 //=======================================================================
418
419 const TopTools_ListOfShape& BRepFilletAPI_MakeChamfer::Generated
420   (const TopoDS_Shape& EorV)
421 {
422   return myBuilder.Generated(EorV);
423 }
424
425 //=======================================================================
426 //function : Modified
427 //purpose  : 
428 //=======================================================================
429
430 const TopTools_ListOfShape& BRepFilletAPI_MakeChamfer::Modified
431   (const TopoDS_Shape& F)
432 {
433   myGenerated.Clear();
434
435   if (myBuilder.Builder()->IsSplit(F, TopAbs_OUT)) {
436     TopTools_ListIteratorOfListOfShape It(myBuilder.Builder()->Splits(F, TopAbs_OUT));
437     for(;It.More();It.Next()) {
438       myGenerated.Append(It.Value());
439     }
440   }
441   if (myBuilder.Builder()->IsSplit(F, TopAbs_IN)) {
442     TopTools_ListIteratorOfListOfShape It(myBuilder.Builder()->Splits(F, TopAbs_IN));
443     for(;It.More();It.Next()) {
444       myGenerated.Append(It.Value());
445     }
446   }
447   if (myBuilder.Builder()->IsSplit(F, TopAbs_ON)) {
448     TopTools_ListIteratorOfListOfShape It(myBuilder.Builder()->Splits(F, TopAbs_ON));
449     for(;It.More();It.Next()) {
450       myGenerated.Append(It.Value());
451     }
452   }
453   return myGenerated;
454 }
455
456 //=======================================================================
457 //function : IsDeleted
458 //purpose  : 
459 //=======================================================================
460
461 Standard_Boolean BRepFilletAPI_MakeChamfer::IsDeleted(const TopoDS_Shape& F) 
462 {
463   if (myMap.Contains(F) || 
464       myBuilder.Builder()->IsSplit (F, TopAbs_OUT)  ||
465       myBuilder.Builder()->IsSplit (F, TopAbs_IN)   ||
466       myBuilder.Builder()->IsSplit (F, TopAbs_ON))
467     return Standard_False;
468   
469   return Standard_True;    
470 }
471
472 //=======================================================================
473 //function : Simulate
474 //purpose  : 
475 //=======================================================================
476
477 void BRepFilletAPI_MakeChamfer::Simulate(const Standard_Integer IC)
478 {
479   myBuilder.Simulate(IC);
480 }
481
482
483 //=======================================================================
484 //function : NbSurf
485 //purpose  : 
486 //=======================================================================
487
488 Standard_Integer  BRepFilletAPI_MakeChamfer::NbSurf(const Standard_Integer IC)const
489 {
490   return myBuilder.NbSurf(IC);
491 }
492
493
494 //=======================================================================
495 //function : Sect
496 //purpose  : 
497 //=======================================================================
498
499 Handle(ChFiDS_SecHArray1) BRepFilletAPI_MakeChamfer::Sect(const Standard_Integer IC,
500                                                     const Standard_Integer IS)const
501 {
502   return myBuilder.Sect(IC, IS);
503 }