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>
18 #define DEB_PLACEMENT 1
19 GeomAlgoAPI_Placement::GeomAlgoAPI_Placement(
20 std::shared_ptr<GeomAPI_Shape> theAttractiveFace,
21 std::shared_ptr<GeomAPI_Pln> theSourcePlane,
22 std::shared_ptr<GeomAPI_Pln> theDestPlane)
24 myShape(new GeomAPI_Shape())
26 build(theAttractiveFace, theSourcePlane, theDestPlane);
29 void GeomAlgoAPI_Placement::build(
30 const std::shared_ptr<GeomAPI_Shape>& theAttractiveShape,
31 const std::shared_ptr<GeomAPI_Pln>& theSourcePlane,
32 const std::shared_ptr<GeomAPI_Pln>& theDestPlane)
34 std::shared_ptr<GeomAPI_Dir> aSourceDir = theSourcePlane->direction();
35 std::shared_ptr<GeomAPI_Pnt> aSourceLoc = theSourcePlane->location();
36 std::shared_ptr<GeomAPI_Dir> aDestDir = theDestPlane->direction();
37 std::shared_ptr<GeomAPI_Pnt> aDestLoc = theDestPlane->location();
39 // Calculate transformation
41 gp_Vec aSrcDir(aSourceDir->x(), aSourceDir->y(), aSourceDir->z());
42 gp_Vec aDstDir(aDestDir->x(), aDestDir->y(), aDestDir->z());
43 gp_Quaternion aRot(aSrcDir, aDstDir);
44 aTrsf.SetRotation(aRot);
45 gp_Vec aSrcCenter(aSourceLoc->x(), aSourceLoc->y(), aSourceLoc->z());
46 aSrcCenter.Transform(aTrsf);
47 gp_Vec aTrans(aDestLoc->x() - aSrcCenter.X(),
48 aDestLoc->y() - aSrcCenter.Y(),
49 aDestLoc->z() - aSrcCenter.Z());
50 aTrsf.SetTransformation(aRot, aTrans);
52 // Transform the shape with copying it
53 const TopoDS_Shape& aShape = theAttractiveShape->impl<TopoDS_Shape>();
54 BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aShape, aTrsf, true);
57 myDone = aBuilder->IsDone() == Standard_True;
59 TopoDS_Shape aResult = aBuilder->Shape();
60 // fill data map to keep correct orientation of sub-shapes
61 for (TopExp_Explorer Exp(aResult,TopAbs_FACE); Exp.More(); Exp.Next()) {
62 std::shared_ptr<GeomAPI_Shape> aCurrentShape(new GeomAPI_Shape());
63 aCurrentShape->setImpl(new TopoDS_Shape(Exp.Current()));
64 myMap.bind(aCurrentShape, aCurrentShape);
67 int aNum = myMap.size();
68 cout << "MAP of Oriented shapes =" << aNum <<endl;
72 myShape->setImpl(new TopoDS_Shape(aResult));
73 myMkShape = new GeomAlgoAPI_MakeShape (aBuilder);
78 //============================================================================
79 const bool GeomAlgoAPI_Placement::isValid() const
81 BRepCheck_Analyzer aChecker(myShape->impl<TopoDS_Shape>());
82 return (aChecker.IsValid() == Standard_True);
85 //============================================================================
86 const bool GeomAlgoAPI_Placement::hasVolume() const
88 bool hasVolume(false);
90 const TopoDS_Shape& aRShape = myShape->impl<TopoDS_Shape>();
92 BRepGProp::VolumeProperties(aRShape, aGProp);
93 if(aGProp.Mass() > Precision::Confusion())
99 //============================================================================
100 const std::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Placement::shape () const
105 //============================================================================
106 void GeomAlgoAPI_Placement::mapOfShapes (GeomAPI_DataMapOfShapeShape& theMap) const
111 //============================================================================
112 GeomAlgoAPI_MakeShape * GeomAlgoAPI_Placement::makeShape() const
117 //============================================================================
118 GeomAlgoAPI_Placement::~GeomAlgoAPI_Placement()