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_Circle.hxx>
15 #include <Geom_Conic.hxx>
16 #include <Geom_Curve.hxx>
17 #include <Geom_Ellipse.hxx>
18 #include <Geom_Hyperbola.hxx>
19 #include <Geom_Line.hxx>
20 #include <Geom_Parabola.hxx>
21 #include <Geom_Plane.hxx>
22 #include <Geom_RectangularTrimmedSurface.hxx>
23 #include <Geom_TrimmedCurve.hxx>
25 #include <TopoDS_Iterator.hxx>
26 #include <TopoDS_Shape.hxx>
30 #define MY_SHAPE implPtr<TopoDS_Shape>()
32 GeomAPI_Shape::GeomAPI_Shape()
33 : GeomAPI_Interface(new TopoDS_Shape())
37 bool GeomAPI_Shape::isNull() const
39 return MY_SHAPE->IsNull() == Standard_True;
42 bool GeomAPI_Shape::isEqual(const std::shared_ptr<GeomAPI_Shape> theShape) const
47 return theShape->isNull();
48 if (theShape->isNull())
51 return MY_SHAPE->IsEqual(theShape->impl<TopoDS_Shape>()) == Standard_True;
54 bool GeomAPI_Shape::isVertex() const
56 const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
57 return !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX;
60 bool GeomAPI_Shape::isEdge() const
62 const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
63 return !aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE;
66 bool GeomAPI_Shape::isFace() const
68 const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
69 return !aShape.IsNull() && aShape.ShapeType() == TopAbs_FACE;
72 bool GeomAPI_Shape::isCompound() const
74 const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
75 return !aShape.IsNull() && aShape.ShapeType() == TopAbs_COMPOUND;
78 bool GeomAPI_Shape::isCompoundOfSolids() const
80 const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
81 if (aShape.IsNull() || aShape.ShapeType() != TopAbs_COMPOUND)
83 bool isAtLeastOne = false;
84 for(TopoDS_Iterator aSubs(aShape); aSubs.More(); aSubs.Next()) {
85 if (aSubs.Value().IsNull() || aSubs.Value().ShapeType() != TopAbs_SOLID)
92 bool GeomAPI_Shape::isSolid() const
94 const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
95 return !aShape.IsNull() && aShape.ShapeType() == TopAbs_SOLID;
98 bool GeomAPI_Shape::isCompSolid() const
100 const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
101 return !aShape.IsNull() && aShape.ShapeType() == TopAbs_COMPSOLID;
104 bool GeomAPI_Shape::isPlanar() const
106 TopoDS_Shape aShape = impl<TopoDS_Shape>();
108 if(aShape.IsNull()) {
112 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
113 if(aShapeType == TopAbs_COMPOUND) {
114 TopoDS_Iterator anIt(aShape);
116 for(; anIt.More(); anIt.Next()) {
120 anIt.Initialize(aShape);
121 aShape = anIt.Value();
125 aShapeType = aShape.ShapeType();
126 if(aShapeType == TopAbs_VERTEX) {
128 } else if(aShapeType == TopAbs_FACE) {
129 const Handle(Geom_Surface)& aSurface = BRep_Tool::Surface(TopoDS::Face(aShape));
130 Handle(Standard_Type) aType = aSurface->DynamicType();
132 if(aType == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
133 Handle(Geom_RectangularTrimmedSurface) aTrimSurface = Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface);
134 aType = aTrimSurface->BasisSurface()->DynamicType();
136 return (aType == STANDARD_TYPE(Geom_Plane)) == Standard_True;
138 BRepBuilderAPI_FindPlane aFindPlane(aShape);
139 bool isFound = aFindPlane.Found() == Standard_True;
141 if(!isFound && aShapeType == TopAbs_EDGE) {
142 Standard_Real aFirst, aLast;
143 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(aShape), aFirst, aLast);
144 Handle(Standard_Type) aType = aCurve->DynamicType();
146 if(aType == STANDARD_TYPE(Geom_TrimmedCurve)) {
147 Handle(Geom_TrimmedCurve) aTrimCurve = Handle(Geom_TrimmedCurve)::DownCast(aCurve);
148 aType = aTrimCurve->BasisCurve()->DynamicType();
151 if(aType == STANDARD_TYPE(Geom_Line)
152 || aType == STANDARD_TYPE(Geom_Conic)
153 || aType == STANDARD_TYPE(Geom_Circle)
154 || aType == STANDARD_TYPE(Geom_Ellipse)
155 || aType == STANDARD_TYPE(Geom_Hyperbola)
156 || aType == STANDARD_TYPE(Geom_Parabola)) {
167 GeomAPI_Shape::ShapeType GeomAPI_Shape::shapeType() const
169 const TopoDS_Shape& aShape = impl<TopoDS_Shape>();
171 ShapeType aST = GeomAPI_Shape::SHAPE;
173 switch(aShape.ShapeType()) {
174 case TopAbs_COMPOUND:
175 aST = GeomAPI_Shape::COMPOUND;
177 case TopAbs_COMPSOLID:
178 aST = GeomAPI_Shape::COMPSOLID;
181 aST = GeomAPI_Shape::SOLID;
184 aST = GeomAPI_Shape::SHELL;
187 aST = GeomAPI_Shape::FACE;
190 aST = GeomAPI_Shape::WIRE;
193 aST = GeomAPI_Shape::EDGE;
196 aST = GeomAPI_Shape::VERTEX;
199 aST = GeomAPI_Shape::SHAPE;
206 std::string GeomAPI_Shape::shapeTypeStr() const
208 ShapeType aShapeType = shapeType();
209 std::string aShapeTypeStr;
213 aShapeTypeStr = "Compound";
217 aShapeTypeStr = "CompSolid";
221 aShapeTypeStr = "Solid";
225 aShapeTypeStr = "Shell";
229 aShapeTypeStr = "Face";
233 aShapeTypeStr = "Wire";
237 aShapeTypeStr = "Edge";
241 aShapeTypeStr = "Vertex";
245 aShapeTypeStr = "Shape";
250 return aShapeTypeStr;
253 bool GeomAPI_Shape::computeSize(double& theXmin, double& theYmin, double& theZmin,
254 double& theXmax, double& theYmax, double& theZmax) const
256 const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
260 BRepBndLib::Add(aShape, aBndBox);
261 aBndBox.Get(theXmin, theYmin, theZmin, theXmax, theYmax, theZmax);
265 std::string GeomAPI_Shape::getShapeStream() const
267 std::ostringstream aStream;
268 const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
269 BRepTools::Write(aShape, aStream);
270 return aStream.str();