]> SALOME platform Git repositories - modules/shaper.git/blob - src/GeomAPI/GeomAPI_Shape.cpp
Salome HOME
bbd1de77b3eff2152a5313bdc6bfa2b95bf867c3
[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 <TopoDS_Iterator.hxx>
11 #include <BRepBndLib.hxx>
12 #include <Bnd_Box.hxx>
13 #include <BRepTools.hxx>
14
15 #include <sstream>
16
17 #define MY_SHAPE implPtr<TopoDS_Shape>()
18
19 GeomAPI_Shape::GeomAPI_Shape()
20     : GeomAPI_Interface(new TopoDS_Shape())
21 {
22 }
23
24 bool GeomAPI_Shape::isNull() const
25 {
26   return MY_SHAPE->IsNull() == Standard_True;
27 }
28
29 bool GeomAPI_Shape::isEqual(const std::shared_ptr<GeomAPI_Shape> theShape) const
30 {
31   if (!theShape.get())
32     return false;
33   if (isNull())
34     return theShape->isNull();
35   if (theShape->isNull())
36     return false;
37
38   return MY_SHAPE->IsEqual(theShape->impl<TopoDS_Shape>()) == Standard_True;
39 }
40
41 bool GeomAPI_Shape::isVertex() const
42 {
43   const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
44   return !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX;
45 }
46
47 bool GeomAPI_Shape::isEdge() const
48 {
49   const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
50   return !aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE;
51 }
52
53 bool GeomAPI_Shape::isFace() const
54 {
55   const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
56   return !aShape.IsNull() && aShape.ShapeType() == TopAbs_FACE;
57 }
58
59 bool GeomAPI_Shape::isCompound() const
60 {
61   const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
62   return !aShape.IsNull() && aShape.ShapeType() == TopAbs_COMPOUND;
63 }
64
65 bool GeomAPI_Shape::isCompoundOfSolids() const
66 {
67   const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
68   if (aShape.IsNull() || aShape.ShapeType() != TopAbs_COMPOUND)
69     return false;
70   bool isAtLeastOne = false;
71   for(TopoDS_Iterator aSubs(aShape); aSubs.More(); aSubs.Next()) {
72     if (aSubs.Value().IsNull() || aSubs.Value().ShapeType() != TopAbs_SOLID)
73       return false;
74     isAtLeastOne = true;
75   }
76   return isAtLeastOne;
77 }
78
79 bool GeomAPI_Shape::isSolid() const
80 {
81   const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
82   return !aShape.IsNull() && aShape.ShapeType() == TopAbs_SOLID;
83 }
84
85 bool GeomAPI_Shape::computeSize(double& theXmin, double& theYmin, double& theZmin,
86                                 double& theXmax, double& theYmax, double& theZmax) const
87 {
88   const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
89   if (aShape.IsNull())
90     return false;
91   Bnd_Box aBndBox;
92   BRepBndLib::Add(aShape, aBndBox);
93   aBndBox.Get(theXmin, theYmin, theZmin, theXmax, theYmax, theZmax);
94   return true;
95 }
96
97 std::string GeomAPI_Shape::getShapeStream() const
98 {
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();
103 }