0031682: Visualization - Prs3d_ShadingAspect::SetTransparency() has no effect with...
[occt.git] / src / BOPAlgo / BOPAlgo_CellsBuilder.hxx
1 // Created by: Eugeny MALTCHIKOV
2 // Copyright (c) 2015 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
16 #ifndef _BOPAlgo_CellsBuilder_HeaderFile
17 #define _BOPAlgo_CellsBuilder_HeaderFile
18
19 #include <Standard_DefineAlloc.hxx>
20 #include <Standard_Handle.hxx>
21 #include <Standard_OStream.hxx>
22
23 #include <TopoDS_Shape.hxx>
24
25 #include <TopAbs_ShapeEnum.hxx>
26 #include <TopTools_MapOfShape.hxx>
27 #include <BOPAlgo_Builder.hxx>
28
29 #include <TopTools_ListOfShape.hxx>
30 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
31 #include <TopTools_DataMapOfIntegerListOfShape.hxx>
32 #include <TopTools_DataMapOfShapeInteger.hxx>
33 #include <TopTools_DataMapOfShapeShape.hxx>
34
35 //!
36 //! The algorithm is based on the General Fuse algorithm (GFA). The result of
37 //! GFA is all split parts of the Arguments.<br>
38 //!
39 //! The purpose of this algorithm is to provide the result with the content of:<br>
40 //! 1. Cells (parts) defined by the user;<br>
41 //! 2. Internal boundaries defined by the user.<br>
42 //!
43 //! In other words the algorithm should provide the possibility for the user
44 //! to add or remove any part to (from) result and remove any internal boundaries
45 //! between parts.<br>
46 //!
47 //! Requirements for the Data:<br>
48 //! All the requirements of GFA for the DATA are inherited in this algorithm -
49 //! The arguments could be of any type (dimension) and should be valid in terms of
50 //! BRepCheck_Analyzer and BOPAlgo_ArgumentAnalyzer.<br>
51 //!
52 //! Results:<br>
53 //! The result of the algorithm is compound containing selected parts of
54 //! the basic types (VERTEX, EDGE, FACE or SOLID). The default result
55 //! is empty compound. It is possible to add any split part to the result
56 //! by using the methods AddToRessult() and AddAllToResult().
57 //! It is also possible to remove any part from the result by using methods
58 //! RemoveFromResult() and RemoveAllFromResult().
59 //! The method RemoveAllFromResult() is also suitable for clearing the result.<br>
60 //!
61 //! To remove Internal boundaries it is necessary to set the same material to the
62 //! parts between which the boundaries should be removed and call the method
63 //! RemoveInternalBoundaries(). The material should not be equal to 0, as this is
64 //! default material value. The boundaries between parts with this value
65 //! will not be removed.
66 //! One part cannot be added with the different materials.
67 //! It is also possible to remove the boundaries during combining the result.
68 //! To do this it is necessary to set the material for parts (not equal to 0)
69 //! and set the flag bUpdate to TRUE.
70 //! For the arguments of the types FACE or EDGE it is recommended
71 //! to remove the boundaries in the end when the result is completely built.
72 //! It will help to avoid self-intersections in the result.<br>
73 //! Note, that if the result contains the parts with same material but of different
74 //! dimension the boundaries between such parts will not be removed. Currently,
75 //! the removal of the internal boundaries between multi-dimensional shapes is not supported.<br>
76 //!
77 //! It is possible to create typed Containers from the parts added to result by using
78 //! method MakeContainers(). The type of the containers will depend on the type of
79 //! the arguments: WIRES for EEDGE, SHELLS for FACES and COMPSOLIDS for SOLIDS.
80 //! The result will be compound containing containers.
81 //! Adding of the parts to such result will not update containers. The result
82 //! compound will contain the containers and new added parts (of basic type).
83 //! Removing of the parts from such result may affect some containers if
84 //! the parts that should be removed is in container. In this case this container
85 //! will be rebuilt without that part.<br>
86 //!
87 //! History:<br>
88 //! The algorithm supports history information for basic types of the shapes -
89 //! VERTEX, EDGE, FACE. This information available through the methods
90 //! IsDeleted() and Modified().<br>
91 //! In DRAW Test Harness it is available through the same
92 //! commands as for Boolean Operations (bmodified, bgenerated and bisdeleted).<br>
93 //!
94 //! The algorithm can return the following Error Statuses:
95 //! - Error status acquired in the General Fuse algorithm.
96 //! The Error status can be checked with HasErrors() method.
97 //! If the Error status is not equal to zero, the result cannot be trustworthy.
98 //!
99 //! The algorithm can set the following Warning Statuses:
100 //! - Warning status acquired in the General Fuse algorithm;
101 //! - BOPAlgo_AlertRemovalOfIBForMDimShapes
102 //! - BOPAlgo_AlertRemovalOfIBForFacesFailed
103 //! - BOPAlgo_AlertRemovalOfIBForEdgesFailed
104 //! - BOPAlgo_AlertRemovalOfIBForSolidsFailed
105 //!
106 //! The Warning status can be checked with HasWarnings() method or
107 //! printed with the DumpWarnings() method. If warnings are recorded,
108 //! the result may be not as expected.<br>
109 //!
110 //! Examples:<br>
111 //! 1. API<br>
112 //! BOPAlgo_CellsBuilder aCBuilder;<br>
113 //! TopTools_ListOfShape aLS = ...; // arguments<br>
114 //! /* parallel or single mode (the default value is FALSE)*/<br>
115 //! Standard_Boolean bRunParallel = Standard_False;<br>
116 //! /* fuzzy option (default value is 0)*/<br>
117 //! Standard_Real aTol = 0.0;<br>
118 //! //<br>
119 //! aCBuilder.SetArguments(aLS);<br>
120 //! aCBuilder.SetRunParallel(bRunParallel);<br>
121 //! aCBuilder.SetFuzzyValue(aTol);<br>
122 //! //<br>
123 //! aCBuilder.Perform();<br>
124 //! if (aCBuilder.HasErrors()) { // check error status<br>
125 //!   return;<br>
126 //! }<br>
127 //! /* empty compound, as nothing has been added yet */<br>
128 //! const TopoDS_Shape& aRes = aCBuilder.Shape();<br>
129 //! /* all split parts */<br>
130 //! const TopoDS_Shape& aRes = aCBuilder.GetAllParts();<br>
131 //! //<br>
132 //! TopTools_ListOfShape aLSToTake = ...; // parts of these arguments will be taken into result<br>
133 //! TopTools_ListOfShape aLSToAvoid = ...; // parts of these arguments will not be taken into result<br>
134 //! //<br>
135 //! /* defines the material common for the cells, i.e. 
136 //!    the boundaries between cells with the same material
137 //!    will be removed.<br>
138 //!    By default it is set to 0. Thus, to remove some boundary
139 //!    the value of this variable should not be equal to 0 */<br>
140 //! Standard_Integer iMaterial = ...;<br>
141 //! /* defines whether to update the result right now or not */<br>
142 //! Standard_Boolean bUpdate = ...;<br>
143 //! // adding to result<br>
144 //! aCBuilder.AddToResult(aLSToTake, aLSToAvoid, iMaterial, bUpdate);<br>
145 //! aR = aCBuilder.Shape(); // the result<br>
146 //! // removing of the boundaries (should be called only if bUpdate is false)<br>
147 //! aCBuilder.RemoveInternalBoundaries();<br>
148 //! //<br>
149 //! // removing from result<br>
150 //! aCBuilder.AddAllToResult();<br>
151 //! aCBuilder.RemoveFromResult(aLSToTake, aLSToAvoid);<br>
152 //! aR = aCBuilder.Shape(); // the result<br>
153 //! <br>
154 //!
155 //! 2. DRAW Test Harness<br>
156 //! psphere s1 15<br>
157 //! psphere s2 15<br>
158 //! psphere s3 15<br>
159 //! ttranslate s1 0 0 10<br>
160 //! ttranslate s2 20 0 10<br>
161 //! ttranslate s3 10 0 0<br>
162 //! \# adding arguments<br>
163 //! bclearobjects; bcleartools<br>
164 //! baddobjects s1 s2 s3<br>
165 //! \# intersection<br>
166 //! bfillds<br>
167 //! \# rx will contain all split parts<br>
168 //! bcbuild rx<br>
169 //! \# add to result the part that is common for all three spheres<br>
170 //! bcadd res s1 1 s2 1 s3 1 -m 1<br>
171 //! \# add to result the part that is common only for first and third spheres<br>
172 //! bcadd res s1 1 s2 0 s3 1 -m 1<br>
173 //! \# remove internal boundaries<br>
174 //! bcremoveint res<br>
175 //!
176 class BOPAlgo_CellsBuilder : public BOPAlgo_Builder
177 {
178  public:
179
180   DEFINE_STANDARD_ALLOC
181
182   Standard_EXPORT BOPAlgo_CellsBuilder();
183
184   Standard_EXPORT BOPAlgo_CellsBuilder(const Handle(NCollection_BaseAllocator)& theAllocator);
185
186   Standard_EXPORT virtual ~BOPAlgo_CellsBuilder();
187
188   //! Redefined method Clear - clears the contents.
189   Standard_EXPORT virtual void Clear() Standard_OVERRIDE;
190
191   //! Adding the parts to result.<br>
192   //! The parts are defined by two lists of shapes:<br>
193   //! <theLSToTake> defines the arguments which parts should be taken into result;<br>
194   //! <theLSToAvoid> defines the arguments which parts should not be taken into result;<br>
195   //! To be taken into result the part must be IN for all shapes from the list
196   //! <theLSToTake> and must be OUT of all shapes from the list <theLSToAvoid>.<br>
197   //! 
198   //! To remove internal boundaries between any cells in the result
199   //! <theMaterial> variable should be used. The boundaries between
200   //! cells with the same material will be removed. Default value is 0.<br>
201   //! Thus, to remove any boundary the value of this variable should not be equal to 0.<br>
202   //! <theUpdate> parameter defines whether to remove boundaries now or not.
203   Standard_EXPORT void AddToResult(const TopTools_ListOfShape& theLSToTake,
204                                    const TopTools_ListOfShape& theLSToAvoid,
205                                    const Standard_Integer theMaterial = 0,
206                                    const Standard_Boolean theUpdate = Standard_False);
207
208   //! Add all split parts to result.<br>
209   //! <theMaterial> defines the removal of internal boundaries;<br>
210   //! <theUpdate> parameter defines whether to remove boundaries now or not.
211   Standard_EXPORT void AddAllToResult(const Standard_Integer theMaterial = 0,
212                                       const Standard_Boolean theUpdate = Standard_False);
213
214   //! Removing the parts from result.<br>
215   //! The parts are defined by two lists of shapes:<br>
216   //! <theLSToTake> defines the arguments which parts should be removed from result;<br>
217   //! <theLSToAvoid> defines the arguments which parts should not be removed from result.<br>
218   //! To be removed from the result the part must be IN for all shapes from the list
219   //! <theLSToTake> and must be OUT of all shapes from the list <theLSToAvoid>.
220   Standard_EXPORT void RemoveFromResult(const TopTools_ListOfShape& theLSToTake,
221                                         const TopTools_ListOfShape& theLSToAvoid);
222
223   //! Remove all parts from result.
224   Standard_EXPORT void RemoveAllFromResult();
225
226   //! Removes internal boundaries between cells with the same material.<br>
227   //! If the result contains the cells with same material but of different dimension
228   //! the removal of internal boundaries between these cells will not be performed.<br>
229   //! In case of some errors during the removal the method will set the appropriate warning 
230   //! status - use GetReport() to access them.
231   Standard_EXPORT void RemoveInternalBoundaries();
232
233   //! Get all split parts.
234   Standard_EXPORT const TopoDS_Shape& GetAllParts() const;
235
236   //! Makes the Containers of proper type from the parts added to result.
237   Standard_EXPORT void MakeContainers();
238
239  protected:
240
241   //! Prepare information for history support taking into account
242   //! local modification map of unified elements - myMapModified.
243   Standard_EXPORT virtual const TopTools_ListOfShape* LocModified(const TopoDS_Shape& theS) Standard_OVERRIDE;
244
245   //! Redefined method PerformInternal1 - makes all split parts,
246   //! nullifies the result <myShape>, and index all parts.
247   Standard_EXPORT virtual void PerformInternal1 (const BOPAlgo_PaveFiller& thePF) Standard_OVERRIDE;
248
249   //! Indexes the parts for quick access to the arguments.
250   Standard_EXPORT void IndexParts();
251
252   //! Looking for the parts defined by two lists.
253   Standard_EXPORT void FindParts(const TopTools_ListOfShape& theLSToTake,
254                                  const TopTools_ListOfShape& theLSToAvoid,
255                                  TopTools_ListOfShape& theParts);
256
257   //! Removes internal boundaries between cells with the same material.<br>
258   //! Returns TRUE if any internal boundaries have been removed.
259   Standard_EXPORT Standard_Boolean RemoveInternals(const TopTools_ListOfShape& theLS,
260                                                    TopTools_ListOfShape& theLSNew,
261                                                    const TopTools_MapOfShape& theMapKeepBnd = TopTools_MapOfShape());
262
263   // fields
264   TopoDS_Shape myAllParts;                           //!< All split parts of the arguments
265   TopTools_IndexedDataMapOfShapeListOfShape myIndex; //!< Connection map from all splits parts to the argument shapes from which they were created
266   TopTools_DataMapOfIntegerListOfShape myMaterials;  //!< Map of assigned materials (material -> list of shape)
267   TopTools_DataMapOfShapeInteger myShapeMaterial;    //!< Map of assigned materials (shape -> material)
268   TopTools_DataMapOfShapeShape myMapModified;        //!< Local modification map to track unification of the splits
269 };
270
271 #endif //_BOPAlgo_CellsBuilder_HeaderFile