X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGeomAlgoAPI%2FGeomAlgoAPI_CompoundBuilder.cpp;h=db0d6fb0d036c7f76c2dcfcd306f5ece40750f1e;hb=06e7f5859095193fc7f498bd89a7d28009794f53;hp=2882ee2fae576ef9973cb9b07a9e4de6229af816;hpb=6654a921211670c15a79a997ca666a174fe8a6f6;p=modules%2Fshaper.git diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_CompoundBuilder.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_CompoundBuilder.cpp index 2882ee2fa..db0d6fb0d 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_CompoundBuilder.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_CompoundBuilder.cpp @@ -1,28 +1,84 @@ -// File: GeomAlgoAPI_CompoundBuilder.cpp -// Created: 24 Apr 2014 -// Author: Natalia ERMOLAEVA +// Copyright (C) 2014-2023 CEA, EDF +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// #include -//#include -//#include -//#include #include #include +#include +#include +#include -boost::shared_ptr GeomAlgoAPI_CompoundBuilder::compound - (std::list > theShapes) +std::shared_ptr GeomAlgoAPI_CompoundBuilder::compound( + std::list > theShapes) { BRep_Builder aBuilder; TopoDS_Compound aComp; aBuilder.MakeCompound(aComp); - std::list >::const_iterator anIt = theShapes.begin(), - aLast = theShapes.end(); + std::list >::const_iterator anIt = theShapes.begin(), aLast = + theShapes.end(); for (; anIt != aLast; anIt++) { aBuilder.Add(aComp, (*anIt)->impl()); } - boost::shared_ptr aRes(new GeomAPI_Shape); + std::shared_ptr aRes(new GeomAPI_Shape); aRes->setImpl(new TopoDS_Shape(aComp)); return aRes; } + +// Returns true if transformations are equal with the given precision +static bool isEqual(const gp_Trsf& theT1, const gp_Trsf& theT2, const double thePrecision) +{ + for(int aRow = 1; aRow < 4; aRow++) { + for(int aCol = 1; aCol < 5; aCol++) { + double aDiff = theT1.Value(aRow, aCol) - theT2.Value(aRow, aCol); + if (aDiff < 0) aDiff = -aDiff; + if (aDiff > thePrecision) + return false; + } + } + return true; +} + +int GeomAlgoAPI_CompoundBuilder::id( + std::shared_ptr theContext, std::shared_ptr theSub) +{ + int anID = 0; + TopoDS_Shape aMainShape = theContext->impl(); + const TopoDS_Shape& aSubShape = theSub->impl(); + if (!aMainShape.IsNull() && !aSubShape.IsNull()) { + TopTools_IndexedMapOfShape aSubShapesMap; + TopExp::MapShapes(aMainShape, aSubShapesMap); + anID = aSubShapesMap.FindIndex(aSubShape); + if (anID == 0) { // try to search shape with the same location if TopLoc_Location is different + TopExp_Explorer anExp(aMainShape, aSubShape.ShapeType()); + for(; anExp.More(); anExp.Next()) { + if (anExp.Current().TShape() == aSubShape.TShape()) { + const TopLoc_Location aLoc1 = anExp.Current().Location(); + if (isEqual(aLoc1.Transformation(), aSubShape.Location().Transformation(), 1.e-7)) { + anID = aSubShapesMap.FindIndex(anExp.Current()); + break; + } + } + } + } + } + + return anID; +}