1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: GeomAPI_Shape.cpp
4 // Created: 23 Apr 2014
5 // Author: Mikhail PONIKAROV
7 #include "GeomAPI_Shape.h"
9 #include <BRep_Tool.hxx>
10 #include <BRepBndLib.hxx>
11 #include <BRepBuilderAPI_FindPlane.hxx>
12 #include <BRepTools.hxx>
13 #include <Bnd_Box.hxx>
14 #include <Geom_Plane.hxx>
15 #include <Geom_RectangularTrimmedSurface.hxx>
17 #include <TopoDS_Iterator.hxx>
18 #include <TopoDS_Shape.hxx>
22 #define MY_SHAPE implPtr<TopoDS_Shape>()
24 GeomAPI_Shape::GeomAPI_Shape()
25 : GeomAPI_Interface(new TopoDS_Shape())
29 bool GeomAPI_Shape::isNull() const
31 return MY_SHAPE->IsNull() == Standard_True;
34 bool GeomAPI_Shape::isEqual(const std::shared_ptr<GeomAPI_Shape> theShape) const
39 return theShape->isNull();
40 if (theShape->isNull())
43 return MY_SHAPE->IsEqual(theShape->impl<TopoDS_Shape>()) == Standard_True;
46 bool GeomAPI_Shape::isVertex() const
48 const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
49 return !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX;
52 bool GeomAPI_Shape::isEdge() const
54 const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
55 return !aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE;
58 bool GeomAPI_Shape::isFace() const
60 const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
61 return !aShape.IsNull() && aShape.ShapeType() == TopAbs_FACE;
64 bool GeomAPI_Shape::isCompound() const
66 const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
67 return !aShape.IsNull() && aShape.ShapeType() == TopAbs_COMPOUND;
70 bool GeomAPI_Shape::isCompoundOfSolids() const
72 const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
73 if (aShape.IsNull() || aShape.ShapeType() != TopAbs_COMPOUND)
75 bool isAtLeastOne = false;
76 for(TopoDS_Iterator aSubs(aShape); aSubs.More(); aSubs.Next()) {
77 if (aSubs.Value().IsNull() || aSubs.Value().ShapeType() != TopAbs_SOLID)
84 bool GeomAPI_Shape::isSolid() const
86 const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
87 return !aShape.IsNull() && aShape.ShapeType() == TopAbs_SOLID;
90 bool GeomAPI_Shape::isCompSolid() const
92 const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
93 return !aShape.IsNull() && aShape.ShapeType() == TopAbs_COMPSOLID;
96 bool GeomAPI_Shape::isPlanar() const
98 const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
100 if(aShape.IsNull()) {
104 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
106 if(aShapeType == TopAbs_VERTEX) {
108 } else if(aShapeType == TopAbs_EDGE || aShapeType == TopAbs_WIRE || aShapeType == TopAbs_SHELL) {
109 BRepBuilderAPI_FindPlane aFindPlane(aShape);
110 return aFindPlane.Found() == Standard_True;
111 } else if(aShapeType == TopAbs_FACE) {
112 const Handle(Geom_Surface)& aSurface = BRep_Tool::Surface(TopoDS::Face(aShape));
113 Handle(Standard_Type) aType = aSurface->DynamicType();
115 if(aType == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
116 Handle(Geom_RectangularTrimmedSurface) aTrimSurface = Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface);
117 aType = aTrimSurface->BasisSurface()->DynamicType();
119 return (aType == STANDARD_TYPE(Geom_Plane)) == Standard_True;
125 GeomAPI_Shape::ShapeType GeomAPI_Shape::shapeType() const
127 const TopoDS_Shape& aShape = impl<TopoDS_Shape>();
129 ShapeType aST = GeomAPI_Shape::SHAPE;
131 switch(aShape.ShapeType()) {
132 case TopAbs_COMPOUND:
133 aST = GeomAPI_Shape::COMPOUND;
135 case TopAbs_COMPSOLID:
136 aST = GeomAPI_Shape::COMPSOLID;
139 aST = GeomAPI_Shape::SOLID;
142 aST = GeomAPI_Shape::SHELL;
145 aST = GeomAPI_Shape::FACE;
148 aST = GeomAPI_Shape::WIRE;
151 aST = GeomAPI_Shape::EDGE;
154 aST = GeomAPI_Shape::VERTEX;
157 aST = GeomAPI_Shape::SHAPE;
164 std::string GeomAPI_Shape::shapeTypeStr() const
166 ShapeType aShapeType = shapeType();
167 std::string aShapeTypeStr;
171 aShapeTypeStr = "Compound";
175 aShapeTypeStr = "CompSolid";
179 aShapeTypeStr = "Solid";
183 aShapeTypeStr = "Shell";
187 aShapeTypeStr = "Face";
191 aShapeTypeStr = "Wire";
195 aShapeTypeStr = "Edge";
199 aShapeTypeStr = "Vertex";
203 aShapeTypeStr = "Shape";
208 return aShapeTypeStr;
211 bool GeomAPI_Shape::computeSize(double& theXmin, double& theYmin, double& theZmin,
212 double& theXmax, double& theYmax, double& theZmax) const
214 const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
218 BRepBndLib::Add(aShape, aBndBox);
219 aBndBox.Get(theXmin, theYmin, theZmin, theXmax, theYmax, theZmax);
223 std::string GeomAPI_Shape::getShapeStream() const
225 std::ostringstream aStream;
226 const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
227 BRepTools::Write(aShape, aStream);
228 return aStream.str();