diff --git a/src/Gui/View3DInventorViewer.cpp b/src/Gui/View3DInventorViewer.cpp index 43c49d006f..0e783031ce 100644 --- a/src/Gui/View3DInventorViewer.cpp +++ b/src/Gui/View3DInventorViewer.cpp @@ -127,9 +127,9 @@ #include "Utilities.h" -FC_LOG_LEVEL_INIT("3DViewer",true,true) +FC_LOG_LEVEL_INIT("3DViewer", true, true) -//#define FC_LOGGING_CB +// #define FC_LOGGING_CB using namespace Gui; @@ -3352,7 +3352,7 @@ void View3DInventorViewer::alignToSelection() return; } - const auto selection = Selection().getSelection(); + const auto selection = Selection().getSelection(nullptr, ResolveMode::NoResolve); // Empty selection if (selection.empty()) { @@ -3367,13 +3367,18 @@ void View3DInventorViewer::alignToSelection() // Get the geo feature App::GeoFeature* geoFeature = nullptr; App::ElementNamePair elementName; - App::GeoFeature::resolveElement(selection[0].pObject, selection[0].SubName, elementName, false, App::GeoFeature::ElementNameType::Normal, nullptr, nullptr, &geoFeature); + App::GeoFeature::resolveElement(selection[0].pObject, selection[0].SubName, elementName, true, App::GeoFeature::ElementNameType::Normal, nullptr, nullptr, &geoFeature); if (!geoFeature) { return; } + const auto globalPlacement = App::GeoFeature::getGlobalPlacement(selection[0].pResolvedObject, selection[0].pObject, elementName.oldName); + const auto rotation = globalPlacement.getRotation() * geoFeature->Placement.getValue().getRotation().inverse(); + const auto geoFeatureSubName = Base::Tools::splitSubName(elementName.oldName).back(); + Base::Vector3d direction; - if (geoFeature->getCameraAlignmentDirection(direction, selection[0].SubName)) { + if (geoFeature->getCameraAlignmentDirection(direction, geoFeatureSubName.c_str())) { + rotation.multVec(direction, direction); const auto orientation = SbRotation(SbVec3f(0, 0, 1), Base::convertTo(direction)); setCameraOrientation(orientation); }