0027067: Avoid use of virtual methods for implementation of destructors in legacy...
[occt.git] / src / QANewModTopOpe / QANewModTopOpe_Limitation.cxx
CommitLineData
b311480e 1// Created on: 2001-05-06
2// Created by: Igor FEOKTISTOV
973c2be1 3// Copyright (c) 2001-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
7fd59977 15
7fd59977 16
17#include <BRep_Builder.hxx>
42cf5bc1 18#include <BRepAlgoAPI_Common.hxx>
19#include <BRepAlgoAPI_Cut.hxx>
20#include <QANewModTopOpe_Limitation.hxx>
21#include <Standard_ConstructionError.hxx>
22#include <TopAbs.hxx>
7fd59977 23#include <TopExp_Explorer.hxx>
24#include <TopoDS.hxx>
25#include <TopoDS_Iterator.hxx>
42cf5bc1 26#include <TopoDS_Shape.hxx>
7fd59977 27#include <TopTools_ListIteratorOfListOfShape.hxx>
42cf5bc1 28#include <TopTools_ListOfShape.hxx>
7fd59977 29#include <TopTools_MapOfShape.hxx>
30
7fd59977 31static TopoDS_Shape MakeCutTool(const TopoDS_Shape& theS2)
32{
33 TopoDS_Shape aRealCutTool, aSh;
34 BRep_Builder aBB;
35
36 aBB.MakeSolid(TopoDS::Solid(aRealCutTool));
37 aBB.MakeShell(TopoDS::Shell(aSh));
38
39 TopExp_Explorer anExp;
40
41 anExp.Init(theS2,TopAbs_FACE);
42
43 for(; anExp.More(); anExp.Next()) aBB.Add(aSh, anExp.Current());
44 aBB.Add(aRealCutTool, aSh);
45
46 return aRealCutTool;
47}
48
49
50QANewModTopOpe_Limitation::QANewModTopOpe_Limitation(const TopoDS_Shape& theObjectToCut,
51 const TopoDS_Shape& theCutTool,
52 const QANewModTopOpe_ModeOfLimitation theMode) :
53 myObjectToCut(theObjectToCut),
2f6cb3ac 54 myCut(NULL),
55 myCommon(NULL),
7fd59977 56 myFwdIsDone(Standard_False),
57 myRevIsDone(Standard_False),
2f6cb3ac 58 myMode(theMode)
7fd59977 59{
60
61 TopExp_Explorer anExp;
62 anExp.Init(theCutTool,TopAbs_FACE);
63
64 if(!anExp.More()) return;
65
66 myCutTool = MakeCutTool(theCutTool);
67
68 Cut();
69
70}
71
72void QANewModTopOpe_Limitation::Cut()
73{
74
75 NotDone();
76
77 if(myMode == QANewModTopOpe_Forward) {
78 if(!myFwdIsDone) {
79 myCut = new BRepAlgoAPI_Cut(myObjectToCut, myCutTool);
80 if(myCut->IsDone()) {
81 myResultFwd = myCut->Shape();
82 myFwdIsDone = Standard_True;
83 }
84 }
85 if(myFwdIsDone) {
86 myShape = myResultFwd;
87 Done();
88 }
89 }
90 else if (myMode == QANewModTopOpe_Reversed) {
91 if(!myRevIsDone) {
92 myCommon = new BRepAlgoAPI_Common(myObjectToCut, myCutTool);
93 if(myCommon->IsDone()) {
94 myResultRvs = myCommon->Shape();
95 myRevIsDone = Standard_True;
96 }
97 }
98 if(myRevIsDone) {
99 myShape = myResultRvs;
100 Done();
101 }
102 }
103 else if (myMode == QANewModTopOpe_BothParts) {
104 if(!myFwdIsDone) {
105 myCut = new BRepAlgoAPI_Cut(myObjectToCut, myCutTool);
106 if(myCut->IsDone()) {
107 myResultFwd = myCut->Shape();
108 myFwdIsDone = Standard_True;
109 }
110 }
111
112 if(!myRevIsDone) {
113 myCommon = new BRepAlgoAPI_Common(myObjectToCut, myCutTool);
114 if(myCommon->IsDone()) {
115 myResultRvs = myCommon->Shape();
116 myRevIsDone = Standard_True;
117 }
118 }
119
120 if(myFwdIsDone && myRevIsDone) {
121 myShape.Nullify();
122 BRep_Builder aBB;
123 aBB.MakeCompound(TopoDS::Compound(myShape));
124 TopoDS_Iterator aItr;
125 aItr.Initialize(myResultFwd, Standard_False, Standard_False);
126 for(; aItr.More(); aItr.Next()) aBB.Add(myShape, aItr.Value());
127
128 aItr.Initialize(myResultRvs, Standard_False, Standard_False);
129 for(; aItr.More(); aItr.Next()) aBB.Add(myShape, aItr.Value());
130
131 Done();
132 }
133
134 }
135 else {
136 Standard_ConstructionError::Raise("QANewModTopOpe_Limitation : wrong mode");
137 }
138
139
140}
141
142void QANewModTopOpe_Limitation::SetMode(const QANewModTopOpe_ModeOfLimitation theMode)
143{
144 myMode = theMode;
145}
146
147QANewModTopOpe_ModeOfLimitation QANewModTopOpe_Limitation::GetMode() const
148{
149 return myMode;
150}
151
152const TopoDS_Shape& QANewModTopOpe_Limitation::Shape1() const
153{
154 return myObjectToCut;
155}
156
157const TopoDS_Shape& QANewModTopOpe_Limitation::Shape2() const
158{
159 return myCutTool;
160}
161
162
163//=======================================================================
164//function : Modified
165//purpose :
166//=======================================================================
167
168const TopTools_ListOfShape& QANewModTopOpe_Limitation::Modified(const TopoDS_Shape& S)
169{
170 Check();
171 myGenerated.Clear();
172 if(myMode == QANewModTopOpe_Forward) {
173 myGenerated = myCut->Modified(S);
174 }
175 else if(myMode == QANewModTopOpe_Reversed) {
176 myGenerated = myCommon->Modified(S);
177 }
178 else {
179 myGenerated = myCut->Modified(S);
180
181 TopTools_MapOfShape aMap; // to check if shape can be added in list more then one time
182 TopTools_ListIteratorOfListOfShape It(myGenerated);
183 for(;It.More();It.Next()) {
184 aMap.Add(It.Value());
185 }
186
187 It.Initialize(myCommon->Modified(S));
188 for(;It.More();It.Next()) {
189 if(aMap.Add(It.Value())) myGenerated.Append(It.Value());
190 }
191 }
192
193 return myGenerated;
7fd59977 194}
195
196// ================================================================================================
197// function: Generated
198// purpose:
199// ================================================================================================
200const TopTools_ListOfShape& QANewModTopOpe_Limitation::Generated(const TopoDS_Shape& S)
201{
202 Check();
203 myGenerated.Clear();
204 if(myMode == QANewModTopOpe_Forward) {
205 myGenerated = myCut->Generated(S);
206 }
207 else if(myMode == QANewModTopOpe_Reversed) {
208 myGenerated = myCommon->Generated(S);
209 }
210 else {
211 myGenerated = myCut->Generated(S);
212
213 TopTools_MapOfShape aMap; // to check if shape can be added in list more then one time
214 TopTools_ListIteratorOfListOfShape It(myGenerated);
215 for(;It.More();It.Next()) {
216 aMap.Add(It.Value());
217 }
218
219 It.Initialize(myCommon->Generated(S));
220 for(;It.More();It.Next()) {
221 if(aMap.Add(It.Value())) myGenerated.Append(It.Value());
222 }
223 }
224
225 return myGenerated;
226}
227
228// ================================================================================================
229// function: HasModified
230// purpose:
231// ================================================================================================
232Standard_Boolean QANewModTopOpe_Limitation::HasModified() const
233{
234 Check();
235 if(myMode == QANewModTopOpe_Forward) {
236 return myCut->HasModified();
237 }
238 else if(myMode == QANewModTopOpe_Reversed) {
239 return myCommon->HasModified();
240 }
241 else {
242 return myCut->HasModified() || myCommon->HasModified();
243 }
244}
245
246// ================================================================================================
247// function: HasGenerated
248// purpose:
249// ================================================================================================
250Standard_Boolean QANewModTopOpe_Limitation::HasGenerated() const
251{
252 Check();
253 if(myMode == QANewModTopOpe_Forward) {
254 return myCut->HasGenerated();
255 }
256 else if(myMode == QANewModTopOpe_Reversed) {
257 return myCommon->HasGenerated();
258 }
259 else {
260 return myCut->HasGenerated() || myCommon->HasGenerated();
261 }
262}
263
264// ================================================================================================
265// function: HasDeleted
266// purpose:
267// ================================================================================================
268Standard_Boolean QANewModTopOpe_Limitation::HasDeleted() const
269{
270 Check();
271 if(myMode == QANewModTopOpe_Forward) {
272 return myCut->HasDeleted();
273 }
274 else if(myMode == QANewModTopOpe_Reversed) {
275 return myCommon->HasDeleted();
276 }
277 else {
278 return myCut->HasDeleted() || myCommon->HasDeleted();
279 }
280}
281
282Standard_Boolean QANewModTopOpe_Limitation::IsDeleted(const TopoDS_Shape& S)
283{
284
285 Check();
286 if(myMode == QANewModTopOpe_Forward) {
287 return myCut->IsDeleted(S);
288 }
289 else if(myMode == QANewModTopOpe_Reversed) {
290 return myCommon->IsDeleted(S);
291 }
292 else {
293 return myCut->IsDeleted(S) && myCommon->IsDeleted(S);
294 }
295
296}
297
e6f550da 298QANewModTopOpe_Limitation::~QANewModTopOpe_Limitation()
7fd59977 299{
300 delete myCut;
301 delete myCommon;
302}