MeshLib Documentation
Loading...
Searching...
No Matches
MRAddVisualPropertiesMixin.h
Go to the documentation of this file.
1#pragma once
2
4
5namespace MR
6{
7
8// Inherits from a datamodel object, adding some visual property masks to it.
9// `BaseObjectType` is the datamodel type to inherit from.
10// `Properties...` is the list of properties to add. Each must be a value from a enum marked as `IsVisualizeMaskEnum`.
11template <typename BaseObjectType, auto ...Properties>
12requires ( IsVisualizeMaskEnum<decltype(Properties)>::value && ... )
13class AddVisualProperties : public BaseObjectType
14{
15public:
16 using BaseObjectType::BaseObjectType;
17
19 {
20 return BaseObjectType::supportsVisualizeProperty( type ) || ( ( type.tryGet<decltype( Properties )>() == Properties ) || ... );
21 }
22
24 {
25 AllVisualizeProperties ret = BaseObjectType::getAllVisualizeProperties();
26 ret.reserve( ret.size() + sizeof...(Properties) );
27 ( void( ret.push_back( this->getVisualizePropertyMask( Properties ) ) ), ... );
28 return ret;
29 }
30
32 {
33 const ViewportMask* ret = nullptr;
34 std::size_t i = 0;
35 (void)( ( type.tryGet<decltype( Properties )>() == Properties ? ( ret = &propertyMasks_[i], true ) : ( i++, false ) ) || ... );
36 if ( ret )
37 return *ret;
38 else
39 return BaseObjectType::getVisualizePropertyMask( type );
40 }
41
42protected:
43 void setAllVisualizeProperties_( const AllVisualizeProperties& properties, std::size_t& pos ) override
44 {
45 BaseObjectType::setAllVisualizeProperties_( properties, pos );
46 for ( std::size_t i = 0; i < sizeof...(Properties); i++ )
47 propertyMasks_[i] = properties[pos++];
48 }
49
50 // All enabled by default.
51 std::array<ViewportMask, sizeof...(Properties)> propertyMasks_ = []{
52 std::array<ViewportMask, sizeof...(Properties)> ret;
53 ret.fill( ViewportMask::all() );
54 return ret;
55 }();
56};
57
58}
Definition MRAddVisualPropertiesMixin.h:14
bool supportsVisualizeProperty(AnyVisualizeMaskEnum type) const override
Definition MRAddVisualPropertiesMixin.h:18
void setAllVisualizeProperties_(const AllVisualizeProperties &properties, std::size_t &pos) override
Definition MRAddVisualPropertiesMixin.h:43
std::array< ViewportMask, sizeof...(Properties)> propertyMasks_
Definition MRAddVisualPropertiesMixin.h:51
AllVisualizeProperties getAllVisualizeProperties() const override
Definition MRAddVisualPropertiesMixin.h:23
const ViewportMask & getVisualizePropertyMask(AnyVisualizeMaskEnum type) const override
Definition MRAddVisualPropertiesMixin.h:31
Definition MRVisualObject.h:67
std::optional< T > tryGet() const
Definition MRVisualObject.h:76
stores mask of viewport unique identifiers
Definition MRViewportId.h:38
static ViewportMask all()
mask meaning all or any viewports
Definition MRViewportId.h:45
std::vector< ViewportMask > AllVisualizeProperties
Definition MRVisualObject.h:85
Definition MRCameraOrientationPlugin.h:8