MeshLib C++ Docs
Loading...
Searching...
No Matches
MRSceneStateCheck.h
Go to the documentation of this file.
1#pragma once
2
4#include "MRMesh/MRObject.h"
5
6namespace MR
7{
10
11
14
16struct NoModelCheck {};
17
18template<typename ObjectT>
19std::string getNObjectsLine( unsigned n )
20{
21 switch ( n )
22 {
23 case 1:
24 return std::string( "one " ) + ObjectT::StaticClassName();
25 case 2:
26 return std::string( "two " ) + ObjectT::StaticClassNameInPlural();
27 case 3:
28 return std::string( "three " ) + ObjectT::StaticClassNameInPlural();
29 case 4:
30 return std::string( "four " ) + ObjectT::StaticClassNameInPlural();
31 default:
32 return std::to_string( n ) + " " + ObjectT::StaticClassNameInPlural();
33 }
34}
35
38template<typename ObjectT, bool visualRepresentationCheck, bool modelCheck>
39std::string sceneSelectedExactly( const std::vector<std::shared_ptr<const Object>>& objs, unsigned n )
40{
41 if ( objs.size() != n )
42 return "Select exactly " + getNObjectsLine<ObjectT>( n );
43 for ( const auto& obj : objs )
44 {
45 auto tObj = dynamic_cast<const ObjectT*>( obj.get() );
46 if ( !tObj )
47 return std::string( "Selected object(s) must be " ) + ObjectT::StaticClassName();
48
49 if constexpr ( modelCheck )
50 if ( !tObj->hasModel() )
51 return "Selected object(s) must have valid model";
52
53 if constexpr ( visualRepresentationCheck )
54 if ( !tObj->hasVisualRepresentation() )
55 return "Selected object(s) must have valid visual representation";
56 }
57 return "";
58}
59
62template<typename ObjectT, bool visualRepresentationCheck, bool modelCheck>
63std::string sceneSelectedAtLeast( const std::vector<std::shared_ptr<const Object>>& objs, unsigned n )
64{
65 if ( objs.size() < n )
66 return "Select at least " + getNObjectsLine<ObjectT>( n );
67 unsigned i = 0;
68 for ( const auto& obj : objs )
69 {
70 auto tObj = dynamic_cast<const ObjectT*>( obj.get() );
71 if ( !tObj )
72 continue;
73
74 if constexpr ( modelCheck )
75 if ( !tObj->hasModel() )
76 continue;
77
78 if constexpr ( visualRepresentationCheck )
79 if ( !tObj->hasVisualRepresentation() )
80 continue;
81 ++i;
82 }
83 return ( i >= n ) ?
84 "" :
85 ( "Select at least " + getNObjectsLine<ObjectT>( n ) + " with valid model" );
86}
87
89template<unsigned N, typename ObjectT, typename = void>
91{
92public:
93 virtual ~SceneStateExactCheck() = default;
94 virtual std::string isAvailable( const std::vector<std::shared_ptr<const Object>>& objs ) const override
95 {
97 }
98};
99
100template<unsigned N, typename ObjectT>
102{
103public:
104 virtual ~SceneStateExactCheck() = default;
105 virtual std::string isAvailable( const std::vector<std::shared_ptr<const Object>>& objs ) const override
106 {
108 }
109};
110
111template<unsigned N, typename ObjectT>
112class SceneStateExactCheck<N, ObjectT, NoModelCheck> : virtual public ISceneStateCheck
113{
114public:
115 virtual ~SceneStateExactCheck() = default;
116 virtual std::string isAvailable( const std::vector<std::shared_ptr<const Object>>& objs ) const override
117 {
119 }
120};
121
123template<unsigned N, typename ObjectT, typename = void>
125{
126public:
127 virtual ~SceneStateAtLeastCheck() = default;
128 virtual std::string isAvailable( const std::vector<std::shared_ptr<const Object>>& objs ) const override
129 {
131 }
132};
133
134template<unsigned N, typename ObjectT>
136{
137public:
138 virtual ~SceneStateAtLeastCheck() = default;
139 virtual std::string isAvailable( const std::vector<std::shared_ptr<const Object>>& objs ) const override
140 {
142 }
143};
144
145template<unsigned N, typename ObjectT>
146class SceneStateAtLeastCheck<N, ObjectT, NoModelCheck> : virtual public ISceneStateCheck
147{
148public:
149 virtual ~SceneStateAtLeastCheck() = default;
150 virtual std::string isAvailable( const std::vector<std::shared_ptr<const Object>>& objs ) const override
151 {
153 }
154};
155
157template<typename ...Checks>
158class SceneStateOrCheck : public Checks...
159{
160public:
161 virtual ~SceneStateOrCheck() = default;
162 virtual std::string isAvailable( const std::vector<std::shared_ptr<const Object>>&objs ) const override
163 {
164 std::vector<std::string> checkRes;
165 checkRes.reserve( sizeof...( Checks ) );
166 ( checkRes.push_back( Checks::isAvailable( objs ) ), ... );
167 std::string combinedRes;
168 for ( int i = 0; i < checkRes.size(); ++i )
169 {
170 if ( checkRes[i].empty() )
171 return "";
172
173 if ( i != 0 )
174 checkRes[i].front() = ( char )tolower( checkRes[i].front() );
175
176 combinedRes += checkRes[i];
177 if ( i + 1 < checkRes.size() )
178 combinedRes += " or ";
179 }
180 return combinedRes;
181 }
182};
183
185template<typename ...Checks>
186class SceneStateAndCheck : public Checks...
187{
188public:
189 virtual ~SceneStateAndCheck() = default;
190 virtual std::string isAvailable( const std::vector<std::shared_ptr<const Object>>& objs ) const override
191 {
192 std::vector<std::string> checkRes;
193 checkRes.reserve( sizeof...( Checks ) );
194 ( checkRes.push_back( Checks::isAvailable( objs ) ), ... );
195 std::string combinedRes;
196 for ( int i = 0; i < checkRes.size(); ++i )
197 {
198 if ( checkRes[i].empty() )
199 continue;
200
201 if ( !combinedRes.empty() )
202 {
203 combinedRes += " and ";
204 checkRes[i].front() = ( char )tolower( checkRes[i].front() );
205 }
206 combinedRes += checkRes[i];
207 }
208 return combinedRes;
209 }
210};
211
212
213}
Interface for checking scene state, to determine availability, also can return string with requiremen...
Definition MRISceneStateCheck.h:17
checks that all of argument checks are true
Definition MRSceneStateCheck.h:187
checks that given vector has at least N objects if type ObjectT
Definition MRSceneStateCheck.h:125
check that given vector has exactly N objects if type ObjectT
Definition MRSceneStateCheck.h:91
checks that at least one of argument checks is true
Definition MRSceneStateCheck.h:159
std::string getNObjectsLine(unsigned n)
Definition MRSceneStateCheck.h:19
virtual ~SceneStateExactCheck()=default
virtual std::string isAvailable(const std::vector< std::shared_ptr< const Object > > &objs) const override
Definition MRSceneStateCheck.h:190
virtual std::string isAvailable(const std::vector< std::shared_ptr< const Object > > &objs) const override
Definition MRSceneStateCheck.h:162
virtual std::string isAvailable(const std::vector< std::shared_ptr< const Object > > &objs) const override
return empty string if all requirements are satisfied, otherwise return first unsatisfied requirement
Definition MRSceneStateCheck.h:105
virtual std::string isAvailable(const std::vector< std::shared_ptr< const Object > > &objs) const override
return empty string if all requirements are satisfied, otherwise return first unsatisfied requirement
Definition MRSceneStateCheck.h:128
virtual std::string isAvailable(const std::vector< std::shared_ptr< const Object > > &objs) const override
return empty string if all requirements are satisfied, otherwise return first unsatisfied requirement
Definition MRSceneStateCheck.h:116
virtual ~SceneStateAtLeastCheck()=default
virtual std::string isAvailable(const std::vector< std::shared_ptr< const Object > > &objs) const override
return empty string if all requirements are satisfied, otherwise return first unsatisfied requirement
Definition MRSceneStateCheck.h:94
virtual std::string isAvailable(const std::vector< std::shared_ptr< const Object > > &objs) const override
return empty string if all requirements are satisfied, otherwise return first unsatisfied requirement
Definition MRSceneStateCheck.h:139
std::string sceneSelectedExactly(const std::vector< std::shared_ptr< const Object > > &objs, unsigned n)
Definition MRSceneStateCheck.h:39
std::string sceneSelectedAtLeast(const std::vector< std::shared_ptr< const Object > > &objs, unsigned n)
Definition MRSceneStateCheck.h:63
virtual std::string isAvailable(const std::vector< std::shared_ptr< const Object > > &objs) const override
return empty string if all requirements are satisfied, otherwise return first unsatisfied requirement
Definition MRSceneStateCheck.h:150
virtual ~SceneStateOrCheck()=default
virtual ~SceneStateAndCheck()=default
only for bindings generation
Definition MRCameraOrientationPlugin.h:8
special struct for disabling model check
Definition MRSceneStateCheck.h:16
special struct for disabling visual representation check
Definition MRSceneStateCheck.h:13