0030686: Visualization, SelectMgr_ViewerSelector - sorting issues of transformation...
[occt.git] / src / BRepAlgoAPI / BRepAlgoAPI_Defeaturing.hxx
CommitLineData
d9ca2e0c 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#ifndef _BRepAlgoAPI_Defeaturing_HeaderFile
16#define _BRepAlgoAPI_Defeaturing_HeaderFile
17
18#include <Standard.hxx>
19#include <Standard_DefineAlloc.hxx>
20#include <Standard_Handle.hxx>
21
22#include <BOPAlgo_RemoveFeatures.hxx>
23#include <BRepAlgoAPI_Algo.hxx>
24
25
26//! The BRepAlgoAPI_Defeaturing algorithm is the API algorithm intended for
27//! removal of the unwanted parts from the shape. The unwanted parts
28//! (or features) can be holes, protrusions, gaps, chamfers, fillets etc.
29//! The shape itself is not modified, the new shape is built as the result.
30//!
31//! The actual removal of the features from the shape is performed by
32//! the low-level *BOPAlgo_RemoveFeatures* tool. So the defeaturing algorithm
33//! has the same options, input data requirements, limitations as the
34//! low-level algorithm.
35//!
36//! <b>Input data</b>
37//!
38//! Currently, only the shapes of type SOLID, COMPSOLID, and COMPOUND of Solids
39//! are supported. And only the FACEs can be removed from the shape.
40//!
41//! On the input the algorithm accepts the shape itself and the
42//! features which have to be removed. It does not matter how the features
43//! are given. It could be the separate faces or the collections
44//! of faces. The faces should belong to the initial shape, and those that
45//! do not belong will be ignored.
46//!
47//! <b>Options</b>
48//!
49//! The algorithm has the following options:
50//! - History support;
51//!
52//! and the options available from base class:
53//! - Error/Warning reporting system;
54//! - Parallel processing mode.
55//!
56//! Please note that the other options of the base class are not supported
57//! here and will have no effect.
58//!
59//! For the details on the available options please refer to the description
60//! of *BOPAlgo_RemoveFeatures* algorithm.
61//!
62//! <b>Limitations</b>
63//!
64//! The defeaturing algorithm has the same limitations as *BOPAlgo_RemoveFeatures*
65//! algorithm.
66//!
67//! <b>Example</b>
68//!
69//! Here is the example of usage of the algorithm:
70//! ~~~~
71//! TopoDS_Shape aSolid = ...; // Input shape to remove the features from
72//! TopTools_ListOfShape aFeatures = ...; // Features to remove from the shape
73//! Standard_Boolean bRunParallel = ...; // Parallel processing mode
74//! Standard_Boolean isHistoryNeeded = ...; // History support
75//!
76//! BRepAlgoAPI_Defeaturing aDF; // De-Featuring algorithm
77//! aDF.SetShape(aSolid); // Set the shape
78//! aDF.AddFacesToRemove(aFaces); // Add faces to remove
79//! aDF.SetRunParallel(bRunParallel); // Define the processing mode (parallel or single)
948fe6ca 80//! aDF.SetToFillHistory(isHistoryNeeded); // Define whether to track the shapes modifications
d9ca2e0c 81//! aDF.Build(); // Perform the operation
82//! if (!aDF.IsDone()) // Check for the errors
83//! {
84//! // error treatment
85//! Standard_SStream aSStream;
86//! aDF.DumpErrors(aSStream);
87//! return;
88//! }
89//! if (aDF.HasWarnings()) // Check for the warnings
90//! {
91//! // warnings treatment
92//! Standard_SStream aSStream;
93//! aDF.DumpWarnings(aSStream);
94//! }
95//! const TopoDS_Shape& aResult = aDF.Shape(); // Result shape
96//! ~~~~
97//!
98//! The algorithm preserves the type of the input shape in the result shape. Thus,
99//! if the input shape is a COMPSOLID, the resulting solids will also be put into a COMPSOLID.
100//!
101class BRepAlgoAPI_Defeaturing: public BRepAlgoAPI_Algo
102{
103public:
104
105 DEFINE_STANDARD_ALLOC
106
107public: //! @name Constructors
108
109 //! Empty constructor
110 BRepAlgoAPI_Defeaturing()
111 :
112 BRepAlgoAPI_Algo(),
948fe6ca 113 myFillHistory(Standard_True)
d9ca2e0c 114 {}
115
116
117public: //! @name Setting input data for the algorithm
118
119 //! Sets the shape for processing.
120 //! @param theShape [in] The shape to remove the features from.
121 //! It should either be the SOLID, COMPSOLID or COMPOUND of Solids.
122 void SetShape(const TopoDS_Shape& theShape)
123 {
124 myInputShape = theShape;
125 }
126
127 //! Returns the input shape
128 const TopoDS_Shape& InputShape() const
129 {
130 return myInputShape;
131 }
132
133 //! Adds the features to remove from the input shape.
134 //! @param theFace [in] The shape to extract the faces for removal.
135 void AddFaceToRemove(const TopoDS_Shape& theFace)
136 {
137 myFacesToRemove.Append(theFace);
138 }
139
140 //! Adds the faces to remove from the input shape.
141 //! @param theFaces [in] The list of shapes to extract the faces for removal.
142 void AddFacesToRemove(const TopTools_ListOfShape& theFaces)
143 {
144 TopTools_ListIteratorOfListOfShape it(theFaces);
145 for (; it.More(); it.Next())
146 myFacesToRemove.Append(it.Value());
147 }
148
149 //! Returns the list of faces which have been requested for removal
150 //! from the input shape.
151 const TopTools_ListOfShape& FacesToRemove() const
152 {
153 return myFacesToRemove;
154 }
155
156
157public: //! @name Performing the operation
158
159 //! Performs the operation
160 Standard_EXPORT virtual void Build() Standard_OVERRIDE;
161
162
163public: //! @name History Methods
164
165 //! Defines whether to track the modification of the shapes or not.
948fe6ca 166 void SetToFillHistory(const Standard_Boolean theFlag)
d9ca2e0c 167 {
948fe6ca 168 myFillHistory = theFlag;
d9ca2e0c 169 }
170
171 //! Returns whether the history was requested or not.
948fe6ca 172 Standard_Boolean HasHistory() const { return myFillHistory; }
d9ca2e0c 173
174 //! Returns the list of shapes modified from the shape <theS> during the operation.
175 Standard_EXPORT virtual const TopTools_ListOfShape& Modified(const TopoDS_Shape& theS) Standard_OVERRIDE;
176
177 //! Returns the list of shapes generated from the shape <theS> during the operation.
178 Standard_EXPORT virtual const TopTools_ListOfShape& Generated(const TopoDS_Shape& theS) Standard_OVERRIDE;
179
180 //! Returns true if the shape <theS> has been deleted during the operation.
181 //! It means that the shape has no any trace in the result.
182 //! Otherwise it returns false.
183 Standard_EXPORT virtual Standard_Boolean IsDeleted(const TopoDS_Shape& theS) Standard_OVERRIDE;
184
948fe6ca 185 //! Returns true if any of the input shapes has been modified during operation.
186 Standard_EXPORT virtual Standard_Boolean HasModified() const;
187
188 //! Returns true if any of the input shapes has generated shapes during operation.
189 Standard_EXPORT virtual Standard_Boolean HasGenerated() const;
190
191 //! Returns true if any of the input shapes has been deleted during operation.
192 Standard_EXPORT virtual Standard_Boolean HasDeleted() const;
193
4f7d41ea 194 //! Returns the History of shapes modifications
948fe6ca 195 Handle(BRepTools_History) History()
4f7d41ea 196 {
197 return myFeatureRemovalTool.History();
198 }
199
d9ca2e0c 200
201protected: //! @name Setting the algorithm into default state
202
203 virtual void Clear() Standard_OVERRIDE
204 {
205 BRepAlgoAPI_Algo::Clear();
206 myFeatureRemovalTool.Clear();
207 }
208
209
210protected: //! @name Fields
211
212 TopoDS_Shape myInputShape; //!< Input shape to remove the features from
213 TopTools_ListOfShape myFacesToRemove; //!< Features to remove from the shape
948fe6ca 214 Standard_Boolean myFillHistory; //!< Defines whether to track the history of
d9ca2e0c 215 //! shapes modifications or not (true by default)
216 BOPAlgo_RemoveFeatures myFeatureRemovalTool; //!< Tool for the features removal
217
218};
219
220#endif // _BRepAlgoAPI_Defeaturing_HeaderFile