#include "SUIT_Accel.h"
#include "VTKViewer_Utilities.h"
+#include "VTKViewer_Transform.h"
#include "SVTK_View.h"
#include "SVTK_MainWindow.h"
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 );
+}
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
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
#include <SUIT_ResourceMgr.h>
#include <qptrlist.h>
+#include <qapplication.h>
#include "utilities.h"
#include <iostream.h>
}
//================================================================
-// Function : removeSavePoint
+// Function :removeSavePoint
/*! Purpose : remove a given save point
*/
//================================================================
viewerEntry+="_";
viewerEntry+=buffer;
- int viewerID = ip.append("AP_VIEWERS_LIST", viewerEntry);
+ /*int viewerID = */ip.append("AP_VIEWERS_LIST", viewerEntry);
QPtrVector<SUIT_ViewWindow> views = vm->getViews();
for(int i = 0; i<view_count; i++) {
//Remove all already existent veiwers and their views
ViewManagerList lst;
((SalomeApp_Application*)application())->viewManagers(lst);
- for(QPtrListIterator<SUIT_ViewManager> it(lst); it.current(); ++it) {
+ for (QPtrListIterator<SUIT_ViewManager> 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
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<string> 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;
}
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<SUIT_ViewWindow> views = vm->getViews();
- for(int i = 0, j = 0; i<viewCount; i++, j+=1) {
+ for (int i = 0, j = 0; i<viewCount; i++, j++) {
viewWin = views[i];
- if(!viewWin) continue;
- if(application()->desktop())
+ 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<string> v = ip.getValues("AP_MODULES_LIST");
- for(int i = 0; i<v.size(); i++) {
+ for (int i = 0; i<v.size(); i++) {
((SalomeApp_Application*)application())->activateModule(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)