1 // File: GeomAlgoAPI_Placement.cpp
3 // Author: Artem ZHIDKOV
5 #include <GeomAlgoAPI_Placement.h>
6 #include <GeomAlgoAPI_DFLoader.h>
8 #include <GeomAPI_Pnt.h>
10 #include <BRepBuilderAPI_Transform.hxx>
11 #include <gp_Trsf.hxx>
12 #include <gp_Quaternion.hxx>
13 #include <TopExp_Explorer.hxx>
14 #include <BRepCheck_Analyzer.hxx>
15 #include <GProp_GProps.hxx>
16 #include <BRepGProp.hxx>
17 #include <Precision.hxx>
20 GeomAlgoAPI_Placement::GeomAlgoAPI_Placement(
21 std::shared_ptr<GeomAPI_Shape> theAttractiveFace,
22 std::shared_ptr<GeomAPI_Pln> theSourcePlane,
23 std::shared_ptr<GeomAPI_Pln> theDestPlane)
25 myShape(new GeomAPI_Shape())
27 build(theAttractiveFace, theSourcePlane, theDestPlane);
30 void GeomAlgoAPI_Placement::build(
31 const std::shared_ptr<GeomAPI_Shape>& theAttractiveShape,
32 const std::shared_ptr<GeomAPI_Pln>& theSourcePlane,
33 const std::shared_ptr<GeomAPI_Pln>& theDestPlane)
35 std::shared_ptr<GeomAPI_Dir> aSourceDir = theSourcePlane->direction();
36 std::shared_ptr<GeomAPI_Pnt> aSourceLoc = theSourcePlane->location();
37 std::shared_ptr<GeomAPI_Dir> aDestDir = theDestPlane->direction();
38 std::shared_ptr<GeomAPI_Pnt> aDestLoc = theDestPlane->location();
40 // Calculate transformation
42 gp_Vec aSrcDir(aSourceDir->x(), aSourceDir->y(), aSourceDir->z());
43 gp_Vec aDstDir(aDestDir->x(), aDestDir->y(), aDestDir->z());
44 gp_Quaternion aRot(aSrcDir, aDstDir);
45 aTrsf.SetRotation(aRot);
46 gp_Vec aSrcCenter(aSourceLoc->x(), aSourceLoc->y(), aSourceLoc->z());
47 aSrcCenter.Transform(aTrsf);
48 gp_Vec aTrans(aDestLoc->x() - aSrcCenter.X(),
49 aDestLoc->y() - aSrcCenter.Y(),
50 aDestLoc->z() - aSrcCenter.Z());
51 aTrsf.SetTransformation(aRot, aTrans);
53 // Transform the shape with copying it
54 const TopoDS_Shape& aShape = theAttractiveShape->impl<TopoDS_Shape>();
55 BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aShape, aTrsf, true);
58 myDone = aBuilder->IsDone() == Standard_True;
60 TopoDS_Shape aResult = aBuilder->Shape();
61 // fill data map to keep correct orientation of sub-shapes
62 for (TopExp_Explorer Exp(aResult,TopAbs_FACE); Exp.More(); Exp.Next()) {
63 std::shared_ptr<GeomAPI_Shape> aCurrentShape(new GeomAPI_Shape());
64 aCurrentShape->setImpl(new TopoDS_Shape(Exp.Current()));
65 myMap.bind(aCurrentShape, aCurrentShape);
67 myShape->setImpl(new TopoDS_Shape(aResult));
68 myMkShape = new GeomAlgoAPI_MakeShape (aBuilder);
73 //============================================================================
74 const bool GeomAlgoAPI_Placement::isValid() const
76 BRepCheck_Analyzer aChecker(myShape->impl<TopoDS_Shape>());
77 return (aChecker.IsValid() == Standard_True);
80 //============================================================================
81 const bool GeomAlgoAPI_Placement::hasVolume() const
83 bool hasVolume(false);
85 const TopoDS_Shape& aRShape = myShape->impl<TopoDS_Shape>();
87 BRepGProp::VolumeProperties(aRShape, aGProp);
88 if(aGProp.Mass() > Precision::Confusion())
94 //============================================================================
95 const std::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Placement::shape () const
100 //============================================================================
101 void GeomAlgoAPI_Placement::mapOfShapes (GeomAPI_DataMapOfShapeShape& theMap) const
106 //============================================================================
107 GeomAlgoAPI_MakeShape * GeomAlgoAPI_Placement::makeShape() const
112 //============================================================================
113 GeomAlgoAPI_Placement::~GeomAlgoAPI_Placement()