Salome HOME
0020598: EDF 1191 GEOM : Creation of hexa block from two faces
[modules/geom.git] / src / NMTTools / NMTTools_CommonBlock.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:        NMTTools_CommonBlock.cxx
23 // Created:     Tue Dec  9 12:23:29 2003
24 // Author:      Peter KURNEV
25 //              <pkv@irinox>
26 //
27 #include <NMTTools_CommonBlock.ixx>
28
29 #include <BOPTools_ListIteratorOfListOfPaveBlock.hxx>
30 #include <TColStd_ListIteratorOfListOfInteger.hxx>
31
32 //=======================================================================
33 // function:  NMTTools_CommonBlock::NMTTools_CommonBlock()
34 // purpose: 
35 //=======================================================================
36   NMTTools_CommonBlock::NMTTools_CommonBlock()
37 {
38 }
39 //=======================================================================
40 // function:  AddPaveBlock
41 // purpose: 
42 //=======================================================================
43   void NMTTools_CommonBlock::AddPaveBlock(const BOPTools_PaveBlock& aPB)
44 {
45   myPaveBlocks.Append(aPB);
46 }
47 //=======================================================================
48 // function:  AddFace
49 // purpose: 
50 //=======================================================================
51   void NMTTools_CommonBlock::AddFace(const Standard_Integer aF)
52 {
53   myFaces.Append(aF);
54 }
55 //=======================================================================
56 // function:  AddFaces
57 // purpose: 
58 //=======================================================================
59   void NMTTools_CommonBlock::AddFaces(const TColStd_ListOfInteger& aLF)
60 {
61   TColStd_ListIteratorOfListOfInteger aIt(aLF);
62   //
63   for (; aIt.More(); aIt.Next()) {
64     myFaces.Append(aIt.Value());
65   }
66 }
67 //=======================================================================
68 // function:  PaveBlocks
69 // purpose: 
70 //=======================================================================
71   const BOPTools_ListOfPaveBlock& NMTTools_CommonBlock::PaveBlocks()const
72 {
73   return myPaveBlocks;
74 }
75 //=======================================================================
76 // function:  Faces
77 // purpose: 
78 //=======================================================================
79   const TColStd_ListOfInteger& NMTTools_CommonBlock::Faces()const
80 {
81   return myFaces;
82 }
83 //=======================================================================
84 // function:  PaveBlock1
85 // purpose: 
86 //=======================================================================
87   const BOPTools_PaveBlock& NMTTools_CommonBlock::PaveBlock1()const
88 {
89   return myPaveBlocks.First();
90 }
91 //=======================================================================
92 // function:  PaveBlock1
93 // purpose: 
94 //=======================================================================
95    BOPTools_PaveBlock& NMTTools_CommonBlock::PaveBlock1(const Standard_Integer aIx)
96 {
97   return PaveBlockOnEdge(aIx);
98 }
99 //=======================================================================
100 // function:  PaveBlockOnEdge
101 // purpose: 
102 //=======================================================================
103    BOPTools_PaveBlock& NMTTools_CommonBlock::PaveBlockOnEdge(const Standard_Integer aIx)
104 {
105   static BOPTools_PaveBlock aPBs;
106   Standard_Integer aIOr;
107   BOPTools_ListIteratorOfListOfPaveBlock anIt(myPaveBlocks);
108   //
109   for (; anIt.More(); anIt.Next()) {
110     BOPTools_PaveBlock& aPB=anIt.Value();
111     aIOr=aPB.OriginalEdge();
112     if (aIOr==aIx){
113       return aPB;
114     }
115   }
116   return aPBs;
117 }
118 //=======================================================================
119 // function:  IsPaveBlockOnFace
120 // purpose: 
121 //=======================================================================
122   Standard_Boolean NMTTools_CommonBlock::IsPaveBlockOnFace(const Standard_Integer aIx)const
123 {
124   Standard_Boolean bFound=Standard_False;
125   Standard_Integer nF;
126   TColStd_ListIteratorOfListOfInteger anIt(myFaces);
127   //
128   for (; anIt.More(); anIt.Next()) {
129     nF=anIt.Value();
130     if (nF==aIx){
131       return !bFound;
132     }
133   }
134   return bFound;
135 }
136 //=======================================================================
137 // function:  IsPaveBlockOnEdge
138 // purpose: 
139 //=======================================================================
140   Standard_Boolean NMTTools_CommonBlock::IsPaveBlockOnEdge(const Standard_Integer aIx)const
141 {
142   Standard_Boolean bFound=Standard_False;
143   Standard_Integer aIOr;
144   BOPTools_ListIteratorOfListOfPaveBlock anIt(myPaveBlocks);
145   //
146   for (; anIt.More(); anIt.Next()) {
147     const BOPTools_PaveBlock& aPB=anIt.Value();
148     aIOr=aPB.OriginalEdge();
149     if (aIOr==aIx){
150       return !bFound;
151     }
152   }
153   return bFound;
154 }
155 //=======================================================================
156 // function:  IsEqual
157 // purpose: 
158 //=======================================================================
159   Standard_Boolean NMTTools_CommonBlock::IsEqual(const NMTTools_CommonBlock& aOther)const
160 {
161   Standard_Boolean bFound=Standard_True;
162   Standard_Integer aNb1, aNb2;
163   BOPTools_ListIteratorOfListOfPaveBlock anIt;
164   //
165   aNb1=myPaveBlocks.Extent();
166   aNb2=aOther.myPaveBlocks.Extent();
167   //
168   if (!aNb1 && !aNb2) {
169     return bFound;
170   }
171   if (!aNb1) {
172     return !bFound;
173   }
174   if (!aNb2) {
175     return !bFound;
176   }
177   //
178   const BOPTools_PaveBlock& aPB=PaveBlock1();
179   //
180   anIt.Initialize(aOther.myPaveBlocks);
181   for (; anIt.More(); anIt.Next()) {
182     const BOPTools_PaveBlock& aPBOther=anIt.Value();
183     if (aPB.IsEqual(aPBOther)){
184       return bFound;
185     }
186   }
187   return !bFound;
188 }
189 //=======================================================================
190 // function:  Contains
191 // purpose: 
192 //=======================================================================
193   Standard_Boolean NMTTools_CommonBlock::Contains(const BOPTools_PaveBlock& aPBx)const
194 {
195   Standard_Boolean bFound=Standard_False;
196   Standard_Integer aNb1;
197   BOPTools_ListIteratorOfListOfPaveBlock anIt;
198   //
199   aNb1=myPaveBlocks.Extent();
200   //
201   if (!aNb1) {
202     return bFound;
203   }
204   //
205   anIt.Initialize(myPaveBlocks);
206   for (; anIt.More(); anIt.Next()) {
207     const BOPTools_PaveBlock& aPB=anIt.Value();
208     if (aPB.IsEqual(aPBx)) {
209       return !bFound;
210     }
211   }
212   return bFound;
213 }
214 /*
215 //=======================================================================
216 // function:  SetEdge
217 // purpose: 
218 //=======================================================================
219   void NMTTools_CommonBlock::SetEdge(const Standard_Integer anEdge)
220 {
221   BOPTools_ListIteratorOfListOfPaveBlock anIt;
222   //
223   anIt.Initialize(myPaveBlocks);
224   for (; anIt.More(); anIt.Next()) {
225     BOPTools_PaveBlock& aPB=anIt.Value();
226     aPB.SetEdge(anEdge);
227   }
228 }
229 //=======================================================================
230 // function:  Edge
231 // purpose: 
232 //=======================================================================
233   Standard_Integer NMTTools_CommonBlock::Edge()const
234 {
235   Standard_Integer aNb;
236   //
237   aNb=myPaveBlocks.Extent();
238   //
239   if (!aNb) {
240     return aNb;
241   }
242   //
243   const BOPTools_PaveBlock& aPB=PaveBlock1();
244   aNb=aPB.Edge();
245   return aNb;
246 }
247 */