Adding of testing cases from subgroups 937 940 and 941 of CHL group
[occt.git] / src / BOP / BOP_SFSCorrector.cxx
CommitLineData
b311480e 1// Created on: 2001-08-02
2// Created by: Peter KURNEV
3// Copyright (c) 2001-2012 OPEN CASCADE SAS
7fd59977 4//
b311480e 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.
9//
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.
12//
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.
19
7fd59977 20
21#include <BOP_SFSCorrector.ixx>
22
23#include <TopTools_IndexedMapOfOrientedShape.hxx>
24#include <TopTools_ListIteratorOfListOfShape.hxx>
25
26#include <TopoDS.hxx>
27#include <TopoDS_Shape.hxx>
28#include <TopoDS_Shell.hxx>
29#include <TopoDS_Face.hxx>
30#include <TopoDS_Edge.hxx>
31
32#include <BRep_Builder.hxx>
33
34#include <BOP_ConnexityBlock.hxx>
35#include <BOP_ListIteratorOfListOfConnexityBlock.hxx>
36#include <BOP_ShellSplitter.hxx>
37#include <BOPTColStd_ListOfListOfShape.hxx>
38#include <BOPTColStd_ListIteratorOfListOfListOfShape.hxx>
39
40
41static
42 void MakeShell (const TopTools_ListOfShape& aLE,
43 TopoDS_Shell& newShell);
44
45//=======================================================================
46// function: BOP_SFSCorrector::BOP_SFSCorrector
47// purpose:
48//=======================================================================
49 BOP_SFSCorrector::BOP_SFSCorrector()
50:
51 myIsDone(Standard_False),
52 myErrorStatus(1)
53{}
54//=======================================================================
55// function: SetSFS
56// purpose:
57//=======================================================================
58 void BOP_SFSCorrector::SetSFS (const BOP_ShellFaceSet& aSFS)
59{
60 BOP_ShellFaceSet* pSFS=(BOP_ShellFaceSet*) &aSFS;
61 mySFS=pSFS;
62}
63//=======================================================================
64// function: SFS
65// purpose:
66//=======================================================================
67 BOP_ShellFaceSet& BOP_SFSCorrector::SFS ()
68{
69 return *mySFS;
70}
71//=======================================================================
72// function: NewSFS
73// purpose:
74//=======================================================================
75 BOP_ShellFaceSet& BOP_SFSCorrector::NewSFS ()
76{
77 return myNewSFS;
78}
79//=======================================================================
80// function: IsDone
81// purpose:
82//=======================================================================
83 Standard_Boolean BOP_SFSCorrector::IsDone () const
84{
85 return myIsDone;
86}
87//=======================================================================
88// function: ErrorStatus
89// purpose:
90//=======================================================================
91 Standard_Integer BOP_SFSCorrector::ErrorStatus () const
92{
93 return myErrorStatus;
94}
95//=======================================================================
96// function: Do
97// purpose:
98//=======================================================================
99 void BOP_SFSCorrector::Do()
100{
101 DoConnexityBlocks();
102 DoCorrections();
103 myIsDone=Standard_True;
104}
105//=======================================================================
106// function: DoConnexityBlocks
107// purpose:
108//=======================================================================
109 void BOP_SFSCorrector::DoConnexityBlocks()
110{
111 Standard_Boolean EnewinM, aGoOn;
112 Standard_Integer Mextent, IsRegular, aNbNeighbours, Eindex;
113 TopTools_IndexedMapOfOrientedShape myOrientedShapeMap, aMap;
114 //
115 mySFS->InitStartElements();
116 for (; mySFS->MoreStartElements(); mySFS->NextStartElement()) {
117 const TopoDS_Shape& anE = mySFS->StartElement();
118 Mextent = myOrientedShapeMap.Extent();
119
120 Eindex = myOrientedShapeMap.Add(anE);
121
122 EnewinM = (Eindex > Mextent);
123 if (EnewinM) {
124 //
125 // make a new block starting at element Eindex
126 IsRegular=Standard_True;
127 aNbNeighbours=0;
128 Mextent = myOrientedShapeMap.Extent();
129 //
130 aMap.Clear();
131 aMap.Add(anE);
132 //
133 aGoOn = (Eindex <= Mextent);
134 while (aGoOn) {
135 const TopoDS_Shape& anEE = myOrientedShapeMap(Eindex);
136 aNbNeighbours = mySFS->MaxNumberSubShape(anEE);
137
138 IsRegular = IsRegular && (aNbNeighbours == 2);
139 //
140 mySFS->InitNeighbours(anEE);
141 for (; mySFS->MoreNeighbours(); mySFS->NextNeighbour()) {
142 const TopoDS_Shape& aNeignbE = mySFS->Neighbour();
143 myOrientedShapeMap.Add(aNeignbE);
144 //
145 aMap.Add(aNeignbE);
146 }
147
148 Eindex++;
149 Mextent = myOrientedShapeMap.Extent();
150 aGoOn = (Eindex <= Mextent);
151 } // end of while aGoOn
152
153 BOP_ConnexityBlock aConnexityBlock;
154 aConnexityBlock.SetShapes(aMap);
155 aConnexityBlock.SetRegularity(IsRegular);
156 myConnexityBlocks.Append(aConnexityBlock);
157 } // end of if (EnewinM)
158 } // end of for (; mySFS->MoreStartElements();...
159}
160
161//=======================================================================
162// function: DoCorrections
163// purpose:
164//=======================================================================
165 void BOP_SFSCorrector::DoCorrections()
166{
167 Standard_Boolean anIsRegular, anIsNothingToDo, anIsDone;
168 TopoDS_Shell aShell;
169 BOP_ListIteratorOfListOfConnexityBlock aCBIt;
170
171 //myNewSFS.Initialize(mySFS->Face());
172 anIsDone=Standard_False;
173 anIsNothingToDo=Standard_True;
174
175 aCBIt.Initialize(myConnexityBlocks);
176 for (; aCBIt.More(); aCBIt.Next()) {
177 const BOP_ConnexityBlock& aCB=aCBIt.Value();
178 const TopTools_ListOfShape& aListOfEdges=aCB.Shapes();
179
180 anIsRegular=aCB.IsRegular();
181
182 if (anIsRegular) {
183 MakeShell(aListOfEdges, aShell);
184 myNewSFS.AddShape (aShell);
185 continue;
186 }
187 //
188 // Treatment of non regular Connexity Block
189 BOP_ShellSplitter aShellSplitter;
190 aShellSplitter.DoWithListOfEdges(aListOfEdges);
191
192 anIsDone=aShellSplitter.IsDone();
193 anIsNothingToDo=aShellSplitter.IsNothingToDo();
194
195 if (!anIsDone || anIsNothingToDo) {
196 MakeShell(aListOfEdges, aShell);
197 myNewSFS.AddShape (aShell);
198 continue;
199 }
200
201 //
202 const BOPTColStd_ListOfListOfShape& aSSS=aShellSplitter.Shapes();
203
204 BOPTColStd_ListIteratorOfListOfListOfShape aShellIt(aSSS);
205 for (; aShellIt.More(); aShellIt.Next()) {
206 const TopTools_ListOfShape& aListF=aShellIt.Value();
207 //
208 MakeShell(aListF, aShell);
209 myNewSFS.AddShape (aShell);
210 }
211 }
212}
213
214//=======================================================================
215// function: MakeShell
216// purpose:
217//=======================================================================
218 void MakeShell(const TopTools_ListOfShape& aLE,
219 TopoDS_Shell& newShell)
220{
221 BRep_Builder aBB;
222 aBB.MakeShell(newShell);
223
224 TopTools_ListIteratorOfListOfShape anIt(aLE);
225 for (; anIt.More(); anIt.Next()){
226 const TopoDS_Face& aF=TopoDS::Face(anIt.Value());
227 aBB.Add(newShell, aF);
228 }
229}
230/////////////////////////////////////////////////////////////////
231//
232// myErrorStatus:
233//
234// 1 - Nothing is done because only constructor has been called
235//
236/////////////////////////////////////////////////////////////////