From 28fa0e11294a3d05fde0420fdf9ffd348e5961b4 Mon Sep 17 00:00:00 2001 From: asv Date: Thu, 9 Feb 2006 14:35:50 +0000 Subject: [PATCH] bugs in save/restore visual parameters are being fixed.. --- src/SVTK/SVTK_ViewWindow.cxx | 7 +- src/SalomeApp/SalomeApp_Module.cxx | 159 ++++++++++++++++++++++++++++- src/SalomeApp/SalomeApp_Study.cxx | 4 - 3 files changed, 162 insertions(+), 8 deletions(-) diff --git a/src/SVTK/SVTK_ViewWindow.cxx b/src/SVTK/SVTK_ViewWindow.cxx index 450321585..106c485b8 100755 --- a/src/SVTK/SVTK_ViewWindow.cxx +++ b/src/SVTK/SVTK_ViewWindow.cxx @@ -660,7 +660,6 @@ SVTK_ViewWindow scale[0] = paramsLst[10].toDouble(); scale[1] = paramsLst[11].toDouble(); scale[2] = paramsLst[12].toDouble(); - bool isActive = (bool)paramsLst[13].toUShort(); // applying parameters vtkCamera* camera = getRenderer()->GetActiveCamera(); @@ -668,7 +667,11 @@ SVTK_ViewWindow camera->SetFocalPoint( focalPnt ); camera->SetViewUp( viewUp ); camera->SetParallelScale( parScale ); - getMainWindow()->GetRenderer()->GetTransform()->SetMatrixScale( scale[0], scale[1], scale[2] ); + SetScale( scale ); + + getRenderer()->ResetCameraClippingRange(); + Repaint(); + // getMainWindow()->GetRenderer()->GetTransform()->SetMatrixScale( scale[0], scale[1], scale[2] ); } } diff --git a/src/SalomeApp/SalomeApp_Module.cxx b/src/SalomeApp/SalomeApp_Module.cxx index abe7dfb4a..d32ea2210 100644 --- a/src/SalomeApp/SalomeApp_Module.cxx +++ b/src/SalomeApp/SalomeApp_Module.cxx @@ -11,6 +11,7 @@ #include "LightApp_Selection.h" #include "LightApp_Operation.h" #include "LightApp_Preferences.h" +#include "LightApp_Displayer.h" #include "CAM_DataModel.h" @@ -19,12 +20,24 @@ #include #include #include +#include + +#include "SALOMEDS_IParameters.hxx" #include +#include + +#include +#include +#include +#include #include #include +#include +#include + /*!Constructor.*/ SalomeApp_Module::SalomeApp_Module( const QString& name ) : LightApp_Module( name ) @@ -98,6 +111,23 @@ void SalomeApp_Module::extractContainers( const SALOME_ListIO& source, SALOME_Li } } +const char gSeparator = '_'; // character used to separate parameter names +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 * @@ -106,9 +136,97 @@ void SalomeApp_Module::extractContainers( const SALOME_ListIO& source, SALOME_Li */ void SalomeApp_Module::storeVisualParameters(int savePoint) { - cout << "SalomeApp_Module::storeVisualParameters" << endl; + 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(); + + // saving VTK actors' properties + if ( vmodel && vmodel->inherits( "SVTK_Viewer" ) ) { + 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; +} /*! * \brief Virtual public @@ -118,6 +236,43 @@ void SalomeApp_Module::storeVisualParameters(int savePoint) */ void SalomeApp_Module::restoreVisualParameters(int savePoint) { - cout << "SalomeApp_Module::restoreVisualParameters" << endl; + 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); + + QMap vtkActors; // actors are stored in a map after displaying of them for quicker access in future + + std::vector entries = ip.getEntries(); + for ( std::vector::iterator entIt = entries.begin(); entIt != entries.end(); ++entIt ) { + 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 ); + std::string viewIndexStr = ::getParam( *namesIt, ViewIndex ); + std::string paramName = ::getParam( *namesIt, ParamName ); + if ( viewerType == SVTK_Viewer::Type().latin1() ) { + cout << "--SVTK parameter: entry = " << *entIt << ", viewIndex = " << viewIndexStr << ", paramName = " << paramName << endl; + int viewIndex = QString( viewIndexStr.c_str() ).toUInt(); + QPtrList lst; + getApp()->viewManagers( SVTK_Viewer::Type(), lst ); + if ( viewIndex < lst.count() ) { + // for VTK ViewManager always has 1 ViewWindow, so view index is number of view manager. + if ( paramName == "Visibility" && displayer() ) { + displayer()->Display( (*entIt).c_str() ); + + SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) lst.at( viewIndex )->getActiveView(); + vtkView->getRenderer()->ResetCameraClippingRange(); + vtkView->Repaint(); + + vtkActors[(*entIt).c_str()] = getActor( *entIt, vtkView ); // store displayed actor + } + } // if view index less then VTK view managers size + } // if SVTK + } // for names/parameters iterator + } // for entries iterator } diff --git a/src/SalomeApp/SalomeApp_Study.cxx b/src/SalomeApp/SalomeApp_Study.cxx index 3164f40c7..6f7fd1298 100644 --- a/src/SalomeApp/SalomeApp_Study.cxx +++ b/src/SalomeApp/SalomeApp_Study.cxx @@ -785,8 +785,6 @@ int SalomeApp_Study::storeState() //================================================================ void SalomeApp_Study::restoreState(int savePoint) { - cout << "SalomeApp_Study::restoreState: " << savePoint << endl; - _PTR(AttributeParameter) ap = studyDS()->GetCommonParameters("Interface Applicative", savePoint); SALOMEDS_IParameters ip(ap); @@ -843,9 +841,7 @@ void SalomeApp_Study::restoreState(int savePoint) if (application()->desktop()) viewWin->resize( (int)( application()->desktop()->width() * 0.6 ), (int)( application()->desktop()->height() * 0.6 ) ); viewWin->setCaption(ip.getValue(viewerEntry, j).c_str()); - viewWin->setVisualParameters(ip.getValue(viewerEntry, j+1).c_str()); - viewWin->show(); sprintf(buffer, "%s_%d", viewerID.c_str(), j); string viewEntry(buffer); if (!activeView && viewEntry == activeViewID) { -- 2.39.2