diff --git a/src/gui/gui_document.cpp b/src/gui/gui_document.cpp index b211c406..6f1f82fb 100644 --- a/src/gui/gui_document.cpp +++ b/src/gui/gui_document.cpp @@ -375,16 +375,27 @@ Bnd_Box boundingBoxForFitAll(const GuiDocument* guiDoc) { Bnd_Box bndBox; + // Retrieve the application items being selected and visible auto appSelectionModel = guiDoc->guiApplication()->selectionModel(); std::vector appItems; for (const ApplicationItem& item : appSelectionModel->selectedItems()) { - if (item.document() == guiDoc->document()) - appItems.push_back(item); + if (item.document() == guiDoc->document()) { + if (item.isDocument()) { + appItems.push_back(item); + } + else if (item.isDocumentTreeNode()) { + const TreeNodeId nodeId = item.documentTreeNode().id(); + if (guiDoc->nodeVisibleState(nodeId) == CheckState::On) + appItems.push_back(item); + } + } } + // If no application items selected(and visible), then take the whole document if (appItems.empty()) appItems = { ApplicationItem{guiDoc->document()} }; + // Helper function to extend main bounding box with each visible graphics object inside tree node auto fnAddTreeNodeBndBox = [&](TreeNodeId nodeId) { if (guiDoc->nodeVisibleState(nodeId) == CheckState::On) { guiDoc->foreachGraphicsObject(nodeId, [&](GraphicsObjectPtr gfxObject) { @@ -393,6 +404,7 @@ Bnd_Box boundingBoxForFitAll(const GuiDocument* guiDoc) } }; + // Iterate over application items to compute main bounding box for (const ApplicationItem& item : appItems) { const Tree& modelTree = item.document()->modelTree(); if (item.isDocument())