Skip to content

Commit

Permalink
Merge branch 'feature/#292' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
HuguesDelorme committed Oct 16, 2024
2 parents 9791ed5 + 9b95914 commit 4f30477
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/app/app_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "../base/io_writer.h"
#include "../base/io_system.h"
#include "../base/settings.h"
#include "../base/tkernel_utils.h"
#include "../gui/gui_application.h"
#include "../gui/gui_document.h"
#include "../qtcommon/filepath_conv.h"
Expand Down
5 changes: 4 additions & 1 deletion src/app/widget_gui_document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ WidgetGuiDocument::WidgetGuiDocument(GuiDocument* guiDoc, QWidget* parent)
m_qtOccView->redraw();
});
QObject::connect(m_btnFitAll, &ButtonFlat::clicked, this, [=]{
m_guiDoc->runViewCameraAnimation(&GraphicsUtils::V3dView_fitAll);
m_guiDoc->runViewCameraAnimation([=](OccHandle<V3d_View> view) {
auto bndBoxFlags = GuiDocument::OnlySelectedGraphics | GuiDocument::OnlyVisibleGraphics;
view->FitAll(this->guiDocument()->graphicsBoundingBox(bndBoxFlags));
});
});
QObject::connect(
m_btnGrid, &ButtonFlat::checked,
Expand Down
2 changes: 1 addition & 1 deletion src/graphics/graphics_view_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace Mayo {

// Helper class providing a V3d view created associated with the owner GraphicsScene object
// Helper class providing a V3d view associated with the owner GraphicsScene object
// The redraw() member function actually calls GraphicsScene::redraw() which under the hood sends
// a "redraw requested" signal
class GraphicsViewPtr {
Expand Down
54 changes: 52 additions & 2 deletions src/gui/gui_document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,61 @@ GuiDocument::GuiDocument(const DocumentPtr& doc, GuiApplication* guiApp)
for (int i = 0; i < doc->entityCount(); ++i)
this->mapEntity(doc->entityTreeNodeId(i));


doc->signalEntityAdded.connectSlot(&GuiDocument::onDocumentEntityAdded, this);
doc->signalEntityAboutToBeDestroyed.connectSlot(&GuiDocument::onDocumentEntityAboutToBeDestroyed, this);
m_gfxScene.signalSelectionChanged.connectSlot(&GuiDocument::onGraphicsSelectionChanged, this);
}

Bnd_Box GuiDocument::graphicsBoundingBox(GraphicsBoundingBoxFlags flags) const
{
if (flags == GraphicsBoundingBoxFlag::AllGraphics)
return m_gfxBoundingBox;

Bnd_Box bndBox;

auto fnIsVisibleTreeNode = [=](TreeNodeId nodeId) {
return (flags & OnlyVisibleGraphics) == 0 || this->nodeVisibleState(nodeId) == CheckState::On;
};

// Retrieve the application items being selected and visible
auto appSelectionModel = this->guiApplication()->selectionModel();
std::vector<ApplicationItem> appItems;
if (flags & OnlySelectedGraphics) {
for (const ApplicationItem& item : appSelectionModel->selectedItems()) {
if (item.document() == this->document()
&& (!item.isDocumentTreeNode() || fnIsVisibleTreeNode(item.documentTreeNode().id())))
{
appItems.push_back(item);
}
}
}

// If no application items selected(and visible), then take the whole document
if (appItems.empty())
appItems = { ApplicationItem{this->document()} };

// Helper function to extend main bounding box with each visible graphics object inside tree node
auto fnAddTreeNodeBndBox = [&](TreeNodeId nodeId) {
if (fnIsVisibleTreeNode(nodeId)) {
this->foreachGraphicsObject(nodeId, [&](GraphicsObjectPtr gfxObject) {
BndUtils::add(&bndBox, GraphicsUtils::AisObject_boundingBox(gfxObject));
});
}
};

// Iterate over application items to compute main bounding box
for (const ApplicationItem& item : appItems) {
const Tree<TDF_Label>& modelTree = item.document()->modelTree();
if (item.isDocument())
traverseTree(modelTree, fnAddTreeNodeBndBox);
else
traverseTree(item.documentTreeNode().id(), modelTree, fnAddTreeNodeBndBox);
}

return bndBox;
}

void GuiDocument::setDevicePixelRatio(double ratio)
{
if (MathUtils::fuzzyEqual(m_devicePixelRatio, ratio))
Expand Down Expand Up @@ -374,7 +424,7 @@ void GuiDocument::setViewCameraOrientation(V3d_TypeOfOrientation projection)
{
this->runViewCameraAnimation([=](OccHandle<V3d_View> view) {
view->SetProj(projection);
GraphicsUtils::V3dView_fitAll(view);
view->FitAll(this->graphicsBoundingBox(OnlySelectedGraphics | OnlyVisibleGraphics));
});
}

Expand Down Expand Up @@ -516,6 +566,7 @@ void GuiDocument::onDocumentEntityAdded(TreeNodeId entityTreeNodeId)
{
this->mapEntity(entityTreeNodeId);
BndUtils::add(&m_gfxBoundingBox, m_vecGraphicsEntity.back().bndBox);
m_v3dView->FitAll(this->graphicsBoundingBox(OnlySelectedGraphics | OnlyVisibleGraphics));
this->signalGraphicsBoundingBoxChanged.send(m_gfxBoundingBox);
}

Expand Down Expand Up @@ -642,7 +693,6 @@ void GuiDocument::mapEntity(TreeNodeId entityTreeNodeId)
m_mapTreeNodeCheckState.insert({ id, CheckState::On });
});

GraphicsUtils::V3dView_fitAll(m_v3dView);
m_vecGraphicsEntity.push_back(std::move(gfxEntity));
}

