1 // Copyright (C) 2007-2015 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>
38 class TopTools_IndexedMapOfShape;
42 * \brief This class encapsulates an algorithm of extraction of sub-shapes
43 * from the main shape.
45 class GEOMAlgo_Extractor : public GEOMAlgo_Algo
50 * \brief Empty constructor.
52 Standard_EXPORT GEOMAlgo_Extractor();
55 * \brief Virtual destructor.
57 Standard_EXPORT virtual ~GEOMAlgo_Extractor();
60 * \brief This method sets the main shape.
62 * \param theShape the main shape.
64 Standard_EXPORT void SetShape(const TopoDS_Shape &theShape);
67 * \brief This method returns the main shape.
69 * \return the main shape.
71 const TopoDS_Shape &GetShape() const
75 * \brief This method sets the list of sub-shapes to be removed
76 * from the main shape.
78 * \param theSubShapes the sub-shapes to be removed.
80 Standard_EXPORT void SetShapesToRemove
81 (const TopTools_ListOfShape &theSubShapes);
84 * \brief This method returns the list of sub-shapes to be removed
85 * from the main shape.
87 * \return the list of sub-shapes to be removed.
89 const TopTools_ListOfShape &GetShapesToRemove() const
90 { return mySubShapes; }
93 * This method performs computation of the extracted shape.
95 Standard_EXPORT virtual void Perform();
98 * This method returns the result of the algorithm.
100 * \return the result of the operation.
102 Standard_EXPORT const TopoDS_Shape &GetResult() const;
105 * \brief This method returns the sub-shapes removed from the main shape.
107 * \return the list of removed sub-shapes.
109 const TopTools_ListOfShape &GetRemoved() const
110 { return myRemoved; }
113 * \brief This method returns the sub-shapes modified in the main shape.
115 * \return the list of modified sub-shapes.
117 const TopTools_ListOfShape &GetModified() const
118 { return myModified; }
121 * \brief This method returns the newly created sub-shapes in the result
124 * \return the list of new sub-shapes in result.
126 const TopTools_ListOfShape &GetNew() const
132 * \brief This method reinitializes the shape.
137 * \brief This method checks the input data.
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.
146 * \param theShape the shape.
148 void makeMapShapeAncestors(const TopoDS_Shape &theShape);
151 * \brief This method marks shapes to be removed and to be modified.
156 * \brief This method marks theShape to be removed. If it is required, it
157 * recursively marks its sub-shapes to be removed.
159 * \param theShape the shape.
161 void markRemoved(const TopoDS_Shape &theShape);
164 * \brief This method marks ancestors of theShape to be modified. It is
165 * recursively called up to the level of main shape.
167 * \param theShape the shape.
169 void markAncestorsModified(const TopoDS_Shape &theShape);
172 * \brief This method performs computation of modified shapes of
175 * \param theType the processed shape type.
177 void processShapes(const TopAbs_ShapeEnum &theType);
180 * \brief This method performs computation of a modified edge.
182 * \param theEdge the modified edge (should be forward).
184 void processEdge(const TopoDS_Shape &theEdge);
187 * \brief This method performs computation of a modified wire.
189 * \param theWire the modified wire (should be forward).
191 void processWire(const TopoDS_Shape &theWire);
194 * \brief This method performs computation of a modified face or solid.
196 * \param theFOrSo the modified face or solid (should be forward).
198 void processFOrSo(const TopoDS_Shape &theFOrSo);
201 * \brief This method performs computation of a modified shell or comp-solid.
203 * \param theShOrCS the modified shell or comp-solid (should be forward).
205 void processShOrCS(const TopoDS_Shape &theShOrCS);
208 * \brief This method performs computation of a modified compound.
210 * \param theCompound the modified compound (should be forward).
212 void processCompound(const TopoDS_Shape &theCompound);
215 * \brief This method removes hanging edges (faces) built for faces (solids)
216 * if they lie on created faces (solids).
218 * \param theType the shape type. Should be either face or solid.
220 void removeBoundsOnFOrSo(const TopAbs_ShapeEnum theType);
223 * \brief Returns theShape with an orientation composed with theContext's
226 * \param theShape the shape to be re-oriented.
227 * \param theContext the context shape.
229 TopoDS_Shape oriented(const TopoDS_Shape &theShape,
230 const TopoDS_Shape &theContext);
233 * \brief This method makes a shape as an empty copy of theShape adding
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.
240 TopoDS_Shape makeShape(const TopoDS_Shape &theShape,
241 const TopTools_ListOfShape &theSubShapes);
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.
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).
252 TopoDS_Shape getShapeFromSubShapes(const TopoDS_Shape &theShape,
253 const TopTools_ListOfShape &theSubShapes);
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).
260 * \param theShape the shape.
261 * \return the result.
263 TopoDS_Shape makeResult(const TopoDS_Shape &theShape);
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.
270 * \param theShape the shape.
271 * \param theMapFence the map of already treated shapes.
273 void makeHistory(const TopoDS_Shape &theShape,
274 TopTools_MapOfShape &theMapFence);
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).
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.
286 Standard_Boolean removeCommonEdges
287 (const TopoDS_Shape &theWire,
288 const TopTools_IndexedMapOfShape &theMapEdgesToRm,
289 TopTools_ListOfShape &theNewWires);
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).
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.
301 Standard_Boolean removeCommonFaces
302 (const TopoDS_Shape &theShell,
303 const TopTools_IndexedMapOfShape &theMapFacesToRm,
304 TopTools_ListOfShape &theNewShells);
307 * \brief This method creates wires from the list of list of edges.
309 * \param theWire the input wire.
310 * \param theListListEdges the list of list of edges. Can be modified
312 * \param theWires the list of created wires. Output parameter.
314 void makeWires(const TopoDS_Shape &theWire,
315 NCollection_List<TopTools_ListOfShape> &theListListEdges,
316 TopTools_ListOfShape &theWires);
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.
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.
329 void groupViaBounds(const TopoDS_Shape &theShape,
330 const TopTools_ListOfShape &theSubShapes,
331 TopTools_ListOfShape &theNewShapes);
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.
340 * \param theShape the shape examined.
341 * \param theModifShapes the list of modified shapes. Output parameter.
342 * \param theShapeType the shape type filter.
344 void getModified(const TopoDS_Shape &theShape,
345 TopTools_ListOfShape &theModifShapes,
346 const TopAbs_ShapeEnum theShapeType = TopAbs_SHAPE);
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;