"0021179: EDF 1654 SMESH GEOM: better look'n'feel" issue.

Material Properties.
This commit is contained in:
ana 2012-05-03 14:15:15 +00:00
parent 956e89f015
commit 8ad1208104
6 changed files with 555 additions and 996 deletions

View File

@ -454,7 +454,6 @@ void GEOMToolsGUI_MaterialPropertiesDlg::onApply()
SUIT_OverrideCursor wc(); SUIT_OverrideCursor wc();
printf("material prop:%s\n", qPrintable(prop));
for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) { for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
Handle(GEOM_AISShape) aisShape = GEOMBase::ConvertIOinGEOMAISShape( It.Value(), true ); Handle(GEOM_AISShape) aisShape = GEOMBase::ConvertIOinGEOMAISShape( It.Value(), true );
if ( !aisShape.IsNull() ) { if ( !aisShape.IsNull() ) {

View File

@ -25,38 +25,25 @@
#include "GEOM_ToolsGUI.hxx" #include "GEOM_ToolsGUI.hxx"
#include <QListWidget>
#include <QtxDialog.h> #include <QtxDialog.h>
#include <QFrame> #include "Material_Model.h"
#include <QMap> #include "Material_ResourceMgr.h"
class QCheckBox; class QCheckBox;
class QGroupBox;
class QLabel; class QLabel;
class QListWidget;
class QListWidgetItem;
class QPushButton; class QPushButton;
class QSpinBox; class QSlider;
class QTabWidget;
class QtxColorButton; class QtxColorButton;
class QtxDoubleSpinBox; class GEOMToolsGUI_MaterialList;
class Material_Model;
class Material_ResourceMgr;
class GEOMTOOLSGUI_EXPORT GEOMToolsGUI_MaterialPropertiesDlg : public QtxDialog class GEOMTOOLSGUI_EXPORT GEOMToolsGUI_MaterialPropertiesDlg : public QtxDialog
{ {
Q_OBJECT Q_OBJECT
enum { Current, Default, Global, User }; enum { Current, Global, User };
enum { TypeRole = Qt::UserRole + 123, NameRole }; enum { TypeRole = Qt::UserRole + 123, NameRole };
//! Enumeration of viewer types
typedef enum {
OCC, //!< OCC viewer
VTK //!< VTK viewer
} ViewerType;
public: public:
GEOMToolsGUI_MaterialPropertiesDlg( QWidget* = 0 ); GEOMToolsGUI_MaterialPropertiesDlg( QWidget* = 0 );
~GEOMToolsGUI_MaterialPropertiesDlg(); ~GEOMToolsGUI_MaterialPropertiesDlg();
@ -66,66 +53,56 @@ public:
bool eventFilter( QObject*, QEvent* ); bool eventFilter( QObject*, QEvent* );
private: private:
Material_ResourceMgr* resourceMgr(); void updateState();
void toModel( Material_Model& ) const;
void fromModel( Material_Model* ); void fromModel( const Material_Model& );
void toModel( Material_Model* ) const;
QString findUniqueName( const QString&, QString findUniqueName( const QString&,
QListWidgetItem* = 0, QListWidgetItem* = 0,
bool = false ); bool = false );
signals: signals:
void materialChanged();
void changed(); void changed();
private slots: private slots:
void onChanged();
void onMaterialChanged();
void onItemChanged( QListWidgetItem* );
void onContextMenu( QContextMenuEvent* );
void onDeleteMaterial();
void onAddMaterial();
void onApply(); void onApply();
void onHelp(); void onHelp();
void onMaterialChanged();
void onChanged();
void onItemChanged( QListWidgetItem* );
void onReflectionTypeToggled( bool );
private: private:
typedef struct
{
QLabel* label;
QtxColorButton* color;
QSlider* coef;
QCheckBox* enabled;
} Reflection;
Material_ResourceMgr* myResMgr; GEOMToolsGUI_MaterialList* myMaterials;
QCheckBox* myPhysical;
QCheckBox* myMaterialPhysicalCheck; QList<Reflection> myReflection;
QSlider* myShininess;
//! Current material model for material QLabel* myColorLab;
Material_Model* myCurrentModelF; QtxColorButton* myColor;
QPushButton* myAddButton;
QListWidget* myMaterialList; QPushButton* myDelButton;
int myMaterialListFId; Material_ResourceMgr myResourceMgr;
Material_Model myCurrentModel;
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;
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 #endif // GEOMTOOLSGUI_MATERIALPROPERTIESDLG_H

File diff suppressed because it is too large Load Diff

View File

@ -28,86 +28,69 @@
#include <QColor> #include <QColor>
#include <QMap> #include <QMap>
#include <QString> #include <QString>
#include <QVector>
class Graphic3d_MaterialAspect; #include <Graphic3d_MaterialAspect.hxx>
class GEOM_VTKPropertyMaterial;
class QtxResourceMgr; class QtxResourceMgr;
class GEOM_VTKPropertyMaterial;
class MATERIAL_SALOME_EXPORT Material_Model class MATERIAL_SALOME_EXPORT Material_Model
{ {
public: public:
//! Reflection type
//! Enumeration of reflection types of material
typedef enum { typedef enum {
Ambient, //!< Ambient Ambient, //!< Ambient
Diffuse, //!< Diffuse Diffuse, //!< Diffuse
Specular, //!< Specular Specular, //!< Specular
Emission //!< Emission Emissive //!< Emissive
} ReflectionType; } ReflectionType;
Material_Model(); Material_Model();
virtual ~Material_Model(); virtual ~Material_Model();
static Material_Model* getMaterialModel( QStringList ); void fromProperties( const QString& );
QString toProperties();
QString getMaterialProperty(); void fromResources( const QString& = QString(), QtxResourceMgr* = 0 );
void toResources( const QString&, QtxResourceMgr* );
Graphic3d_MaterialAspect getMaterialOCCAspect();
GEOM_VTKPropertyMaterial* getMaterialVTKProperty();
void initDefaults();
void fromResources( QtxResourceMgr*, const QString& = QString());
void save( QtxResourceMgr* = 0, const QString& = QString() );
QtxResourceMgr* resourceMgr() const;
QString resourceSection() const;
bool hasAmbientReflection();
bool hasDiffuseReflection();
bool hasSpecularReflection();
bool hasEmissionReflection();
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 shininess() const;
void setShininess( double );
bool isPhysical() const; bool isPhysical() const;
void setPhysical( bool ); void setPhysical( bool );
private: bool hasReflection( ReflectionType ) const;
void clearModel(); void setReflection( ReflectionType, bool );
QColor color( ReflectionType ) const;
void setColor( ReflectionType, const QColor& );
double reflection( ReflectionType ) const;
void setReflection( ReflectionType, double );
double shininess() const;
void setShininess( double );
double transparency() const;
void setTransparency( double );
Graphic3d_MaterialAspect getMaterialOCCAspect();
GEOM_VTKPropertyMaterial* getMaterialVTKProperty();
private: private:
typedef QMap<ReflectionType, QColor> ColorMap; void init();
typedef QMap<ReflectionType, double> CoefficientMap;
QtxResourceMgr* myResourceMgr; private:
QString myResourceSection; typedef struct {
QColor color;
double coef;
bool enabled;
} ReflectionData;
ColorMap myColors; typedef QVector<ReflectionData> ReflectionList;
CoefficientMap myCoefficients;
double myShininess;
bool myIsPhysical; bool myIsPhysical;
double myShininess;
double myTransparency;
ReflectionList myReflection;
}; };
#endif // MATERIAL_MODEL_H #endif // MATERIAL_MODEL_H

View File

@ -19,11 +19,8 @@
// File : Material_ResourceMgr.cxx // File : Material_ResourceMgr.cxx
// Author : Margarita KARPUNINA, Open CASCADE S.A.S. (margarita.karpunina@opencascade.com) // 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 "Material_ResourceMgr.h"
//#include <iostream> // used to print colors of global materials
/*! /*!
\class Material_ResourceMgr \class Material_ResourceMgr
@ -49,299 +46,6 @@ Material_ResourceMgr::Material_ResourceMgr()
if ( dirList().isEmpty() && ::getenv( "GEOM_ROOT_DIR" ) ) if ( dirList().isEmpty() && ::getenv( "GEOM_ROOT_DIR" ) )
setDirList( QStringList() << Qtx::addSlash( ::getenv( "GEOM_ROOT_DIR" ) ) + "share/salome/resources/geom" ); setDirList( QStringList() << Qtx::addSlash( ::getenv( "GEOM_ROOT_DIR" ) ) + "share/salome/resources/geom" );
setCurrentFormat( "xml" ); 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 Material_ResourceMgr::materials( MaterialType theType, bool theSort )
{ {
QStringList sl; // store original working mode
WorkingMode m = workingMode(); 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<QString> 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 ) { switch ( theType ) {
case Global: case Global:
setWorkingMode( IgnoreUserValues ); result = slglobal;
sl = sections();
break; break;
case User: case User:
{ result = sluser;
setWorkingMode( AllowUserValues );
sl = sections();
setWorkingMode( IgnoreUserValues );
QMutableListIterator<QString> it( sl );
while ( it.hasNext() ) {
QString s = it.next();
if ( hasSection( s ) ) it.remove();
}
}
break; break;
case All: case All:
setWorkingMode( AllowUserValues ); result = slglobal + sluser;
sl = sections();
break; break;
default: default:
break; break;
} }
setWorkingMode( m ); return result;
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;
} }

View File

@ -42,8 +42,6 @@ public:
QStringList materials( MaterialType = All, bool = true ); QStringList materials( MaterialType = All, bool = true );
QStringList getPreferenceMaterialsNames();
}; };
#endif // MATERIAL_RESOURCEMGR_H #endif // MATERIAL_RESOURCEMGR_H