From 8ad1208104480c09190e2b92570dcee86d21c494 Mon Sep 17 00:00:00 2001 From: ana Date: Thu, 3 May 2012 14:15:15 +0000 Subject: [PATCH] "0021179: EDF 1654 SMESH GEOM: better look'n'feel" issue. Material Properties. --- .../GEOMToolsGUI_MaterialPropertiesDlg.cxx | 1 - .../GEOMToolsGUI_MaterialPropertiesDlg.h | 113 +- src/Material/Material_Model.cxx | 971 ++++++++---------- src/Material/Material_Model.h | 81 +- src/Material/Material_ResourceMgr.cxx | 367 +------ src/Material/Material_ResourceMgr.h | 2 - 6 files changed, 547 insertions(+), 988 deletions(-) diff --git a/src/GEOMToolsGUI/GEOMToolsGUI_MaterialPropertiesDlg.cxx b/src/GEOMToolsGUI/GEOMToolsGUI_MaterialPropertiesDlg.cxx index e4b6171b9..ba9876064 100644 --- a/src/GEOMToolsGUI/GEOMToolsGUI_MaterialPropertiesDlg.cxx +++ b/src/GEOMToolsGUI/GEOMToolsGUI_MaterialPropertiesDlg.cxx @@ -454,7 +454,6 @@ void GEOMToolsGUI_MaterialPropertiesDlg::onApply() SUIT_OverrideCursor wc(); - printf("material prop:%s\n", qPrintable(prop)); for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) { Handle(GEOM_AISShape) aisShape = GEOMBase::ConvertIOinGEOMAISShape( It.Value(), true ); if ( !aisShape.IsNull() ) { diff --git a/src/GEOMToolsGUI/GEOMToolsGUI_MaterialPropertiesDlg.h b/src/GEOMToolsGUI/GEOMToolsGUI_MaterialPropertiesDlg.h index f2df86420..328f5f99a 100644 --- a/src/GEOMToolsGUI/GEOMToolsGUI_MaterialPropertiesDlg.h +++ b/src/GEOMToolsGUI/GEOMToolsGUI_MaterialPropertiesDlg.h @@ -25,38 +25,25 @@ #include "GEOM_ToolsGUI.hxx" +#include #include -#include -#include +#include "Material_Model.h" +#include "Material_ResourceMgr.h" class QCheckBox; -class QGroupBox; class QLabel; -class QListWidget; -class QListWidgetItem; class QPushButton; -class QSpinBox; -class QTabWidget; - +class QSlider; class QtxColorButton; -class QtxDoubleSpinBox; - -class Material_Model; -class Material_ResourceMgr; +class GEOMToolsGUI_MaterialList; class GEOMTOOLSGUI_EXPORT GEOMToolsGUI_MaterialPropertiesDlg : public QtxDialog { Q_OBJECT - enum { Current, Default, Global, User }; + enum { Current, Global, User }; enum { TypeRole = Qt::UserRole + 123, NameRole }; - //! Enumeration of viewer types - typedef enum { - OCC, //!< OCC viewer - VTK //!< VTK viewer - } ViewerType; - public: GEOMToolsGUI_MaterialPropertiesDlg( QWidget* = 0 ); ~GEOMToolsGUI_MaterialPropertiesDlg(); @@ -66,66 +53,56 @@ public: bool eventFilter( QObject*, QEvent* ); private: - Material_ResourceMgr* resourceMgr(); - - void fromModel( Material_Model* ); - void toModel( Material_Model* ) const; - + void updateState(); + void toModel( Material_Model& ) const; + void fromModel( const Material_Model& ); QString findUniqueName( const QString&, - QListWidgetItem* = 0, - bool = false ); + QListWidgetItem* = 0, + bool = false ); signals: - void materialChanged(); void changed(); private slots: - - void onApply(); - void onHelp(); - - void onMaterialChanged(); void onChanged(); + void onMaterialChanged(); void onItemChanged( QListWidgetItem* ); - void onReflectionTypeToggled( bool ); + void onContextMenu( QContextMenuEvent* ); + void onDeleteMaterial(); + void onAddMaterial(); + void onApply(); + void onHelp(); private: - - Material_ResourceMgr* myResMgr; - - QCheckBox* myMaterialPhysicalCheck; - - //! Current material model for material - Material_Model* myCurrentModelF; - - QListWidget* myMaterialList; - int myMaterialListFId; - - QTabWidget* myMaterialTab; - - //! Controls defining material properties - QGroupBox* myAmbientGroupF; - QtxColorButton* myAmbientColorF; - QtxDoubleSpinBox* myAmbientCoefntF; - - QGroupBox* myDiffuseGroupF; - QtxColorButton* myDiffuseColorF; - QtxDoubleSpinBox* myDiffuseCoefntF; - - QGroupBox* mySpecularGroupF; - QtxColorButton* mySpecularColorF; - QtxDoubleSpinBox* mySpecularCoefntF; - - QGroupBox* myEmissionGroupF; - QtxColorButton* myEmissionColorF; - QtxDoubleSpinBox* myEmissionCoefntF; - - QtxDoubleSpinBox* myShininessF; - - QString myHelpFileName; + typedef struct + { + QLabel* label; + QtxColorButton* color; + QSlider* coef; + QCheckBox* enabled; + } Reflection; + + GEOMToolsGUI_MaterialList* myMaterials; + QCheckBox* myPhysical; + QList myReflection; + QSlider* myShininess; + QLabel* myColorLab; + QtxColorButton* myColor; + QPushButton* myAddButton; + QPushButton* myDelButton; + Material_ResourceMgr myResourceMgr; + Material_Model myCurrentModel; +}; - ViewerType myViewerType; - +class GEOMToolsGUI_MaterialList : public QListWidget +{ +Q_OBJECT +public: + GEOMToolsGUI_MaterialList( QWidget* parent ); +protected: + void contextMenuEvent( QContextMenuEvent* e ); +signals: + void contextMenu( QContextMenuEvent* ); }; #endif // GEOMTOOLSGUI_MATERIALPROPERTIESDLG_H diff --git a/src/Material/Material_Model.cxx b/src/Material/Material_Model.cxx index be5627a2f..9744571c5 100644 --- a/src/Material/Material_Model.cxx +++ b/src/Material/Material_Model.cxx @@ -22,17 +22,8 @@ // #include "Material_Model.h" -#include "Material_ResourceMgr.h" - #include "GEOM_VTKPropertyMaterial.hxx" -#include - -#include -#include -#include - -// OCCT Includes -#include +#include "Material_ResourceMgr.h" /*! \brief Constructor @@ -40,10 +31,9 @@ Create new SALOME material model with default properties. */ Material_Model::Material_Model() - : myResourceMgr( 0 ) { - myShininess = 0.0; - myIsPhysical = false; + myReflection = ReflectionList(4); + init(); // set default properties } /*! @@ -54,664 +44,567 @@ Material_Model::~Material_Model() } /*! - \brief Construct material model according to the given list of - material properties - - \param theProps the list of material properties - \return material model object with correspondent properties - \sa getMaterialProperty() + \brief Initialize material data from the given properties list + \param props material properties + \sa toProperties() */ -Material_Model* Material_Model::getMaterialModel( QStringList theProps ) +void Material_Model::fromProperties( const QString& props ) { - Material_Model* aModel = new Material_Model(); - - foreach ( QString aProp, theProps ) { - if ( aProp.isNull() ) continue; - - // Set current ambient color - aModel->setColor( aProp, "AmbientColor=", Material_Model::Ambient ); - // Set current ambient coefficient - aModel->setCoefficient( aProp, "AmbientCoefficient=", Material_Model::Ambient ); - - // Set current diffuse color - aModel->setColor( aProp, "DiffuseColor=", Material_Model::Diffuse ); - // Set current diffuse coefficient - aModel->setCoefficient( aProp, "DiffuseCoefficient=", Material_Model::Diffuse ); - - // Set current specular color - aModel->setColor( aProp, "SpecularColor=", Material_Model::Specular ); - // Set current specular coefficient - aModel->setCoefficient( aProp, "SpecularCoefficient=", Material_Model::Specular ); - - // Set current emission color - aModel->setColor( aProp, "EmissionColor=", Material_Model::Emission ); - // Set current emission coefficient - aModel->setCoefficient( aProp, "EmissionCoefficient=", Material_Model::Emission ); + // reset to default values + init(); + + // parse material properties + QStringList propList = props.split( ":", QString::SkipEmptyParts ); + foreach ( QString prop, propList ) + { + QStringList pdata = prop.split( "=" ); + if ( pdata.count() < 2 ) continue; + QString key = pdata[0].trimmed().toLower(); + QString data = pdata[1].trimmed().toLower(); + bool dblOk, boolOk; + double dblValue = data.toDouble( &dblOk ); + bool boolValue = (bool)( data.toInt( &boolOk ) ); + QColor colorValue; - // Set current shininess - QString aPropName = "Shininess="; - int anId = aProp.indexOf(aPropName); - if ( anId != -1 ) { - bool ok; - double aCoef = aProp.right( aProp.length() - (anId+aPropName.length()) ).toDouble(&ok); - if ( ok ) - aModel->setShininess( aCoef ); - } - - // Set current material type: physical or artificial - aPropName = "Physical="; - anId = aProp.indexOf(aPropName); - if ( anId != -1 ) { - bool ok; - bool aFlag = aProp.right( aProp.length() - (anId+aPropName.length()) ).toInt( &ok ); - if ( ok ) - aModel->setPhysical( aFlag ); - } + if ( key == "ambientcolor" && Qtx::stringToColor( data, colorValue ) ) { + setColor( Ambient, colorValue ); + } + else if ( key == "diffusecolor" && Qtx::stringToColor( data, colorValue ) ) { + setColor( Diffuse, colorValue ); + } + else if ( key == "specularcolor" && Qtx::stringToColor( data, colorValue ) ) { + setColor( Specular, colorValue ); + } + else if ( key == "emissivecolor" && Qtx::stringToColor( data, colorValue ) ) { + setColor( Emissive, colorValue ); + } + else if ( key == "ambientcoefficient" && dblOk ) { + setReflection( Ambient, dblValue ); + } + else if ( key == "diffusecoefficient" && dblOk ) { + setReflection( Diffuse, dblValue ); + } + else if ( key == "specularcoefficient" && dblOk ) { + setReflection( Specular, dblValue ); + } + else if ( key == "emissivecoefficient" && dblOk ) { + setReflection( Emissive, dblValue ); + } + else if ( key == "shininess" && dblOk ) { + setShininess( dblValue ); + } + else if ( key == "transparency" && dblOk ) { + setTransparency( dblValue ); + } + else if ( key == "physical" && boolOk ) { + setPhysical( boolValue ); + } + else if ( key == "ambient" && boolOk ) { + setReflection( Ambient, boolValue ); + } + else if ( key == "diffuse" && boolOk ) { + setReflection( Diffuse, boolValue ); + } + else if ( key == "specular" && boolOk ) { + setReflection( Specular, boolValue ); + } + else if ( key == "emissive" && boolOk ) { + setReflection( Emissive, boolValue ); + } } - - return aModel; } /*! - \brief Construct string of material properties for this model object - - \return a string representing a set of material properties - \sa getMaterialModel() + \brief Get material properties string representation + \return string representing of material properties + \sa fromProperties() */ -QString Material_Model::getMaterialProperty() +QString Material_Model::toProperties() { - // Parse material properties of the current model and form a string for persistent purpose - QString aMaterial; - - bool isReflectionTypeActive; - QColor c; - double coef; - - // Ambient reflection - isReflectionTypeActive = hasAmbientReflection(); - if ( isReflectionTypeActive ) { - c = color( Material_Model::Ambient ); - coef = coefficient(Material_Model::Ambient); - // Insert properties into persistent string - aMaterial = "AmbientColor=%1%2AmbientCoefficient=%3"; - aMaterial = aMaterial.arg( Qtx::colorToString(c) ); - aMaterial = aMaterial.arg( DIGIT_SEPARATOR ); - aMaterial = aMaterial.arg( coef ); - } - // Diffuse reflection - isReflectionTypeActive = hasDiffuseReflection(); - if ( isReflectionTypeActive ) { - c = color( Material_Model::Diffuse ); - coef = coefficient(Material_Model::Diffuse); - // Insert properties into persistent string - aMaterial += "%1DiffuseColor=%2%3DiffuseCoefficient=%4"; - aMaterial = aMaterial.arg( DIGIT_SEPARATOR ); - aMaterial = aMaterial.arg( Qtx::colorToString(c) ); - aMaterial = aMaterial.arg( DIGIT_SEPARATOR ); - aMaterial = aMaterial.arg( coef ); - } - // Specular reflection - isReflectionTypeActive = hasSpecularReflection(); - if ( isReflectionTypeActive ) { - c = color( Material_Model::Specular ); - coef = coefficient(Material_Model::Specular); - // Insert properties into persistent string - aMaterial += "%1SpecularColor=%2%3SpecularCoefficient=%4"; - aMaterial = aMaterial.arg( DIGIT_SEPARATOR ); - aMaterial = aMaterial.arg( Qtx::colorToString(c) ); - aMaterial = aMaterial.arg( DIGIT_SEPARATOR ); - aMaterial = aMaterial.arg( coef ); - } - // Emission reflection - isReflectionTypeActive = hasEmissionReflection(); - if ( isReflectionTypeActive ) { - c = color( Material_Model::Emission ); - coef = coefficient(Material_Model::Emission); - // Insert properties into persistent string - aMaterial += "%1EmissionColor=%2%3EmissionCoefficient=%4"; - aMaterial = aMaterial.arg( DIGIT_SEPARATOR ); - aMaterial = aMaterial.arg( Qtx::colorToString(c) ); - aMaterial = aMaterial.arg( DIGIT_SEPARATOR ); - aMaterial = aMaterial.arg( coef ); - } - if ( !aMaterial.isEmpty() ) { - // Shininess - // Insert properties into persistent string - aMaterial += "%1Shininess=%2"; - aMaterial = aMaterial.arg( DIGIT_SEPARATOR ); - aMaterial = aMaterial.arg( shininess() ); - // Type: physical - True, artificial - False - // Insert properties into persistent string - aMaterial += "%1Physical=%2"; - aMaterial = aMaterial.arg( DIGIT_SEPARATOR ); - aMaterial = aMaterial.arg( isPhysical() ); - } - - return aMaterial; + QStringList props; + QString fmt = "%1=%2"; + + // physical + props << fmt.arg( "Physical" ).arg( isPhysical() ); + + // shininess + props << fmt.arg( "Shininess" ).arg( shininess() ); + + //transparency + props << fmt.arg( "Transparency" ).arg( transparency() ); + + // ambient reflection + props << fmt.arg( "Ambient" ).arg( hasReflection( Ambient ) ); + if ( color( Ambient ).isValid() ) + props << fmt.arg( "AmbientColor" ).arg( Qtx::colorToString( color( Ambient ) ) ); + props << fmt.arg( "AmbientCoefficient" ).arg( reflection( Ambient ) ); + + // diffuse reflection + props << fmt.arg( "Diffuse" ).arg( hasReflection( Diffuse ) ); + if ( color( Diffuse ).isValid() ) + props << fmt.arg( "DiffuseColor" ).arg( Qtx::colorToString( color( Diffuse ) ) ); + props << fmt.arg( "DiffuseCoefficient" ).arg( reflection( Diffuse ) ); + + // specular reflection + props << fmt.arg( "Specular" ).arg( hasReflection( Specular ) ); + if ( color( Specular ).isValid() ) + props << fmt.arg( "SpecularColor" ).arg( Qtx::colorToString( color( Specular ) ) ); + props << fmt.arg( "SpecularCoefficient" ).arg( reflection( Specular ) ); + + // emissive reflection + props << fmt.arg( "Emissive" ).arg( hasReflection( Emissive ) ); + if ( color( Emissive ).isValid() ) + props << fmt.arg( "EmissiveColor" ).arg( Qtx::colorToString( color( Emissive ) ) ); + props << fmt.arg( "EmissiveCoefficient" ).arg( reflection( Emissive ) ); + + return props.join( ":" ); } /*! - \brief Construct OCCT material aspect object based on the current model - - \return material aspect object with correspondent properties -*/ -Graphic3d_MaterialAspect Material_Model::getMaterialOCCAspect() -{ - // Get material aspect from the current model - Graphic3d_MaterialAspect aMat; - - bool isReflectionTypeActive; - QColor c; - double coef; - - // Ambient reflection - isReflectionTypeActive = hasAmbientReflection(); - if ( isReflectionTypeActive ) { - aMat.SetReflectionModeOn( Graphic3d_TOR_AMBIENT ); - c = color( Material_Model::Ambient ); - aMat.SetAmbientColor( Quantity_Color( c.redF(), c.greenF(), c.blueF(), Quantity_TOC_RGB ) ); - coef = coefficient( Material_Model::Ambient ); - aMat.SetAmbient( coef ); - } - // Diffuse reflection - isReflectionTypeActive = hasDiffuseReflection(); - if ( isReflectionTypeActive ) { - aMat.SetReflectionModeOn( Graphic3d_TOR_DIFFUSE ); - c = color( Material_Model::Diffuse ); - aMat.SetDiffuseColor( Quantity_Color( c.redF(), c.greenF(), c.blueF(), Quantity_TOC_RGB ) ); - coef = coefficient( Material_Model::Diffuse ); - aMat.SetDiffuse( coef ); - } - // Specular reflection - isReflectionTypeActive = hasSpecularReflection(); - if ( isReflectionTypeActive ) { - aMat.SetReflectionModeOn( Graphic3d_TOR_SPECULAR ); - c = color( Material_Model::Specular ); - aMat.SetSpecularColor( Quantity_Color( c.redF(), c.greenF(), c.blueF(), Quantity_TOC_RGB ) ); - coef = coefficient( Material_Model::Specular ); - aMat.SetSpecular( coef ); - } - // Emission reflection - isReflectionTypeActive = hasEmissionReflection(); - if ( isReflectionTypeActive ) { - aMat.SetReflectionModeOn( Graphic3d_TOR_EMISSION ); - c = color( Material_Model::Emission ); - aMat.SetEmissiveColor( Quantity_Color( c.redF(), c.greenF(), c.blueF(), Quantity_TOC_RGB ) ); - coef = coefficient( Material_Model::Emission ); - aMat.SetEmissive( coef ); - } - // Shininess - aMat.SetShininess( shininess() ); - aMat.SetMaterialType(isPhysical() ? Graphic3d_MATERIAL_PHYSIC : Graphic3d_MATERIAL_ASPECT); + \brief Initialize material model from the resources - return aMat; -} + This function can be used to retrieve material properties from the resource file. -/*! - \brief Construct VTK property with properties of material based on the current model - - \return VTK property with correspondent material properties + \param material material name (if not specified, model is initialized by default material) + \param resMgr resource manager (if not specified, new resources manager is created) + \sa toResources() */ -GEOM_VTKPropertyMaterial* Material_Model::getMaterialVTKProperty() +void Material_Model::fromResources( const QString& material, QtxResourceMgr* resMgr ) { - // Get material properties from the current model - GEOM_VTKPropertyMaterial* aProperty = GEOM_VTKPropertyMaterial::New(); + static QString common = "[common]"; - bool isReflectionTypeActive; - QColor c; - double coef; - - // Ambient reflection - isReflectionTypeActive = hasAmbientReflection(); - if ( isReflectionTypeActive ) { - c = color( Material_Model::Ambient ); - aProperty->SetAmbientColor( c.redF(), c.greenF(), c.blueF() ); //SalomeApp_Tools::color( c ) - coef = coefficient( Material_Model::Ambient ); - aProperty->SetAmbient( coef ); - } - // Diffuse reflection - isReflectionTypeActive = hasDiffuseReflection(); - if ( isReflectionTypeActive ) { - c = color( Material_Model::Diffuse ); - aProperty->SetDiffuseColor( c.redF(), c.greenF(), c.blueF() ); - coef = coefficient( Material_Model::Diffuse ); - aProperty->SetDiffuse( coef ); - } - // Specular reflection - isReflectionTypeActive = hasSpecularReflection(); - if ( isReflectionTypeActive ) { - c = color( Material_Model::Specular ); - aProperty->SetSpecularColor( c.redF(), c.greenF(), c.blueF() ); - coef = coefficient( Material_Model::Specular ); - aProperty->SetSpecular( coef ); - } - // Shininess - aProperty->SetSpecularPower( shininess()*100.0 ); - //Type - aProperty->SetPhysical( isPhysical() ); + // reset to default values + init(); - return aProperty; -} + // material name is not specified: use default values + if ( material.isEmpty() ) return; -/*! - \brief Initialize material model with default values -*/ -void Material_Model::initDefaults() -{ - // Set default ambient color - setColor( Ambient, "#333333" ); - // Set default ambient coefficient - setCoefficient( Ambient, 0.3 ); - - // Set default diffuse color - setColor( Diffuse, "#000000" ); - // Set default diffuse coefficient - setCoefficient( Diffuse, 0.65 ); - - // Set default specular color - setColor( Specular, "#ffffff" ); - // Set default specular coefficient - setCoefficient( Specular, 0.0 ); + bool ownResourcesMgr = resMgr == 0; - // Set default shininess - setShininess( 0.039 ); - - // Set default type - artificial - setPhysical( false ); -} - -/*! - \brief Clear current content of this material model -*/ -void Material_Model::clearModel() -{ - myColors.clear(); - myCoefficients.clear(); - myShininess = 0.0; - myIsPhysical = false; -} - -/*! - \brief Initialize material model from the resources - - This function can be used to retrieve material properties from the resource file(s). - Note, that paremeters \a theResMgr and \a theResSection are stored by the model to be used - later with save() method. + if ( ownResourcesMgr ) + resMgr = new Material_ResourceMgr(); - \param theResMgr resources manager - \param theResSection resources section name - \sa save() -*/ -void Material_Model::fromResources( QtxResourceMgr* theResMgr, - const QString& theResSection/*, bool theIsFront*/ ) -{ - // Clear current content of the model - // before setting properties from resources - clearModel(); - - myResourceMgr = theResMgr; - myResourceSection = theResSection; + // read common section + if ( material != common && resMgr->hasSection( common ) ) + fromResources( common, resMgr ); - // init from resource manager - if ( !resourceMgr() ) - return; - - if ( theResSection.compare( "Geometry" ) == 0 ) { - myResourceSection = theResMgr->stringValue("Geometry", "material", "Gold"); - myResourceMgr = new Material_ResourceMgr(); + // physical + if ( resMgr->hasValue( material, "physical" ) ) { + setPhysical( resMgr->booleanValue( material, "physical" ) ); } - - QString section = resourceSection(); - // If there is no material preference in XML files, - // use the default material hardcoded in material model - if ( section.isEmpty() ) { - initDefaults(); - return; + // shininess + if ( resMgr->hasValue( material, "shininess" ) ) { + setShininess( resMgr->doubleValue( material, "shininess" ) ); } - // Set ambient color - if ( resourceMgr()->hasValue( section, "ambient-color" ) ) { - setColor( Ambient, resourceMgr()->colorValue( section, "ambient-color" ) ); - } - // Set ambient coefficient - if ( resourceMgr()->hasValue( section, "ambient-coefficient" ) ) { - setCoefficient( Ambient, resourceMgr()->doubleValue( section, "ambient-coefficient" ) ); + // transparency + if ( resMgr->hasValue( material, "transparency" ) ) { + setTransparency( resMgr->doubleValue( material, "transparency" ) ); } - // Set diffuse color - if ( resourceMgr()->hasValue( section, "diffuse-color" ) ) { - setColor( Diffuse, resourceMgr()->colorValue( section, "diffuse-color" ) ); - } - // Set diffuse coefficient - if ( resourceMgr()->hasValue( section, "diffuse-coefficient" ) ) { - setCoefficient( Diffuse, resourceMgr()->doubleValue( section, "diffuse-coefficient" ) ); + // ambient reflection + if ( resMgr->hasValue( material, "ambient-color" ) ) { + setColor( Ambient, resMgr->colorValue( material, "ambient-color" ) ); } - - // Set specular color - if ( resourceMgr()->hasValue( section, "specular-color" ) ) { - setColor( Specular, resourceMgr()->colorValue( section, "specular-color" ) ); + if ( resMgr->hasValue( material, "ambient-coefficient" ) ) { + setReflection( Ambient, resMgr->doubleValue( material, "ambient-coefficient" ) ); } - // Set specular coefficient - if ( resourceMgr()->hasValue( section, "specular-coefficient" ) ) { - setCoefficient( Specular, resourceMgr()->doubleValue( section, "specular-coefficient" ) ); + if ( resMgr->hasValue( material, "ambient" ) ) { + setReflection( Ambient, resMgr->booleanValue( material, "ambient" ) ); } - // Set emission color - if ( resourceMgr()->hasValue( section, "emission-color" ) ) { - setColor( Emission, resourceMgr()->colorValue( section, "emission-color" ) ); + // diffuse reflection + if ( resMgr->hasValue( material, "diffuse-color" ) ) { + setColor( Diffuse, resMgr->colorValue( material, "diffuse-color" ) ); } - // Set emission coefficient - if ( resourceMgr()->hasValue( section, "emission-coefficient" ) ) { - setCoefficient( Emission, resourceMgr()->doubleValue( section, "emission-coefficient" ) ); + if ( resMgr->hasValue( material, "diffuse-coefficient" ) ) { + setReflection( Diffuse, resMgr->doubleValue( material, "diffuse-coefficient" ) ); } - - // Set shininess - if ( resourceMgr()->hasValue( section, "shininess" ) ) { - setShininess( resourceMgr()->doubleValue( section, "shininess" ) ); + if ( resMgr->hasValue( material, "diffuse" ) ) { + setReflection( Diffuse, resMgr->booleanValue( material, "diffuse" ) ); } - // Set type: physical or artificial - if ( resourceMgr()->hasValue( section, "physical" ) ) { - setPhysical( resourceMgr()->booleanValue( section, "physical" ) ); + // specular reflection + if ( resMgr->hasValue( material, "specular-color" ) ) { + setColor( Specular, resMgr->colorValue( material, "specular-color" ) ); } -} - -/*! - \brief Save material properties to the resource file. - - If paremeters \a theResMgr and \a theResSection are not specified, default ones - (those passed to the fromResources() function) are used instead. - - \param theResMgr resources manager - \param theResSection resources section name - \sa fromResources() -*/ -void Material_Model::save( QtxResourceMgr* theResMgr, - const QString& theResSection) -{ - if ( !theResMgr ) - theResMgr = resourceMgr(); - if ( !theResMgr ) - return; - - QString section = theResSection.isEmpty() ? resourceSection() : theResSection; - myResourceSection = section; - - if ( hasAmbientReflection() ) { - // Save ambient color - theResMgr->setValue( section, "ambient-color", color( Ambient ) ); - // Save ambient coefficient - theResMgr->setValue( section, "ambient-coefficient", coefficient( Ambient ) ); + if ( resMgr->hasValue( material, "specular-coefficient" ) ) { + setReflection( Specular, resMgr->doubleValue( material, "specular-coefficient" ) ); } - else { - // Remove ambient color - theResMgr->remove( section, "ambient-color" ); - // Remove ambient coefficient - theResMgr->remove( section, "ambient-coefficient" ); + if ( resMgr->hasValue( material, "specular" ) ) { + setReflection( Specular, resMgr->booleanValue( material, "specular" ) ); } - if ( hasDiffuseReflection() ) { - // Save diffuse color - theResMgr->setValue( section, "diffuse-color", color( Diffuse ) ); - // Save diffuse coefficient - theResMgr->setValue( section, "diffuse-coefficient", coefficient( Diffuse ) ); + // emissive reflection + if ( resMgr->hasValue( material, "emissive-color" ) ) { + setColor( Emissive, resMgr->colorValue( material, "emissive-color" ) ); } - else { - // Remove diffuse color - theResMgr->remove( section, "diffuse-color" ); - // Remove diffuse coefficient - theResMgr->remove( section, "diffuse-coefficient" ); - } - - if ( hasSpecularReflection() ) { - // Save specular color - theResMgr->setValue( section, "specular-color", color( Specular ) ); - // Save specular coefficient - theResMgr->setValue( section, "specular-coefficient", coefficient( Specular ) ); + if ( resMgr->hasValue( material, "emissive-coefficient" ) ) { + setReflection( Emissive, resMgr->doubleValue( material, "emissive-coefficient" ) ); } - else { - // Remove specular color - theResMgr->remove( section, "specular-color" ); - // Remove specular coefficient - theResMgr->remove( section, "specular-coefficient" ); + if ( resMgr->hasValue( material, "emissive" ) ) { + setReflection( Emissive, resMgr->booleanValue( material, "emissive" ) ); } - if ( hasEmissionReflection() ) { - // Save emission color - theResMgr->setValue( section, "emission-color", color( Emission ) ); - // Save emission coefficient - theResMgr->setValue( section, "emission-coefficient", coefficient( Emission ) ); - } - else { - // Remove emission color - theResMgr->remove( section, "emission-color" ); - // Remove emission coefficient - theResMgr->remove( section, "emission-coefficient" ); - } - - // Save shininess - theResMgr->setValue( section, "shininess", shininess() ); - - // Save type: physical or artificial - theResMgr->setValue( section, "physical", isPhysical() ); + if ( ownResourcesMgr ) + delete resMgr; } /*! - \brief Get resource manager used by this material model. - - \return pointer to the resource manager passed previously to the fromResources() method - \sa fromResources(), resourceSection() + \brief Save material properties to the resource file. + \param material material name + \param resMgr resource manager + \sa fromResources() */ -QtxResourceMgr* Material_Model::resourceMgr() const +void Material_Model::toResources( const QString& material, QtxResourceMgr* resMgr ) { - return myResourceMgr; + if ( resMgr && !material.isEmpty() ) { + // remove resources section (to clean-up all previous properties) + resMgr->remove( material ); + + // physical + resMgr->setValue( material, "physical", isPhysical() ); + + // shininess + resMgr->setValue( material, "shininess", shininess() ); + + // transparency + resMgr->setValue( material, "transparency", transparency() ); + + // ambient reflection + if ( color( Ambient ).isValid() ) + resMgr->setValue( material, "ambient-color", color( Ambient ) ); + resMgr->setValue( material, "ambient-coefficient", reflection( Ambient ) ); + resMgr->setValue( material, "ambient", hasReflection( Ambient ) ); + + // diffuse reflection + if ( color( Diffuse ).isValid() ) + resMgr->setValue( material, "diffuse-color", color( Diffuse ) ); + resMgr->setValue( material, "diffuse-coefficient", reflection( Diffuse ) ); + resMgr->setValue( material, "diffuse", hasReflection( Diffuse ) ); + + // Specular reflection + if ( color( Specular ).isValid() ) + resMgr->setValue( material, "specular-color", color( Specular ) ); + resMgr->setValue( material, "specular-coefficient", reflection( Specular ) ); + resMgr->setValue( material, "specular", hasReflection( Specular ) ); + + // Emissive reflection + if ( color( Emissive ).isValid() ) + resMgr->setValue( material, "emissive-color", color( Emissive ) ); + resMgr->setValue( material, "emissive-coefficient", reflection( Emissive ) ); + resMgr->setValue( material, "emissive", hasReflection( Emissive ) ); + } } /*! - \brief Get resources section name + \brief Initialize material model from the preferences - If section name is empty, default material name from "Geometry" section - is returned. + The material name is retrieved from the "material" parameter of the "Geometry" section + of the specified resources manager. - \return resource section name passed previously to the fromResources() method - \sa fromResources(), resourceMgr() + \param resMgr resources manager + \sa fromResources(), toResources() */ -QString Material_Model::resourceSection() const -{ - return !myResourceSection.isEmpty() ? myResourceSection : - SUIT_Session::session()->resourceMgr()->stringValue("Geometry", "material", "Gold"); -} +// void Material_Model::fromPreferences( QtxResourceMgr* resMgr ) +// { +// if ( resMgr ) { +// // default material is Plastic +// fromResources( resMgr->stringValue( "Geometry", "material", "Plastic" ) ); +// } +// } /*! - \brief Check if ambient reflection type is defined for this material - - \return true if ambient reflection type is defined for this material, - false - otherwise + \brief Get material type + \return \c true if material is physical or \c false otherwise + \sa setPhysical() */ -bool Material_Model::hasAmbientReflection() +bool Material_Model::isPhysical() const { - return ( !myColors.isEmpty() && myColors.contains(Ambient) || !myCoefficients.isEmpty() && myCoefficients.contains(Ambient) ); + return myIsPhysical; } /*! - \brief Check if diffuse reflection type is defined for this material - - \return true if diffuse reflection type is defined for this material, - false - otherwise + \brief Set material type + \param value \c true if material is physical or \c false otherwise + \sa isPhysical() */ -bool Material_Model::hasDiffuseReflection() +void Material_Model::setPhysical( bool value ) { - return ( !myColors.isEmpty() && myColors.contains(Diffuse) || !myCoefficients.isEmpty() && myCoefficients.contains(Diffuse) ); + myIsPhysical = value; } /*! - \brief Check if specular reflection type is defined for this material - - \return true if specular reflection type is defined for this material, - false - otherwise + \brief Check if given reflection is enabled + \param type reflection type + \return \c true if specified reflection type is enabled or \c false otherwise + \sa setReflection(ReflectionType, bool) */ -bool Material_Model::hasSpecularReflection() +bool Material_Model::hasReflection( ReflectionType type ) const { - return ( !myColors.isEmpty() && myColors.contains(Specular) || !myCoefficients.isEmpty() && myCoefficients.contains(Specular) ); + bool value = false; + if ( type >= 0 && type < 4 ) + value = myReflection[ type ].enabled; + return value; } /*! - \brief Check if emission reflection type is defined for this material - - \return true if emission reflection type is defined for this material, - false - otherwise + \brief Enable/disable given reflection type + \param type reflection type + \param value boolean flag + \sa hasReflection() */ -bool Material_Model::hasEmissionReflection() +void Material_Model::setReflection( ReflectionType type, bool value ) { - return ( !myColors.isEmpty() && myColors.contains(Emission) || !myCoefficients.isEmpty() && myCoefficients.contains(Emission) ); + if ( type >= 0 && type < 4 ) + myReflection[ type ].enabled = value; } /*! \brief Get color value for the given reflection type - \param theReflectionType reflection type - \return a color which should be used by the given reflection type + \param type reflection type + \return color associated with the specified reflection type \sa setColor() */ -QColor Material_Model::color( ReflectionType theReflectionType ) const +QColor Material_Model::color( ReflectionType type ) const { - return myColors[ theReflectionType ]; + QColor value; + if ( type >= 0 && type < 4 ) + value = myReflection[ type ].color; + return value; } /*! \brief Set color value for the given reflection type - - \param theReflectionType reflection type - \param theColor a color to be used by the given reflection type + \param type reflection type + \param value color to be used for specified reflection type \sa color() */ -void Material_Model::setColor( ReflectionType theReflectionType, - const QColor& theColor ) +void Material_Model::setColor( ReflectionType type, const QColor& value ) { - myColors[ theReflectionType ] = theColor; + if ( type >= 0 && type < 4 ) + myReflection[ type ].color = value; } /*! - \brief Set color of the current material from the given string - \param theProp the considered property - \param theColorName the name of the color property - \param theReflectionType the type of reflection + \brief Get coefficient value for the given reflection type + \param type reflection type + \return coefficient value for the specified reflection type + \sa setReflection(ReflectionType, double) */ -void Material_Model::setColor( QString theProp, - QString theColorName, - ReflectionType theReflectionType ) +double Material_Model::reflection( ReflectionType type ) const { - int anId = theProp.indexOf( theColorName ); - if ( anId != -1 ) { - QColor c; - if ( Qtx::stringToColor( theProp.right( theProp.length() - ( anId + theColorName.length() ) ), c ) ) - setColor( theReflectionType, c ); - } + double value = 0.0; + if ( type >= 0 && type < 4 ) + value = myReflection[ type ].coef; + return value; } /*! - \brief Remove color value for the given reflection type - - \param theReflectionType reflection type - \sa color(), setColor() + \brief Set coefficient value for the given reflection type + \param type reflection type + \param value coefficient to be used by the given reflection type + \sa reflection() */ -void Material_Model::removeColor( ReflectionType theReflectionType ) +void Material_Model::setReflection( ReflectionType type, double value ) { - myColors.remove( theReflectionType ); + if ( type >= 0 && type < 4 ) + myReflection[ type ].coef = value; } /*! - \brief Get coefficient value for the given reflection type - \param theReflectionType reflection type - \return a coefficient which should be used by the given reflection type - \sa setCoefficient() + \brief Get shininess value + \return shininess value of the material + \sa setShininess() */ -double Material_Model::coefficient( ReflectionType theReflectionType ) const +double Material_Model::shininess() const { - return myCoefficients[ theReflectionType ]; + return myShininess; } /*! - \brief Set coefficient value for the given reflection type - - \param theReflectionType reflection type - \param theCoefficient a coefficient to be used by the given reflection type - \sa coefficient() + \brief Set shininess value + \param value new shininess value + \sa shininess() */ -void Material_Model::setCoefficient( ReflectionType theReflectionType, - double theCoefficient ) +void Material_Model::setShininess( double value ) { - myCoefficients[ theReflectionType ] = theCoefficient; + myShininess = value; } /*! - \brief Set coefficient of the current material from the given string - \param theProp the considered property - \param theCoefName the name of the color property - \param theReflectionType the type of reflection + \brief Get transparency value + \return transparency value of the material + \sa setTransparency() */ -void Material_Model::setCoefficient( QString theProp, - QString theCoefName, - ReflectionType theReflectionType ) +double Material_Model::transparency() const { - int anId = theProp.indexOf( theCoefName ); - if ( anId != -1 ) { - bool ok; - double aCoef = theProp.right( theProp.length() - ( anId + theCoefName.length() ) ).toDouble( &ok ); - if ( ok ) - setCoefficient( theReflectionType, aCoef ); - } + return myTransparency; } /*! - \brief Remove coefficient value for the given reflection type - - \param theReflectionType reflection type - \sa coefficient(), setCoefficient() + \brief Set transparency value + \param value new transparency value + \sa transparency() */ -void Material_Model::removeCoefficient( ReflectionType theReflectionType ) +void Material_Model::setTransparency( double value ) { - myCoefficients.remove( theReflectionType ); + myTransparency = value; } /*! - \brief Get shininess value - \return a shininess value of this material - \sa setShininess() + \brief Initialize material model with default values */ -double Material_Model::shininess() const -{ - return myShininess; +void Material_Model::init() +{ + QColor c; + + // non-physical by default + setPhysical( false ); + // shininess + setShininess( 0.039 ); + // transparency + setTransparency( 0.0 ); + + // ambient reflection (enabled by default) + Qtx::stringToColor( "#333333", c ); + setColor( Ambient, c ); + setReflection( Ambient, 0.3 ); + setReflection( Ambient, true ); + + // diffuse reflection (enabled by default) + Qtx::stringToColor( "#000000", c ); + setColor( Diffuse, c ); + setReflection( Diffuse, 0.65 ); + setReflection( Diffuse, true ); + + // specular reflection (enabled by default) + Qtx::stringToColor( "#ffffff", c ); + setColor( Specular, c ); + setReflection( Specular, 0.0 ); + setReflection( Specular, true ); + + // emissive reflection (disabled by default) + Qtx::stringToColor( "#000000", c ); + setColor( Emissive, c ); + setReflection( Emissive, 0.0 ); + setReflection( Emissive, false ); } /*! - \brief Set shininess value - - \param theShininess a shininess value of this material - \sa shininess() + \brief Construct OCCT material aspect from material model + \return material aspect object with corresponding properties */ -void Material_Model::setShininess( double theShininess) +Graphic3d_MaterialAspect Material_Model::getMaterialOCCAspect() { - myShininess = theShininess; + // Get material aspect from the current model + Graphic3d_MaterialAspect aspect; + + QColor c; + + // ambient reflection + if ( color( Ambient ).isValid() ) { + c = color( Ambient ); + aspect.SetAmbientColor( Quantity_Color( c.redF(), c.greenF(), c.blueF(), Quantity_TOC_RGB ) ); + } + aspect.SetAmbient( reflection( Ambient )); + if ( hasReflection( Ambient ) ) + aspect.SetReflectionModeOn( Graphic3d_TOR_AMBIENT ); + else + aspect.SetReflectionModeOff( Graphic3d_TOR_AMBIENT ); + + // diffuse reflection + if ( color( Diffuse ).isValid() ) { + c = color( Diffuse ); + aspect.SetDiffuseColor( Quantity_Color( c.redF(), c.greenF(), c.blueF(), Quantity_TOC_RGB ) ); + } + aspect.SetDiffuse( reflection( Diffuse )); + if ( hasReflection( Diffuse ) ) + aspect.SetReflectionModeOn( Graphic3d_TOR_DIFFUSE ); + else + aspect.SetReflectionModeOff( Graphic3d_TOR_DIFFUSE ); + + // specular reflection + if ( color( Specular ).isValid() ) { + c = color( Specular ); + aspect.SetSpecularColor( Quantity_Color( c.redF(), c.greenF(), c.blueF(), Quantity_TOC_RGB ) ); + } + aspect.SetSpecular( reflection( Specular )); + if ( hasReflection( Specular ) ) + aspect.SetReflectionModeOn( Graphic3d_TOR_SPECULAR ); + else + aspect.SetReflectionModeOff( Graphic3d_TOR_SPECULAR ); + + // emissive reflection + if ( color( Emissive ).isValid() ) { + c = color( Emissive ); + aspect.SetEmissiveColor( Quantity_Color( c.redF(), c.greenF(), c.blueF(), Quantity_TOC_RGB ) ); + } + aspect.SetEmissive( reflection( Emissive )); + if ( hasReflection( Emissive ) ) + aspect.SetReflectionModeOn( Graphic3d_TOR_EMISSION ); + else + aspect.SetReflectionModeOff( Graphic3d_TOR_EMISSION ); + + // shininess + aspect.SetShininess( shininess() ); + + // transparency + aspect.SetTransparency( transparency() ); + + // material type + aspect.SetMaterialType( isPhysical() ? Graphic3d_MATERIAL_PHYSIC : Graphic3d_MATERIAL_ASPECT ); + + return aspect; } /*! - \brief Get type value: physical or artificial - \return True if the material is physical and False if the material is artificial - \sa setShininess() + \brief Construct VTK property from material model + \return VTK property with correspondent material properties */ -bool Material_Model::isPhysical() const +GEOM_VTKPropertyMaterial* Material_Model::getMaterialVTKProperty() { - return myIsPhysical; -} + // NOTE: In VTK it's impossible to switch on/off specific reflection type + // NOTE: In VTK emissive reflection type is not supported + // NOTE: In VTK shininess is specified via SpecularPower attribute + // NOTE: In VTK transparency is specified via Opacity attribute -/*! - \brief Set type: physical or artificial + // Get material properties from the current model + GEOM_VTKPropertyMaterial* prop = GEOM_VTKPropertyMaterial::New(); - \param theFlag True if the material is physical and False if the material is artificial - \sa isPhysical() -*/ -void Material_Model::setPhysical( bool theFlag) -{ - myIsPhysical = theFlag; + QColor c; + + // ambient reflection + if ( color( Ambient ).isValid() && hasReflection( Ambient ) ) { + c = color( Ambient ); + prop->SetAmbientColor( c.redF(), c.greenF(), c.blueF() ); + prop->SetAmbient( reflection( Ambient ) ); + } + + // diffuse reflection + if ( color( Diffuse ).isValid() && hasReflection( Diffuse ) ) { + c = color( Diffuse ); + prop->SetDiffuseColor( c.redF(), c.greenF(), c.blueF() ); + prop->SetDiffuse( reflection( Diffuse ) ); + } + + // specular reflection + if ( color( Specular ).isValid() && hasReflection( Specular ) ) { + c = color( Specular ); + prop->SetSpecularColor( c.redF(), c.greenF(), c.blueF() ); + prop->SetSpecular( reflection( Specular ) ); + } + + // shininess + prop->SetSpecularPower( shininess()*100.0 ); + + // transparency + prop->SetOpacity( 1 - transparency() ); + + // material type + prop->SetPhysical( isPhysical() ); + + return prop; } + diff --git a/src/Material/Material_Model.h b/src/Material/Material_Model.h index 2ce233622..3f3c8ff24 100644 --- a/src/Material/Material_Model.h +++ b/src/Material/Material_Model.h @@ -28,86 +28,69 @@ #include #include #include +#include -class Graphic3d_MaterialAspect; - -class GEOM_VTKPropertyMaterial; +#include class QtxResourceMgr; +class GEOM_VTKPropertyMaterial; class MATERIAL_SALOME_EXPORT Material_Model { - public: - - //! Enumeration of reflection types of material + //! Reflection type typedef enum { Ambient, //!< Ambient Diffuse, //!< Diffuse Specular, //!< Specular - Emission //!< Emission + Emissive //!< Emissive } ReflectionType; - Material_Model(); virtual ~Material_Model(); - static Material_Model* getMaterialModel( QStringList ); - - QString getMaterialProperty(); - - Graphic3d_MaterialAspect getMaterialOCCAspect(); - GEOM_VTKPropertyMaterial* getMaterialVTKProperty(); + void fromProperties( const QString& ); + QString toProperties(); + void fromResources( const QString& = QString(), QtxResourceMgr* = 0 ); + void toResources( const QString&, QtxResourceMgr* ); - void initDefaults(); - void fromResources( QtxResourceMgr*, const QString& = QString()); - void save( QtxResourceMgr* = 0, const QString& = QString() ); - - QtxResourceMgr* resourceMgr() const; - QString resourceSection() const; + bool isPhysical() const; + void setPhysical( bool ); - bool hasAmbientReflection(); - bool hasDiffuseReflection(); - bool hasSpecularReflection(); - bool hasEmissionReflection(); + bool hasReflection( ReflectionType ) const; + void setReflection( ReflectionType, bool ); QColor color( ReflectionType ) const; void setColor( ReflectionType, const QColor& ); - void setColor( QString, - QString, - ReflectionType ); - void removeColor( ReflectionType ); - - double coefficient( ReflectionType ) const; - void setCoefficient( ReflectionType, double ); - void setCoefficient( QString, - QString, - ReflectionType ); - void removeCoefficient( ReflectionType ); + + double reflection( ReflectionType ) const; + void setReflection( ReflectionType, double ); double shininess() const; - void setShininess( double ); + void setShininess( double ); - bool isPhysical() const; - void setPhysical( bool ); + double transparency() const; + void setTransparency( double ); -private: - void clearModel(); + Graphic3d_MaterialAspect getMaterialOCCAspect(); + GEOM_VTKPropertyMaterial* getMaterialVTKProperty(); private: - typedef QMap ColorMap; - typedef QMap CoefficientMap; + void init(); - QtxResourceMgr* myResourceMgr; - QString myResourceSection; - - ColorMap myColors; - CoefficientMap myCoefficients; +private: + typedef struct { + QColor color; + double coef; + bool enabled; + } ReflectionData; - double myShininess; + typedef QVector ReflectionList; bool myIsPhysical; - + double myShininess; + double myTransparency; + ReflectionList myReflection; }; #endif // MATERIAL_MODEL_H diff --git a/src/Material/Material_ResourceMgr.cxx b/src/Material/Material_ResourceMgr.cxx index 4f23c6d66..97853f532 100644 --- a/src/Material/Material_ResourceMgr.cxx +++ b/src/Material/Material_ResourceMgr.cxx @@ -19,11 +19,8 @@ // File : Material_ResourceMgr.cxx // Author : Margarita KARPUNINA, Open CASCADE S.A.S. (margarita.karpunina@opencascade.com) -// -#include "Material_ResourceMgr.h" -//#include "Qtx.h" // used to print colors of global materials -//#include // used to print colors of global materials +#include "Material_ResourceMgr.h" /*! \class Material_ResourceMgr @@ -49,299 +46,6 @@ Material_ResourceMgr::Material_ResourceMgr() if ( dirList().isEmpty() && ::getenv( "GEOM_ROOT_DIR" ) ) setDirList( QStringList() << Qtx::addSlash( ::getenv( "GEOM_ROOT_DIR" ) ) + "share/salome/resources/geom" ); setCurrentFormat( "xml" ); - - /* - // Get string equivalent for colors of global materials ----> - QColor c; - QString s; - - // 1. ============= Plastic - std::cout << "---- Plastic:" << std::endl; - // ambient - c.setRgbF(0.2, 0.2, 0.2); - s = Qtx::colorToString( c ); - std::cout << " ambient color: " << s.toStdString().c_str() << std::endl; - // diffuse - c.setRgbF(0.0, 0.0, 0.0); - s = Qtx::colorToString( c ); - std::cout << " diffuse color: " << s.toStdString().c_str() << std::endl; - // specular - c.setRgbF(1.0, 1.0, 1.0); - s = Qtx::colorToString( c ); - std::cout << " specular color: " << s.toStdString().c_str() << std::endl; - - // 2. ============= Shiny plastic - std::cout << "---- Shiny plastic:" << std::endl; - // ambient - c.setRgbF(0.2, 0.2, 0.2); - s = Qtx::colorToString( c ); - std::cout << " ambient color: " << s.toStdString().c_str() << std::endl; - // diffuse - c.setRgbF(0.0, 0.0, 0.0); - s = Qtx::colorToString( c ); - std::cout << " diffuse color: " << s.toStdString().c_str() << std::endl; - // specular - c.setRgbF(1.0, 1.0, 1.0); - s = Qtx::colorToString( c ); - std::cout << " specular color: " << s.toStdString().c_str() << std::endl; - - // 3. ============= Satin - std::cout << "---- Satin:" << std::endl; - // ambient - c.setRgbF(0.2, 0.2, 0.2); - s = Qtx::colorToString( c ); - std::cout << " ambient color: " << s.toStdString().c_str() << std::endl; - // diffuse - c.setRgbF(0.0, 0.0, 0.0); - s = Qtx::colorToString( c ); - std::cout << " diffuse color: " << s.toStdString().c_str() << std::endl; - // specular - c.setRgbF(1.0, 1.0, 1.0); - s = Qtx::colorToString( c ); - std::cout << " specular color: " << s.toStdString().c_str() << std::endl; - - // 4. ============= Metal - std::cout << "---- Metal:" << std::endl; - // diffuse - c.setRgbF(0.0, 0.0, 0.0); - s = Qtx::colorToString( c ); - std::cout << " diffuse color: " << s.toStdString().c_str() << std::endl; - // specular - c.setRgbF(1.0, 1.0, 1.0); - s = Qtx::colorToString( c ); - std::cout << " specular color: " << s.toStdString().c_str() << std::endl; - - // 5. ============= Brass - std::cout << "---- Brass:" << std::endl; - // ambient - c.setRgbF(0.329412, 0.223529, 0.027451); - s = Qtx::colorToString( c ); - std::cout << " ambient color: " << s.toStdString().c_str() << std::endl; - // diffuse - c.setRgbF(0.780392, 0.568627, 0.113725); - s = Qtx::colorToString( c ); - std::cout << " diffuse color: " << s.toStdString().c_str() << std::endl; - // specular - c.setRgbF(0.992157, 0.941176, 0.807843); - s = Qtx::colorToString( c ); - std::cout << " specular color: " << s.toStdString().c_str() << std::endl; - - // 6. ============= Bronze - std::cout << "---- Bronze:" << std::endl; - // ambient - c.setRgbF(0.2125, 0.1275, 0.054); - s = Qtx::colorToString( c ); - std::cout << " ambient color: " << s.toStdString().c_str() << std::endl; - // diffuse - c.setRgbF(0.714, 0.4284, 0.18144); - s = Qtx::colorToString( c ); - std::cout << " diffuse color: " << s.toStdString().c_str() << std::endl; - // specular - c.setRgbF(0.393548, 0.271906, 0.166721); - s = Qtx::colorToString( c ); - std::cout << " specular color: " << s.toStdString().c_str() << std::endl; - - // 7. ============= Copper - std::cout << "---- Copper:" << std::endl; - // ambient - c.setRgbF(0.33, 0.26, 0.23); - s = Qtx::colorToString( c ); - std::cout << " ambient color: " << s.toStdString().c_str() << std::endl; - // diffuse - c.setRgbF(0.50, 0.11, 0.0); - s = Qtx::colorToString( c ); - std::cout << " diffuse color: " << s.toStdString().c_str() << std::endl; - // specular - c.setRgbF(0.95, 0.73, 0.0); - s = Qtx::colorToString( c ); - std::cout << " specular color: " << s.toStdString().c_str() << std::endl; - - // 8. ============= Gold - std::cout << "---- Gold:" << std::endl; - // ambient - c.setRgbF(1.0, 0.76862745, 0.31764706); - s = Qtx::colorToString( c ); - std::cout << " ambient color: " << s.toStdString().c_str() << std::endl; - // diffuse - c.setRgbF(1.0, 0.69, 0.0); - s = Qtx::colorToString( c ); - std::cout << " diffuse color: " << s.toStdString().c_str() << std::endl; - // specular - c.setRgbF(1.0, 0.98, 0.78); - s = Qtx::colorToString( c ); - std::cout << " specular color: " << s.toStdString().c_str() << std::endl; - - // 9. ============= Pewter - std::cout << "---- Pewter:" << std::endl; - // ambient - c.setRgbF(0.105882, 0.058824, 0.113725); - s = Qtx::colorToString( c ); - std::cout << " ambient color: " << s.toStdString().c_str() << std::endl; - // diffuse - c.setRgbF(0.427451, 0.470588, 0.541176); - s = Qtx::colorToString( c ); - std::cout << " diffuse color: " << s.toStdString().c_str() << std::endl; - // specular - c.setRgbF(0.333333, 0.333333, 0.521569); - s = Qtx::colorToString( c ); - std::cout << " specular color: " << s.toStdString().c_str() << std::endl; - - // 10. ============= Plaster - std::cout << "---- Plaster:" << std::endl; - // ambient - c.setRgbF(0.19225, 0.19225, 0.19225); - s = Qtx::colorToString( c ); - std::cout << " ambient color: " << s.toStdString().c_str() << std::endl; - // diffuse - c.setRgbF(0.50754, 0.50754, 0.50754); - s = Qtx::colorToString( c ); - std::cout << " diffuse color: " << s.toStdString().c_str() << std::endl; - // specular - c.setRgbF(0.508273, 0.508273, 0.508273); - s = Qtx::colorToString( c ); - std::cout << " specular color: " << s.toStdString().c_str() << std::endl; - - // 11. ============= Silver - std::cout << "---- Silver:" << std::endl; - // ambient - c.setRgbF(0.19225, 0.19225, 0.19225); - s = Qtx::colorToString( c ); - std::cout << " ambient color: " << s.toStdString().c_str() << std::endl; - // diffuse - c.setRgbF(0.50754, 0.50754, 0.50754); - s = Qtx::colorToString( c ); - std::cout << " diffuse color: " << s.toStdString().c_str() << std::endl; - // specular - c.setRgbF(0.508273, 0.508273, 0.508273); - s = Qtx::colorToString( c ); - std::cout << " specular color: " << s.toStdString().c_str() << std::endl; - - // 12. ============= Steel - std::cout << "---- Steel:" << std::endl; - // ambient - c.setRgbF(0.2, 0.2, 0.2); - s = Qtx::colorToString( c ); - std::cout << " ambient color: " << s.toStdString().c_str() << std::endl; - // diffuse - c.setRgbF(0.0, 0.0, 0.0); - s = Qtx::colorToString( c ); - std::cout << " diffuse color: " << s.toStdString().c_str() << std::endl; - // specular - c.setRgbF(1.0, 1.0, 1.0); - s = Qtx::colorToString( c ); - std::cout << " specular color: " << s.toStdString().c_str() << std::endl; - - // 13. ============= Stone - std::cout << "---- Stone:" << std::endl; - // ambient - c.setRgbF(1.0, 0.8, 0.62); - s = Qtx::colorToString( c ); - std::cout << " ambient color: " << s.toStdString().c_str() << std::endl; - // diffuse - c.setRgbF(1.0, 0.8, 0.62); - s = Qtx::colorToString( c ); - std::cout << " diffuse color: " << s.toStdString().c_str() << std::endl; - // specular - c.setRgbF(0.98, 1.0, 0.60); - s = Qtx::colorToString( c ); - std::cout << " specular color: " << s.toStdString().c_str() << std::endl; - - // 14. ============= Chrome - std::cout << "---- Chrome:" << std::endl; - // ambient - c.setRgbF(0.35, 0.35, 0.35); - s = Qtx::colorToString( c ); - std::cout << " ambient color: " << s.toStdString().c_str() << std::endl; - // diffuse - c.setRgbF(0.4, 0.4, 0.4); - s = Qtx::colorToString( c ); - std::cout << " diffuse color: " << s.toStdString().c_str() << std::endl; - // specular - c.setRgbF(0.974597, 0.974597, 0.974597); - s = Qtx::colorToString( c ); - std::cout << " specular color: " << s.toStdString().c_str() << std::endl; - - // 15. ============= Neon - std::cout << "---- Neon:" << std::endl; - // ambient - c.setRgbF(1.0, 1.0, 1.0); - s = Qtx::colorToString( c ); - std::cout << " ambient color: " << s.toStdString().c_str() << std::endl; - // diffuse - c.setRgbF(1.0, 1.0, 1.0); - s = Qtx::colorToString( c ); - std::cout << " diffuse color: " << s.toStdString().c_str() << std::endl; - // specular - c.setRgbF(1.0, 1.0, 1.0); - s = Qtx::colorToString( c ); - std::cout << " specular color: " << s.toStdString().c_str() << std::endl; - // emissive - c.setRgbF(0.0, 1.0, 0.46); - s = Qtx::colorToString( c ); - std::cout << " emissive color: " << s.toStdString().c_str() << std::endl; - - // 16. ============= Aluminium - std::cout << "---- Aluminium:" << std::endl; - // ambient - c.setRgbF(0.30, 0.30, 0.30); - s = Qtx::colorToString( c ); - std::cout << " ambient color: " << s.toStdString().c_str() << std::endl; - // diffuse - c.setRgbF(0.30, 0.30, 0.30); - s = Qtx::colorToString( c ); - std::cout << " diffuse color: " << s.toStdString().c_str() << std::endl; - // specular - c.setRgbF(0.70, 0.70, 0.80); - s = Qtx::colorToString( c ); - std::cout << " specular color: " << s.toStdString().c_str() << std::endl; - - // 17. ============= Obsidian - std::cout << "---- Obsidian:" << std::endl; - // ambient - c.setRgbF(0.05375, 0.05, 0.06625); - s = Qtx::colorToString( c ); - std::cout << " ambient color: " << s.toStdString().c_str() << std::endl; - // diffuse - c.setRgbF(0.18275, 0.17, 0.22525); - s = Qtx::colorToString( c ); - std::cout << " diffuse color: " << s.toStdString().c_str() << std::endl; - // specular - c.setRgbF(0.332741, 0.328634, 0.346435); - s = Qtx::colorToString( c ); - std::cout << " specular color: " << s.toStdString().c_str() << std::endl; - - // 18. ============= Jade - std::cout << "---- Jade:" << std::endl; - // ambient - c.setRgbF(0.135, 0.2225, 0.1575); - s = Qtx::colorToString( c ); - std::cout << " ambient color: " << s.toStdString().c_str() << std::endl; - // diffuse - c.setRgbF(0.54, 0.89, 0.63); - s = Qtx::colorToString( c ); - std::cout << " diffuse color: " << s.toStdString().c_str() << std::endl; - // specular - c.setRgbF(0.316228, 0.316228, 0.316228); - s = Qtx::colorToString( c ); - std::cout << " specular color: " << s.toStdString().c_str() << std::endl; - - // 19. ============= Default material - std::cout << "---- Default material:" << std::endl; - // ambient - c.setRgbF(0.2, 0.2, 0.2); - s = Qtx::colorToString( c ); - std::cout << " ambient color: " << s.toStdString().c_str() << std::endl; - // diffuse - c.setRgbF(0.0, 0.0, 0.0); - s = Qtx::colorToString( c ); - std::cout << " diffuse color: " << s.toStdString().c_str() << std::endl; - // specular - c.setRgbF(1.0, 1.0, 1.0); - s = Qtx::colorToString( c ); - std::cout << " specular color: " << s.toStdString().c_str() << std::endl; - - // Get string equivalent for colors of global materials <---- - */ } /*! @@ -359,49 +63,54 @@ Material_ResourceMgr::~Material_ResourceMgr() */ QStringList Material_ResourceMgr::materials( MaterialType theType, bool theSort ) { - QStringList sl; - + // store original working mode WorkingMode m = workingMode(); + QStringList slglobal, sluser; + + // retrieve all materials : global + user + setWorkingMode( AllowUserValues ); + sluser = sections(); + + // retrieve only global materials + setWorkingMode( IgnoreUserValues ); + slglobal = sections(); + + // remove global materials from user list to obtain only user materials + QMutableListIterator it( sluser ); + while ( it.hasNext() ) { + QString s = it.next(); + if ( slglobal.contains( s ) ) it.remove(); + } + + // remove 'common' material + slglobal.removeAll("[common]"); + + // restore original working mode + setWorkingMode( m ); + + // sort if necessary (separately global and user materials) + if ( theSort ) { + qSort( slglobal ); + qSort( sluser ); + } + + // combine the materials to obtain result list + QStringList result; + switch ( theType ) { case Global: - setWorkingMode( IgnoreUserValues ); - sl = sections(); + result = slglobal; break; case User: - { - setWorkingMode( AllowUserValues ); - sl = sections(); - setWorkingMode( IgnoreUserValues ); - QMutableListIterator it( sl ); - while ( it.hasNext() ) { - QString s = it.next(); - if ( hasSection( s ) ) it.remove(); - } - } + result = sluser; break; case All: - setWorkingMode( AllowUserValues ); - sl = sections(); + result = slglobal + sluser; break; default: break; } - setWorkingMode( m ); - - if ( theSort ) - qSort( sl ); - - return sl; -} - -/*! - \brief Get list of materials names for preferences dialog - \return list of materials names -*/ -QStringList Material_ResourceMgr::getPreferenceMaterialsNames() -{ - QStringList aMaterialsList = materials( Material_ResourceMgr::All ); - return aMaterialsList; + return result; } diff --git a/src/Material/Material_ResourceMgr.h b/src/Material/Material_ResourceMgr.h index 769b74d34..a98a531d7 100644 --- a/src/Material/Material_ResourceMgr.h +++ b/src/Material/Material_ResourceMgr.h @@ -41,8 +41,6 @@ public: ~Material_ResourceMgr(); QStringList materials( MaterialType = All, bool = true ); - - QStringList getPreferenceMaterialsNames(); }; -- 2.39.2