0025609: Clean up the duplicate classes in TKBO project
[occt.git] / src / BOPDS / BOPDS_CommonBlock.cxx
1 // Created by: Peter KURNEV
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15
16 #include <BOPDS_CommonBlock.hxx>
17 #include <BOPDS_PaveBlock.hxx>
18 #include <Standard_Type.hxx>
19
20 IMPLEMENT_STANDARD_RTTIEXT(BOPDS_CommonBlock,Standard_Transient)
21
22 //=======================================================================
23 // function:  
24 // purpose: 
25 //=======================================================================
26   BOPDS_CommonBlock::BOPDS_CommonBlock()
27 {
28 }
29 //=======================================================================
30 // function:  
31 // purpose: 
32 //=======================================================================
33   BOPDS_CommonBlock::BOPDS_CommonBlock(const Handle(NCollection_BaseAllocator)& theAllocator)
34 :
35   myPaveBlocks(theAllocator),
36   myFaces(theAllocator)
37 {
38 }
39 //=======================================================================
40 // function:  AddPaveBlock
41 // purpose: 
42 //=======================================================================
43   void BOPDS_CommonBlock::AddPaveBlock(const Handle(BOPDS_PaveBlock)& aPB)
44 {
45   if (myPaveBlocks.IsEmpty()) {
46     myPaveBlocks.Append(aPB);
47     return;
48   }
49   //
50   // Put the pave block with the minimal index of the original edge in the first place
51   if (aPB->OriginalEdge() < myPaveBlocks.First()->OriginalEdge()) {
52     myPaveBlocks.Prepend(aPB);
53   }
54   else {
55     myPaveBlocks.Append(aPB);
56   }
57 }
58 //=======================================================================
59 // function:  SetPaveBlocks
60 // purpose: 
61 //=======================================================================
62   void BOPDS_CommonBlock::SetPaveBlocks(const BOPDS_ListOfPaveBlock& aLPB)
63 {
64   myPaveBlocks.Clear();
65   BOPDS_ListIteratorOfListOfPaveBlock aIt(aLPB);
66   for (; aIt.More(); aIt.Next()) {
67     AddPaveBlock(aIt.Value());
68   }
69 }
70 //=======================================================================
71 // function:  PaveBlocks
72 // purpose: 
73 //=======================================================================
74   const BOPDS_ListOfPaveBlock& BOPDS_CommonBlock::PaveBlocks()const
75 {
76   return myPaveBlocks;
77 }
78 //=======================================================================
79 // function:  AddFace
80 // purpose: 
81 //=======================================================================
82   void BOPDS_CommonBlock::AddFace(const Standard_Integer aF)
83 {
84   myFaces.Append(aF);
85 }
86 //=======================================================================
87 // function:  AddFaces
88 // purpose: 
89 //=======================================================================
90   void BOPDS_CommonBlock::SetFaces(const TColStd_ListOfInteger& aLF)
91 {
92   myFaces=aLF;
93 }
94 //=======================================================================
95 // function:  AppendFaces
96 // purpose: 
97 //=======================================================================
98 void BOPDS_CommonBlock::AppendFaces(TColStd_ListOfInteger& aLF)
99 {
100   myFaces.Append(aLF);
101 }
102   //=======================================================================
103 // function:  Faces
104 // purpose: 
105 //=======================================================================
106   const TColStd_ListOfInteger& BOPDS_CommonBlock::Faces()const
107 {
108   return myFaces;
109 }
110 //=======================================================================
111 // function:  PaveBlock1
112 // purpose: 
113 //=======================================================================
114   const Handle(BOPDS_PaveBlock)& BOPDS_CommonBlock::PaveBlock1()const
115 {
116   return myPaveBlocks.First();
117 }
118 //=======================================================================
119 // function:  PaveBlockOnEdge
120 // purpose: 
121 //=======================================================================
122   Handle(BOPDS_PaveBlock)& BOPDS_CommonBlock::PaveBlockOnEdge(const Standard_Integer aIx)
123 {
124   static Handle(BOPDS_PaveBlock) aPBs;
125   //
126   Standard_Integer aIOr;
127   BOPDS_ListIteratorOfListOfPaveBlock anIt;
128   //
129   anIt.Initialize(myPaveBlocks);
130   for (; anIt.More(); anIt.Next()) {
131     Handle(BOPDS_PaveBlock)& aPB=anIt.ChangeValue();
132     aIOr=aPB->OriginalEdge();
133     if (aIOr==aIx){
134       return aPB;
135     }
136   }
137   return aPBs;
138 }
139 //=======================================================================
140 // function:  IsPaveBlockOnFace
141 // purpose: 
142 //=======================================================================
143   Standard_Boolean BOPDS_CommonBlock::IsPaveBlockOnFace(const Standard_Integer aIx)const
144 {
145   Standard_Boolean bFound;
146   Standard_Integer nF;
147   TColStd_ListIteratorOfListOfInteger anIt;
148   //
149   bFound=Standard_False;
150   anIt.Initialize(myFaces);
151   for (; anIt.More(); anIt.Next()) {
152     nF=anIt.Value();
153     if (nF==aIx){
154       return !bFound;
155     }
156   }
157   return bFound;
158 }
159 //=======================================================================
160 // function:  IsPaveBlockOnEdge
161 // purpose: 
162 //=======================================================================
163   Standard_Boolean BOPDS_CommonBlock::IsPaveBlockOnEdge(const Standard_Integer aIx)const
164 {
165   Standard_Boolean bFound;
166   Standard_Integer aIOr;
167   BOPDS_ListIteratorOfListOfPaveBlock anIt;
168   //
169   bFound=Standard_False;
170   anIt.Initialize(myPaveBlocks);
171   for (; anIt.More(); anIt.Next()) {
172     const Handle(BOPDS_PaveBlock)& aPB=anIt.Value();
173     aIOr=aPB->OriginalEdge();
174     if (aIOr==aIx){
175       return !bFound;
176     }
177   }
178   return bFound;
179 }
180 //=======================================================================
181 //function : SetEdge
182 //purpose  : 
183 //=======================================================================
184   void BOPDS_CommonBlock::SetEdge(const Standard_Integer theEdge)
185 {
186   BOPDS_ListIteratorOfListOfPaveBlock anIt;
187   //
188   anIt.Initialize(myPaveBlocks);
189   for (; anIt.More(); anIt.Next()) {
190     Handle(BOPDS_PaveBlock)& aPB=anIt.ChangeValue();
191     aPB->SetEdge(theEdge);
192   }
193 }
194 //=======================================================================
195 //function : Edge
196 //purpose  : 
197 //=======================================================================
198   Standard_Integer BOPDS_CommonBlock::Edge()const
199 {
200   const Handle(BOPDS_PaveBlock)& aPB1=myPaveBlocks.First();
201   if(!aPB1.IsNull()) {
202     return aPB1->Edge();
203   }
204   return -1;
205 }
206 //=======================================================================
207 // function:  Contains
208 // purpose: 
209 //=======================================================================
210   Standard_Boolean BOPDS_CommonBlock::Contains(const Handle(BOPDS_PaveBlock)& aPBx)const
211 {
212   Standard_Boolean bFound;
213   Standard_Integer aNb1;
214   BOPDS_ListIteratorOfListOfPaveBlock anIt;
215   //
216   bFound=Standard_False;
217   aNb1=myPaveBlocks.Extent();
218   //
219   if (!aNb1) {
220     return bFound;
221   }
222   //
223   anIt.Initialize(myPaveBlocks);
224   for (; anIt.More(); anIt.Next()) {
225     const Handle(BOPDS_PaveBlock)& aPB=anIt.Value();
226     if (aPB==aPBx) {
227       return !bFound;
228     }
229   }
230   return bFound;
231 }
232 //=======================================================================
233 // function:  Contains
234 // purpose: 
235 //=======================================================================
236   Standard_Boolean BOPDS_CommonBlock::Contains(const Standard_Integer theF)const
237 {
238   Standard_Boolean bFound;
239   TColStd_ListIteratorOfListOfInteger aIt;
240   //
241   bFound=Standard_False;
242   aIt.Initialize(myFaces);
243   for (; aIt.More(); aIt.Next()) {
244     if (aIt.Value()==theF) {
245       return !bFound;
246     }
247   }
248   return bFound;
249 }
250 //=======================================================================
251 // function:  Dump
252 // purpose: 
253 //=======================================================================
254   void BOPDS_CommonBlock::Dump()const
255 {
256   Standard_Integer nF;
257   TColStd_ListIteratorOfListOfInteger aIt;
258   BOPDS_ListIteratorOfListOfPaveBlock aItPB;
259   //
260   printf(" -- CB:\n");
261   aItPB.Initialize(myPaveBlocks);
262   for (; aItPB.More(); aItPB.Next()) {
263     const Handle(BOPDS_PaveBlock)& aPB=aItPB.Value();
264     aPB->Dump();
265     printf("\n");
266   }
267   //
268   if (myFaces.Extent()) {
269     printf(" Faces:");
270     aIt.Initialize(myFaces);
271     for (; aIt.More(); aIt.Next()) {
272       nF=aIt.Value();
273       printf(" %d", nF);
274     }
275     printf("\n");
276   }
277 }