1 // Copyright (C) 2017-2022 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "Selector_NExplode.h"
22 #include <GeomAPI_Shape.h>
23 #include <GeomAlgoAPI_NExplode.h>
25 ////#include <TopoDS_Shape.hxx>
26 ////#include <BRep_Tool.hxx>
27 ////#include <TopoDS.hxx>
28 ////#include <GProp_GProps.hxx>
29 ////#include <BRepGProp.hxx>
30 ////#include <NCollection_DataMap.hxx>
31 ////#include <Precision.hxx>
32 ////#include <Bnd_Box.hxx>
33 ////#include <BRepBndLib.hxx>
34 ////#include <TopExp_Explorer.hxx>
35 ////#include <TopTools_MapOfShape.hxx>
37 static GeomAlgoAPI_NExplode::ShapeOrder getOrder(const bool isOld)
39 return isOld ? GeomAlgoAPI_NExplode::ORDER_BY_HASH_VALUE
40 : GeomAlgoAPI_NExplode::ORDER_BY_MIDDLE_POINT;
43 static GeomShapePtr convertShape(const TopoDS_Shape& theShape)
45 GeomShapePtr aNewShape(new GeomAPI_Shape);
46 aNewShape->setImpl(new TopoDS_Shape(theShape));
50 Selector_NExplode::Selector_NExplode(const TopoDS_ListOfShape& theShapes, const bool theOldOrder)
51 : myToBeReordered(theOldOrder)
54 for (TopoDS_ListOfShape::Iterator anIt(theShapes); anIt.More(); anIt.Next())
55 aShapes.push_back(convertShape(anIt.Value()));
57 mySorted = std::make_shared<GeomAlgoAPI_NExplode>(aShapes, getOrder(theOldOrder));
60 Selector_NExplode::Selector_NExplode(const TopoDS_Shape& theShape, const TopAbs_ShapeEnum theType,
61 const bool theOldOrder)
62 : myToBeReordered(theOldOrder)
64 GeomShapePtr aShape = convertShape(theShape);
65 GeomAPI_Shape::ShapeType aType = (GeomAPI_Shape::ShapeType)theType;
66 mySorted = std::make_shared<GeomAlgoAPI_NExplode>(aShape, aType, getOrder(theOldOrder));
70 int Selector_NExplode::index(const TopoDS_Shape& theSubShape)
72 int anIndex = mySorted->index(convertShape(theSubShape));
73 return anIndex > 0 ? anIndex : -1; // -1 if not found
76 TopoDS_Shape Selector_NExplode::shape(int& theIndex)
79 GeomShapePtr aShape = mySorted->shape(theIndex);
81 aResult = aShape->impl<TopoDS_Shape>();
82 if (myToBeReordered) {
83 mySorted->reorder(GeomAlgoAPI_NExplode::ORDER_BY_MIDDLE_POINT);
84 theIndex = mySorted->index(aShape);