Skip to content

Commit

Permalink
Connect visibility checkbox wip
Browse files Browse the repository at this point in the history
  • Loading branch information
sguionni committed Dec 11, 2024
1 parent e6b704f commit 0b6d4eb
Show file tree
Hide file tree
Showing 3 changed files with 213 additions and 133 deletions.
68 changes: 43 additions & 25 deletions lib/renderer/src/renderer/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,31 +362,6 @@ namespace VTX::Renderer
setValue( _StructUBOModel { matrixModelView, matrixNormal }, "MatrixModelView", _getProxyId( &p_proxy ) );
};

// Visibility.
p_proxy.onVisible += [ this, &p_proxy ]( const bool p_visible )
{
auto & rangeSpheres = _cacheSpheresCylinders[ &p_proxy ].rangeSpheres;
auto & rangeCylinders = _cacheSpheresCylinders[ &p_proxy ].rangeCylinders;
auto & rangeRibbons = _cacheRibbons[ &p_proxy ].range;

if ( p_visible )
{
drawRangeSpheresRL.addRange( rangeSpheres );
drawRangeCylindersRL.addRange( rangeCylinders );
drawRangeRibbonsRL.addRange( rangeRibbons );
}
else
{
drawRangeSpheresRL.removeRange( rangeSpheres );
drawRangeCylindersRL.removeRange( rangeCylinders );
drawRangeRibbonsRL.removeRange( rangeRibbons );
}

drawRangeSpheresRL.toVectors<void *, uint>( drawRangeSpheres.offsets, drawRangeSpheres.counts );
drawRangeCylindersRL.toVectors<void *, uint>( drawRangeCylinders.offsets, drawRangeCylinders.counts );
drawRangeRibbonsRL.toVectors<void *, uint>( drawRangeRibbons.offsets, drawRangeRibbons.counts );
};

// Representation.
p_proxy.onRepresentation += [ this, &p_proxy ]( const uchar p_representation )
{
Expand Down Expand Up @@ -481,6 +456,49 @@ namespace VTX::Renderer
// TODO: ribbons and SES.
};

// Visibility.
p_proxy.onVisible += [ this, &p_proxy ]( const bool p_visible )
{
auto & rangeSpheres = _cacheSpheresCylinders[ &p_proxy ].rangeSpheres;
auto & rangeCylinders = _cacheSpheresCylinders[ &p_proxy ].rangeCylinders;
auto & rangeRibbons = _cacheRibbons[ &p_proxy ].range;

if ( p_visible )
{
drawRangeSpheresRL.addRange( rangeSpheres );
drawRangeCylindersRL.addRange( rangeCylinders );
drawRangeRibbonsRL.addRange( rangeRibbons );
}
else
{
drawRangeSpheresRL.removeRange( rangeSpheres );
drawRangeCylindersRL.removeRange( rangeCylinders );
drawRangeRibbonsRL.removeRange( rangeRibbons );
}

drawRangeSpheresRL.toVectors<void *, uint>( drawRangeSpheres.offsets, drawRangeSpheres.counts );
drawRangeCylindersRL.toVectors<void *, uint>( drawRangeCylinders.offsets, drawRangeCylinders.counts );
drawRangeRibbonsRL.toVectors<void *, uint>( drawRangeRibbons.offsets, drawRangeRibbons.counts );
};

p_proxy.onAtomVisibilities +=
[ this, &p_proxy ]( const Util::Math::RangeList<uint> & p_atomIds, const bool p_visible )
{
Cache::SphereCylinder & cacheSC = _cacheSpheresCylinders[ &p_proxy ];
uchar mask = 1 << E_ELEMENT_FLAGS::VISIBILITY;
for ( auto it = p_atomIds.rangeBegin(); it != p_atomIds.rangeEnd(); ++it )
{
for ( uint i = it->getFirst(); i <= it->getLast(); ++i )
{
cacheSC.flags[ i ] &= ~mask;
cacheSC.flags[ i ] |= p_visible << E_ELEMENT_FLAGS::VISIBILITY;
}
}
_context->setSub( cacheSC.flags, "SpheresCylindersFlags", cacheSC.rangeSpheres.getFirst() );

// TODO: ribbons.
};

