From 64957a55eb4856d3ee4e2ff4988ba6dff1ce1f94 Mon Sep 17 00:00:00 2001 From: "MA-DEVELOP\\apeltauer" Date: Tue, 29 Jan 2019 09:08:44 +0100 Subject: [PATCH] transform sub shapes to global position --- src/Mod/Part/Gui/DlgProjectionOnSurface.cpp | 35 +++++++++++++++++++++ src/Mod/Part/Gui/DlgProjectionOnSurface.h | 1 + 2 files changed, 36 insertions(+) diff --git a/src/Mod/Part/Gui/DlgProjectionOnSurface.cpp b/src/Mod/Part/Gui/DlgProjectionOnSurface.cpp index 01c64082cb..f075908e0e 100644 --- a/src/Mod/Part/Gui/DlgProjectionOnSurface.cpp +++ b/src/Mod/Part/Gui/DlgProjectionOnSurface.cpp @@ -55,6 +55,8 @@ #include #include #include +#include +#include using namespace PartGui; @@ -339,6 +341,9 @@ void PartGui::DlgProjectionOnSurface::store_current_selected_parts(std::vectorgetNameInDocument(); auto currentShape = aPart->Shape.getShape().getSubShape(itName->c_str()); + + transform_shape_to_global_postion(currentShape, aPart); + currentShapeStore.inputShape = currentShape; currentShapeStore.partName = *itName; auto store = store_part_in_vector(currentShapeStore, iStoreVec); @@ -348,6 +353,7 @@ void PartGui::DlgProjectionOnSurface::store_current_selected_parts(std::vectorShape.getName(), store, iColor); } @@ -869,6 +875,35 @@ void PartGui::DlgProjectionOnSurface::set_xyz_dir_spinbox(QDoubleSpinBox* icurre icurrentSpinBox->setValue(newVal); } +void PartGui::DlgProjectionOnSurface::transform_shape_to_global_postion(TopoDS_Shape& ioShape, Part::Feature* iPart) +{ + auto currentPos = iPart->Placement.getValue().getPosition(); + auto currentRotation = iPart->Placement.getValue().getRotation(); + auto globalPlacement = iPart->globalPlacement(); + auto globalPostion = globalPlacement.getPosition(); + auto globalRotation = globalPlacement.getRotation(); + + if (currentRotation != globalRotation) + { + auto newRotation = globalRotation; + newRotation *= currentRotation.invert(); + + gp_Trsf aAngleTransform; + Base::Vector3d rotationAxes; + double rotationAngle; + newRotation.getRawValue(rotationAxes, rotationAngle); + aAngleTransform.SetRotation(gp_Ax1(gp_Pnt(currentPos.x, currentPos.y, currentPos.z), gp_Dir(rotationAxes.x, rotationAxes.y, rotationAxes.z)), rotationAngle); + ioShape = BRepBuilderAPI_Transform(ioShape, aAngleTransform, true).Shape(); + } + + if (currentPos != globalPostion) + { + gp_Trsf aPosTransform; + aPosTransform.SetTranslation(gp_Pnt(currentPos.x, currentPos.y, currentPos.z), gp_Pnt(globalPostion.x, globalPostion.y, globalPostion.z)); + ioShape = BRepBuilderAPI_Transform(ioShape, aPosTransform, true).Shape(); + } +} + void PartGui::DlgProjectionOnSurface::on_pushButtonAddProjFace_clicked() { if (ui->pushButtonAddProjFace->isChecked()) diff --git a/src/Mod/Part/Gui/DlgProjectionOnSurface.h b/src/Mod/Part/Gui/DlgProjectionOnSurface.h index 185eedaa0e..3db1e545ed 100644 --- a/src/Mod/Part/Gui/DlgProjectionOnSurface.h +++ b/src/Mod/Part/Gui/DlgProjectionOnSurface.h @@ -113,6 +113,7 @@ private: void create_face_extrude(std::vector& iCurrentShape); void store_wire_in_vector(const SShapeStore& iCurrentShape, const TopoDS_Shape& iParentShape, std::vector& iStoreVec, const unsigned int iColor); void set_xyz_dir_spinbox(QDoubleSpinBox* icurrentSpinBox); + void transform_shape_to_global_postion(TopoDS_Shape& ioShape, Part::Feature* iPart); private: Ui::DlgProjectionOnSurface *ui;