0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / BOPAlgo / BOPAlgo_BuilderShape.hxx
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
6 //
7 // This file is part of Open CASCADE Technology software library.
8 //
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.
14 //
15 // Alternatively, this file may be used under the terms of Open CASCADE
16 // commercial license or contractual agreement.
17
18 #ifndef _BOPAlgo_BuilderShape_HeaderFile
19 #define _BOPAlgo_BuilderShape_HeaderFile
20
21 #include <Standard.hxx>
22 #include <Standard_DefineAlloc.hxx>
23 #include <Standard_Handle.hxx>
24
25 #include <BOPAlgo_Algo.hxx>
26 #include <BRepTools_History.hxx>
27
28 #include <NCollection_BaseAllocator.hxx>
29 #include <TopoDS_Shape.hxx>
30 #include <TopTools_ListOfShape.hxx>
31 #include <TopTools_MapOfShape.hxx>
32 class TopoDS_Shape;
33
34 //! Root class for algorithms that has shape as result.
35 //!
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
41 {
42 public:
43
44   DEFINE_STANDARD_ALLOC
45
46 public: //! @name Getting the result
47
48   //! Returns the result of algorithm
49   const TopoDS_Shape& Shape() const { return myShape; }
50
51
52 public: //! @name History methods
53
54   //! Returns the list of shapes Modified from the shape theS.
55   const TopTools_ListOfShape& Modified(const TopoDS_Shape& theS)
56   {
57     if (myFillHistory && myHistory)
58       return myHistory->Modified(theS);
59     myHistShapes.Clear();
60     return myHistShapes;
61   }
62
63   //! Returns the list of shapes Generated from the shape theS.
64   const TopTools_ListOfShape& Generated(const TopoDS_Shape& theS)
65   {
66     if (myFillHistory && myHistory)
67       return myHistory->Generated(theS);
68     myHistShapes.Clear();
69     return myHistShapes;
70   }
71
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)
76   {
77     return (myFillHistory && myHistory ? myHistory->IsRemoved(theS) : Standard_False);
78   }
79
80   //! Returns true if any of the input shapes has been modified during operation.
81   Standard_Boolean HasModified() const
82   {
83     return (myFillHistory && myHistory ? myHistory->HasModified() : Standard_False);
84   }
85
86   //! Returns true if any of the input shapes has generated shapes during operation.
87   Standard_Boolean HasGenerated() const
88   {
89     return (myFillHistory && myHistory ? myHistory->HasGenerated() : Standard_False);
90   }
91
92   //! Returns true if any of the input shapes has been deleted during operation.
93   Standard_Boolean HasDeleted() const
94   {
95     return (myFillHistory && myHistory ? myHistory->HasRemoved() : Standard_False);
96   }
97
98   //! History Tool
99   Handle(BRepTools_History) History()
100   {
101     if (myFillHistory)
102     {
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();
108
109       return myHistory;
110     }
111
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
114     // internal needs.
115     return NULL;
116   }
117
118 public: //! @name Enabling/Disabling the history collection.
119
120   //! Allows disabling the history collection
121   void SetToFillHistory(const Standard_Boolean theHistFlag) { myFillHistory = theHistFlag; }
122
123   //! Returns flag of history availability
124   Standard_Boolean HasHistory() const { return myFillHistory; }
125
126 protected: //! @name Constructors
127
128   //! Empty constructor
129   BOPAlgo_BuilderShape()
130   :
131     BOPAlgo_Algo(),
132     myFillHistory(Standard_True)
133   {}
134
135   //! Constructor with allocator
136   BOPAlgo_BuilderShape(const Handle(NCollection_BaseAllocator)& theAllocator)
137   :
138     BOPAlgo_Algo(theAllocator),
139     myFillHistory(Standard_True)
140   {}
141
142
143 protected: //! @name Clearing
144
145   //! Clears the content of the algorithm.
146   virtual void Clear() Standard_OVERRIDE
147   {
148     BOPAlgo_Algo::Clear();
149     myHistory.Nullify();
150     myMapShape.Clear();
151   }
152
153 protected: //! @name Fields
154
155   TopoDS_Shape myShape; //!< Result of the operation
156
157   TopTools_ListOfShape myHistShapes;   //!< Storer for the history shapes
158   TopTools_MapOfShape myMapShape;      //!< cached map of all arguments shapes
159
160   Standard_Boolean myFillHistory;      //!< Controls the history filling
161   Handle(BRepTools_History) myHistory; //!< History tool
162
163 };
164
165 #endif // _BOPAlgo_BuilderShape_HeaderFile