1 // Created by: Peter KURNEV
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
4 // The content of this file is subject to the Open CASCADE Technology Public
5 // License Version 6.5 (the "License"). You may not use the content of this file
6 // except in compliance with the License. Please obtain a copy of the License
7 // at http://www.opencascade.org and read it completely before using this file.
9 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 // The Original Code and all software distributed under the License is
13 // distributed on an "AS IS" basis, without warranty of any kind, and the
14 // Initial Developer hereby disclaims all such warranties, including without
15 // limitation, any warranties of merchantability, fitness for a particular
16 // purpose or non-infringement. Please see the License for the specific terms
17 // and conditions governing the rights and limitations under the License.
20 //#include <BOPTools_Set.ixx>
22 #include <TopExp_Explorer.hxx>
23 #include <BRep_Tool.hxx>
27 inline Standard_Boolean operator<(const TopoDS_Shape& theS1,
28 const TopoDS_Shape& theS2);
30 inline void SortShell(const int n, TopoDS_Shape *a);
33 inline Standard_Integer NormalizedIds(const Standard_Integer aId,
34 const Standard_Integer aDiv);
35 //=======================================================================
38 //=======================================================================
39 inline BOPTools_Set::BOPTools_Set()
41 myAllocator(NCollection_BaseAllocator::CommonBaseAllocator()),
48 //=======================================================================
51 //=======================================================================
52 inline BOPTools_Set::BOPTools_Set(const Handle(NCollection_BaseAllocator)& theAllocator)
54 myAllocator(theAllocator),
61 //=======================================================================
64 //=======================================================================
65 inline BOPTools_Set::~BOPTools_Set()
69 //=======================================================================
72 //=======================================================================
73 inline void BOPTools_Set::Clear()
79 //=======================================================================
82 //=======================================================================
83 inline Standard_Integer BOPTools_Set::NbShapes()const
87 //=======================================================================
90 //=======================================================================
91 inline BOPTools_Set& BOPTools_Set::Assign(const BOPTools_Set& theOther)
93 BOPCol_ListIteratorOfListOfShape aIt;
95 myShape=theOther.myShape;
96 myNbShapes=theOther.myNbShapes;
98 myUpper=theOther.myUpper;
99 myAllocator=theOther.myAllocator;
102 aIt.Initialize(theOther.myShapes);
103 for (; aIt.More(); aIt.Next()) {
104 const TopoDS_Shape& aSx=aIt.Value();
105 myShapes.Append(aSx);
109 //=======================================================================
112 //=======================================================================
113 inline const TopoDS_Shape& BOPTools_Set::Shape()const
117 //=======================================================================
120 //=======================================================================
121 inline void BOPTools_Set::Add(const TopoDS_Shape& theS,
122 const TopAbs_ShapeEnum theType)
124 if (theType==TopAbs_EDGE) {
129 Standard_Integer i, aNb, aId, aIdN;
130 TopoDS_Shape *pShapes;
131 TopExp_Explorer aExp;
137 aExp.Init(theS, theType);
138 for (aNb=0; aExp.More(); aExp.Next(), ++aNb) {
146 pShapes=(TopoDS_Shape *)myAllocator->Allocate(aNb*sizeof(TopoDS_Shape));
149 for (i=0; aExp.More(); aExp.Next(),++i) {
150 const TopoDS_Shape& aSx=aExp.Current();
151 new (pShapes+i) TopoDS_Shape();
155 SortShell(aNb, pShapes);
158 for (i=0; i<aNb; ++i) {
159 const TopoDS_Shape& aSx=pShapes[i];
160 myShapes.Append(aSx);
162 aId=aSx.HashCode(myUpper);
163 aIdN=NormalizedIds(aId, aNb);
167 for (i=0; i<aNb; ++i) {
168 pShapes[i].~TopoDS_Shape();
170 myAllocator->Free((Standard_Address&)pShapes);
172 //=======================================================================
173 //function : AddEdges
175 //=======================================================================
176 inline void BOPTools_Set::AddEdges(const TopoDS_Shape& theS)
178 Standard_Integer i, aNb, aId, aIdN;
179 TopoDS_Shape *pShapes;
180 TopExp_Explorer aExp;
186 aExp.Init(theS, TopAbs_EDGE);
187 for (aNb=0; aExp.More(); aExp.Next()) {
188 const TopoDS_Edge& aE=(*(TopoDS_Edge*)(&aExp.Current()));
189 if (!BRep_Tool::Degenerated(aE)) {
199 pShapes=(TopoDS_Shape *)myAllocator->Allocate(aNb*sizeof(TopoDS_Shape));
203 for (; aExp.More(); aExp.Next()) {
204 const TopoDS_Shape& aSx=aExp.Current();
205 const TopoDS_Edge& aE=(*(TopoDS_Edge*)(&aSx));
206 if (!BRep_Tool::Degenerated(aE)) {
207 new (pShapes+i) TopoDS_Shape();
213 SortShell(aNb, pShapes);
216 for (i=0; i<aNb; ++i) {
217 const TopoDS_Shape& aSx=pShapes[i];
218 myShapes.Append(aSx);
220 aId=aSx.HashCode(myUpper);
221 aIdN=NormalizedIds(aId, aNb);
225 for (i=0; i<aNb; ++i) {
226 pShapes[i].~TopoDS_Shape();
228 myAllocator->Free((Standard_Address&)pShapes);
230 //=======================================================================
233 //=======================================================================
234 inline Standard_Boolean BOPTools_Set::IsEqual(const BOPTools_Set& theOther)const
236 Standard_Boolean bRet;
240 if (theOther.myNbShapes!=myNbShapes) {
244 BOPCol_ListIteratorOfListOfShape aIt1, aIt2;
246 aIt1.Initialize(myShapes);
247 aIt2.Initialize(theOther.myShapes);
248 for (; aIt1.More()||aIt2.More(); aIt1.Next(), aIt2.Next()) {
249 const TopoDS_Shape& aSx1=aIt1.Value();
250 const TopoDS_Shape& aSx2=aIt2.Value();
251 if (aSx1.TShape().operator->() != aSx2.TShape().operator->()) {
257 //=======================================================================
258 //function : HashCode
260 //=======================================================================
261 inline Standard_Integer BOPTools_Set::HashCode(const Standard_Integer theUpper)const
263 return ::HashCode(mySum, theUpper);
265 //=======================================================================
266 // function: NormalizedIds
268 //=======================================================================
269 Standard_Integer NormalizedIds(const Standard_Integer aId,
270 const Standard_Integer aDiv)
272 Standard_Integer aMax, aTresh, aIdRet;
275 aMax=::IntegerLast();
283 //=======================================================================
284 //function : operator<
286 //=======================================================================
287 Standard_Boolean operator<(const TopoDS_Shape& theS1,
288 const TopoDS_Shape& theS2)
290 Standard_Address aAddr1, aAddr2;
292 const Handle(TopoDS_TShape)& aTS1=theS1.TShape();
293 aAddr1=aTS1.operator->();
295 const Handle(TopoDS_TShape)& aTS2=theS2.TShape();
296 aAddr2=aTS2.operator->();
298 return (aAddr1<aAddr2);
300 //=======================================================================
301 // function: SortShell
303 //=======================================================================
304 void SortShell(const int n, TopoDS_Shape *a)
306 int nd, i, j, l, d=1;
317 for (i=0; i<nd; ++i) {
326 if (j > -1) goto m30;
328 }//for (i=0; i<nd; ++i)