Salome HOME
Processing composilid like a solid in selection.
[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::isCompSolid() const
86 {
87   const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
88   return !aShape.IsNull() && aShape.ShapeType() == TopAbs_COMPSOLID;
89 }
90
91 GeomAPI_Shape::ShapeType GeomAPI_Shape::shapeType() const
92 {
93   const TopoDS_Shape& aShape = impl<TopoDS_Shape>();
94   return (ShapeType)aShape.ShapeType();
95 }
96
97 bool GeomAPI_Shape::computeSize(double& theXmin, double& theYmin, double& theZmin,
98                                 double& theXmax, double& theYmax, double& theZmax) const
99 {
100   const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
101   if (aShape.IsNull())
102     return false;
103   Bnd_Box aBndBox;
104   BRepBndLib::Add(aShape, aBndBox);
105   aBndBox.Get(theXmin, theYmin, theZmin, theXmax, theYmax, theZmax);
106   return true;
107 }
108
109 std::string GeomAPI_Shape::getShapeStream() const
110 {
111   std::ostringstream aStream;
112   const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
113   BRepTools::Write(aShape, aStream);
114   return aStream.str();
115 }