1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: GeomAPI_Shape.cpp
4 // Created: 23 Apr 2014
5 // Author: Mikhail PONIKAROV
7 #include<GeomAPI_Shape.h>
9 #include <TopoDS_Shape.hxx>
10 #include <TopoDS_Iterator.hxx>
11 #include <BRepBndLib.hxx>
12 #include <Bnd_Box.hxx>
13 #include <BRepTools.hxx>
17 #define MY_SHAPE implPtr<TopoDS_Shape>()
19 GeomAPI_Shape::GeomAPI_Shape()
20 : GeomAPI_Interface(new TopoDS_Shape())
24 bool GeomAPI_Shape::isNull() const
26 return MY_SHAPE->IsNull() == Standard_True;
29 bool GeomAPI_Shape::isEqual(const std::shared_ptr<GeomAPI_Shape> theShape) const
34 return theShape->isNull();
35 if (theShape->isNull())
38 return MY_SHAPE->IsEqual(theShape->impl<TopoDS_Shape>()) == Standard_True;
41 bool GeomAPI_Shape::isVertex() const
43 const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
44 return !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX;
47 bool GeomAPI_Shape::isEdge() const
49 const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
50 return !aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE;
53 bool GeomAPI_Shape::isFace() const
55 const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
56 return !aShape.IsNull() && aShape.ShapeType() == TopAbs_FACE;
59 bool GeomAPI_Shape::isCompound() const
61 const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
62 return !aShape.IsNull() && aShape.ShapeType() == TopAbs_COMPOUND;
65 bool GeomAPI_Shape::isCompoundOfSolids() const
67 const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
68 if (aShape.IsNull() || aShape.ShapeType() != TopAbs_COMPOUND)
70 bool isAtLeastOne = false;
71 for(TopoDS_Iterator aSubs(aShape); aSubs.More(); aSubs.Next()) {
72 if (aSubs.Value().IsNull() || aSubs.Value().ShapeType() != TopAbs_SOLID)
79 bool GeomAPI_Shape::isSolid() const
81 const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
82 return !aShape.IsNull() && aShape.ShapeType() == TopAbs_SOLID;
85 bool GeomAPI_Shape::computeSize(double& theXmin, double& theYmin, double& theZmin,
86 double& theXmax, double& theYmax, double& theZmax) const
88 const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
92 BRepBndLib::Add(aShape, aBndBox);
93 aBndBox.Get(theXmin, theYmin, theZmin, theXmax, theYmax, theZmax);
97 std::string GeomAPI_Shape::getShapeStream() const
99 std::ostringstream aStream;
100 const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
101 BRepTools::Write(aShape, aStream);
102 return aStream.str();