Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-13 09:15:42

0001 // Created by: Peter KURNEV
0002 // Copyright (c) 2010-2014 OPEN CASCADE SAS
0003 // Copyright (c) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
0004 // Copyright (c) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT,
0005 //                         EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
0006 //
0007 // This file is part of Open CASCADE Technology software library.
0008 //
0009 // This library is free software; you can redistribute it and/or modify it under
0010 // the terms of the GNU Lesser General Public License version 2.1 as published
0011 // by the Free Software Foundation, with special exception defined in the file
0012 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0013 // distribution for complete text of the license and disclaimer of any warranty.
0014 //
0015 // Alternatively, this file may be used under the terms of Open CASCADE
0016 // commercial license or contractual agreement.
0017 
0018 #ifndef _BOPAlgo_BuilderShape_HeaderFile
0019 #define _BOPAlgo_BuilderShape_HeaderFile
0020 
0021 #include <Standard.hxx>
0022 #include <Standard_DefineAlloc.hxx>
0023 #include <Standard_Handle.hxx>
0024 
0025 #include <BOPAlgo_Algo.hxx>
0026 #include <BRepTools_History.hxx>
0027 
0028 #include <NCollection_BaseAllocator.hxx>
0029 #include <TopoDS_Shape.hxx>
0030 #include <NCollection_List.hxx>
0031 #include <TopTools_ShapeMapHasher.hxx>
0032 #include <NCollection_Map.hxx>
0033 class TopoDS_Shape;
0034 
0035 //! Root class for algorithms that has shape as result.
0036 //!
0037 //! The class provides the History mechanism, which allows
0038 //! tracking the modification of the input shapes during
0039 //! the operation. It uses the *BRepTools_History* tool
0040 //! as a storer for history objects.
0041 class BOPAlgo_BuilderShape : public BOPAlgo_Algo
0042 {
0043 public:
0044   DEFINE_STANDARD_ALLOC
0045 
0046 public: //! @name Getting the result
0047   //! Returns the result of algorithm
0048   const TopoDS_Shape& Shape() const { return myShape; }
0049 
0050 public: //! @name History methods
0051   //! Returns the list of shapes Modified from the shape theS.
0052   const NCollection_List<TopoDS_Shape>& Modified(const TopoDS_Shape& theS)
0053   {
0054     if (myFillHistory && myHistory)
0055       return myHistory->Modified(theS);
0056     myHistShapes.Clear();
0057     return myHistShapes;
0058   }
0059 
0060   //! Returns the list of shapes Generated from the shape theS.
0061   const NCollection_List<TopoDS_Shape>& Generated(const TopoDS_Shape& theS)
0062   {
0063     if (myFillHistory && myHistory)
0064       return myHistory->Generated(theS);
0065     myHistShapes.Clear();
0066     return myHistShapes;
0067   }
0068 
0069   //! Returns true if the shape theS has been deleted.
0070   //! In this case the shape will have no Modified elements,
0071   //! but can have Generated elements.
0072   bool IsDeleted(const TopoDS_Shape& theS)
0073   {
0074     return (myFillHistory && myHistory ? myHistory->IsRemoved(theS) : false);
0075   }
0076 
0077   //! Returns true if any of the input shapes has been modified during operation.
0078   bool HasModified() const
0079   {
0080     return (myFillHistory && myHistory ? myHistory->HasModified() : false);
0081   }
0082 
0083   //! Returns true if any of the input shapes has generated shapes during operation.
0084   bool HasGenerated() const
0085   {
0086     return (myFillHistory && myHistory ? myHistory->HasGenerated() : false);
0087   }
0088 
0089   //! Returns true if any of the input shapes has been deleted during operation.
0090   bool HasDeleted() const { return (myFillHistory && myHistory ? myHistory->HasRemoved() : false); }
0091 
0092   //! History Tool
0093   occ::handle<BRepTools_History> History()
0094   {
0095     if (myFillHistory)
0096     {
0097       if (myHistory.IsNull())
0098         // It seems the algorithm has exited with error before filling
0099         // the history. Initialize the History tool to return the empty
0100         // History instead of NULL.
0101         myHistory = new BRepTools_History();
0102 
0103       return myHistory;
0104     }
0105 
0106     // If the History has not been requested to be filled, return the NULL
0107     // explicitly as the History may be partially filled for the algorithm's
0108     // internal needs.
0109     return nullptr;
0110   }
0111 
0112 public: //! @name Enabling/Disabling the history collection.
0113   //! Allows disabling the history collection
0114   void SetToFillHistory(const bool theHistFlag) { myFillHistory = theHistFlag; }
0115 
0116   //! Returns flag of history availability
0117   bool HasHistory() const { return myFillHistory; }
0118 
0119 protected: //! @name Constructors
0120   //! Empty constructor
0121   BOPAlgo_BuilderShape()
0122       : myFillHistory(true)
0123   {
0124   }
0125 
0126   //! Constructor with allocator
0127   BOPAlgo_BuilderShape(const occ::handle<NCollection_BaseAllocator>& theAllocator)
0128       : BOPAlgo_Algo(theAllocator),
0129         myFillHistory(true)
0130   {
0131   }
0132 
0133 protected: //! @name Clearing
0134   //! Clears the content of the algorithm.
0135   void Clear() override
0136   {
0137     BOPAlgo_Algo::Clear();
0138     myHistory.Nullify();
0139     myMapShape.Clear();
0140   }
0141 
0142 protected:              //! @name Fields
0143   TopoDS_Shape myShape; //!< Result of the operation
0144 
0145   NCollection_List<TopoDS_Shape> myHistShapes; //!< Storer for the history shapes
0146   NCollection_Map<TopoDS_Shape, TopTools_ShapeMapHasher>
0147     myMapShape; //!< cached map of all arguments shapes
0148 
0149   bool                           myFillHistory; //!< Controls the history filling
0150   occ::handle<BRepTools_History> myHistory;     //!< History tool
0151 };
0152 
0153 #endif // _BOPAlgo_BuilderShape_HeaderFile