ceaa5e27 |
1 | // Created by: Peter KURNEV |
955b3e71 |
2 | // Copyright (c) 2010-2014 OPEN CASCADE SAS |
ceaa5e27 |
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 | // |
d5f74e42 |
7 | // This file is part of Open CASCADE Technology software library. |
ceaa5e27 |
8 | // |
d5f74e42 |
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. |
ceaa5e27 |
14 | // |
d5f74e42 |
15 | // Alternatively, this file may be used under the terms of Open CASCADE |
16 | // commercial license or contractual agreement. |
17 | |
42cf5bc1 |
18 | #include <BOPAlgo_PaveFiller.hxx> |
25dfc507 |
19 | |
20 | #include <Precision.hxx> |
21 | |
488e5b9d |
22 | #include <gp_Pnt.hxx> |
25dfc507 |
23 | #include <Bnd_Box.hxx> |
24 | |
25 | #include <TopoDS_Iterator.hxx> |
26 | #include <TopoDS_Vertex.hxx> |
27 | #include <TopoDS_Edge.hxx> |
28 | |
25dfc507 |
29 | #include <BRep_Builder.hxx> |
30 | #include <BRepBndLib.hxx> |
31 | |
25dfc507 |
32 | #include <BOPDS_MapOfCommonBlock.hxx> |
33 | #include <BOPDS_ListOfPaveBlock.hxx> |
34 | #include <BOPDS_CommonBlock.hxx> |
35 | #include <BOPDS_DS.hxx> |
36 | |
488e5b9d |
37 | //======================================================================= |
25dfc507 |
38 | //function : SetNonDestructive |
488e5b9d |
39 | //purpose : |
40 | //======================================================================= |
25dfc507 |
41 | void BOPAlgo_PaveFiller::SetNonDestructive() |
42 | { |
43 | if (!myIsPrimary || myNonDestructive) { |
44 | return; |
488e5b9d |
45 | } |
46 | // |
25dfc507 |
47 | Standard_Boolean bFlag; |
1155d05a |
48 | TopTools_ListIteratorOfListOfShape aItLS; |
488e5b9d |
49 | // |
25dfc507 |
50 | bFlag=Standard_False; |
51 | aItLS.Initialize(myArguments); |
52 | for(; aItLS.More() && (!bFlag); aItLS.Next()) { |
53 | const TopoDS_Shape& aS=aItLS.Value(); |
54 | bFlag=aS.Locked(); |
488e5b9d |
55 | } |
25dfc507 |
56 | myNonDestructive=bFlag; |
57 | } |
488e5b9d |
58 | //======================================================================= |
25dfc507 |
59 | //function : UpdateEdgeTolerance |
488e5b9d |
60 | //purpose : |
61 | //======================================================================= |
25dfc507 |
62 | void BOPAlgo_PaveFiller::UpdateEdgeTolerance (const Standard_Integer nE, |
d3578357 |
63 | const Standard_Real theTol) |
25dfc507 |
64 | { |
d3578357 |
65 | BOPDS_ShapeInfo& aSIE = myDS->ChangeShapeInfo(nE); |
66 | const TColStd_ListOfInteger& aLI = aSIE.SubShapes(); |
67 | |
68 | // For the safe input mode avoid modifying the input shapes |
69 | if (myNonDestructive) |
70 | { |
71 | if (!myDS->IsNewShape(nE)) |
25dfc507 |
72 | return; |
d3578357 |
73 | |
74 | TColStd_ListIteratorOfListOfInteger itLI(aLI); |
75 | for (; itLI.More(); itLI.Next()) |
76 | { |
77 | Standard_Integer nV = itLI.Value(), nVSD; |
78 | if (!myDS->IsNewShape(nV) && |
79 | !myDS->HasShapeSD(nV, nVSD)) |
25dfc507 |
80 | return; |
488e5b9d |
81 | } |
25dfc507 |
82 | } |
d3578357 |
83 | |
84 | // Update edge |
25dfc507 |
85 | const TopoDS_Edge& aE = *(TopoDS_Edge*)&myDS->Shape(nE); |
d3578357 |
86 | BRep_Builder().UpdateEdge(aE, theTol); |
87 | Bnd_Box& aBoxE = aSIE.ChangeBox(); |
25dfc507 |
88 | BRepBndLib::Add(aE, aBoxE); |
89 | aBoxE.SetGap(aBoxE.GetGap() + Precision::Confusion()); |
d3578357 |
90 | |
91 | // Update vertices |
92 | TColStd_ListIteratorOfListOfInteger itLI(aLI); |
93 | for (; itLI.More(); itLI.Next()) |
94 | { |
95 | Standard_Integer nV = itLI.Value(); |
96 | UpdateVertex(nV, theTol); |
25dfc507 |
97 | } |
98 | } |
ceaa5e27 |
99 | //======================================================================= |
25dfc507 |
100 | //function : UpdateVertex |
ceaa5e27 |
101 | //purpose : |
102 | //======================================================================= |
25dfc507 |
103 | Standard_Integer BOPAlgo_PaveFiller::UpdateVertex |
104 | (const Standard_Integer nV, |
105 | const Standard_Real aTolNew) |
ceaa5e27 |
106 | { |
25dfc507 |
107 | Standard_Integer nVNew; |
108 | Standard_Real aTolV; |
109 | BRep_Builder aBB; |
110 | |
111 | nVNew = nV; |
112 | if (myDS->IsNewShape(nVNew) || |
113 | myDS->HasShapeSD(nV, nVNew) || |
114 | !myNonDestructive) { |
115 | // nV is a new vertex, it has SD or non-destructive mode is not in force |
116 | const TopoDS_Vertex& aVSD = *(TopoDS_Vertex*)&myDS->Shape(nVNew); |
117 | aTolV = BRep_Tool::Tolerance(aVSD); |
118 | if (aTolV < aTolNew) { |
119 | aBB.UpdateVertex(aVSD, aTolNew); |
120 | BOPDS_ShapeInfo& aSIV = myDS->ChangeShapeInfo(nVNew); |
121 | Bnd_Box& aBoxV = aSIV.ChangeBox(); |
122 | BRepBndLib::Add(aVSD, aBoxV); |
123 | aBoxV.SetGap(aBoxV.GetGap() + Precision::Confusion()); |
d3578357 |
124 | myIncreasedSS.Add(nV); |
25dfc507 |
125 | } |
126 | return nVNew; |
127 | } |
ceaa5e27 |
128 | // |
25dfc507 |
129 | // nV is old vertex |
130 | const TopoDS_Vertex& aV = *(TopoDS_Vertex*)&myDS->Shape(nV); |
131 | aTolV = BRep_Tool::Tolerance(aV); |
ceaa5e27 |
132 | // |
25dfc507 |
133 | // create new vertex |
134 | TopoDS_Vertex aVNew; |
135 | gp_Pnt aPV = BRep_Tool::Pnt(aV); |
136 | aBB.MakeVertex(aVNew, aPV, Max(aTolV, aTolNew)); |
ceaa5e27 |
137 | // |
25dfc507 |
138 | // append new vertex to DS |
139 | BOPDS_ShapeInfo aSIV; |
140 | aSIV.SetShapeType(TopAbs_VERTEX); |
141 | aSIV.SetShape(aVNew); |
142 | nVNew = myDS->Append(aSIV); |
ceaa5e27 |
143 | // |
25dfc507 |
144 | // bounding box for the new vertex |
145 | BOPDS_ShapeInfo& aSIDS = myDS->ChangeShapeInfo(nVNew); |
146 | Bnd_Box& aBoxDS = aSIDS.ChangeBox(); |
147 | BRepBndLib::Add(aVNew, aBoxDS); |
148 | aBoxDS.SetGap(aBoxDS.GetGap() + Precision::Confusion()); |
488e5b9d |
149 | // |
25dfc507 |
150 | // add vertex to SD map |
151 | myDS->AddShapeSD(nV, nVNew); |
d3578357 |
152 | |
153 | // Add new vertex to map of vertices to avoid further extension |
154 | myVertsToAvoidExtension.Add(nVNew); |
155 | |
156 | if (aTolV < aTolNew) |
157 | myIncreasedSS.Add(nV); |
158 | |
25dfc507 |
159 | return nVNew; |
ceaa5e27 |
160 | } |
161 | //======================================================================= |
25dfc507 |
162 | //function : UpdatePaveBlocksWithSDVertices |
ceaa5e27 |
163 | //purpose : |
164 | //======================================================================= |
25dfc507 |
165 | void BOPAlgo_PaveFiller::UpdatePaveBlocksWithSDVertices() |
166 | { |
167 | myDS->UpdatePaveBlocksWithSDVertices(); |
488e5b9d |
168 | } |
169 | //======================================================================= |
25dfc507 |
170 | //function : UpdateCommonBlocksWithSDVertices |
488e5b9d |
171 | //purpose : |
172 | //======================================================================= |
25dfc507 |
173 | void BOPAlgo_PaveFiller::UpdateCommonBlocksWithSDVertices() |
ceaa5e27 |
174 | { |
25dfc507 |
175 | if (!myNonDestructive) { |
176 | UpdatePaveBlocksWithSDVertices(); |
177 | return; |
ceaa5e27 |
178 | } |
25dfc507 |
179 | Standard_Integer aNbPBP; |
ceaa5e27 |
180 | // |
25dfc507 |
181 | BOPDS_VectorOfListOfPaveBlock& aPBP=myDS->ChangePaveBlocksPool(); |
1155d05a |
182 | aNbPBP=aPBP.Length(); |
25dfc507 |
183 | if(!aNbPBP) { |
184 | return; |
488e5b9d |
185 | } |
186 | // |
25dfc507 |
187 | Standard_Integer i, nV1, nV2; |
188 | Standard_Real aTolV; |
189 | BOPDS_MapOfCommonBlock aMCB; |
190 | BOPDS_ListIteratorOfListOfPaveBlock aItPB; |
191 | Handle(BOPDS_PaveBlock) aPB; |
192 | // |
193 | aTolV = Precision::Confusion(); |
194 | // |
195 | for (i=0; i<aNbPBP; ++i) { |
196 | BOPDS_ListOfPaveBlock& aLPB=aPBP(i); |
197 | aItPB.Initialize(aLPB); |
198 | for (; aItPB.More(); aItPB.Next()) { |
199 | aPB=aItPB.Value(); |
200 | const Handle(BOPDS_CommonBlock)& aCB=myDS->CommonBlock(aPB); |
201 | if (aCB.IsNull()) { |
202 | continue; |
203 | } |
488e5b9d |
204 | // |
25dfc507 |
205 | if (aMCB.Add(aCB)) { |
25dfc507 |
206 | aPB->Indices(nV1, nV2); |
207 | UpdateVertex(nV1, aTolV); |
208 | UpdateVertex(nV2, aTolV); |
209 | myDS->UpdateCommonBlockWithSDVertices(aCB); |
210 | } |
ceaa5e27 |
211 | } |
ceaa5e27 |
212 | } |
25dfc507 |
213 | UpdatePaveBlocksWithSDVertices(); |
ceaa5e27 |
214 | } |
25dfc507 |
215 | |
216 | namespace |
ceaa5e27 |
217 | { |
25dfc507 |
218 | //======================================================================= |
219 | //function : UpdateInterfsWithSDVertices |
220 | //purpose : |
221 | //======================================================================= |
222 | template <class InterfType> |
1155d05a |
223 | void UpdateIntfsWithSDVertices(BOPDS_PDS theDS, NCollection_Vector<InterfType>& theInterfs) |
25dfc507 |
224 | { |
225 | for (Standard_Integer i = 0; i < theInterfs.Length(); i++) |
226 | { |
227 | InterfType& anIntf = theInterfs(i); |
228 | Standard_Integer anInd; |
229 | if (anIntf.HasIndexNew(anInd)) |
230 | { |
231 | Standard_Integer anIndSD; |
232 | if (theDS->HasShapeSD(anInd, anIndSD)) |
233 | { |
234 | anIntf.SetIndexNew(anIndSD); |
235 | } |
488e5b9d |
236 | } |
ceaa5e27 |
237 | } |
ceaa5e27 |
238 | } |
239 | } |
25dfc507 |
240 | |
241 | //======================================================================= |
242 | //function : UpdateInterfsWithSDVertices |
243 | //purpose : |
244 | //======================================================================= |
245 | void BOPAlgo_PaveFiller::UpdateInterfsWithSDVertices() |
246 | { |
247 | UpdateIntfsWithSDVertices(myDS, myDS->InterfVV()); |
248 | UpdateIntfsWithSDVertices(myDS, myDS->InterfVE()); |
249 | UpdateIntfsWithSDVertices(myDS, myDS->InterfVF()); |
250 | UpdateIntfsWithSDVertices(myDS, myDS->InterfEE()); |
251 | UpdateIntfsWithSDVertices(myDS, myDS->InterfEF()); |
252 | } |