From 6e123199de5a2c125ee158d5b1bd7b6e95425f3c Mon Sep 17 00:00:00 2001 From: vsr Date: Tue, 9 Jun 2015 18:16:09 +0300 Subject: [PATCH] 0023085: [CEA 1439] To define the size of the OCC and VTK via Python --- src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx | 77 +++++++++++++++++++++++ src/SALOME_PYQT/SalomePyQt/SalomePyQt.h | 1 + src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip | 1 + 3 files changed, 79 insertions(+) diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx index f8ce9cf33..39b6e8113 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx @@ -39,6 +39,7 @@ #include "LightApp_SelectionMgr.h" #include "LogWindow.h" #include "OCCViewer_ViewWindow.h" +#include "OCCViewer_ViewFrame.h" #include "Plot2d_ViewManager.h" #include "Plot2d_ViewWindow.h" #include "PVViewer_ViewManager.h" @@ -2499,6 +2500,82 @@ bool SalomePyQt::setViewTitle( const int id, const QString& title ) return ProcessEvent( new TSetViewTitle( id, title ) ); } +/*! + \fn bool SalomePyQt::setViewSize( const int w, const int h, const int id ); + \brief Set view size + \param w window width + \param h window height + \param id window identifier + \return \c true if operation is completed successfully and \c false otherwise +*/ + +class TSetViewSize: public SALOME_Event +{ +public: + typedef bool TResult; + TResult myResult; + int myWndWidth; + int myWndHeight; + int myWndId; + TSetViewSize( const int w, const int h, const int id ) + : myResult( false ), + myWndWidth( w ), + myWndHeight( h ), + myWndId( id ) {} + virtual void Execute() + { + SUIT_ViewWindow* wnd = 0; + if ( !myWndId ) { + if ( LightApp_Application* anApp = getApplication() ) { + SUIT_ViewManager* vm = anApp->activeViewManager(); + if ( vm ) + wnd = vm->getActiveView(); + } + } + else { + wnd = dynamic_cast( getWnd( myWndId ) ); + } + if ( wnd ) { + SUIT_ViewManager* viewMgr = wnd->getViewManager(); + if ( viewMgr ) { + QString type = viewMgr->getType(); + if ( type == "OCCViewer") { + // specific processing for OCC viewer: + // OCC view can embed up to 4 sub-views, split according to the specified layout; + // - if there is only one sub-view active; it will be resized; + // - if there are several sub-views, each of them will be resized. + OCCViewer_ViewWindow* occView = qobject_cast( wnd ); + for ( int i = OCCViewer_ViewFrame::BOTTOM_RIGHT; i <= OCCViewer_ViewFrame::TOP_RIGHT; i++ ) { + if ( occView && occView->getView( i ) ) { + occView->getView( i )->centralWidget()->resize( myWndWidth, myWndHeight ); + myResult = true; + } + } + } + else if ( type == "ParaView") { + // specific processing for ParaView viewer: + // hierarchy of ParaView viewer is much complex than for usual view; + // we look for sub-widget named "Viewport" + QList lst = qFindChildren( wnd, "Viewport" ); + if ( !lst.isEmpty() ) { + lst[0]->resize( myWndWidth, myWndHeight ); + myResult = true; + } + } + else { + if ( wnd->centralWidget() ) { + wnd->centralWidget()->resize( myWndWidth, myWndHeight ); + myResult = true; + } + } + } + } + } +}; +bool SalomePyQt::setViewSize( const int w, const int h, const int id ) +{ + return ProcessEvent( new TSetViewSize( w, h, id ) ); +} /*! \fn QString SalomePyQt::getViewTitle( const int id ); diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h index 74aace1da..5e04d6627 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h @@ -269,6 +269,7 @@ public: static QString getViewType( const int ); static bool setViewTitle( const int, const QString& ); static QString getViewTitle( const int ); + static bool setViewSize( const int, const int, const int = 0 ); static QList findViews( const QString& ); static bool activateView( const int ); static int createView( const QString&, bool visible = true, const int width = 0, const int height = 0 ); diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip index 4b21ff530..75518ae08 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip @@ -439,6 +439,7 @@ public: static QString getViewType( const int ) /ReleaseGIL/ ; static bool setViewTitle( const int, const QString& ) /ReleaseGIL/ ; static QString getViewTitle( const int ) /ReleaseGIL/ ; + static bool setViewSize( const int, const int, const int = 0 ) /ReleaseGIL/ ; static QList findViews( const QString& ) /ReleaseGIL/ ; static bool activateView( const int ) /ReleaseGIL/ ; static int createView( const QString&, bool visible = true, const int width = 0, const int height = 0 ) /ReleaseGIL/ ; -- 2.39.2