X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGeomAPI%2FGeomAPI_Shape.cpp;h=c4f30b6d321fb8aceee45910f7ce2f4cb0da47ee;hb=b06cf1477fb1ee46d7ae260c234cac5d0000abf2;hp=78179ec86047d1ea1e080a01d62c28b66307bf33;hpb=46aa3024234701a2e73ef90c378ae4bf414d90f7;p=modules%2Fshaper.git diff --git a/src/GeomAPI/GeomAPI_Shape.cpp b/src/GeomAPI/GeomAPI_Shape.cpp index 78179ec86..c4f30b6d3 100644 --- a/src/GeomAPI/GeomAPI_Shape.cpp +++ b/src/GeomAPI/GeomAPI_Shape.cpp @@ -1,11 +1,33 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: GeomAPI_Shape.cpp -// Created: 23 Apr 2014 -// Author: Mikhail PONIKAROV +// Copyright (C) 2014-2017 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 +// 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 "GeomAPI_Shape.h" +#include +#include +#include +#include +#include +#include +#include + #include #include #include @@ -29,6 +51,9 @@ #include #include +#include +#include + #include #include // for std::transform @@ -89,12 +114,24 @@ bool GeomAPI_Shape::isEdge() const return !aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE; } +bool GeomAPI_Shape::isWire() const +{ + const TopoDS_Shape& aShape = const_cast(this)->impl(); + return !aShape.IsNull() && aShape.ShapeType() == TopAbs_WIRE; +} + bool GeomAPI_Shape::isFace() const { const TopoDS_Shape& aShape = const_cast(this)->impl(); return !aShape.IsNull() && aShape.ShapeType() == TopAbs_FACE; } +bool GeomAPI_Shape::isShell() const +{ + const TopoDS_Shape& aShape = const_cast(this)->impl(); + return !aShape.IsNull() && aShape.ShapeType() == TopAbs_SHELL; +} + bool GeomAPI_Shape::isCompound() const { const TopoDS_Shape& aShape = const_cast(this)->impl(); @@ -115,6 +152,23 @@ bool GeomAPI_Shape::isCompoundOfSolids() const return isAtLeastOne; } +GeomAPI_Shape::ShapeType GeomAPI_Shape::typeOfCompoundShapes() const +{ + const TopoDS_Shape& aShape = const_cast(this)->impl(); + if (aShape.IsNull() || aShape.ShapeType() != TopAbs_COMPOUND) + return SHAPE; + int aType = -1; + for(TopoDS_Iterator aSubs(aShape); aSubs.More(); aSubs.Next()) { + if (!aSubs.Value().IsNull()) { + if (aType == -1) + aType = aSubs.Value().ShapeType(); + else if (aSubs.Value().ShapeType() != aType) + return SHAPE; + } + } + return (GeomAPI_Shape::ShapeType) aType; +} + // adds the nopt-compound elements recursively to the list static void addSimpleToList(const TopoDS_Shape& theShape, NCollection_List& theList) { @@ -261,9 +315,94 @@ bool GeomAPI_Shape::isPlanar() const return false; } +std::shared_ptr GeomAPI_Shape::vertex() const +{ + GeomVertexPtr aVertex; + if (isVertex()) { + const TopoDS_Shape& aShape = const_cast(this)->impl(); + aVertex = GeomVertexPtr(new GeomAPI_Vertex); + aVertex->setImpl(new TopoDS_Shape(aShape)); + } + return aVertex; +} + +std::shared_ptr GeomAPI_Shape::edge() const +{ + GeomEdgePtr anEdge; + if (isEdge()) { + const TopoDS_Shape& aShape = const_cast(this)->impl(); + anEdge = GeomEdgePtr(new GeomAPI_Edge); + anEdge->setImpl(new TopoDS_Shape(aShape)); + } + return anEdge; +} + +std::shared_ptr GeomAPI_Shape::wire() const +{ + GeomWirePtr aWire; + if (isWire()) { + const TopoDS_Shape& aShape = const_cast(this)->impl(); + aWire = GeomWirePtr(new GeomAPI_Wire); + aWire->setImpl(new TopoDS_Shape(aShape)); + } + return aWire; +} + +std::shared_ptr GeomAPI_Shape::face() const +{ + GeomFacePtr aFace; + if (isFace()) { + const TopoDS_Shape& aShape = const_cast(this)->impl(); + aFace = GeomFacePtr(new GeomAPI_Face); + aFace->setImpl(new TopoDS_Shape(aShape)); + } + return aFace; +} + +std::shared_ptr GeomAPI_Shape::shell() const +{ + GeomShellPtr aShell; + if (isShell()) { + const TopoDS_Shape& aShape = const_cast(this)->impl(); + aShell = GeomShellPtr(new GeomAPI_Shell); + aShell->setImpl(new TopoDS_Shape(aShape)); + } + return aShell; +} + +std::shared_ptr GeomAPI_Shape::solid() const +{ + GeomSolidPtr aSolid; + if (isSolid()) { + const TopoDS_Shape& aShape = const_cast(this)->impl(); + aSolid = GeomSolidPtr(new GeomAPI_Solid); + aSolid->setImpl(new TopoDS_Shape(aShape)); + } + return aSolid; +} + +std::list > +GeomAPI_Shape::subShapes(ShapeType theSubShapeType) const +{ + ListOfShape aSubs; + const TopoDS_Shape& aShape = impl(); + if (aShape.IsNull()) + return aSubs; + + for (TopExp_Explorer anExp(aShape, (TopAbs_ShapeEnum)theSubShapeType); + anExp.More(); anExp.Next()) { + GeomShapePtr aSub(new GeomAPI_Shape); + aSub->setImpl(new TopoDS_Shape(anExp.Current())); + aSubs.push_back(aSub); + } + return aSubs; +} + GeomAPI_Shape::ShapeType GeomAPI_Shape::shapeType() const { const TopoDS_Shape& aShape = impl(); + if (aShape.IsNull()) + return GeomAPI_Shape::SHAPE; ShapeType aST = GeomAPI_Shape::SHAPE; @@ -394,7 +533,13 @@ void GeomAPI_Shape::setOrientation(const GeomAPI_Shape::Orientation theOrientati } } -bool GeomAPI_Shape::isSubShape(const std::shared_ptr theShape) const +void GeomAPI_Shape::reverse() +{ + MY_SHAPE->Reverse(); +} + +bool GeomAPI_Shape::isSubShape(const std::shared_ptr theShape, + const bool theCheckOrientation) const { if(!theShape.get()) { return false; @@ -406,7 +551,8 @@ bool GeomAPI_Shape::isSubShape(const std::shared_ptr theShape) co } for(TopExp_Explorer anExp(*MY_SHAPE, aShapeToSearch.ShapeType()); anExp.More(); anExp.Next()) { - if(aShapeToSearch.IsEqual(anExp.Current())) { + if(theCheckOrientation ? + aShapeToSearch.IsEqual(anExp.Current()) : aShapeToSearch.IsSame(anExp.Current())) { return true; } } @@ -421,11 +567,48 @@ bool GeomAPI_Shape::computeSize(double& theXmin, double& theYmin, double& theZmi if (aShape.IsNull()) return false; Bnd_Box aBndBox; - BRepBndLib::Add(aShape, aBndBox); + BRepBndLib::Add(aShape, aBndBox, false); + if (aBndBox.IsVoid()) + return false; aBndBox.Get(theXmin, theYmin, theZmin, theXmax, theYmax, theZmax); return true; } +GeomPointPtr GeomAPI_Shape::middlePoint() const +{ + GeomPointPtr aMiddlePoint; + + switch (shapeType()) { + case VERTEX: + aMiddlePoint = vertex()->point(); + break; + case EDGE: + aMiddlePoint = edge()->middlePoint(); + break; + case WIRE: + aMiddlePoint = wire()->middlePoint(); + break; + case FACE: + aMiddlePoint = face()->middlePoint(); + break; + case SHELL: + aMiddlePoint = shell()->middlePoint(); + break; + case SOLID: + aMiddlePoint = solid()->middlePoint(); + break; + default: { + // get middle point as center of the bounding box + double aMinX, aMinY, aMinZ, aMaxX, aMaxY, aMaxZ; + computeSize(aMinX, aMinY, aMinZ, aMaxX, aMaxY, aMaxZ); + aMiddlePoint = GeomPointPtr(new GeomAPI_Pnt( + (aMinX + aMaxX) * 0.5, (aMinY + aMaxY) * 0.5, (aMinZ + aMaxZ) * 0.5)); + } + } + + return aMiddlePoint; +} + std::string GeomAPI_Shape::getShapeStream() const { std::ostringstream aStream; @@ -476,3 +659,29 @@ bool GeomAPI_Shape::isIntersect(const GeomShapePtr theShape) const return false; } + +void GeomAPI_Shape::translate(const std::shared_ptr theDir, const double theOffset) +{ + gp_Dir aDir = theDir->impl(); + gp_Vec aTrsfVec(aDir.XYZ() * theOffset); + gp_Trsf aTranslation; + aTranslation.SetTranslation(aTrsfVec); + TopoDS_Shape aResult = MY_SHAPE->Moved(aTranslation); + setImpl(new TopoDS_Shape(aResult)); +} + +bool GeomAPI_Shape::isSelfIntersected(const int theLevelOfCheck) const +{ + BOPAlgo_CheckerSI aCSI; // checker of self-interferences + aCSI.SetLevelOfCheck(theLevelOfCheck); + TopTools_ListOfShape aList; + const TopoDS_Shape& aThisShape = const_cast(this)->impl(); + aList.Append(aThisShape); + aCSI.SetArguments(aList); + aCSI.Perform(); + if (aCSI.HasErrors() || aCSI.DS().Interferences().Extent() > 0) { + return true; + } + + return false; +}