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 <BOPCol_MapOfShape.hxx>
17 #include <BOPTools_Set.hxx>
18 #include <BRep_Tool.hxx>
19 #include <TopExp_Explorer.hxx>
20 #include <TopoDS_Edge.hxx>
21 #include <TopoDS_Shape.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 BOPCol_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
110 //=======================================================================
111 //function : HashCode
113 //=======================================================================
114 Standard_Integer BOPTools_Set::HashCode
115 (const Standard_Integer theUpper)const
117 return ::HashCode(mySum, theUpper);
119 //=======================================================================
122 //=======================================================================
123 Standard_Boolean BOPTools_Set::IsEqual
124 (const BOPTools_Set& theOther)const
126 Standard_Boolean bRet;
130 if (theOther.myNbShapes!=myNbShapes) {
134 BOPCol_MapOfShape aM1;
135 BOPCol_ListIteratorOfListOfShape aIt;
137 aIt.Initialize(myShapes);
138 for (; aIt.More(); aIt.Next()) {
139 const TopoDS_Shape& aSx1=aIt.Value();
143 aIt.Initialize(theOther.myShapes);
144 for (; aIt.More(); aIt.Next()) {
145 const TopoDS_Shape& aSx2=aIt.Value();
146 if (!aM1.Contains(aSx2)) {
153 //=======================================================================
156 //=======================================================================
157 void BOPTools_Set::Add(const TopoDS_Shape& theS,
158 const TopAbs_ShapeEnum theType)
160 Standard_Integer aId, aIdN;
161 TopAbs_Orientation aOr;
162 TopExp_Explorer aExp;
169 aExp.Init(theS, theType);
170 for (; aExp.More(); aExp.Next()) {
171 const TopoDS_Shape& aSx=aExp.Current();
172 if (theType==TopAbs_EDGE) {
173 const TopoDS_Edge& aEx=*((TopoDS_Edge*)&aSx);
174 if (BRep_Tool::Degenerated(aEx)) {
179 aOr=aSx.Orientation();
180 if (aOr==TopAbs_INTERNAL) {
185 aSy.Orientation(TopAbs_FORWARD);
186 myShapes.Append(aSy);
188 aSy.Orientation(TopAbs_REVERSED);
189 myShapes.Append(aSy);
192 myShapes.Append(aSx);
196 myNbShapes=myShapes.Extent();
201 BOPCol_ListIteratorOfListOfShape aIt;
203 aIt.Initialize(myShapes);
204 for (; aIt.More(); aIt.Next()) {
205 const TopoDS_Shape& aSx=aIt.Value();
206 aId=aSx.HashCode(myUpper);
207 aIdN=NormalizedIds(aId, myNbShapes);
211 //=======================================================================
212 // function: NormalizedIds
214 //=======================================================================
215 Standard_Integer NormalizedIds(const Standard_Integer aId,
216 const Standard_Integer aDiv)
218 Standard_Integer aMax, aTresh, aIdRet;
221 aMax=::IntegerLast();