-// Copyright (C) 2014-2017 CEA/DEN, EDF R&D
+// Copyright (C) 2014-2019 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
//
// 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
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
-// See http://www.salome-platform.org/ or
-// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
#include "GeomAPI_Shape.h"
+#include <GeomAPI_Pnt.h>
+#include <GeomAPI_Vertex.h>
+#include <GeomAPI_Edge.h>
+#include <GeomAPI_Wire.h>
+#include <GeomAPI_Face.h>
+#include <GeomAPI_Shell.h>
+#include <GeomAPI_Solid.h>
+
#include <BRep_Tool.hxx>
#include <BRepAlgoAPI_Section.hxx>
#include <BRepBndLib.hxx>
#include <TopoDS_Shape.hxx>
#include <NCollection_List.hxx>
+#include <BOPAlgo_CheckerSI.hxx>
+#include <BOPDS_DS.hxx>
+
#include <sstream>
#include <algorithm> // for std::transform
return !aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE;
}
+bool GeomAPI_Shape::isWire() const
+{
+ const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
+ return !aShape.IsNull() && aShape.ShapeType() == TopAbs_WIRE;
+}
+
bool GeomAPI_Shape::isFace() const
{
const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
return !aShape.IsNull() && aShape.ShapeType() == TopAbs_FACE;
}
+bool GeomAPI_Shape::isShell() const
+{
+ const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
+ return !aShape.IsNull() && aShape.ShapeType() == TopAbs_SHELL;
+}
+
bool GeomAPI_Shape::isCompound() const
{
const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
return isAtLeastOne;
}
+// LCOV_EXCL_START
+GeomAPI_Shape::ShapeType GeomAPI_Shape::typeOfCompoundShapes() const
+{
+ const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
+ 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;
+}
+// LCOV_EXCL_STOP
+
// adds the nopt-compound elements recursively to the list
static void addSimpleToList(const TopoDS_Shape& theShape, NCollection_List<TopoDS_Shape>& theList)
{
return false;
}
+std::shared_ptr<GeomAPI_Vertex> GeomAPI_Shape::vertex() const
+{
+ GeomVertexPtr aVertex;
+ if (isVertex()) {
+ const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
+ aVertex = GeomVertexPtr(new GeomAPI_Vertex);
+ aVertex->setImpl(new TopoDS_Shape(aShape));
+ }
+ return aVertex;
+}
+
+std::shared_ptr<GeomAPI_Edge> GeomAPI_Shape::edge() const
+{
+ GeomEdgePtr anEdge;
+ if (isEdge()) {
+ const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
+ anEdge = GeomEdgePtr(new GeomAPI_Edge);
+ anEdge->setImpl(new TopoDS_Shape(aShape));
+ }
+ return anEdge;
+}
+
+std::shared_ptr<GeomAPI_Wire> GeomAPI_Shape::wire() const
+{
+ GeomWirePtr aWire;
+ if (isWire()) {
+ const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
+ aWire = GeomWirePtr(new GeomAPI_Wire);
+ aWire->setImpl(new TopoDS_Shape(aShape));
+ }
+ return aWire;
+}
+
+std::shared_ptr<GeomAPI_Face> GeomAPI_Shape::face() const
+{
+ GeomFacePtr aFace;
+ if (isFace()) {
+ const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
+ aFace = GeomFacePtr(new GeomAPI_Face);
+ aFace->setImpl(new TopoDS_Shape(aShape));
+ }
+ return aFace;
+}
+
+std::shared_ptr<GeomAPI_Shell> GeomAPI_Shape::shell() const
+{
+ GeomShellPtr aShell;
+ if (isShell()) {
+ const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
+ aShell = GeomShellPtr(new GeomAPI_Shell);
+ aShell->setImpl(new TopoDS_Shape(aShape));
+ }
+ return aShell;
+}
+
+std::shared_ptr<GeomAPI_Solid> GeomAPI_Shape::solid() const
+{
+ GeomSolidPtr aSolid;
+ if (isSolid()) {
+ const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
+ aSolid = GeomSolidPtr(new GeomAPI_Solid);
+ aSolid->setImpl(new TopoDS_Shape(aShape));
+ }
+ return aSolid;
+}
+
+std::list<std::shared_ptr<GeomAPI_Shape> >
+GeomAPI_Shape::subShapes(ShapeType theSubShapeType) const
+{
+ ListOfShape aSubs;
+ const TopoDS_Shape& aShape = impl<TopoDS_Shape>();
+ if (aShape.IsNull())
+ return aSubs;
+
+ // process multi-level compounds
+ if (shapeType() == COMPOUND && theSubShapeType == COMPOUND) {
+ for (TopoDS_Iterator anIt(aShape); anIt.More(); anIt.Next()) {
+ const TopoDS_Shape& aCurrent = anIt.Value();
+ if (aCurrent.ShapeType() == TopAbs_COMPOUND) {
+ GeomShapePtr aSub(new GeomAPI_Shape);
+ aSub->setImpl(new TopoDS_Shape(aCurrent));
+ aSubs.push_back(aSub);
+ }
+ }
+ // add self
+ GeomShapePtr aSub(new GeomAPI_Shape);
+ aSub->setImpl(new TopoDS_Shape(aShape));
+ aSubs.push_back(aSub);
+ }
+ else {
+ 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<TopoDS_Shape>();
+ if (aShape.IsNull())
+ return GeomAPI_Shape::SHAPE;
ShapeType aST = GeomAPI_Shape::SHAPE;
GeomAPI_Shape::ShapeType GeomAPI_Shape::shapeTypeByStr(std::string theType)
{
std::transform(theType.begin(), theType.end(), theType.begin(), ::toupper);
- if (theType == "COMPOUND")
+ if (theType == "COMPOUND" || theType == "COMPOUNDS")
return COMPOUND;
- if (theType == "COMPSOLID")
+ if (theType == "COMPSOLID" || theType == "COMPSOLIDS")
return COMPSOLID;
- if (theType == "SOLID")
+ if (theType == "SOLID" || theType == "SOLIDS")
return SOLID;
- if (theType == "SHELL")
+ if (theType == "SHELL" || theType == "SHELLS")
return SHELL;
- if (theType == "FACE")
+ if (theType == "FACE" || theType == "FACES")
return FACE;
- if (theType == "WIRE")
+ if (theType == "WIRE" || theType == "WIRES")
return WIRE;
- if (theType == "EDGE")
+ if (theType == "EDGE" || theType == "EDGES")
return EDGE;
- if (theType == "VERTEX")
+ if (theType == "VERTEX" || theType == "VERTICES")
return VERTEX;
return SHAPE; // default
}
}
}
-bool GeomAPI_Shape::isSubShape(const std::shared_ptr<GeomAPI_Shape> theShape) const
+void GeomAPI_Shape::reverse()
+{
+ MY_SHAPE->Reverse();
+}
+
+bool GeomAPI_Shape::isSubShape(const std::shared_ptr<GeomAPI_Shape> theShape,
+ const bool theCheckOrientation) const
{
if(!theShape.get()) {
return false;
}
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;
}
}
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;
+}
+
+// LCOV_EXCL_START
std::string GeomAPI_Shape::getShapeStream() const
{
std::ostringstream aStream;
BRepTools::Write(aShape, aStream);
return aStream.str();
}
+// LCOV_EXCL_STOP
GeomShapePtr GeomAPI_Shape::intersect(const GeomShapePtr theShape) const
{
return false;
}
+
+void GeomAPI_Shape::translate(const std::shared_ptr<GeomAPI_Dir> theDir, const double theOffset)
+{
+ gp_Dir aDir = theDir->impl<gp_Dir>();
+ 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<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
+ aList.Append(aThisShape);
+ aCSI.SetArguments(aList);
+ aCSI.Perform();
+ if (aCSI.HasErrors() || aCSI.DS().Interferences().Extent() > 0) {
+ return true;
+ }
+
+ return false;
+}
+
+bool GeomAPI_Shape::Comparator::operator()(const std::shared_ptr<GeomAPI_Shape>& theShape1,
+ const std::shared_ptr<GeomAPI_Shape>& theShape2) const
+{
+ return theShape1->impl<TopoDS_Shape>().TShape() < theShape2->impl<TopoDS_Shape>().TShape();
+}