From a7227cd69e46bbd8a7ca5594c5b874f49fc53f04 Mon Sep 17 00:00:00 2001 From: asv Date: Fri, 10 Feb 2006 09:37:34 +0000 Subject: [PATCH] save/restore visual parameters being implemented. --- src/VISUGUI/VisuGUI_Module.cxx | 210 +++++++++++++++++++++++++++++++++ src/VISUGUI/VisuGUI_Module.h | 9 ++ 2 files changed, 219 insertions(+) diff --git a/src/VISUGUI/VisuGUI_Module.cxx b/src/VISUGUI/VisuGUI_Module.cxx index f496c5dc..79f71258 100644 --- a/src/VISUGUI/VisuGUI_Module.cxx +++ b/src/VISUGUI/VisuGUI_Module.cxx @@ -43,6 +43,7 @@ #include "LightApp_SelectionMgr.h" #include "LightApp_VTKSelector.h" #include "LightApp_Preferences.h" +#include "LightApp_Displayer.h" #include "VVTK_ViewManager.h" #include "VVTK_ViewWindow.h" @@ -76,6 +77,8 @@ #include "VVTK_MainWindow.h" #include "VISU_View_i.hh" +#include "SALOMEDS_IParameters.hxx" + #include #include @@ -1661,3 +1664,210 @@ eventFilter( QObject * theWatched, QEvent * theEvent ) } return aRet; } + +const char gSeparator = '_'; // character used to separate parameter names +/*! + * \brief Virtual public + * + * This method is called just before the study document is saved, so the module has a possibility + * to store visual parameters in AttributeParameter attribue(s) + */ +void VisuGUI_Module::storeVisualParameters(int savePoint) +{ + SalomeApp_Study* study = dynamic_cast( SUIT_Session::session()->activeApplication()->activeStudy() ); + if( !study ) + return; + _PTR(AttributeParameter) ap = study->studyDS()->GetModuleParameters("Interface Applicative", moduleName().latin1(), savePoint); + SALOMEDS_IParameters ip(ap); + + QPtrList lst; + getApp()->viewManagers( lst ); + int vtkViewers( 0 ); + for ( QPtrListIterator it( lst ); it.current(); ++it ) { + SUIT_ViewManager* vman = it.current(); + SUIT_ViewModel* vmodel = vman->getViewModel(); + if ( !vmodel ) + continue; + + // saving VTK actors' properties + if ( vmodel->getType() == SVTK_Viewer::Type() || // processing SVTK and VVTK viewers + vmodel->getType() == VVTK_Viewer::Type() ) { // in the same way (VVTK_ViewWindow + // inherits SVTK_ViewWindow) + QPtrVector views = vman->getViews(); + for ( int i = 0, iEnd = vman->getViewsCount(); i < iEnd; i++ ) { + SVTK_ViewWindow* vtkView = dynamic_cast( views[i] ); + if ( vtkView ) { + vtkActorCollection* allActors = vtkView->getRenderer()->GetActors(); + allActors->InitTraversal(); + while ( vtkActor* actor = allActors->GetNextActor() ) { + if ( actor->GetVisibility() ) { // store only visible actors + if ( SALOME_Actor* salomeActor = SALOME_Actor::SafeDownCast( actor ) ) { + if ( salomeActor->hasIO() ) { // actor corresponds to existing obj + + Handle(SALOME_InteractiveObject) io = salomeActor->getIO(); + const char* entry = io->getEntry(); + const char* aName = salomeActor->getName(); + float opacity = salomeActor->GetOpacity(); + float r, g, b; + salomeActor->GetColor(r, g, b); + int repMode = salomeActor->GetRepresentation(); + int disMode = salomeActor->getDisplayMode(); + bool isInf = salomeActor->IsInfinitive(); + bool isShrunk = ( salomeActor->IsShrunkable() && salomeActor->IsShrunk() ); + + // printf (" -- actor: entry=%s, name=%s, opacity=%f, color=%d,%d,%d, repMode=%d, disMode=%d... -- \n", + // entry, aName, opacity, r, g, b, repMode, disMode ); + + QString param, vtkParam = vmodel->getType(); vtkParam += gSeparator; + vtkParam += QString::number( vtkViewers ); vtkParam += gSeparator; + param = vtkParam + "Visibility"; + ip.setParameter( entry, param.latin1(), "true" ); + param = vtkParam + "Name"; + ip.setParameter( entry, param.latin1(), aName ); + param = vtkParam + "Opacity"; + ip.setParameter( entry, param.latin1(), QString::number( opacity ).latin1() ); + param = vtkParam + "ColorRed"; + ip.setParameter( entry, param.latin1(), QString::number( r ).latin1() ); + param = vtkParam + "ColorGreen"; + ip.setParameter( entry, param.latin1(), QString::number( g ).latin1() ); + param = vtkParam + "ColorBlue"; + ip.setParameter( entry, param.latin1(), QString::number( b ).latin1() ); + param = vtkParam + "RepresentationMode"; + ip.setParameter( entry, param.latin1(), QString::number( repMode ).latin1() ); + param = vtkParam + "DisplayMode"; + ip.setParameter( entry, param.latin1(), QString::number( disMode ).latin1() ); + param = vtkParam + "IsInfitine"; + ip.setParameter( entry, param.latin1(), QString::number( isInf ).latin1() ); + param = vtkParam + "IsShrunk"; + ip.setParameter( entry, param.latin1(), QString::number( isShrunk ).latin1() ); + } // hasIO + } // salome_actor successfull downcast + } // isVisible + } // end of ..while.. actors traversal + } // if ( vtkView ) + } // for ( views ) + vtkViewers++; + } // if ( SVTK view model ) + } +} + +// returns SALOME_Actor with IO with given entry +SALOME_Actor* getActor( std::string entry, SVTK_ViewWindow* vtkView ) +{ + if ( vtkView && !entry.empty() ) { + vtkActorCollection* allActors = vtkView->getRenderer()->GetActors(); + allActors->InitTraversal(); + while ( vtkActor* actor = allActors->GetNextActor() ) { + if ( SALOME_Actor* salomeActor = SALOME_Actor::SafeDownCast( actor ) ) { + if ( salomeActor->hasIO() ) { // actor corresponds to existing obj + Handle(SALOME_InteractiveObject) io = salomeActor->getIO(); + if ( entry == io->getEntry() ) + return salomeActor; + } + } + } + } + return 0; +} + +const int ViewerType = 0; +const int ViewIndex = 1; +const int ParamName = 2; +// visual parameters are stored in strings as follows: +// ViewerType_ViewNumber_ParamName. '_' is used as separator and should not be used in +// viewer type or parameter names + +// return viewer type substring from parameter name +std::string getParam( const std::string& paramName, const int index ) +{ + QStringList lst = QStringList::split( gSeparator, QString( paramName.c_str() ) ); + if ( !lst.isEmpty() && index < lst.size() ) + return lst[index]; + return ""; +} + + +/*! + * \brief Virtual public + * + * This method is called after the study document is opened, so the module has a possibility to restore + * visual parameters + */ +void VisuGUI_Module::restoreVisualParameters(int savePoint) +{ + SalomeApp_Study* study = dynamic_cast( SUIT_Session::session()->activeApplication()->activeStudy() ); + if( !study ) + return; + _PTR(AttributeParameter) ap = study->studyDS()->GetModuleParameters("Interface Applicative", moduleName().latin1(), savePoint); + SALOMEDS_IParameters ip(ap); + + // actors are stored in a map after displaying of them for quicker access in future + QMap > vtkActors; // map: entry to map: view_id to actor + + std::vector entries = ip.getEntries(); + + for ( std::vector::iterator entIt = entries.begin(); entIt != entries.end(); ++entIt ) { + QString entry( (*entIt).c_str() ); + std::vector paramNames = ip.getAllParameterNames( *entIt ); + std::vector paramValues = ip.getAllParameterValues( *entIt ); + std::vector::iterator namesIt = paramNames.begin(); + std::vector::iterator valuesIt = paramValues.begin(); + + for ( ; namesIt != paramNames.end(); ++namesIt, ++valuesIt ) { + std::string viewerType = ::getParam( *namesIt, ViewerType ); + + if ( viewerType == SVTK_Viewer::Type().latin1() || + viewerType == VVTK_Viewer::Type().latin1() ) { + + std::string paramName = ::getParam( *namesIt, ParamName ); + bool ok; + std::string viewIndexStr = ::getParam( *namesIt, ViewIndex ); + int viewIndex = QString( viewIndexStr.c_str() ).toUInt( &ok ); + if ( !ok ) // bad conversion of view index to integer + continue; + + cout << "--SVTK parameter: entry = " << *entIt << ", paramName = " << paramName << endl; + + if ( paramName == "Visibility" && displayer() ) { + QPtrList lst; + getApp()->viewManagers( viewerType, lst ); + + // SVTK/VVTK ViewManager always has 1 ViewWindow, so view index is index of view manager + if ( viewIndex >= 0 && viewIndex < lst.count() ) { + SUIT_ViewManager* vman = lst.at( viewIndex ); + SUIT_ViewModel* vmodel = vman->getViewModel(); + // SVTK and VVTK view models can be casted to SALOME_View + displayer()->Display( entry, true, dynamic_cast( vmodel ) ); + SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) vman->getActiveView(); + // vtkView->getRenderer()->ResetCameraClippingRange(); + // vtkView->Repaint(); + + // store displayed actor so setting of color, opacity, etc. will be much faster + QMap viewActorMap; + if ( vtkActors.contains( entry ) ) + viewActorMap = vtkActors[ entry ]; + viewActorMap[ viewIndex ] = getActor( *entIt, vtkView ); + vtkActors[ entry ] = viewActorMap; + } + } // if view index less then VTK view managers size + } // if SVTK + } // for names/parameters iterator + } // for entries iterator + + // [ update all SVTK/VVTK views + QPtrList lst; + getApp()->viewManagers( lst ); + for ( QPtrListIterator it( lst ); it.current(); ++it ) { + SUIT_ViewManager* vman = it.current(); + SUIT_ViewModel* vmodel = vman->getViewModel(); + if ( !vmodel ) + continue; + if ( vmodel->getType() == SVTK_Viewer::Type() || // processing SVTK and VVTK viewers + vmodel->getType() == VVTK_Viewer::Type() ) { // in the same way + SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) vman->getActiveView(); + vtkView->getRenderer()->ResetCameraClippingRange(); + vtkView->Repaint(); + } + } // ] end of update views +} + diff --git a/src/VISUGUI/VisuGUI_Module.h b/src/VISUGUI/VisuGUI_Module.h index c13c8235..37360257 100644 --- a/src/VISUGUI/VisuGUI_Module.h +++ b/src/VISUGUI/VisuGUI_Module.h @@ -84,6 +84,15 @@ public: getViewManager(const QString& theType, const bool theIsCreate); + virtual + void + storeVisualParameters(int savePoint); + + virtual + void + restoreVisualParameters(int savePoint); + + public slots: //! Reimplemented method of the module deactivation. virtual -- 2.39.2