Salome HOME
Create SketcherPrs package
[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 static_cast<TopoDS_Shape*>(myImpl)
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 (isNull())
31     return theShape->isNull();
32   if (theShape->isNull())
33     return false;
34
35   return MY_SHAPE->IsEqual(theShape->impl<TopoDS_Shape>()) == Standard_True;
36 }
37
38 bool GeomAPI_Shape::isVertex() const
39 {
40   const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
41   return !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX;
42 }
43
44 bool GeomAPI_Shape::isEdge() const
45 {
46   const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
47   return aShape.ShapeType() == TopAbs_EDGE;
48 }
49
50 bool GeomAPI_Shape::isFace() const
51 {
52   const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
53   return aShape.ShapeType() == TopAbs_FACE;
54 }
55
56 bool GeomAPI_Shape::computeSize(double& theXmin, double& theYmin, double& theZmin,
57                                 double& theXmax, double& theYmax, double& theZmax) const
58 {
59   const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
60   if (aShape.IsNull())
61     return false;
62   Bnd_Box aBndBox;
63   BRepBndLib::Add(aShape, aBndBox);
64   aBndBox.Get(theXmin, theYmin, theZmin, theXmax, theYmax, theZmax);
65   return true;
66 }
67
68 std::string GeomAPI_Shape::getShapeStream() const
69 {
70   std::ostringstream aStream;
71   const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
72   BRepTools::Write(aShape, aStream);
73   return aStream.str();
74 }