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

Material Properties.
This commit is contained in:
ana 2012-05-03 14:09:12 +00:00
parent 29505882a3
commit 956e89f015
7 changed files with 527 additions and 723 deletions

View File

@ -569,8 +569,9 @@ bool GEOMGUI_Selection::isPhysicalMaterial( const int idx ) const{
bool found = false; bool found = false;
QVariant v = visibleProperty( entry( idx ), MATERIAL_PROP ); QVariant v = visibleProperty( entry( idx ), MATERIAL_PROP );
if ( v.canConvert<QString>() ) { if ( v.canConvert<QString>() ) {
Material_Model* aModel = Material_Model::getMaterialModel( v.toString().split(DIGIT_SEPARATOR) ); Material_Model material;
res = aModel->isPhysical(); material.fromProperties( v.toString() );
res = material.isPhysical();
found = true; found = true;
} }

View File

@ -961,31 +961,20 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
} }
// get material properties, set material // get material properties, set material
Material_Model* aModelF = 0; Material_Model material;
if ( useStudy ) { if ( useStudy ) {
// Get material property from study and construct material model // Get material property from study and construct material model
QString aMaterialF = aPropMap.value(MATERIAL_PROP).toString(); material.fromProperties( aPropMap.value(MATERIAL_PROP).toString() );
QStringList aProps = aMaterialF.split(DIGIT_SEPARATOR);
aModelF = Material_Model::getMaterialModel( aProps );
} else { } else {
// Get material property from study and construct material model // Get material property from study and construct material model
aModelF = new Material_Model(); QString mname = aResMgr->stringValue( "Geometry", "material", "Plastic" );
aModelF->fromResources( aResMgr, "Geometry" ); material.fromResources( mname );
} }
// Set material property aStudy->setObjectProperty( aMgrId, anIO->getEntry(), MATERIAL_PROP, material.toProperties() );
QString aMaterialPropF = aModelF->getMaterialProperty();
aStudy->setObjectProperty( aMgrId, anIO->getEntry(), MATERIAL_PROP, aMaterialPropF );
// Get material properties from the model
Graphic3d_MaterialAspect aMatF = aModelF->getMaterialOCCAspect();
// Set material for the selected shape // Set material for the selected shape
AISShape->SetMaterial(aMatF); AISShape->SetMaterial( material.getMaterialOCCAspect() );
// Release memory
if ( aModelF )
delete aModelF;
if(HasWidth()) if(HasWidth())
aStudy->setObjectProperty( aMgrId, anIO->getEntry(), EDGE_WIDTH_PROP, GetWidth() ); aStudy->setObjectProperty( aMgrId, anIO->getEntry(), EDGE_WIDTH_PROP, GetWidth() );
@ -1174,24 +1163,16 @@ void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
aGeomGActor->setDisplayMode(aDispModeId); aGeomGActor->setDisplayMode(aDispModeId);
aGeomGActor->SetDeflection(aPropMap.value(DEFLECTION_COEFF_PROP).toDouble()); aGeomGActor->SetDeflection(aPropMap.value(DEFLECTION_COEFF_PROP).toDouble());
// Get material property of the object stored in the study
QString aMaterialF = aPropMap.value(MATERIAL_PROP).toString();
QStringList aPropsF = aMaterialF.split(DIGIT_SEPARATOR);
// Create material model // Create material model
Material_Model* aModelF = Material_Model::getMaterialModel( aPropsF ); Material_Model material;
material.fromProperties( aPropMap.value(MATERIAL_PROP).toString() );
// Set material properties for the object // Set material properties for the object
QString aMaterialPropF = aModelF->getMaterialProperty(); aStudy->setObjectProperty( aMgrId, anEntry, MATERIAL_PROP, material.toProperties() );
aStudy->setObjectProperty( aMgrId, anEntry, MATERIAL_PROP, aMaterialPropF );
// Get material properties from the model
GEOM_VTKPropertyMaterial* aMatPropF = aModelF->getMaterialVTKProperty();
// Set the same front and back materials for the selected shape // Set the same front and back materials for the selected shape
std::vector<vtkProperty*> aProps; std::vector<vtkProperty*> aProps;
aProps.push_back( (vtkProperty*) aMatPropF ); aProps.push_back( material.getMaterialVTKProperty() );
aGeomGActor->SetMaterial(aProps); aGeomGActor->SetMaterial(aProps);
// Release memory
delete aModelF;
vtkFloatingPointType aColor[3] = {1.,0.,0.}; vtkFloatingPointType aColor[3] = {1.,0.,0.};
if(aPropMap.contains(COLOR_PROP)) { if(aPropMap.contains(COLOR_PROP)) {
QColor c = aPropMap.value(COLOR_PROP).value<QColor>(); QColor c = aPropMap.value(COLOR_PROP).value<QColor>();
@ -1222,26 +1203,24 @@ void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
} }
} }
} }
if ( !aMatPropF->GetPhysical() ) if ( !material.isPhysical() )
aGeomGActor->SetColor(aColor[0],aColor[1],aColor[2]); aGeomGActor->SetColor(aColor[0],aColor[1],aColor[2]);
} }
else { else {
SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
if ( aResMgr ) { if ( aResMgr ) {
// Create material model // Create material model
Material_Model aModelF; Material_Model material;
// Get material name from resources // Get material name from resources
aModelF.fromResources( aResMgr, "Geometry" ); QString mname = aResMgr->stringValue( "Geometry", "material", "Plastic" );
material.fromResources( mname );
// Set material properties for the object // Set material properties for the object
QString aMaterialPropF = aModelF.getMaterialProperty(); aStudy->setObjectProperty( aMgrId, anEntry, MATERIAL_PROP, material.toProperties() );
aStudy->setObjectProperty( aMgrId, anEntry, MATERIAL_PROP, aMaterialPropF );
// Get material properties from the model
GEOM_VTKPropertyMaterial* aMatPropF = aModelF.getMaterialVTKProperty();
// Set material for the selected shape // Set material for the selected shape
std::vector<vtkProperty*> aProps; std::vector<vtkProperty*> aProps;
aProps.push_back( (vtkProperty*) aMatPropF ); aProps.push_back( material.getMaterialVTKProperty() );
aGeomGActor->SetMaterial(aProps); } aGeomGActor->SetMaterial(aProps);
}
} }
} }
@ -1935,10 +1914,10 @@ PropMap GEOM_Displayer::getDefaultPropertyMap(const QString& viewer_type) {
aDefaultMap.insert( DEFLECTION_COEFF_PROP , aDC); aDefaultMap.insert( DEFLECTION_COEFF_PROP , aDC);
//8. Material //8. Material
Material_Model aModelF; Material_Model material;
aModelF.fromResources( aResMgr, "Geometry" ); QString mname = aResMgr->stringValue( "Geometry", "material", "Plastic" );
QString aMaterialF = aModelF.getMaterialProperty(); material.fromResources( mname );
aDefaultMap.insert( MATERIAL_PROP , aMaterialF ); aDefaultMap.insert( MATERIAL_PROP, material.toProperties() );
//9. Width of the edges //9. Width of the edges
aDefaultMap.insert( EDGE_WIDTH_PROP , aResMgr->integerValue("Geometry", "edge_width", 1)); aDefaultMap.insert( EDGE_WIDTH_PROP , aResMgr->integerValue("Geometry", "edge_width", 1));

View File

@ -5228,35 +5228,27 @@ Would you like to continue?</translation>
<name>GEOMToolsGUI_MaterialPropertiesDlg</name> <name>GEOMToolsGUI_MaterialPropertiesDlg</name>
<message> <message>
<source>MATERIAL_PROPERTIES_TLT</source> <source>MATERIAL_PROPERTIES_TLT</source>
<translation>Set Material Properties</translation> <translation>Color and Material Properties</translation>
</message> </message>
<message> <message>
<source>MATERIAL_BACK_CHK</source> <source>REFLECTION_0</source>
<translation>Enable back material</translation>
</message>
<message>
<source>AMBIENT_GRP</source>
<translation>Ambient</translation> <translation>Ambient</translation>
</message> </message>
<message> <message>
<source>DIFFUSE_GRP</source> <source>REFLECTION_1</source>
<translation>Diffuse</translation> <translation>Diffuse</translation>
</message> </message>
<message> <message>
<source>SPECULAR_GRP</source> <source>REFLECTION_2</source>
<translation>Specular</translation> <translation>Specular</translation>
</message> </message>
<message> <message>
<source>EMISSION_GRP</source> <source>REFLECTION_3</source>
<translation>Emission</translation> <translation>Emissive</translation>
</message> </message>
<message> <message>
<source>COLOR</source> <source>ENABLED</source>
<translation>Color:</translation> <translation>Enabled</translation>
</message>
<message>
<source>COEFFICIENT</source>
<translation>Coefficient:</translation>
</message> </message>
<message> <message>
<source>SHININESS</source> <source>SHININESS</source>
@ -5264,12 +5256,41 @@ Would you like to continue?</translation>
</message> </message>
<message> <message>
<source>PHYSICAL</source> <source>PHYSICAL</source>
<translation>Physical:</translation> <translation>Physical</translation>
</message>
<message>
<source>ADD_MATERIAL</source>
<translation>Add Material</translation>
</message>
<message>
<source>DELETE_MATERIAL</source>
<translation>Remove material</translation>
</message>
<message>
<source>RENAME_MATERIAL</source>
<translation>Rename material</translation>
</message>
<message>
<source>CURRENT_MATERIAL</source>
<translation>[ Current ]</translation>
</message>
<message>
<source>CURRENT_COLOR</source>
<translation>Color</translation>
</message> </message>
<message> <message>
<source>CUSTOM_MATERIAL</source> <source>CUSTOM_MATERIAL</source>
<translation>Custom material</translation> <translation>Custom material</translation>
</message> </message>
<message>
<source>QUE_CREATE_NEW_MATERIAL</source>
<translation>Changing properties of pre-defined material is not allowed.
Do you want to create new material?</translation>
</message>
<message>
<source>QUE_REMOVE_MATERIAL</source>
<translation>Remove material %1?</translation>
</message>
<message> <message>
<source>OK_BTN</source> <source>OK_BTN</source>
<translation>&amp;OK</translation> <translation>&amp;OK</translation>

View File

@ -5228,47 +5228,68 @@ Voulez-vous continuer?</translation>
<name>GEOMToolsGUI_MaterialPropertiesDlg</name> <name>GEOMToolsGUI_MaterialPropertiesDlg</name>
<message> <message>
<source>MATERIAL_PROPERTIES_TLT</source> <source>MATERIAL_PROPERTIES_TLT</source>
<translation>Définir une propriétés des matériaux</translation> <translation>Color and Material Properties</translation>
</message> </message>
<message> <message>
<source>MATERIAL_BACK_CHK</source> <source>REFLECTION_0</source>
<translation>Activer l&apos;arrière du matériau</translation> <translation>Ambient</translation>
</message> </message>
<message> <message>
<source>AMBIENT_GRP</source> <source>REFLECTION_1</source>
<translation>Ambiante</translation>
</message>
<message>
<source>DIFFUSE_GRP</source>
<translation>Diffuse</translation> <translation>Diffuse</translation>
</message> </message>
<message> <message>
<source>SPECULAR_GRP</source> <source>REFLECTION_2</source>
<translation>Spéculaire</translation> <translation>Specular</translation>
</message> </message>
<message> <message>
<source>EMISSION_GRP</source> <source>REFLECTION_3</source>
<translation>Emission</translation> <translation>Emissive</translation>
</message> </message>
<message> <message>
<source>COLOR</source> <source>ENABLED</source>
<translation>Couleurs:</translation> <translation>Enabled</translation>
</message>
<message>
<source>COEFFICIENT</source>
<translation>Coefficient:</translation>
</message> </message>
<message> <message>
<source>SHININESS</source> <source>SHININESS</source>
<translation>Brillance:</translation> <translation>Shininess:</translation>
</message> </message>
<message> <message>
<source>PHYSICAL</source> <source>PHYSICAL</source>
<translation>Matériau physique (couleur imposée):</translation> <translation>Physical</translation>
</message>
<message>
<source>ADD_MATERIAL</source>
<translation>Add Material</translation>
</message>
<message>
<source>DELETE_MATERIAL</source>
<translation>Remove material</translation>
</message>
<message>
<source>RENAME_MATERIAL</source>
<translation>Rename material</translation>
</message>
<message>
<source>CURRENT_MATERIAL</source>
<translation>[ Current ]</translation>
</message>
<message>
<source>CURRENT_COLOR</source>
<translation>Color</translation>
</message> </message>
<message> <message>
<source>CUSTOM_MATERIAL</source> <source>CUSTOM_MATERIAL</source>
<translation>Matériau personnalisé</translation> <translation>Custom material</translation>
</message>
<message>
<source>QUE_CREATE_NEW_MATERIAL</source>
<translation>Changing properties of pre-defined material is not allowed.
Do you want to create new material?</translation>
</message>
<message>
<source>QUE_REMOVE_MATERIAL</source>
<translation>Remove material %1?</translation>
</message> </message>
<message> <message>
<source>OK_BTN</source> <source>OK_BTN</source>

View File

@ -592,10 +592,9 @@ void GeometryGUI::OnGUIEvent( int id )
LightApp_Preferences* pref = preferences(); LightApp_Preferences* pref = preferences();
if ( pref ) { if ( pref ) {
Material_ResourceMgr aMatResMgr; Material_ResourceMgr aMatResMgr;
QStringList aPerfMatNames = aMatResMgr.getPreferenceMaterialsNames();
setPreferenceProperty( pref->rootItem()->findItem( tr( "PREF_MATERIAL" ), true )->id(), setPreferenceProperty( pref->rootItem()->findItem( tr( "PREF_MATERIAL" ), true )->id(),
"strings", "strings",
aPerfMatNames ); aMatResMgr.materials() );
} }
} }
} }
@ -1814,8 +1813,7 @@ void GeometryGUI::createPreferences()
// Set property for default material // Set property for default material
Material_ResourceMgr aMatResMgr; Material_ResourceMgr aMatResMgr;
QStringList aPrefMatNames = aMatResMgr.getPreferenceMaterialsNames(); setPreferenceProperty( material, "strings", aMatResMgr.materials() );
setPreferenceProperty( material, "strings", aPrefMatNames );
// Set property vertex marker type // Set property vertex marker type
QList<QVariant> aMarkerTypeIndicesList; QList<QVariant> aMarkerTypeIndicesList;

