Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-24 09:15:53

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 //! TopTools_ListOfShape aFeatures = ...;    // Features to remove from the shape
0072 //! Standard_Boolean bRunParallel = ...;     // Parallel processing mode
0073 //! Standard_Boolean 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       : BRepAlgoAPI_Algo(),
0109         myFillHistory(Standard_True)
0110   {
0111   }
0112 
0113 public: //! @name Setting input data for the algorithm
0114   //! Sets the shape for processing.
0115   //! @param[in] theShape  The shape to remove the features from.
0116   //!                      It should either be the SOLID, COMPSOLID or COMPOUND of Solids.
0117   void SetShape(const TopoDS_Shape& theShape) { myInputShape = theShape; }
0118 
0119   //! Returns the input shape
0120   const TopoDS_Shape& InputShape() const { return myInputShape; }
0121 
0122   //! Adds the features to remove from the input shape.
0123   //! @param[in] theFace  The shape to extract the faces for removal.
0124   void AddFaceToRemove(const TopoDS_Shape& theFace) { myFacesToRemove.Append(theFace); }
0125 
0126   //! Adds the faces to remove from the input shape.
0127   //! @param[in] theFaces  The list of shapes to extract the faces for removal.
0128   void AddFacesToRemove(const TopTools_ListOfShape& theFaces)
0129   {
0130     TopTools_ListIteratorOfListOfShape it(theFaces);
0131     for (; it.More(); it.Next())
0132       myFacesToRemove.Append(it.Value());
0133   }
0134 
0135   //! Returns the list of faces which have been requested for removal
0136   //! from the input shape.
0137   const TopTools_ListOfShape& FacesToRemove() const { return myFacesToRemove; }
0138 
0139 public: //! @name Performing the operation
0140   //! Performs the operation
0141   Standard_EXPORT virtual void Build(
0142     const Message_ProgressRange& theRange = Message_ProgressRange()) Standard_OVERRIDE;
0143 
0144 public: //! @name History Methods
0145   //! Defines whether to track the modification of the shapes or not.
0146   void SetToFillHistory(const Standard_Boolean theFlag) { myFillHistory = theFlag; }
0147 
0148   //! Returns whether the history was requested or not.
0149   Standard_Boolean HasHistory() const { return myFillHistory; }
0150 
0151   //! Returns the list of shapes modified from the shape <theS> during the operation.
0152   Standard_EXPORT virtual const TopTools_ListOfShape& Modified(const TopoDS_Shape& theS)
0153     Standard_OVERRIDE;
0154 
0155   //! Returns the list of shapes generated from the shape <theS> during the operation.
0156   Standard_EXPORT virtual const TopTools_ListOfShape& Generated(const TopoDS_Shape& theS)
0157     Standard_OVERRIDE;
0158 
0159   //! Returns true if the shape <theS> has been deleted during the operation.
0160   //! It means that the shape has no any trace in the result.
0161   //! Otherwise it returns false.
0162   Standard_EXPORT virtual Standard_Boolean IsDeleted(const TopoDS_Shape& theS) Standard_OVERRIDE;
0163 
0164   //! Returns true if any of the input shapes has been modified during operation.
0165   Standard_EXPORT virtual Standard_Boolean HasModified() const;
0166 
0167   //! Returns true if any of the input shapes has generated shapes during operation.
0168   Standard_EXPORT virtual Standard_Boolean HasGenerated() const;
0169 
0170   //! Returns true if any of the input shapes has been deleted during operation.
0171   Standard_EXPORT virtual Standard_Boolean HasDeleted() const;
0172 
0173   //! Returns the History of shapes modifications
0174   Handle(BRepTools_History) History() { return myFeatureRemovalTool.History(); }
0175 
0176 protected: //! @name Setting the algorithm into default state
0177   virtual void Clear() Standard_OVERRIDE
0178   {
0179     BRepAlgoAPI_Algo::Clear();
0180     myFeatureRemovalTool.Clear();
0181   }
0182 
0183 protected:                                     //! @name Fields
0184   TopoDS_Shape         myInputShape;           //!< Input shape to remove the features from
0185   TopTools_ListOfShape myFacesToRemove;        //!< Features to remove from the shape
0186   Standard_Boolean     myFillHistory;          //!< Defines whether to track the history of
0187                                                //! shapes modifications or not (true by default)
0188   BOPAlgo_RemoveFeatures myFeatureRemovalTool; //!< Tool for the features removal
0189 };
0190 
0191 #endif // _BRepAlgoAPI_Defeaturing_HeaderFile