0024023: Revamp the OCCT Handle -- ambiguity
[occt.git] / src / BOPTools / BOPTools.cxx
1 // Created by: Peter KURNEV
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15 #include <BOPTools.ixx>
16 #include <TopExp_Explorer.hxx>
17 #include <BOPCol_ListOfShape.hxx>
18
19 //=======================================================================
20 //function : MapShapes
21 //purpose  : 
22 //=======================================================================
23 void BOPTools::MapShapes(const TopoDS_Shape& S,
24                          BOPCol_MapOfShape& M)
25 {
26   M.Add(S);
27   TopoDS_Iterator It(S);
28   while (It.More()) {
29     MapShapes(It.Value(),M);
30     It.Next();
31   }
32 }
33
34
35 //=======================================================================
36 //function : MapShapes
37 //purpose  : 
38 //=======================================================================
39 void BOPTools::MapShapes(const TopoDS_Shape& S,
40                          BOPCol_IndexedMapOfShape& M)
41 {
42   M.Add(S);
43   TopoDS_Iterator It(S);
44   while (It.More()) {
45     MapShapes(It.Value(),M);
46     It.Next();
47   }
48 }
49
50 //=======================================================================
51 //function : MapShapes
52 //purpose  : 
53 //=======================================================================
54 void BOPTools::MapShapes(const TopoDS_Shape& S,
55                          const TopAbs_ShapeEnum T,
56                          BOPCol_IndexedMapOfShape& M)
57 {
58   TopExp_Explorer Ex(S,T);
59   while (Ex.More()) {
60     M.Add(Ex.Current());
61     Ex.Next();
62   }
63 }
64 //=======================================================================
65 //function : MapShapesAndAncestors
66 //purpose  : 
67 //=======================================================================
68 void BOPTools::MapShapesAndAncestors
69   (const TopoDS_Shape& S, 
70    const TopAbs_ShapeEnum TS, 
71    const TopAbs_ShapeEnum TA, 
72    BOPCol_IndexedDataMapOfShapeListOfShape& aMEF)
73 {
74   TopExp_Explorer aExS, aExA;
75   //
76   // visit ancestors
77   aExA.Init(S, TA);
78   while (aExA.More()) {
79     // visit shapes
80     const TopoDS_Shape& aF = aExA.Current();
81     //
82     aExS.Init(aF, TS);
83     while (aExS.More()) {
84       const TopoDS_Shape& aE= aExS.Current();
85       if (aMEF.Contains(aE)) {
86         aMEF.ChangeFromKey(aE).Append(aF);
87       }
88       else {
89         BOPCol_ListOfShape aLS;
90         aLS.Append(aF);
91         aMEF.Add(aE, aLS);
92       }
93       aExS.Next();
94     }
95     aExA.Next();
96   }
97   //
98   // visit shapes not under ancestors
99   aExS.Init(S, TS, TA);
100   while (aExS.More()) {
101     const TopoDS_Shape& aE=aExS.Current();
102     BOPCol_ListOfShape aLS;
103     aMEF.Add(aE, aLS);
104     aExS.Next();
105   }
106 }