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.
15 #include <BOPTools_Set.ixx>
16 #include <TopoDS_Shape.hxx>
17 #include <TopExp_Explorer.hxx>
18 #include <TopoDS_Edge.hxx>
19 #include <BRep_Tool.hxx>
20 #include <BOPCol_MapOfShape.hxx>
23 Standard_Integer NormalizedIds(const Standard_Integer aId,
24 const Standard_Integer aDiv);
26 //=======================================================================
29 //=======================================================================
30 BOPTools_Set::BOPTools_Set()
32 myAllocator(NCollection_BaseAllocator::CommonBaseAllocator()),
39 //=======================================================================
42 //=======================================================================
43 BOPTools_Set::BOPTools_Set
44 (const Handle(NCollection_BaseAllocator)& theAllocator)
46 myAllocator(theAllocator),
53 //=======================================================================
56 //=======================================================================
57 BOPTools_Set::~BOPTools_Set()
61 //=======================================================================
64 //=======================================================================
65 void BOPTools_Set::Clear()
71 //=======================================================================
74 //=======================================================================
75 Standard_Integer BOPTools_Set::NbShapes()const
79 //=======================================================================
82 //=======================================================================
83 BOPTools_Set& BOPTools_Set::Assign(const BOPTools_Set& theOther)
85 BOPCol_ListIteratorOfListOfShape aIt;
87 myShape=theOther.myShape;
88 myNbShapes=theOther.myNbShapes;
90 myUpper=theOther.myUpper;
91 myAllocator=theOther.myAllocator;
94 aIt.Initialize(theOther.myShapes);
95 for (; aIt.More(); aIt.Next()) {
96 const TopoDS_Shape& aSx=aIt.Value();
101 //=======================================================================
104 //=======================================================================
105 const TopoDS_Shape& BOPTools_Set::Shape()const
109 //=======================================================================
110 //function : HashCode
112 //=======================================================================
113 Standard_Integer BOPTools_Set::HashCode
114 (const Standard_Integer theUpper)const
116 return ::HashCode(mySum, theUpper);
118 //=======================================================================
121 //=======================================================================
122 Standard_Boolean BOPTools_Set::IsEqual
123 (const BOPTools_Set& theOther)const
125 Standard_Boolean bRet;
129 if (theOther.myNbShapes!=myNbShapes) {
133 BOPCol_MapOfShape aM1;
134 BOPCol_ListIteratorOfListOfShape aIt;
136 aIt.Initialize(myShapes);
137 for (; aIt.More(); aIt.Next()) {
138 const TopoDS_Shape& aSx1=aIt.Value();
142 aIt.Initialize(theOther.myShapes);
143 for (; aIt.More(); aIt.Next()) {
144 const TopoDS_Shape& aSx2=aIt.Value();
145 if (!aM1.Contains(aSx2)) {
152 //=======================================================================
155 //=======================================================================
156 void BOPTools_Set::Add(const TopoDS_Shape& theS,
157 const TopAbs_ShapeEnum theType)
159 Standard_Integer aId, aIdN;
160 TopExp_Explorer aExp;
167 aExp.Init(theS, theType);
168 for (; aExp.More(); aExp.Next()) {
169 const TopoDS_Shape& aSx=aExp.Current();
170 if (theType==TopAbs_EDGE) {
171 const TopoDS_Edge& aEx=*((TopoDS_Edge*)&aSx);
172 if (BRep_Tool::Degenerated(aEx)) {
176 myShapes.Append(aSx);
179 myNbShapes=myShapes.Extent();
184 BOPCol_ListIteratorOfListOfShape aIt;
186 aIt.Initialize(myShapes);
187 for (; aIt.More(); aIt.Next()) {
188 const TopoDS_Shape& aSx=aIt.Value();
189 aId=aSx.HashCode(myUpper);
190 aIdN=NormalizedIds(aId, myNbShapes);
194 //=======================================================================
195 // function: NormalizedIds
197 //=======================================================================
198 Standard_Integer NormalizedIds(const Standard_Integer aId,
199 const Standard_Integer aDiv)
201 Standard_Integer aMax, aTresh, aIdRet;
204 aMax=::IntegerLast();