0025880: fuzzy booleans with multiple tools
[occt.git] / src / BOPTools / BOPTools_EdgeSet.lxx
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 <TopExp_Explorer.hxx>
16 #include <TopoDS_Edge.hxx>
17 #include <BRep_Tool.hxx>
18
19 //=======================================================================
20 //function : 
21 //purpose  : 
22 //=======================================================================
23   inline BOPTools_EdgeSet::BOPTools_EdgeSet()
24 {
25 }
26 //=======================================================================
27 //function : 
28 //purpose  : 
29 //=======================================================================
30   inline BOPTools_EdgeSet::BOPTools_EdgeSet(const Handle(NCollection_BaseAllocator)& theObj)
31 :
32   myMap(100, theObj),
33   myEdges(theObj)
34 {
35 }
36 //=======================================================================
37 //function : ~
38 //purpose  : 
39 //=======================================================================
40   inline BOPTools_EdgeSet::~BOPTools_EdgeSet()
41 {
42 }
43 //=======================================================================
44 //function : Clear
45 //purpose  : 
46 //=======================================================================
47   inline void BOPTools_EdgeSet::Clear()
48 {
49   myMap.Clear();
50   myEdges.Clear();
51 }
52 //=======================================================================
53 //function : SetShape
54 //purpose  : 
55 //=======================================================================
56   inline void BOPTools_EdgeSet::SetShape(const TopoDS_Shape& theShape)
57 {
58   myShape=theShape;
59 }
60 //=======================================================================
61 //function : Shape
62 //purpose  : 
63 //=======================================================================
64   inline const TopoDS_Shape& BOPTools_EdgeSet::Shape()const
65 {
66   return myShape;
67 }
68 //=======================================================================
69 //function : AddEdge
70 //purpose  : 
71 //=======================================================================
72   inline void BOPTools_EdgeSet::AddEdge(const TopoDS_Edge& theEdge)
73 {
74   if (!BRep_Tool::Degenerated(theEdge)){
75     myEdges.Append(theEdge);
76     myMap.Add(theEdge);
77   }
78 }
79 //=======================================================================
80 //function : AddEdges
81 //purpose  : 
82 //=======================================================================
83   inline void BOPTools_EdgeSet::AddEdges(const BOPCol_ListOfShape& theLS)
84 {
85   BOPCol_ListIteratorOfListOfShape aIt;
86   //
87   aIt.Initialize(theLS);
88   for (; aIt.More(); aIt.Next()) {
89     const TopoDS_Edge& aE=(*(TopoDS_Edge*)&aIt.Value());
90     AddEdge(aE);
91   }
92 }
93 //=======================================================================
94 //function : AddEdges
95 //purpose  : 
96 //=======================================================================
97   inline void BOPTools_EdgeSet::AddEdges(const TopoDS_Shape& theFace)
98 {
99   TopExp_Explorer aExp(theFace, TopAbs_EDGE);
100   for(; aExp.More(); aExp.Next()) {
101     const TopoDS_Edge& aE=(*(TopoDS_Edge*)&aExp.Current());
102     AddEdge(aE);
103   }
104 }
105 //=======================================================================
106 //function : Get 
107 //purpose  : 
108 //=======================================================================
109   inline void BOPTools_EdgeSet::Get(BOPCol_ListOfShape& theLS)const
110 {
111   BOPCol_ListIteratorOfListOfShape aIt;
112   //
113   aIt.Initialize(myEdges);
114   for (; aIt.More(); aIt.Next()) {
115     const TopoDS_Shape& aS=aIt.Value();
116     theLS.Append(aS);
117   }
118 }
119 //=======================================================================
120 //function : Contains
121 //purpose  : 
122 //=======================================================================
123   inline Standard_Boolean BOPTools_EdgeSet::Contains(const BOPTools_EdgeSet& theOther)const
124 {
125   Standard_Integer aNbEOther, aNbE;
126   Standard_Boolean bRet;
127   BOPCol_ListIteratorOfListOfShape aIt;
128   //
129   aNbE=0;
130   aNbEOther=theOther.myEdges.Extent();
131   aIt.Initialize(theOther.myEdges);
132   for (; aIt.More(); aIt.Next()) {
133     const TopoDS_Shape& aS=aIt.Value();
134     bRet=myMap.Contains(aS);
135     if (!bRet) {
136       return bRet;
137     }
138     ++aNbE;
139   }
140   bRet=(aNbE==aNbEOther);
141   //
142   return bRet;
143 }