0024166: Unable to create file with "Save" menu of voxeldemo Qt sample
[occt.git] / src / BOPAlgo / BOPAlgo_BOP_1.cxx
CommitLineData
4e57c75e 1// Created by: Peter KURNEV
2// Copyright (c) 1999-2012 OPEN CASCADE SAS
3//
4// The content of this file is subject to the Open CASCADE Technology Public
5// License Version 6.5 (the "License"). You may not use the content of this file
6// except in compliance with the License. Please obtain a copy of the License
7// at http://www.opencascade.org and read it completely before using this file.
8//
9// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11//
12// The Original Code and all software distributed under the License is
13// distributed on an "AS IS" basis, without warranty of any kind, and the
14// Initial Developer hereby disclaims all such warranties, including without
15// limitation, any warranties of merchantability, fitness for a particular
16// purpose or non-infringement. Please see the License for the specific terms
17// and conditions governing the rights and limitations under the License.
18
19
20#include <BOPAlgo_BOP.ixx>
21
22#include <BOPDS_DS.hxx>
23#include <BOPDS_PaveBlock.hxx>
24#include <BOPDS_CommonBlock.hxx>
25#include <BOPDS_FaceInfo.hxx>
26#include <BOPDS_ListOfPaveBlock.hxx>
27#include <BOPDS_MapOfPaveBlock.hxx>
28#include <BOPDS_VectorOfListOfPaveBlock.hxx>
29#include <BOPDS_VectorOfFaceInfo.hxx>
30
31#include <BOPTools.hxx>
32#include <BOPTools_AlgoTools.hxx>
33
34#include <BOPCol_MapOfShape.hxx>
35
36#include <BRep_Builder.hxx>
0ed6989c 37#include <TopExp_Explorer.hxx>
4e57c75e 38
39
40//=======================================================================
41//function : BuildSection
42//purpose :
43//=======================================================================
44 void BOPAlgo_BOP::BuildSection()
45{
46
0ed6989c 47 Standard_Integer i, j, k, nE, nF1, nF2, aNbPB, aNbFF;
48 Standard_Boolean bFlag;
4e57c75e 49 TopoDS_Shape aRC;
50 BRep_Builder aBB;
51 BOPCol_MapOfShape aME;
0ed6989c 52 BOPCol_IndexedMapOfShape aME1, aME2;
4e57c75e 53 //
54 myErrorStatus=0;
55 //
56 BOPTools_AlgoTools::MakeContainer(TopAbs_COMPOUND, aRC);
0ed6989c 57 BOPDS_VectorOfInterfFF& aFFs=myDS->InterfFF();
58 aNbFF=aFFs.Extent();
59 //
60 for (i=0; i<aNbFF; ++i) {
61 BOPDS_InterfFF& aFF=aFFs(i);
62 aFF.Indices(nF1, nF2);
63 const BOPDS_FaceInfo& aFI1=myDS->FaceInfo(nF1);
64 const BOPDS_FaceInfo& aFI2=myDS->FaceInfo(nF2);
4e57c75e 65 //
0ed6989c 66 const BOPDS_IndexedMapOfPaveBlock& aMPBIn1=aFI1.PaveBlocksIn();
67 const BOPDS_IndexedMapOfPaveBlock& aMPBOn1=aFI1.PaveBlocksOn();
68 const BOPDS_IndexedMapOfPaveBlock& aMPBSc1=aFI1.PaveBlocksSc();
4e57c75e 69 //
0ed6989c 70 const BOPDS_IndexedMapOfPaveBlock& aMPBIn2=aFI2.PaveBlocksIn();
71 const BOPDS_IndexedMapOfPaveBlock& aMPBOn2=aFI2.PaveBlocksOn();
72 //
73 //1. Section edges
74 aNbPB = aMPBSc1.Extent();
4e57c75e 75 for (j=1; j<=aNbPB; ++j) {
0ed6989c 76 const Handle(BOPDS_PaveBlock)& aPB=aMPBSc1(j);
4e57c75e 77 nE=aPB->Edge();
78 const TopoDS_Shape& aE=myDS->Shape(nE);
79 if (aME.Add(aE)) {
80 aBB.Add(aRC, aE);
81 }
82 }
0ed6989c 83 //2. Common edges
84 BOPDS_IndexedMapOfPaveBlock aMPB[4] = {aMPBOn2, aMPBIn1, aMPBIn2, aMPBOn1};
85 for (k = 0; k < 3; ++k) {
86 aNbPB = aMPB[k].Extent();
87 for (j=1; j<=aNbPB; ++j) {
88 const Handle(BOPDS_PaveBlock)& aPB=aMPB[k](j);
89 bFlag = (k==0) ? aMPB[3].Contains(aPB) :
90 (aMPB[k-1].Contains(aPB) || aMPB[k+1].Contains(aPB));
91 if (bFlag) {
92 nE=aPB->Edge();
93 const TopoDS_Shape& aE=myDS->Shape(nE);
94 if (aME.Add(aE)) {
95 aBB.Add(aRC, aE);
96 }
97 }
98 }
99 }
100 //3. Shared edges
101 aME1.Clear();
102 aME2.Clear();
103 //
104 const TopoDS_Face& aF1=(*(TopoDS_Face *)(&myDS->Shape(nF1)));
105 const TopoDS_Face& aF2=(*(TopoDS_Face *)(&myDS->Shape(nF2)));
106 //
107 BOPTools::MapShapes(aF1, TopAbs_EDGE, aME1);
108 BOPTools::MapShapes(aF2, TopAbs_EDGE, aME2);
109 //
110 aNbPB = aME1.Extent();
111 for (j=1; j<=aNbPB; ++j) {
112 const TopoDS_Shape& aE = aME1(j);
113 if (aME2.Contains(aE)) {
114 if (aME.Add(aE)) {
115 aBB.Add(aRC, aE);
116 }
117 }
118 }
4e57c75e 119 }
4e57c75e 120 //
0ed6989c 121 //case when arguments are the same
122 if (!aNbFF) {
123 if (myArgs[0].IsSame(myArgs[1])) {
124 TopExp_Explorer anExpF, anExpE;
125 //
126 anExpF.Init(myArgs[0], TopAbs_FACE);
127 for(; anExpF.More(); anExpF.Next()) {
128 const TopoDS_Shape& aF = anExpF.Current();
129 //
130 anExpE.Init(aF, TopAbs_EDGE);
131 for (; anExpE.More(); anExpE.Next()) {
132 const TopoDS_Shape& aE = anExpE.Current();
133 //
134 if (aME.Add(aE)) {
135 aBB.Add(aRC, aE);
136 }
137 }
4e57c75e 138 }
139 }
140 }
0ed6989c 141 //
4e57c75e 142 myShape=aRC;
143}