2#include <Gui/RaGui.hpp>
6#include <QPlainTextEdit>
10#include <nlohmann/json.hpp>
12#include <Core/Containers/VariableSetEnumManagement.hpp>
13#include <Gui/Widgets/ControlPanel.hpp>
24class RenderParameters;
64 bool showUnspecified() {
return m_showUnspecified; }
80 const nlohmann::json& paramMetadata );
93 const nlohmann::json& metadata );
103 template <
typename T>
107 const nlohmann::json& metadata );
117 template <
typename T>
121 const nlohmann::json& metadata );
131 bool m_showUnspecified =
false;
138 const nlohmann::json& metadata ) {
139 using namespace Ra::Core::VariableSetEnumManagement;
140 auto m = metadata[key];
142 std::string description = m.contains(
"description" ) ? m[
"description"] :
"";
145 if (
auto ec = getEnumConverter<T>( params, key ) ) {
146 auto items = ( *ec )->getEnumerators();
147 auto onEnumParameterStringChanged = [
this, ¶ms, &key](
const QString& value ) {
149 setEnumVariable( params, key, value.toStdString() );
153 onEnumParameterStringChanged,
154 getEnumString( params, key, initial ),
159 LOG( Core::Utils::logWARNING )
160 <<
"ParameterSet don't have converter for enum " << key <<
" use index<>int instead.";
163 items.reserve( m[
"values"].size() );
164 for (
const auto& value : m[
"values"] ) {
165 items.push_back( value );
168 auto onEnumParameterIntChanged = [
this, ¶ms, &key]( T value ) {
172 addComboBox( nm, onEnumParameterIntChanged, initial, items, description );
180 const nlohmann::json& metadata ) {
181 auto onNumberParameterChanged = [
this, &initial, &key]( T value ) {
187 if ( metadata.contains( key ) ) {
188 auto m = metadata[key];
192 std::string description = m.contains(
"description" ) ? m[
"description"] :
"";
195 if ( m.contains(
"oneOf" ) ) {
198 bounds.
reserve( m[
"oneOf"].size() );
199 for (
const auto& bound : m[
"oneOf"] ) {
200 auto mini = bound.contains(
"minimum" ) ? T( bound[
"minimum"] ) : min;
201 auto maxi = bound.contains(
"maximum" ) ? T( bound[
"maximum"] ) : max;
204 auto predicate = [bounds]( T value ) {
206 auto it = bounds.
begin();
207 while ( !valid && it != bounds.
end() ) {
208 valid = value >= ( *it ).first && value <= ( *it ).second;
215 nm, onNumberParameterChanged, initial, predicate, description );
217 else if ( m.contains(
"minimum" ) && m.contains(
"maximum" ) ) {
218 min = T( m[
"minimum"] );
219 max = T( m[
"maximum"] );
220 if constexpr ( std::is_floating_point_v<T> ) {
223 else {
addSliderInput( nm, onNumberParameterChanged, initial, min, max, description ); }
226 min = m.contains(
"minimum" ) ? T( m[
"minimum"] ) : min;
227 max = m.contains(
"maximum" ) ? T( m[
"maximum"] ) : max;
228 addNumberInput<T>( nm, onNumberParameterChanged, initial, min, max, description );
231 else if ( m_showUnspecified ) {
addNumberInput<T>( key, onNumberParameterChanged, initial ); }
238 const nlohmann::json& metadata ) {
239 auto onVectorParameterChanged = [
this, &initial, &key](
const std::vector<T>& value ) {
244 if ( metadata.contains( key ) ) {
245 auto m = metadata[key];
246 std::string description = m.contains(
"description" ) ? m[
"description"] :
"";
249 else if ( m_showUnspecified ) {
addVectorInput<T>( key, onVectorParameterChanged, initial ); }
256 const nlohmann::json& metadata ) {
257 auto onMatrixParameterChanged = [
this, &initial, &key](
const Ra::Core::MatrixN& value ) {
258 initial = T( value );
262 if ( metadata.contains( key ) ) {
263 auto m = metadata[key];
264 std::string description = m.contains(
"description" ) ? m[
"description"] :
"";
265 addMatrixInput( m[
"name"], onMatrixParameterChanged, initial, 3, description );
267 else if ( m_showUnspecified ) {
addMatrixInput( key, onMatrixParameterChanged, initial ); }
Heterogeneous container storing "Variables", that maps a name (std::string) to a value (of any type T...
auto setVariable(const std::string &name, const T &value) -> std::pair< VariableHandle< T >, bool >
reset (or set if the variable does not exist yet) the value of the variable.
Simple Widget for RenderParameter editing The editor will expose a control panel containing all of th...
void addNumberWidget(const std::string &name, T &initial, Core::VariableSet ¶ms, const nlohmann::json &metadata)
void addVectorWidget(const std::string &key, std::vector< T > &initial, Core::VariableSet ¶ms, const nlohmann::json &metadata)
void addEnumWidget(const std::string &name, T &initial, Core::VariableSet ¶ms, const nlohmann::json ¶mMetadata)
Add a combobox allowing to chose the value of an enumerator.
void addMatrixWidget(const std::string &key, T &initial, Core::VariableSet ¶ms, const nlohmann::json &metadata)
void setShowUnspecified(bool enable)
Wether to show parameters without associated metadata.
void parameterModified(const std::string &name)
T emplace_back(T... args)
hepler function to manage enum as underlying types in VariableSet