From e9bcd4fa6aeec7cd0616cf82c466e2e7c0fb74dd Mon Sep 17 00:00:00 2001 From: asv Date: Wed, 8 Feb 2006 09:42:46 +0000 Subject: [PATCH] improved store/restore visual parameters. --- src/SVTK/SVTK_ViewWindow.cxx | 92 +++++++++++++++++++++++++++++++ src/SVTK/SVTK_ViewWindow.h | 18 ++++++ src/SalomeApp/SalomeApp_Study.cxx | 46 ++++++++++------ 3 files changed, 138 insertions(+), 18 deletions(-) diff --git a/src/SVTK/SVTK_ViewWindow.cxx b/src/SVTK/SVTK_ViewWindow.cxx index b95a23d20..450321585 100755 --- a/src/SVTK/SVTK_ViewWindow.cxx +++ b/src/SVTK/SVTK_ViewWindow.cxx @@ -41,6 +41,7 @@ #include "SUIT_Accel.h" #include "VTKViewer_Utilities.h" +#include "VTKViewer_Transform.h" #include "SVTK_View.h" #include "SVTK_MainWindow.h" @@ -597,3 +598,94 @@ SVTK_ViewWindow myMainWindow->InvokeEvent( anEvent, 0 ); } } + +/*! The method returns the visual parameters of this view as a formated string + */ +QString +SVTK_ViewWindow +::getVisualParameters() +{ + double pos[3], focalPnt[3], viewUp[3], parScale, scale[3]; + + vtkCamera* camera = getRenderer()->GetActiveCamera(); + camera->GetPosition( pos ); + camera->GetFocalPoint( focalPnt ); + camera->GetViewUp( viewUp ); + parScale = camera->GetParallelScale(); + GetScale( scale ); + + QString retStr; + retStr.sprintf( "%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e", + pos[0], pos[1], pos[2], focalPnt[0], focalPnt[1], focalPnt[2], viewUp[0], viewUp[1], + viewUp[2], parScale, scale[0], scale[1], scale[2] ); + return retStr; +} + +/* The method restores visual parameters of this view or postpones it untill the view is shown + */ +void +SVTK_ViewWindow +::setVisualParameters( const QString& parameters ) +{ + SVTK_RenderWindowInteractor* anInteractor = getMainWindow()->GetInteractor(); + if ( anInteractor->isVisible() ) { + doSetVisualParameters( parameters ); + } + else { + myVisualParams = parameters; + anInteractor->installEventFilter(this); + } +} + +/* The method restores visual parameters of this view from a formated string + */ +void +SVTK_ViewWindow +::doSetVisualParameters( const QString& parameters ) +{ + QStringList paramsLst = QStringList::split( '*', parameters, true ); + if ( paramsLst.size() == 13 ) { + // 'reading' list of parameters + double pos[3], focalPnt[3], viewUp[3], parScale, scale[3]; + pos[0] = paramsLst[0].toDouble(); + pos[1] = paramsLst[1].toDouble(); + pos[2] = paramsLst[2].toDouble(); + focalPnt[0] = paramsLst[3].toDouble(); + focalPnt[1] = paramsLst[4].toDouble(); + focalPnt[2] = paramsLst[5].toDouble(); + viewUp[0] = paramsLst[6].toDouble(); + viewUp[1] = paramsLst[7].toDouble(); + viewUp[2] = paramsLst[8].toDouble(); + parScale = paramsLst[9].toDouble(); + 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(); + camera->SetPosition( pos ); + camera->SetFocalPoint( focalPnt ); + camera->SetViewUp( viewUp ); + camera->SetParallelScale( parScale ); + getMainWindow()->GetRenderer()->GetTransform()->SetMatrixScale( scale[0], scale[1], scale[2] ); + } +} + + +//================================================================ +// Function : eventFilter +/*! Purpose : delayed setVisualParameters +*/ +//================================================================ +bool SVTK_ViewWindow::eventFilter( QObject* theWatched, QEvent* theEvent ) +{ + if ( theEvent->type() == QEvent::Show && theWatched->inherits( "SVTK_RenderWindowInteractor" ) ) { + SVTK_RenderWindowInteractor* anInteractor = (SVTK_RenderWindowInteractor*)theWatched; + if ( anInteractor->isVisible() ) { + doSetVisualParameters( myVisualParams ); + anInteractor->removeEventFilter( this ); // theWatched = RenderWindowInteractor + } + } + return SUIT_ViewWindow::eventFilter( theWatched, theEvent ); +} diff --git a/src/SVTK/SVTK_ViewWindow.h b/src/SVTK/SVTK_ViewWindow.h index 1fc559c78..8b7d8fad4 100755 --- a/src/SVTK/SVTK_ViewWindow.h +++ b/src/SVTK/SVTK_ViewWindow.h @@ -242,6 +242,19 @@ class SVTK_EXPORT SVTK_ViewWindow : public SUIT_ViewWindow void SetSelectionTolerance(const double& theTolNodes = 0.025, const double& theTolCell = 0.001); + + //! Methods to save/restore visual parameters of a view (pan, zoom, etc.) + virtual + QString + getVisualParameters(); + + virtual + void + setVisualParameters( const QString& parameters ); + + virtual + bool + eventFilter( QObject*, QEvent* ); public slots: virtual @@ -326,12 +339,17 @@ protected: Initialize(SVTK_View* theView, SVTK_ViewModelBase* theModel); + void + doSetVisualParameters( const QString& ); + QImage dumpView(); virtual void action( const int ); SVTK_View* myView; SVTK_MainWindow* myMainWindow; SVTK_ViewModelBase* myModel; + + QString myVisualParams; // used for delayed setting of view parameters }; #ifdef WIN32 diff --git a/src/SalomeApp/SalomeApp_Study.cxx b/src/SalomeApp/SalomeApp_Study.cxx index f7eaf1ac9..be30d0d19 100644 --- a/src/SalomeApp/SalomeApp_Study.cxx +++ b/src/SalomeApp/SalomeApp_Study.cxx @@ -31,6 +31,7 @@ #include #include +#include #include "utilities.h" #include @@ -669,7 +670,7 @@ vector SalomeApp_Study::getSavePoints() } //================================================================ -// Function : removeSavePoint +// Function :removeSavePoint /*! Purpose : remove a given save point */ //================================================================ @@ -738,7 +739,7 @@ int SalomeApp_Study::storeState() viewerEntry+="_"; viewerEntry+=buffer; - int viewerID = ip.append("AP_VIEWERS_LIST", viewerEntry); + /*int viewerID = */ip.append("AP_VIEWERS_LIST", viewerEntry); QPtrVector views = vm->getViews(); for(int i = 0; iviewManagers(lst); - for(QPtrListIterator it(lst); it.current(); ++it) { + for (QPtrListIterator it(lst); it.current(); ++it) { SUIT_ViewManager* vm = it.current(); - if(vm) ((SalomeApp_Application*)application())->removeViewManager(vm); + if (vm) + ((SalomeApp_Application*)application())->removeViewManager(vm); } //Restore the viewers @@ -804,14 +806,14 @@ void SalomeApp_Study::restoreState(int savePoint) SUIT_ViewWindow *viewWin = 0, *activeView = 0; - for(int i = 0; i < nbViewers; i++) { + for (int i = 0; i < nbViewers; i++) { string viewerEntry = ip.getValue("AP_VIEWERS_LIST", i); vector veiewerParams = ip.parseValue(viewerEntry,'_'); string type = veiewerParams[0]; string viewerID = veiewerParams[1]; SUIT_ViewManager* vm = ((SalomeApp_Application*)application())->newViewManager(type.c_str()); - if(!vm) continue; //Unknown viewer - + if (!vm) + continue; //Unknown viewer int nbViews = (ip.nbValues(viewerEntry))/2; @@ -822,44 +824,52 @@ void SalomeApp_Study::restoreState(int savePoint) } int viewCount = vm->getViewsCount(); - if(viewCount != nbViews) { + if (viewCount != nbViews) { cout << "Unknow error, Can't create a view!" << endl; continue; } //Resize the views, set their captions and apply visual parameters. QPtrVector views = vm->getViews(); - for(int i = 0, j = 0; idesktop()) + if ( !viewWin ) + continue; + + // wait untill the window is really shown. This step fixes MANY bugs.. + while ( !viewWin->isVisible() ) + qApp->processEvents(); + + 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) activeView = viewWin; + if (!activeView && viewEntry == activeViewID) { + activeView = viewWin; + } } } //Set focus to an active view window - if(activeView) { - activeView->show(); - activeView->raise(); + if (activeView) { activeView->setActiveWindow(); - activeView->setFocus(); + activeView->setFocus(); } vector v = ip.getValues("AP_MODULES_LIST"); - for(int i = 0; iactivateModule(v[i].c_str()); SalomeApp_Module* module = (SalomeApp_Module*)(((SalomeApp_Application*)application())->activeModule()); module->restoreVisualParameters(savePoint); } QString activeModuleName(ip.getProperty("AP_ACTIVE_MODULE").c_str()); - if(activeModuleName != "") ((SalomeApp_Application*)application())->activateModule(activeModuleName); + if (activeModuleName != "") + ((SalomeApp_Application*)application())->activateModule(activeModuleName); } QString SalomeApp_Study::getVisulDump(int savePoint) -- 2.39.2