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 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.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
16 #include <BOPAlgo_Tools.hxx>
17 #include <BOPCol_IndexedMapOfInteger.hxx>
18 #include <BOPDS_CommonBlock.hxx>
19 #include <BOPDS_DataMapOfPaveBlockListOfPaveBlock.hxx>
20 #include <BOPDS_DS.hxx>
21 #include <BOPDS_IndexedMapOfPaveBlock.hxx>
22 #include <BOPDS_MapOfPaveBlock.hxx>
23 #include <BOPDS_PaveBlock.hxx>
25 //=======================================================================
26 //function : MakeBlocksCnx
28 //=======================================================================
29 void BOPAlgo_Tools::MakeBlocksCnx(const BOPCol_IndexedDataMapOfIntegerListOfInteger& aMILI,
30 BOPCol_DataMapOfIntegerListOfInteger& aMBlocks,
31 const Handle(NCollection_BaseAllocator)& aAllocator)
33 Standard_Integer aNbV, nV, aNbVS, nVP, nVx, aNbVP, aNbEC, k, i, j;
34 BOPCol_ListIteratorOfListOfInteger aItLI;
36 BOPCol_MapOfInteger aMVS(100, aAllocator);
37 BOPCol_IndexedMapOfInteger aMEC(100, aAllocator);
38 BOPCol_IndexedMapOfInteger aMVP(100, aAllocator);
39 BOPCol_IndexedMapOfInteger aMVAdd(100, aAllocator);
43 for (k=0,i=1; i<=aNbV; ++i) {
49 nV = aMILI.FindKey(i);
50 if (aMVS.Contains(nV)){
62 for (j=1; j<=aNbVP; ++j) {
64 const BOPCol_ListOfInteger& aLV=aMILI.FindFromKey(nVP);
65 aItLI.Initialize(aLV);
66 for (; aItLI.More(); aItLI.Next()) {
68 if (aMEC.Contains(nVx)) {
78 aNbVP=aMVAdd.Extent();
80 break; // from while(1)
84 for (j=1; j<=aNbVP; ++j) {
90 BOPCol_ListOfInteger aLIx(aAllocator);
92 aNbEC = aMEC.Extent();
93 for (j=1; j<=aNbEC; ++j) {
98 aMBlocks.Bind(k, aLIx);
100 }//for (k=0,i=1; i<=aNbV; ++i)
106 //=======================================================================
109 //=======================================================================
110 void BOPAlgo_Tools::FillMap(const Standard_Integer n1,
111 const Standard_Integer n2,
112 BOPCol_IndexedDataMapOfIntegerListOfInteger& aMILI,
113 const Handle(NCollection_BaseAllocator)& aAllocator)
115 if (aMILI.Contains(n1)) {
116 BOPCol_ListOfInteger& aLI=aMILI.ChangeFromKey(n1);
120 BOPCol_ListOfInteger aLI(aAllocator);
124 if (aMILI.Contains(n2)) {
125 BOPCol_ListOfInteger& aLI=aMILI.ChangeFromKey(n2);
129 BOPCol_ListOfInteger aLI(aAllocator);
134 //=======================================================================
137 //=======================================================================
138 void BOPAlgo_Tools::FillMap(const Handle(BOPDS_PaveBlock)& aPB1,
139 const Handle(BOPDS_PaveBlock)& aPB2,
140 BOPDS_IndexedDataMapOfPaveBlockListOfPaveBlock& aMPBLPB,
141 const Handle(NCollection_BaseAllocator)& aAllocator)
143 if (aMPBLPB.Contains(aPB1)) {
144 BOPDS_ListOfPaveBlock& aLPB=aMPBLPB.ChangeFromKey(aPB1);
148 BOPDS_ListOfPaveBlock aLPB(aAllocator);
150 aMPBLPB.Add(aPB1, aLPB);
152 if (aMPBLPB.Contains(aPB2)) {
153 BOPDS_ListOfPaveBlock& aLPB=aMPBLPB.ChangeFromKey(aPB2);
157 BOPDS_ListOfPaveBlock aLPB(aAllocator);
159 aMPBLPB.Add(aPB2, aLPB);
162 //=======================================================================
165 //=======================================================================
166 void BOPAlgo_Tools::FillMap(const Handle(BOPDS_PaveBlock)& aPB,
167 const Standard_Integer nF,
168 BOPDS_IndexedDataMapOfPaveBlockListOfInteger& aMPBLI,
169 const Handle(NCollection_BaseAllocator)& aAllocator)
171 if (aMPBLI.Contains(aPB)) {
172 BOPCol_ListOfInteger& aLI=aMPBLI.ChangeFromKey(aPB);
176 BOPCol_ListOfInteger aLI(aAllocator);
178 aMPBLI.Add(aPB, aLI);
181 //=======================================================================
182 //function : MakeBlocks
184 //=======================================================================
185 void BOPAlgo_Tools::MakeBlocks(const BOPDS_IndexedDataMapOfPaveBlockListOfPaveBlock& aMILI,
186 BOPDS_DataMapOfIntegerListOfPaveBlock& aMBlocks,
187 const Handle(NCollection_BaseAllocator)& aAllocator)
189 Standard_Integer aNbV, aNbVS, aNbVP, aNbEC, k, i, j;
190 BOPDS_ListIteratorOfListOfPaveBlock aItLI;
192 BOPDS_MapOfPaveBlock aMVS(100, aAllocator);
193 BOPDS_IndexedMapOfPaveBlock aMEC(100, aAllocator);
194 BOPDS_IndexedMapOfPaveBlock aMVP(100, aAllocator);
195 BOPDS_IndexedMapOfPaveBlock aMVAdd(100, aAllocator);
199 for (k=0, i=1; i<=aNbV; ++i) {
205 const Handle(BOPDS_PaveBlock)& nV=aMILI.FindKey(i);
206 if (aMVS.Contains(nV)){
218 for (j=1; j<=aNbVP; ++j) {
219 const Handle(BOPDS_PaveBlock)& nVP=aMVP(j);
220 const BOPDS_ListOfPaveBlock& aLV=aMILI.FindFromKey(nVP);
221 aItLI.Initialize(aLV);
222 for (; aItLI.More(); aItLI.Next()) {
223 const Handle(BOPDS_PaveBlock)& nVx=aItLI.Value();
224 if (aMEC.Contains(nVx)) {
234 aNbVP=aMVAdd.Extent();
236 break; // from while(1)
240 for (j=1; j<=aNbVP; ++j) {
246 BOPDS_ListOfPaveBlock aLIx(aAllocator);
248 aNbEC = aMEC.Extent();
249 for (j=1; j<=aNbEC; ++j) {
250 const Handle(BOPDS_PaveBlock)& nVx=aMEC(j);
254 aMBlocks.Bind(k, aLIx);
256 }//for (k=0, i=1; i<=aNbV; ++i)
262 //=======================================================================
263 //function : PerformCommonBlocks
265 //=======================================================================
266 void BOPAlgo_Tools::PerformCommonBlocks(BOPDS_IndexedDataMapOfPaveBlockListOfPaveBlock& aMPBLPB,
267 const Handle(NCollection_BaseAllocator)& aAllocator,
270 Standard_Integer aNbCB;
272 aNbCB=aMPBLPB.Extent();
277 Standard_Integer aNbPB, aNbBlocks, k;
278 BOPDS_ListIteratorOfListOfPaveBlock aItLPB;
279 Handle(BOPDS_CommonBlock) aCB;
280 BOPDS_DataMapOfIntegerListOfPaveBlock aMBlocks(100, aAllocator);
282 BOPAlgo_Tools::MakeBlocks(aMPBLPB, aMBlocks, aAllocator);
284 aNbBlocks = aMBlocks.Extent();
285 for (k=0; k<aNbBlocks; ++k) {
286 const BOPDS_ListOfPaveBlock& aLPB=aMBlocks.Find(k);
289 aCB=new BOPDS_CommonBlock;
291 aItLPB.Initialize(aLPB);
292 for (; aItLPB.More(); aItLPB.Next()) {
293 const Handle(BOPDS_PaveBlock)& aPBx=aItLPB.Value();
294 aCB->AddPaveBlock(aPBx);
297 aItLPB.Initialize(aLPB);
298 for (; aItLPB.More(); aItLPB.Next()) {
299 const Handle(BOPDS_PaveBlock)& aPBx=aItLPB.Value();
300 pDS->SetCommonBlock(aPBx, aCB);
305 //=======================================================================
306 //function : PerformCommonBlocks
308 //=======================================================================
309 void BOPAlgo_Tools::PerformCommonBlocks(const BOPDS_IndexedDataMapOfPaveBlockListOfInteger& aMPBLI,
310 const Handle(NCollection_BaseAllocator)& ,//aAllocator
313 Standard_Integer nF, i, aNb;
314 BOPCol_ListIteratorOfListOfInteger aItLI;
315 Handle(BOPDS_PaveBlock) aPB;
316 Handle(BOPDS_CommonBlock) aCB;
319 for (i=1; i<=aNb; ++i) {
320 aPB=aMPBLI.FindKey(i);
321 if (pDS->IsCommonBlock(aPB)) {
322 aCB=pDS->CommonBlock(aPB);
325 aCB=new BOPDS_CommonBlock;
326 aCB->AddPaveBlock(aPB);
329 const BOPCol_ListOfInteger& aLI=aMPBLI.FindFromKey(aPB);
330 aItLI.Initialize(aLI);
331 for (; aItLI.More(); aItLI.Next()) {
335 pDS->SetCommonBlock(aPB, aCB);