1 // Created by: Peter KURNEV
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and / or modify it
7 // under the terms of the GNU Lesser General Public 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.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #include <BOPAlgo_Tools.ixx>
16 #include <BOPDS_DS.hxx>
17 #include <BOPDS_MapOfPaveBlock.hxx>
18 #include <BOPDS_IndexedMapOfPaveBlock.hxx>
19 #include <BOPDS_CommonBlock.hxx>
20 #include <BOPDS_DataMapOfPaveBlockListOfPaveBlock.hxx>
21 #include <BOPCol_IndexedMapOfInteger.hxx>
23 //=======================================================================
24 //function : MakeBlocksCnx
26 //=======================================================================
27 void BOPAlgo_Tools::MakeBlocksCnx(const BOPCol_IndexedDataMapOfIntegerListOfInteger& aMILI,
28 BOPCol_DataMapOfIntegerListOfInteger& aMBlocks,
29 Handle(NCollection_BaseAllocator)& aAllocator)
31 Standard_Integer aNbV, nV, aNbVS, nVP, nVx, aNbVP, aNbEC, k, i, j;
32 BOPCol_ListIteratorOfListOfInteger aItLI;
34 BOPCol_MapOfInteger aMVS(100, aAllocator);
35 BOPCol_IndexedMapOfInteger aMEC(100, aAllocator);
36 BOPCol_IndexedMapOfInteger aMVP(100, aAllocator);
37 BOPCol_IndexedMapOfInteger aMVAdd(100, aAllocator);
41 for (k=0,i=1; i<=aNbV; ++i) {
47 nV = aMILI.FindKey(i);
48 if (aMVS.Contains(nV)){
60 for (j=1; j<=aNbVP; ++j) {
62 const BOPCol_ListOfInteger& aLV=aMILI.FindFromKey(nVP);
63 aItLI.Initialize(aLV);
64 for (; aItLI.More(); aItLI.Next()) {
66 if (aMEC.Contains(nVx)) {
76 aNbVP=aMVAdd.Extent();
78 break; // from while(1)
82 for (j=1; j<=aNbVP; ++j) {
88 BOPCol_ListOfInteger aLIx(aAllocator);
90 aNbEC = aMEC.Extent();
91 for (j=1; j<=aNbEC; ++j) {
96 aMBlocks.Bind(k, aLIx);
98 }//for (k=0,i=1; i<=aNbV; ++i)
104 //=======================================================================
107 //=======================================================================
108 void BOPAlgo_Tools::FillMap(const Standard_Integer n1,
109 const Standard_Integer n2,
110 BOPCol_IndexedDataMapOfIntegerListOfInteger& aMILI,
111 Handle(NCollection_BaseAllocator)& aAllocator)
113 if (aMILI.Contains(n1)) {
114 BOPCol_ListOfInteger& aLI=aMILI.ChangeFromKey(n1);
118 BOPCol_ListOfInteger aLI(aAllocator);
122 if (aMILI.Contains(n2)) {
123 BOPCol_ListOfInteger& aLI=aMILI.ChangeFromKey(n2);
127 BOPCol_ListOfInteger aLI(aAllocator);
132 //=======================================================================
135 //=======================================================================
136 void BOPAlgo_Tools::FillMap(const Handle(BOPDS_PaveBlock)& aPB1,
137 const Handle(BOPDS_PaveBlock)& aPB2,
138 BOPDS_IndexedDataMapOfPaveBlockListOfPaveBlock& aMPBLPB,
139 Handle(NCollection_BaseAllocator)& aAllocator)
141 if (aMPBLPB.Contains(aPB1)) {
142 BOPDS_ListOfPaveBlock& aLPB=aMPBLPB.ChangeFromKey(aPB1);
146 BOPDS_ListOfPaveBlock aLPB(aAllocator);
148 aMPBLPB.Add(aPB1, aLPB);
150 if (aMPBLPB.Contains(aPB2)) {
151 BOPDS_ListOfPaveBlock& aLPB=aMPBLPB.ChangeFromKey(aPB2);
155 BOPDS_ListOfPaveBlock aLPB(aAllocator);
157 aMPBLPB.Add(aPB2, aLPB);
160 //=======================================================================
163 //=======================================================================
164 void BOPAlgo_Tools::FillMap(const Handle(BOPDS_PaveBlock)& aPB,
165 const Standard_Integer nF,
166 BOPDS_IndexedDataMapOfPaveBlockListOfInteger& aMPBLI,
167 Handle(NCollection_BaseAllocator)& aAllocator)
169 if (aMPBLI.Contains(aPB)) {
170 BOPCol_ListOfInteger& aLI=aMPBLI.ChangeFromKey(aPB);
174 BOPCol_ListOfInteger aLI(aAllocator);
176 aMPBLI.Add(aPB, aLI);
179 //=======================================================================
180 //function : MakeBlocks
182 //=======================================================================
183 void BOPAlgo_Tools::MakeBlocks(const BOPDS_IndexedDataMapOfPaveBlockListOfPaveBlock& aMILI,
184 BOPDS_DataMapOfIntegerListOfPaveBlock& aMBlocks,
185 Handle(NCollection_BaseAllocator)& aAllocator)
187 Standard_Integer aNbV, aNbVS, aNbVP, aNbEC, k, i, j;
188 BOPDS_ListIteratorOfListOfPaveBlock aItLI;
190 BOPDS_MapOfPaveBlock aMVS(100, aAllocator);
191 BOPDS_IndexedMapOfPaveBlock aMEC(100, aAllocator);
192 BOPDS_IndexedMapOfPaveBlock aMVP(100, aAllocator);
193 BOPDS_IndexedMapOfPaveBlock aMVAdd(100, aAllocator);
197 for (k=0, i=1; i<=aNbV; ++i) {
203 const Handle(BOPDS_PaveBlock)& nV=aMILI.FindKey(i);
204 if (aMVS.Contains(nV)){
216 for (j=1; j<=aNbVP; ++j) {
217 const Handle(BOPDS_PaveBlock)& nVP=aMVP(j);
218 const BOPDS_ListOfPaveBlock& aLV=aMILI.FindFromKey(nVP);
219 aItLI.Initialize(aLV);
220 for (; aItLI.More(); aItLI.Next()) {
221 const Handle(BOPDS_PaveBlock)& nVx=aItLI.Value();
222 if (aMEC.Contains(nVx)) {
232 aNbVP=aMVAdd.Extent();
234 break; // from while(1)
238 for (j=1; j<=aNbVP; ++j) {
244 BOPDS_ListOfPaveBlock aLIx(aAllocator);
246 aNbEC = aMEC.Extent();
247 for (j=1; j<=aNbEC; ++j) {
248 const Handle(BOPDS_PaveBlock)& nVx=aMEC(j);
252 aMBlocks.Bind(k, aLIx);
254 }//for (k=0, i=1; i<=aNbV; ++i)
260 //=======================================================================
261 //function : PerformCommonBlocks
263 //=======================================================================
264 void BOPAlgo_Tools::PerformCommonBlocks(BOPDS_IndexedDataMapOfPaveBlockListOfPaveBlock& aMPBLPB,
265 Handle(NCollection_BaseAllocator)& aAllocator,
268 Standard_Integer aNbCB;
270 aNbCB=aMPBLPB.Extent();
275 Standard_Integer aNbPB, aNbBlocks, k;
276 BOPDS_ListIteratorOfListOfPaveBlock aItLPB;
277 Handle(BOPDS_CommonBlock) aCB;
278 BOPDS_DataMapOfIntegerListOfPaveBlock aMBlocks(100, aAllocator);
280 BOPAlgo_Tools::MakeBlocks(aMPBLPB, aMBlocks, aAllocator);
282 aNbBlocks = aMBlocks.Extent();
283 for (k=0; k<aNbBlocks; ++k) {
284 const BOPDS_ListOfPaveBlock& aLPB=aMBlocks.Find(k);
287 aCB=new BOPDS_CommonBlock;
289 aItLPB.Initialize(aLPB);
290 for (; aItLPB.More(); aItLPB.Next()) {
291 const Handle(BOPDS_PaveBlock)& aPBx=aItLPB.Value();
292 aCB->AddPaveBlock(aPBx);
295 aItLPB.Initialize(aLPB);
296 for (; aItLPB.More(); aItLPB.Next()) {
297 const Handle(BOPDS_PaveBlock)& aPBx=aItLPB.Value();
298 pDS->SetCommonBlock(aPBx, aCB);
303 //=======================================================================
304 //function : PerformCommonBlocks
306 //=======================================================================
307 void BOPAlgo_Tools::PerformCommonBlocks(const BOPDS_IndexedDataMapOfPaveBlockListOfInteger& aMPBLI,
308 Handle(NCollection_BaseAllocator)& ,//aAllocator
311 Standard_Integer nF, i, aNb;
312 BOPCol_ListIteratorOfListOfInteger aItLI;
313 Handle(BOPDS_PaveBlock) aPB;
314 Handle(BOPDS_CommonBlock) aCB;
317 for (i=1; i<=aNb; ++i) {
318 aPB=aMPBLI.FindKey(i);
319 if (pDS->IsCommonBlock(aPB)) {
320 aCB=pDS->CommonBlock(aPB);
323 aCB=new BOPDS_CommonBlock;
324 aCB->AddPaveBlock(aPB);
327 const BOPCol_ListOfInteger& aLI=aMPBLI.FindFromKey(aPB);
328 aItLI.Initialize(aLI);
329 for (; aItLI.More(); aItLI.Next()) {
333 pDS->SetCommonBlock(aPB, aCB);