From 7e797eaaf8bc77ba10791593b214c1be7dc6d1e2 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Mon, 6 Apr 2020 08:06:07 +0200 Subject: [PATCH] Dependencies check in debug mode Some common resources can depend on each other - this checks that the requirements are consistent --- src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp | 25 ++++++++++++++++++------ src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp | 15 +++++++++++++- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp b/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp index 3dd604b6b..40ac66c71 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp @@ -43,11 +43,24 @@ SelectionInfo* CommonGizmosDataPool::selection_info() } #ifndef NDEBUG +// Check the required resources one by one and return true if all +// dependencies are met. bool CommonGizmosDataPool::check_dependencies(CommonGizmosDataID required) const { // This should iterate over currently required data. Each of them should // be asked about its dependencies and it must check that all dependencies // are also in required and before the current one. + for (auto& [id, data] : m_data) { + // in case we don't use this, the deps are irrelevant + if (! (int(required) & int(CommonGizmosDataID(id)))) + continue; + + + CommonGizmosDataID deps = data->get_dependencies(); + assert(int(deps) == (int(deps) & int(required))); + } + + return true; } #endif // NDEBUG @@ -57,7 +70,7 @@ bool CommonGizmosDataPool::check_dependencies(CommonGizmosDataID required) const void SelectionInfo::on_update() { - const Selection& selection = m_common->get_canvas()->get_selection(); + const Selection& selection = get_pool()->get_canvas()->get_selection(); if (selection.is_single_full_instance()) m_model_object = selection.get_model()->objects[selection.get_object_idx()]; else @@ -71,7 +84,7 @@ void SelectionInfo::on_release() int SelectionInfo::get_active_instance() { - const Selection& selection = m_common->get_canvas()->get_selection(); + const Selection& selection = get_pool()->get_canvas()->get_selection(); return selection.get_instance_idx(); } @@ -81,9 +94,9 @@ int SelectionInfo::get_active_instance() void InstancesHider::on_update() { - const ModelObject* mo = m_common->selection_info()->model_object(); - int active_inst = m_common->selection_info()->get_active_instance(); - GLCanvas3D* canvas = m_common->get_canvas(); + const ModelObject* mo = get_pool()->selection_info()->model_object(); + int active_inst = get_pool()->selection_info()->get_active_instance(); + GLCanvas3D* canvas = get_pool()->get_canvas(); if (mo && active_inst != -1) { canvas->toggle_model_objects_visibility(false); @@ -95,7 +108,7 @@ void InstancesHider::on_update() void InstancesHider::on_release() { - m_common->get_canvas()->toggle_model_objects_visibility(true); + get_pool()->get_canvas()->toggle_model_objects_visibility(true); } diff --git a/src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp b/src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp index f1840837f..5211ca48f 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp @@ -85,13 +85,22 @@ public: // Returns whether the resource is currently maintained. bool is_valid() const { return m_is_valid; } +#ifndef NDEBUG + // Return a bitmask of all resources that this one relies on. + // The dependent resource must have higher ID than the one + // it depends on. + virtual CommonGizmosDataID get_dependencies() const { return CommonGizmosDataID::None; } +#endif // NDEBUG + protected: - CommonGizmosDataPool* m_common = nullptr; virtual void on_release() = 0; virtual void on_update() = 0; + CommonGizmosDataPool* get_pool() const { return m_common; } + private: bool m_is_valid = false; + CommonGizmosDataPool* m_common = nullptr; }; @@ -125,6 +134,10 @@ class InstancesHider : public CommonGizmosDataBase public: explicit InstancesHider(CommonGizmosDataPool* cgdp) : CommonGizmosDataBase(cgdp) {} +#ifndef NDEBUG + CommonGizmosDataID get_dependencies() const override { return CommonGizmosDataID::SelectionInfo; } +#endif // NDEBUG + protected: void on_update() override; void on_release() override;