1 // Created by: Eugeny MALTCHIKOV
2 // Copyright (c) 2018 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
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.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #ifndef _BRepAlgoAPI_Defeaturing_HeaderFile
16 #define _BRepAlgoAPI_Defeaturing_HeaderFile
18 #include <Standard.hxx>
19 #include <Standard_DefineAlloc.hxx>
20 #include <Standard_Handle.hxx>
22 #include <BOPAlgo_RemoveFeatures.hxx>
23 #include <BRepAlgoAPI_Algo.hxx>
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.
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.
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.
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.
49 //! The algorithm has the following options:
50 //! - History support;
52 //! and the options available from base class:
53 //! - Error/Warning reporting system;
54 //! - Parallel processing mode.
56 //! Please note that the other options of the base class are not supported
57 //! here and will have no effect.
59 //! For the details on the available options please refer to the description
60 //! of *BOPAlgo_RemoveFeatures* algorithm.
62 //! <b>Limitations</b>
64 //! The defeaturing algorithm has the same limitations as *BOPAlgo_RemoveFeatures*
69 //! Here is the example of usage of the algorithm:
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
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)
80 //! aDF.SetToFillHistory(isHistoryNeeded); // Define whether to track the shapes modifications
81 //! aDF.Build(); // Perform the operation
82 //! if (!aDF.IsDone()) // Check for the errors
84 //! // error treatment
85 //! Standard_SStream aSStream;
86 //! aDF.DumpErrors(aSStream);
89 //! if (aDF.HasWarnings()) // Check for the warnings
91 //! // warnings treatment
92 //! Standard_SStream aSStream;
93 //! aDF.DumpWarnings(aSStream);
95 //! const TopoDS_Shape& aResult = aDF.Shape(); // Result shape
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.
101 class BRepAlgoAPI_Defeaturing: public BRepAlgoAPI_Algo
105 DEFINE_STANDARD_ALLOC
107 public: //! @name Constructors
109 //! Empty constructor
110 BRepAlgoAPI_Defeaturing()
113 myFillHistory(Standard_True)
117 public: //! @name Setting input data for the algorithm
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)
124 myInputShape = theShape;
127 //! Returns the input shape
128 const TopoDS_Shape& InputShape() const
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)
137 myFacesToRemove.Append(theFace);
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)
144 TopTools_ListIteratorOfListOfShape it(theFaces);
145 for (; it.More(); it.Next())
146 myFacesToRemove.Append(it.Value());
149 //! Returns the list of faces which have been requested for removal
150 //! from the input shape.
151 const TopTools_ListOfShape& FacesToRemove() const
153 return myFacesToRemove;
157 public: //! @name Performing the operation
159 //! Performs the operation
160 Standard_EXPORT virtual void Build() Standard_OVERRIDE;
163 public: //! @name History Methods
165 //! Defines whether to track the modification of the shapes or not.
166 void SetToFillHistory(const Standard_Boolean theFlag)
168 myFillHistory = theFlag;
171 //! Returns whether the history was requested or not.
172 Standard_Boolean HasHistory() const { return myFillHistory; }
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;
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;
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;
185 //! Returns true if any of the input shapes has been modified during operation.
186 Standard_EXPORT virtual Standard_Boolean HasModified() const;
188 //! Returns true if any of the input shapes has generated shapes during operation.
189 Standard_EXPORT virtual Standard_Boolean HasGenerated() const;
191 //! Returns true if any of the input shapes has been deleted during operation.
192 Standard_EXPORT virtual Standard_Boolean HasDeleted() const;
194 //! Returns the History of shapes modifications
195 Handle(BRepTools_History) History()
197 return myFeatureRemovalTool.History();
201 protected: //! @name Setting the algorithm into default state
203 virtual void Clear() Standard_OVERRIDE
205 BRepAlgoAPI_Algo::Clear();
206 myFeatureRemovalTool.Clear();
210 protected: //! @name Fields
212 TopoDS_Shape myInputShape; //!< Input shape to remove the features from
213 TopTools_ListOfShape myFacesToRemove; //!< Features to remove from the shape
214 Standard_Boolean myFillHistory; //!< Defines whether to track the history of
215 //! shapes modifications or not (true by default)
216 BOPAlgo_RemoveFeatures myFeatureRemovalTool; //!< Tool for the features removal
220 #endif // _BRepAlgoAPI_Defeaturing_HeaderFile