Salome HOME
Make plane as close as possible to selected shape by its size
[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
13 #define MY_SHAPE static_cast<TopoDS_Shape*>(myImpl)
14
15 GeomAPI_Shape::GeomAPI_Shape()
16     : GeomAPI_Interface(new TopoDS_Shape())
17 {
18 }
19
20 bool GeomAPI_Shape::isNull() const
21 {
22   return MY_SHAPE->IsNull() == Standard_True;
23 }
24
25 bool GeomAPI_Shape::isEqual(const std::shared_ptr<GeomAPI_Shape> theShape) const
26 {
27   if (isNull())
28     return theShape->isNull();
29   if (theShape->isNull())
30     return false;
31
32   return MY_SHAPE->IsEqual(theShape->impl<TopoDS_Shape>()) == Standard_True;
33 }
34
35 bool GeomAPI_Shape::isVertex() const
36 {
37   const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
38   return !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX;
39 }
40
41 bool GeomAPI_Shape::isEdge() const
42 {
43   const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
44   return aShape.ShapeType() == TopAbs_EDGE;
45 }
46
47 bool GeomAPI_Shape::isFace() const
48 {
49   const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
50   return aShape.ShapeType() == TopAbs_FACE;
51 }
52
53 bool GeomAPI_Shape::computeSize(double& theXmin, double& theYmin, double& theZmin,
54                                 double& theXmax, double& theYmax, double& theZmax) const
55 {
56   const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
57   if (aShape.IsNull())
58     return false;
59   Bnd_Box aBndBox;
60   BRepBndLib::Add(aShape, aBndBox);
61   aBndBox.Get(theXmin, theYmin, theZmin, theXmax, theYmax, theZmax);
62   return true;
63 }