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