1 // Created by: Peter KURNEV
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
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.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
16 #include <BOPTools_Set.hxx>
17 #include <BRep_Tool.hxx>
18 #include <TopExp_Explorer.hxx>
19 #include <TopoDS_Edge.hxx>
20 #include <TopoDS_Shape.hxx>
21 #include <TopTools_MapOfShape.hxx>
24 Standard_Integer NormalizedIds(const Standard_Integer aId,
25 const Standard_Integer aDiv);
27 //=======================================================================
30 //=======================================================================
31 BOPTools_Set::BOPTools_Set()
33 myAllocator(NCollection_BaseAllocator::CommonBaseAllocator()),
40 //=======================================================================
43 //=======================================================================
44 BOPTools_Set::BOPTools_Set
45 (const Handle(NCollection_BaseAllocator)& theAllocator)
47 myAllocator(theAllocator),
55 //=======================================================================
56 //function : BOPTools_Set
58 //=======================================================================
59 BOPTools_Set::BOPTools_Set (const BOPTools_Set& theOther)
60 : myAllocator(theOther.myAllocator),
61 myShape (theOther.myShape),
62 myNbShapes (theOther.myNbShapes),
63 mySum (theOther.mySum),
64 myUpper (theOther.myUpper)
66 for (TopTools_ListIteratorOfListOfShape aIt (theOther.myShapes); aIt.More(); aIt.Next())
68 const TopoDS_Shape& aShape = aIt.Value();
69 myShapes.Append (aShape);
73 //=======================================================================
76 //=======================================================================
77 BOPTools_Set::~BOPTools_Set()
81 //=======================================================================
84 //=======================================================================
85 void BOPTools_Set::Clear()
91 //=======================================================================
94 //=======================================================================
95 Standard_Integer BOPTools_Set::NbShapes()const
99 //=======================================================================
102 //=======================================================================
103 BOPTools_Set& BOPTools_Set::Assign(const BOPTools_Set& theOther)
105 TopTools_ListIteratorOfListOfShape aIt;
107 myShape=theOther.myShape;
108 myNbShapes=theOther.myNbShapes;
109 mySum=theOther.mySum;
110 myUpper=theOther.myUpper;
111 myAllocator=theOther.myAllocator;
114 aIt.Initialize(theOther.myShapes);
115 for (; aIt.More(); aIt.Next()) {
116 const TopoDS_Shape& aSx=aIt.Value();
117 myShapes.Append(aSx);
121 //=======================================================================
124 //=======================================================================
125 const TopoDS_Shape& BOPTools_Set::Shape()const
130 //=======================================================================
131 // function : HashCode
133 //=======================================================================
134 Standard_Integer BOPTools_Set::HashCode (const Standard_Integer theUpperBound) const
136 return ::HashCode (mySum, theUpperBound);
139 //=======================================================================
142 //=======================================================================
143 Standard_Boolean BOPTools_Set::IsEqual
144 (const BOPTools_Set& theOther)const
146 Standard_Boolean bRet;
150 if (theOther.myNbShapes!=myNbShapes) {
154 TopTools_MapOfShape aM1;
155 TopTools_ListIteratorOfListOfShape aIt;
157 aIt.Initialize(myShapes);
158 for (; aIt.More(); aIt.Next()) {
159 const TopoDS_Shape& aSx1=aIt.Value();
163 aIt.Initialize(theOther.myShapes);
164 for (; aIt.More(); aIt.Next()) {
165 const TopoDS_Shape& aSx2=aIt.Value();
166 if (!aM1.Contains(aSx2)) {
173 //=======================================================================
176 //=======================================================================
177 void BOPTools_Set::Add(const TopoDS_Shape& theS,
178 const TopAbs_ShapeEnum theType)
180 Standard_Integer aId, aIdN;
181 TopAbs_Orientation aOr;
182 TopExp_Explorer aExp;
189 aExp.Init(theS, theType);
190 for (; aExp.More(); aExp.Next()) {
191 const TopoDS_Shape& aSx=aExp.Current();
192 if (theType==TopAbs_EDGE) {
193 const TopoDS_Edge& aEx=*((TopoDS_Edge*)&aSx);
194 if (BRep_Tool::Degenerated(aEx)) {
199 aOr=aSx.Orientation();
200 if (aOr==TopAbs_INTERNAL) {
205 aSy.Orientation(TopAbs_FORWARD);
206 myShapes.Append(aSy);
208 aSy.Orientation(TopAbs_REVERSED);
209 myShapes.Append(aSy);
212 myShapes.Append(aSx);
216 myNbShapes=myShapes.Extent();
221 TopTools_ListIteratorOfListOfShape aIt;
223 aIt.Initialize(myShapes);
224 for (; aIt.More(); aIt.Next()) {
225 const TopoDS_Shape& aSx=aIt.Value();
226 aId=aSx.HashCode(myUpper);
227 aIdN=NormalizedIds(aId, myNbShapes);
231 //=======================================================================
232 // function: NormalizedIds
234 //=======================================================================
235 Standard_Integer NormalizedIds(const Standard_Integer aId,
236 const Standard_Integer aDiv)
238 Standard_Integer aMax, aTresh, aIdRet;
241 aMax=::IntegerLast();