1 // Created by: Peter KURNEV
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
4 // The content of this file is subject to the Open CASCADE Technology Public
5 // License Version 6.5 (the "License"). You may not use the content of this file
6 // except in compliance with the License. Please obtain a copy of the License
7 // at http://www.opencascade.org and read it completely before using this file.
9 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 // The Original Code and all software distributed under the License is
13 // distributed on an "AS IS" basis, without warranty of any kind, and the
14 // Initial Developer hereby disclaims all such warranties, including without
15 // limitation, any warranties of merchantability, fitness for a particular
16 // purpose or non-infringement. Please see the License for the specific terms
17 // and conditions governing the rights and limitations under the License.
19 #include <BOPAlgo_Tools.ixx>
20 #include <BOPDS_DS.hxx>
21 #include <BOPDS_MapOfPaveBlock.hxx>
22 #include <BOPDS_IndexedMapOfPaveBlock.hxx>
23 #include <BOPDS_CommonBlock.hxx>
24 #include <BOPDS_DataMapOfPaveBlockListOfPaveBlock.hxx>
25 #include <BOPCol_IndexedMapOfInteger.hxx>
27 //=======================================================================
28 //function : MakeBlocksCnx
30 //=======================================================================
31 void BOPAlgo_Tools::MakeBlocksCnx(const BOPCol_IndexedDataMapOfIntegerListOfInteger& aMILI,
32 BOPCol_DataMapOfIntegerListOfInteger& aMBlocks,
33 Handle(NCollection_BaseAllocator)& aAllocator)
35 Standard_Integer aNbV, nV, aNbVS, nVP, nVx, aNbVP, aNbEC, k, i, j;
36 BOPCol_ListIteratorOfListOfInteger aItLI;
38 BOPCol_MapOfInteger aMVS(100, aAllocator);
39 BOPCol_IndexedMapOfInteger aMEC(100, aAllocator);
40 BOPCol_IndexedMapOfInteger aMVP(100, aAllocator);
41 BOPCol_IndexedMapOfInteger aMVAdd(100, aAllocator);
45 for (k=0,i=1; i<=aNbV; ++i) {
51 nV = aMILI.FindKey(i);
52 if (aMVS.Contains(nV)){
64 for (j=1; j<=aNbVP; ++j) {
66 const BOPCol_ListOfInteger& aLV=aMILI.FindFromKey(nVP);
67 aItLI.Initialize(aLV);
68 for (; aItLI.More(); aItLI.Next()) {
70 if (aMEC.Contains(nVx)) {
80 aNbVP=aMVAdd.Extent();
82 break; // from while(1)
86 for (j=1; j<=aNbVP; ++j) {
92 BOPCol_ListOfInteger aLIx(aAllocator);
94 aNbEC = aMEC.Extent();
95 for (j=1; j<=aNbEC; ++j) {
100 aMBlocks.Bind(k, aLIx);
102 }//for (k=0,i=1; i<=aNbV; ++i)
108 //=======================================================================
111 //=======================================================================
112 void BOPAlgo_Tools::FillMap(const Standard_Integer n1,
113 const Standard_Integer n2,
114 BOPCol_IndexedDataMapOfIntegerListOfInteger& aMILI,
115 Handle(NCollection_BaseAllocator)& aAllocator)
117 if (aMILI.Contains(n1)) {
118 BOPCol_ListOfInteger& aLI=aMILI.ChangeFromKey(n1);
122 BOPCol_ListOfInteger aLI(aAllocator);
126 if (aMILI.Contains(n2)) {
127 BOPCol_ListOfInteger& aLI=aMILI.ChangeFromKey(n2);
131 BOPCol_ListOfInteger aLI(aAllocator);
136 //=======================================================================
139 //=======================================================================
140 void BOPAlgo_Tools::FillMap(const Handle(BOPDS_PaveBlock)& aPB1,
141 const Handle(BOPDS_PaveBlock)& aPB2,
142 BOPDS_IndexedDataMapOfPaveBlockListOfPaveBlock& aMPBLPB,
143 Handle(NCollection_BaseAllocator)& aAllocator)
145 if (aMPBLPB.Contains(aPB1)) {
146 BOPDS_ListOfPaveBlock& aLPB=aMPBLPB.ChangeFromKey(aPB1);
150 BOPDS_ListOfPaveBlock aLPB(aAllocator);
152 aMPBLPB.Add(aPB1, aLPB);
154 if (aMPBLPB.Contains(aPB2)) {
155 BOPDS_ListOfPaveBlock& aLPB=aMPBLPB.ChangeFromKey(aPB2);
159 BOPDS_ListOfPaveBlock aLPB(aAllocator);
161 aMPBLPB.Add(aPB2, aLPB);
164 //=======================================================================
167 //=======================================================================
168 void BOPAlgo_Tools::FillMap(const Handle(BOPDS_PaveBlock)& aPB,
169 const Standard_Integer nF,
170 BOPDS_IndexedDataMapOfPaveBlockListOfInteger& aMPBLI,
171 Handle(NCollection_BaseAllocator)& aAllocator)
173 if (aMPBLI.Contains(aPB)) {
174 BOPCol_ListOfInteger& aLI=aMPBLI.ChangeFromKey(aPB);
178 BOPCol_ListOfInteger aLI(aAllocator);
180 aMPBLI.Add(aPB, aLI);
183 //=======================================================================
184 //function : MakeBlocks
186 //=======================================================================
187 void BOPAlgo_Tools::MakeBlocks(const BOPDS_IndexedDataMapOfPaveBlockListOfPaveBlock& aMILI,
188 BOPDS_DataMapOfIntegerListOfPaveBlock& aMBlocks,
189 Handle(NCollection_BaseAllocator)& aAllocator)
191 Standard_Integer aNbV, aNbVS, aNbVP, aNbEC, k, i, j;
192 BOPDS_ListIteratorOfListOfPaveBlock aItLI;
194 BOPDS_MapOfPaveBlock aMVS(100, aAllocator);
195 BOPDS_IndexedMapOfPaveBlock aMEC(100, aAllocator);
196 BOPDS_IndexedMapOfPaveBlock aMVP(100, aAllocator);
197 BOPDS_IndexedMapOfPaveBlock aMVAdd(100, aAllocator);
201 for (k=0, i=1; i<=aNbV; ++i) {
207 const Handle(BOPDS_PaveBlock)& nV=aMILI.FindKey(i);
208 if (aMVS.Contains(nV)){
220 for (j=1; j<=aNbVP; ++j) {
221 const Handle(BOPDS_PaveBlock)& nVP=aMVP(j);
222 const BOPDS_ListOfPaveBlock& aLV=aMILI.FindFromKey(nVP);
223 aItLI.Initialize(aLV);
224 for (; aItLI.More(); aItLI.Next()) {
225 const Handle(BOPDS_PaveBlock)& nVx=aItLI.Value();
226 if (aMEC.Contains(nVx)) {
236 aNbVP=aMVAdd.Extent();
238 break; // from while(1)
242 for (j=1; j<=aNbVP; ++j) {
248 BOPDS_ListOfPaveBlock aLIx(aAllocator);
250 aNbEC = aMEC.Extent();
251 for (j=1; j<=aNbEC; ++j) {
252 const Handle(BOPDS_PaveBlock)& nVx=aMEC(j);
256 aMBlocks.Bind(k, aLIx);
258 }//for (k=0, i=1; i<=aNbV; ++i)
264 //=======================================================================
265 //function : PerformCommonBlocks
267 //=======================================================================
268 void BOPAlgo_Tools::PerformCommonBlocks(BOPDS_IndexedDataMapOfPaveBlockListOfPaveBlock& aMPBLPB,
269 Handle(NCollection_BaseAllocator)& aAllocator,
272 Standard_Integer aNbCB;
274 aNbCB=aMPBLPB.Extent();
279 Standard_Integer aNbPB, aNbBlocks, k;
280 BOPDS_ListIteratorOfListOfPaveBlock aItLPB;
281 Handle(BOPDS_CommonBlock) aCB;
282 BOPDS_DataMapOfIntegerListOfPaveBlock aMBlocks(100, aAllocator);
284 BOPAlgo_Tools::MakeBlocks(aMPBLPB, aMBlocks, aAllocator);
286 aNbBlocks = aMBlocks.Extent();
287 for (k=0; k<aNbBlocks; ++k) {
288 const BOPDS_ListOfPaveBlock& aLPB=aMBlocks.Find(k);
291 aCB=new BOPDS_CommonBlock;
293 aItLPB.Initialize(aLPB);
294 for (; aItLPB.More(); aItLPB.Next()) {
295 const Handle(BOPDS_PaveBlock)& aPBx=aItLPB.Value();
296 aCB->AddPaveBlock(aPBx);
299 aItLPB.Initialize(aLPB);
300 for (; aItLPB.More(); aItLPB.Next()) {
301 const Handle(BOPDS_PaveBlock)& aPBx=aItLPB.Value();
302 pDS->SetCommonBlock(aPBx, aCB);
307 //=======================================================================
308 //function : PerformCommonBlocks
310 //=======================================================================
311 void BOPAlgo_Tools::PerformCommonBlocks(const BOPDS_IndexedDataMapOfPaveBlockListOfInteger& aMPBLI,
312 Handle(NCollection_BaseAllocator)& ,//aAllocator
315 Standard_Integer nF, i, aNb;
316 BOPCol_ListIteratorOfListOfInteger aItLI;
317 Handle(BOPDS_PaveBlock) aPB;
318 Handle(BOPDS_CommonBlock) aCB;
321 for (i=1; i<=aNb; ++i) {
322 aPB=aMPBLI.FindKey(i);
323 if (pDS->IsCommonBlock(aPB)) {
324 aCB=pDS->CommonBlock(aPB);
327 aCB=new BOPDS_CommonBlock;
328 aCB->AddPaveBlock(aPB);
331 const BOPCol_ListOfInteger& aLI=aMPBLI.FindFromKey(aPB);
332 aItLI.Initialize(aLI);
333 for (; aItLI.More(); aItLI.Next()) {
337 pDS->SetCommonBlock(aPB, aCB);