From 2e342cb5f38238bd273ed03eabd723f9f6913196 Mon Sep 17 00:00:00 2001 From: ana Date: Fri, 13 Apr 2012 11:09:23 +0000 Subject: [PATCH] Fix for the "0021179: EDF 1654 SMESH GEOM: better look'n'feel" issue: - Material Properties --- resources/SalomeApp.xml.in | 3 +- src/GEOMGUI/GEOMGUI_Selection.cxx | 67 +- src/GEOMGUI/GEOMGUI_Selection.h | 1 + src/GEOMGUI/GEOM_Displayer.cxx | 181 ++---- src/GEOMGUI/GEOM_msg_en.ts | 12 +- src/GEOMGUI/GEOM_msg_fr.ts | 4 + src/GEOMGUI/GeometryGUI.cxx | 36 +- src/GEOMToolsGUI/GEOMToolsGUI_1.cxx | 49 +- .../GEOMToolsGUI_MaterialPropertiesDlg.cxx | 571 +++--------------- .../GEOMToolsGUI_MaterialPropertiesDlg.h | 37 +- src/Material/Makefile.am | 1 + src/Material/Material_Model.cxx | 96 ++- src/Material/Material_Model.h | 23 +- src/Material/resources/SalomeMaterial.xml | 18 + src/OBJECT/GEOM_Actor.cxx | 53 +- src/OBJECT/GEOM_Actor.h | 4 +- src/OBJECT/GEOM_Constants.h | 3 +- src/OBJECT/GEOM_DeviceActor.cxx | 14 - src/OBJECT/GEOM_DeviceActor.h | 3 - src/OBJECT/GEOM_VTKPropertyMaterial.cxx | 39 ++ src/OBJECT/GEOM_VTKPropertyMaterial.hxx | 52 ++ src/OBJECT/Makefile.am | 2 + 22 files changed, 469 insertions(+), 800 deletions(-) create mode 100755 src/OBJECT/GEOM_VTKPropertyMaterial.cxx create mode 100755 src/OBJECT/GEOM_VTKPropertyMaterial.hxx diff --git a/resources/SalomeApp.xml.in b/resources/SalomeApp.xml.in index 5aec2f60f..058d0ebd6 100644 --- a/resources/SalomeApp.xml.in +++ b/resources/SalomeApp.xml.in @@ -56,8 +56,7 @@ - - + diff --git a/src/GEOMGUI/GEOMGUI_Selection.cxx b/src/GEOMGUI/GEOMGUI_Selection.cxx index ac9db21f1..ac9ce2b42 100644 --- a/src/GEOMGUI/GEOMGUI_Selection.cxx +++ b/src/GEOMGUI/GEOMGUI_Selection.cxx @@ -28,6 +28,8 @@ #include "GeometryGUI.h" #include "GEOM_Displayer.h" +#include "Material_Model.h" + #include #include @@ -54,11 +56,16 @@ #include #include +#include // OCCT Includes #include #include #include +#include +#include +#include +#include // VTK Includes #include @@ -159,6 +166,8 @@ QVariant GEOMGUI_Selection::parameter( const int idx, const QString& p ) const v = compoundOfVertices( idx ); else if ( p == "imported" ) v = isImported( idx ); + else if ( p == "isPhysicalMaterial" ) + v = isPhysicalMaterial(idx); else v = LightApp_Selection::parameter( idx, p ); @@ -313,7 +322,7 @@ QString GEOMGUI_Selection::displayMode( const int index ) const } } } - else if ( viewType == SVTK_Viewer::Type() ) { // assuming VTK + else if ( viewType == SVTK_Viewer::Type() ) { // assuming VTK SVTK_Prs* vtkPrs = dynamic_cast( prs ); vtkActorCollection* lst = vtkPrs ? vtkPrs->GetObjects() : 0; if ( lst ) { @@ -517,7 +526,7 @@ QString GEOMGUI_Selection::selectionMode() const bool GEOMGUI_Selection::topLevel( const int index ) const { bool res = false; - + #ifdef USE_VISUAL_PROP_MAP bool found = false; QVariant v = visibleProperty( entry( index ), TOP_LEVEL_PROP ); @@ -551,3 +560,57 @@ bool GEOMGUI_Selection::topLevel( const int index ) const { } return res; } + +bool GEOMGUI_Selection::isPhysicalMaterial( const int idx ) const{ + bool res = false; + +#ifdef USE_VISUAL_PROP_MAP + bool found = false; + QVariant v = visibleProperty( entry( idx ), MATERIAL_PROP ); + if ( v.canConvert() ) { + Material_Model* aModel = Material_Model::getMaterialModel( v.toString().split(DIGIT_SEPARATOR) ); + res = aModel->isPhysical(); + found = true; + } + + if ( !found ) { +#endif + SALOME_View* view = GEOM_Displayer::GetActiveView(); + QString viewType = activeViewType(); + if ( view ) { + SALOME_Prs* prs = view->CreatePrs( entry( idx ).toLatin1().constData() ); + if ( prs ) { + if ( viewType == OCCViewer_Viewer::Type() ) { // assuming OCC + SOCC_Prs* occPrs = (SOCC_Prs*) prs; + AIS_ListOfInteractive lst; + occPrs->GetObjects( lst ); + if ( lst.Extent() ) { + Handle(AIS_InteractiveObject) io = lst.First(); + if ( !io.IsNull() ) { + Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(io); + if ( !aSh.IsNull() ) + res =(bool) aSh->Attributes()->ShadingAspect()-> + Material(Aspect_TypeOfFacingModel::Aspect_TOFM_BOTH_SIDE).MaterialType( Graphic3d_MATERIAL_PHYSIC ); + } + } + } + else if ( viewType == SVTK_Viewer::Type() ) { // assuming VTK + SVTK_Prs* vtkPrs = dynamic_cast( prs ); + vtkActorCollection* lst = vtkPrs ? vtkPrs->GetObjects() : 0; + if ( lst ) { + lst->InitTraversal(); + vtkActor* actor = lst->GetNextActor(); + if ( actor ) { + GEOM_Actor* aGeomGActor = GEOM_Actor::SafeDownCast( actor ); + if ( aGeomGActor ) { + GEOM_VTKPropertyMaterial* mat = GEOM_VTKPropertyMaterial::SafeDownCast(aGeomGActor->GetProperty()); + res = mat->GetPhysical(); + } // if ( salome actor ) + } // if ( actor ) + } // if ( lst == vtkPrs->GetObjects() ) + } + } + } + } + return res; +} diff --git a/src/GEOMGUI/GEOMGUI_Selection.h b/src/GEOMGUI/GEOMGUI_Selection.h index 93f243bdd..c6e9b59da 100644 --- a/src/GEOMGUI/GEOMGUI_Selection.h +++ b/src/GEOMGUI/GEOMGUI_Selection.h @@ -70,6 +70,7 @@ private: bool hasShownChildren( const int ) const; bool compoundOfVertices( const int ) const; bool topLevel( const int ) const; + bool isPhysicalMaterial( const int ) const; bool isComponent( const int ) const; GEOM::GEOM_Object_ptr getObject( const int ) const; diff --git a/src/GEOMGUI/GEOM_Displayer.cxx b/src/GEOMGUI/GEOM_Displayer.cxx index a6abae6f5..b4f7abfe7 100644 --- a/src/GEOMGUI/GEOM_Displayer.cxx +++ b/src/GEOMGUI/GEOM_Displayer.cxx @@ -42,6 +42,7 @@ #include #include #include +#include #include @@ -810,7 +811,7 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs ) anAspect = AISShape->Attributes()->UnFreeBoundaryAspect(); anAspect->SetColor( aColor ); AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect ); - AISShape->storeBoundaryColors(); + AISShape->storeBoundaryColors(); // Set free boundaries aspect col = aResMgr->colorValue( "Geometry", "free_bound_color", QColor( 0, 255, 0 ) ); @@ -828,10 +829,10 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs ) anAspect->SetColor( aColor ); AISShape->Attributes()->SetWireAspect( anAspect ); - // Set color for edges in shading - col = aResMgr->colorValue( "Geometry", "edges_in_shading_color", QColor( 255, 255, 0 ) ); - aColor = SalomeApp_Tools::color( col ); - AISShape->SetEdgesInShadingColor( aColor ); + // Set color for edges in shading + col = aResMgr->colorValue( "Geometry", "edges_in_shading_color", QColor( 255, 255, 0 ) ); + aColor = SalomeApp_Tools::color( col ); + AISShape->SetEdgesInShadingColor( aColor ); // bug [SALOME platform 0019868] // Set deviation angle. Default one is 12 degrees (Prs3d_Drawer.cxx:18) @@ -841,8 +842,8 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs ) double aDC = 0; if(useStudy) { aDC = aPropMap.value(DEFLECTION_COEFF_PROP).toDouble(); - SetWidth(aPropMap.value(EDGE_WIDTH_PROP).toInt()); - SetIsosWidth(aPropMap.value(ISOS_WIDTH_PROP).toInt()); + SetWidth(aPropMap.value(EDGE_WIDTH_PROP).toInt()); + SetIsosWidth(aPropMap.value(ISOS_WIDTH_PROP).toInt()); } else { aDC = aResMgr->doubleValue("Geometry", "deflection_coeff", 0.001); @@ -961,62 +962,30 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs ) // get material properties, set material Material_Model* aModelF = 0; - Material_Model* aModelB = 0; if ( useStudy ) { - // Get front material property from study and construct front material model - QString aMaterialF = aPropMap.value(FRONT_MATERIAL_PROP).toString(); + // Get material property from study and construct material model + QString aMaterialF = aPropMap.value(MATERIAL_PROP).toString(); QStringList aProps = aMaterialF.split(DIGIT_SEPARATOR); aModelF = Material_Model::getMaterialModel( aProps ); - - // Get back material property from study and construct back material model - QString aMaterialB = aPropMap.value(BACK_MATERIAL_PROP).toString(); - if ( !aMaterialB.isEmpty() ) { - QStringList aPropsB = aMaterialB.split(DIGIT_SEPARATOR); - aModelB = Material_Model::getMaterialModel( aPropsB ); - } - else - aModelB = aModelF; - } else { - // Get front material property from study and construct front material model + // Get material property from study and construct material model aModelF = new Material_Model(); - aModelF->fromResources( aResMgr, "Geometry", true ); - - // Get back material property from study and construct back material model - aModelB = new Material_Model(); - aModelB->fromResources( aResMgr, "Geometry", false ); + aModelF->fromResources( aResMgr, "Geometry" ); } - // Set front material property + // Set material property QString aMaterialPropF = aModelF->getMaterialProperty(); - aStudy->setObjectProperty( aMgrId, anIO->getEntry(), FRONT_MATERIAL_PROP, aMaterialPropF ); + aStudy->setObjectProperty( aMgrId, anIO->getEntry(), MATERIAL_PROP, aMaterialPropF ); - // Set back material property - QString aMaterialPropB = aModelB->getMaterialProperty(); - aStudy->setObjectProperty( aMgrId, anIO->getEntry(), BACK_MATERIAL_PROP, aMaterialPropB ); - - // Get front material properties from the model + // Get material properties from the model Graphic3d_MaterialAspect aMatF = aModelF->getMaterialOCCAspect(); - // Get back material properties from the model - Graphic3d_MaterialAspect aMatB = aModelB->getMaterialOCCAspect(); - - // Set front material for the selected shape - AISShape->SetCurrentFacingModel(Aspect_TOFM_FRONT_SIDE); - AISShape->SetMaterial(aMatF); - - // Set back material for the selected shape - AISShape->SetCurrentFacingModel(Aspect_TOFM_BACK_SIDE); - AISShape->SetMaterial(aMatB); - - // Return to the default facing mode - AISShape->SetCurrentFacingModel(Aspect_TOFM_BOTH_SIDE); + // Set material for the selected shape + AISShape->SetMaterial(aMatF); // Release memory if ( aModelF ) delete aModelF; - if ( aModelB ) - delete aModelB; if(HasWidth()) aStudy->setObjectProperty( aMgrId, anIO->getEntry(), EDGE_WIDTH_PROP, GetWidth() ); @@ -1205,52 +1174,21 @@ void GEOM_Displayer::Update( SALOME_VTKPrs* prs ) aGeomGActor->setDisplayMode(aDispModeId); aGeomGActor->SetDeflection(aPropMap.value(DEFLECTION_COEFF_PROP).toDouble()); - // Get front material property of the object stored in the study - QString aMaterialF = aPropMap.value(FRONT_MATERIAL_PROP).toString(); + // Get material property of the object stored in the study + QString aMaterialF = aPropMap.value(MATERIAL_PROP).toString(); QStringList aPropsF = aMaterialF.split(DIGIT_SEPARATOR); - // Create front material model + // Create material model Material_Model* aModelF = Material_Model::getMaterialModel( aPropsF ); - // Set front material properties for the object + // Set material properties for the object QString aMaterialPropF = aModelF->getMaterialProperty(); - aStudy->setObjectProperty( aMgrId, anEntry, FRONT_MATERIAL_PROP, aMaterialPropF ); - // Get material properties from the front model - vtkProperty* aMatPropF = aModelF->getMaterialVTKProperty(); + 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 + std::vector aProps; + aProps.push_back( (vtkProperty*) aMatPropF ); + aGeomGActor->SetMaterial(aProps); - // Get back material property of the object stored in the study - QString aMaterialB = aPropMap.value(BACK_MATERIAL_PROP).toString(); - if ( !aMaterialB.isEmpty() ) { - QStringList aPropsB = aMaterialB.split(DIGIT_SEPARATOR); - // Create back material model - Material_Model* aModelB = Material_Model::getMaterialModel( aPropsB ); - // Set back material properties for the object - QString aMaterialPropB = aModelB->getMaterialProperty(); - aStudy->setObjectProperty( aMgrId, anEntry, BACK_MATERIAL_PROP, aMaterialPropB ); - // Get material properties from the back model - vtkProperty* aMatPropB = aModelB->getMaterialVTKProperty(); - - // Set front and back materials for the selected shape - std::vector aProps; - aProps.push_back(aMatPropF); - aProps.push_back(aMatPropB); - aGeomGActor->SetMaterial(aProps); - - // Release memory - delete aModelB; - - if(HasWidth()) - aStudy->setObjectProperty( aMgrId, anEntry, EDGE_WIDTH_PROP, GetWidth() ); - - if(HasIsosWidth()) - aStudy->setObjectProperty( aMgrId, anEntry, ISOS_WIDTH_PROP, GetIsosWidth() ); - - } - else { - // Set the same front and back materials for the selected shape - std::vector aProps; - aProps.push_back(aMatPropF); - aGeomGActor->SetMaterial(aProps); - } - // Release memory delete aModelF; @@ -1284,37 +1222,26 @@ void GEOM_Displayer::Update( SALOME_VTKPrs* prs ) } } } - aGeomGActor->SetColor(aColor[0],aColor[1],aColor[2]); + if ( !aMatPropF->GetPhysical() ) + aGeomGActor->SetColor(aColor[0],aColor[1],aColor[2]); } else { SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); if ( aResMgr ) { - // Create front material model + // Create material model Material_Model aModelF; - // Get front material name from resources - aModelF.fromResources( aResMgr, "Geometry", true ); - // Set front material properties for the object + // Get material name from resources + aModelF.fromResources( aResMgr, "Geometry" ); + // Set material properties for the object QString aMaterialPropF = aModelF.getMaterialProperty(); - aStudy->setObjectProperty( aMgrId, anEntry, FRONT_MATERIAL_PROP, aMaterialPropF ); - // Get material properties from the front model - vtkProperty* aMatPropF = aModelF.getMaterialVTKProperty(); - - // Create back material model - Material_Model aModelB; - // Get back material name from resources - aModelB.fromResources( aResMgr, "Geometry", false ); - // Set back material properties for the object - QString aMaterialPropB = aModelB.getMaterialProperty(); - aStudy->setObjectProperty( aMgrId, anEntry, BACK_MATERIAL_PROP, aMaterialPropB ); - // Get material properties from the back model - vtkProperty* aMatPropB = aModelB.getMaterialVTKProperty(); + aStudy->setObjectProperty( aMgrId, anEntry, MATERIAL_PROP, aMaterialPropF ); + // Get material properties from the model + GEOM_VTKPropertyMaterial* aMatPropF = aModelF.getMaterialVTKProperty(); // Set material for the selected shape - std::vector aProps; - aProps.push_back(aMatPropF); - aProps.push_back(aMatPropB); - aGeomGActor->SetMaterial(aProps); - } + std::vector aProps; + aProps.push_back( (vtkProperty*) aMatPropF ); + aGeomGActor->SetMaterial(aProps); } } } @@ -2010,23 +1937,16 @@ PropMap GEOM_Displayer::getDefaultPropertyMap(const QString& viewer_type) { aDefaultMap.insert( DEFLECTION_COEFF_PROP , aDC); //8. Material - // Front material Material_Model aModelF; - aModelF.fromResources( aResMgr, "Geometry", true ); + aModelF.fromResources( aResMgr, "Geometry" ); QString aMaterialF = aModelF.getMaterialProperty(); - aDefaultMap.insert( FRONT_MATERIAL_PROP , aMaterialF ); + aDefaultMap.insert( MATERIAL_PROP , aMaterialF ); - //9. Back material - Material_Model aModelB; - aModelB.fromResources( aResMgr, "Geometry", false ); - QString aMaterialB = aModelB.getMaterialProperty(); - aDefaultMap.insert( BACK_MATERIAL_PROP , aMaterialB ); - - //10. Width of the edges + //9. Width of the edges aDefaultMap.insert( EDGE_WIDTH_PROP , aResMgr->integerValue("Geometry", "edge_width", 1)); - //11. Width of iso-lines + //10. Width of iso-lines aDefaultMap.insert( ISOS_WIDTH_PROP , aResMgr->integerValue("Geometry", "isolines_width", 1)); if(viewer_type == SOCC_Viewer::Type()) { @@ -2063,12 +1983,8 @@ bool GEOM_Displayer::MergePropertyMaps(PropMap& theOrigin, PropMap& theDefault) theOrigin.insert(DEFLECTION_COEFF_PROP, theDefault.value(DEFLECTION_COEFF_PROP)); nbInserted++; } - if(!theOrigin.contains(FRONT_MATERIAL_PROP)) { - theOrigin.insert(FRONT_MATERIAL_PROP, theDefault.value(FRONT_MATERIAL_PROP)); - nbInserted++; - } - if(!theOrigin.contains(BACK_MATERIAL_PROP)) { - theOrigin.insert(BACK_MATERIAL_PROP, theDefault.value(BACK_MATERIAL_PROP)); + if(!theOrigin.contains(MATERIAL_PROP)) { + theOrigin.insert(MATERIAL_PROP, theDefault.value(MATERIAL_PROP)); nbInserted++; } @@ -2082,6 +1998,11 @@ bool GEOM_Displayer::MergePropertyMaps(PropMap& theOrigin, PropMap& theDefault) nbInserted++; } + if(!theOrigin.contains(COLOR_PROP)) { + theOrigin.insert(COLOR_PROP, theDefault.value(COLOR_PROP)); + nbInserted++; + } + return (nbInserted > 0); } diff --git a/src/GEOMGUI/GEOM_msg_en.ts b/src/GEOMGUI/GEOM_msg_en.ts index b43229a40..51660252e 100644 --- a/src/GEOMGUI/GEOM_msg_en.ts +++ b/src/GEOMGUI/GEOM_msg_en.ts @@ -3015,12 +3015,8 @@ Please, select face, shell or solid and try again Default wireframe color - PREF_FRONT_MATERIAL - Default front material - - - PREF_BACK_MATERIAL - Default back material + PREF_MATERIAL + Default material PREF_EDGE_WIDTH @@ -5274,6 +5270,10 @@ Would you like to continue? SHININESS Shininess: + + PHYSICAL + Physical: + CUSTOM_MATERIAL Custom material diff --git a/src/GEOMGUI/GEOM_msg_fr.ts b/src/GEOMGUI/GEOM_msg_fr.ts index 983f5ab23..54309e6bc 100644 --- a/src/GEOMGUI/GEOM_msg_fr.ts +++ b/src/GEOMGUI/GEOM_msg_fr.ts @@ -5274,6 +5274,10 @@ Voulez-vous continuer? SHININESS Shininess: + + PHYSICAL + Physical: + CUSTOM_MATERIAL Matériau personnalisé diff --git a/src/GEOMGUI/GeometryGUI.cxx b/src/GEOMGUI/GeometryGUI.cxx index ee66a0b50..685c6551b 100644 --- a/src/GEOMGUI/GeometryGUI.cxx +++ b/src/GEOMGUI/GeometryGUI.cxx @@ -591,10 +591,7 @@ void GeometryGUI::OnGUIEvent( int id ) if ( pref ) { Material_ResourceMgr aMatResMgr; QStringList aPerfMatNames = aMatResMgr.getPreferenceMaterialsNames(); - setPreferenceProperty( pref->rootItem()->findItem( tr( "PREF_FRONT_MATERIAL" ), true )->id(), - "strings", - aPerfMatNames ); - setPreferenceProperty( pref->rootItem()->findItem( tr( "PREF_BACK_MATERIAL" ), true )->id(), + setPreferenceProperty( pref->rootItem()->findItem( tr( "PREF_MATERIAL" ), true )->id(), "strings", aPerfMatNames ); } @@ -1250,7 +1247,7 @@ void GeometryGUI::initialize( CAM_Application* app ) mgr->setRule( action( GEOMOp::OpVectors ), clientOCCorVTK + " and isVectorsMode", QtxPopupMgr::ToggleRule ); mgr->insert( separator(), -1, -1 ); // ----------- mgr->insert( action( GEOMOp::OpColor ), -1, -1 ); // color - mgr->setRule( action( GEOMOp::OpColor ), clientOCCorVTKorOB_AndSomeVisible + " and ($component={'GEOM'})", QtxPopupMgr::VisibleRule ); + mgr->setRule( action( GEOMOp::OpColor ), clientOCCorVTKorOB_AndSomeVisible + " and ($component={'GEOM'})" + "and isPhysicalMaterial=false", QtxPopupMgr::VisibleRule ); mgr->insert( action( GEOMOp::OpTransparency ), -1, -1 ); // transparency mgr->setRule( action( GEOMOp::OpTransparency ), clientOCCorVTK_AndSomeVisible, QtxPopupMgr::VisibleRule ); mgr->insert( action( GEOMOp::OpIsos ), -1, -1 ); // isos @@ -1719,14 +1716,10 @@ void GeometryGUI::createPreferences() int defl = addPreference( tr( "PREF_DEFLECTION" ), genGroup, LightApp_Preferences::DblSpin, "Geometry", "deflection_coeff" ); - int front_material = addPreference( tr( "PREF_FRONT_MATERIAL" ), genGroup, + int material = addPreference( tr( "PREF_MATERIAL" ), genGroup, LightApp_Preferences::Selector, - "Geometry", "front_material" ); + "Geometry", "material" ); - int back_material = addPreference( tr( "PREF_BACK_MATERIAL" ), genGroup, - LightApp_Preferences::Selector, - "Geometry", "back_material" ); - const int nb = 4; int wd[nb]; int iter=0; @@ -1816,8 +1809,7 @@ void GeometryGUI::createPreferences() // Set property for default material Material_ResourceMgr aMatResMgr; QStringList aPrefMatNames = aMatResMgr.getPreferenceMaterialsNames(); - setPreferenceProperty( front_material, "strings", aPrefMatNames ); - setPreferenceProperty( back_material, "strings", aPrefMatNames ); + setPreferenceProperty( material, "strings", aPrefMatNames ); // Set property vertex marker type QList aMarkerTypeIndicesList; @@ -2014,17 +2006,11 @@ void GeometryGUI::storeVisualParameters (int savePoint) ip->setParameter(entry, param, aProps.value(MARKER_TYPE_PROP).toString().toLatin1().data()); } - if(aProps.contains(FRONT_MATERIAL_PROP)) { - param = occParam + FRONT_MATERIAL_PROP; - ip->setParameter(entry, param, aProps.value(FRONT_MATERIAL_PROP).toString().toLatin1().data()); + if(aProps.contains(MATERIAL_PROP)) { + param = occParam + MATERIAL_PROP; + ip->setParameter(entry, param, aProps.value(MATERIAL_PROP).toString().toLatin1().data()); } - if(aProps.contains(BACK_MATERIAL_PROP)) { - param = occParam + BACK_MATERIAL_PROP; - ip->setParameter(entry, param, aProps.value(BACK_MATERIAL_PROP).toString().toLatin1().data()); - - } - if(aProps.contains( EDGE_WIDTH_PROP )) { param = occParam + EDGE_WIDTH_PROP; ip->setParameter(entry, param, aProps.value(EDGE_WIDTH_PROP).toString().toLatin1().data()); @@ -2144,10 +2130,8 @@ void GeometryGUI::restoreVisualParameters (int savePoint) aListOfMap[viewIndex].insert( DEFLECTION_COEFF_PROP, val.toDouble()); } else if(paramNameStr == MARKER_TYPE_PROP) { aListOfMap[viewIndex].insert( MARKER_TYPE_PROP, val); - } else if(paramNameStr == FRONT_MATERIAL_PROP) { - aListOfMap[viewIndex].insert( FRONT_MATERIAL_PROP, val); - } else if(paramNameStr == BACK_MATERIAL_PROP) { - aListOfMap[viewIndex].insert( BACK_MATERIAL_PROP, val); + } else if(paramNameStr == MATERIAL_PROP) { + aListOfMap[viewIndex].insert( MATERIAL_PROP, val); } else if(paramNameStr == EDGE_WIDTH_PROP) { aListOfMap[viewIndex].insert( EDGE_WIDTH_PROP , val); } else if(paramNameStr == ISOS_WIDTH_PROP) { diff --git a/src/GEOMToolsGUI/GEOMToolsGUI_1.cxx b/src/GEOMToolsGUI/GEOMToolsGUI_1.cxx index 3c801ec66..3c061b29e 100644 --- a/src/GEOMToolsGUI/GEOMToolsGUI_1.cxx +++ b/src/GEOMToolsGUI/GEOMToolsGUI_1.cxx @@ -34,6 +34,7 @@ #include "GEOMToolsGUI_PublishDlg.h" #include "GEOMToolsGUI_MaterialPropertiesDlg.h" #include "GEOMToolsGUI_LineWidthDlg.h" +#include "Material_Model.h" #include #include @@ -293,22 +294,35 @@ void GEOMToolsGUI::OnColor() if ( c.isValid() ) { SUIT_OverrideCursor(); for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) { - aView->SetColor( It.Value(), c ); - appStudy->setObjectProperty(mgrId,It.Value()->getEntry(),COLOR_PROP, c); + QString defMatProp; + QVariant mp = appStudy->getObjectProperty(mgrId,It.Value()->getEntry(), MATERIAL_PROP, defMatProp); + QString matProp = mp.value(); + QStringList aProps = matProp.split(DIGIT_SEPARATOR); + Material_Model* aModelF = Material_Model::getMaterialModel( aProps ); + bool aPhys = false; + if ( aModelF ) { + aPhys = aModelF->isPhysical(); + // Release memory + delete aModelF; + } + if ( !aPhys ) { + aView->SetColor( It.Value(), c ); + appStudy->setObjectProperty(mgrId,It.Value()->getEntry(),COLOR_PROP, c); + } } GeometryGUI::Modified(); } } // if ( isVTK ) else if ( isOCC ) { - Handle(AIS_InteractiveObject) io = GEOMBase::GetAIS( selected.First() ); + Handle(AIS_InteractiveObject) io = GEOMBase::GetAIS( selected.First() ); if ( !io.IsNull() ) { Quantity_Color aColor; io->Color( aColor ); - QColor ic = QColor((int )( aColor.Red() * 255.0 ), + QColor ic = QColor((int )( aColor.Red() * 255.0 ), (int)( aColor.Green() * 255.0 ), (int)( aColor.Blue() * 255.0 )); - QVariant v = appStudy->getObjectProperty(mgrId,selected.First()->getEntry(), COLOR_PROP, ic); + QVariant v = appStudy->getObjectProperty(mgrId,selected.First()->getEntry(), COLOR_PROP, ic); QColor initcolor = v.value(); QColor c = QColorDialog::getColor( initcolor, app->desktop() ); @@ -318,8 +332,19 @@ void GEOMToolsGUI::OnColor() OCCViewer_Viewer* vm = dynamic_cast ( window->getViewManager()->getViewModel() ); Handle (AIS_InteractiveContext) ic = vm->getAISContext(); for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) { + QString defMatProp; + QVariant mp = appStudy->getObjectProperty(mgrId,It.Value()->getEntry(), MATERIAL_PROP, defMatProp); + QString matProp = mp.value(); + QStringList aProps = matProp.split(DIGIT_SEPARATOR); + 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 ); - if ( !io.IsNull() ) { + if ( !io.IsNull() && !aPhys ) { // change color only for shapes with not physical type of material if ( io->IsKind( STANDARD_TYPE(AIS_Shape) ) ) { TopoDS_Shape theShape = Handle(AIS_Shape)::DownCast( io )->Shape(); @@ -351,14 +376,14 @@ void GEOMToolsGUI::OnColor() ic->SetLocalAttributes(io, aCurDrawer, Standard_False); } } - + io->SetColor( aColor ); if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) ) { Handle(GEOM_AISShape) aGAISShape = Handle(GEOM_AISShape)::DownCast( io ); - aGAISShape->SetShadingColor( aColor ); - aGAISShape->storeBoundaryColors(); - } - + aGAISShape->SetShadingColor( aColor ); + aGAISShape->storeBoundaryColors(); + } + appStudy->setObjectProperty(mgrId,It.Value()->getEntry(), COLOR_PROP, c); io->Redisplay( Standard_True ); @@ -375,7 +400,7 @@ void GEOMToolsGUI::OnColor() aSColor.G = (double)c.green() / 255.0; aSColor.B = (double)c.blue() / 255.0; anObject->SetColor( aSColor ); - anObject->SetAutoColor( false ); + anObject->SetAutoColor( false ); } } // for ic->UpdateCurrentViewer(); diff --git a/src/GEOMToolsGUI/GEOMToolsGUI_MaterialPropertiesDlg.cxx b/src/GEOMToolsGUI/GEOMToolsGUI_MaterialPropertiesDlg.cxx index c82bd4839..ed94f9cc0 100644 --- a/src/GEOMToolsGUI/GEOMToolsGUI_MaterialPropertiesDlg.cxx +++ b/src/GEOMToolsGUI/GEOMToolsGUI_MaterialPropertiesDlg.cxx @@ -123,11 +123,9 @@ GEOMToolsGUI_MaterialPropertiesDlg::GEOMToolsGUI_MaterialPropertiesDlg( QWidget* main->setMargin( 0 ); main->setSpacing( SPACING ); // Create main widgets - myBackMaterialCheck = new QCheckBox( tr( "MATERIAL_BACK_CHK" ), this ); QFrame* fr = new QFrame( this ); fr->setFrameStyle( QFrame::Box | QFrame::Sunken ); - main->addWidget( myBackMaterialCheck ); main->addWidget( fr ); // Create editor widgets @@ -141,7 +139,7 @@ GEOMToolsGUI_MaterialPropertiesDlg::GEOMToolsGUI_MaterialPropertiesDlg( QWidget* frLayout->setStretchFactor( myMaterialList, 1 ); frLayout->setStretchFactor( myMaterialTab, 2 ); - // ======================= Create a tab for front material ======================= + // ======================= Create a tab for material ======================= QWidget* w1 = new QWidget( myMaterialTab ); QVBoxLayout* vLayout1 = new QVBoxLayout( w1 ); @@ -262,166 +260,34 @@ GEOMToolsGUI_MaterialPropertiesDlg::GEOMToolsGUI_MaterialPropertiesDlg( QWidget* gLayout1->addWidget( mySpecularGroupF, 1, 0 ); gLayout1->addWidget( myEmissionGroupF, 1, 1 ); - // Shininess + // Shininess and type QLabel* shininessLab1 = new QLabel( tr( "SHININESS" ), w1 ); myShininessF = new QtxDoubleSpinBox( w1 ); myShininessF->setMaximum(1); myShininessF->setSingleStep(0.05); connect( myShininessF, SIGNAL( valueChanged( double ) ), this, SIGNAL( materialChanged() ) ); + + QLabel* physicalLab1 = new QLabel( tr( "PHYSICAL" ), w1 ); + myMaterialPhysicalCheck = new QCheckBox( w1 ); + myMaterialPhysicalCheck->setCheckable( true ); + connect( myMaterialPhysicalCheck, SIGNAL( toggled( bool ) ), this, SLOT( onReflectionTypeToggled( bool ) ) ); - // Shininess layout - QHBoxLayout* shLayout1 = new QHBoxLayout( w1 ); + // Shininess and type layout + QGridLayout* shLayout1 = new QGridLayout( w1 ); shLayout1->setMargin( MARGIN ); shLayout1->setSpacing( SPACING ); - shLayout1->addWidget( shininessLab1 ); - shLayout1->addWidget( myShininessF ); + shLayout1->addWidget( shininessLab1, 0, 0 ); + shLayout1->addWidget( myShininessF, 0, 1 ); + shLayout1->addWidget( physicalLab1, 1, 0 ); + shLayout1->addWidget( myMaterialPhysicalCheck, 1, 1 ); + // Fill initial vertical layout of the reflection type group box vLayout1->addLayout( gLayout1 ); vLayout1->addLayout( shLayout1 ); vLayout1->addStretch(); - // ======================= Create a tab for back material ======================= - myMaterialBWidget = new QWidget( myMaterialTab ); - QVBoxLayout* vLayout2 = new QVBoxLayout( myMaterialBWidget ); - - QGridLayout* gLayout2 = new QGridLayout( myMaterialBWidget ); - gLayout2->setMargin( MARGIN ); gLayout2->setSpacing( SPACING ); - - // ----------------- "Ambient" reflection type group box ----------------- - myAmbientGroupB = new QGroupBox( tr( "AMBIENT_GRP" ), myMaterialBWidget ); - myAmbientGroupB->setCheckable(true); - connect( myAmbientGroupB, SIGNAL( toggled( bool ) ), this, SLOT( onReflectionTypeToggled( bool ) ) ); - - // Ambient color - QLabel* ambColorLab2 = new QLabel( tr( "COLOR" ), myAmbientGroupB ); - myAmbientColorB = new QtxColorButton( myAmbientGroupB ); - myAmbientColorB->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); - connect( myAmbientColorB, SIGNAL( changed( QColor ) ), this, SIGNAL( changed() ) ); - - // Ambient coefficient - QLabel* ambCoefficientLab2 = new QLabel( tr( "COEFFICIENT" ), myAmbientGroupB ); - myAmbientCoefntB = new QtxDoubleSpinBox( myAmbientGroupB ); - myAmbientCoefntB->setMaximum(1); - myAmbientCoefntB->setSingleStep(0.05); - connect( myAmbientCoefntB, SIGNAL( valueChanged( double ) ), this, SIGNAL( materialChanged() ) ); - - // Ambient group box layout - QGridLayout* ambientLayout2 = new QGridLayout( myAmbientGroupB ); - ambientLayout2->setMargin( MARGIN ); ambientLayout2->setSpacing( SPACING ); - ambientLayout2->addWidget( ambColorLab2, 0, 0 ); - ambientLayout2->addWidget( myAmbientColorB, 0, 1 ); - ambientLayout2->addWidget( ambCoefficientLab2, 1, 0 ); - ambientLayout2->addWidget( myAmbientCoefntB, 1, 1 ); - - // ----------------- "Diffuse" reflection type group box ----------------- - myDiffuseGroupB = new QGroupBox( tr( "DIFFUSE_GRP" ), myMaterialBWidget ); - myDiffuseGroupB->setCheckable(true); - connect( myDiffuseGroupB, SIGNAL( toggled( bool ) ), this, SLOT( onReflectionTypeToggled( bool ) ) ); - - // Diffuse color - QLabel* difColorLab2 = new QLabel( tr( "COLOR" ), myDiffuseGroupB ); - myDiffuseColorB = new QtxColorButton( myDiffuseGroupB ); - myDiffuseColorB->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); - connect( myDiffuseColorB, SIGNAL( changed( QColor ) ), this, SIGNAL( changed() ) ); - - // Diffuse coefficient - QLabel* difCoefficientLab2 = new QLabel( tr( "COEFFICIENT" ), myDiffuseGroupB ); - myDiffuseCoefntB = new QtxDoubleSpinBox( myDiffuseGroupB ); - myDiffuseCoefntB->setMaximum(1); - myDiffuseCoefntB->setSingleStep(0.05); - connect( myDiffuseCoefntB, SIGNAL( valueChanged( double ) ), this, SIGNAL( materialChanged() ) ); - - // Diffuse group box layout - QGridLayout* diffuseLayout2 = new QGridLayout( myDiffuseGroupB ); - diffuseLayout2->setMargin( MARGIN ); diffuseLayout2->setSpacing( SPACING ); - diffuseLayout2->addWidget( difColorLab2, 0, 0 ); - diffuseLayout2->addWidget( myDiffuseColorB, 0, 1 ); - diffuseLayout2->addWidget( difCoefficientLab2, 1, 0 ); - diffuseLayout2->addWidget( myDiffuseCoefntB, 1, 1 ); - - // ----------------- "Specular" reflection type group box ----------------- - mySpecularGroupB = new QGroupBox( tr( "SPECULAR_GRP" ), myMaterialBWidget ); - mySpecularGroupB->setCheckable(true); - connect( mySpecularGroupB, SIGNAL( toggled( bool ) ), this, SLOT( onReflectionTypeToggled( bool ) ) ); - - // Specular color - QLabel* specColorLab2 = new QLabel( tr( "COLOR" ), mySpecularGroupB ); - mySpecularColorB = new QtxColorButton( mySpecularGroupB ); - mySpecularColorB->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); - connect( mySpecularColorB, SIGNAL( changed( QColor ) ), this, SIGNAL( changed() ) ); - - // Specular coefficient - QLabel* specCoefficientLab2 = new QLabel( tr( "COEFFICIENT" ), mySpecularGroupB ); - mySpecularCoefntB = new QtxDoubleSpinBox( mySpecularGroupB ); - mySpecularCoefntB->setMaximum(1); - mySpecularCoefntB->setSingleStep(0.05); - connect( mySpecularCoefntB, SIGNAL( valueChanged( double ) ), this, SIGNAL( materialChanged() ) ); - - // Specular group box layout - QGridLayout* specularLayout2 = new QGridLayout( mySpecularGroupB ); - specularLayout2->setMargin( MARGIN ); specularLayout2->setSpacing( SPACING ); - specularLayout2->addWidget( specColorLab2, 0, 0 ); - specularLayout2->addWidget( mySpecularColorB, 0, 1 ); - specularLayout2->addWidget( specCoefficientLab2, 1, 0 ); - specularLayout2->addWidget( mySpecularCoefntB, 1, 1 ); - - // ----------------- "Emission" reflection type group box ----------------- - myEmissionGroupB = new QGroupBox( tr( "EMISSION_GRP" ), myMaterialBWidget ); - myEmissionGroupB->setCheckable(true); - connect( myEmissionGroupB, SIGNAL( toggled( bool ) ), this, SLOT( onReflectionTypeToggled( bool ) ) ); - - // Emission color - QLabel* emisColorLab2 = new QLabel( tr( "COLOR" ), myEmissionGroupB ); - myEmissionColorB = new QtxColorButton( myEmissionGroupB ); - myEmissionColorB->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); - connect( myEmissionColorB, SIGNAL( changed( QColor ) ), this, SIGNAL( changed() ) ); - - // Emission coefficient - QLabel* emisCoefficientLab2 = new QLabel( tr( "COEFFICIENT" ), myEmissionGroupB ); - myEmissionCoefntB = new QtxDoubleSpinBox( myEmissionGroupB ); - myEmissionCoefntB->setMaximum(1); - myEmissionCoefntB->setSingleStep(0.05); - connect( myEmissionCoefntB, SIGNAL( valueChanged( double ) ), this, SIGNAL( materialChanged() ) ); - - // Emission group box layout - QGridLayout* emissionLayout2 = new QGridLayout( myEmissionGroupB ); - emissionLayout2->setMargin( MARGIN ); emissionLayout2->setSpacing( SPACING ); - emissionLayout2->addWidget( emisColorLab2, 0, 0 ); - emissionLayout2->addWidget( myEmissionColorB, 0, 1 ); - emissionLayout2->addWidget( emisCoefficientLab2, 1, 0 ); - emissionLayout2->addWidget( myEmissionCoefntB, 1, 1 ); - - // Erase emission group in case of VTK viewer - if ( myViewerType == VTK ) - myEmissionGroupB->hide(); - - // Add group boxes to the main grid layout of the frame with material properties - gLayout2->addWidget( myAmbientGroupB, 0, 0 ); - gLayout2->addWidget( myDiffuseGroupB, 0, 1 ); - gLayout2->addWidget( mySpecularGroupB, 1, 0 ); - gLayout2->addWidget( myEmissionGroupB, 1, 1 ); - - // Shininess - QLabel* shininessLab2 = new QLabel( tr( "SHININESS" ), myMaterialBWidget ); - myShininessB = new QtxDoubleSpinBox( myMaterialBWidget ); - myShininessB->setMaximum(1); - myShininessB->setSingleStep(0.05); - connect( myShininessB, SIGNAL( valueChanged( double ) ), this, SIGNAL( materialChanged() ) ); - - // Shininess layout - QHBoxLayout* shLayout2 = new QHBoxLayout( myMaterialBWidget ); - shLayout2->setMargin( MARGIN ); shLayout2->setSpacing( SPACING ); - shLayout2->addWidget( shininessLab2 ); - shLayout2->addWidget( myShininessB ); - - // Fill initial vertical layout of the reflection type group box - vLayout2->addLayout( gLayout2 ); - vLayout2->addLayout( shLayout2 ); - vLayout2->addStretch(); - // Add tabs to material tab widget - myMaterialTab->addTab( w1, tr( "Front material" ) ); - myMaterialTab->addTab( myMaterialBWidget, tr( "Back material" ) ); + myMaterialTab->addTab( w1, tr( "Material" ) ); // Initialize dialog box setFocusProxy( fr ); @@ -466,11 +332,6 @@ GEOMToolsGUI_MaterialPropertiesDlg::GEOMToolsGUI_MaterialPropertiesDlg( QWidget* } // Connect signals - connect( myMaterialTab, SIGNAL( currentChanged( int ) ), - this, SLOT( onCurrentTabChanged( int ) ) ); - connect( myBackMaterialCheck, SIGNAL( toggled( bool ) ), - this, SLOT( onBackMaterialChecked( bool ) ) ); - connect( myMaterialList, SIGNAL( itemSelectionChanged() ), this, SLOT( onMaterialChanged() ) ); connect( myMaterialList, SIGNAL( itemChanged( QListWidgetItem* ) ), @@ -484,7 +345,7 @@ GEOMToolsGUI_MaterialPropertiesDlg::GEOMToolsGUI_MaterialPropertiesDlg( QWidget* connect( this, SIGNAL( dlgApply() ), this, SLOT( onApply() ) ); connect( this, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) ); - // Initialize current fornt and back material models of the selected shape + // Initialize current material models of the selected shape if ( app ) { LightApp_SelectionMgr* aSelMgr = app->selectionMgr(); if ( aSelMgr ) { @@ -499,33 +360,18 @@ GEOMToolsGUI_MaterialPropertiesDlg::GEOMToolsGUI_MaterialPropertiesDlg( QWidget* int aMgrId = window->getViewManager()->getGlobalId(); QString aMaterialF; - QString aMaterialB; for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) { PropMap aPropMap = aStudy->getObjectPropMap( aMgrId, It.Value()->getEntry() ); - aMaterialF = aPropMap.value(FRONT_MATERIAL_PROP).toString(); - aMaterialB = aPropMap.value(BACK_MATERIAL_PROP).toString(); + aMaterialF = aPropMap.value(MATERIAL_PROP).toString(); if ( !aMaterialF.isEmpty() ) { QStringList aPropsF = aMaterialF.split(DIGIT_SEPARATOR); myCurrentModelF = Material_Model::getMaterialModel( aPropsF ); - - if ( !aMaterialB.isEmpty() ) { - QStringList aPropsB = aMaterialB.split(DIGIT_SEPARATOR); - myCurrentModelB = Material_Model::getMaterialModel( aPropsB ); - - myBackMaterialCheck->setChecked( true ); - } - else { - myCurrentModelB = Material_Model::getMaterialModel( aPropsF ); - - myBackMaterialCheck->setChecked( false ); - myMaterialTab->removeTab( 1 ); - } - + break; } } @@ -533,20 +379,14 @@ GEOMToolsGUI_MaterialPropertiesDlg::GEOMToolsGUI_MaterialPropertiesDlg( QWidget* if ( aMaterialF.isEmpty() ) { myCurrentModelF = new Material_Model(); myCurrentModelF->fromResources( SUIT_Session::session()->resourceMgr(), "Geometry" ); - - myCurrentModelB = new Material_Model(); - myCurrentModelB->fromResources( SUIT_Session::session()->resourceMgr(), "Geometry", false ); - } - } + } + } } } } myMaterialList->setCurrentRow( 0 ); myMaterialListFId = 0; - myMaterialListBId = 0; - - myIsBTabWasActivated = false; myHelpFileName = "material_page.html"; } @@ -558,9 +398,6 @@ GEOMToolsGUI_MaterialPropertiesDlg::~GEOMToolsGUI_MaterialPropertiesDlg() { if ( myCurrentModelF ) delete myCurrentModelF; - - if ( myCurrentModelB ) - delete myCurrentModelB; } /*! @@ -617,125 +454,63 @@ Material_ResourceMgr* GEOMToolsGUI_MaterialPropertiesDlg::resourceMgr() void GEOMToolsGUI_MaterialPropertiesDlg::fromModel( Material_Model* model) { if ( !model ) return; - - bool isReflectionTypeActive; - - if ( isFrontTabActive() ) { // Fill in front material tab - - // Ambient reflection type - isReflectionTypeActive = model->hasAmbientReflection(); - myAmbientGroupF->setChecked( isReflectionTypeActive ); - if ( isReflectionTypeActive ) { - // Load ambient color - myAmbientColorF->setColor( model->color(Material_Model::Ambient) ); - // Load ambient coefficient - myAmbientCoefntF->setValue( model->coefficient(Material_Model::Ambient) ); - } - - // Diffuse reflection type - isReflectionTypeActive = model->hasDiffuseReflection(); - myDiffuseGroupF->setChecked( isReflectionTypeActive ); - if ( isReflectionTypeActive ) { - // Load diffuse color - myDiffuseColorF->setColor( model->color(Material_Model::Diffuse) ); - // Load diffuse coefficient - myDiffuseCoefntF->setValue( model->coefficient(Material_Model::Diffuse) ); - } - - // Specular reflection type - isReflectionTypeActive = model->hasSpecularReflection(); - mySpecularGroupF->setChecked( isReflectionTypeActive ); - if ( isReflectionTypeActive ) { - // Load specular color - mySpecularColorF->setColor( model->color(Material_Model::Specular) ); - // Load specular coefficient - mySpecularCoefntF->setValue( model->coefficient(Material_Model::Specular) ); - } - - // Emission reflection type - isReflectionTypeActive = model->hasEmissionReflection(); - myEmissionGroupF->setChecked( isReflectionTypeActive ); - if ( isReflectionTypeActive ) { - // Load emission color - myEmissionColorF->setColor( model->color(Material_Model::Emission) ); - // Load emission coefficient - myEmissionCoefntF->setValue( model->coefficient(Material_Model::Emission) ); - } - - // Shininess - myShininessF->setValue( model->shininess() ); - + bool isReflectionTypeActive; + // Ambient reflection type + isReflectionTypeActive = model->hasAmbientReflection(); + myAmbientGroupF->setChecked( isReflectionTypeActive ); + if ( isReflectionTypeActive ) { + // Load ambient color + myAmbientColorF->setColor( model->color(Material_Model::Ambient) ); + // Load ambient coefficient + myAmbientCoefntF->setValue( model->coefficient(Material_Model::Ambient) ); } - else { // Fill in back material tab - - // Ambient reflection type - isReflectionTypeActive = model->hasAmbientReflection(); - myAmbientGroupB->setChecked( isReflectionTypeActive ); - if ( isReflectionTypeActive ) { - // Load ambient color - myAmbientColorB->setColor( model->color(Material_Model::Ambient) ); - // Load ambient coefficient - myAmbientCoefntB->setValue( model->coefficient(Material_Model::Ambient) ); - } - - // Diffuse reflection type - isReflectionTypeActive = model->hasDiffuseReflection(); - myDiffuseGroupB->setChecked( isReflectionTypeActive ); - if ( isReflectionTypeActive ) { - // Load diffuse color - myDiffuseColorB->setColor( model->color(Material_Model::Diffuse) ); - // Load diffuse coefficient - myDiffuseCoefntB->setValue( model->coefficient(Material_Model::Diffuse) ); - } - - // Specular reflection type - isReflectionTypeActive = model->hasSpecularReflection(); - mySpecularGroupB->setChecked( isReflectionTypeActive ); - if ( isReflectionTypeActive ) { - // Load specular color - mySpecularColorB->setColor( model->color(Material_Model::Specular) ); - // Load specular coefficient - mySpecularCoefntB->setValue( model->coefficient(Material_Model::Specular) ); - } - - // Emission reflection type - isReflectionTypeActive = model->hasEmissionReflection(); - myEmissionGroupB->setChecked( isReflectionTypeActive ); - if ( isReflectionTypeActive ) { - // Load emission color - myEmissionColorB->setColor( model->color(Material_Model::Emission) ); - // Load emission coefficient - myEmissionCoefntB->setValue( model->coefficient(Material_Model::Emission) ); - } - - // Shininess - myShininessB->setValue( model->shininess() ); - + + // Diffuse reflection type + isReflectionTypeActive = model->hasDiffuseReflection(); + myDiffuseGroupF->setChecked( isReflectionTypeActive ); + if ( isReflectionTypeActive ) { + // Load diffuse color + myDiffuseColorF->setColor( model->color(Material_Model::Diffuse) ); + // Load diffuse coefficient + myDiffuseCoefntF->setValue( model->coefficient(Material_Model::Diffuse) ); } + + // Specular reflection type + isReflectionTypeActive = model->hasSpecularReflection(); + mySpecularGroupF->setChecked( isReflectionTypeActive ); + if ( isReflectionTypeActive ) { + // Load specular color + mySpecularColorF->setColor( model->color(Material_Model::Specular) ); + // Load specular coefficient + mySpecularCoefntF->setValue( model->coefficient(Material_Model::Specular) ); + } + + // Emission reflection type + isReflectionTypeActive = model->hasEmissionReflection(); + myEmissionGroupF->setChecked( isReflectionTypeActive ); + if ( isReflectionTypeActive ) { + // Load emission color + myEmissionColorF->setColor( model->color(Material_Model::Emission) ); + // Load emission coefficient + myEmissionCoefntF->setValue( model->coefficient(Material_Model::Emission) ); + } + + // Shininess + myShininessF->setValue( model->shininess() ); + + //Physical + myMaterialPhysicalCheck->setChecked( model->isPhysical() ); + } /*! - \brief Save values from dialog box fields to material model - \param model material model + \brief Save values from dialog box fields material model + \param model material model to be filled */ void GEOMToolsGUI_MaterialPropertiesDlg::toModel( Material_Model* model ) const { if ( !model ) return; - if ( isFrontTabActive() ) - toFrontModel( model ); - else - toBackModel( model ); -} - -/*! - \brief Save values from dialog box fields to front material model - \param model front material model to be filled -*/ -void GEOMToolsGUI_MaterialPropertiesDlg::toFrontModel( Material_Model* model ) const -{ - if ( !model ) return; - // "Ambient" reflection type if ( myAmbientGroupF->isChecked() ) { model->setColor( Material_Model::Ambient, myAmbientColorF->color() ); @@ -778,59 +553,9 @@ void GEOMToolsGUI_MaterialPropertiesDlg::toFrontModel( Material_Model* model ) c // Shininess model->setShininess( myShininessF->value() ); -} -/*! - \brief Save values from dialog box fields to back material model - \param model back material model to be filled -*/ -void GEOMToolsGUI_MaterialPropertiesDlg::toBackModel( Material_Model* model ) const -{ - if ( !model ) - return; - - // "Ambient" reflection type - if ( myAmbientGroupB->isChecked() ) { - model->setColor( Material_Model::Ambient, myAmbientColorB->color() ); - model->setCoefficient( Material_Model::Ambient, myAmbientCoefntB->value() ); - } - else { - model->removeColor( Material_Model::Ambient ); - model->removeCoefficient( Material_Model::Ambient ); - } - - // "Diffuse" reflection type - if ( myDiffuseGroupB->isChecked() ) { - model->setColor( Material_Model::Diffuse, myDiffuseColorB->color() ); - model->setCoefficient( Material_Model::Diffuse, myDiffuseCoefntB->value() ); - } - else { - model->removeColor( Material_Model::Diffuse ); - model->removeCoefficient( Material_Model::Diffuse ); - } - - // "Specular" reflection type - if ( mySpecularGroupB->isChecked() ) { - model->setColor( Material_Model::Specular, mySpecularColorB->color() ); - model->setCoefficient( Material_Model::Specular, mySpecularCoefntB->value() ); - } - else { - model->removeColor( Material_Model::Specular ); - model->removeCoefficient( Material_Model::Specular ); - } - - // "Emission" reflection type - if ( myEmissionGroupB->isChecked() ) { - model->setColor( Material_Model::Emission, myEmissionColorB->color() ); - model->setCoefficient( Material_Model::Emission, myEmissionCoefntB->value() ); - } - else { - model->removeColor( Material_Model::Emission ); - model->removeCoefficient( Material_Model::Emission ); - } - - // Shininess - model->setShininess( myShininessB->value() ); + //Type + model->setPhysical( myMaterialPhysicalCheck->isChecked()? true : false ); } /*! @@ -861,15 +586,6 @@ QString GEOMToolsGUI_MaterialPropertiesDlg::findUniqueName( const QString& name, return found || addSuffix ? QString( "%1 %2" ).arg( name ).arg( idx+1 ) : name; } -/*! - \brief Check if tab with front material properties is currently active - \return true if front material tab is active -*/ -bool GEOMToolsGUI_MaterialPropertiesDlg::isFrontTabActive() const -{ - return ( myMaterialTab->currentIndex() == 0 ? true : false ); -} - /*! \brief Called when "Apply" button is pressed */ @@ -878,9 +594,7 @@ void GEOMToolsGUI_MaterialPropertiesDlg::onApply() // save user materials resourceMgr()->save(); - toFrontModel( myCurrentModelF ); - if ( myBackMaterialCheck->isChecked() && myIsBTabWasActivated ) - toBackModel( myCurrentModelB ); + toModel( myCurrentModelF ); SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() ); if ( !app ) @@ -908,10 +622,7 @@ void GEOMToolsGUI_MaterialPropertiesDlg::onApply() // Parse material properties and form a string for persistent purpose QString aMaterialF = myCurrentModelF->getMaterialProperty(); - QString aMaterialB; - if ( myBackMaterialCheck->isChecked() ) - aMaterialB = myCurrentModelB->getMaterialProperty(); - + if ( myViewerType == VTK ) { // Get material properties from the current model /* @@ -919,10 +630,7 @@ void GEOMToolsGUI_MaterialPropertiesDlg::onApply() if ( !unsetMaterial ) aPropertyF = myCurrentModelF->getMaterialVTKProperty(); */ - vtkProperty* aPropertyF = myCurrentModelF->getMaterialVTKProperty(); - vtkProperty* aPropertyB = aPropertyF; - if ( myBackMaterialCheck->isChecked() ) - aPropertyB = myCurrentModelB->getMaterialVTKProperty(); + GEOM_VTKPropertyMaterial* aPropertyF = myCurrentModelF->getMaterialVTKProperty(); SVTK_ViewWindow* vtkVW = dynamic_cast( window ); if ( !vtkVW ) @@ -939,11 +647,18 @@ void GEOMToolsGUI_MaterialPropertiesDlg::onApply() else // Set material for the selected shape */ - aView->SetMaterial( It.Value(), aPropertyF, aPropertyB ); + aView->SetMaterial( It.Value(), (vtkProperty*) aPropertyF ); + // Restore color for not physical materials + PropMap aPropMap = aStudy->getObjectPropMap( aMgrId, It.Value()->getEntry() ); + if( !myMaterialPhysicalCheck->isChecked() && aPropMap.contains(COLOR_PROP) ) { + aView->SetColor(It.Value(), aPropMap.value(COLOR_PROP).value()); + } + int aDispModeId = aPropMap.value(DISPLAY_MODE_PROP).toInt(); + aView->SetDisplayMode(aDispModeId); + // eWireframe - 0, eShading - 1, eShadingWithEdges - 3 // Persistent - aStudy->setObjectProperty( aMgrId, It.Value()->getEntry(), FRONT_MATERIAL_PROP, aMaterialF ); - aStudy->setObjectProperty( aMgrId, It.Value()->getEntry(), BACK_MATERIAL_PROP, aMaterialB ); + aStudy->setObjectProperty( aMgrId, It.Value()->getEntry(), MATERIAL_PROP, aMaterialF ); } // for... aView->Repaint(); GeometryGUI::Modified(); @@ -957,9 +672,6 @@ void GEOMToolsGUI_MaterialPropertiesDlg::onApply() aMatF = myCurrentModelF->getMaterialOCCAspect(); */ Graphic3d_MaterialAspect aMatF = myCurrentModelF->getMaterialOCCAspect(); - Graphic3d_MaterialAspect aMatB = aMatF; - if ( myBackMaterialCheck->isChecked() ) - aMatB = myCurrentModelB->getMaterialOCCAspect(); Handle(GEOM_AISShape) aisShape; @@ -984,27 +696,13 @@ void GEOMToolsGUI_MaterialPropertiesDlg::onApply() aisShape->UnsetMaterial(); else */ - if ( myBackMaterialCheck->isChecked() ) { - // Set front material for the selected shape - aisShape->SetCurrentFacingModel(Aspect_TOFM_FRONT_SIDE); - aisShape->SetMaterial(aMatF); - // Set back material for the selected shape - aisShape->SetCurrentFacingModel(Aspect_TOFM_BACK_SIDE); - aisShape->SetMaterial(aMatB); - // Return to the default facing mode - aisShape->SetCurrentFacingModel(Aspect_TOFM_BOTH_SIDE); - } - else { - // Set the same front and back (is equal to front) materials for the selected shape - aisShape->SetMaterial(aMatF); - } + aisShape->SetMaterial(aMatF); if (aisShape->DisplayMode() != AIS_Shaded/*aisShape->DisplayMode() == GEOM_AISShape::ShadingWithEdges*/) ic->RecomputePrsOnly( aisShape, Standard_False ); // Persistent - aStudy->setObjectProperty( aMgrId, It.Value()->getEntry(), FRONT_MATERIAL_PROP, aMaterialF ); - aStudy->setObjectProperty( aMgrId, It.Value()->getEntry(), BACK_MATERIAL_PROP, aMaterialB ); + aStudy->setObjectProperty( aMgrId, It.Value()->getEntry(), MATERIAL_PROP, aMaterialF ); } } // for... ic->UpdateCurrentViewer(); @@ -1036,58 +734,6 @@ void GEOMToolsGUI_MaterialPropertiesDlg::onHelp() } } -/*! - \brief Called when user check/uncheck "Enable back material" check box - \param theIsChecked the check state of the check box -*/ -void GEOMToolsGUI_MaterialPropertiesDlg::onBackMaterialChecked( bool theIsChecked ) -{ - if ( theIsChecked ) { - // Tab with back material properties is displayed - myMaterialTab->addTab( myMaterialBWidget, tr( "Back material" ) ); - - // Create a current model of back material - if ( !myCurrentModelB ) { - myCurrentModelB = new Material_Model(); - myCurrentModelB->fromResources( SUIT_Session::session()->resourceMgr(), "Geometry", false ); - } - - myMaterialListBId = 0; - } - else { - // Tab with back material properties is hidden - myMaterialTab->removeTab( 1 ); - - // Remove the current model for back material - if ( myCurrentModelB ) { - delete myCurrentModelB; - myCurrentModelB = 0; - } - } -} - -/*! - \brief Called when user activates material tab - \param theIndex the index of the tab which was activated by the user -*/ -void GEOMToolsGUI_MaterialPropertiesDlg::onCurrentTabChanged(int theIndex) -{ - blockSignals( true ); - - // Change selection in the list of materials - if ( isFrontTabActive() ) - myMaterialList->setCurrentRow( myMaterialListFId ); - else if ( myBackMaterialCheck->isChecked() ) - myMaterialList->setCurrentRow( myMaterialListBId ); - - if ( theIndex == 1 ) - myIsBTabWasActivated = true; - - blockSignals( false ); - - onMaterialChanged(); -} - /*! \brief Called when user selects any material item in the materials list */ @@ -1100,22 +746,17 @@ void GEOMToolsGUI_MaterialPropertiesDlg::onMaterialChanged() Material_Model* model = 0; - bool isFrontTab = isFrontTabActive(); - - if ( isFrontTab ) - myMaterialListFId = myMaterialList->currentRow(); - else - myMaterialListBId = myMaterialList->currentRow(); + myMaterialListFId = myMaterialList->currentRow(); switch ( type ) { case Current: // current material - model = ( isFrontTab ? myCurrentModelF : myCurrentModelB ); + model = myCurrentModelF; break; case Default: // default material model = new Material_Model(); - model->fromResources( SUIT_Session::session()->resourceMgr(), "Geometry", ( isFrontTab ? true : false ) ); + model->fromResources( SUIT_Session::session()->resourceMgr(), "Geometry" ); break; case Global: case User: @@ -1142,13 +783,11 @@ void GEOMToolsGUI_MaterialPropertiesDlg::onChanged() QListWidgetItem* item = myMaterialList->currentItem(); int type = item->data( TypeRole ).toInt(); - bool isFrontTab = isFrontTabActive(); - // for the current and user schemas do not perform any actions if ( type == Current ) { - Material_Model model = ( isFrontTab ? *( myCurrentModelF ) : *( myCurrentModelB ) ); + Material_Model model = *(myCurrentModelF); toModel( &model ); - model.save( 0, QString(), isFrontTab ); + model.save( 0, QString() ); blockSignals( true ); fromModel( &model ); blockSignals( false ); @@ -1158,11 +797,11 @@ void GEOMToolsGUI_MaterialPropertiesDlg::onChanged() toModel( &model ); QString oldName = item->data( NameRole ).toString(), newName = item->text(); if ( oldName == newName ) { - model.save( resourceMgr(), oldName, isFrontTab ); + model.save( resourceMgr(), oldName ); } else { resourceMgr()->remove( oldName ); - model.save( resourceMgr(), newName, isFrontTab ); + model.save( resourceMgr(), newName ); item->setData( NameRole, newName ); } blockSignals( true ); @@ -1181,15 +820,11 @@ void GEOMToolsGUI_MaterialPropertiesDlg::onChanged() Material_Model model; toModel( &model ); - model.save( resourceMgr(), newName, isFrontTab ); + model.save( resourceMgr(), newName ); myMaterialList->setCurrentItem( item ); - if ( isFrontTab ) - myMaterialListFId = myMaterialList->currentRow(); - else - myMaterialListBId = myMaterialList->currentRow(); - + myMaterialListFId = myMaterialList->currentRow(); } } @@ -1220,7 +855,7 @@ void GEOMToolsGUI_MaterialPropertiesDlg::onReflectionTypeToggled( bool theIsOn ) QColor c; - // Make changes on front material tab + // Make changes on material tab if ( anObj == myAmbientGroupF ) { myAmbientColorF->setColor( c ); myAmbientCoefntF->setValue( 0.0 ); @@ -1237,24 +872,6 @@ void GEOMToolsGUI_MaterialPropertiesDlg::onReflectionTypeToggled( bool theIsOn ) myEmissionColorF->setColor( c ); myEmissionCoefntF->setValue( 0.0 ); } - - // Make changes on back material tab - if ( anObj == myAmbientGroupB ) { - myAmbientColorB->setColor( c ); - myAmbientCoefntB->setValue( 0.0 ); - } - else if ( anObj == myDiffuseGroupB ) { - myDiffuseColorB->setColor( c ); - myDiffuseCoefntB->setValue( 0.0 ); - } - else if ( anObj == mySpecularGroupB ) { - mySpecularColorB->setColor( c ); - mySpecularCoefntB->setValue( 0.0 ); - } - else if ( anObj == myEmissionGroupB ) { - myEmissionColorB->setColor( c ); - myEmissionCoefntB->setValue( 0.0 ); - } emit( changed() ); } diff --git a/src/GEOMToolsGUI/GEOMToolsGUI_MaterialPropertiesDlg.h b/src/GEOMToolsGUI/GEOMToolsGUI_MaterialPropertiesDlg.h index e53a029e6..f2df86420 100644 --- a/src/GEOMToolsGUI/GEOMToolsGUI_MaterialPropertiesDlg.h +++ b/src/GEOMToolsGUI/GEOMToolsGUI_MaterialPropertiesDlg.h @@ -70,15 +70,11 @@ private: void fromModel( Material_Model* ); void toModel( Material_Model* ) const; - void toFrontModel( Material_Model* ) const; - void toBackModel( Material_Model* ) const; QString findUniqueName( const QString&, QListWidgetItem* = 0, bool = false ); - bool isFrontTabActive() const; - signals: void materialChanged(); void changed(); @@ -88,8 +84,6 @@ private slots: void onApply(); void onHelp(); - void onBackMaterialChecked( bool ); - void onCurrentTabChanged( int ); void onMaterialChanged(); void onChanged(); void onItemChanged( QListWidgetItem* ); @@ -99,23 +93,17 @@ private: Material_ResourceMgr* myResMgr; - QCheckBox* myBackMaterialCheck; + QCheckBox* myMaterialPhysicalCheck; - //! Current material model for front material + //! Current material model for material Material_Model* myCurrentModelF; - //! Current material model for back material - Material_Model* myCurrentModelB; - QListWidget* myMaterialList; int myMaterialListFId; - int myMaterialListBId; QTabWidget* myMaterialTab; - QWidget* myMaterialBWidget; - bool myIsBTabWasActivated; - //! Controls defining front material properties + //! Controls defining material properties QGroupBox* myAmbientGroupF; QtxColorButton* myAmbientColorF; QtxDoubleSpinBox* myAmbientCoefntF; @@ -134,25 +122,6 @@ private: QtxDoubleSpinBox* myShininessF; - //! Controls defining back material properties - QGroupBox* myAmbientGroupB; - QtxColorButton* myAmbientColorB; - QtxDoubleSpinBox* myAmbientCoefntB; - - QGroupBox* myDiffuseGroupB; - QtxColorButton* myDiffuseColorB; - QtxDoubleSpinBox* myDiffuseCoefntB; - - QGroupBox* mySpecularGroupB; - QtxColorButton* mySpecularColorB; - QtxDoubleSpinBox* mySpecularCoefntB; - - QGroupBox* myEmissionGroupB; - QtxColorButton* myEmissionColorB; - QtxDoubleSpinBox* myEmissionCoefntB; - - QtxDoubleSpinBox* myShininessB; - QString myHelpFileName; ViewerType myViewerType; diff --git a/src/Material/Makefile.am b/src/Material/Makefile.am index ae98e6205..c0c43367f 100644 --- a/src/Material/Makefile.am +++ b/src/Material/Makefile.am @@ -46,6 +46,7 @@ libMaterial_la_CPPFLAGS = \ -I$(srcdir)/../OBJECT libMaterial_la_LDFLAGS = -lVTKViewer -lOCCViewer -lsuit -lSalomeApp \ + ../OBJECT/libGEOMObject.la \ $(GUI_LDFLAGS) -lqtx \ $(QT_MT_LIBS) \ $(CAS_LDFLAGS) -lTKV3d -lTKGeomBase \ diff --git a/src/Material/Material_Model.cxx b/src/Material/Material_Model.cxx index 4f9655744..28456fbfa 100644 --- a/src/Material/Material_Model.cxx +++ b/src/Material/Material_Model.cxx @@ -24,6 +24,7 @@ #include "Material_Model.h" #include "Material_ResourceMgr.h" +#include "GEOM_VTKPropertyMaterial.hxx" #include #include @@ -33,9 +34,6 @@ // OCCT Includes #include -// VTK includes -#include - /*! \brief Constructor @@ -45,6 +43,7 @@ Material_Model::Material_Model() : myResourceMgr( 0 ) { myShininess = 0.0; + myIsPhysical = false; } /*! @@ -96,8 +95,18 @@ Material_Model* Material_Model::getMaterialModel( QStringList theProps ) bool ok; double aCoef = aProp.right( aProp.length() - (anId+aPropName.length()) ).toDouble(&ok); if ( ok ) - aModel->setShininess( aCoef ); + 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 ); + } } return aModel; @@ -171,6 +180,11 @@ QString Material_Model::getMaterialProperty() 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; @@ -228,6 +242,7 @@ Graphic3d_MaterialAspect Material_Model::getMaterialOCCAspect() } // Shininess aMat.SetShininess( shininess() ); + aMat.SetMaterialType(isPhysical() ? Graphic3d_MATERIAL_PHYSIC : Graphic3d_MATERIAL_ASPECT); return aMat; } @@ -237,10 +252,10 @@ Graphic3d_MaterialAspect Material_Model::getMaterialOCCAspect() \return VTK property with correspondent material properties */ -vtkProperty* Material_Model::getMaterialVTKProperty() +GEOM_VTKPropertyMaterial* Material_Model::getMaterialVTKProperty() { // Get material properties from the current model - vtkProperty* aProperty = vtkProperty::New(); + GEOM_VTKPropertyMaterial* aProperty = GEOM_VTKPropertyMaterial::New(); bool isReflectionTypeActive; QColor c; @@ -272,6 +287,8 @@ vtkProperty* Material_Model::getMaterialVTKProperty() } // Shininess aProperty->SetSpecularPower( shininess()*100.0 ); + //Type + aProperty->SetPhysical( isPhysical() ); return aProperty; } @@ -298,6 +315,9 @@ void Material_Model::initDefaults() // Set default shininess setShininess( 0.039 ); + + // Set default type - artificial + setPhysical( false ); } /*! @@ -308,6 +328,7 @@ void Material_Model::clearModel() myColors.clear(); myCoefficients.clear(); myShininess = 0.0; + myIsPhysical = false; } /*! @@ -319,12 +340,10 @@ void Material_Model::clearModel() \param theResMgr resources manager \param theResSection resources section name - \param theIsFront if True, it is front material, else it is back material \sa save() */ void Material_Model::fromResources( QtxResourceMgr* theResMgr, - const QString& theResSection, - bool theIsFront ) + const QString& theResSection/*, bool theIsFront*/ ) { // Clear current content of the model // before setting properties from resources @@ -338,19 +357,11 @@ void Material_Model::fromResources( QtxResourceMgr* theResMgr, return; if ( theResSection.compare( "Geometry" ) == 0 ) { - if ( theIsFront ) { - myResourceSection = theResMgr->stringValue("Geometry", "front_material", "Gold"); - } - else { - myResourceSection = theResMgr->stringValue("Geometry", "back_material", ""); - if ( myResourceSection.isEmpty() ) - myResourceSection = theResMgr->stringValue("Geometry", "front_material", "Gold"); - } - + myResourceSection = theResMgr->stringValue("Geometry", "material", "Gold"); myResourceMgr = new Material_ResourceMgr(); } - QString section = resourceSection( theIsFront ); + QString section = resourceSection(); // If there is no material preference in XML files, // use the default material hardcoded in material model @@ -399,6 +410,11 @@ void Material_Model::fromResources( QtxResourceMgr* theResMgr, if ( resourceMgr()->hasValue( section, "shininess" ) ) { setShininess( resourceMgr()->doubleValue( section, "shininess" ) ); } + + // Set type: physical or artificial + if ( resourceMgr()->hasValue( section, "physical" ) ) { + setPhysical( resourceMgr()->booleanValue( section, "physical" ) ); + } } /*! @@ -409,19 +425,17 @@ void Material_Model::fromResources( QtxResourceMgr* theResMgr, \param theResMgr resources manager \param theResSection resources section name - \param theIsFront if True, it is front material, else it is back material \sa fromResources() */ void Material_Model::save( QtxResourceMgr* theResMgr, - const QString& theResSection, - bool theIsFront ) + const QString& theResSection) { if ( !theResMgr ) theResMgr = resourceMgr(); if ( !theResMgr ) return; - QString section = theResSection.isEmpty() ? resourceSection( theIsFront ) : theResSection; + QString section = theResSection.isEmpty() ? resourceSection() : theResSection; myResourceSection = section; if ( hasAmbientReflection() ) { @@ -478,6 +492,9 @@ void Material_Model::save( QtxResourceMgr* theResMgr, // Save shininess theResMgr->setValue( section, "shininess", shininess() ); + + // Save type: physical or artificial + theResMgr->setValue( section, "physical", isPhysical() ); } /*! @@ -495,20 +512,15 @@ QtxResourceMgr* Material_Model::resourceMgr() const \brief Get resources section name If section name is empty, default material name from "Geometry" section - is returned ("front_material" or "back_material" is used depending on - the parameter value) + is returned. - \param theIsFront the flag indicating that section of front or back material - is required \return resource section name passed previously to the fromResources() method \sa fromResources(), resourceMgr() */ -QString Material_Model::resourceSection( bool theIsFront ) const +QString Material_Model::resourceSection() const { return !myResourceSection.isEmpty() ? myResourceSection : - SUIT_Session::session()->resourceMgr()->stringValue("Geometry", - ( theIsFront ? "front_material" : "back_material" ), - "Gold"); + SUIT_Session::session()->resourceMgr()->stringValue("Geometry", "material", "Gold"); } /*! @@ -682,3 +694,25 @@ void Material_Model::setShininess( double theShininess) { myShininess = theShininess; } + +/*! + \brief Get type value: physical or artificial + \return True if the material is physical and False if the material is artificial + \sa setShininess() +*/ +bool Material_Model::isPhysical() const +{ + return myIsPhysical; +} + +/*! + \brief Set type: physical or artificial + + \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; +} + \ No newline at end of file diff --git a/src/Material/Material_Model.h b/src/Material/Material_Model.h index a2014a4f0..2ce233622 100644 --- a/src/Material/Material_Model.h +++ b/src/Material/Material_Model.h @@ -31,7 +31,7 @@ class Graphic3d_MaterialAspect; -class vtkProperty; +class GEOM_VTKPropertyMaterial; class QtxResourceMgr; @@ -57,14 +57,14 @@ public: QString getMaterialProperty(); Graphic3d_MaterialAspect getMaterialOCCAspect(); - vtkProperty* getMaterialVTKProperty(); + GEOM_VTKPropertyMaterial* getMaterialVTKProperty(); void initDefaults(); - void fromResources( QtxResourceMgr*, const QString& = QString(), bool theIsFront = true ); - void save( QtxResourceMgr* = 0, const QString& = QString(), bool theIsFront = true ); + void fromResources( QtxResourceMgr*, const QString& = QString()); + void save( QtxResourceMgr* = 0, const QString& = QString() ); QtxResourceMgr* resourceMgr() const; - QString resourceSection( bool theIsFront ) const; + QString resourceSection() const; bool hasAmbientReflection(); bool hasDiffuseReflection(); @@ -74,20 +74,23 @@ public: QColor color( ReflectionType ) const; void setColor( ReflectionType, const QColor& ); void setColor( QString, - QString, - ReflectionType ); + QString, + ReflectionType ); void removeColor( ReflectionType ); double coefficient( ReflectionType ) const; void setCoefficient( ReflectionType, double ); void setCoefficient( QString, - QString, - ReflectionType ); + QString, + ReflectionType ); void removeCoefficient( ReflectionType ); double shininess() const; void setShininess( double ); + bool isPhysical() const; + void setPhysical( bool ); + private: void clearModel(); @@ -103,6 +106,8 @@ private: double myShininess; + bool myIsPhysical; + }; #endif // MATERIAL_MODEL_H diff --git a/src/Material/resources/SalomeMaterial.xml b/src/Material/resources/SalomeMaterial.xml index 4dfa41716..579aa471c 100644 --- a/src/Material/resources/SalomeMaterial.xml +++ b/src/Material/resources/SalomeMaterial.xml @@ -30,6 +30,7 @@ +
@@ -39,6 +40,7 @@ +
@@ -48,6 +50,7 @@ +
@@ -55,6 +58,7 @@ +
@@ -64,6 +68,7 @@ +
@@ -73,6 +78,7 @@ +
@@ -82,6 +88,7 @@ +
@@ -91,6 +98,7 @@ +
@@ -100,6 +108,7 @@ +
@@ -109,6 +118,7 @@ +
@@ -118,6 +128,7 @@ +
@@ -127,6 +138,7 @@ +
@@ -136,6 +148,7 @@ +
@@ -145,6 +158,7 @@ +
@@ -156,6 +170,7 @@ +
@@ -165,6 +180,7 @@ +
@@ -174,6 +190,7 @@ +
@@ -183,5 +200,6 @@ +
diff --git a/src/OBJECT/GEOM_Actor.cxx b/src/OBJECT/GEOM_Actor.cxx index ff6142f45..a68e25b0e 100644 --- a/src/OBJECT/GEOM_Actor.cxx +++ b/src/OBJECT/GEOM_Actor.cxx @@ -113,8 +113,7 @@ GEOM_Actor::GEOM_Actor(): myHighlightProp(vtkProperty::New()), myPreHighlightProp(vtkProperty::New()), - myShadingFaceProp(vtkProperty::New()), - myShadingBackFaceProp(vtkProperty::New()) + myShadingFaceProp(vtkProperty::New()) { #ifdef MYDEBUG MESSAGE (this<< " GEOM_Actor::GEOM_Actor"); @@ -203,7 +202,6 @@ GEOM_Actor::~GEOM_Actor() myHighlightProp->Delete(); myPreHighlightProp->Delete(); myShadingFaceProp->Delete(); - myShadingBackFaceProp->Delete(); } GEOM_Actor* @@ -548,6 +546,7 @@ void GEOM_Actor::Render(vtkRenderer *ren, vtkMapper *theMapper) case eShadingWithEdges://shading with edges myPreHighlightProp->SetRepresentationToSurface(); myHighlightProp->SetRepresentationToSurface(); + myShadingFaceProp->SetRepresentationToSurface(); break; } @@ -555,17 +554,14 @@ void GEOM_Actor::Render(vtkRenderer *ren, vtkMapper *theMapper) if(myIsPreselected){ this->myHighlightActor->SetProperty(myPreHighlightProp.GetPointer()); myShadingFaceActor->SetProperty(myPreHighlightProp.GetPointer()); - myShadingFaceActor->SetBackfaceProperty(myPreHighlightProp.GetPointer()); } else { this->myHighlightActor->SetProperty(myShadingFaceProp.GetPointer()); myShadingFaceActor->SetProperty(myShadingFaceProp.GetPointer()); - myShadingFaceActor->SetBackfaceProperty(myShadingBackFaceProp.GetPointer()); } } else{ this->myHighlightActor->SetProperty(myHighlightProp.GetPointer()); myShadingFaceActor->SetProperty(myHighlightProp.GetPointer()); - myShadingFaceActor->SetBackfaceProperty(myHighlightProp.GetPointer()); } this->Property->Render(this, ren); @@ -676,7 +672,6 @@ void GEOM_Actor::SetOpacity(vtkFloatingPointType opa) { // enk:tested OK myShadingFaceProp->SetOpacity(opa); - myShadingBackFaceProp->SetOpacity(opa); myHighlightProp->SetOpacity(opa); myPreHighlightProp->SetOpacity(opa); myVertexActor->GetProperty()->SetOpacity(opa); @@ -692,7 +687,6 @@ void GEOM_Actor::SetColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloat { // enk:tested OK myShadingFaceProp->SetColor(r,g,b); // shading color (Shading) - myShadingBackFaceProp->SetColor(r,g,b); // back face shading color (Shading) myVertexActor->GetProperty()->SetColor(r,g,b); // vertex actor (Shading/Wireframe) if ( myDisplayMode != (int)eShadingWithEdges ) { myIsolatedEdgeActor->GetProperty()->SetColor(r,g,b); // standalone edge color (Wireframe) @@ -715,42 +709,23 @@ void GEOM_Actor::GetColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFlo void GEOM_Actor::SetMaterial(std::vector theProps) { - int aSize = theProps.size(); - - if ( aSize < 1 || aSize > 2) - return; - - // theProps[0] -- front material properties - // theProps[1] -- back material properties (if exist) - // If there are no back material properties, - // we get front material properties as back material - + // we set material properties as back and front material double aCoefnt; // Set reflection coefficients aCoefnt = theProps[0]->GetAmbient(); myShadingFaceProp->SetAmbient(aCoefnt); myVertexActor->GetProperty()->SetAmbient(aCoefnt); - if ( aSize == 2 ) - aCoefnt = theProps[1]->GetAmbient(); - myShadingBackFaceProp->SetAmbient(aCoefnt); // Set diffuse coefficients aCoefnt = theProps[0]->GetDiffuse(); myShadingFaceProp->SetDiffuse(aCoefnt); myVertexActor->GetProperty()->SetDiffuse(aCoefnt); - if ( aSize == 2 ) - aCoefnt = theProps[1]->GetDiffuse(); - myShadingBackFaceProp->SetDiffuse(aCoefnt); // Set specular coefficients aCoefnt = theProps[0]->GetSpecular(); myShadingFaceProp->SetSpecular(aCoefnt); myVertexActor->GetProperty()->SetSpecular(aCoefnt); - if ( aSize == 2 ) - aCoefnt = theProps[1]->GetSpecular(); - myShadingBackFaceProp->SetSpecular(aCoefnt); - double* aColor; @@ -758,48 +733,28 @@ void GEOM_Actor::SetMaterial(std::vector theProps) aColor = theProps[0]->GetAmbientColor(); myShadingFaceProp->SetAmbientColor(aColor[0], aColor[1], aColor[2]); myVertexActor->GetProperty()->SetAmbientColor(aColor[0], aColor[1], aColor[2]); - if ( aSize == 2 ) - aColor = theProps[1]->GetAmbientColor(); - myShadingBackFaceProp->SetAmbientColor(aColor[0], aColor[1], aColor[2]); // Set diffuse colors aColor = theProps[0]->GetDiffuseColor(); myShadingFaceProp->SetDiffuseColor(aColor[0], aColor[1], aColor[2]); myVertexActor->GetProperty()->SetDiffuseColor(aColor[0], aColor[1], aColor[2]); - if ( aSize == 2 ) - aColor = theProps[1]->GetDiffuseColor(); - myShadingBackFaceProp->SetDiffuseColor(aColor[0], aColor[1], aColor[2]); // Set specular colors aColor = theProps[0]->GetSpecularColor(); myShadingFaceProp->SetSpecularColor(aColor[0], aColor[1], aColor[2]); myVertexActor->GetProperty()->SetSpecularColor(aColor[0], aColor[1], aColor[2]); - if ( aSize == 2 ) - aColor = theProps[1]->GetSpecularColor(); - myShadingBackFaceProp->SetSpecularColor(aColor[0], aColor[1], aColor[2]); // Set shininess aCoefnt = theProps[0]->GetSpecularPower(); myShadingFaceProp->SetSpecularPower(aCoefnt); myVertexActor->GetProperty()->SetSpecularPower(aCoefnt); - if ( aSize == 2 ) - aCoefnt = theProps[1]->GetSpecularPower(); - myShadingBackFaceProp->SetSpecularPower(aCoefnt); - - // Set back face material property - myShadingFaceActor->SetBackfaceProperty(myShadingBackFaceProp.GetPointer()); } -vtkProperty* GEOM_Actor::GetFrontMaterial() +vtkProperty* GEOM_Actor::GetMaterial() { return myShadingFaceProp; } -vtkProperty* GEOM_Actor::GetBackMaterial() -{ - return myShadingBackFaceProp; -} - bool GEOM_Actor::IsInfinitive() { return ((bool)myShape.Infinite() || isOnlyVertex); diff --git a/src/OBJECT/GEOM_Actor.h b/src/OBJECT/GEOM_Actor.h index c80dec626..28df32d67 100644 --- a/src/OBJECT/GEOM_Actor.h +++ b/src/OBJECT/GEOM_Actor.h @@ -127,8 +127,7 @@ public: // Material void SetMaterial(std::vector theProps); - vtkProperty* GetFrontMaterial(); - vtkProperty* GetBackMaterial(); + vtkProperty* GetMaterial(); virtual bool IsInfinitive(); @@ -244,7 +243,6 @@ private: vtkSmartPointer myHighlightProp; vtkSmartPointer myPreHighlightProp; vtkSmartPointer myShadingFaceProp; - vtkSmartPointer myShadingBackFaceProp; PAppendFilter myAppendFilter; PPolyGeomPainterDataMapper myPolyDataMapper; diff --git a/src/OBJECT/GEOM_Constants.h b/src/OBJECT/GEOM_Constants.h index 7827d65d2..b890379e3 100644 --- a/src/OBJECT/GEOM_Constants.h +++ b/src/OBJECT/GEOM_Constants.h @@ -43,8 +43,7 @@ #define VECTOR_MODE_PROP "VectorMode" //Vector mode property #define DEFLECTION_COEFF_PROP "DeflectionCoeff" //Deflection coeff property #define MARKER_TYPE_PROP "MarkerType" //Marker type property -#define FRONT_MATERIAL_PROP "FrontMaterial" //Object front material property -#define BACK_MATERIAL_PROP "BackMaterial" //Object back material property +#define MATERIAL_PROP "Material" //Object material property #define EDGE_WIDTH_PROP "EdgeWidth" //Width of the edge #define ISOS_WIDTH_PROP "IsosWidth" //Width of the iso-lines #define TOP_LEVEL_PROP "TopLevelFlag" //Top level flag diff --git a/src/OBJECT/GEOM_DeviceActor.cxx b/src/OBJECT/GEOM_DeviceActor.cxx index eee3f74f7..266814569 100755 --- a/src/OBJECT/GEOM_DeviceActor.cxx +++ b/src/OBJECT/GEOM_DeviceActor.cxx @@ -73,20 +73,6 @@ GetProperty() return myActor->GetProperty(); } -void -GEOM_DeviceActor:: -SetBackfaceProperty(vtkProperty* theProperty) -{ - myActor->SetBackfaceProperty(theProperty); -} - -vtkProperty* -GEOM_DeviceActor:: -GetBackfaceProperty() -{ - return myActor->GetBackfaceProperty(); -} - void GEOM_DeviceActor:: SetVisibility(int theVisibility) diff --git a/src/OBJECT/GEOM_DeviceActor.h b/src/OBJECT/GEOM_DeviceActor.h index 5b96b4d65..8b36ab7ae 100755 --- a/src/OBJECT/GEOM_DeviceActor.h +++ b/src/OBJECT/GEOM_DeviceActor.h @@ -52,9 +52,6 @@ public: void SetProperty(vtkProperty* theProperty); vtkProperty* GetProperty(); - - void SetBackfaceProperty(vtkProperty* theProperty); - vtkProperty* GetBackfaceProperty(); void SetVisibility(int theVisibility); int GetVisibility(); diff --git a/src/OBJECT/GEOM_VTKPropertyMaterial.cxx b/src/OBJECT/GEOM_VTKPropertyMaterial.cxx new file mode 100755 index 000000000..cccaa1ef3 --- /dev/null +++ b/src/OBJECT/GEOM_VTKPropertyMaterial.cxx @@ -0,0 +1,39 @@ +// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// SALOME GEOM : +// File : GEOM_VTKPropertyMaterial.cxx + +#include "GEOM_VTKPropertyMaterial.hxx" + +#include + +vtkStandardNewMacro( GEOM_VTKPropertyMaterial ); + +GEOM_VTKPropertyMaterial::GEOM_VTKPropertyMaterial() +{ + Physical = false; +} + +GEOM_VTKPropertyMaterial::~GEOM_VTKPropertyMaterial() +{ +} diff --git a/src/OBJECT/GEOM_VTKPropertyMaterial.hxx b/src/OBJECT/GEOM_VTKPropertyMaterial.hxx new file mode 100755 index 000000000..c45c3f656 --- /dev/null +++ b/src/OBJECT/GEOM_VTKPropertyMaterial.hxx @@ -0,0 +1,52 @@ +// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// SALOME GEOM : +// File : GEOM_VTKPropertyMaterial.hxx + +#ifndef GEOM_VTKPropertyMaterial_H +#define GEOM_VTKPropertyMaterial_H + +#include "GEOM_OBJECT_defs.hxx" + +#include + +class GEOM_OBJECT_EXPORT GEOM_VTKPropertyMaterial : public vtkProperty +{ + +protected: + GEOM_VTKPropertyMaterial(); + virtual ~GEOM_VTKPropertyMaterial(); + +public: + vtkTypeMacro(GEOM_VTKPropertyMaterial, vtkProperty); + + vtkSetMacro(Physical, bool); + vtkGetMacro(Physical, bool); + + static GEOM_VTKPropertyMaterial* New(); + +protected: + bool Physical; +}; + +#endif diff --git a/src/OBJECT/Makefile.am b/src/OBJECT/Makefile.am index 1c45ee511..d777e8dd1 100644 --- a/src/OBJECT/Makefile.am +++ b/src/OBJECT/Makefile.am @@ -38,6 +38,7 @@ salomeinclude_HEADERS = \ Handle_GEOM_InteractiveObject.hxx \ GEOM_AISTrihedron.hxx \ GEOM_VTKTrihedron.hxx \ + GEOM_VTKPropertyMaterial.hxx \ GEOM_AISVector.hxx \ GEOM_OBJECT_defs.hxx \ GEOM_OCCReader.h \ @@ -56,6 +57,7 @@ dist_libGEOMObject_la_SOURCES = \ GEOM_InteractiveObject.cxx \ GEOM_AISTrihedron.cxx \ GEOM_VTKTrihedron.cxx \ + GEOM_VTKPropertyMaterial.cxx \ GEOM_AISVector.cxx \ GEOM_PainterPolyDataMapper.cxx \ GEOM_DeviceActor.cxx