Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:03: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 
0026 //! The BRepAlgoAPI_Defeaturing algorithm is the API algorithm intended for
0027 //! removal of the unwanted parts from the shape. The unwanted parts 
0028 //! (or features) can be holes, protrusions, gaps, chamfers, fillets etc.
0029 //! The shape itself is not modified, the new shape is built as the result.
0030 //!
0031 //! The actual removal of the features from the shape is performed by
0032 //! the low-level *BOPAlgo_RemoveFeatures* tool. So the defeaturing algorithm
0033 //! has the same options, input data requirements, limitations as the
0034 //! low-level algorithm.
0035 //!
0036 //! <b>Input data</b>
0037 //!
0038 //! Currently, only the shapes of type SOLID, COMPSOLID, and COMPOUND of Solids
0039 //! are supported. And only the FACEs can be removed from the shape.
0040 //!
0041 //! On the input the algorithm accepts the shape itself and the
0042 //! features which have to be removed. It does not matter how the features
0043 //! are given. It could be the separate faces or the collections
0044 //! of faces. The faces should belong to the initial shape, and those that
0045 //! do not belong will be ignored.
0046 //!
0047 //! <b>Options</b>
0048 //!
0049 //! The algorithm has the following options:
0050 //! - History support;
0051 //!
0052 //! and the options available from base class:
0053 //! - Error/Warning reporting system;
0054 //! - Parallel processing mode.
0055 //!
0056 //! Please note that the other options of the base class are not supported
0057 //! here and will have no effect.
0058 //!
0059 //! For the details on the available options please refer to the description
0060 //! of *BOPAlgo_RemoveFeatures* algorithm.
0061 //!
0062 //! <b>Limitations</b>
0063 //!
0064 //! The defeaturing algorithm has the same limitations as *BOPAlgo_RemoveFeatures*
0065 //! algorithm.
0066 //!
0067 //! <b>Example</b>
0068 //!
0069 //! Here is the example of usage of the algorithm:
0070 //! ~~~~
0071 //! TopoDS_Shape aSolid = ...;               // Input shape to remove the features from
0072 //! TopTools_ListOfShape aFeatures = ...;    // Features to remove from the shape
0073 //! Standard_Boolean bRunParallel = ...;     // Parallel processing mode
0074 //! Standard_Boolean isHistoryNeeded = ...;  // History support
0075 //!
0076 //! BRepAlgoAPI_Defeaturing aDF;             // De-Featuring algorithm
0077 //! aDF.SetShape(aSolid);                    // Set the shape
0078 //! aDF.AddFacesToRemove(aFaces);            // Add faces to remove
0079 //! aDF.SetRunParallel(bRunParallel);        // Define the processing mode (parallel or single)
0080 //! aDF.SetToFillHistory(isHistoryNeeded);   // Define whether to track the shapes modifications
0081 //! aDF.Build();                             // Perform the operation
0082 //! if (!aDF.IsDone())                       // Check for the errors
0083 //! {
0084 //!   // error treatment
0085 //!   Standard_SStream aSStream;
0086 //!   aDF.DumpErrors(aSStream);
0087 //!   return;
0088 //! }
0089 //! if (aDF.HasWarnings())                   // Check for the warnings
0090 //! {
0091 //!   // warnings treatment
0092 //!   Standard_SStream aSStream;
0093 //!   aDF.DumpWarnings(aSStream);
0094 //! }
0095 //! const TopoDS_Shape& aResult = aDF.Shape(); // Result shape
0096 //! ~~~~
0097 //!
0098 //! The algorithm preserves the type of the input shape in the result shape. Thus,
0099 //! if the input shape is a COMPSOLID, the resulting solids will also be put into a COMPSOLID.
0100 //!
0101 class BRepAlgoAPI_Defeaturing: public BRepAlgoAPI_Algo
0102 {
0103 public:
0104 
0105   DEFINE_STANDARD_ALLOC
0106 
0107 public: //! @name Constructors
0108 
0109   //! Empty constructor
0110   BRepAlgoAPI_Defeaturing()
0111   :
0112     BRepAlgoAPI_Algo(),
0113     myFillHistory(Standard_True)
0114   {}
0115 
0116 
0117 public: //! @name Setting input data for the algorithm
0118 
0119   //! Sets the shape for processing.
0120   //! @param theShape [in] The shape to remove the features from.
0121   //!                      It should either be the SOLID, COMPSOLID or COMPOUND of Solids.
0122   void SetShape(const TopoDS_Shape& theShape)
0123   {
0124     myInputShape = theShape;
0125   }
0126 
0127   //! Returns the input shape
0128   const TopoDS_Shape& InputShape() const
0129   {
0130     return myInputShape;
0131   }
0132 
0133   //! Adds the features to remove from the input shape.
0134   //! @param theFace [in] The shape to extract the faces for removal.
0135   void AddFaceToRemove(const TopoDS_Shape& theFace)
0136   {
0137     myFacesToRemove.Append(theFace);
0138   }
0139 
0140   //! Adds the faces to remove from the input shape.
0141   //! @param theFaces [in] The list of shapes to extract the faces for removal.
0142   void AddFacesToRemove(const TopTools_ListOfShape& theFaces)
0143   {
0144     TopTools_ListIteratorOfListOfShape it(theFaces);
0145     for (; it.More(); it.Next())
0146       myFacesToRemove.Append(it.Value());
0147   }
0148 
0149   //! Returns the list of faces which have been requested for removal
0150   //! from the input shape.
0151   const TopTools_ListOfShape& FacesToRemove() const
0152   {
0153     return myFacesToRemove;
0154   }
0155 
0156 
0157 public: //! @name Performing the operation
0158 
0159   //! Performs the operation
0160   Standard_EXPORT virtual void Build(const Message_ProgressRange& theRange = Message_ProgressRange()) Standard_OVERRIDE;
0161 
0162 
0163 public: //! @name History Methods
0164 
0165   //! Defines whether to track the modification of the shapes or not.
0166   void SetToFillHistory(const Standard_Boolean theFlag)
0167   {
0168     myFillHistory = theFlag;
0169   }
0170 
0171   //! Returns whether the history was requested or not.
0172   Standard_Boolean HasHistory() const { return myFillHistory; }
0173 
0174   //! Returns the list of shapes modified from the shape <theS> during the operation.
0175   Standard_EXPORT virtual const TopTools_ListOfShape& Modified(const TopoDS_Shape& theS) Standard_OVERRIDE;
0176 
0177   //! Returns the list of shapes generated from the shape <theS> during the operation.
0178   Standard_EXPORT virtual const TopTools_ListOfShape& Generated(const TopoDS_Shape& theS) Standard_OVERRIDE;
0179 
0180   //! Returns true if the shape <theS> has been deleted during the operation.
0181   //! It means that the shape has no any trace in the result.
0182   //! Otherwise it returns false.
0183   Standard_EXPORT virtual Standard_Boolean IsDeleted(const TopoDS_Shape& theS) Standard_OVERRIDE;
0184 
0185   //! Returns true if any of the input shapes has been modified during operation.
0186   Standard_EXPORT virtual Standard_Boolean HasModified() const;
0187 
0188   //! Returns true if any of the input shapes has generated shapes during operation.
0189   Standard_EXPORT virtual Standard_Boolean HasGenerated() const;
0190 
0191   //! Returns true if any of the input shapes has been deleted during operation.
0192   Standard_EXPORT virtual Standard_Boolean HasDeleted() const;
0193 
0194   //! Returns the History of shapes modifications
0195   Handle(BRepTools_History) History()
0196   {
0197     return myFeatureRemovalTool.History();
0198   }
0199 
0200 
0201 protected: //! @name Setting the algorithm into default state
0202 
0203   virtual void Clear() Standard_OVERRIDE
0204   {
0205     BRepAlgoAPI_Algo::Clear();
0206     myFeatureRemovalTool.Clear();
0207   }
0208 
0209 
0210 protected: //! @name Fields
0211 
0212   TopoDS_Shape myInputShape;                   //!< Input shape to remove the features from
0213   TopTools_ListOfShape myFacesToRemove;        //!< Features to remove from the shape
0214   Standard_Boolean myFillHistory;              //!< Defines whether to track the history of
0215                                                //! shapes modifications or not (true by default)
0216   BOPAlgo_RemoveFeatures myFeatureRemovalTool; //!< Tool for the features removal
0217 
0218 };
0219 
0220 #endif // _BRepAlgoAPI_Defeaturing_HeaderFile