0029481: Implementation of the Feature Removal algorithm
[occt.git] / src / BRepAlgoAPI / BRepAlgoAPI_Defeaturing.cxx
1 // Created by: Eugeny MALTCHIKOV
2 // Copyright (c) 2018 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License 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.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15
16 #include <BRepAlgoAPI_Defeaturing.hxx>
17
18 #include <BRepTools_History.hxx>
19
20 //=======================================================================
21 //function : Build
22 //purpose  : 
23 //=======================================================================
24 void BRepAlgoAPI_Defeaturing::Build()
25 {
26   // Set not done state for the operation
27   NotDone();
28
29   // Clear the tools performing the operation
30   Clear();
31
32   // Set the inputs to BOPAlgo_RemoveFeatures algorithm
33   myFeatureRemovalTool.SetShape(myInputShape);
34   myFeatureRemovalTool.AddFacesToRemove(myFacesToRemove);
35   myFeatureRemovalTool.TrackHistory(myTrackHistory);
36   myFeatureRemovalTool.SetRunParallel(myRunParallel);
37
38   // Perform the features removal
39   myFeatureRemovalTool.Perform();
40
41   // Merge the Errors/Warnings from the features removal tool
42   GetReport()->Merge(myFeatureRemovalTool.GetReport());
43
44   if (HasErrors())
45     return;
46
47   // Set done state
48   Done();
49
50   // Get the result shape
51   myShape = myFeatureRemovalTool.Shape();
52 }
53
54 //=======================================================================
55 //function : Modified
56 //purpose  : 
57 //=======================================================================
58 const TopTools_ListOfShape& BRepAlgoAPI_Defeaturing::Modified(const TopoDS_Shape& theS)
59 {
60   myGenerated.Clear();
61   if (!myFeatureRemovalTool.History().IsNull())
62     myGenerated = myFeatureRemovalTool.History()->Modified(theS);
63   return myGenerated;
64 }
65
66 //=======================================================================
67 //function : Generated
68 //purpose  : 
69 //=======================================================================
70 const TopTools_ListOfShape& BRepAlgoAPI_Defeaturing::Generated(const TopoDS_Shape& theS)
71 {
72   myGenerated.Clear();
73   if (!myFeatureRemovalTool.History().IsNull())
74     myGenerated = myFeatureRemovalTool.History()->Generated(theS);
75   return myGenerated;
76 }
77
78 //=======================================================================
79 //function : IsDeleted
80 //purpose  : 
81 //=======================================================================
82 Standard_Boolean BRepAlgoAPI_Defeaturing::IsDeleted(const TopoDS_Shape& theS)
83 {
84   return (!myFeatureRemovalTool.History().IsNull() ?
85     myFeatureRemovalTool.History()->IsRemoved(theS) : Standard_False);
86 }