Gui: Add alignToSelection() method and command
This commit is contained in:
@@ -4076,6 +4076,33 @@ bool StdRecallWorkingView::isActive()
|
||||
return view && view->getViewer()->hasHomePosition();
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
// Std_AlignToSelection
|
||||
//===========================================================================
|
||||
|
||||
DEF_STD_CMD_A(StdCmdAlignToSelection)
|
||||
|
||||
StdCmdAlignToSelection::StdCmdAlignToSelection()
|
||||
: Command("Std_AlignToSelection")
|
||||
{
|
||||
sGroup = "Standard-View";
|
||||
sMenuText = QT_TR_NOOP("Align to selection");
|
||||
sToolTipText = QT_TR_NOOP("Align the view with the selection");
|
||||
sWhatsThis = "Std_AlignToSelection";
|
||||
eType = Alter3DView;
|
||||
}
|
||||
|
||||
void StdCmdAlignToSelection::activated(int iMsg)
|
||||
{
|
||||
Q_UNUSED(iMsg);
|
||||
doCommand(Command::Gui,"Gui.SendMsgToActiveView(\"AlignToSelection\")");
|
||||
}
|
||||
|
||||
bool StdCmdAlignToSelection::isActive()
|
||||
{
|
||||
return getGuiApplication()->sendHasMsgToActiveView("AlignToSelection");
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
// Instantiation
|
||||
//===========================================================================
|
||||
@@ -4107,6 +4134,7 @@ void CreateViewStdCommands()
|
||||
rcCmdMgr.addCommand(new StdStoreWorkingView());
|
||||
rcCmdMgr.addCommand(new StdRecallWorkingView());
|
||||
rcCmdMgr.addCommand(new StdCmdViewGroup());
|
||||
rcCmdMgr.addCommand(new StdCmdAlignToSelection());
|
||||
|
||||
rcCmdMgr.addCommand(new StdCmdViewExample1());
|
||||
rcCmdMgr.addCommand(new StdCmdViewExample2());
|
||||
|
||||
@@ -408,6 +408,10 @@ bool View3DInventor::onMsg(const char* pMsg, const char** ppReturn)
|
||||
getGuiDocument()->saveCopy();
|
||||
return true;
|
||||
}
|
||||
else if (strcmp("AlignToSelection", pMsg) == 0) {
|
||||
_viewer->alignToSelection();
|
||||
return true;
|
||||
}
|
||||
else if (strcmp("ZoomIn", pMsg) == 0) {
|
||||
View3DInventorViewer* viewer = getViewer();
|
||||
viewer->navigationStyle()->zoomIn();
|
||||
@@ -511,6 +515,9 @@ bool View3DInventor::onHasMsg(const char* pMsg) const
|
||||
else if(strncmp("Dump",pMsg,4) == 0) {
|
||||
return true;
|
||||
}
|
||||
else if (strcmp("AlignToSelection", pMsg) == 0) {
|
||||
return true;
|
||||
}
|
||||
if (strcmp("ZoomIn", pMsg) == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
*
|
||||
|
||||
@@ -414,6 +414,8 @@ public:
|
||||
*/
|
||||
void viewSelection();
|
||||
|
||||
void alignToSelection();
|
||||
|
||||
void setGradientBackground(Background);
|
||||
Background getGradientBackground() const;
|
||||
void setGradientBackgroundColor(const SbColor& fromColor,
|
||||
|
||||
Reference in New Issue
Block a user