0031668: Visualization - WebGL sample doesn't work on Emscripten 1.39
[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 {
60   myBuilder.Add(Dis, E);
61 }
62
63
64 //=======================================================================
65 //function : SetDist
66 //purpose  : 
67 //=======================================================================
68
69 void BRepFilletAPI_MakeChamfer::SetDist(const Standard_Real Dis, 
70                                   const Standard_Integer IC,
71                                   const TopoDS_Face &F)
72 {
73   myBuilder.SetDist(Dis, IC, F);
74 }
75
76 //=======================================================================
77 //function : GetDist
78 //purpose  : 
79 //================================================================
80
81 void BRepFilletAPI_MakeChamfer::GetDist(const Standard_Integer IC,
82                                   Standard_Real&         Dis) const
83 {
84   myBuilder.GetDist(IC, Dis);
85
86 }
87
88 //=======================================================================
89 //function : Add
90 //purpose  : 
91 //=======================================================================
92
93 void BRepFilletAPI_MakeChamfer::Add(const Standard_Real Dis1, 
94                               const Standard_Real Dis2,
95                               const TopoDS_Edge &E,
96                               const TopoDS_Face &F)
97 {
98   myBuilder.Add(Dis1,Dis2,E,F);
99 }
100
101
102 //=======================================================================
103 //function : SetDists
104 //purpose  : 
105 //=======================================================================
106
107 void BRepFilletAPI_MakeChamfer::SetDists(const Standard_Real Dis1, 
108                                    const Standard_Real Dis2,
109                                    const Standard_Integer IC,
110                                    const TopoDS_Face &F)
111 {
112   myBuilder.SetDists(Dis1,Dis2,IC,F);
113 }
114
115 //=======================================================================
116 //function : Dists
117 //purpose  : 
118 //================================================================
119
120 void BRepFilletAPI_MakeChamfer::Dists(const Standard_Integer IC,
121                                 Standard_Real&         Dis1, 
122                                 Standard_Real&         Dis2) const
123 {
124   Standard_Real temp1, temp2;
125   myBuilder.Dists(IC,temp1,temp2);
126   Dis1 = temp1;
127   Dis2 = temp2;
128
129 }
130
131
132 //=======================================================================
133 //function : Add
134 //purpose  : 
135 //=======================================================================
136
137 void BRepFilletAPI_MakeChamfer::AddDA(const Standard_Real Dis, 
138                                 const Standard_Real Angle,
139                                 const TopoDS_Edge &E,
140                                 const TopoDS_Face &F)
141 {
142   myBuilder.AddDA(Dis, Angle, E, F);
143 }
144
145 //=======================================================================
146 //function : SetDist
147 //purpose  : 
148 //=======================================================================
149
150 void BRepFilletAPI_MakeChamfer::SetDistAngle(const Standard_Real Dis, 
151                                        const Standard_Real Angle,
152                                        const Standard_Integer IC,
153                                        const TopoDS_Face &F)
154 {
155   myBuilder.SetDistAngle(Dis, Angle, IC, F);
156 }
157
158 //=======================================================================
159 //function : GetDistAngle
160 //purpose  : 
161 //================================================================
162
163 void BRepFilletAPI_MakeChamfer::GetDistAngle(const Standard_Integer IC,
164                                              Standard_Real&         Dis, 
165                                              Standard_Real&         Angle) const
166 {
167   myBuilder.GetDistAngle(IC, Dis, Angle);
168 }
169
170 //=======================================================================
171 //function : SetMode
172 //purpose  : 
173 //=======================================================================
174
175 void BRepFilletAPI_MakeChamfer::SetMode(const ChFiDS_ChamfMode theMode)
176 {
177   myBuilder.SetMode(theMode);
178 }
179
180 //=======================================================================
181 //function : IsSymetric
182 //purpose  : 
183 //===============================================================
184
185 Standard_Boolean BRepFilletAPI_MakeChamfer::IsSymetric(const Standard_Integer IC) const
186 {
187   ChFiDS_ChamfMethod ChamfMeth =  myBuilder.IsChamfer(IC);
188   Standard_Boolean ret = Standard_False;
189
190   if (ChamfMeth == ChFiDS_Sym) ret = Standard_True;
191
192   return ret;
193 }
194
195
196 //=======================================================================
197 //function : IsTwoDistances
198 //purpose  : 
199 //===============================================================
200
201 Standard_Boolean BRepFilletAPI_MakeChamfer::IsTwoDistances(const Standard_Integer IC) const
202 {
203   ChFiDS_ChamfMethod ChamfMeth =  myBuilder.IsChamfer(IC);
204   Standard_Boolean ret = Standard_False;
205
206   if (ChamfMeth == ChFiDS_TwoDist) ret = Standard_True;
207
208   return ret;
209 }
210
211
212
213 //=======================================================================
214 //function : IsDistanceAngle
215 //purpose  : 
216 //===============================================================
217
218 Standard_Boolean BRepFilletAPI_MakeChamfer::IsDistanceAngle(const Standard_Integer IC) const
219 {
220   ChFiDS_ChamfMethod ChamfMeth =  myBuilder.IsChamfer(IC);
221   Standard_Boolean ret = Standard_False;
222
223   if (ChamfMeth == ChFiDS_DistAngle) ret = Standard_True;
224
225   return ret;
226 }
227
228
229
230 //=======================================================================
231 //function : ResetContour
232 //purpose  : 
233 //===============================================================
234
235 void BRepFilletAPI_MakeChamfer::ResetContour(const Standard_Integer IC)
236 {
237   myBuilder.ResetContour(IC);
238 }
239
240
241 //=======================================================================
242 //function : NbContours
243 //purpose  : 
244 //=======================================================================
245
246 Standard_Integer BRepFilletAPI_MakeChamfer::NbContours()const
247 {
248   return myBuilder.NbElements();
249 }
250
251
252
253 //=======================================================================
254 //function : Contour
255 //purpose  : 
256 //=======================================================================
257
258 Standard_Integer BRepFilletAPI_MakeChamfer::Contour(const TopoDS_Edge &E)const
259 {
260   return myBuilder.Contains(E);
261 }
262
263
264
265 //=======================================================================
266 //function : NbEdges
267 //purpose  : 
268 //=======================================================================
269
270 Standard_Integer BRepFilletAPI_MakeChamfer::NbEdges(const Standard_Integer I)const
271
272 {
273   const Handle(ChFiDS_Spine)& Spine = myBuilder.Value(I);
274   return (Spine->NbEdges());
275 }
276
277
278 //=======================================================================
279 //function : Edge
280 //purpose  : 
281 //=======================================================================
282
283 const TopoDS_Edge& BRepFilletAPI_MakeChamfer::Edge(const Standard_Integer I,
284                                              const Standard_Integer J)const
285 {
286   const Handle(ChFiDS_Spine)& Spine = myBuilder.Value(I);
287   const TopoDS_Edge& E = Spine->Edges(J);
288   return E;
289 }
290
291 //=======================================================================
292 //function : Remove
293 //purpose  : 
294 //=======================================================================
295
296 void BRepFilletAPI_MakeChamfer::Remove(const TopoDS_Edge& E)
297 {
298   myBuilder.Remove(E);
299 }
300
301 //=======================================================================
302 //function : Length
303 //purpose  : 
304 //=======================================================================
305
306 Standard_Real BRepFilletAPI_MakeChamfer::Length(const Standard_Integer IC)const
307 {
308   return myBuilder.Length(IC);
309 }
310
311 //=======================================================================
312 //function : FirstVertex
313 //purpose  : 
314 //=======================================================================
315
316 TopoDS_Vertex BRepFilletAPI_MakeChamfer::FirstVertex(const Standard_Integer IC)const
317 {
318   return myBuilder.FirstVertex(IC);
319 }
320
321
322 //=======================================================================
323 //function : LastVertex
324 //purpose  : 
325 //=======================================================================
326
327 TopoDS_Vertex BRepFilletAPI_MakeChamfer::LastVertex(const Standard_Integer IC)const
328 {
329   return myBuilder.LastVertex(IC);
330 }
331
332
333 //=======================================================================
334 //function : Abscissa
335 //purpose  : 
336 //=======================================================================
337
338 Standard_Real BRepFilletAPI_MakeChamfer::Abscissa(const Standard_Integer IC,
339                                            const TopoDS_Vertex& V)const
340 {
341   return myBuilder.Abscissa(IC,V);
342 }
343
344
345 //=======================================================================
346 //function : RelativeAbscissa
347 //purpose  : 
348 //=======================================================================
349
350 Standard_Real BRepFilletAPI_MakeChamfer::RelativeAbscissa(const Standard_Integer IC,
351                                                    const TopoDS_Vertex& V)const
352 {
353   return myBuilder.RelativeAbscissa(IC,V);
354 }
355
356 //=======================================================================
357 //function : ClosedAndTangent
358 //purpose  : 
359 //=======================================================================
360
361 Standard_Boolean BRepFilletAPI_MakeChamfer::ClosedAndTangent
362 (const Standard_Integer IC)const
363 {
364   return myBuilder.ClosedAndTangent(IC);
365 }
366
367
368 //=======================================================================
369 //function : Closed
370 //purpose  : 
371 //=======================================================================
372
373 Standard_Boolean BRepFilletAPI_MakeChamfer::Closed
374 (const Standard_Integer IC)const
375 {
376   return myBuilder.Closed(IC);
377 }
378
379 //=======================================================================
380 //function : Builder
381 //purpose  : 
382 //=======================================================================
383
384 Handle(TopOpeBRepBuild_HBuilder) BRepFilletAPI_MakeChamfer::Builder()const 
385 {
386   return myBuilder.Builder();
387 }
388
389 //=======================================================================
390 //function : Build
391 //purpose  : 
392 //=======================================================================
393
394 void BRepFilletAPI_MakeChamfer::Build()
395 {
396   myBuilder.Compute();
397   if (myBuilder.IsDone()){
398     Done();
399     myShape = myBuilder.Shape();
400       
401       //creation of the Map.
402     TopExp_Explorer ex;
403     for (ex.Init(myShape, TopAbs_FACE); ex.More(); ex.Next()) {
404       myMap.Add(ex.Current());
405     }
406   }
407 }
408
409 //=======================================================================
410 //function : Reset
411 //purpose  : 
412 //=======================================================================
413
414 void BRepFilletAPI_MakeChamfer::Reset()
415 {
416   NotDone();
417   myBuilder.Reset();
418   myMap.Clear();
419 }
420
421 //=======================================================================
422 //function : Generated
423 //purpose  : 
424 //=======================================================================
425
426 const TopTools_ListOfShape& BRepFilletAPI_MakeChamfer::Generated
427   (const TopoDS_Shape& EorV)
428 {
429   return myBuilder.Generated(EorV);
430 }
431
432 //=======================================================================
433 //function : Modified
434 //purpose  : 
435 //=======================================================================
436
437 const TopTools_ListOfShape& BRepFilletAPI_MakeChamfer::Modified
438   (const TopoDS_Shape& F)
439 {
440   myGenerated.Clear();
441
442   if (myBuilder.Builder()->IsSplit(F, TopAbs_OUT)) {
443     TopTools_ListIteratorOfListOfShape It(myBuilder.Builder()->Splits(F, TopAbs_OUT));
444     for(;It.More();It.Next()) {
445       myGenerated.Append(It.Value());
446     }
447   }
448   if (myBuilder.Builder()->IsSplit(F, TopAbs_IN)) {
449     TopTools_ListIteratorOfListOfShape It(myBuilder.Builder()->Splits(F, TopAbs_IN));
450     for(;It.More();It.Next()) {
451       myGenerated.Append(It.Value());
452     }
453   }
454   if (myBuilder.Builder()->IsSplit(F, TopAbs_ON)) {
455     TopTools_ListIteratorOfListOfShape It(myBuilder.Builder()->Splits(F, TopAbs_ON));
456     for(;It.More();It.Next()) {
457       myGenerated.Append(It.Value());
458     }
459   }
460   return myGenerated;
461 }
462
463 //=======================================================================
464 //function : IsDeleted
465 //purpose  : 
466 //=======================================================================
467
468 Standard_Boolean BRepFilletAPI_MakeChamfer::IsDeleted(const TopoDS_Shape& F) 
469 {
470   if (myMap.Contains(F) || 
471       myBuilder.Builder()->IsSplit (F, TopAbs_OUT)  ||
472       myBuilder.Builder()->IsSplit (F, TopAbs_IN)   ||
473       myBuilder.Builder()->IsSplit (F, TopAbs_ON))
474     return Standard_False;
475   
476   return Standard_True;    
477 }
478
479 //=======================================================================
480 //function : Simulate
481 //purpose  : 
482 //=======================================================================
483
484 void BRepFilletAPI_MakeChamfer::Simulate(const Standard_Integer IC)
485 {
486   myBuilder.Simulate(IC);
487 }
488
489
490 //=======================================================================
491 //function : NbSurf
492 //purpose  : 
493 //=======================================================================
494
495 Standard_Integer  BRepFilletAPI_MakeChamfer::NbSurf(const Standard_Integer IC)const
496 {
497   return myBuilder.NbSurf(IC);
498 }
499
500
501 //=======================================================================
502 //function : Sect
503 //purpose  : 
504 //=======================================================================
505
506 Handle(ChFiDS_SecHArray1) BRepFilletAPI_MakeChamfer::Sect(const Standard_Integer IC,
507                                                     const Standard_Integer IS)const
508 {
509   return myBuilder.Sect(IC, IS);
510 }