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