Salome HOME
Issue #805 In the sketch presentation, show both the parameter and its value: minor...
[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 std::string GeomAPI_Shape::shapeTypeStr() const
98 {
99   ShapeType aShapeType = shapeType();
100   std::string aShapeTypeStr;
101
102   switch(aShapeType) {
103     case COMPOUND: {
104       aShapeTypeStr = "Compound";
105       break;
106     }
107     case COMPSOLID: {
108       aShapeTypeStr = "CompSolid";
109       break;
110     }
111     case SOLID: {
112       aShapeTypeStr = "Solid";
113       break;
114     }
115     case SHELL: {
116       aShapeTypeStr = "Shell";
117       break;
118     }
119     case FACE: {
120       aShapeTypeStr = "Face";
121       break;
122     }
123     case WIRE: {
124       aShapeTypeStr = "Wire";
125       break;
126     }
127     case EDGE: {
128       aShapeTypeStr = "Edge";
129       break;
130     }
131     case VERTEX: {
132       aShapeTypeStr = "Vertex";
133       break;
134     }
135     case SHAPE: {
136       aShapeTypeStr = "Shape";
137       break;
138     }
139   }
140
141   return aShapeTypeStr;
142 }
143
144 bool GeomAPI_Shape::computeSize(double& theXmin, double& theYmin, double& theZmin,
145                                 double& theXmax, double& theYmax, double& theZmax) const
146 {
147   const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
148   if (aShape.IsNull())
149     return false;
150   Bnd_Box aBndBox;
151   BRepBndLib::Add(aShape, aBndBox);
152   aBndBox.Get(theXmin, theYmin, theZmin, theXmax, theYmax, theZmax);
153   return true;
154 }
155
156 std::string GeomAPI_Shape::getShapeStream() const
157 {
158   std::ostringstream aStream;
159   const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
160   BRepTools::Write(aShape, aStream);
161   return aStream.str();
162 }