#include "LightApp_SelectionMgr.h"
#include "LightApp_VTKSelector.h"
#include "LightApp_Preferences.h"
+#include "LightApp_Displayer.h"
#include "VVTK_ViewManager.h"
#include "VVTK_ViewWindow.h"
#include "VVTK_MainWindow.h"
#include "VISU_View_i.hh"
+#include "SALOMEDS_IParameters.hxx"
+
#include <qaction.h>
#include <vtkRenderer.h>
}
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<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
+ if( !study )
+ return;
+ _PTR(AttributeParameter) ap = study->studyDS()->GetModuleParameters("Interface Applicative", moduleName().latin1(), savePoint);
+ SALOMEDS_IParameters ip(ap);
+
+ QPtrList<SUIT_ViewManager> lst;
+ getApp()->viewManagers( lst );
+ int vtkViewers( 0 );
+ for ( QPtrListIterator<SUIT_ViewManager> 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<SUIT_ViewWindow> views = vman->getViews();
+ for ( int i = 0, iEnd = vman->getViewsCount(); i < iEnd; i++ ) {
+ SVTK_ViewWindow* vtkView = dynamic_cast<SVTK_ViewWindow*>( 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<SalomeApp_Study*>( 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<QString, QMap<int, SALOME_Actor*> > vtkActors; // map: entry to map: view_id to actor
+
+ std::vector<std::string> entries = ip.getEntries();
+
+ for ( std::vector<std::string>::iterator entIt = entries.begin(); entIt != entries.end(); ++entIt ) {
+ QString entry( (*entIt).c_str() );
+ std::vector<std::string> paramNames = ip.getAllParameterNames( *entIt );
+ std::vector<std::string> paramValues = ip.getAllParameterValues( *entIt );
+ std::vector<std::string>::iterator namesIt = paramNames.begin();
+ std::vector<std::string>::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<SUIT_ViewManager> 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<SALOME_View*>( 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<int, SALOME_Actor*> 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<SUIT_ViewManager> lst;
+ getApp()->viewManagers( lst );
+ for ( QPtrListIterator<SUIT_ViewManager> 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
+}
+