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 | // |
973c2be1 |
6 | // This library is free software; you can redistribute it and / or modify it |
7 | // under the terms of the GNU Lesser General Public version 2.1 as published |
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 | //======================================================================= |
39 | void BOPAlgo_BOP::BuildSection() |
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 | // |
0ed6989c |
116 | //case when arguments are the same |
117 | if (!aNbFF) { |
118 | if (myArgs[0].IsSame(myArgs[1])) { |
119 | TopExp_Explorer anExpF, anExpE; |
120 | // |
121 | anExpF.Init(myArgs[0], TopAbs_FACE); |
122 | for(; anExpF.More(); anExpF.Next()) { |
123 | const TopoDS_Shape& aF = anExpF.Current(); |
124 | // |
125 | anExpE.Init(aF, TopAbs_EDGE); |
126 | for (; anExpE.More(); anExpE.Next()) { |
127 | const TopoDS_Shape& aE = anExpE.Current(); |
128 | // |
129 | if (aME.Add(aE)) { |
130 | aBB.Add(aRC, aE); |
131 | } |
132 | } |
4e57c75e |
133 | } |
134 | } |
135 | } |
0ed6989c |
136 | // |
4e57c75e |
137 | myShape=aRC; |
138 | } |