From 33baa4a9f265753d63588e99bf1db6f3bd57d93c Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 19 Sep 2017 15:43:28 +0200 Subject: [PATCH] add convenience methods to directly set/get a placement to/from a shape --- src/Mod/Part/App/TopoShape.cpp | 30 ++++++++++++++++++++++++++++++ src/Mod/Part/App/TopoShape.h | 4 ++++ 2 files changed, 34 insertions(+) diff --git a/src/Mod/Part/App/TopoShape.cpp b/src/Mod/Part/App/TopoShape.cpp index c377ac0e0c..30af09dc15 100644 --- a/src/Mod/Part/App/TopoShape.cpp +++ b/src/Mod/Part/App/TopoShape.cpp @@ -433,6 +433,36 @@ Base::Matrix4D TopoShape::getTransform(void) const return mtrx; } +void TopoShape::setPlacement(const Base::Placement& rclTrf) +{ + const Base::Vector3d& pos = rclTrf.getPosition(); + Base::Vector3d axis; + double angle; + rclTrf.getRotation().getValue(axis, angle); + + gp_Trsf trsf; + trsf.SetRotation(gp_Ax1(gp_Pnt(0.,0.,0.), gp_Dir(axis.x, axis.y, axis.z)), angle); + trsf.SetTranslationPart(gp_Vec(pos.x, pos.y, pos.z)); + TopLoc_Location loc(trsf); + _Shape.Location(loc); +} + +Base::Placement TopoShape::getPlacemet(void) const +{ + TopLoc_Location loc = _Shape.Location(); + gp_Trsf trsf = loc.Transformation(); + gp_XYZ pos = trsf.TranslationPart(); + + gp_XYZ axis; + Standard_Real angle; + trsf.GetRotation(axis, angle); + + Base::Rotation rot(Base::Vector3d(axis.X(), axis.Y(), axis.Z()), angle); + Base::Placement placement(Base::Vector3d(pos.X(), pos.Y(), pos.Z()), rot); + + return placement; +} + void TopoShape::read(const char *FileName) { Base::FileInfo File(FileName); diff --git a/src/Mod/Part/App/TopoShape.h b/src/Mod/Part/App/TopoShape.h index 8f97f4dd9d..e4d1a44fc6 100644 --- a/src/Mod/Part/App/TopoShape.h +++ b/src/Mod/Part/App/TopoShape.h @@ -77,8 +77,12 @@ public: //@{ /// set the transformation of the CasCade Shape void setTransform(const Base::Matrix4D& rclTrf); + /// set the transformation of the CasCade Shape + void setPlacement(const Base::Placement& rclTrf); /// get the transformation of the CasCade Shape Base::Matrix4D getTransform(void) const; + /// get the transformation of the CasCade Shape + Base::Placement getPlacemet(void) const; /// Bound box from the CasCade shape Base::BoundBox3d getBoundBox(void)const; virtual bool getCenterOfGravity(Base::Vector3d& center) const;