1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: GeomAlgoAPI_Placement.cpp
5 // Author: Artem ZHIDKOV
7 #include <GeomAlgoAPI_Placement.h>
8 #include <GeomAlgoAPI_DFLoader.h>
10 #include <GeomAPI_Pnt.h>
12 #include <BRepBuilderAPI_Transform.hxx>
13 #include <gp_Trsf.hxx>
14 #include <gp_Quaternion.hxx>
15 #include <TopExp_Explorer.hxx>
16 #include <BRepCheck_Analyzer.hxx>
17 #include <GProp_GProps.hxx>
18 #include <BRepGProp.hxx>
19 #include <Precision.hxx>
20 #define DEB_PLACEMENT 1
21 GeomAlgoAPI_Placement::GeomAlgoAPI_Placement(
22 std::shared_ptr<GeomAPI_Shape> theAttractiveFace,
23 std::shared_ptr<GeomAPI_Pln> theSourcePlane,
24 std::shared_ptr<GeomAPI_Pln> theDestPlane)
26 myShape(new GeomAPI_Shape())
28 build(theAttractiveFace, theSourcePlane, theDestPlane);
31 void GeomAlgoAPI_Placement::build(
32 const std::shared_ptr<GeomAPI_Shape>& theAttractiveShape,
33 const std::shared_ptr<GeomAPI_Pln>& theSourcePlane,
34 const std::shared_ptr<GeomAPI_Pln>& theDestPlane)
36 std::shared_ptr<GeomAPI_Dir> aSourceDir = theSourcePlane->direction();
37 std::shared_ptr<GeomAPI_Pnt> aSourceLoc = theSourcePlane->location();
38 std::shared_ptr<GeomAPI_Dir> aDestDir = theDestPlane->direction();
39 std::shared_ptr<GeomAPI_Pnt> aDestLoc = theDestPlane->location();
41 // Calculate transformation
43 gp_Vec aSrcDir(aSourceDir->x(), aSourceDir->y(), aSourceDir->z());
44 gp_Vec aDstDir(aDestDir->x(), aDestDir->y(), aDestDir->z());
45 gp_Quaternion aRot(aSrcDir, aDstDir);
46 aTrsf.SetRotation(aRot);
47 gp_Vec aSrcCenter(aSourceLoc->x(), aSourceLoc->y(), aSourceLoc->z());
48 aSrcCenter.Transform(aTrsf);
49 gp_Vec aTrans(aDestLoc->x() - aSrcCenter.X(),
50 aDestLoc->y() - aSrcCenter.Y(),
51 aDestLoc->z() - aSrcCenter.Z());
52 aTrsf.SetTransformation(aRot, aTrans);
54 // Transform the shape with copying it
55 const TopoDS_Shape& aShape = theAttractiveShape->impl<TopoDS_Shape>();
56 BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aShape, aTrsf, true);
59 myDone = aBuilder->IsDone() == Standard_True;
61 TopoDS_Shape aResult = aBuilder->Shape();
62 // fill data map to keep correct orientation of sub-shapes
63 for (TopExp_Explorer Exp(aResult,TopAbs_FACE); Exp.More(); Exp.Next()) {
64 std::shared_ptr<GeomAPI_Shape> aCurrentShape(new GeomAPI_Shape());
65 aCurrentShape->setImpl(new TopoDS_Shape(Exp.Current()));
66 myMap.bind(aCurrentShape, aCurrentShape);
69 int aNum = myMap.size();
70 cout << "MAP of Oriented shapes =" << aNum <<endl;
74 myShape->setImpl(new TopoDS_Shape(aResult));
75 myMkShape = new GeomAlgoAPI_MakeShape (aBuilder);
80 //============================================================================
81 const bool GeomAlgoAPI_Placement::isValid() const
83 BRepCheck_Analyzer aChecker(myShape->impl<TopoDS_Shape>());
84 return (aChecker.IsValid() == Standard_True);
87 //============================================================================
88 const bool GeomAlgoAPI_Placement::hasVolume() const
90 bool hasVolume(false);
92 const TopoDS_Shape& aRShape = myShape->impl<TopoDS_Shape>();
94 BRepGProp::VolumeProperties(aRShape, aGProp);
95 if(aGProp.Mass() > Precision::Confusion())
101 //============================================================================
102 const std::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Placement::shape () const
107 //============================================================================
108 void GeomAlgoAPI_Placement::mapOfShapes (GeomAPI_DataMapOfShapeShape& theMap) const
113 //============================================================================
114 GeomAlgoAPI_MakeShape * GeomAlgoAPI_Placement::makeShape() const
119 //============================================================================
120 GeomAlgoAPI_Placement::~GeomAlgoAPI_Placement()