1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File: GEOMAlgo_Extractor.hxx
24 // Author: Sergey KHROMOV
26 #ifndef _GEOMAlgo_Extractor_HeaderFile
27 #define _GEOMAlgo_Extractor_HeaderFile
30 #include <GEOMAlgo_Algo.hxx>
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>
41 * \brief This class encapsulates an algorithm of extraction of sub-shapes
42 * from the main shape.
44 class GEOMAlgo_Extractor : public GEOMAlgo_Algo
49 * \brief Empty constructor.
51 Standard_EXPORT GEOMAlgo_Extractor();
54 * \brief Virtual destructor.
56 Standard_EXPORT virtual ~GEOMAlgo_Extractor();
59 * \brief This method sets the main shape.
61 * \param theShape the main shape.
63 Standard_EXPORT void SetShape(const TopoDS_Shape &theShape);
66 * \brief This method returns the main shape.
68 * \return the main shape.
70 const TopoDS_Shape &GetShape() const
74 * \brief This method sets the list of sub-shapes to be removed
75 * from the main shape.
77 * \param theSubShapes the sub-shapes to be removed.
79 Standard_EXPORT void SetShapesToRemove
80 (const TopTools_ListOfShape &theSubShapes);
83 * \brief This method returns the list of sub-shapes to be removed
84 * from the main shape.
86 * \return the list of sub-shapes to be removed.
88 const TopTools_ListOfShape &GetShapesToRemove() const
89 { return mySubShapes; }
92 * This method performs computation of the extracted shape.
94 Standard_EXPORT virtual void Perform();
97 * This method returns the result of the algorithm.
99 * \return the result of the operation.
101 Standard_EXPORT const TopoDS_Shape &GetResult() const;
104 * \brief This method returns the sub-shapes removed from the main shape.
106 * \return the list of removed sub-shapes.
108 const TopTools_ListOfShape &GetRemoved() const
109 { return myRemoved; }
112 * \brief This method returns the sub-shapes modified in the main shape.
114 * \return the list of modified sub-shapes.
116 const TopTools_ListOfShape &GetModified() const
117 { return myModified; }
120 * \brief This method returns the newly created sub-shapes in the result
123 * \return the list of new sub-shapes in result.
125 const TopTools_ListOfShape &GetNew() const
131 * \brief This method reinitializes the shape.
136 * \brief This method checks the input data.
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.
145 * \param theShape the shape.
147 void makeMapShapeAncestors(const TopoDS_Shape &theShape);
150 * \brief This method marks shapes to be removed and to be modified.
155 * \brief This method marks theShape to be removed. If it is required, it
156 * recursively marks its sub-shapes to be removed.
158 * \param theShape the shape.
160 void markRemoved(const TopoDS_Shape &theShape);
163 * \brief This method marks ancestors of theShape to be modified. It is
164 * recursively called up to the level of main shape.
166 * \param theShape the shape.
168 void markAncestorsModified(const TopoDS_Shape &theShape);
171 * \brief This method performs computation of modified shapes of
174 * \param theType the processed shape type.
176 void processShapes(const TopAbs_ShapeEnum &theType);
179 * \brief This method performs computation of a modified edge.
181 * \param theEdge the modified edge (should be forward).
183 void processEdge(const TopoDS_Shape &theEdge);
186 * \brief This method performs computation of a modified wire.
188 * \param theWire the modified wire (should be forward).
190 void processWire(const TopoDS_Shape &theWire);
193 * \brief This method performs computation of a modified face or solid.
195 * \param theFOrSo the modified face or solid (should be forward).
197 void processFOrSo(const TopoDS_Shape &theFOrSo);
200 * \brief This method performs computation of a modified shell or comp-solid.
202 * \param theShOrCS the modified shell or comp-solid (should be forward).
204 void processShOrCS(const TopoDS_Shape &theShOrCS);
207 * \brief This method performs computation of a modified compound.
209 * \param theCompound the modified compound (should be forward).
211 void processCompound(const TopoDS_Shape &theCompound);
214 * \brief This method removes hanging edges (faces) built for faces (solids)
215 * if they lie on created faces (solids).
217 * \param theType the shape type. Should be either face or solid.
219 void removeBoundsOnFOrSo(const TopAbs_ShapeEnum theType);
222 * \brief Returns theShape with an orientation composed with theContext's
225 * \param theShape the shape to be re-oriented.
226 * \param theContext the context shape.
228 TopoDS_Shape oriented(const TopoDS_Shape &theShape,
229 const TopoDS_Shape &theContext);
232 * \brief This method makes a shape as an empty copy of theShape adding
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.
239 TopoDS_Shape makeShape(const TopoDS_Shape &theShape,
240 const TopTools_ListOfShape &theSubShapes);
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.
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).
251 TopoDS_Shape getShapeFromSubShapes(const TopoDS_Shape &theShape,
252 const TopTools_ListOfShape &theSubShapes);
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).
259 * \param theShape the shape.
260 * \return the result.
262 TopoDS_Shape makeResult(const TopoDS_Shape &theShape);
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.
269 * \param theShape the shape.
270 * \param theMapFence the map of already treated shapes.
272 void makeHistory(const TopoDS_Shape &theShape,
273 TopTools_MapOfShape &theMapFence);
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).
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.
285 Standard_Boolean removeCommonEdges
286 (const TopoDS_Shape &theWire,
287 const TopTools_IndexedMapOfShape &theMapEdgesToRm,
288 TopTools_ListOfShape &theNewWires);
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).
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.
300 Standard_Boolean removeCommonFaces
301 (const TopoDS_Shape &theShell,
302 const TopTools_IndexedMapOfShape &theMapFacesToRm,
303 TopTools_ListOfShape &theNewShells);
306 * \brief This method creates wires from the list of list of edges.
308 * \param theWire the input wire.
309 * \param theListListEdges the list of list of edges. Can be modified
311 * \param theWires the list of created wires. Output parameter.
313 void makeWires(const TopoDS_Shape &theWire,
314 NCollection_List<TopTools_ListOfShape> &theListListEdges,
315 TopTools_ListOfShape &theWires);
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.
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.
328 void groupViaBounds(const TopoDS_Shape &theShape,
329 const TopTools_ListOfShape &theSubShapes,
330 TopTools_ListOfShape &theNewShapes);
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.
339 * \param theShape the shape examined.
340 * \param theModifShapes the list of modified shapes. Output parameter.
341 * \param theShapeType the shape type filter.
343 void getModified(const TopoDS_Shape &theShape,
344 TopTools_ListOfShape &theModifShapes,
345 const TopAbs_ShapeEnum theShapeType = TopAbs_SHAPE);
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;