Salome HOME
Replace void* with shared_ptr<void> in GeomAPI_Interface
[modules/shaper.git] / src / GeomAPI / GeomAPI_Shape.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        GeomAPI_Shape.cpp
4 // Created:     23 Apr 2014
5 // Author:      Mikhail PONIKAROV
6
7 #include<GeomAPI_Shape.h>
8
9 #include <TopoDS_Shape.hxx>
10 #include <BRepBndLib.hxx>
11 #include <Bnd_Box.hxx>
12 #include <BRepTools.hxx>
13
14 #include <sstream>
15
16 #define MY_SHAPE implPtr<TopoDS_Shape>()
17
18 GeomAPI_Shape::GeomAPI_Shape()
19     : GeomAPI_Interface(new TopoDS_Shape())
20 {
21 }
22
23 bool GeomAPI_Shape::isNull() const
24 {
25   return MY_SHAPE->IsNull() == Standard_True;
26 }
27
28 bool GeomAPI_Shape::isEqual(const std::shared_ptr<GeomAPI_Shape> theShape) const
29 {
30   if (!theShape.get())
31     return false;
32   if (isNull())
33     return theShape->isNull();
34   if (theShape->isNull())
35     return false;
36
37   return MY_SHAPE->IsEqual(theShape->impl<TopoDS_Shape>()) == Standard_True;
38 }
39
40 bool GeomAPI_Shape::isVertex() const
41 {
42   const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
43   return !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX;
44 }
45
46 bool GeomAPI_Shape::isEdge() const
47 {
48   const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
49   return !aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE;
50 }
51
52 bool GeomAPI_Shape::isFace() const
53 {
54   const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
55   return !aShape.IsNull() && aShape.ShapeType() == TopAbs_FACE;
56 }
57
58 bool GeomAPI_Shape::isCompound() const
59 {
60   const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
61   return !aShape.IsNull() && aShape.ShapeType() == TopAbs_COMPOUND;
62 }
63
64 bool GeomAPI_Shape::isSolid() const
65 {
66   const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
67   return !aShape.IsNull() && aShape.ShapeType() == TopAbs_SOLID;
68 }
69
70 bool GeomAPI_Shape::computeSize(double& theXmin, double& theYmin, double& theZmin,
71                                 double& theXmax, double& theYmax, double& theZmax) const
72 {
73   const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
74   if (aShape.IsNull())
75     return false;
76   Bnd_Box aBndBox;
77   BRepBndLib::Add(aShape, aBndBox);
78   aBndBox.Get(theXmin, theYmin, theZmin, theXmax, theYmax, theZmax);
79   return true;
80 }
81
82 std::string GeomAPI_Shape::getShapeStream() const
83 {
84   std::ostringstream aStream;
85   const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
86   BRepTools::Write(aShape, aStream);
87   return aStream.str();
88 }