X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGeomAPI%2FGeomAPI_Shape.cpp;h=cd044b69a2b600b08a58e9bd270e68278cfb2dd7;hb=90b8e5b49e8654b43df7f8f5cac9dd183c881f48;hp=78a10ac3c5ffb0bb6940a29828e1a07dca6c034d;hpb=645e2cb70c0e40290725f28fdc5fec8a93338d28;p=modules%2Fshaper.git diff --git a/src/GeomAPI/GeomAPI_Shape.cpp b/src/GeomAPI/GeomAPI_Shape.cpp index 78a10ac3c..cd044b69a 100644 --- a/src/GeomAPI/GeomAPI_Shape.cpp +++ b/src/GeomAPI/GeomAPI_Shape.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2019 CEA/DEN, EDF R&D +// Copyright (C) 2014-2020 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -46,6 +46,7 @@ #include #include #include +#include #include #include #include @@ -93,11 +94,10 @@ bool GeomAPI_Shape::isEqual(const std::shared_ptr theShape) const bool GeomAPI_Shape::isSame(const std::shared_ptr theShape) const { - if (!theShape.get()) - return false; + bool isNullShape = !theShape.get() || theShape->isNull();; if (isNull()) - return theShape->isNull(); - if (theShape->isNull()) + return isNullShape; + if (isNullShape) return false; return MY_SHAPE->IsSame(theShape->impl()) == Standard_True; @@ -228,9 +228,9 @@ bool GeomAPI_Shape::isConnectedTopology() const // (if shapes are connected, vertices are connected for sure) TopExp_Explorer anExp2(aNewIter.Value(), TopAbs_VERTEX); for(; !aConnected && anExp2.More(); anExp2.Next()) { - NCollection_List::Iterator aNotIter(aNotVertices); - for(; aNotIter.More(); aNotIter.Next()) { - if (aNotIter.Value().IsSame(anExp2.Current())) { + NCollection_List::Iterator aNotVIter(aNotVertices); + for(; aNotVIter.More(); aNotVIter.Next()) { + if (aNotVIter.Value().IsSame(anExp2.Current())) { aConnected = true; break; } @@ -288,15 +288,13 @@ bool GeomAPI_Shape::isPlanar() const if(aShapeType == TopAbs_VERTEX) { return true; } else if(aShapeType == TopAbs_FACE) { - const Handle(Geom_Surface)& aSurface = BRep_Tool::Surface(TopoDS::Face(aShape)); - Handle(Standard_Type) aType = aSurface->DynamicType(); - - if(aType == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) { + Handle(Geom_Surface) aSurface = BRep_Tool::Surface(TopoDS::Face(aShape)); + if(aSurface->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) { Handle(Geom_RectangularTrimmedSurface) aTrimSurface = - Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface); - aType = aTrimSurface->BasisSurface()->DynamicType(); + Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface); + aSurface = aTrimSurface->BasisSurface(); } - return (aType == STANDARD_TYPE(Geom_Plane)) == Standard_True; + return GeomLib_IsPlanarSurface(aSurface).IsPlanar(); } else { BRepBuilderAPI_FindPlane aFindPlane(aShape); bool isFound = aFindPlane.Found() == Standard_True; @@ -470,7 +468,8 @@ GeomAPI_Shape::ShapeType GeomAPI_Shape::shapeType() const GeomAPI_Shape::ShapeType GeomAPI_Shape::shapeTypeByStr(std::string theType) { - std::transform(theType.begin(), theType.end(), theType.begin(), ::toupper); + std::transform(theType.begin(), theType.end(), theType.begin(), + [](char c) { return static_cast(::toupper(c)); }); if (theType == "COMPOUND" || theType == "COMPOUNDS") return COMPOUND; if (theType == "COMPSOLID" || theType == "COMPSOLIDS") @@ -552,8 +551,6 @@ GeomAPI_Shape::Orientation GeomAPI_Shape::orientation() const void GeomAPI_Shape::setOrientation(const GeomAPI_Shape::Orientation theOrientation) { - TopAbs_Orientation anOrientation = MY_SHAPE->Orientation(); - switch(theOrientation) { case FORWARD: MY_SHAPE->Orientation(TopAbs_FORWARD); break; case REVERSED: MY_SHAPE->Orientation(TopAbs_REVERSED); break; @@ -596,7 +593,19 @@ bool GeomAPI_Shape::computeSize(double& theXmin, double& theYmin, double& theZmi if (aShape.IsNull()) return false; Bnd_Box aBndBox; - BRepBndLib::Add(aShape, aBndBox, false); + // Workaround: compute optimal bounding box for the compounds of edges/vertices, because sometimes + // the bounding box of sketch is calculated if the transformation is applied twice (issue #20167). + bool isShape1D = false; + if (aShape.ShapeType() == TopAbs_COMPOUND) { + isShape1D = true; + for (TopoDS_Iterator anIt(aShape); anIt.More() && isShape1D; anIt.Next()) + if (anIt.Value().ShapeType() < TopAbs_WIRE) + isShape1D = false; + } + if (isShape1D) + BRepBndLib::AddOptimal(aShape, aBndBox, false, true); + else + BRepBndLib::Add(aShape, aBndBox, false); if (aBndBox.IsVoid()) return false; aBndBox.Get(theXmin, theYmin, theZmin, theXmax, theYmax, theZmax); @@ -646,6 +655,11 @@ std::string GeomAPI_Shape::getShapeStream(const bool theWithTriangulation) const if (!theWithTriangulation) { // make a copy of shape without triangulation BRepBuilderAPI_Copy aCopy(aShape, Standard_False, Standard_False); const TopoDS_Shape& aCopyShape = aCopy.Shape(); + // make all faces unchecked to make the stream of shapes the same + TopExp_Explorer aFaceExp(aCopyShape, TopAbs_FACE); + for(; aFaceExp.More(); aFaceExp.Next()) { + aFaceExp.Current().TShape()->Checked(Standard_False); + } BRepTools::Write(aCopyShape, aStream); } else { BRepTools::Write(aShape, aStream);