From: asl Date: Wed, 20 Sep 2017 13:39:50 +0000 (+0300) Subject: refs #1328: integration of the overview window to HYDROGUI module X-Git-Tag: v2.1~66^2~14^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=511c5b40429730c2f48b5df8c15538ddb2c1fc28;p=modules%2Fhydro.git refs #1328: integration of the overview window to HYDROGUI module --- diff --git a/src/HYDROGUI/HYDROGUI_Module.cxx b/src/HYDROGUI/HYDROGUI_Module.cxx index 4f8eeafd..dba41335 100644 --- a/src/HYDROGUI/HYDROGUI_Module.cxx +++ b/src/HYDROGUI/HYDROGUI_Module.cxx @@ -40,6 +40,7 @@ #include "HYDROGUI_SetColorOp.h" #include "HYDROGUI_ImportGeomObjectOp.h" #include "HYDROGUI_ShowHideOp.h" +#include "HYDROGUI_Overview.h" #include #include @@ -120,7 +121,8 @@ HYDROGUI_Module::HYDROGUI_Module() : LightApp_Module( "HYDRO" ), myDisplayer( 0 ), myOCCDisplayer( 0 ), - myIsUpdateEnabled( true ) + myIsUpdateEnabled( true ), + myOverview( 0 ) { } @@ -209,12 +211,19 @@ bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy ) ViewManagerList anOCCViewManagers; anApp->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers ); - foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) { + + foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) + { connect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ), this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) ); - foreach( SUIT_ViewWindow* aViewWindow, aViewManager->getViews() ) { + connect( aViewManager, SIGNAL( activated( SUIT_ViewManager* ) ), + this, SLOT( onViewActivated( SUIT_ViewManager* ) ) ); + + foreach( SUIT_ViewWindow* aViewWindow, aViewManager->getViews() ) + { OCCViewer_ViewFrame* aViewFrame = dynamic_cast( aViewWindow ); - if ( aViewFrame && aViewFrame->getViewPort() ) { + if ( aViewFrame && aViewFrame->getViewPort() ) + { aViewFrame->getViewPort()->installEventFilter( this ); } } @@ -287,12 +296,28 @@ bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy ) void HYDROGUI_Module::windows( QMap& theMap ) const { + static bool inWindows = false; + if( inWindows ) + return; + theMap.clear(); theMap.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea ); #ifndef DISABLE_PYCONSOLE theMap.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea ); #endif theMap.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea ); + theMap.insert( OverviewWindow, Qt::LeftDockWidgetArea ); + + inWindows = true; + LightApp_Application* app = getApp(); + if( app && app->getWindow( OverviewWindow )==0 ) + { + const_cast( this )->myOverview = + new HYDROGUI_Overview( tr( "OVERVIEW" ), 0, app->desktop() ); + myOverview->setGeometry( 0, 0, 320, 240 ); + app->insertDockWindow( OverviewWindow, myOverview ); + } + inWindows = false; } void HYDROGUI_Module::viewManagers( QStringList& theTypesList ) const @@ -1482,6 +1507,8 @@ void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager ) this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) ); connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ), this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) ); + connect( theViewManager, SIGNAL( activated( SUIT_ViewManager* ) ), + this, SLOT( onViewActivated( SUIT_ViewManager* ) ) ); } else if( theViewManager->getType() == SVTK_Viewer::Type() ) { @@ -1873,3 +1900,16 @@ void HYDROGUI_Module::setObjectRemoved( const Handle(HYDROData_Entity)& theObjec } } } + +void HYDROGUI_Module::onViewActivated( SUIT_ViewManager* theMgr ) +{ + if( !theMgr ) + return; + + SUIT_ViewWindow* wnd = theMgr->getActiveView(); + OCCViewer_ViewFrame* occwnd = dynamic_cast( wnd ); + if( !occwnd ) + return; + + myOverview->setMainView( occwnd ); +} diff --git a/src/HYDROGUI/HYDROGUI_Module.h b/src/HYDROGUI/HYDROGUI_Module.h index 2e62e508..6b702063 100644 --- a/src/HYDROGUI/HYDROGUI_Module.h +++ b/src/HYDROGUI/HYDROGUI_Module.h @@ -26,6 +26,7 @@ #endif #include +#include #include #include @@ -51,6 +52,7 @@ class HYDROGUI_AbstractDisplayer; class HYDROGUI_Shape; class HYDROGUI_VTKPrs; class HYDROGUI_Operation; +class HYDROGUI_Overview; /**\class HYDROGUI_Module *\brief The class representing the HYDROGUI module @@ -60,6 +62,7 @@ class HYDROGUI_Module : public LightApp_Module Q_OBJECT enum CustomEvent { NewViewEvent = QEvent::User + 100 }; + enum CustomWindows { OverviewWindow = LightApp_Application::WT_User + 100 }; enum CursorType { @@ -282,6 +285,8 @@ protected slots: virtual void onViewManagerRemoved( SUIT_ViewManager* ); virtual void onViewCreated( SUIT_ViewWindow* ); + void onViewActivated( SUIT_ViewManager* ); + void onViewPortMouseEvent( QGraphicsSceneMouseEvent* ); void onMouseMove( SUIT_ViewWindow*, QMouseEvent* ); @@ -332,6 +337,8 @@ private: QStringList myGeomObjectsToImport; ///< entries of GEOM objects to be imported ViewId2StricklerTable myLandCoverColoringMap; + + HYDROGUI_Overview* myOverview; }; #endif diff --git a/src/HYDROGUI/HYDROGUI_Overview.cxx b/src/HYDROGUI/HYDROGUI_Overview.cxx index a72155b6..8b53cfeb 100644 --- a/src/HYDROGUI/HYDROGUI_Overview.cxx +++ b/src/HYDROGUI/HYDROGUI_Overview.cxx @@ -23,6 +23,7 @@ #include #include #include +#include class HYDROGUI_OverviewBand : public QtxPolyRubberBand { @@ -172,11 +173,15 @@ void HYDROGUI_OverviewBand::update( bool isFromMain ) int h = main->height(); QPolygon poly; - poly.append( myOverview->fromMain( 0, 0 ) ); - poly.append( myOverview->fromMain( w, 0 ) ); - poly.append( myOverview->fromMain( w, h ) ); - poly.append( myOverview->fromMain( 0, h ) ); - poly.append( myOverview->fromMain( 0, 0 ) ); + QPoint p1 = myOverview->fromMain( 0, 0 ); + QPoint p2 = myOverview->fromMain( w, 0 ); + QPoint p3 = myOverview->fromMain( w, h ); + QPoint p4 = myOverview->fromMain( 0, h ); + poly.append( p1 ); + poly.append( p2 ); + poly.append( p3 ); + poly.append( p4 ); + poly.append( p1 ); initGeometry( poly ); } else @@ -213,10 +218,15 @@ void HYDROGUI_OverviewBand::paintEvent( QPaintEvent* thePaintEvent ) HYDROGUI_Overview::HYDROGUI_Overview( const QString& theTitle, int theMargin, QWidget* theParent ) - : QDockWidget( theParent ), myMargin( theMargin ), + : QFrame( theParent ), myMargin( theMargin ), myMainView( 0 ), myViewPort( 0 ), myBand( 0 ) { setWindowTitle( theTitle ); + myLayout = new QGridLayout( this ); + myLayout->setMargin( 0 ); + myLayout->setSpacing( 0 ); + myLayout->setRowStretch( 0, 1 ); + myLayout->setColumnStretch( 0, 1 ); } HYDROGUI_Overview::~HYDROGUI_Overview() @@ -272,23 +282,32 @@ void HYDROGUI_Overview::setMainView( OCCViewer_ViewFrame* theMainView ) connect( aMainView->getViewPort(), SIGNAL( vpTransformed( OCCViewer_ViewPort* ) ), this, SLOT( OnTransformation() ) ); - myViewPort = new OCCViewer_ViewPort3d( this, myMainView->getViewPort()->getViewer(), V3d_ORTHOGRAPHIC ); - myViewPort->setBackgroundColor( Qt::white ); + if( !myViewPort ) + { + myViewPort = new OCCViewer_ViewPort3d( this, myMainView->getViewPort()->getViewer(), V3d_ORTHOGRAPHIC ); + //myViewPort->setBackgroundColor( Qt::white ); - connect( myViewPort, SIGNAL( vpMouseEvent( QMouseEvent* ) ), - this, SLOT( OnMouseEvent( QMouseEvent* ) ) ); - connect( myViewPort, SIGNAL( vpResizeEvent( QResizeEvent* ) ), - this, SLOT( OnResizeEvent( QResizeEvent* ) ) ); + connect( myViewPort, SIGNAL( vpMouseEvent( QMouseEvent* ) ), + this, SLOT( OnMouseEvent( QMouseEvent* ) ) ); + connect( myViewPort, SIGNAL( vpResizeEvent( QResizeEvent* ) ), + this, SLOT( OnResizeEvent( QResizeEvent* ) ) ); + + myLayout->addWidget( myViewPort, 0, 0 ); + } #if defined(TEST_MODE) || defined(_DEBUG) //qApp->installEventFilter( this ); #endif - setWidget( myViewPort ); + qApp->processEvents(); + setTopView(); qApp->processEvents(); - myBand = new HYDROGUI_OverviewBand( this ); + + if( !myBand ) + myBand = new HYDROGUI_OverviewBand( this ); + myBand->update( true ); } @@ -300,8 +319,11 @@ void HYDROGUI_Overview::setTopView() myViewPort->fitAll(); // Apply margins for internal area in the view port - QRect aRect( -myMargin, -myMargin, myViewPort->width()+2*myMargin, myViewPort->height()+2*myMargin ); - myViewPort->fitRect( aRect ); + if( myMargin>0 ) + { + QRect aRect( -myMargin, -myMargin, myViewPort->width()+2*myMargin, myViewPort->height()+2*myMargin ); + myViewPort->fitRect( aRect ); + } if( myBand ) myBand->update( true ); @@ -309,7 +331,8 @@ void HYDROGUI_Overview::setTopView() void HYDROGUI_Overview::OnTransformation() { - myBand->update( true ); + if( myBand ) + myBand->update( true ); } QPoint HYDROGUI_Overview::fromMain( int xp, int yp ) const @@ -378,7 +401,7 @@ bool HYDROGUI_Overview::eventFilter( QObject* theObject, QEvent* theEvent ) break; }*/ #endif - return QDockWidget::eventFilter( theObject, theEvent ); + return QFrame::eventFilter( theObject, theEvent ); } void HYDROGUI_Overview::OnResizeEvent( QResizeEvent* ) diff --git a/src/HYDROGUI/HYDROGUI_Overview.h b/src/HYDROGUI/HYDROGUI_Overview.h index 11df12af..f2a7ea6e 100644 --- a/src/HYDROGUI/HYDROGUI_Overview.h +++ b/src/HYDROGUI/HYDROGUI_Overview.h @@ -20,13 +20,14 @@ #ifndef HYDROGUI_OVERVIEW_H #define HYDROGUI_OVERVIEW_H -#include +#include class OCCViewer_ViewPort3d; class OCCViewer_ViewFrame; class HYDROGUI_OverviewBand; +class QGridLayout; -class HYDROGUI_Overview : public QDockWidget +class HYDROGUI_Overview : public QFrame { Q_OBJECT @@ -51,6 +52,7 @@ private slots: void OnResizeEvent( QResizeEvent* ); private: + QGridLayout* myLayout; int myMargin; OCCViewer_ViewFrame* myMainView; OCCViewer_ViewPort3d* myViewPort; diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index 82ce2e0f..65b9c033 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -294,6 +294,10 @@ All supported formats (*.brep *.iges *.igs *.step *.stp) LAND_COVER_POLYLINES Polylines + + OVERVIEW + Overview + diff --git a/src/HYDRO_tests/test_Overview.cxx b/src/HYDRO_tests/test_Overview.cxx index d52f7b76..3850853d 100644 --- a/src/HYDRO_tests/test_Overview.cxx +++ b/src/HYDRO_tests/test_Overview.cxx @@ -194,6 +194,23 @@ void test_Overview::test_actions_in_main() //QTest::qWait( 50000 ); } +void test_Overview::test_set_mainview_2_times() +{ + create(); + showShape(); + TestViewer::viewWindow()->onTopView(); + QTest::mouseMove( TestViewer::viewWindow() ); + + //QTest::qWait( 20000 ); + CPPUNIT_ASSERT_OVERVIEW( "overview_selection" ); + + myOverview->setMainView( TestViewer::viewWindow() ); + qApp->processEvents(); + + CPPUNIT_ASSERT_OVERVIEW( "overview_selection" ); +} + void test_Overview::test_actions_in_overview() { + //TODO } diff --git a/src/HYDRO_tests/test_Overview.h b/src/HYDRO_tests/test_Overview.h index 140663ad..2c76c435 100644 --- a/src/HYDRO_tests/test_Overview.h +++ b/src/HYDRO_tests/test_Overview.h @@ -33,6 +33,7 @@ class test_Overview : public CppUnit::TestFixture CPPUNIT_TEST( test_presentation ); CPPUNIT_TEST( test_actions_in_main ); CPPUNIT_TEST( test_actions_in_overview ); + CPPUNIT_TEST( test_set_mainview_2_times ); CPPUNIT_TEST_SUITE_END(); public: @@ -40,6 +41,7 @@ public: void test_presentation(); void test_actions_in_main(); void test_actions_in_overview(); + void test_set_mainview_2_times(); private: static HYDROGUI_Overview* overView();