View File

@ -294,18 +294,11 @@ void GEOMToolsGUI::OnColor()
if ( c.isValid() ) { if ( c.isValid() ) {
SUIT_OverrideCursor(); SUIT_OverrideCursor();
for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) { for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
QString defMatProp; QString matProp;
QVariant mp = appStudy->getObjectProperty(mgrId,It.Value()->getEntry(), MATERIAL_PROP, defMatProp); matProp = appStudy->getObjectProperty(mgrId,It.Value()->getEntry(), MATERIAL_PROP, matProp).toString();
QString matProp = mp.value<QString>(); Material_Model material;
QStringList aProps = matProp.split(DIGIT_SEPARATOR); material.fromProperties( matProp );
Material_Model* aModelF = Material_Model::getMaterialModel( aProps ); if ( !material.isPhysical() ) {
bool aPhys = false;
if ( aModelF ) {
aPhys = aModelF->isPhysical();
// Release memory
delete aModelF;
}
if ( !aPhys ) {
aView->SetColor( It.Value(), c ); aView->SetColor( It.Value(), c );
appStudy->setObjectProperty(mgrId,It.Value()->getEntry(),COLOR_PROP, c); appStudy->setObjectProperty(mgrId,It.Value()->getEntry(),COLOR_PROP, c);
} }
@ -332,19 +325,12 @@ void GEOMToolsGUI::OnColor()
OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*> ( window->getViewManager()->getViewModel() ); OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*> ( window->getViewManager()->getViewModel() );
Handle (AIS_InteractiveContext) ic = vm->getAISContext(); Handle (AIS_InteractiveContext) ic = vm->getAISContext();
for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) { for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
QString defMatProp; QString matProp;
QVariant mp = appStudy->getObjectProperty(mgrId,It.Value()->getEntry(), MATERIAL_PROP, defMatProp); matProp = appStudy->getObjectProperty(mgrId,It.Value()->getEntry(), MATERIAL_PROP, matProp).toString();
QString matProp = mp.value<QString>(); Material_Model material;
QStringList aProps = matProp.split(DIGIT_SEPARATOR); material.fromProperties( matProp );
Material_Model* aModelF = Material_Model::getMaterialModel( aProps );
bool aPhys = false;
if ( aModelF ) {
aPhys = aModelF->isPhysical();
// Release memory
delete aModelF;
}
io = GEOMBase::GetAIS( It.Value(), true ); io = GEOMBase::GetAIS( It.Value(), true );
if ( !io.IsNull() && !aPhys ) { // change color only for shapes with not physical type of material if ( !io.IsNull() && !material.isPhysical() ) { // change color only for shapes with not physical type of material
if ( io->IsKind( STANDARD_TYPE(AIS_Shape) ) ) { if ( io->IsKind( STANDARD_TYPE(AIS_Shape) ) ) {
TopoDS_Shape theShape = Handle(AIS_Shape)::DownCast( io )->Shape(); TopoDS_Shape theShape = Handle(AIS_Shape)::DownCast( io )->Shape();

File diff suppressed because it is too large Load Diff