1 // Created by: Peter KURNEV
2 // Copyright (c) 2010-2014 OPEN CASCADE SAS
3 // Copyright (c) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
4 // Copyright (c) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT,
5 // EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
7 // This file is part of Open CASCADE Technology software library.
9 // This library is free software; you can redistribute it and/or modify it under
10 // the terms of the GNU Lesser General Public License version 2.1 as published
11 // by the Free Software Foundation, with special exception defined in the file
12 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
13 // distribution for complete text of the license and disclaimer of any warranty.
15 // Alternatively, this file may be used under the terms of Open CASCADE
16 // commercial license or contractual agreement.
18 #ifndef _BOPAlgo_BuilderShape_HeaderFile
19 #define _BOPAlgo_BuilderShape_HeaderFile
21 #include <Standard.hxx>
22 #include <Standard_DefineAlloc.hxx>
23 #include <Standard_Handle.hxx>
25 #include <BOPAlgo_Algo.hxx>
26 #include <BRepTools_History.hxx>
28 #include <NCollection_BaseAllocator.hxx>
29 #include <TopoDS_Shape.hxx>
30 #include <TopTools_ListOfShape.hxx>
31 #include <TopTools_MapOfShape.hxx>
34 //! Root class for algorithms that has shape as result.
36 //! The class provides the History mechanism, which allows
37 //! tracking the modification of the input shapes during
38 //! the operation. It uses the *BRepTools_History* tool
39 //! as a storer for history objects.
40 class BOPAlgo_BuilderShape : public BOPAlgo_Algo
46 public: //! @name Getting the result
48 //! Returns the result of algorithm
49 const TopoDS_Shape& Shape() const { return myShape; }
52 public: //! @name History methods
54 //! Returns the list of shapes Modified from the shape theS.
55 const TopTools_ListOfShape& Modified(const TopoDS_Shape& theS)
57 if (myFillHistory && myHistory)
58 return myHistory->Modified(theS);
63 //! Returns the list of shapes Generated from the shape theS.
64 const TopTools_ListOfShape& Generated(const TopoDS_Shape& theS)
66 if (myFillHistory && myHistory)
67 return myHistory->Generated(theS);
72 //! Returns true if the shape theS has been deleted.
73 //! In this case the shape will have no Modified elements,
74 //! but can have Generated elements.
75 Standard_Boolean IsDeleted(const TopoDS_Shape& theS)
77 return (myFillHistory && myHistory ? myHistory->IsRemoved(theS) : Standard_False);
80 //! Returns true if any of the input shapes has been modified during operation.
81 Standard_Boolean HasModified() const
83 return (myFillHistory && myHistory ? myHistory->HasModified() : Standard_False);
86 //! Returns true if any of the input shapes has generated shapes during operation.
87 Standard_Boolean HasGenerated() const
89 return (myFillHistory && myHistory ? myHistory->HasGenerated() : Standard_False);
92 //! Returns true if any of the input shapes has been deleted during operation.
93 Standard_Boolean HasDeleted() const
95 return (myFillHistory && myHistory ? myHistory->HasRemoved() : Standard_False);
99 Handle(BRepTools_History) History()
103 if (myHistory.IsNull())
104 // It seems the algorithm has exited with error before filling
105 // the history. Initialize the History tool to return the empty
106 // History instead of NULL.
107 myHistory = new BRepTools_History();
112 // If the History has not been requested to be filled, return the NULL
113 // explicitly as the History may be partially filled for the algorithm's
118 public: //! @name Enabling/Disabling the history collection.
120 //! Allows disabling the history collection
121 void SetToFillHistory(const Standard_Boolean theHistFlag) { myFillHistory = theHistFlag; }
123 //! Returns flag of history availability
124 Standard_Boolean HasHistory() const { return myFillHistory; }
126 protected: //! @name Constructors
128 //! Empty constructor
129 BOPAlgo_BuilderShape()
132 myFillHistory(Standard_True)
135 //! Constructor with allocator
136 BOPAlgo_BuilderShape(const Handle(NCollection_BaseAllocator)& theAllocator)
138 BOPAlgo_Algo(theAllocator),
139 myFillHistory(Standard_True)
143 protected: //! @name Clearing
145 //! Clears the content of the algorithm.
146 virtual void Clear() Standard_OVERRIDE
148 BOPAlgo_Algo::Clear();
153 protected: //! @name Fields
155 TopoDS_Shape myShape; //!< Result of the operation
157 TopTools_ListOfShape myHistShapes; //!< Storer for the history shapes
158 TopTools_MapOfShape myMapShape; //!< cached map of all arguments shapes
160 Standard_Boolean myFillHistory; //!< Controls the history filling
161 Handle(BRepTools_History) myHistory; //!< History tool
165 #endif // _BOPAlgo_BuilderShape_HeaderFile