Gui: Add alignToSelection() method and command

This commit is contained in:
Bas Ruigrok
2024-05-12 14:45:16 +02:00
parent f7078d13d4
commit 52b6f4f5ad
4 changed files with 70 additions and 0 deletions

View File

@@ -3341,6 +3341,39 @@ void View3DInventorViewer::viewSelection()
}
}
void View3DInventorViewer::alignToSelection()
{
if (!getCamera()) {
return;
}
const auto selection = Selection().getSelection();
// Empty selection
if (selection.empty()) {
return;
}
// Too much selections
if (selection.size() > 1) {
return;
}
// Get the geo feature
App::GeoFeature* geoFeature = nullptr;
std::pair<std::string, std::string> elementName;
App::GeoFeature::resolveElement(selection[0].pObject, selection[0].SubName, elementName, false, App::GeoFeature::ElementNameType::Normal, nullptr, nullptr, &geoFeature);
if (!geoFeature) {
return;
}
Base::Vector3d direction;
if (geoFeature->getCameraAlignmentDirection(direction, selection[0].SubName)) {
const auto orientation = SbRotation(SbVec3f(0, 0, 1), Base::convertTo<SbVec3f>(direction));
setCameraOrientation(orientation);
}
}
/**
* @brief Decide if it should be possible to start any animation
*