Salome HOME
updated copyright message
[modules/geom.git] / src / GEOMAlgo / GEOMAlgo_Extractor.hxx
1 // Copyright (C) 2007-2023  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // File:        GEOMAlgo_Extractor.hxx
24 // Author:      Sergey KHROMOV
25
26 #ifndef _GEOMAlgo_Extractor_HeaderFile
27 #define _GEOMAlgo_Extractor_HeaderFile
28
29
30 #include <GEOMAlgo_Algo.hxx>
31
32 #include <NCollection_List.hxx>
33 #include <TopoDS_Shape.hxx>
34 #include <TopTools_DataMapOfShapeListOfShape.hxx>
35 #include <TopTools_ListOfShape.hxx>
36 #include <TopTools_MapOfShape.hxx>
37 #include <TopTools_IndexedMapOfShape.hxx>
38
39
40 /**
41  * \brief This class encapsulates an algorithm of extraction of sub-shapes
42  * from the main shape.
43  */
44 class GEOMAlgo_Extractor : public GEOMAlgo_Algo
45 {
46 public:
47
48   /**
49    * \brief Empty constructor.
50    */
51   Standard_EXPORT GEOMAlgo_Extractor();
52
53   /**
54    * \brief Virtual destructor.
55    */
56   Standard_EXPORT virtual ~GEOMAlgo_Extractor();
57
58   /**
59    * \brief This method sets the main shape.
60    *
61    * \param theShape the main shape.
62    */
63   Standard_EXPORT void SetShape(const TopoDS_Shape &theShape);
64
65   /**
66    * \brief This method returns the main shape.
67    *
68    * \return the main shape.
69    */
70   const TopoDS_Shape &GetShape() const
71   { return myShape; }
72
73   /**
74    * \brief This method sets the list of sub-shapes to be removed
75    *  from the main shape.
76    *
77    * \param theSubShapes the sub-shapes to be removed.
78    */
79   Standard_EXPORT void SetShapesToRemove
80       (const TopTools_ListOfShape &theSubShapes);
81
82   /**
83    * \brief This method returns the list of sub-shapes to be removed
84    *  from the main shape.
85    *
86    * \return the list of sub-shapes to be removed.
87    */
88   const TopTools_ListOfShape &GetShapesToRemove() const
89   { return mySubShapes; }
90
91   /**
92    * This method performs computation of the extracted shape.
93    */
94   Standard_EXPORT virtual void Perform();
95
96   /**
97    * This method returns the result of the algorithm.
98    *
99    * \return the result of the operation.
100    */
101   Standard_EXPORT const TopoDS_Shape &GetResult() const;
102
103   /**
104    * \brief This method returns the sub-shapes removed from the main shape.
105    *
106    * \return the list of removed sub-shapes.
107    */
108   const TopTools_ListOfShape &GetRemoved() const
109   { return myRemoved; }
110
111   /**
112    * \brief This method returns the sub-shapes modified in the main shape.
113    *
114    * \return the list of modified sub-shapes.
115    */
116   const TopTools_ListOfShape &GetModified() const
117   { return myModified; }
118
119   /**
120    * \brief This method returns the newly created sub-shapes in the result
121    * shape.
122    *
123    * \return the list of new sub-shapes in result.
124    */
125   const TopTools_ListOfShape &GetNew() const
126   { return myNew; }
127
128 private:
129
130   /**
131    * \brief This method reinitializes the shape.
132    */
133   void clear();
134
135   /**
136    * \brief This method checks the input data.
137    */
138   void checkData();
139
140   /**
141    * \brief This method fills the map of shapes and ancestors for the whole
142    * sub-shapes of theShape. This method is recursively called up to the lowest
143    * level of sub-shapes i.e. vertices.
144    *
145    * \param theShape the shape.
146    */
147   void makeMapShapeAncestors(const TopoDS_Shape &theShape);
148
149   /**
150    * \brief This method marks shapes to be removed and to be modified.
151    */
152   void markShapes();
153
154   /**
155    * \brief This method marks theShape to be removed. If it is required, it
156    * recursively marks its sub-shapes to be removed.
157    *
158    * \param theShape the shape.
159    */
160   void markRemoved(const TopoDS_Shape &theShape);
161
162   /**
163    * \brief This method marks ancestors of theShape to be modified. It is
164    * recursively called up to the level of main shape.
165    *
166    * \param theShape the shape.
167    */
168   void markAncestorsModified(const TopoDS_Shape &theShape);
169
170   /**
171    * \brief This method performs computation of modified shapes of
172    *  the provided type.
173    *
174    * \param theType the processed shape type.
175    */
176   void processShapes(const TopAbs_ShapeEnum &theType);
177
178   /**
179    * \brief This method performs computation of a modified edge. 
180    *
181    * \param theEdge the modified edge (should be forward).
182    */
183   void processEdge(const TopoDS_Shape &theEdge);
184
185   /**
186    * \brief This method performs computation of a modified wire.
187    *
188    * \param theWire the modified wire (should be forward).
189    */
190   void processWire(const TopoDS_Shape &theWire);
191
192   /**
193    * \brief This method performs computation of a modified face or solid.
194    *
195    * \param theFOrSo the modified face or solid (should be forward).
196    */
197   void processFOrSo(const TopoDS_Shape &theFOrSo);
198
199   /**
200    * \brief This method performs computation of a modified shell or comp-solid.
201    *
202    * \param theShOrCS the modified shell or comp-solid (should be forward).
203    */
204   void processShOrCS(const TopoDS_Shape &theShOrCS);
205
206   /**
207    * \brief This method performs computation of a modified compound.
208    *
209    * \param theCompound the modified compound (should be forward).
210    */
211   void processCompound(const TopoDS_Shape &theCompound);
212
213   /**
214    * \brief This method removes hanging edges (faces) built for faces (solids)
215    * if they lie on created faces (solids).
216    *
217    * \param theType the shape type. Should be either face or solid.
218    */
219   void removeBoundsOnFOrSo(const TopAbs_ShapeEnum theType);
220
221   /**
222    * \brief Returns theShape with an orientation composed with theContext's
223    * orientation.
224    *
225    * \param theShape the shape to be re-oriented.
226    * \param theContext the context shape.
227    */
228   TopoDS_Shape oriented(const TopoDS_Shape &theShape,
229                         const TopoDS_Shape &theContext);
230
231   /**
232    * \brief This method makes a shape as an empty copy of theShape adding
233    * subshapes to it.
234    *
235    * \param theShape the shape to be copied (should be forward).
236    * \param theSubShapes the sub-shapes (should be oriented correctly).
237    * \return the modified shape.
238    */
239   TopoDS_Shape makeShape(const TopoDS_Shape         &theShape,
240                          const TopTools_ListOfShape &theSubShapes);
241
242   /**
243    * \brief This method returns the shape from the list of sub-shapes
244    * if there is any shape created already with these sub-shapes.
245    * If there is no such shape, null shape is returned.
246    *
247    * \param theShape the shape to be copied (should be forward).
248    * \param theSubShapes the sub-shapes (should be oriented correctly).
249    * \return the modified shape (or null if it is not found).
250    */
251   TopoDS_Shape getShapeFromSubShapes(const TopoDS_Shape         &theShape,
252                                      const TopTools_ListOfShape &theSubShapes);
253
254   /**
255    * \brief This method makes the result for the given shape. If it is removed
256    * the result is a compound of its modified sub-shapes (or a single
257    * modified sub-shape if it in only one).
258    *
259    * \param theShape the shape.
260    * \return the result.
261    */
262   TopoDS_Shape makeResult(const TopoDS_Shape &theShape);
263
264   /**
265    * \brief This method fills the lists of shapes myRemoved, myModified and
266    * myNew with removed, modified and newly created shapes correspondingly.
267    * This method is called recursively for sub-shapes of the shape.
268    *
269    * \param theShape the shape.
270    * \param theMapFence the map of already treated shapes.
271    */
272   void makeHistory(const TopoDS_Shape        &theShape,
273                          TopTools_MapOfShape &theMapFence);
274
275   /**
276    * \brief This method removes edges that are in theMapEdgesToRm from
277    * theWire and re-creates one or more wires from the rest edges. theNewWires
278    * contains the modified wire(s).
279    *
280    * \param theWire the input wire.
281    * \param theMapEdgesToRm the map of edges to be extracted from theWire.
282    * \param theNewWires is the list of new wires. Output parameter.
283    * \return Standard_True if theWire is modified; Standard_False otherwise.
284    */
285   Standard_Boolean removeCommonEdges
286                      (const TopoDS_Shape               &theWire,
287                       const TopTools_IndexedMapOfShape &theMapEdgesToRm,
288                             TopTools_ListOfShape       &theNewWires);
289
290   /**
291    * \brief This method removes faces that are in theMapFacesToRm from
292    * theShell and re-creates one or more shells from the rest faces.
293    * theNewShells contains the modified shell(s).
294    *
295    * \param theShell the input shell.
296    * \param theMapFacesToRm the map of faces to be extracted from theShell.
297    * \param theNewShells is the list of new shells. Output parameter.
298    * \return Standard_True if theShell is modified; Standard_False otherwise.
299    */
300   Standard_Boolean removeCommonFaces
301                      (const TopoDS_Shape               &theShell,
302                       const TopTools_IndexedMapOfShape &theMapFacesToRm,
303                             TopTools_ListOfShape       &theNewShells);
304
305   /**
306    * \brief This method creates wires from the list of list of edges.
307    *
308    * \param theWire the input wire.
309    * \param theListListEdges the list of list of edges. Can be modified
310    *        on output.
311    * \param theWires the list of created wires. Output parameter.
312    */
313   void makeWires(const TopoDS_Shape                           &theWire,
314                        NCollection_List<TopTools_ListOfShape> &theListListEdges,
315                        TopTools_ListOfShape                   &theWires);
316
317   /**
318    * \brief This method collects the shapes in theShapes via common bounds.
319    * This method is used to group faces into shells via common edges or
320    * solids into compsolids via common faces. Collected lists of shapes
321    * are used to create new shapes from theShape that are returned in
322    * theNewShapes. theNewShapes is not cleared at first.
323    *
324    * \param theShape the original shape.
325    * \param theSubShapes the list of shapes to be connected.
326    * \param theNewShapes the list of newly created shapes. Output parameter.
327    */
328   void groupViaBounds(const TopoDS_Shape         &theShape,
329                       const TopTools_ListOfShape &theSubShapes,
330                             TopTools_ListOfShape &theNewShapes);
331
332   /**
333    * \brief This method returns the list of modified shapes obtained
334    * from theShape. It performs recursive search in myMapModified.
335    * theModifShapes is not cleared at first. If theShapeType filter is equal
336    * to TopAbs_SHAPE (default value) all modified shapes will be returned,
337    * otherwise shapes of particular type will only be returned.
338    *
339    * \param theShape the shape examined.
340    * \param theModifShapes the list of modified shapes. Output parameter.
341    * \param theShapeType the shape type filter.
342    */
343   void getModified(const TopoDS_Shape         &theShape,
344                          TopTools_ListOfShape &theModifShapes,
345                    const TopAbs_ShapeEnum      theShapeType = TopAbs_SHAPE);
346
347 protected:
348
349   TopoDS_Shape                       myShape;
350   TopoDS_Shape                       myResult;
351   TopTools_ListOfShape               mySubShapes;
352   TopTools_ListOfShape               myRemoved;
353   TopTools_ListOfShape               myModified;
354   TopTools_ListOfShape               myNew;
355   TopTools_DataMapOfShapeListOfShape myMapShapeAnc;
356   TopTools_MapOfShape                myMapRemoved;
357   TopTools_DataMapOfShapeListOfShape myMapModified;
358   TopTools_DataMapOfShapeListOfShape myMapNewShapeAnc;
359
360 };
361
362 #endif