mirror of
https://git.salome-platform.org/gitpub/modules/geom.git
synced 2025-02-14 03:33:07 +05:00
Improve material management (performance issues)
This commit is contained in:
parent
52f5e304e4
commit
a81cc8e71d
@ -213,28 +213,21 @@ int GEOMGUI_Selection::typeId( const int index ) const
|
||||
|
||||
bool GEOMGUI_Selection::isVisible( const int index ) const
|
||||
{
|
||||
#ifdef USE_VISUAL_PROP_MAP
|
||||
QVariant v = visibleProperty( entry( index ), GEOM::propertyName( GEOM::Visibility ) );
|
||||
if ( v.canConvert( QVariant::Bool ) )
|
||||
return v.toBool();
|
||||
#endif
|
||||
|
||||
bool res = false;
|
||||
|
||||
#ifdef USE_VISUAL_PROP_MAP
|
||||
bool found = false;
|
||||
QVariant v = visibleProperty( entry( index ), GEOM::propertyName( GEOM::Visibility ) );
|
||||
if ( v.canConvert( QVariant::Bool ) ) {
|
||||
res = v.toBool();
|
||||
found = true;
|
||||
GEOM::GEOM_Object_var obj = getObject( index );
|
||||
SALOME_View* view = GEOM_Displayer::GetActiveView();
|
||||
if ( !CORBA::is_nil( obj ) && view ) {
|
||||
Handle(SALOME_InteractiveObject) io = new SALOME_InteractiveObject( entry( index ).toLatin1().constData(), "GEOM", "TEMP_IO" );
|
||||
res = view->isVisible( io );
|
||||
}
|
||||
|
||||
if ( !found ) {
|
||||
#endif
|
||||
GEOM::GEOM_Object_var obj = getObject( index );
|
||||
SALOME_View* view = GEOM_Displayer::GetActiveView();
|
||||
if ( !CORBA::is_nil( obj ) && view ) {
|
||||
Handle(SALOME_InteractiveObject) io = new SALOME_InteractiveObject( entry( index ).toLatin1().constData(), "GEOM", "TEMP_IO" );
|
||||
res = view->isVisible( io );
|
||||
}
|
||||
#ifdef USE_VISUAL_PROP_MAP
|
||||
}
|
||||
#endif
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -288,6 +281,7 @@ QString GEOMGUI_Selection::displayMode( const int index ) const
|
||||
{
|
||||
QString res;
|
||||
QString viewType = activeViewType();
|
||||
|
||||
#ifdef USE_VISUAL_PROP_MAP
|
||||
QVariant v = visibleProperty( entry( index ), GEOM::propertyName( GEOM::DisplayMode ) );
|
||||
if ( v.canConvert( QVariant::Int ) ) {
|
||||
@ -297,113 +291,103 @@ QString GEOMGUI_Selection::displayMode( const int index ) const
|
||||
} else if ( viewType == SVTK_Viewer::Type() ) {
|
||||
VTK_DISPLAY_MODE_TO_STRING( res, dm );
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
if ( res.isEmpty() ) {
|
||||
#endif
|
||||
SALOME_View* view = GEOM_Displayer::GetActiveView();
|
||||
if ( view /*fix for 9320==>*/&& ( viewType == OCCViewer_Viewer::Type() || viewType == SVTK_Viewer::Type() ) ) {
|
||||
SALOME_Prs* prs = view->CreatePrs( entry( index ).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() ) {
|
||||
int dm;
|
||||
Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(io);
|
||||
if(!aSh.IsNull()) {
|
||||
dm = aSh->isTopLevel() ? aSh->prevDisplayMode() : aSh->DisplayMode();
|
||||
} else {
|
||||
dm = io->DisplayMode();
|
||||
}
|
||||
|
||||
SALOME_View* view = GEOM_Displayer::GetActiveView();
|
||||
if ( view /*fix for 9320==>*/&& ( viewType == OCCViewer_Viewer::Type() || viewType == SVTK_Viewer::Type() ) ) {
|
||||
SALOME_Prs* prs = view->CreatePrs( entry( index ).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() ) {
|
||||
int dm;
|
||||
Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(io);
|
||||
if(!aSh.IsNull()) {
|
||||
dm = aSh->isTopLevel() ? aSh->prevDisplayMode() : aSh->DisplayMode();
|
||||
} else {
|
||||
dm = io->DisplayMode();
|
||||
}
|
||||
OCC_DISPLAY_MODE_TO_STRING( res, dm );
|
||||
if ( res.isEmpty() ) { // return default display mode of AIS_InteractiveContext
|
||||
OCCViewer_Viewer* occViewer = (OCCViewer_Viewer*)SUIT_Session::session()->activeApplication()->
|
||||
desktop()->activeWindow()->getViewManager()->getViewModel();
|
||||
Handle(AIS_InteractiveContext) ic = occViewer->getAISContext();
|
||||
dm = ic->DisplayMode();
|
||||
OCC_DISPLAY_MODE_TO_STRING( res, dm );
|
||||
if ( res.isEmpty() ) { // return default display mode of AIS_InteractiveContext
|
||||
OCCViewer_Viewer* occViewer = (OCCViewer_Viewer*)SUIT_Session::session()->activeApplication()->
|
||||
desktop()->activeWindow()->getViewManager()->getViewModel();
|
||||
Handle(AIS_InteractiveContext) ic = occViewer->getAISContext();
|
||||
dm = ic->DisplayMode();
|
||||
OCC_DISPLAY_MODE_TO_STRING( res, dm );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ( viewType == SVTK_Viewer::Type() ) { // assuming VTK
|
||||
SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
|
||||
vtkActorCollection* lst = vtkPrs ? vtkPrs->GetObjects() : 0;
|
||||
if ( lst ) {
|
||||
lst->InitTraversal();
|
||||
vtkActor* actor = lst->GetNextActor();
|
||||
if ( actor ) {
|
||||
SALOME_Actor* salActor = dynamic_cast<SALOME_Actor*>( actor );
|
||||
if ( salActor ) {
|
||||
int dm = salActor->getDisplayMode();
|
||||
VTK_DISPLAY_MODE_TO_STRING( res, dm );
|
||||
} // if ( salome actor )
|
||||
} // if ( actor )
|
||||
} // if ( lst == vtkPrs->GetObjects() )
|
||||
} // if VTK
|
||||
}
|
||||
else if ( viewType == SVTK_Viewer::Type() ) { // assuming VTK
|
||||
SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
|
||||
vtkActorCollection* lst = vtkPrs ? vtkPrs->GetObjects() : 0;
|
||||
if ( lst ) {
|
||||
lst->InitTraversal();
|
||||
vtkActor* actor = lst->GetNextActor();
|
||||
if ( actor ) {
|
||||
SALOME_Actor* salActor = dynamic_cast<SALOME_Actor*>( actor );
|
||||
if ( salActor ) {
|
||||
int dm = salActor->getDisplayMode();
|
||||
VTK_DISPLAY_MODE_TO_STRING( res, dm );
|
||||
} // if ( salome actor )
|
||||
} // if ( actor )
|
||||
} // if ( lst == vtkPrs->GetObjects() )
|
||||
} // if VTK
|
||||
}
|
||||
|
||||
#ifdef USE_VISUAL_PROP_MAP
|
||||
}
|
||||
#endif
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
bool GEOMGUI_Selection::isVectorsMode( const int index ) const
|
||||
{
|
||||
bool res = false;
|
||||
|
||||
#ifdef USE_VISUAL_PROP_MAP
|
||||
bool found = false;
|
||||
QVariant v = visibleProperty( entry( index ), GEOM::propertyName( GEOM::EdgesDirection ) );
|
||||
if ( v.canConvert( QVariant::Bool ) ) {
|
||||
res = v.toBool();
|
||||
found = true;
|
||||
}
|
||||
|
||||
if ( !found ) {
|
||||
if ( v.canConvert( QVariant::Bool ) )
|
||||
return v.toBool();
|
||||
#endif
|
||||
SALOME_View* view = GEOM_Displayer::GetActiveView();
|
||||
QString viewType = activeViewType();
|
||||
if ( view && ( viewType == OCCViewer_Viewer::Type() || viewType == SVTK_Viewer::Type() ) ) {
|
||||
SALOME_Prs* prs = view->CreatePrs( entry( index ).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 = aSh->isShowVectors();
|
||||
}
|
||||
}
|
||||
} else if ( viewType == SVTK_Viewer::Type() ) { // assuming VTK
|
||||
SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
|
||||
vtkActorCollection* lst = vtkPrs ? vtkPrs->GetObjects() : 0;
|
||||
if ( lst ) {
|
||||
lst->InitTraversal();
|
||||
vtkActor* actor = lst->GetNextActor();
|
||||
if ( actor ) {
|
||||
GEOM_Actor* aGeomActor = GEOM_Actor::SafeDownCast(actor);
|
||||
if ( aGeomActor )
|
||||
res = aGeomActor->GetVectorMode();
|
||||
}
|
||||
|
||||
bool res = false;
|
||||
|
||||
SALOME_View* view = GEOM_Displayer::GetActiveView();
|
||||
QString viewType = activeViewType();
|
||||
if ( view && ( viewType == OCCViewer_Viewer::Type() || viewType == SVTK_Viewer::Type() ) ) {
|
||||
SALOME_Prs* prs = view->CreatePrs( entry( index ).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 = aSh->isShowVectors();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ( viewType == SVTK_Viewer::Type() ) { // assuming VTK
|
||||
SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
|
||||
vtkActorCollection* lst = vtkPrs ? vtkPrs->GetObjects() : 0;
|
||||
if ( lst ) {
|
||||
lst->InitTraversal();
|
||||
vtkActor* actor = lst->GetNextActor();
|
||||
if ( actor ) {
|
||||
GEOM_Actor* aGeomActor = GEOM_Actor::SafeDownCast(actor);
|
||||
if ( aGeomActor )
|
||||
res = aGeomActor->GetVectorMode();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifdef USE_VISUAL_PROP_MAP
|
||||
}
|
||||
#endif
|
||||
|
||||
return res;
|
||||
}
|
||||
@ -548,35 +532,31 @@ QString GEOMGUI_Selection::selectionMode() const
|
||||
return "";
|
||||
}
|
||||
|
||||
bool GEOMGUI_Selection::topLevel( const int index ) const {
|
||||
bool GEOMGUI_Selection::topLevel( const int index ) const
|
||||
{
|
||||
#ifdef USE_VISUAL_PROP_MAP
|
||||
QVariant v = visibleProperty( entry( index ), GEOM::propertyName( GEOM::TopLevel ) );
|
||||
if ( v.canConvert<bool>() )
|
||||
return v.toBool();
|
||||
#endif
|
||||
|
||||
bool res = false;
|
||||
|
||||
#ifdef USE_VISUAL_PROP_MAP
|
||||
bool found = false;
|
||||
QVariant v = visibleProperty( entry( index ), GEOM::propertyName( GEOM::TopLevel ) );
|
||||
if ( v.canConvert<bool>() ) {
|
||||
res = v.toBool();
|
||||
found = true;
|
||||
}
|
||||
|
||||
if ( !found ) {
|
||||
#endif
|
||||
SALOME_View* view = GEOM_Displayer::GetActiveView();
|
||||
QString viewType = activeViewType();
|
||||
if ( view && viewType == OCCViewer_Viewer::Type() ) {
|
||||
SALOME_Prs* prs = view->CreatePrs( entry( index ).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->isTopLevel();
|
||||
}
|
||||
SALOME_View* view = GEOM_Displayer::GetActiveView();
|
||||
QString viewType = activeViewType();
|
||||
if ( view && viewType == OCCViewer_Viewer::Type() ) {
|
||||
SALOME_Prs* prs = view->CreatePrs( entry( index ).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->isTopLevel();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -585,57 +565,55 @@ bool GEOMGUI_Selection::topLevel( const int index ) const {
|
||||
return res;
|
||||
}
|
||||
|
||||
bool GEOMGUI_Selection::isPhysicalMaterial( const int idx ) const{
|
||||
bool res = false;
|
||||
|
||||
bool GEOMGUI_Selection::isPhysicalMaterial( const int idx ) const
|
||||
{
|
||||
#ifdef USE_VISUAL_PROP_MAP
|
||||
bool found = false;
|
||||
QVariant v = visibleProperty( entry( idx ), GEOM::propertyName( GEOM::Material ) );
|
||||
if ( v.canConvert<QString>() ) {
|
||||
Material_Model material;
|
||||
material.fromProperties( v.toString() );
|
||||
res = material.isPhysical();
|
||||
found = true;
|
||||
}
|
||||
|
||||
if ( !found ) {
|
||||
QVariant v = visibleProperty( entry( idx ), GEOM::propertyName( GEOM::Material ) );
|
||||
if ( v.canConvert<QString>() ) {
|
||||
Material_Model material;
|
||||
material.fromProperties( v.toString() );
|
||||
return material.isPhysical();
|
||||
}
|
||||
#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_TOFM_BOTH_SIDE).MaterialType( Graphic3d_MATERIAL_PHYSIC );
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ( viewType == SVTK_Viewer::Type() ) { // assuming VTK
|
||||
SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( 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;
|
||||
|
||||
bool res = false;
|
||||
|
||||
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_TOFM_BOTH_SIDE).MaterialType( Graphic3d_MATERIAL_PHYSIC );
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ( viewType == SVTK_Viewer::Type() ) { // assuming VTK
|
||||
SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( 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;
|
||||
}
|
||||
|
@ -207,6 +207,8 @@ GeometryGUI::GeometryGUI() :
|
||||
|
||||
myDisplayer = 0;
|
||||
myLocalSelectionMode = GEOM_ALLOBJECTS;
|
||||
|
||||
connect( Material_ResourceMgr::resourceMgr(), SIGNAL( changed() ), this, SLOT( updateMaterials() ) );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
@ -603,16 +605,6 @@ void GeometryGUI::OnGUIEvent( int id, const QVariant& theParam )
|
||||
library->OnGUIEvent( id, desk );
|
||||
else
|
||||
library->OnGUIEvent( id, desk, theParam);
|
||||
// Update a list of materials for "Preferences" dialog
|
||||
if ( id == GEOMOp::OpMaterialProperties ) {
|
||||
LightApp_Preferences* pref = preferences();
|
||||
if ( pref ) {
|
||||
Material_ResourceMgr aMatResMgr;
|
||||
setPreferenceProperty( pref->rootItem()->findItem( tr( "PREF_MATERIAL" ), true )->id(),
|
||||
"strings",
|
||||
aMatResMgr.materials() );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
SUIT_MessageBox::critical( desk, tr( "GEOM_ERROR" ), tr( "GEOM_ERR_LIB_NOT_FOUND" ), tr( "GEOM_BUT_OK" ) );
|
||||
@ -1734,18 +1726,21 @@ void GeometryGUI::contextMenuPopup( const QString& client, QMenu* menu, QString&
|
||||
QString curModel = "";
|
||||
if ( v.canConvert<QString>() ) curModel = v.toString();
|
||||
// get list of all predefined materials
|
||||
Material_ResourceMgr aMatResMgr;
|
||||
QStringList matNameList = aMatResMgr.materials();
|
||||
foreach ( QString name, matNameList )
|
||||
QStringList materials = Material_ResourceMgr::resourceMgr()->materials();
|
||||
bool found = false;
|
||||
foreach ( QString material, materials )
|
||||
{
|
||||
QAction* menAct = matMenu->addAction( name );
|
||||
QAction* menAct = matMenu->addAction( material );
|
||||
connect(menAct, SIGNAL( toggled( bool ) ), signalMapper, SLOT( map() ) );
|
||||
signalMapper->setMapping( menAct, name );
|
||||
signalMapper->setMapping( menAct, material );
|
||||
menAct->setCheckable( true );
|
||||
// Set checked if this material is current
|
||||
Material_Model aModel;
|
||||
aModel.fromResources( name );
|
||||
menAct->setChecked( aModel.toProperties() == curModel );
|
||||
aModel.fromResources( material );
|
||||
if ( !found && aModel.toProperties() == curModel ) {
|
||||
menAct->setChecked( true );
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
matMenu->insertAction( matMenu->addSeparator(), action( GEOMOp::OpPredefMaterCustom ) );
|
||||
matMenu->insertSeparator( action( GEOMOp::OpPredefMaterCustom ) );
|
||||
@ -1818,12 +1813,12 @@ void GeometryGUI::createPreferences()
|
||||
int defl = addPreference( tr( "PREF_DEFLECTION" ), genGroup,
|
||||
LightApp_Preferences::DblSpin, "Geometry", "deflection_coeff" );
|
||||
|
||||
int predef_materials = addPreference( tr( "PREF_PREDEF_MATERIALS" ), genGroup,
|
||||
LightApp_Preferences::Bool, "Geometry", "predef_materials" );
|
||||
addPreference( tr( "PREF_PREDEF_MATERIALS" ), genGroup,
|
||||
LightApp_Preferences::Bool, "Geometry", "predef_materials" );
|
||||
|
||||
int material = addPreference( tr( "PREF_MATERIAL" ), genGroup,
|
||||
LightApp_Preferences::Selector,
|
||||
"Geometry", "material" );
|
||||
LightApp_Preferences::Selector,
|
||||
"Geometry", "material" );
|
||||
|
||||
addPreference( tr( "PREF_EDITGROUP_COLOR" ), genGroup,
|
||||
LightApp_Preferences::Color, "Geometry", "editgroup_color" );
|
||||
@ -1942,11 +1937,8 @@ void GeometryGUI::createPreferences()
|
||||
setPreferenceProperty( defl, "step", 1.0e-04 );
|
||||
setPreferenceProperty( defl, "precision", 6 );
|
||||
|
||||
// Set property for 'Show predefined materials'
|
||||
setPreferenceProperty( predef_materials, "eval", true);
|
||||
// Set property for default material
|
||||
Material_ResourceMgr aMatResMgr;
|
||||
setPreferenceProperty( material, "strings", aMatResMgr.materials() );
|
||||
setPreferenceProperty( material, "strings", Material_ResourceMgr::resourceMgr()->materials() );
|
||||
|
||||
// Set property vertex marker type
|
||||
QList<QVariant> aMarkerTypeIndicesList;
|
||||
@ -2396,3 +2388,22 @@ bool GeometryGUI::renameObject( const QString& entry, const QString& name)
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void GeometryGUI::updateMaterials()
|
||||
{
|
||||
LightApp_Preferences* pref = preferences();
|
||||
if ( pref ) {
|
||||
QStringList materials = Material_ResourceMgr::resourceMgr()->materials();
|
||||
QString currentMaterial = SUIT_Session::session()->resourceMgr()->stringValue( "Geometry", "material" );
|
||||
if ( !materials.contains( currentMaterial ) )
|
||||
// user material set as default in the preferences, might be removed
|
||||
SUIT_Session::session()->resourceMgr()->setValue( "Geometry", "material", QString( "Plastic" ) );
|
||||
|
||||
QtxPreferenceItem* prefItem = pref->rootItem()->findItem( tr( "PREF_MATERIAL" ), true );
|
||||
if ( prefItem ) {
|
||||
setPreferenceProperty( prefItem->id(),
|
||||
"strings", materials );
|
||||
prefItem->retrieve();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -152,6 +152,7 @@ private slots:
|
||||
void onWindowActivated( SUIT_ViewWindow* );
|
||||
void onViewAboutToShow();
|
||||
void OnSetMaterial( const QString& );
|
||||
void updateMaterials();
|
||||
|
||||
signals :
|
||||
void SignalDeactivateActiveDialog();
|
||||
|
@ -36,6 +36,12 @@ dist_libMaterial_la_SOURCES = \
|
||||
Material_Model.cxx \
|
||||
Material_ResourceMgr.cxx
|
||||
|
||||
MOC_FILES = \
|
||||
Material_ResourceMgr_moc.cxx
|
||||
|
||||
nodist_libMaterial_la_SOURCES = \
|
||||
$(MOC_FILES)
|
||||
|
||||
# additional information to compile and link file
|
||||
libMaterial_la_CPPFLAGS = \
|
||||
$(QT_INCLUDES) \
|
||||
|
@ -25,6 +25,8 @@
|
||||
#include "GEOM_VTKPropertyMaterial.hxx"
|
||||
#include "Material_ResourceMgr.h"
|
||||
|
||||
#include <QMutexLocker>
|
||||
|
||||
/*!
|
||||
\brief Constructor
|
||||
|
||||
@ -184,7 +186,7 @@ QString Material_Model::toProperties()
|
||||
\param resMgr resource manager (if not specified, new resources manager is created)
|
||||
\sa toResources()
|
||||
*/
|
||||
void Material_Model::fromResources( const QString& material, QtxResourceMgr* resMgr )
|
||||
void Material_Model::fromResources( const QString& material, Material_ResourceMgr* resMgr )
|
||||
{
|
||||
static QString common = "[common]";
|
||||
|
||||
@ -194,15 +196,22 @@ void Material_Model::fromResources( const QString& material, QtxResourceMgr* res
|
||||
// material name is not specified: use default values
|
||||
if ( material.isEmpty() ) return;
|
||||
|
||||
bool ownResourcesMgr = resMgr == 0;
|
||||
|
||||
if ( ownResourcesMgr )
|
||||
resMgr = new Material_ResourceMgr();
|
||||
if ( !resMgr )
|
||||
resMgr = Material_ResourceMgr::resourceMgr();
|
||||
|
||||
// lock resources manager
|
||||
QMutexLocker lock( &resMgr->myMutex );
|
||||
|
||||
// read common section
|
||||
if ( material != common && resMgr->hasSection( common ) )
|
||||
fromResources( common, resMgr );
|
||||
read( common, resMgr );
|
||||
|
||||
// read material section
|
||||
read( material, resMgr );
|
||||
}
|
||||
|
||||
void Material_Model::read( const QString& material, Material_ResourceMgr* resMgr )
|
||||
{
|
||||
// physical
|
||||
if ( resMgr->hasValue( material, "physical" ) ) {
|
||||
setPhysical( resMgr->booleanValue( material, "physical" ) );
|
||||
@ -276,9 +285,6 @@ void Material_Model::fromResources( const QString& material, QtxResourceMgr* res
|
||||
if ( resMgr->hasValue( material, "emissive" ) ) {
|
||||
setReflection( Emissive, resMgr->booleanValue( material, "emissive" ) );
|
||||
}
|
||||
|
||||
if ( ownResourcesMgr )
|
||||
delete resMgr;
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -287,9 +293,12 @@ void Material_Model::fromResources( const QString& material, QtxResourceMgr* res
|
||||
\param resMgr resource manager
|
||||
\sa fromResources()
|
||||
*/
|
||||
void Material_Model::toResources( const QString& material, QtxResourceMgr* resMgr )
|
||||
void Material_Model::toResources( const QString& material, Material_ResourceMgr* resMgr )
|
||||
{
|
||||
if ( resMgr && !material.isEmpty() ) {
|
||||
// lock resources manager
|
||||
QMutexLocker lock( &resMgr->myMutex );
|
||||
|
||||
// remove resources section (to clean-up all previous properties)
|
||||
resMgr->remove( material );
|
||||
|
||||
|
@ -32,7 +32,7 @@
|
||||
|
||||
#include <Graphic3d_MaterialAspect.hxx>
|
||||
|
||||
class QtxResourceMgr;
|
||||
class Material_ResourceMgr;
|
||||
class GEOM_VTKPropertyMaterial;
|
||||
|
||||
class MATERIAL_SALOME_EXPORT Material_Model
|
||||
@ -51,8 +51,8 @@ public:
|
||||
|
||||
void fromProperties( const QString& );
|
||||
QString toProperties();
|
||||
void fromResources( const QString& = QString(), QtxResourceMgr* = 0 );
|
||||
void toResources( const QString&, QtxResourceMgr* );
|
||||
void fromResources( const QString& = QString(), Material_ResourceMgr* = 0 );
|
||||
void toResources( const QString&, Material_ResourceMgr* );
|
||||
|
||||
bool isPhysical() const;
|
||||
void setPhysical( bool );
|
||||
@ -77,6 +77,7 @@ public:
|
||||
|
||||
private:
|
||||
void init();
|
||||
void read( const QString&, Material_ResourceMgr* );
|
||||
|
||||
private:
|
||||
typedef struct {
|
||||
|
@ -22,6 +22,31 @@
|
||||
|
||||
#include "Material_ResourceMgr.h"
|
||||
|
||||
#include <QFileSystemWatcher>
|
||||
#include <QThread>
|
||||
|
||||
/*!
|
||||
\class Material_ResourceMgr::Updater
|
||||
\brief Updates the contents of the resource manager as soon as
|
||||
user materials database file is changed
|
||||
\internal
|
||||
*/
|
||||
class Material_ResourceMgr::Updater : public QThread
|
||||
{
|
||||
public:
|
||||
Material_ResourceMgr* myResourceMgr;
|
||||
Updater( Material_ResourceMgr* resMgr ) : myResourceMgr( resMgr )
|
||||
{
|
||||
start();
|
||||
}
|
||||
void run()
|
||||
{
|
||||
QMutexLocker lock( &myResourceMgr->myMutex );
|
||||
myResourceMgr->clear();
|
||||
myResourceMgr->load();
|
||||
}
|
||||
};
|
||||
|
||||
/*!
|
||||
\class Material_ResourceMgr
|
||||
\brief Material properties resources manager.
|
||||
@ -41,7 +66,8 @@
|
||||
\brief Constructor
|
||||
*/
|
||||
Material_ResourceMgr::Material_ResourceMgr()
|
||||
: QtxResourceMgr( "SalomeMaterial", "%1Config" )
|
||||
: QtxResourceMgr( "SalomeMaterial", "%1Config" ),
|
||||
myWatcher( 0 )
|
||||
{
|
||||
if ( dirList().isEmpty() && ::getenv( "GEOM_ROOT_DIR" ) )
|
||||
setDirList( QStringList() << Qtx::addSlash( ::getenv( "GEOM_ROOT_DIR" ) ) + "share/salome/resources/geom" );
|
||||
@ -53,6 +79,24 @@ Material_ResourceMgr::Material_ResourceMgr()
|
||||
*/
|
||||
Material_ResourceMgr::~Material_ResourceMgr()
|
||||
{
|
||||
watchUserFile( false );
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Get shared instance of resources manager
|
||||
|
||||
This instance of resource manager is global for the application;
|
||||
it watches for changes in the user materials database file to
|
||||
maintain the fresh version of the materials data.
|
||||
*/
|
||||
Material_ResourceMgr* Material_ResourceMgr::resourceMgr()
|
||||
{
|
||||
static Material_ResourceMgr* resMgr = 0;
|
||||
if ( !resMgr ) {
|
||||
resMgr = new Material_ResourceMgr();
|
||||
resMgr->watchUserFile( true );
|
||||
}
|
||||
return resMgr;
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -63,6 +107,8 @@ Material_ResourceMgr::~Material_ResourceMgr()
|
||||
*/
|
||||
QStringList Material_ResourceMgr::materials( MaterialType theType, bool theSort )
|
||||
{
|
||||
QMutexLocker lock( &myMutex );
|
||||
|
||||
// store original working mode
|
||||
WorkingMode m = workingMode();
|
||||
|
||||
@ -114,3 +160,34 @@ QStringList Material_ResourceMgr::materials( MaterialType theType, bool theSort
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Start/stop this resource manager watching the user materials database file.
|
||||
\internal
|
||||
*/
|
||||
void Material_ResourceMgr::watchUserFile( bool on )
|
||||
{
|
||||
if ( on ) {
|
||||
if ( !myWatcher ) {
|
||||
myWatcher = new QFileSystemWatcher( this );
|
||||
myWatcher->addPath( userFileName( appName() ) );
|
||||
connect( myWatcher, SIGNAL( fileChanged( QString ) ), this, SLOT( update() ) );
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ( myWatcher ) {
|
||||
delete myWatcher;
|
||||
myWatcher = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Update user database slot
|
||||
\internal
|
||||
*/
|
||||
void Material_ResourceMgr::update()
|
||||
{
|
||||
Updater( this ).wait();
|
||||
emit changed();
|
||||
}
|
||||
|
@ -25,10 +25,18 @@
|
||||
|
||||
#include "Material.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QMutex>
|
||||
#include <QtxResourceMgr.h>
|
||||
|
||||
class MATERIAL_SALOME_EXPORT Material_ResourceMgr : public QtxResourceMgr
|
||||
class QFileSystemWatcher;
|
||||
|
||||
class MATERIAL_SALOME_EXPORT Material_ResourceMgr : public QObject, public QtxResourceMgr
|
||||
{
|
||||
Q_OBJECT;
|
||||
|
||||
class Updater;
|
||||
|
||||
public:
|
||||
//! Material type
|
||||
typedef enum {
|
||||
@ -40,8 +48,24 @@ public:
|
||||
Material_ResourceMgr();
|
||||
~Material_ResourceMgr();
|
||||
|
||||
static Material_ResourceMgr* resourceMgr();
|
||||
|
||||
QStringList materials( MaterialType = All, bool = true );
|
||||
|
||||
|
||||
signals:
|
||||
void changed();
|
||||
|
||||
private:
|
||||
void watchUserFile( bool );
|
||||
|
||||
private slots:
|
||||
void update();
|
||||
|
||||
private:
|
||||
QFileSystemWatcher* myWatcher;
|
||||
QMutex myMutex;
|
||||
|
||||
friend class Material_Model;
|
||||
};
|
||||
|
||||
#endif // MATERIAL_RESOURCEMGR_H
|
||||
|
Loading…
Reference in New Issue
Block a user