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