0031668: Visualization - WebGL sample doesn't work on Emscripten 1.39
[occt.git] / src / BOPAlgo / BOPAlgo_BuilderShape.hxx
CommitLineData
42cf5bc1 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
1155d05a 25#include <BOPAlgo_Algo.hxx>
948fe6ca 26#include <BRepTools_History.hxx>
27
28#include <Standard_Boolean.hxx>
29
1155d05a 30#include <NCollection_BaseAllocator.hxx>
42cf5bc1 31#include <TopoDS_Shape.hxx>
32#include <TopTools_ListOfShape.hxx>
1155d05a 33#include <TopTools_MapOfShape.hxx>
34#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
42cf5bc1 35class TopoDS_Shape;
36
948fe6ca 37//! Root class for algorithms that has shape as result.
38//!
33ba8565 39//! The class provides the History mechanism, which allows
40//! tracking the modification of the input shapes during
948fe6ca 41//! the operation. It uses the *BRepTools_History* tool
42//! as a storer for history objects.
43class BOPAlgo_BuilderShape : public BOPAlgo_Algo
42cf5bc1 44{
45public:
46
47 DEFINE_STANDARD_ALLOC
48
948fe6ca 49public: //! @name Getting the result
50
42cf5bc1 51 //! Returns the result of algorithm
948fe6ca 52 const TopoDS_Shape& Shape() const { return myShape; }
53
54
55public: //! @name History methods
56
57 //! Returns the list of shapes Modified from the shape theS.
58 const TopTools_ListOfShape& Modified(const TopoDS_Shape& theS)
59 {
60 if (myFillHistory && myHistory)
61 return myHistory->Modified(theS);
62 myHistShapes.Clear();
63 return myHistShapes;
64 }
65
66 //! Returns the list of shapes Generated from the shape theS.
67 const TopTools_ListOfShape& Generated(const TopoDS_Shape& theS)
68 {
69 if (myFillHistory && myHistory)
70 return myHistory->Generated(theS);
71 myHistShapes.Clear();
72 return myHistShapes;
73 }
74
42cf5bc1 75 //! Returns true if the shape theS has been deleted.
948fe6ca 76 //! In this case the shape will have no Modified elements,
77 //! but can have Generated elements.
78 Standard_Boolean IsDeleted(const TopoDS_Shape& theS)
79 {
80 return (myFillHistory && myHistory ? myHistory->IsRemoved(theS) : Standard_False);
81 }
82
83 //! Returns true if any of the input shapes has been modified during operation.
84 Standard_Boolean HasModified() const
85 {
86 return (myFillHistory && myHistory ? myHistory->HasModified() : Standard_False);
87 }
88
89 //! Returns true if any of the input shapes has generated shapes during operation.
90 Standard_Boolean HasGenerated() const
91 {
92 return (myFillHistory && myHistory ? myHistory->HasGenerated() : Standard_False);
93 }
94
95 //! Returns true if any of the input shapes has been deleted during operation.
96 Standard_Boolean HasDeleted() const
97 {
98 return (myFillHistory && myHistory ? myHistory->HasRemoved() : Standard_False);
99 }
100
101 //! History Tool
3dc58095 102 Handle(BRepTools_History) History()
948fe6ca 103 {
3dc58095 104 if (myFillHistory)
105 {
106 if (myHistory.IsNull())
107 // It seems the algorithm has exited with error before filling
108 // the history. Initialize the History tool to return the empty
109 // History instead of NULL.
110 myHistory = new BRepTools_History();
111
112 return myHistory;
113 }
114
115 // If the History has not been requested to be filled, return the NULL
116 // explicitly as the History may be partially filled for the algorithm's
117 // internal needs.
118 return NULL;
948fe6ca 119 }
120
121public: //! @name Enabling/Disabling the history collection.
122
123 //! Allows disabling the history collection
124 void SetToFillHistory(const Standard_Boolean theHistFlag) { myFillHistory = theHistFlag; }
125
126 //! Returns flag of history availability
127 Standard_Boolean HasHistory() const { return myFillHistory; }
128
129protected: //! @name Constructors
130
131 //! Empty constructor
132 BOPAlgo_BuilderShape()
133 :
134 BOPAlgo_Algo(),
135 myFillHistory(Standard_True)
136 {}
137
138 //! Constructor with allocator
139 BOPAlgo_BuilderShape(const Handle(NCollection_BaseAllocator)& theAllocator)
140 :
141 BOPAlgo_Algo(theAllocator),
142 myFillHistory(Standard_True)
143 {}
144
145
146protected: //! @name Clearing
147
148 //! Clears the content of the algorithm.
149 virtual void Clear() Standard_OVERRIDE
150 {
151 BOPAlgo_Algo::Clear();
152 myHistory.Nullify();
153 myMapShape.Clear();
154 }
155
156protected: //! @name Fields
157
158 TopoDS_Shape myShape; //!< Result of the operation
159
160 TopTools_ListOfShape myHistShapes; //!< Storer for the history shapes
161 TopTools_MapOfShape myMapShape; //!< Cashed map of all arguments shapes
162
163 Standard_Boolean myFillHistory; //!< Controls the history filling
164 Handle(BRepTools_History) myHistory; //!< History tool
42cf5bc1 165
42cf5bc1 166};
167
42cf5bc1 168#endif // _BOPAlgo_BuilderShape_HeaderFile