8eb388e51f9bebc0f6d4cd27f3e9e7086e34f730
[occt.git] / src / BOPAlgo / BOPAlgo_PaveFiller_1.cxx
1 // Created by: Peter KURNEV
2 // Copyright (c) 2010-2014 OPEN CASCADE SAS
3 // Copyright (c) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
4 // Copyright (c) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT,
5 //                         EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 //
7 // This file is part of Open CASCADE Technology software library.
8 //
9 // This library is free software; you can redistribute it and/or modify it under
10 // the terms of the GNU Lesser General Public License version 2.1 as published
11 // by the Free Software Foundation, with special exception defined in the file
12 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
13 // distribution for complete text of the license and disclaimer of any warranty.
14 //
15 // Alternatively, this file may be used under the terms of Open CASCADE
16 // commercial license or contractual agreement.
17
18
19 #include <Bnd_Box.hxx>
20 #include <BOPAlgo_PaveFiller.hxx>
21 #include <BOPAlgo_SectionAttribute.hxx>
22 #include <BOPAlgo_Tools.hxx>
23 #include <BOPCol_DataMapOfIntegerListOfInteger.hxx>
24 #include <BOPCol_ListOfShape.hxx>
25 #include <BOPCol_MapOfInteger.hxx>
26 #include <BOPDS_Curve.hxx>
27 #include <BOPDS_DS.hxx>
28 #include <BOPDS_Iterator.hxx>
29 #include <BOPDS_PaveBlock.hxx>
30 #include <BOPDS_ShapeInfo.hxx>
31 #include <BOPDS_VectorOfInterfVV.hxx>
32 #include <BOPTools_AlgoTools.hxx>
33 #include <BRepBndLib.hxx>
34 #include <gp_Pnt.hxx>
35 #include <IntTools_Context.hxx>
36 #include <NCollection_BaseAllocator.hxx>
37 #include <NCollection_IncAllocator.hxx>
38 #include <TopoDS_Face.hxx>
39 #include <TopoDS_Vertex.hxx>
40
41 //=======================================================================
42 // function: PerformVV
43 // purpose: 
44 //=======================================================================
45   void BOPAlgo_PaveFiller::PerformVV() 
46 {
47   Standard_Boolean bWithSubShape;
48   Standard_Integer n1, n2, iFlag, nX, n, aSize, i, j, k, aNbBlocks;
49   Handle(NCollection_IncAllocator) aAllocator;
50   BOPCol_ListIteratorOfListOfInteger aItLI, aItLI2;
51   TopoDS_Vertex aVn;
52   BOPDS_ShapeInfo aSIn;
53   //
54   myErrorStatus=0;
55   //
56   myIterator->Initialize(TopAbs_VERTEX, TopAbs_VERTEX);
57   aSize=myIterator->ExpectedLength();
58   if (!aSize) {
59     return; 
60   }
61   //
62   aSIn.SetShapeType(TopAbs_VERTEX);
63   
64   BOPDS_VectorOfInterfVV& aVVs=myDS->InterfVV();
65   aVVs.SetIncrement(aSize);
66   //
67   //-----------------------------------------------------scope f
68   aAllocator=new NCollection_IncAllocator();
69   BOPCol_IndexedDataMapOfIntegerListOfInteger aMILI(100, aAllocator);
70   BOPCol_DataMapOfIntegerListOfInteger aMBlocks(100, aAllocator);
71   BOPCol_ListOfShape aLV(aAllocator);
72   //
73   // 1. Map V/LV
74   for (; myIterator->More(); myIterator->Next()) {
75     myIterator->Value(n1, n2, bWithSubShape);
76     //
77     const TopoDS_Vertex& aV1=(*(TopoDS_Vertex *)(&myDS->Shape(n1))); 
78     const TopoDS_Vertex& aV2=(*(TopoDS_Vertex *)(&myDS->Shape(n2))); 
79     //
80     iFlag=BOPTools_AlgoTools::ComputeVV(aV1, aV2);
81     if (!iFlag) {
82       BOPAlgo_Tools::FillMap(n1, n2, aMILI, aAllocator);
83     }
84   } 
85   //
86   // 2. Make blocks
87   BOPAlgo_Tools::MakeBlocksCnx(aMILI, aMBlocks, aAllocator);
88   //
89   // 3. Make vertices
90   aNbBlocks=aMBlocks.Extent();
91   for (k=0; k<aNbBlocks; ++k) {
92     const BOPCol_ListOfInteger& aLI=aMBlocks.Find(k);
93     //
94     aLV.Clear();
95     aItLI.Initialize(aLI);
96     for (; aItLI.More(); aItLI.Next()) {
97       nX=aItLI.Value();
98       const TopoDS_Shape& aV=myDS->Shape(nX);
99       aLV.Append(aV);
100     }
101     //
102     BOPTools_AlgoTools::MakeVertex(aLV, aVn);
103     //
104     // Appennd new vertex to the DS
105     aSIn.SetShape(aVn);
106     n=myDS->Append(aSIn);
107     //
108     BOPDS_ShapeInfo& aSIDS=myDS->ChangeShapeInfo(n);
109     Bnd_Box& aBox=aSIDS.ChangeBox();
110     BRepBndLib::Add(aVn, aBox);
111     //
112     // Fill ShapesSD
113     aItLI.Initialize(aLI);
114     for (i=0; aItLI.More(); aItLI.Next(), ++i) {
115       n1=aItLI.Value();
116       myDS->AddShapeSD(n1, n);
117       //
118       aItLI2.Initialize(aLI);
119       for (j=0; aItLI2.More(); aItLI2.Next(), ++j) {
120         if (j>i) {
121           n2=aItLI2.Value();
122           //
123           myDS->AddInterf(n1, n2);
124           BOPDS_InterfVV& aVV=aVVs.Append1();
125           //
126           aVV.SetIndices(n1, n2);
127           aVV.SetIndexNew(n);
128         }
129       }
130     }
131   }
132   //
133   //-----------------------------------------------------scope t
134   aLV.Clear();
135   aMBlocks.Clear();
136   aMILI.Clear();
137   aAllocator.Nullify();
138 }