Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-22 08:57:06

0001 // Created by: Eugeny MALTCHIKOV
0002 // Copyright (c) 2018 OPEN CASCADE SAS
0003 //
0004 // This file is part of Open CASCADE Technology software library.
0005 //
0006 // This library is free software; you can redistribute it and/or modify it under
0007 // the terms of the GNU Lesser General Public License version 2.1 as published
0008 // by the Free Software Foundation, with special exception defined in the file
0009 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0010 // distribution for complete text of the license and disclaimer of any warranty.
0011 //
0012 // Alternatively, this file may be used under the terms of Open CASCADE
0013 // commercial license or contractual agreement.
0014 
0015 #ifndef _BRepAlgoAPI_Defeaturing_HeaderFile
0016 #define _BRepAlgoAPI_Defeaturing_HeaderFile
0017 
0018 #include <Standard.hxx>
0019 #include <Standard_DefineAlloc.hxx>
0020 #include <Standard_Handle.hxx>
0021 
0022 #include <BOPAlgo_RemoveFeatures.hxx>
0023 #include <BRepAlgoAPI_Algo.hxx>
0024 
0025 //! The BRepAlgoAPI_Defeaturing algorithm is the API algorithm intended for
0026 //! removal of the unwanted parts from the shape. The unwanted parts
0027 //! (or features) can be holes, protrusions, gaps, chamfers, fillets etc.
0028 //! The shape itself is not modified, the new shape is built as the result.
0029 //!
0030 //! The actual removal of the features from the shape is performed by
0031 //! the low-level *BOPAlgo_RemoveFeatures* tool. So the defeaturing algorithm
0032 //! has the same options, input data requirements, limitations as the
0033 //! low-level algorithm.
0034 //!
0035 //! <b>Input data</b>
0036 //!
0037 //! Currently, only the shapes of type SOLID, COMPSOLID, and COMPOUND of Solids
0038 //! are supported. And only the FACEs can be removed from the shape.
0039 //!
0040 //! On the input the algorithm accepts the shape itself and the
0041 //! features which have to be removed. It does not matter how the features
0042 //! are given. It could be the separate faces or the collections
0043 //! of faces. The faces should belong to the initial shape, and those that
0044 //! do not belong will be ignored.
0045 //!
0046 //! <b>Options</b>
0047 //!
0048 //! The algorithm has the following options:
0049 //! - History support;
0050 //!
0051 //! and the options available from base class:
0052 //! - Error/Warning reporting system;
0053 //! - Parallel processing mode.
0054 //!
0055 //! Please note that the other options of the base class are not supported
0056 //! here and will have no effect.
0057 //!
0058 //! For the details on the available options please refer to the description
0059 //! of *BOPAlgo_RemoveFeatures* algorithm.
0060 //!
0061 //! <b>Limitations</b>
0062 //!
0063 //! The defeaturing algorithm has the same limitations as *BOPAlgo_RemoveFeatures*
0064 //! algorithm.
0065 //!
0066 //! <b>Example</b>
0067 //!
0068 //! Here is the example of usage of the algorithm:
0069 //! ~~~~
0070 //! TopoDS_Shape aSolid = ...;               // Input shape to remove the features from
0071 //! NCollection_List<TopoDS_Shape> aFeatures = ...;    // Features to remove from the shape
0072 //! bool bRunParallel = ...;     // Parallel processing mode
0073 //! bool isHistoryNeeded = ...;  // History support
0074 //!
0075 //! BRepAlgoAPI_Defeaturing aDF;             // De-Featuring algorithm
0076 //! aDF.SetShape(aSolid);                    // Set the shape
0077 //! aDF.AddFacesToRemove(aFaces);            // Add faces to remove
0078 //! aDF.SetRunParallel(bRunParallel);        // Define the processing mode (parallel or single)
0079 //! aDF.SetToFillHistory(isHistoryNeeded);   // Define whether to track the shapes modifications
0080 //! aDF.Build();                             // Perform the operation
0081 //! if (!aDF.IsDone())                       // Check for the errors
0082 //! {
0083 //!   // error treatment
0084 //!   Standard_SStream aSStream;
0085 //!   aDF.DumpErrors(aSStream);
0086 //!   return;
0087 //! }
0088 //! if (aDF.HasWarnings())                   // Check for the warnings
0089 //! {
0090 //!   // warnings treatment
0091 //!   Standard_SStream aSStream;
0092 //!   aDF.DumpWarnings(aSStream);
0093 //! }
0094 //! const TopoDS_Shape& aResult = aDF.Shape(); // Result shape
0095 //! ~~~~
0096 //!
0097 //! The algorithm preserves the type of the input shape in the result shape. Thus,
0098 //! if the input shape is a COMPSOLID, the resulting solids will also be put into a COMPSOLID.
0099 //!
0100 class BRepAlgoAPI_Defeaturing : public BRepAlgoAPI_Algo
0101 {
0102 public:
0103   DEFINE_STANDARD_ALLOC
0104 
0105 public: //! @name Constructors
0106   //! Empty constructor
0107   BRepAlgoAPI_Defeaturing()
0108       : myFillHistory(true)
0109   {
0110   }
0111 
0112 public: //! @name Setting input data for the algorithm
0113   //! Sets the shape for processing.
0114   //! @param[in] theShape  The shape to remove the features from.
0115   //!                      It should either be the SOLID, COMPSOLID or COMPOUND of Solids.
0116   void SetShape(const TopoDS_Shape& theShape) { myInputShape = theShape; }
0117 
0118   //! Returns the input shape
0119   const TopoDS_Shape& InputShape() const { return myInputShape; }
0120 
0121   //! Adds the features to remove from the input shape.
0122   //! @param[in] theFace  The shape to extract the faces for removal.
0123   void AddFaceToRemove(const TopoDS_Shape& theFace) { myFacesToRemove.Append(theFace); }
0124 
0125   //! Adds the faces to remove from the input shape.
0126   //! @param[in] theFaces  The list of shapes to extract the faces for removal.
0127   void AddFacesToRemove(const NCollection_List<TopoDS_Shape>& theFaces)
0128   {
0129     NCollection_List<TopoDS_Shape>::Iterator it(theFaces);
0130     for (; it.More(); it.Next())
0131       myFacesToRemove.Append(it.Value());
0132   }
0133 
0134   //! Returns the list of faces which have been requested for removal
0135   //! from the input shape.
0136   const NCollection_List<TopoDS_Shape>& FacesToRemove() const { return myFacesToRemove; }
0137 
0138 public: //! @name Performing the operation
0139   //! Performs the operation
0140   Standard_EXPORT void Build(
0141     const Message_ProgressRange& theRange = Message_ProgressRange()) override;
0142 
0143 public: //! @name History Methods
0144   //! Defines whether to track the modification of the shapes or not.
0145   void SetToFillHistory(const bool theFlag) { myFillHistory = theFlag; }
0146 
0147   //! Returns whether the history was requested or not.
0148   bool HasHistory() const { return myFillHistory; }
0149 
0150   //! Returns the list of shapes modified from the shape <theS> during the operation.
0151   Standard_EXPORT const NCollection_List<TopoDS_Shape>& Modified(const TopoDS_Shape& theS) override;
0152 
0153   //! Returns the list of shapes generated from the shape <theS> during the operation.
0154   Standard_EXPORT const NCollection_List<TopoDS_Shape>& Generated(
0155     const TopoDS_Shape& theS) override;
0156 
0157   //! Returns true if the shape <theS> has been deleted during the operation.
0158   //! It means that the shape has no any trace in the result.
0159   //! Otherwise it returns false.
0160   Standard_EXPORT bool IsDeleted(const TopoDS_Shape& theS) override;
0161 
0162   //! Returns true if any of the input shapes has been modified during operation.
0163   Standard_EXPORT virtual bool HasModified() const;
0164 
0165   //! Returns true if any of the input shapes has generated shapes during operation.
0166   Standard_EXPORT virtual bool HasGenerated() const;
0167 
0168   //! Returns true if any of the input shapes has been deleted during operation.
0169   Standard_EXPORT virtual bool HasDeleted() const;
0170 
0171   //! Returns the History of shapes modifications
0172   occ::handle<BRepTools_History> History() { return myFeatureRemovalTool.History(); }
0173 
0174 protected: //! @name Setting the algorithm into default state
0175   void Clear() override
0176   {
0177     BRepAlgoAPI_Algo::Clear();
0178     myFeatureRemovalTool.Clear();
0179   }
0180 
0181 protected:                                        //! @name Fields
0182   TopoDS_Shape                   myInputShape;    //!< Input shape to remove the features from
0183   NCollection_List<TopoDS_Shape> myFacesToRemove; //!< Features to remove from the shape
0184   bool                           myFillHistory;   //!< Defines whether to track the history of
0185                                                   //! shapes modifications or not (true by default)
0186   BOPAlgo_RemoveFeatures myFeatureRemovalTool;    //!< Tool for the features removal
0187 };
0188 
0189 #endif // _BRepAlgoAPI_Defeaturing_HeaderFile