// TODO:
// onAtomVisibilities
// onAtomSelections
Expand Down
130 changes: 60 additions & 70 deletions lib/ui/qt/include/ui/qt/dock_widget/scene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,94 +4,84 @@
#include "ui/qt/core/base_dock_widget.hpp"
#include <QPointer>
#include <QTreeWidget>
#include <app/component/chemistry/system.hpp>

namespace VTX::UI::QT::DockWidget
{
/*
struct Data
{
uint level;
};
// Static polymorphism.
template<typename T>
concept TreeItemData = requires( T t ) {
{ t.getName() } -> std::same_as<const std::string_view>;
{ t.getPersistentSceneID() } -> std::same_as<int>;
};
// Test structs.
struct TestData
{
std::string_view name = "Default system";
int persistentId = 0;
const std::string_view getName() const { return name; }
int getPersistentSceneID() const { return persistentId; }
};
struct TestData2
{
std::string_view myName = "Default system adapted";
int myID = 0;
const std::string_view getMyName() const { return myName; }
int getMyID() const { return myID; }
};

// Adapter.
class BaseAdapterTreeItemData
{
public:
virtual const std::string_view name() const = 0;
virtual int id() const = 0;
virtual ~BaseAdapterTreeItemData() = default;
};
class AdapterSceneItemComponent : public BaseAdapterTreeItemData
/**
* @brief Display a tree widget with loaded systems.
* Load only minimal data on expand/collapse.
*/
class Scene : public Core::BaseDockWidget<Scene>
{
public:
AdapterSceneItemComponent( const VTX::App::Component::Scene::SceneItemComponent & p_item ) : _item( p_item ) {}
const std::string_view name() const override { return _item.getName(); }
int id() const override { return _item.getPersistentSceneID(); }
Scene( QWidget * );

private:
const VTX::App::Component::Scene::SceneItemComponent & _item;
};
class AdapterTestData2 : public BaseAdapterTreeItemData
{
public:
AdapterTestData2( const TestData2 & p_item ) : _item( p_item ) {}
enum struct E_DEPTH
{
TREE = 0,
SYSTEM,
CHAIN,
RESIDUE,
ATOM
};

const std::string_view name() const override { return _item.getMyName(); }
int id() const override { return _item.getMyID(); }
using WidgetData = size_t;

private:
const TestData2 & _item;
};
*/
/**
* @brief Load data function.
*/
using LoadFunc = std::function<void( const E_DEPTH, QTreeWidgetItem * const )>;

class Scene : public Core::BaseDockWidget<Scene>
{
public:
using WidgetData = size_t;
/**
* @brief Store data to create a tree item.
*/
struct TreeItemData
{
std::string_view name;
WidgetData data;
size_t childrenCount;
};
using LoadFunc = std::function<void( const uint, QTreeWidgetItem * const )>;

Scene( QWidget * );

private:
QPointer<QTreeWidget> _tree;
std::map<QTreeWidgetItem *, LoadFunc> _loadFuncs;

void _addTreeItem( const TreeItemData &, std::variant<const LoadFunc, QTreeWidgetItem * const> );
QPointer<QTreeWidget> _tree;

/**
* @brief Map top level items to data loading functions (to request App).
*/
std::map<const QTreeWidgetItem * const, LoadFunc> _loadFuncs;

/**
* @brief Map top level items to system components.
*/
std::map<const QTreeWidgetItem * const, App::Component::Chemistry::System * const> _systemComponents;

/**
* @brief Add a tree item.
* @param the TreeItemData to add.
* @param the parent item.
* @param the optional loading function.
* @param the optional system component.
*/
void _addTreeItem(
const TreeItemData &,
QTreeWidgetItem * const = nullptr,
std::optional<const LoadFunc> = std::nullopt,
std::optional<App::Component::Chemistry::System *> = std::nullopt
);

/**
* @brief Get the depth of the item.
* @param p_item the widget item.
* @return [E_DEPTH, QTreeWidgetItem * const] the depth and the top level item.
*/
std::pair<E_DEPTH, QTreeWidgetItem * const> _getDepth( QTreeWidgetItem * const p_item ) const;

/**
* @brief Reset the item tree (unload content on collapse).
* @param the item to reset.
*/
void _resetTreeItem( QTreeWidgetItem * const );
};

Expand Down
Loading

0 comments on commit 0b6d4eb

Please sign in to comment.