0025412: BRepMesh_FastDiscretFace::tryToInsertAnalyticVertex() - fix invalid comparison
[occt.git] / src / BOPAlgo / BOPAlgo_BOP_1.cxx
CommitLineData
4e57c75e 1// Created by: Peter KURNEV
973c2be1 2// Copyright (c) 1999-2014 OPEN CASCADE SAS
4e57c75e 3//
973c2be1 4// This file is part of Open CASCADE Technology software library.
4e57c75e 5//
d5f74e42 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
973c2be1 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.
4e57c75e 11//
973c2be1 12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
4e57c75e 14
15#include <BOPAlgo_BOP.ixx>
16
17#include <BOPDS_DS.hxx>
18#include <BOPDS_PaveBlock.hxx>
19#include <BOPDS_CommonBlock.hxx>
20#include <BOPDS_FaceInfo.hxx>
21#include <BOPDS_ListOfPaveBlock.hxx>
22#include <BOPDS_MapOfPaveBlock.hxx>
23#include <BOPDS_VectorOfListOfPaveBlock.hxx>
24#include <BOPDS_VectorOfFaceInfo.hxx>
25
26#include <BOPTools.hxx>
27#include <BOPTools_AlgoTools.hxx>
28
29#include <BOPCol_MapOfShape.hxx>
30
31#include <BRep_Builder.hxx>
0ed6989c 32#include <TopExp_Explorer.hxx>
4e57c75e 33
34
35//=======================================================================
36//function : BuildSection
37//purpose :
38//=======================================================================
8620e18d 39void BOPAlgo_BOP::BuildSection()
4e57c75e 40{
41
0ed6989c 42 Standard_Integer i, j, k, nE, nF1, nF2, aNbPB, aNbFF;
43 Standard_Boolean bFlag;
4e57c75e 44 TopoDS_Shape aRC;
45 BRep_Builder aBB;
46 BOPCol_MapOfShape aME;
0ed6989c 47 BOPCol_IndexedMapOfShape aME1, aME2;
4e57c75e 48 //
49 myErrorStatus=0;
50 //
51 BOPTools_AlgoTools::MakeContainer(TopAbs_COMPOUND, aRC);
0ed6989c 52 BOPDS_VectorOfInterfFF& aFFs=myDS->InterfFF();
53 aNbFF=aFFs.Extent();
54 //
55 for (i=0; i<aNbFF; ++i) {
56 BOPDS_InterfFF& aFF=aFFs(i);
57 aFF.Indices(nF1, nF2);
58 const BOPDS_FaceInfo& aFI1=myDS->FaceInfo(nF1);
59 const BOPDS_FaceInfo& aFI2=myDS->FaceInfo(nF2);
4e57c75e 60 //
0ed6989c 61 const BOPDS_IndexedMapOfPaveBlock& aMPBIn1=aFI1.PaveBlocksIn();
62 const BOPDS_IndexedMapOfPaveBlock& aMPBOn1=aFI1.PaveBlocksOn();
63 const BOPDS_IndexedMapOfPaveBlock& aMPBSc1=aFI1.PaveBlocksSc();
4e57c75e 64 //
0ed6989c 65 const BOPDS_IndexedMapOfPaveBlock& aMPBIn2=aFI2.PaveBlocksIn();
66 const BOPDS_IndexedMapOfPaveBlock& aMPBOn2=aFI2.PaveBlocksOn();
67 //
68 //1. Section edges
69 aNbPB = aMPBSc1.Extent();
4e57c75e 70 for (j=1; j<=aNbPB; ++j) {
0ed6989c 71 const Handle(BOPDS_PaveBlock)& aPB=aMPBSc1(j);
4e57c75e 72 nE=aPB->Edge();
73 const TopoDS_Shape& aE=myDS->Shape(nE);
74 if (aME.Add(aE)) {
75 aBB.Add(aRC, aE);
76 }
77 }
0ed6989c 78 //2. Common edges
79 BOPDS_IndexedMapOfPaveBlock aMPB[4] = {aMPBOn2, aMPBIn1, aMPBIn2, aMPBOn1};
80 for (k = 0; k < 3; ++k) {
81 aNbPB = aMPB[k].Extent();
82 for (j=1; j<=aNbPB; ++j) {
83 const Handle(BOPDS_PaveBlock)& aPB=aMPB[k](j);
84 bFlag = (k==0) ? aMPB[3].Contains(aPB) :
85 (aMPB[k-1].Contains(aPB) || aMPB[k+1].Contains(aPB));
86 if (bFlag) {
87 nE=aPB->Edge();
88 const TopoDS_Shape& aE=myDS->Shape(nE);
89 if (aME.Add(aE)) {
90 aBB.Add(aRC, aE);
91 }
92 }
93 }
94 }
95 //3. Shared edges
96 aME1.Clear();
97 aME2.Clear();
98 //
99 const TopoDS_Face& aF1=(*(TopoDS_Face *)(&myDS->Shape(nF1)));
100 const TopoDS_Face& aF2=(*(TopoDS_Face *)(&myDS->Shape(nF2)));
101 //
102 BOPTools::MapShapes(aF1, TopAbs_EDGE, aME1);
103 BOPTools::MapShapes(aF2, TopAbs_EDGE, aME2);
104 //
105 aNbPB = aME1.Extent();
106 for (j=1; j<=aNbPB; ++j) {
107 const TopoDS_Shape& aE = aME1(j);
108 if (aME2.Contains(aE)) {
109 if (aME.Add(aE)) {
110 aBB.Add(aRC, aE);
111 }
112 }
113 }
4e57c75e 114 }
4e57c75e 115 //
4e57c75e 116 myShape=aRC;
117}
b24ac892 118//=======================================================================
119//function : Generated
120//purpose :
121//=======================================================================
8620e18d 122const TopTools_ListOfShape& BOPAlgo_BOP::Generated
123 (const TopoDS_Shape& theS)
b24ac892 124{
125 myHistShapes.Clear();
126 if (theS.IsNull() || (myOperation != BOPAlgo_SECTION)) {
127 return myHistShapes;
128 }
129 //
130 TopAbs_ShapeEnum aType = theS.ShapeType();
131 if (aType != TopAbs_FACE) {
132 return myHistShapes;
133 }
134 //
135 Standard_Integer nS = myDS->Index(theS);
136 if (nS < 0) {
137 return myHistShapes;
138 }
139 //
140 if (!myDS->HasFaceInfo(nS)) {
141 return myHistShapes;
142 }
143 //
144 //collect section edges of the face theS
145 Standard_Integer i, aNb, nSp;
146 //
147 const BOPDS_FaceInfo& aFI = myDS->FaceInfo(nS);
148 const BOPDS_IndexedMapOfPaveBlock& aMPBSc = aFI.PaveBlocksSc();
149 aNb = aMPBSc.Extent();
150 for (i = 1; i <= aNb; ++i) {
151 const Handle(BOPDS_PaveBlock)& aPB = aMPBSc(i);
152 nSp = aPB->Edge();
153 const TopoDS_Shape& aSp = myDS->Shape(nSp);
154 myHistShapes.Append(aSp);
155 }
156 //
157 return myHistShapes;
158}
159