1 // Created on: 2001-05-06
2 // Created by: Igor FEOKTISTOV
3 // Copyright (c) 2001-2012 OPEN CASCADE SAS
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.
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.
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.
20 #include <QANewModTopOpe_Limitation.ixx>
22 #include <BRep_Builder.hxx>
23 #include <TopExp_Explorer.hxx>
25 #include <TopoDS_Iterator.hxx>
27 #include <TopTools_ListOfShape.hxx>
28 #include <BRepAlgoAPI_Cut.hxx>
29 #include <BRepAlgoAPI_Common.hxx>
30 #include <TopTools_ListIteratorOfListOfShape.hxx>
31 #include <Standard_ConstructionError.hxx>
32 #include <TopTools_MapOfShape.hxx>
35 static TopoDS_Shape MakeCutTool(const TopoDS_Shape& theS2)
37 TopoDS_Shape aRealCutTool, aSh;
40 aBB.MakeSolid(TopoDS::Solid(aRealCutTool));
41 aBB.MakeShell(TopoDS::Shell(aSh));
43 TopExp_Explorer anExp;
45 anExp.Init(theS2,TopAbs_FACE);
47 for(; anExp.More(); anExp.Next()) aBB.Add(aSh, anExp.Current());
48 aBB.Add(aRealCutTool, aSh);
54 QANewModTopOpe_Limitation::QANewModTopOpe_Limitation(const TopoDS_Shape& theObjectToCut,
55 const TopoDS_Shape& theCutTool,
56 const QANewModTopOpe_ModeOfLimitation theMode) :
57 myObjectToCut(theObjectToCut),
58 myFwdIsDone(Standard_False),
59 myRevIsDone(Standard_False),
65 TopExp_Explorer anExp;
66 anExp.Init(theCutTool,TopAbs_FACE);
68 if(!anExp.More()) return;
70 myCutTool = MakeCutTool(theCutTool);
76 void QANewModTopOpe_Limitation::Cut()
81 if(myMode == QANewModTopOpe_Forward) {
83 myCut = new BRepAlgoAPI_Cut(myObjectToCut, myCutTool);
85 myResultFwd = myCut->Shape();
86 myFwdIsDone = Standard_True;
90 myShape = myResultFwd;
94 else if (myMode == QANewModTopOpe_Reversed) {
96 myCommon = new BRepAlgoAPI_Common(myObjectToCut, myCutTool);
97 if(myCommon->IsDone()) {
98 myResultRvs = myCommon->Shape();
99 myRevIsDone = Standard_True;
103 myShape = myResultRvs;
107 else if (myMode == QANewModTopOpe_BothParts) {
109 myCut = new BRepAlgoAPI_Cut(myObjectToCut, myCutTool);
110 if(myCut->IsDone()) {
111 myResultFwd = myCut->Shape();
112 myFwdIsDone = Standard_True;
117 myCommon = new BRepAlgoAPI_Common(myObjectToCut, myCutTool);
118 if(myCommon->IsDone()) {
119 myResultRvs = myCommon->Shape();
120 myRevIsDone = Standard_True;
124 if(myFwdIsDone && myRevIsDone) {
127 aBB.MakeCompound(TopoDS::Compound(myShape));
128 TopoDS_Iterator aItr;
129 aItr.Initialize(myResultFwd, Standard_False, Standard_False);
130 for(; aItr.More(); aItr.Next()) aBB.Add(myShape, aItr.Value());
132 aItr.Initialize(myResultRvs, Standard_False, Standard_False);
133 for(; aItr.More(); aItr.Next()) aBB.Add(myShape, aItr.Value());
140 Standard_ConstructionError::Raise("QANewModTopOpe_Limitation : wrong mode");
146 void QANewModTopOpe_Limitation::SetMode(const QANewModTopOpe_ModeOfLimitation theMode)
151 QANewModTopOpe_ModeOfLimitation QANewModTopOpe_Limitation::GetMode() const
156 const TopoDS_Shape& QANewModTopOpe_Limitation::Shape1() const
158 return myObjectToCut;
161 const TopoDS_Shape& QANewModTopOpe_Limitation::Shape2() const
167 //=======================================================================
168 //function : Modified
170 //=======================================================================
172 const TopTools_ListOfShape& QANewModTopOpe_Limitation::Modified(const TopoDS_Shape& S)
176 if(myMode == QANewModTopOpe_Forward) {
177 myGenerated = myCut->Modified(S);
179 else if(myMode == QANewModTopOpe_Reversed) {
180 myGenerated = myCommon->Modified(S);
183 myGenerated = myCut->Modified(S);
185 TopTools_MapOfShape aMap; // to check if shape can be added in list more then one time
186 TopTools_ListIteratorOfListOfShape It(myGenerated);
187 for(;It.More();It.Next()) {
188 aMap.Add(It.Value());
191 It.Initialize(myCommon->Modified(S));
192 for(;It.More();It.Next()) {
193 if(aMap.Add(It.Value())) myGenerated.Append(It.Value());
200 // ================================================================================================
201 // function: Generated
203 // ================================================================================================
204 const TopTools_ListOfShape& QANewModTopOpe_Limitation::Generated(const TopoDS_Shape& S)
208 if(myMode == QANewModTopOpe_Forward) {
209 myGenerated = myCut->Generated(S);
211 else if(myMode == QANewModTopOpe_Reversed) {
212 myGenerated = myCommon->Generated(S);
215 myGenerated = myCut->Generated(S);
217 TopTools_MapOfShape aMap; // to check if shape can be added in list more then one time
218 TopTools_ListIteratorOfListOfShape It(myGenerated);
219 for(;It.More();It.Next()) {
220 aMap.Add(It.Value());
223 It.Initialize(myCommon->Generated(S));
224 for(;It.More();It.Next()) {
225 if(aMap.Add(It.Value())) myGenerated.Append(It.Value());
232 // ================================================================================================
233 // function: HasModified
235 // ================================================================================================
236 Standard_Boolean QANewModTopOpe_Limitation::HasModified() const
239 if(myMode == QANewModTopOpe_Forward) {
240 return myCut->HasModified();
242 else if(myMode == QANewModTopOpe_Reversed) {
243 return myCommon->HasModified();
246 return myCut->HasModified() || myCommon->HasModified();
250 // ================================================================================================
251 // function: HasGenerated
253 // ================================================================================================
254 Standard_Boolean QANewModTopOpe_Limitation::HasGenerated() const
257 if(myMode == QANewModTopOpe_Forward) {
258 return myCut->HasGenerated();
260 else if(myMode == QANewModTopOpe_Reversed) {
261 return myCommon->HasGenerated();
264 return myCut->HasGenerated() || myCommon->HasGenerated();
268 // ================================================================================================
269 // function: HasDeleted
271 // ================================================================================================
272 Standard_Boolean QANewModTopOpe_Limitation::HasDeleted() const
275 if(myMode == QANewModTopOpe_Forward) {
276 return myCut->HasDeleted();
278 else if(myMode == QANewModTopOpe_Reversed) {
279 return myCommon->HasDeleted();
282 return myCut->HasDeleted() || myCommon->HasDeleted();
286 Standard_Boolean QANewModTopOpe_Limitation::IsDeleted(const TopoDS_Shape& S)
290 if(myMode == QANewModTopOpe_Forward) {
291 return myCut->IsDeleted(S);
293 else if(myMode == QANewModTopOpe_Reversed) {
294 return myCommon->IsDeleted(S);
297 return myCut->IsDeleted(S) && myCommon->IsDeleted(S);
302 void QANewModTopOpe_Limitation::Delete()