58c394642dbb26064cc169d408c50ab6074da156
[occt.git] / src / BOPAlgo / BOPAlgo_MakerVolume.hxx
1 // Created by: Eugeny MALTCHIKOV
2 // Copyright (c) 2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15 #ifndef _BOPAlgo_MakerVolume_HeaderFile
16 #define _BOPAlgo_MakerVolume_HeaderFile
17
18 #include <Standard.hxx>
19 #include <Standard_DefineAlloc.hxx>
20 #include <Standard_Handle.hxx>
21 #include <Standard_Boolean.hxx>
22
23 #include <BOPAlgo_Builder.hxx>
24 #include <Bnd_Box.hxx>
25 #include <NCollection_BaseAllocator.hxx>
26 #include <TopoDS_Solid.hxx>
27 #include <TopTools_ListOfShape.hxx>
28 #include <TopTools_MapOfShape.hxx>
29 class TopoDS_Solid;
30 class BOPAlgo_PaveFiller;
31
32
33
34 //! The algorithm is to build solids from set of shapes.
35 //! It uses the BOPAlgo_Builder algorithm to intersect the given shapes
36 //! and build the images of faces (if needed) and BOPAlgo_BuilderSolid
37 //! algorithm to build the solids.
38 //!
39 //! Steps of the algorithm:
40 //! 1. Collect all faces: intersect the shapes if necessary and collect
41 //! the images of faces, otherwise just collect the faces to the
42 //! <myFaces> list;
43 //! All faces on this step added twice, with orientation FORWARD
44 //! and REVERSED;
45 //!
46 //! 2. Create bounding box covering all the faces from <myFaces> and
47 //! create solid box from corner points of that bounding box
48 //! (myBBox, mySBox). Add faces from that box to <myFaces>;
49 //!
50 //! 3. Build solids from <myFaces> using BOPAlgo_BuilderSolid algorithm;
51 //!
52 //! 4. Treat the result: Eliminate solid containig faces from <mySBox>;
53 //!
54 //! 5. Fill internal shapes: add internal vertices and edges into
55 //! created solids;
56 //!
57 //! 6. Prepare the history.
58 //!
59 //! Fields:
60 //! <myIntersect> - boolean flag. It defines whether intersect shapes
61 //! from <myArguments> (if set to TRUE) or not (FALSE).
62 //! The default value is TRUE. By setting it to FALSE
63 //! the user should guarantee that shapes in <myArguments>
64 //! do not interfere with each other, otherwise the result
65 //! is unpredictable.
66 //!
67 //! <myBBox>      - bounding box, covering all faces from <myFaces>.
68 //!
69 //! <mySBox>      - Solid box created from the corner points of <myBBox>.
70 //!
71 //! <myFaces>     - the list is to keep the "final" faces, that will be
72 //! given to the BOPAlgo_BuilderSolid algorithm.
73 //! If the shapes have been interfered it should contain
74 //! the images of the source shapes, otherwise its just
75 //! the original faces.
76 //! It also contains the faces from <mySBox>.
77 //!
78 //! Fields inherited from BOPAlgo_Builder:
79 //!
80 //! <myArguments> - list of the source shapes. The source shapes can have
81 //! any type, but each shape must not be self-interfered.
82 //!
83 //! <myShape>     - Result shape:
84 //! - empty compound - if no solids were created;
85 //! - solid - if created only one solid;
86 //! - compound of solids - if created more than one solid.
87 //!
88 //! Fields inherited from BOPAlgo_Algo:
89 //!
90 //! <myRunParallel> - Defines whether the parallel processing is
91 //! switched on or not.
92 //! <myReport> - Error status of the operation. Additionally to the
93 //! errors of the parent algorithm it can have the following values:
94 //! - *BOPAlgo_AlertSolidBuilderFailed* - BOPAlgo_BuilderSolid algorithm has failed.
95 //!
96 //! Example:
97 //!
98 //! BOPAlgo_MakerVolume aMV;
99 //! //
100 //! aMV.SetArguments(aLS); //source shapes
101 //! aMV.SetRunParallel(bRunParallel); //parallel or single mode
102 //! aMV.SetIntersect(bIntersect); //intersect or not the shapes from <aLS>
103 //! //
104 //! aMV.Perform(); //perform the operation
105 //! if (aMV.HasErrors()) { //check error status
106 //!   return;
107 //! }
108 //! //
109 //! const TopoDS_Shape& aResult = aMV.Shape();  //result of the operation
110 class BOPAlgo_MakerVolume  : public BOPAlgo_Builder
111 {
112 public:
113
114   DEFINE_STANDARD_ALLOC
115
116   
117
118   //! Empty contructor.
119   BOPAlgo_MakerVolume();
120   virtual ~BOPAlgo_MakerVolume();
121
122   //! Empty contructor.
123   BOPAlgo_MakerVolume(const Handle(NCollection_BaseAllocator)& theAllocator);
124
125   //! Clears the data.
126   virtual void Clear() Standard_OVERRIDE;
127
128   //! Sets the flag myIntersect:
129   //! if <bIntersect> is TRUE the shapes from <myArguments> will be intersected.
130   //! if <bIntersect> is FALSE no intersection will be done.
131   void SetIntersect(const Standard_Boolean bIntersect);
132
133   //! Returns the flag <myIntersect>.
134   Standard_Boolean IsIntersect() const;
135
136   //! Returns the solid box <mySBox>.
137   const TopoDS_Solid& Box() const;
138
139   //! Returns the processed faces <myFaces>.
140   const TopTools_ListOfShape& Faces() const;
141
142   //! Defines the preventing of addition of internal for solid parts into the result.
143   //! By default the internal parts are added into result.
144   Standard_EXPORT void SetAvoidInternalShapes(const Standard_Boolean theAvoidInternal) {
145     myAvoidInternalShapes = theAvoidInternal;
146   }
147
148   //! Returns the AvoidInternalShapes flag
149   Standard_EXPORT Standard_Boolean IsAvoidInternalShapes() const {
150     return myAvoidInternalShapes;
151   }
152
153   //! Performs the operation.
154   Standard_EXPORT virtual void Perform() Standard_OVERRIDE;
155
156 protected:
157
158   //! Checks the data.
159   Standard_EXPORT virtual void CheckData() Standard_OVERRIDE;
160
161   //! Performs the operation.
162   Standard_EXPORT virtual void PerformInternal1 (const BOPAlgo_PaveFiller& thePF) Standard_OVERRIDE;
163
164   //! Collects all faces.
165   Standard_EXPORT void CollectFaces();
166
167   //! Makes solid box.
168   Standard_EXPORT void MakeBox (TopTools_MapOfShape& theBoxFaces);
169
170   //! Builds solids.
171   Standard_EXPORT void BuildSolids (TopTools_ListOfShape& theLSR);
172
173   //! Removes the covering box.
174   Standard_EXPORT void RemoveBox (TopTools_ListOfShape& theLSR, const TopTools_MapOfShape& theBoxFaces);
175
176   //! Fills the solids with internal shapes.
177   Standard_EXPORT void FillInternalShapes (const TopTools_ListOfShape& theLSR);
178
179   //! Builds the result.
180   Standard_EXPORT void BuildShape (const TopTools_ListOfShape& theLSR);
181
182
183   Standard_Boolean myIntersect;
184   Bnd_Box myBBox;
185   TopoDS_Solid mySBox;
186   TopTools_ListOfShape myFaces;
187   Standard_Boolean myAvoidInternalShapes;
188
189 private:
190
191 };
192
193 #include <BOPAlgo_MakerVolume.lxx>
194
195 #endif // _BOPAlgo_MakerVolume_HeaderFile