Salome HOME
Merge branch 'OCCT780'
[modules/geom.git] / src / GEOMAlgo / GEOMAlgo_PassKeyShape.cxx
1 // Copyright (C) 2007-2024  CEA, EDF, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // File:        GEOMAlgo_PassKeyShape.cxx
24 // Created:
25 // Author:      Peter KURNEV
26 //              <pkv@irinox>
27 //
28 #include <GEOMAlgo_PassKeyShape.hxx>
29
30 #include <Basics_OCCTVersion.hxx>
31
32 #include <TopTools_ListOfShape.hxx>
33 #include <TopTools_ListIteratorOfListOfShape.hxx>
34
35
36 static
37   Standard_Integer NormalizedId(const Standard_Integer aId,
38                                 const Standard_Integer aDiv);
39 //=======================================================================
40 //function :
41 //purpose  :
42 //=======================================================================
43   GEOMAlgo_PassKeyShape::GEOMAlgo_PassKeyShape()
44 {
45   myUpper=432123;
46 }
47 //=======================================================================
48 //function :
49 //purpose  :
50 //=======================================================================
51   GEOMAlgo_PassKeyShape::GEOMAlgo_PassKeyShape(const GEOMAlgo_PassKeyShape& aOther)
52 {
53   myUpper=432123;
54   myNbIds=aOther.myNbIds;
55   mySum=aOther.mySum;
56   myMap=aOther.myMap;
57 }
58 //=======================================================================
59 //function :~
60 //purpose  :
61 //=======================================================================
62   GEOMAlgo_PassKeyShape::~GEOMAlgo_PassKeyShape()
63 {
64 }
65 //=======================================================================
66 //function :Assign
67 //purpose  :
68 //=======================================================================
69   GEOMAlgo_PassKeyShape& GEOMAlgo_PassKeyShape::Assign(const GEOMAlgo_PassKeyShape& aOther)
70 {
71   myUpper=432123;
72   myNbIds=aOther.myNbIds;
73   mySum=aOther.mySum;
74   myMap=aOther.myMap;
75   return *this;
76 }
77 //=======================================================================
78 //function :Clear
79 //purpose  :
80 //=======================================================================
81   void GEOMAlgo_PassKeyShape::Clear()
82 {
83   myNbIds=0;
84   mySum=0;
85   myMap.Clear();
86 }
87 //=======================================================================
88 //function :SetShapes
89 //purpose  :
90 //=======================================================================
91   void GEOMAlgo_PassKeyShape::SetShapes(const TopoDS_Shape& aS1)
92
93 {
94   Standard_Integer aHC;
95   //
96   Clear();
97   myNbIds=1;
98   myMap.Add(aS1);
99 #if OCC_VERSION_LARGE < 0x07080000
100   aHC=aS1.HashCode(myUpper);
101 #else
102   aHC = std::hash<TopoDS_Shape>{}(aS1);
103 #endif
104   mySum=NormalizedId(aHC, myNbIds);
105 }
106 //=======================================================================
107 //function :SetShapes
108 //purpose  :
109 //=======================================================================
110   void GEOMAlgo_PassKeyShape::SetShapes(const TopoDS_Shape& aS1,
111                                         const TopoDS_Shape& aS2)
112 {
113   TopTools_ListOfShape aLS;
114   //
115   aLS.Append(aS1);
116   aLS.Append(aS2);
117   SetShapes(aLS);
118 }
119 //=======================================================================
120 //function :SetShapes
121 //purpose  :
122 //=======================================================================
123   void GEOMAlgo_PassKeyShape::SetShapes(const TopoDS_Shape& aS1,
124                                         const TopoDS_Shape& aS2,
125                                         const TopoDS_Shape& aS3)
126 {
127   TopTools_ListOfShape aLS;
128   //
129   aLS.Append(aS1);
130   aLS.Append(aS2);
131   aLS.Append(aS3);
132   SetShapes(aLS);
133 }
134 //=======================================================================
135 //function :SetShapes
136 //purpose  :
137 //=======================================================================
138   void GEOMAlgo_PassKeyShape::SetShapes(const TopoDS_Shape& aS1,
139                                         const TopoDS_Shape& aS2,
140                                         const TopoDS_Shape& aS3,
141                                         const TopoDS_Shape& aS4)
142 {
143   TopTools_ListOfShape aLS;
144   //
145   aLS.Append(aS1);
146   aLS.Append(aS2);
147   aLS.Append(aS3);
148   aLS.Append(aS4);
149   SetShapes(aLS);
150 }
151 //=======================================================================
152 //function :SetShapes
153 //purpose  :
154 //=======================================================================
155   void GEOMAlgo_PassKeyShape::SetShapes(const TopTools_ListOfShape& aLS)
156 {
157   Standard_Integer i, aId, aIdN;
158   TopTools_ListIteratorOfListOfShape aIt;
159   //
160   Clear();
161   aIt.Initialize(aLS);
162   for (; aIt.More(); aIt.Next()) {
163     const TopoDS_Shape& aS=aIt.Value();
164     myMap.Add(aS);
165   }
166   myNbIds=myMap.Extent();
167   for(i=1; i<=myNbIds; ++i) {
168     const TopoDS_Shape& aS=myMap(i);
169 #if OCC_VERSION_LARGE < 0x07080000
170     aId=aS.HashCode(myUpper);
171 #else
172     aId = std::hash<TopoDS_Shape>{}(aS);
173 #endif
174     aIdN=NormalizedId(aId, myNbIds);
175     mySum+=aIdN;
176   }
177 }
178 //=======================================================================
179 //function :NbIds
180 //purpose  :
181 //=======================================================================
182   Standard_Integer GEOMAlgo_PassKeyShape::NbIds()const
183 {
184   return myNbIds;
185 }
186 //=======================================================================
187 //function :IsEqual
188 //purpose  :
189 //=======================================================================
190   Standard_Boolean GEOMAlgo_PassKeyShape::IsEqual(const GEOMAlgo_PassKeyShape& aOther) const
191 {
192   Standard_Boolean bRet;
193   Standard_Integer i;
194   //
195   bRet=Standard_False;
196   //
197   if (myNbIds!=aOther.myNbIds) {
198     return bRet;
199   }
200   for (i=1; i<=myNbIds; ++i) {
201     const TopoDS_Shape& aS=myMap(i);
202     if (!aOther.myMap.Contains(aS)) {
203       return bRet;
204     }
205   }
206   return !bRet;
207 }
208 #if OCC_VERSION_LARGE < 0x07080000
209 //=======================================================================
210 //function : HashCode
211 //purpose  :
212 //=======================================================================
213   Standard_Integer GEOMAlgo_PassKeyShape::HashCode(const Standard_Integer aUpper) const
214 {
215   return ::HashCode(mySum, aUpper);
216 }
217 #endif
218 //=======================================================================
219 //function : Dump
220 //purpose  :
221 //=======================================================================
222   void GEOMAlgo_PassKeyShape::Dump(const Standard_Integer)const
223 {
224 }
225 //=======================================================================
226 // function: NormalizedId
227 // purpose :
228 //=======================================================================
229 Standard_Integer NormalizedId(const Standard_Integer aId,
230                               const Standard_Integer aDiv)
231 {
232   Standard_Integer aMax, aTresh, aIdRet;
233   //
234   aIdRet=aId;
235   aMax=::IntegerLast();
236   aTresh=aMax/aDiv;
237   if (aId>aTresh) {
238     aIdRet=aId%aTresh;
239   }
240   return aIdRet;
241 }