Radium Engine  1.5.20
Loading...
Searching...
No Matches
MaterialParameterEditor.cpp
1#include <Gui/ParameterSetEditor/MaterialParameterEditor.hpp>
2
3#include <Gui/Widgets/ControlPanel.hpp>
4
5// include the Material Definition
6#include <Engine/Data/Material.hpp>
7
8#include <QBoxLayout>
9#include <QFormLayout>
10#include <QLabel>
11#include <QPlainTextEdit>
12#include <QString>
13#include <QWidget>
14
15#include <limits>
16#include <memory>
17
18namespace Ra::Gui {
19
20MaterialParameterEditor::MaterialParameterEditor( QWidget* parent ) : QWidget( parent ) {
21 // setup the GUI
22 auto verticalLayout = new QVBoxLayout( this );
23
24 m_matInstanceNameLabel = new QLabel();
25 m_matNameLabel = new QLabel();
26 m_matProperties = new QPlainTextEdit();
27 m_matProperties->setReadOnly( true );
28
29 auto nameLayout = new QHBoxLayout();
30 nameLayout->addWidget( new QLabel( "Instance name :" ) );
31 nameLayout->addWidget( m_matInstanceNameLabel );
32 verticalLayout->addLayout( nameLayout );
33
34 m_matInfoGroup = new QGroupBox();
35 m_matInfoGroup->setTitle( "Material Informations" );
36 m_matInfoGroup->setCheckable( false );
37 auto matInfoForm = new QFormLayout( m_matInfoGroup );
38 matInfoForm->addRow( tr( "Material Type :" ), m_matNameLabel );
39 matInfoForm->addRow( tr( "Instance Properties :" ), m_matProperties );
40 m_matInfoGroup->setMaximumHeight( 150 );
41 verticalLayout->addWidget( m_matInfoGroup );
42 m_matInfoGroup->setVisible( false );
43
44 auto matParamsGroup = new QGroupBox();
45 matParamsGroup->setTitle( "Edit Parameters" );
46 matParamsGroup->setEnabled( true );
47 matParamsGroup->setCheckable( false );
48
49 verticalLayout->addWidget( matParamsGroup );
50 m_matParamsLayout = new QVBoxLayout( matParamsGroup );
51 m_parametersControlPanel = new VariableSetEditor( "Material Parameters", this );
52 m_matParamsLayout->addWidget( m_parametersControlPanel );
53
54 verticalLayout->addStretch();
55}
56
59 auto hasMetadata =
61 m_matNameLabel->setText( QString::fromStdString( material->getMaterialName() ) );
62 m_matProperties->clear();
63 for ( auto& prop : material->getPropertyList() ) {
64 m_matProperties->appendPlainText( QString::fromStdString( prop ) );
65 }
66 // move the cursor to the top
67 auto tmpCursor = m_matProperties->textCursor();
68 tmpCursor.movePosition( QTextCursor::Start );
69 m_matProperties->setTextCursor( tmpCursor );
70
71 auto& params = material->getParameters();
72 auto metadata = ( hasMetadata ) ? hasMetadata->getParametersMetadata() : nlohmann::json {};
73
74 m_matInstanceNameLabel->setText( material->getInstanceName().c_str() );
75
76 // clear the old control panel
77 m_matParamsLayout->removeWidget( m_parametersControlPanel );
78 delete m_parametersControlPanel;
79 m_parametersControlPanel = new VariableSetEditor( "Material Parameters", this );
80 m_parametersControlPanel->setShowUnspecified( m_showUnspecified );
81 m_matParamsLayout->addWidget( m_parametersControlPanel );
82
83 m_parametersControlPanel->setupUi( params, metadata );
84
85 connect( m_parametersControlPanel,
87 [this]( const std::string& nm ) { emit materialParametersModified( nm ); } );
88 m_matInfoGroup->setVisible( true );
89}
90
92 m_showUnspecified = enable;
93 m_parametersControlPanel->setShowUnspecified( m_showUnspecified );
94}
95} // namespace Ra::Gui
void materialParametersModified(const std::string &name)
void setupFromMaterial(std::shared_ptr< Ra::Engine::Data::Material > material)
MaterialParameterEditor(QWidget *parent=nullptr)
Simple Widget for RenderParameter editing The editor will expose a control panel containing all of th...
void setupUi(Core::VariableSet &params, const nlohmann::json &constraints)
Update the different UI element with the given renderParameter, using the given constraints.
void setShowUnspecified(bool enable)
Wether to show parameters without associated metadata.
void parameterModified(const std::string &name)
T dynamic_pointer_cast(T... args)