1 // Copyright (C) 2014-2022 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "GeomAPI_Shape.h"
22 #include <GeomAPI_Pnt.h>
23 #include <GeomAPI_Vertex.h>
24 #include <GeomAPI_Edge.h>
25 #include <GeomAPI_Wire.h>
26 #include <GeomAPI_Face.h>
27 #include <GeomAPI_Shell.h>
28 #include <GeomAPI_Solid.h>
29 #include <GeomAPI_Trsf.h>
31 #include <BRep_Tool.hxx>
32 #include <BRepAlgoAPI_Section.hxx>
33 #include <BRepBndLib.hxx>
34 #include <BRepBuilderAPI_FindPlane.hxx>
35 #include <BRepBuilderAPI_Copy.hxx>
36 #include <BRepExtrema_DistShapeShape.hxx>
37 #include <BRepTools.hxx>
38 #include <Bnd_Box.hxx>
39 #include <Geom_Circle.hxx>
40 #include <Geom_Conic.hxx>
41 #include <Geom_Curve.hxx>
42 #include <Geom_Ellipse.hxx>
43 #include <Geom_Hyperbola.hxx>
44 #include <Geom_Line.hxx>
45 #include <Geom_Parabola.hxx>
46 #include <Geom_Plane.hxx>
47 #include <Geom_RectangularTrimmedSurface.hxx>
48 #include <Geom_TrimmedCurve.hxx>
49 #include <GeomLib_IsPlanarSurface.hxx>
50 #include <TopExp_Explorer.hxx>
52 #include <TopoDS_Iterator.hxx>
53 #include <TopoDS_Shape.hxx>
54 #include <NCollection_List.hxx>
56 #include <BOPAlgo_CheckerSI.hxx>
57 #include <BOPDS_DS.hxx>
58 #include <BOPTools_AlgoTools.hxx>
61 #include <algorithm> // for std::transform
63 #include <BRepTools.hxx>
65 #define MY_SHAPE implPtr<TopoDS_Shape>()
67 GeomAPI_Shape::GeomAPI_Shape()
68 : GeomAPI_Interface(new TopoDS_Shape())
72 std::shared_ptr<GeomAPI_Shape> GeomAPI_Shape::emptyCopied() const
74 GeomShapePtr aShape(new GeomAPI_Shape());
75 aShape->setImpl(new TopoDS_Shape(MY_SHAPE->EmptyCopied()));
79 bool GeomAPI_Shape::isNull() const
81 return MY_SHAPE->IsNull() == Standard_True;
84 bool GeomAPI_Shape::isEqual(const std::shared_ptr<GeomAPI_Shape> theShape) const
89 return theShape->isNull();
90 if (theShape->isNull())
93 return MY_SHAPE->IsEqual(theShape->impl<TopoDS_Shape>()) == Standard_True;
96 bool GeomAPI_Shape::isSame(const std::shared_ptr<GeomAPI_Shape> theShape) const
98 bool isNullShape = !theShape.get() || theShape->isNull();;
104 return MY_SHAPE->IsSame(theShape->impl<TopoDS_Shape>()) == Standard_True;
107 bool GeomAPI_Shape::isSameGeometry(const std::shared_ptr<GeomAPI_Shape> theShape) const
110 return face()->isSameGeometry(theShape);
112 return edge()->isSameGeometry(theShape);
116 bool GeomAPI_Shape::isVertex() const
118 const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
119 return !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX;
122 bool GeomAPI_Shape::isEdge() const
124 const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
125 return !aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE;
128 bool GeomAPI_Shape::isWire() const
130 const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
131 return !aShape.IsNull() && aShape.ShapeType() == TopAbs_WIRE;
134 bool GeomAPI_Shape::isFace() const
136 const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
137 return !aShape.IsNull() && aShape.ShapeType() == TopAbs_FACE;
140 bool GeomAPI_Shape::isShell() const
142 const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
143 return !aShape.IsNull() && aShape.ShapeType() == TopAbs_SHELL;
146 bool GeomAPI_Shape::isCompound() const
148 const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
149 return !aShape.IsNull() && aShape.ShapeType() == TopAbs_COMPOUND;
152 bool GeomAPI_Shape::isCollectionOfSolids() const
154 const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
158 if (aShape.ShapeType() == TopAbs_SOLID ||
159 aShape.ShapeType() == TopAbs_COMPSOLID)
162 if (aShape.ShapeType() != TopAbs_COMPOUND)
165 TopTools_ListOfShape aLS;
166 TopTools_MapOfShape aMFence;
167 BOPTools_AlgoTools::TreatCompound(aShape, aLS, &aMFence);
168 TopTools_ListOfShape::Iterator it(aLS);
169 for (; it.More(); it.Next()) {
170 const TopoDS_Shape& aSx = it.Value();
171 if (aSx.ShapeType() != TopAbs_SOLID &&
172 aSx.ShapeType() != TopAbs_COMPSOLID)
178 bool GeomAPI_Shape::isCompoundOfSolids() const
180 const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
181 if (aShape.IsNull() || aShape.ShapeType() != TopAbs_COMPOUND)
183 bool isAtLeastOne = false;
184 for(TopoDS_Iterator aSubs(aShape); aSubs.More(); aSubs.Next()) {
185 if (aSubs.Value().IsNull() || aSubs.Value().ShapeType() != TopAbs_SOLID)
193 GeomAPI_Shape::ShapeType GeomAPI_Shape::typeOfCompoundShapes() const
195 const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
196 if (aShape.IsNull() || aShape.ShapeType() != TopAbs_COMPOUND)
199 for(TopoDS_Iterator aSubs(aShape); aSubs.More(); aSubs.Next()) {
200 if (!aSubs.Value().IsNull()) {
202 aType = aSubs.Value().ShapeType();
203 else if (aSubs.Value().ShapeType() != aType)
207 return (GeomAPI_Shape::ShapeType) aType;
211 // adds the nopt-compound elements recursively to the list
212 static void addSimpleToList(const TopoDS_Shape& theShape, NCollection_List<TopoDS_Shape>& theList)
214 if (!theShape.IsNull()) {
215 if (theShape.ShapeType() == TopAbs_COMPOUND) {
216 for(TopoDS_Iterator aSubs(theShape); aSubs.More(); aSubs.Next()) {
217 addSimpleToList(aSubs.Value(), theList);
220 theList.Append(theShape);
225 bool GeomAPI_Shape::isConnectedTopology() const
227 const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
228 if (aShape.IsNull() || aShape.ShapeType() != TopAbs_COMPOUND)
230 // list of simple elements that are not detected in connection to others
231 NCollection_List<TopoDS_Shape> aNotConnected;
232 addSimpleToList(aShape, aNotConnected);
233 if (aNotConnected.IsEmpty()) // an empty compound
236 // collect here the group of connected subs, starting with one first element
237 NCollection_List<TopoDS_Shape> aNewConnected;
238 aNewConnected.Append(aNotConnected.First());
239 aNotConnected.RemoveFirst();
240 // iterate until some new element become connected
241 while(!aNewConnected.IsEmpty() && !aNotConnected.IsEmpty()) {
242 NCollection_List<TopoDS_Shape> aNew; // very new connected to new connected
243 NCollection_List<TopoDS_Shape>::Iterator aNotIter(aNotConnected);
244 while(aNotIter.More()) {
245 // optimization to avoid TopExp_Explorer double-cycle, collect all vertices in the list first
246 NCollection_List<TopoDS_Shape> aNotVertices;
247 for(TopExp_Explorer anExp1(aNotIter.Value(), TopAbs_VERTEX); anExp1.More(); anExp1.Next()) {
248 aNotVertices.Append(anExp1.Current());
251 bool aConnected = false;
252 NCollection_List<TopoDS_Shape>::Iterator aNewIter(aNewConnected);
253 for(; !aConnected && aNewIter.More(); aNewIter.Next()) {
254 // checking topological connecion of aNotIter and aNewIter
255 // (if shapes are connected, vertices are connected for sure)
256 TopExp_Explorer anExp2(aNewIter.Value(), TopAbs_VERTEX);
257 for(; !aConnected && anExp2.More(); anExp2.Next()) {
258 NCollection_List<TopoDS_Shape>::Iterator aNotVIter(aNotVertices);
259 for(; aNotVIter.More(); aNotVIter.Next()) {
260 if (aNotVIter.Value().IsSame(anExp2.Current())) {
268 aNew.Append(aNotIter.Value());
269 aNotConnected.Remove(aNotIter);
274 // remove all new connected and put to this list very new connected
275 aNewConnected.Clear();
276 aNewConnected.Append(aNew);
278 return aNotConnected.IsEmpty() == Standard_True;
281 bool GeomAPI_Shape::isSolid() const
283 const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
284 return !aShape.IsNull() && aShape.ShapeType() == TopAbs_SOLID;
287 bool GeomAPI_Shape::isCompSolid() const
289 const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
290 return !aShape.IsNull() && aShape.ShapeType() == TopAbs_COMPSOLID;
293 bool GeomAPI_Shape::isPlanar() const
295 TopoDS_Shape aShape = impl<TopoDS_Shape>();
297 if(aShape.IsNull()) {
301 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
302 if(aShapeType == TopAbs_COMPOUND) {
303 TopoDS_Iterator anIt(aShape);
305 for(; anIt.More(); anIt.Next()) {
309 anIt.Initialize(aShape);
310 aShape = anIt.Value();
314 aShapeType = aShape.ShapeType();
315 if(aShapeType == TopAbs_VERTEX) {
317 } else if(aShapeType == TopAbs_FACE) {
318 Handle(Geom_Surface) aSurface = BRep_Tool::Surface(TopoDS::Face(aShape));
319 if(aSurface->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
320 Handle(Geom_RectangularTrimmedSurface) aTrimSurface =
321 Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface);
322 aSurface = aTrimSurface->BasisSurface();
324 return GeomLib_IsPlanarSurface(aSurface).IsPlanar();
326 BRepBuilderAPI_FindPlane aFindPlane(aShape);
327 bool isFound = aFindPlane.Found() == Standard_True;
329 if(!isFound && aShapeType == TopAbs_EDGE) {
330 Standard_Real aFirst, aLast;
331 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(aShape), aFirst, aLast);
332 Handle(Standard_Type) aType = aCurve->DynamicType();
334 if(aType == STANDARD_TYPE(Geom_TrimmedCurve)) {
335 Handle(Geom_TrimmedCurve) aTrimCurve = Handle(Geom_TrimmedCurve)::DownCast(aCurve);
336 aType = aTrimCurve->BasisCurve()->DynamicType();
339 if(aType == STANDARD_TYPE(Geom_Line)
340 || aType == STANDARD_TYPE(Geom_Conic)
341 || aType == STANDARD_TYPE(Geom_Circle)
342 || aType == STANDARD_TYPE(Geom_Ellipse)
343 || aType == STANDARD_TYPE(Geom_Hyperbola)
344 || aType == STANDARD_TYPE(Geom_Parabola)) {
355 std::shared_ptr<GeomAPI_Vertex> GeomAPI_Shape::vertex() const
357 GeomVertexPtr aVertex;
359 const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
360 aVertex = GeomVertexPtr(new GeomAPI_Vertex);
361 aVertex->setImpl(new TopoDS_Shape(aShape));
366 std::shared_ptr<GeomAPI_Edge> GeomAPI_Shape::edge() const
370 const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
371 anEdge = GeomEdgePtr(new GeomAPI_Edge);
372 anEdge->setImpl(new TopoDS_Shape(aShape));
377 std::shared_ptr<GeomAPI_Wire> GeomAPI_Shape::wire() const
381 const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
382 aWire = GeomWirePtr(new GeomAPI_Wire);
383 aWire->setImpl(new TopoDS_Shape(aShape));
388 std::shared_ptr<GeomAPI_Face> GeomAPI_Shape::face() const
392 const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
393 aFace = GeomFacePtr(new GeomAPI_Face);
394 aFace->setImpl(new TopoDS_Shape(aShape));
399 std::shared_ptr<GeomAPI_Shell> GeomAPI_Shape::shell() const
403 const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
404 aShell = GeomShellPtr(new GeomAPI_Shell);
405 aShell->setImpl(new TopoDS_Shape(aShape));
410 std::shared_ptr<GeomAPI_Solid> GeomAPI_Shape::solid() const
414 const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
415 aSolid = GeomSolidPtr(new GeomAPI_Solid);
416 aSolid->setImpl(new TopoDS_Shape(aShape));
421 std::list<std::shared_ptr<GeomAPI_Shape> >
422 GeomAPI_Shape::subShapes(const ShapeType theSubShapeType, const bool theOnlyUnique) const
425 const TopoDS_Shape& aShape = impl<TopoDS_Shape>();
429 TopTools_MapOfShape alreadyThere;
431 // process multi-level compounds
432 if (shapeType() == COMPOUND && theSubShapeType == COMPOUND) {
433 for (TopoDS_Iterator anIt(aShape); anIt.More(); anIt.Next()) {
434 const TopoDS_Shape& aCurrent = anIt.Value();
435 if (aCurrent.ShapeType() == TopAbs_COMPOUND) {
436 if (!theOnlyUnique || alreadyThere.Add(aCurrent)) {
437 GeomShapePtr aSub(new GeomAPI_Shape);
438 aSub->setImpl(new TopoDS_Shape(aCurrent));
439 aSubs.push_back(aSub);
444 GeomShapePtr aSub(new GeomAPI_Shape);
445 aSub->setImpl(new TopoDS_Shape(aShape));
446 aSubs.push_back(aSub);
449 for (TopExp_Explorer anExp(aShape, (TopAbs_ShapeEnum)theSubShapeType);
450 anExp.More(); anExp.Next()) {
451 if (!theOnlyUnique || alreadyThere.Add(anExp.Current())) {
452 GeomShapePtr aSub(new GeomAPI_Shape);
453 aSub->setImpl(new TopoDS_Shape(anExp.Current()));
454 aSubs.push_back(aSub);
461 GeomAPI_Shape::ShapeType GeomAPI_Shape::shapeType() const
463 const TopoDS_Shape& aShape = impl<TopoDS_Shape>();
465 return GeomAPI_Shape::SHAPE;
467 ShapeType aST = GeomAPI_Shape::SHAPE;
469 switch(aShape.ShapeType()) {
470 case TopAbs_COMPOUND:
471 aST = GeomAPI_Shape::COMPOUND;
473 case TopAbs_COMPSOLID:
474 aST = GeomAPI_Shape::COMPSOLID;
477 aST = GeomAPI_Shape::SOLID;
480 aST = GeomAPI_Shape::SHELL;
483 aST = GeomAPI_Shape::FACE;
486 aST = GeomAPI_Shape::WIRE;
489 aST = GeomAPI_Shape::EDGE;
492 aST = GeomAPI_Shape::VERTEX;
495 aST = GeomAPI_Shape::SHAPE;
502 GeomAPI_Shape::ShapeType GeomAPI_Shape::shapeTypeByStr(std::string theType)
504 std::transform(theType.begin(), theType.end(), theType.begin(),
505 [](char c) { return static_cast<char>(::toupper(c)); });
506 if (theType == "COMPOUND" || theType == "COMPOUNDS")
508 if (theType == "COMPSOLID" || theType == "COMPSOLIDS")
510 if (theType == "SOLID" || theType == "SOLIDS")
512 if (theType == "SHELL" || theType == "SHELLS")
514 if (theType == "FACE" || theType == "FACES")
516 if (theType == "WIRE" || theType == "WIRES")
518 if (theType == "EDGE" || theType == "EDGES")
520 if (theType == "VERTEX" || theType == "VERTICES")
522 return SHAPE; // default
525 std::string GeomAPI_Shape::shapeTypeStr() const
527 ShapeType aShapeType = shapeType();
528 std::string aShapeTypeStr;
532 aShapeTypeStr = "COMPOUND";
536 aShapeTypeStr = "COMPSOLID";
540 aShapeTypeStr = "SOLID";
544 aShapeTypeStr = "SHELL";
548 aShapeTypeStr = "FACE";
552 aShapeTypeStr = "WIRE";
556 aShapeTypeStr = "EDGE";
560 aShapeTypeStr = "VERTEX";
564 aShapeTypeStr = "SHAPE";
569 return aShapeTypeStr;
572 GeomAPI_Shape::Orientation GeomAPI_Shape::orientation() const
574 TopAbs_Orientation anOrientation = MY_SHAPE->Orientation();
576 switch(anOrientation) {
577 case TopAbs_FORWARD: return FORWARD;
578 case TopAbs_REVERSED: return REVERSED;
579 case TopAbs_INTERNAL: return INTERNAL;
580 case TopAbs_EXTERNAL: return EXTERNAL;
581 default: return FORWARD;
585 void GeomAPI_Shape::setOrientation(const GeomAPI_Shape::Orientation theOrientation)
587 switch(theOrientation) {
588 case FORWARD: MY_SHAPE->Orientation(TopAbs_FORWARD); break;
589 case REVERSED: MY_SHAPE->Orientation(TopAbs_REVERSED); break;
590 case INTERNAL: MY_SHAPE->Orientation(TopAbs_INTERNAL); break;
591 case EXTERNAL: MY_SHAPE->Orientation(TopAbs_EXTERNAL); break;
595 void GeomAPI_Shape::reverse()
600 bool GeomAPI_Shape::isSubShape(const std::shared_ptr<GeomAPI_Shape> theShape,
601 const bool theCheckOrientation) const
603 if(!theShape.get()) {
607 const TopoDS_Shape& aShapeToSearch = theShape->impl<TopoDS_Shape>();
608 if(aShapeToSearch.IsNull()) {
612 for(TopExp_Explorer anExp(*MY_SHAPE, aShapeToSearch.ShapeType()); anExp.More(); anExp.Next()) {
613 if(theCheckOrientation ?
614 aShapeToSearch.IsEqual(anExp.Current()) : aShapeToSearch.IsSame(anExp.Current())) {
622 bool GeomAPI_Shape::computeSize(double& theXmin, double& theYmin, double& theZmin,
623 double& theXmax, double& theYmax, double& theZmax) const
625 const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
629 // Workaround: compute optimal bounding box for the compounds of edges/vertices, because sometimes
630 // the bounding box of sketch is calculated if the transformation is applied twice (issue #20167).
631 bool isShape1D = false;
632 if (aShape.ShapeType() == TopAbs_COMPOUND) {
634 for (TopoDS_Iterator anIt(aShape); anIt.More() && isShape1D; anIt.Next())
635 if (anIt.Value().ShapeType() < TopAbs_WIRE)
639 BRepBndLib::AddOptimal(aShape, aBndBox, false, true);
641 BRepBndLib::Add(aShape, aBndBox, false);
642 if (aBndBox.IsVoid())
644 aBndBox.Get(theXmin, theYmin, theZmin, theXmax, theYmax, theZmax);
648 GeomPointPtr GeomAPI_Shape::middlePoint() const
650 GeomPointPtr aMiddlePoint;
652 switch (shapeType()) {
654 aMiddlePoint = vertex()->point();
657 aMiddlePoint = edge()->middlePoint();
660 aMiddlePoint = wire()->middlePoint();
663 aMiddlePoint = face()->middlePoint();
666 aMiddlePoint = shell()->middlePoint();
669 aMiddlePoint = solid()->middlePoint();
672 // get middle point as center of the bounding box
673 double aMinX, aMinY, aMinZ, aMaxX, aMaxY, aMaxZ;
674 computeSize(aMinX, aMinY, aMinZ, aMaxX, aMaxY, aMaxZ);
675 aMiddlePoint = GeomPointPtr(new GeomAPI_Pnt(
676 (aMinX + aMaxX) * 0.5, (aMinY + aMaxY) * 0.5, (aMinZ + aMaxZ) * 0.5));
684 std::string GeomAPI_Shape::getShapeStream(const bool theWithTriangulation) const
686 std::ostringstream aStream;
687 const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
688 if (!theWithTriangulation) { // make a copy of shape without triangulation
689 BRepBuilderAPI_Copy aCopy(aShape, Standard_False, Standard_False);
690 const TopoDS_Shape& aCopyShape = aCopy.Shape();
691 // make all faces unchecked to make the stream of shapes the same
692 TopExp_Explorer aFaceExp(aCopyShape, TopAbs_FACE);
693 for(; aFaceExp.More(); aFaceExp.Next()) {
694 aFaceExp.Current().TShape()->Checked(Standard_False);
696 BRepTools::Write(aCopyShape, aStream);
698 BRepTools::Write(aShape, aStream);
700 return aStream.str();
704 GeomShapePtr GeomAPI_Shape::intersect(const GeomShapePtr theShape) const
706 const TopoDS_Shape& aShape1 = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
707 const TopoDS_Shape& aShape2 = theShape->impl<TopoDS_Shape>();
709 BRepAlgoAPI_Section aCommon(aShape1, aShape2);
710 if (!aCommon.IsDone())
711 return GeomShapePtr();
713 TopoDS_Shape aResult = aCommon.Shape();
714 if (aResult.ShapeType() == TopAbs_COMPOUND) {
715 NCollection_List<TopoDS_Shape> aSubs;
716 addSimpleToList(aResult, aSubs);
717 if(aSubs.Size() == 1) {
718 aResult = aSubs.First();
719 } else if(aSubs.Size() == 0) {
720 return GeomShapePtr();
724 GeomShapePtr aResShape(new GeomAPI_Shape);
725 aResShape->setImpl(new TopoDS_Shape(aResult));
729 bool GeomAPI_Shape::isIntersect(const GeomShapePtr theShape) const
731 if(!theShape.get()) {
735 const TopoDS_Shape& aShape1 = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
736 const TopoDS_Shape& aShape2 = theShape->impl<TopoDS_Shape>();
738 BRepExtrema_DistShapeShape aDist(aShape1, aShape2);
740 if(aDist.IsDone() && aDist.Value() < Precision::Confusion()) {
747 void GeomAPI_Shape::translate(const std::shared_ptr<GeomAPI_Dir> theDir, const double theOffset)
749 gp_Dir aDir = theDir->impl<gp_Dir>();
750 gp_Vec aTrsfVec(aDir.XYZ() * theOffset);
751 gp_Trsf aTranslation;
752 aTranslation.SetTranslation(aTrsfVec);
753 TopoDS_Shape aResult = MY_SHAPE->Moved(aTranslation);
754 setImpl(new TopoDS_Shape(aResult));
757 void GeomAPI_Shape::move(const std::shared_ptr<GeomAPI_Trsf> theTransformation)
759 TopoDS_Shape aResult = MY_SHAPE->Moved(theTransformation->impl<gp_Trsf>());
760 setImpl(new TopoDS_Shape(aResult));
763 bool GeomAPI_Shape::isSelfIntersected(const int theLevelOfCheck) const
765 BOPAlgo_CheckerSI aCSI; // checker of self-interferences
766 aCSI.SetLevelOfCheck(theLevelOfCheck);
767 TopTools_ListOfShape aList;
768 const TopoDS_Shape& aThisShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
769 aList.Append(aThisShape);
770 aCSI.SetArguments(aList);
772 if (aCSI.HasErrors() || aCSI.DS().Interferences().Extent() > 0) {
779 bool GeomAPI_Shape::Comparator::operator()(const std::shared_ptr<GeomAPI_Shape>& theShape1,
780 const std::shared_ptr<GeomAPI_Shape>& theShape2) const
782 const TopoDS_Shape& aShape1 = theShape1->impl<TopoDS_Shape>();
783 const TopoDS_Shape& aShape2 = theShape2->impl<TopoDS_Shape>();
784 bool isLess = aShape1.TShape() < aShape2.TShape();
785 if (aShape1.TShape() == aShape2.TShape()) {
786 Standard_Integer aHash1 = aShape1.Location().HashCode(IntegerLast());
787 Standard_Integer aHash2 = aShape2.Location().HashCode(IntegerLast());
788 isLess = aHash1 < aHash2;
793 bool GeomAPI_Shape::ComparatorWithOri::operator()(
794 const std::shared_ptr<GeomAPI_Shape>& theShape1,
795 const std::shared_ptr<GeomAPI_Shape>& theShape2) const
797 const TopoDS_Shape& aShape1 = theShape1->impl<TopoDS_Shape>();
798 const TopoDS_Shape& aShape2 = theShape2->impl<TopoDS_Shape>();
799 bool isLess = aShape1.TShape() < aShape2.TShape();
800 if (aShape1.TShape() == aShape2.TShape()) {
801 Standard_Integer aHash1 = aShape1.Location().HashCode(IntegerLast());
802 Standard_Integer aHash2 = aShape2.Location().HashCode(IntegerLast());
803 isLess = (aHash1 < aHash2) ||
804 (aHash1 == aHash2 && aShape1.Orientation() < aShape2.Orientation());
809 int GeomAPI_Shape::Hash::operator()(const std::shared_ptr<GeomAPI_Shape>& theShape) const
811 const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
812 return aShape.HashCode(IntegerLast());
815 bool GeomAPI_Shape::Equal::operator()(const std::shared_ptr<GeomAPI_Shape>& theShape1,
816 const std::shared_ptr<GeomAPI_Shape>& theShape2) const
818 const TopoDS_Shape& aShape1 = theShape1->impl<TopoDS_Shape>();
819 const TopoDS_Shape& aShape2 = theShape2->impl<TopoDS_Shape>();
821 Standard_Integer aHash1 = aShape1.Location().HashCode(IntegerLast());
822 Standard_Integer aHash2 = aShape2.Location().HashCode(IntegerLast());
824 return aShape1.TShape() == aShape2.TShape() && aHash1 == aHash2;