Salome HOME
Copyright update 2021
[modules/geom.git] / src / GEOMAlgo / GEOMAlgo_PassKeyShape.cxx
1 // Copyright (C) 2007-2021  CEA/DEN, EDF R&D, 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 <TopTools_ListOfShape.hxx>
31 #include <TopTools_ListIteratorOfListOfShape.hxx>
32
33
34 static
35   Standard_Integer NormalizedId(const Standard_Integer aId,
36                                 const Standard_Integer aDiv);
37 //=======================================================================
38 //function :
39 //purpose  :
40 //=======================================================================
41   GEOMAlgo_PassKeyShape::GEOMAlgo_PassKeyShape()
42 {
43   myUpper=432123;
44 }
45 //=======================================================================
46 //function :
47 //purpose  :
48 //=======================================================================
49   GEOMAlgo_PassKeyShape::GEOMAlgo_PassKeyShape(const GEOMAlgo_PassKeyShape& aOther)
50 {
51   myUpper=432123;
52   myNbIds=aOther.myNbIds;
53   mySum=aOther.mySum;
54   myMap=aOther.myMap;
55 }
56 //=======================================================================
57 //function :~
58 //purpose  :
59 //=======================================================================
60   GEOMAlgo_PassKeyShape::~GEOMAlgo_PassKeyShape()
61 {
62 }
63 //=======================================================================
64 //function :Assign
65 //purpose  :
66 //=======================================================================
67   GEOMAlgo_PassKeyShape& GEOMAlgo_PassKeyShape::Assign(const GEOMAlgo_PassKeyShape& aOther)
68 {
69   myUpper=432123;
70   myNbIds=aOther.myNbIds;
71   mySum=aOther.mySum;
72   myMap=aOther.myMap;
73   return *this;
74 }
75 //=======================================================================
76 //function :Clear
77 //purpose  :
78 //=======================================================================
79   void GEOMAlgo_PassKeyShape::Clear()
80 {
81   myNbIds=0;
82   mySum=0;
83   myMap.Clear();
84 }
85 //=======================================================================
86 //function :SetShapes
87 //purpose  :
88 //=======================================================================
89   void GEOMAlgo_PassKeyShape::SetShapes(const TopoDS_Shape& aS1)
90
91 {
92   Standard_Integer aHC;
93   //
94   Clear();
95   myNbIds=1;
96   myMap.Add(aS1);
97   aHC=aS1.HashCode(myUpper);
98   mySum=NormalizedId(aHC, myNbIds);
99 }
100 //=======================================================================
101 //function :SetShapes
102 //purpose  :
103 //=======================================================================
104   void GEOMAlgo_PassKeyShape::SetShapes(const TopoDS_Shape& aS1,
105                                         const TopoDS_Shape& aS2)
106 {
107   TopTools_ListOfShape aLS;
108   //
109   aLS.Append(aS1);
110   aLS.Append(aS2);
111   SetShapes(aLS);
112 }
113 //=======================================================================
114 //function :SetShapes
115 //purpose  :
116 //=======================================================================
117   void GEOMAlgo_PassKeyShape::SetShapes(const TopoDS_Shape& aS1,
118                                         const TopoDS_Shape& aS2,
119                                         const TopoDS_Shape& aS3)
120 {
121   TopTools_ListOfShape aLS;
122   //
123   aLS.Append(aS1);
124   aLS.Append(aS2);
125   aLS.Append(aS3);
126   SetShapes(aLS);
127 }
128 //=======================================================================
129 //function :SetShapes
130 //purpose  :
131 //=======================================================================
132   void GEOMAlgo_PassKeyShape::SetShapes(const TopoDS_Shape& aS1,
133                                         const TopoDS_Shape& aS2,
134                                         const TopoDS_Shape& aS3,
135                                         const TopoDS_Shape& aS4)
136 {
137   TopTools_ListOfShape aLS;
138   //
139   aLS.Append(aS1);
140   aLS.Append(aS2);
141   aLS.Append(aS3);
142   aLS.Append(aS4);
143   SetShapes(aLS);
144 }
145 //=======================================================================
146 //function :SetShapes
147 //purpose  :
148 //=======================================================================
149   void GEOMAlgo_PassKeyShape::SetShapes(const TopTools_ListOfShape& aLS)
150 {
151   Standard_Integer i, aId, aIdN;
152   TopTools_ListIteratorOfListOfShape aIt;
153   //
154   Clear();
155   aIt.Initialize(aLS);
156   for (; aIt.More(); aIt.Next()) {
157     const TopoDS_Shape& aS=aIt.Value();
158     myMap.Add(aS);
159   }
160   myNbIds=myMap.Extent();
161   for(i=1; i<=myNbIds; ++i) {
162     const TopoDS_Shape& aS=myMap(i);
163     aId=aS.HashCode(myUpper);
164     aIdN=NormalizedId(aId, myNbIds);
165     mySum+=aIdN;
166   }
167 }
168 //=======================================================================
169 //function :NbIds
170 //purpose  :
171 //=======================================================================
172   Standard_Integer GEOMAlgo_PassKeyShape::NbIds()const
173 {
174   return myNbIds;
175 }
176 //=======================================================================
177 //function :IsEqual
178 //purpose  :
179 //=======================================================================
180   Standard_Boolean GEOMAlgo_PassKeyShape::IsEqual(const GEOMAlgo_PassKeyShape& aOther) const
181 {
182   Standard_Boolean bRet;
183   Standard_Integer i;
184   //
185   bRet=Standard_False;
186   //
187   if (myNbIds!=aOther.myNbIds) {
188     return bRet;
189   }
190   for (i=1; i<=myNbIds; ++i) {
191     const TopoDS_Shape& aS=myMap(i);
192     if (!aOther.myMap.Contains(aS)) {
193       return bRet;
194     }
195   }
196   return !bRet;
197 }
198 //=======================================================================
199 //function : HashCode
200 //purpose  :
201 //=======================================================================
202   Standard_Integer GEOMAlgo_PassKeyShape::HashCode(const Standard_Integer aUpper) const
203 {
204   return ::HashCode(mySum, aUpper);
205 }
206 //=======================================================================
207 //function : Dump
208 //purpose  :
209 //=======================================================================
210   void GEOMAlgo_PassKeyShape::Dump(const Standard_Integer)const
211 {
212 }
213 //=======================================================================
214 // function: NormalizedId
215 // purpose :
216 //=======================================================================
217 Standard_Integer NormalizedId(const Standard_Integer aId,
218                               const Standard_Integer aDiv)
219 {
220   Standard_Integer aMax, aTresh, aIdRet;
221   //
222   aIdRet=aId;
223   aMax=::IntegerLast();
224   aTresh=aMax/aDiv;
225   if (aId>aTresh) {
226     aIdRet=aId%aTresh;
227   }
228   return aIdRet;
229 }