Expand Down
26 changes: 20 additions & 6 deletions src/gui/gui_document.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "../base/document.h"
#include "../base/global.h"
#include "../base/signal.h"
#include "../base/tkernel_utils.h"
#include "../graphics/graphics_object_driver.h"
#include "../graphics/graphics_scene.h"
#include "../graphics/graphics_view_ptr.h"
Expand All @@ -19,7 +18,6 @@
#include <Bnd_Box.hxx>
#include <V3d_View.hxx>
#include <functional>
#include <memory>
#include <unordered_map>
#include <vector>

Expand All @@ -29,24 +27,40 @@ class ApplicationItem;
class GuiApplication;
class V3dViewCameraAnimation;

// Provides the link between Base::Document and graphical representations
// Provides the link between Base::Document and graphical representations(called "graphics objects")
class GuiDocument {
public:
// Applicable flags for function graphicsBoundingBox()
enum GraphicsBoundingBoxFlag {
AllGraphics = 0xFF,
OnlyVisibleGraphics = 0x01,
OnlySelectedGraphics = 0x02
};
using GraphicsBoundingBoxFlags = unsigned;

// Constructor & destructor
GuiDocument(const DocumentPtr& doc, GuiApplication* guiApp);
~GuiDocument();

// Not copyable
// GuiDocument objects are not copyable
GuiDocument(const GuiDocument&) = delete;
GuiDocument& operator=(const GuiDocument&) = delete;

// Gets the base document linked to
const DocumentPtr& document() const { return m_document; }

// Gets the owning GuiApplication object
GuiApplication* guiApplication() const { return m_guiApp; }

// Gets the main 3D graphics view
const OccHandle<V3d_View>& v3dView() const { return m_v3dView; }
GraphicsScene* graphicsScene() { return &m_gfxScene; }
GraphicsViewPtr graphicsView() { return GraphicsViewPtr{ &m_gfxScene, m_v3dView }; }
const Bnd_Box& graphicsBoundingBox() const { return m_gfxBoundingBox; }

// Gets the graphics scene, container of all document's graphics objects
GraphicsScene* graphicsScene() { return &m_gfxScene; }

// Returns the bounding box of all graphics objects satisfying `flags`
Bnd_Box graphicsBoundingBox(GraphicsBoundingBoxFlags flags = AllGraphics) const;

// Gets/sets the ratio between physical pixels and device-independent pixels for the target window.
// This value is dependent on the screen the window is on, and may have to be updated when the
Expand Down

0 comments on commit 4f30477

Please sign in to comment.