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