1 // Created on: 2001-11-02
2 // Created by: Peter KURNEV
3 // Copyright (c) 2001-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
21 #include <BOP_BuilderTools.ixx>
23 #include <TColStd_IndexedMapOfInteger.hxx>
27 #include <BRepAdaptor_Surface.hxx>
28 #include <GeomAbs_SurfaceType.hxx>
30 #include <TopAbs_State.hxx>
32 #include <TopoDS_Shape.hxx>
34 #include <TopExp_Explorer.hxx>
36 #include <TopTools_ListOfShape.hxx>
37 #include <TopTools_ListIteratorOfListOfShape.hxx>
38 #include <TopTools_IndexedMapOfOrientedShape.hxx>
39 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
40 #include <TopTools_IndexedMapOfShape.hxx>
42 #include <BooleanOperations_StateOfShape.hxx>
44 #include <BOPTools_Tools3D.hxx>
45 #include <BOPTools_SSInterference.hxx>
47 #include <BOP_ConnexityBlock.hxx>
48 #include <BOP_ListOfConnexityBlock.hxx>
50 //=======================================================================
51 // function: StateToCompare
53 //=======================================================================
54 BooleanOperations_StateOfShape
55 BOP_BuilderTools::StateToCompare(const Standard_Integer iRank,
56 const BOP_Operation anOp)
58 BooleanOperations_StateOfShape aSt=BooleanOperations_UNKNOWN;
61 if (anOp==BOP_COMMON) {
62 aSt=BooleanOperations_IN;
65 aSt=BooleanOperations_OUT;
68 aSt=BooleanOperations_OUT;
70 if (anOp==BOP_CUT21) {
71 aSt=BooleanOperations_IN;
76 if (anOp==BOP_COMMON) {
77 aSt=BooleanOperations_IN;
80 aSt=BooleanOperations_OUT;
83 aSt=BooleanOperations_IN;
85 if (anOp==BOP_CUT21) {
86 aSt=BooleanOperations_OUT;
91 //=======================================================================
92 // function: ToReverseSection
94 //=======================================================================
95 Standard_Boolean BOP_BuilderTools::ToReverseSection(const Standard_Integer iRank,
96 const BOP_Operation anOp)
98 Standard_Boolean bFlag=Standard_False;
101 if (anOp==BOP_FUSE || anOp==BOP_CUT) {
107 if (anOp==BOP_FUSE || anOp==BOP_CUT21) {
113 //=======================================================================
114 // function: ToReverseFace
116 //=======================================================================
117 Standard_Boolean BOP_BuilderTools::ToReverseFace(const Standard_Integer iRank,
118 const BOP_Operation anOp)
120 Standard_Boolean bFlag=Standard_False;
123 if (anOp==BOP_CUT21) {
136 //=======================================================================
137 // function: OrientSectionEdgeOnF1
139 //=======================================================================
140 void BOP_BuilderTools::OrientSectionEdgeOnF1(const TopoDS_Face& aF1,
141 const TopoDS_Face& aF2,
142 const Standard_Integer iRankF1,
143 const BOP_Operation anOperation,
146 TopAbs_Orientation anOr;
147 Standard_Boolean bToReverseSection;
149 anOr=BOPTools_Tools3D::EdgeOrientation(aE, aF1, aF2);
150 aE.Orientation(anOr);
151 bToReverseSection=BOP_BuilderTools::ToReverseSection(iRankF1, anOperation);
152 if (bToReverseSection) {
157 //=======================================================================
158 // function: IsSameDomainFaceWithF1
160 //=======================================================================
162 BOP_BuilderTools::IsSameDomainFaceWithF1(const Standard_Integer nF1,
163 const Standard_Integer nF2,
164 const TColStd_IndexedMapOfInteger& aFFIndicesMap,
165 BOPTools_CArray1OfSSInterference& aFFs)
167 Standard_Boolean bIsSDF, bYes;
168 Standard_Integer j, aNbj, iFFx, nFx;
171 aNbj=aFFIndicesMap.Extent();
173 for (j=1; j<=aNbj; j++) {
174 iFFx=aFFIndicesMap(j);
175 BOPTools_SSInterference& aFFx=aFFs(iFFx);
176 bIsSDF=aFFx.IsTangentFaces();
178 nFx=aFFx.OppositeIndex(nF1);
187 //=======================================================================
188 // function: IsPartIN2DToKeep
190 //=======================================================================
192 BOP_BuilderTools::IsPartIN2DToKeep(const TopAbs_State aST1,
193 const Standard_Integer iRankF1,
194 const BOP_Operation anOp)
198 Standard_Boolean bRetFlag= (aST1==TopAbs_OUT);
202 if (anOp==BOP_CUT && iRankF1==2) {
206 if (anOp==BOP_CUT21 && iRankF1==1) {
210 if (anOp==BOP_COMMON && iRankF1==2) {
214 if (anOp==BOP_COMMON && iRankF1==1) {
221 // Different oriented
222 else if (!bRetFlag) {
223 if (anOp==BOP_FUSE) {
227 if (anOp==BOP_CUT && iRankF1==1) {
231 if (anOp==BOP_CUT21 && iRankF1==2) {
238 //=======================================================================
239 // function: IsPartOn2dToKeep
241 //=======================================================================
243 BOP_BuilderTools::IsPartOn2dToKeep(const TopAbs_State aST1,
244 const Standard_Integer iRankF1,
245 const BOP_Operation anOp)
247 Standard_Boolean bRetFlag=Standard_False;
250 if (aST1==TopAbs_OUT) {
251 if (anOp==BOP_FUSE) {
252 bRetFlag=Standard_True;
256 bRetFlag=Standard_True;
260 if (anOp==BOP_CUT21) {
261 bRetFlag=Standard_True;
267 if (aST1==TopAbs_IN) {
268 if (anOp==BOP_COMMON) {
269 bRetFlag=Standard_True;
273 bRetFlag=Standard_True;
277 if (anOp==BOP_CUT21) {
278 bRetFlag=Standard_True;
285 //=======================================================================
288 //=======================================================================
289 void BOP_BuilderTools::DoMap
290 (BOPTools_CArray1OfSSInterference& aFFs,
291 BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aFFMap)
293 Standard_Integer i, aNb, nF1, nF2;
295 // Intersection Map for Faces
298 TColStd_IndexedMapOfInteger aFFIndices;
301 for (i=1; i<=aNb; i++) {
302 BOPTools_SSInterference& aFF=aFFs(i);
307 if (!aFFMap.Contains(nF1)) {
310 aFFMap.Add(nF1, aFFIndices);
313 TColStd_IndexedMapOfInteger& aMF=aFFMap.ChangeFromKey(nF1);
317 if (!aFFMap.Contains(nF2)) {
320 aFFMap.Add(nF2, aFFIndices);
323 TColStd_IndexedMapOfInteger& aMF=aFFMap.ChangeFromKey(nF2);
329 //=======================================================================
332 void Pathx(const TopoDS_Shape& aVx,
333 const TopoDS_Shape& aEx,
334 const TopAbs_ShapeEnum aType2,
335 const TopTools_IndexedDataMapOfShapeListOfShape& aVEMap,
336 TopTools_IndexedMapOfOrientedShape& aProcessedEdges,
337 TopTools_IndexedMapOfOrientedShape& aCBMap);
339 //=======================================================================
340 // function: MakeConnexityBlocks
342 //=======================================================================
343 void BOP_BuilderTools::MakeConnexityBlocks(const TopTools_ListOfShape& aLEIn,
344 const TopAbs_ShapeEnum aType,
345 BOP_ListOfConnexityBlock& aLConBlks)
347 Standard_Integer i, aNbV, aNbE;
348 TopTools_IndexedDataMapOfShapeListOfShape aVEMap;
349 TopTools_IndexedMapOfOrientedShape aProcessedEdges, aCBMap;
350 TopAbs_ShapeEnum aType2;
352 if (aType==TopAbs_EDGE) {
353 aType2=TopAbs_VERTEX;
355 else if (aType==TopAbs_FACE) {
362 TopTools_ListIteratorOfListOfShape anIt(aLEIn);
364 for (; anIt.More(); anIt.Next()) {
365 const TopoDS_Shape& aE=anIt.Value();
366 TopExp::MapShapesAndAncestors(aE, aType2, aType, aVEMap);
369 aNbV=aVEMap.Extent();
370 for (i=1; i<=aNbV; i++) {
373 const TopoDS_Shape& aV=aVEMap.FindKey(i);
375 const TopTools_ListOfShape& aLE=aVEMap(i);
376 anIt.Initialize(aLE);
377 for (; anIt.More(); anIt.Next()) {
378 const TopoDS_Shape& aE=anIt.Value();
379 if (!aProcessedEdges.Contains(aE)) {
380 aProcessedEdges.Add(aE);
382 Pathx (aV, aE, aType2, aVEMap, aProcessedEdges, aCBMap);
385 aNbE=aCBMap.Extent();
387 BOP_ConnexityBlock aConnexityBlock;
388 aConnexityBlock.SetShapes(aCBMap);
389 aLConBlks.Append(aConnexityBlock);
394 //=======================================================================
397 //=======================================================================
398 void Pathx(const TopoDS_Shape& aVx,
399 const TopoDS_Shape& aEx,
400 const TopAbs_ShapeEnum aType2,
401 const TopTools_IndexedDataMapOfShapeListOfShape& aVEMap,
402 TopTools_IndexedMapOfOrientedShape& aProcessedEdges,
403 TopTools_IndexedMapOfOrientedShape& aCBMap)
405 TopExp_Explorer anExp(aEx, aType2);
406 for (; anExp.More(); anExp.Next()){
407 const TopoDS_Shape& aV=anExp.Current();
413 const TopTools_ListOfShape& aLE=aVEMap.FindFromKey(aV);
414 TopTools_ListIteratorOfListOfShape anIt(aLE);
415 for (; anIt.More(); anIt.Next()) {
416 const TopoDS_Shape& aE=anIt.Value();
417 if (!aProcessedEdges.Contains(aE)) {
418 aProcessedEdges.Add(aE);
421 Pathx (aV, aE, aType2, aVEMap, aProcessedEdges, aCBMap);