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),
54 //=======================================================================
57 //=======================================================================
58 BOPTools_Set::~BOPTools_Set()
62 //=======================================================================
65 //=======================================================================
66 void BOPTools_Set::Clear()
72 //=======================================================================
75 //=======================================================================
76 Standard_Integer BOPTools_Set::NbShapes()const
80 //=======================================================================
83 //=======================================================================
84 BOPTools_Set& BOPTools_Set::Assign(const BOPTools_Set& theOther)
86 TopTools_ListIteratorOfListOfShape aIt;
88 myShape=theOther.myShape;
89 myNbShapes=theOther.myNbShapes;
91 myUpper=theOther.myUpper;
92 myAllocator=theOther.myAllocator;
95 aIt.Initialize(theOther.myShapes);
96 for (; aIt.More(); aIt.Next()) {
97 const TopoDS_Shape& aSx=aIt.Value();
102 //=======================================================================
105 //=======================================================================
106 const TopoDS_Shape& BOPTools_Set::Shape()const
111 //=======================================================================
112 // function : HashCode
114 //=======================================================================
115 Standard_Integer BOPTools_Set::HashCode (const Standard_Integer theUpperBound) const
117 return ::HashCode (mySum, theUpperBound);
120 //=======================================================================
123 //=======================================================================
124 Standard_Boolean BOPTools_Set::IsEqual
125 (const BOPTools_Set& theOther)const
127 Standard_Boolean bRet;
131 if (theOther.myNbShapes!=myNbShapes) {
135 TopTools_MapOfShape aM1;
136 TopTools_ListIteratorOfListOfShape aIt;
138 aIt.Initialize(myShapes);
139 for (; aIt.More(); aIt.Next()) {
140 const TopoDS_Shape& aSx1=aIt.Value();
144 aIt.Initialize(theOther.myShapes);
145 for (; aIt.More(); aIt.Next()) {
146 const TopoDS_Shape& aSx2=aIt.Value();
147 if (!aM1.Contains(aSx2)) {
154 //=======================================================================
157 //=======================================================================
158 void BOPTools_Set::Add(const TopoDS_Shape& theS,
159 const TopAbs_ShapeEnum theType)
161 Standard_Integer aId, aIdN;
162 TopAbs_Orientation aOr;
163 TopExp_Explorer aExp;
170 aExp.Init(theS, theType);
171 for (; aExp.More(); aExp.Next()) {
172 const TopoDS_Shape& aSx=aExp.Current();
173 if (theType==TopAbs_EDGE) {
174 const TopoDS_Edge& aEx=*((TopoDS_Edge*)&aSx);
175 if (BRep_Tool::Degenerated(aEx)) {
180 aOr=aSx.Orientation();
181 if (aOr==TopAbs_INTERNAL) {
186 aSy.Orientation(TopAbs_FORWARD);
187 myShapes.Append(aSy);
189 aSy.Orientation(TopAbs_REVERSED);
190 myShapes.Append(aSy);
193 myShapes.Append(aSx);
197 myNbShapes=myShapes.Extent();
202 TopTools_ListIteratorOfListOfShape aIt;
204 aIt.Initialize(myShapes);
205 for (; aIt.More(); aIt.Next()) {
206 const TopoDS_Shape& aSx=aIt.Value();
207 aId=aSx.HashCode(myUpper);
208 aIdN=NormalizedIds(aId, myNbShapes);
212 //=======================================================================
213 // function: NormalizedIds
215 //=======================================================================
216 Standard_Integer NormalizedIds(const Standard_Integer aId,
217 const Standard_Integer aDiv)
219 Standard_Integer aMax, aTresh, aIdRet;
222 aMax=::IntegerLast();