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
7 // This file is part of Open CASCADE Technology software library.
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.
15 // Alternatively, this file may be used under the terms of Open CASCADE
16 // commercial license or contractual agreement.
18 #include <BOPAlgo_PaveFiller.hxx>
20 #include <Precision.hxx>
23 #include <Bnd_Box.hxx>
25 #include <TopoDS_Iterator.hxx>
26 #include <TopoDS_Vertex.hxx>
27 #include <TopoDS_Edge.hxx>
29 #include <BRep_Tool.hxx>
30 #include <BRep_Builder.hxx>
31 #include <BRepBndLib.hxx>
33 #include <BOPDS_ShapeInfo.hxx>
34 #include <BOPDS_VectorOfListOfPaveBlock.hxx>
35 #include <BOPDS_MapOfCommonBlock.hxx>
36 #include <BOPDS_ListOfPaveBlock.hxx>
37 #include <BOPDS_CommonBlock.hxx>
38 #include <BOPDS_DS.hxx>
40 //=======================================================================
41 //function : SetNonDestructive
43 //=======================================================================
44 void BOPAlgo_PaveFiller::SetNonDestructive()
46 if (!myIsPrimary || myNonDestructive) {
50 Standard_Boolean bFlag;
51 TopTools_ListIteratorOfListOfShape aItLS;
54 aItLS.Initialize(myArguments);
55 for(; aItLS.More() && (!bFlag); aItLS.Next()) {
56 const TopoDS_Shape& aS=aItLS.Value();
59 myNonDestructive=bFlag;
61 //=======================================================================
62 //function : UpdateEdgeTolerance
64 //=======================================================================
65 void BOPAlgo_PaveFiller::UpdateEdgeTolerance (const Standard_Integer nE,
66 const Standard_Real theTol)
68 BOPDS_ShapeInfo& aSIE = myDS->ChangeShapeInfo(nE);
69 const TColStd_ListOfInteger& aLI = aSIE.SubShapes();
71 // For the safe input mode avoid modifying the input shapes
74 if (!myDS->IsNewShape(nE))
77 TColStd_ListIteratorOfListOfInteger itLI(aLI);
78 for (; itLI.More(); itLI.Next())
80 Standard_Integer nV = itLI.Value(), nVSD;
81 if (!myDS->IsNewShape(nV) &&
82 !myDS->HasShapeSD(nV, nVSD))
88 const TopoDS_Edge& aE = *(TopoDS_Edge*)&myDS->Shape(nE);
89 BRep_Builder().UpdateEdge(aE, theTol);
90 Bnd_Box& aBoxE = aSIE.ChangeBox();
91 BRepBndLib::Add(aE, aBoxE);
92 aBoxE.SetGap(aBoxE.GetGap() + Precision::Confusion());
95 TColStd_ListIteratorOfListOfInteger itLI(aLI);
96 for (; itLI.More(); itLI.Next())
98 Standard_Integer nV = itLI.Value();
99 UpdateVertex(nV, theTol);
102 //=======================================================================
103 //function : UpdateVertex
105 //=======================================================================
106 Standard_Integer BOPAlgo_PaveFiller::UpdateVertex
107 (const Standard_Integer nV,
108 const Standard_Real aTolNew)
110 Standard_Integer nVNew;
115 if (myDS->IsNewShape(nVNew) ||
116 myDS->HasShapeSD(nV, nVNew) ||
118 // nV is a new vertex, it has SD or non-destructive mode is not in force
119 const TopoDS_Vertex& aVSD = *(TopoDS_Vertex*)&myDS->Shape(nVNew);
120 aTolV = BRep_Tool::Tolerance(aVSD);
121 if (aTolV < aTolNew) {
122 aBB.UpdateVertex(aVSD, aTolNew);
123 BOPDS_ShapeInfo& aSIV = myDS->ChangeShapeInfo(nVNew);
124 Bnd_Box& aBoxV = aSIV.ChangeBox();
125 BRepBndLib::Add(aVSD, aBoxV);
126 aBoxV.SetGap(aBoxV.GetGap() + Precision::Confusion());
127 myIncreasedSS.Add(nV);
133 const TopoDS_Vertex& aV = *(TopoDS_Vertex*)&myDS->Shape(nV);
134 aTolV = BRep_Tool::Tolerance(aV);
138 gp_Pnt aPV = BRep_Tool::Pnt(aV);
139 aBB.MakeVertex(aVNew, aPV, Max(aTolV, aTolNew));
141 // append new vertex to DS
142 BOPDS_ShapeInfo aSIV;
143 aSIV.SetShapeType(TopAbs_VERTEX);
144 aSIV.SetShape(aVNew);
145 nVNew = myDS->Append(aSIV);
147 // bounding box for the new vertex
148 BOPDS_ShapeInfo& aSIDS = myDS->ChangeShapeInfo(nVNew);
149 Bnd_Box& aBoxDS = aSIDS.ChangeBox();
150 BRepBndLib::Add(aVNew, aBoxDS);
151 aBoxDS.SetGap(aBoxDS.GetGap() + Precision::Confusion());
153 // add vertex to SD map
154 myDS->AddShapeSD(nV, nVNew);
156 // Add new vertex to map of vertices to avoid further extension
157 myVertsToAvoidExtension.Add(nVNew);
160 myIncreasedSS.Add(nV);
164 //=======================================================================
165 //function : UpdatePaveBlocksWithSDVertices
167 //=======================================================================
168 void BOPAlgo_PaveFiller::UpdatePaveBlocksWithSDVertices()
170 myDS->UpdatePaveBlocksWithSDVertices();
172 //=======================================================================
173 //function : UpdateCommonBlocksWithSDVertices
175 //=======================================================================
176 void BOPAlgo_PaveFiller::UpdateCommonBlocksWithSDVertices()
178 if (!myNonDestructive) {
179 UpdatePaveBlocksWithSDVertices();
182 Standard_Integer aNbPBP;
184 BOPDS_VectorOfListOfPaveBlock& aPBP=myDS->ChangePaveBlocksPool();
185 aNbPBP=aPBP.Length();
190 Standard_Integer i, nV1, nV2;
192 BOPDS_MapOfCommonBlock aMCB;
193 BOPDS_ListIteratorOfListOfPaveBlock aItPB;
194 Handle(BOPDS_PaveBlock) aPB;
196 aTolV = Precision::Confusion();
198 for (i=0; i<aNbPBP; ++i) {
199 BOPDS_ListOfPaveBlock& aLPB=aPBP(i);
200 aItPB.Initialize(aLPB);
201 for (; aItPB.More(); aItPB.Next()) {
203 const Handle(BOPDS_CommonBlock)& aCB=myDS->CommonBlock(aPB);
209 aPB->Indices(nV1, nV2);
210 UpdateVertex(nV1, aTolV);
211 UpdateVertex(nV2, aTolV);
212 myDS->UpdateCommonBlockWithSDVertices(aCB);
216 UpdatePaveBlocksWithSDVertices();
221 //=======================================================================
222 //function : UpdateInterfsWithSDVertices
224 //=======================================================================
225 template <class InterfType>
226 void UpdateIntfsWithSDVertices(BOPDS_PDS theDS, NCollection_Vector<InterfType>& theInterfs)
228 for (Standard_Integer i = 0; i < theInterfs.Length(); i++)
230 InterfType& anIntf = theInterfs(i);
231 Standard_Integer anInd;
232 if (anIntf.HasIndexNew(anInd))
234 Standard_Integer anIndSD;
235 if (theDS->HasShapeSD(anInd, anIndSD))
237 anIntf.SetIndexNew(anIndSD);
244 //=======================================================================
245 //function : UpdateInterfsWithSDVertices
247 //=======================================================================
248 void BOPAlgo_PaveFiller::UpdateInterfsWithSDVertices()
250 UpdateIntfsWithSDVertices(myDS, myDS->InterfVV());
251 UpdateIntfsWithSDVertices(myDS, myDS->InterfVE());
252 UpdateIntfsWithSDVertices(myDS, myDS->InterfVF());
253 UpdateIntfsWithSDVertices(myDS, myDS->InterfEE());
254 UpdateIntfsWithSDVertices(myDS, myDS->InterfEF());