bool GEOMGUI_Selection::isVisible( const int index ) const
{
- 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;
- }
-
- if ( !found ) {
+ if ( v.canConvert( QVariant::Bool ) )
+ return v.toBool();
#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
+
+ bool res = false;
+
+ 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 );
}
-#endif
return res;
}
{
QString res;
QString viewType = activeViewType();
+
#ifdef USE_VISUAL_PROP_MAP
QVariant v = visibleProperty( entry( index ), GEOM::propertyName( GEOM::DisplayMode ) );
if ( v.canConvert( QVariant::Int ) ) {
} 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();
- }
+
+ 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();
+ }
+ }
+ 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;
}
return "";
}
-bool GEOMGUI_Selection::topLevel( const int index ) const {
- bool res = false;
-
+bool GEOMGUI_Selection::topLevel( const int index ) const
+{
#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 ) {
+ if ( v.canConvert<bool>() )
+ return v.toBool();
#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();
- }
+
+ bool res = false;
+
+ 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();
}
}
}
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;
}
myDisplayer = 0;
myLocalSelectionMode = GEOM_ALLOBJECTS;
+
+ connect( Material_ResourceMgr::resourceMgr(), SIGNAL( changed() ), this, SLOT( updateMaterials() ) );
}
//=======================================================================
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" ) );
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 ) );
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" );
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;
}
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();
+ }
+ }
+}
#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.
\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" );
*/
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;
}
/*!
*/
QStringList Material_ResourceMgr::materials( MaterialType theType, bool theSort )
{
+ QMutexLocker lock( &myMutex );
+
// store original working mode
WorkingMode m = workingMode();
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();
+}