From b5ffd524bdd35644f79fd05f868b770788ee086a Mon Sep 17 00:00:00 2001 From: asv Date: Fri, 27 Jan 2006 09:28:48 +0000 Subject: [PATCH] implementation of get/setVisualParameters() functions. --- src/GLViewer/GLViewer_ViewFrame.cxx | 13 +++ src/GLViewer/GLViewer_ViewFrame.h | 3 + src/OCCViewer/OCCViewer_ViewWindow.cxx | 110 ++++++++++++++++++------- src/OCCViewer/OCCViewer_ViewWindow.h | 5 ++ src/Plot2d/Plot2d_ViewWindow.cxx | 13 +++ src/Plot2d/Plot2d_ViewWindow.h | 3 + src/VTKViewer/VTKViewer_ViewWindow.cxx | 53 ++++++++++++ src/VTKViewer/VTKViewer_ViewWindow.h | 3 + 8 files changed, 172 insertions(+), 31 deletions(-) diff --git a/src/GLViewer/GLViewer_ViewFrame.cxx b/src/GLViewer/GLViewer_ViewFrame.cxx index 6600bb35f..c72b71eb9 100644 --- a/src/GLViewer/GLViewer_ViewFrame.cxx +++ b/src/GLViewer/GLViewer_ViewFrame.cxx @@ -547,3 +547,16 @@ void GLViewer_ViewFrame::wheelEvent( QWheelEvent* e ) break; } } + +/*! The method returns the visual parameters of this view as a formated string + */ +QString GLViewer_ViewFrame::getVisualParameters() +{ + return " "; +} + +/* The method restors visual parameters of this view from a formated string + */ +void GLViewer_ViewFrame::setVisualParameters( const QString& parameters ) +{ +} diff --git a/src/GLViewer/GLViewer_ViewFrame.h b/src/GLViewer/GLViewer_ViewFrame.h index d90dfd3f5..8b9267a42 100644 --- a/src/GLViewer/GLViewer_ViewFrame.h +++ b/src/GLViewer/GLViewer_ViewFrame.h @@ -72,6 +72,9 @@ public: QSize sizeHint() const; virtual void onUpdate( int ); + + virtual QString getVisualParameters(); + virtual void setVisualParameters( const QString& parameters ); signals: void vfDrawExternal( QPainter* ); diff --git a/src/OCCViewer/OCCViewer_ViewWindow.cxx b/src/OCCViewer/OCCViewer_ViewWindow.cxx index 4900fd9de..d3e98ac4b 100755 --- a/src/OCCViewer/OCCViewer_ViewWindow.cxx +++ b/src/OCCViewer/OCCViewer_ViewWindow.cxx @@ -851,37 +851,7 @@ void OCCViewer_ViewWindow::onClipping( bool on ) //**************************************************************** void OCCViewer_ViewWindow::onMemorizeView() { - double centerX, centerY, projX, projY, projZ, twist; - double atX, atY, atZ, eyeX, eyeY, eyeZ; - - Handle(V3d_View) aView3d = myViewPort->getView(); - - aView3d->Center( centerX, centerY ); - aView3d->Proj( projX, projY, projZ ); - aView3d->At( atX, atY, atZ ); - aView3d->Eye( eyeX, eyeY, eyeZ ); - twist = aView3d->Twist(); - - viewAspect params; - QString aName = QTime::currentTime().toString() + QString::fromLatin1( " h:m:s" ); - - params.scale = aView3d->Scale(); - params.centerX = centerX; - params.centerY = centerY; - params.projX = projX; - params.projY = projY; - params.projZ = projZ; - params.twist = twist; - params.atX = atX; - params.atY = atY; - params.atZ = atZ; - params.eyeX = eyeX; - params.eyeY = eyeY; - params.eyeZ = eyeZ; - params.name = aName; - - myModel->appendViewAspect( params ); - + myModel->appendViewAspect( getViewParams() ); } //**************************************************************** @@ -980,3 +950,81 @@ void OCCViewer_ViewWindow::setCuttingPlane( bool on, const double x, const dou v->Update(); v->Redraw(); } + +/*! The method returns the visual parameters of this view as a viewAspect object + */ +viewAspect OCCViewer_ViewWindow::getViewParams() const +{ + double centerX, centerY, projX, projY, projZ, twist; + double atX, atY, atZ, eyeX, eyeY, eyeZ; + + Handle(V3d_View) aView3d = myViewPort->getView(); + + aView3d->Center( centerX, centerY ); + aView3d->Proj( projX, projY, projZ ); + aView3d->At( atX, atY, atZ ); + aView3d->Eye( eyeX, eyeY, eyeZ ); + twist = aView3d->Twist(); + + QString aName = QTime::currentTime().toString() + QString::fromLatin1( " h:m:s" ); + + viewAspect params; + params.scale = aView3d->Scale(); + params.centerX = centerX; + params.centerY = centerY; + params.projX = projX; + params.projY = projY; + params.projZ = projZ; + params.twist = twist; + params.atX = atX; + params.atY = atY; + params.atZ = atZ; + params.eyeX = eyeX; + params.eyeY = eyeY; + params.eyeZ = eyeZ; + params.name = aName; + + return params; +} + + +/*! The method returns the visual parameters of this view as a formated string + */ +QString OCCViewer_ViewWindow::getVisualParameters() +{ + viewAspect params = getViewParams(); + return QString( "%1*%2*%3*%4*%5*%6*%7*%8*%9*%10*%11*%12*%13" ).arg( + params.scale ).arg( params.centerX ).arg( params.centerY ).arg( params.projX ).arg( + params.projY ).arg( params.projZ ).arg( params.twist ).arg( params.atX ).arg( + params.atY ).arg( params.atZ ).arg( params.eyeX ).arg( params.eyeY ).arg( params.eyeZ ); +} + +/* The method restors visual parameters of this view from a formated string + */ +void OCCViewer_ViewWindow::setVisualParameters( const QString& parameters ) +{ + QStringList paramsLst = QStringList::split( '*', parameters, true ); + if ( paramsLst.size() == 13 ) { + printf( "-- OCC::setVisualParameters = %f %f %f %f %f %f %f %f %f %f %f %f %f\n", paramsLst[0].toDouble(), + paramsLst[1].toDouble(), paramsLst[2].toDouble(), paramsLst[3].toDouble(), paramsLst[4].toDouble(), + paramsLst[5].toDouble(), paramsLst[6].toDouble(), paramsLst[7].toDouble(), paramsLst[8].toDouble(), + paramsLst[9].toDouble(), paramsLst[10].toDouble(), paramsLst[11].toDouble(), paramsLst[12].toDouble() ); + + viewAspect params; + params.scale = paramsLst[0].toDouble(); + params.centerX = paramsLst[1].toDouble(); + params.centerY = paramsLst[2].toDouble(); + params.projX = paramsLst[3].toDouble(); + params.projY = paramsLst[4].toDouble(); + params.projZ = paramsLst[5].toDouble(); + params.twist = paramsLst[6].toDouble(); + params.atX = paramsLst[7].toDouble(); + params.atY = paramsLst[8].toDouble(); + params.atZ = paramsLst[9].toDouble(); + params.eyeX = paramsLst[10].toDouble(); + params.eyeY = paramsLst[11].toDouble(); + params.eyeZ = paramsLst[12].toDouble(); + + performRestoring( params ); + } +} diff --git a/src/OCCViewer/OCCViewer_ViewWindow.h b/src/OCCViewer/OCCViewer_ViewWindow.h index b4f2bc8db..b6bda965a 100755 --- a/src/OCCViewer/OCCViewer_ViewWindow.h +++ b/src/OCCViewer/OCCViewer_ViewWindow.h @@ -62,6 +62,9 @@ public: void setCuttingPlane( bool on, const double x = 0 , const double y = 0 , const double z = 0, const double dx = 0, const double dy = 0, const double dz = 1); + + virtual QString getVisualParameters(); + virtual void setVisualParameters( const QString& parameters ); public slots: void onFrontView(); @@ -119,6 +122,8 @@ protected: virtual OperationType getButtonState(QMouseEvent* theEvent); + viewAspect getViewParams() const; + OperationType myOperation; OCCViewer_Viewer* myModel; OCCViewer_ViewPort3d* myViewPort; diff --git a/src/Plot2d/Plot2d_ViewWindow.cxx b/src/Plot2d/Plot2d_ViewWindow.cxx index 5c558ea0f..7d21b50ca 100755 --- a/src/Plot2d/Plot2d_ViewWindow.cxx +++ b/src/Plot2d/Plot2d_ViewWindow.cxx @@ -465,3 +465,16 @@ QString Plot2d_ViewWindow::filter() const { return SUIT_ViewWindow::filter() + ";;" + tr( "POSTSCRIPT_FILES" ); } + +/*! The method returns the visual parameters of this view as a formated string + */ +QString Plot2d_ViewWindow::getVisualParameters() +{ + return " "; +} + +/* The method restors visual parameters of this view from a formated string + */ +void Plot2d_ViewWindow::setVisualParameters( const QString& parameters ) +{ +} diff --git a/src/Plot2d/Plot2d_ViewWindow.h b/src/Plot2d/Plot2d_ViewWindow.h index 571d692bf..ec0e5bf64 100755 --- a/src/Plot2d/Plot2d_ViewWindow.h +++ b/src/Plot2d/Plot2d_ViewWindow.h @@ -46,6 +46,9 @@ public: QToolBar* getToolBar() { return myToolBar; }; void contextMenuPopup( QPopupMenu* thePopup ); + virtual QString getVisualParameters(); + virtual void setVisualParameters( const QString& parameters ); + protected: virtual QImage dumpView(); virtual QString filter() const; diff --git a/src/VTKViewer/VTKViewer_ViewWindow.cxx b/src/VTKViewer/VTKViewer_ViewWindow.cxx index d4500095a..d8f607235 100755 --- a/src/VTKViewer/VTKViewer_ViewWindow.cxx +++ b/src/VTKViewer/VTKViewer_ViewWindow.cxx @@ -559,3 +559,56 @@ QImage VTKViewer_ViewWindow::dumpView() QPixmap px = QPixmap::grabWindow( myRenderWindow->winId() ); return px.convertToImage(); } + +/*! The method returns the visual parameters of this view as a formated string + */ +QString VTKViewer_ViewWindow::getVisualParameters() +{ + double pos[3], focalPnt[3], viewUp[3], parScale, scale[3]; + + vtkCamera* camera = myRenderer->GetActiveCamera(); + camera->GetPosition( pos ); + camera->GetFocalPoint( focalPnt ); + camera->GetViewUp( viewUp ); + parScale = camera->GetParallelScale(); + GetScale( scale ); + + return QString( "%1*%2*%3*%4*%5*%6*%7*%8*%9*%10*%11*%12*%13" ).arg( + pos[0] ).arg( pos[1] ).arg( pos[2] ).arg( focalPnt[0] ).arg( focalPnt[1] ).arg( + focalPnt[2] ).arg( viewUp[0] ).arg( viewUp[1] ).arg( viewUp[2] ).arg( parScale ).arg( + scale[0] ).arg( scale[1] ).arg( scale[2] ); +} + +/* The method restors visual parameters of this view from a formated string + */ +void VTKViewer_ViewWindow::setVisualParameters( const QString& parameters ) +{ + QStringList paramsLst = QStringList::split( '*', parameters, true ); + if ( paramsLst.size() == 13 ) { + printf( "-- VTK::setVisualParameters = %f %f %f %f %f %f %f %f %f %f %f %f %f\n", paramsLst[0].toDouble(), + paramsLst[1].toDouble(), paramsLst[2].toDouble(), paramsLst[3].toDouble(), paramsLst[4].toDouble(), + paramsLst[5].toDouble(), paramsLst[6].toDouble(), paramsLst[7].toDouble(), paramsLst[8].toDouble(), + paramsLst[9].toDouble(), paramsLst[10].toDouble(), paramsLst[11].toDouble(), paramsLst[12].toDouble() ); + + double pos[3], focalPnt[3], viewUp[3], parScale, scale[3]; + pos[0] = paramsLst[0].toDouble(); + pos[0] = paramsLst[1].toDouble(); + pos[0] = paramsLst[2].toDouble(); + focalPnt[0] = paramsLst[3].toDouble(); + focalPnt[0] = paramsLst[4].toDouble(); + focalPnt[0] = paramsLst[5].toDouble(); + viewUp[0] = paramsLst[6].toDouble(); + viewUp[0] = paramsLst[7].toDouble(); + viewUp[0] = paramsLst[8].toDouble(); + parScale = paramsLst[9].toDouble(); + scale[0] = paramsLst[10].toDouble(); + scale[0] = paramsLst[11].toDouble(); + scale[0] = paramsLst[12].toDouble(); + vtkCamera* camera = myRenderer->GetActiveCamera(); + camera->SetPosition( pos ); + camera->SetFocalPoint( focalPnt ); + camera->SetViewUp( viewUp ); + camera->SetParallelScale( parScale ); + SetScale( scale ); + } +} diff --git a/src/VTKViewer/VTKViewer_ViewWindow.h b/src/VTKViewer/VTKViewer_ViewWindow.h index 951d96d4c..5c02b79a6 100755 --- a/src/VTKViewer/VTKViewer_ViewWindow.h +++ b/src/VTKViewer/VTKViewer_ViewWindow.h @@ -70,6 +70,9 @@ public: void AddActor( VTKViewer_Actor*, bool update = false ); void RemoveActor( VTKViewer_Actor*, bool update = false); + virtual QString getVisualParameters(); + virtual void setVisualParameters( const QString& parameters ); + public slots: void onFrontView(); void onBackView(); -- 2.39.2