From: asl Date: Wed, 20 Sep 2017 12:03:47 +0000 (+0300) Subject: refs #1328: draft implementation of the overview window with automatic tests X-Git-Tag: v2.1~66^2~14^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=02c9930b0a94cbbb306d84bcc87afcc27cd8ef00;p=modules%2Fhydro.git refs #1328: draft implementation of the overview window with automatic tests --- diff --git a/src/HYDROGUI/CMakeLists.txt b/src/HYDROGUI/CMakeLists.txt index 96cbffbc..ae312aba 100644 --- a/src/HYDROGUI/CMakeLists.txt +++ b/src/HYDROGUI/CMakeLists.txt @@ -144,6 +144,7 @@ set(PROJECT_HEADERS HYDROGUI_LandCoverColoringOp.h HYDROGUI_SetTransparencyOp.h HYDROGUI_TransparencyDlg.h + HYDROGUI_Overview.h ) QT_WRAP_MOC(PROJECT_HEADERS_MOC ${PROJECT_HEADERS}) @@ -290,6 +291,7 @@ set(PROJECT_SOURCES HYDROGUI_LandCoverColoringOp.cxx HYDROGUI_SetTransparencyOp.cxx HYDROGUI_TransparencyDlg.cxx + HYDROGUI_Overview.cxx ) add_definitions( diff --git a/src/HYDROGUI/HYDROGUI_Overview.cxx b/src/HYDROGUI/HYDROGUI_Overview.cxx new file mode 100644 index 00000000..a72155b6 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_Overview.cxx @@ -0,0 +1,388 @@ +// Copyright (C) 2014-2015 EDF-R&D +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include +#include +#include +#include +#include +#include +#include + +class HYDROGUI_OverviewBand : public QtxPolyRubberBand +{ +public: + HYDROGUI_OverviewBand( HYDROGUI_Overview* theOverview ); + virtual ~HYDROGUI_OverviewBand(); + + void initGeometry( const QPolygon& ); + void update( bool isFromMain ); + QPoint center() const; + int count() const; + + void drag( const QPoint&, bool isStart ); + bool isDrag() const; + void dragging( const QPoint& ); + bool contains( const QPoint& ) const; + QRect boundingRect() const; + +protected: + virtual void paintEvent( QPaintEvent* ); + +private: + HYDROGUI_Overview* myOverview; + bool myIsDrag; + QPolygon myStartPoints; + QPoint myStartPnt; +}; + + +HYDROGUI_OverviewBand::HYDROGUI_OverviewBand( HYDROGUI_Overview* theOverview ) + : QtxPolyRubberBand( theOverview->getViewPort( false ) ), + myOverview( theOverview ), myIsDrag( false ) +{ +} + +HYDROGUI_OverviewBand::~HYDROGUI_OverviewBand() +{ +} + +bool isEmpty( const QPolygon& thePoly ) +{ + QSize s = thePoly.boundingRect().size(); + if( s.width() < 2 || s.height() < 2 ) + return true; + else + return false; +} + +void HYDROGUI_OverviewBand::initGeometry( const QPolygon& thePoly ) +{ + int w2 = myOverview->width()*2; + int h2 = myOverview->height()*2; + + QPolygon aPoly; + for( int i=0, n=thePoly.size(); i w2 ) + p.setX( w2 ); + if( p.y() < -h2 ) + p.setY( -h2 ); + if( p.y() > h2 ) + p.setY( h2 ); + } + + QtxPolyRubberBand::initGeometry( thePoly ); + if( isEmpty( thePoly ) ) + hide(); + else + show(); +} + +QRect HYDROGUI_OverviewBand::boundingRect() const +{ + return myPoints.boundingRect(); +} + +QPoint HYDROGUI_OverviewBand::center() const +{ + QPoint c; + int n = myPoints.size()-1; + if( n==0 ) + return QPoint(); + + for( int i=0; igetViewPort( true ); + if( isFromMain ) + { + int w = main->width(); + 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 ) ); + initGeometry( poly ); + } + else + { + OCCViewer_ViewPort3d* overview = myOverview->getViewPort( false ); + QPoint c = center(); + double x1, y1, z1, x2, y2, z2; + main->getView()->Convert( main->width()/2, main->height()/2, x1, y1, z1 ); + overview->getView()->Convert( c.x(), c.y(), x2, y2, z2 ); + + gp_Trsf aTrsf; + aTrsf.SetTranslation( gp_Pnt( x1, y1, z1 ), gp_Pnt( x2, y2, z2 ) ); + main->getView()->Camera()->Transform( aTrsf ); + main->repaint(); + } +} + +void HYDROGUI_OverviewBand::paintEvent( QPaintEvent* thePaintEvent ) +{ + QPainter painter( this ); + painter.setRenderHint( QPainter::Antialiasing ); + + static QColor aColor = Qt::red; + static int aWidth = 2; + static QPen aPen( QBrush( aColor ), aWidth, Qt::SolidLine ); + + painter.setPen( aPen ); + painter.drawPolygon( myPoints ); +} + + + + + + +HYDROGUI_Overview::HYDROGUI_Overview( const QString& theTitle, int theMargin, QWidget* theParent ) + : QDockWidget( theParent ), myMargin( theMargin ), + myMainView( 0 ), myViewPort( 0 ), myBand( 0 ) +{ + setWindowTitle( theTitle ); +} + +HYDROGUI_Overview::~HYDROGUI_Overview() +{ +} + +QImage HYDROGUI_Overview::dump() const +{ + if( !myViewPort ) + return QImage(); + + Handle(V3d_View) view = myViewPort->getView(); + if( view.IsNull() ) + return QImage(); + + int aWidth = myViewPort->width(); + int aHeight = myViewPort->height(); + + Image_PixMap aPix; + view->ToPixMap( aPix,aWidth, aHeight,Graphic3d_BT_RGBA ); + + QImage anImage( aPix.Data(), aWidth, aHeight, QImage::Format_ARGB32 ); + anImage = anImage.mirrored(); + anImage = anImage.rgbSwapped(); + + if( myBand && myBand->isVisible() ) + { + QPixmap aPixmap = QPixmap::fromImage( anImage ); + QPoint p = myBand->boundingRect().topLeft(); + myBand->render( &aPixmap, p ); + anImage = aPixmap.toImage(); + } + + return anImage; +} + +OCCViewer_ViewPort3d* HYDROGUI_Overview::getViewPort( bool isMain ) const +{ + return isMain ? myMainView->getViewPort() : myViewPort; +} + +void HYDROGUI_Overview::setMainView( OCCViewer_ViewFrame* theMainView ) +{ + myMainView = theMainView; + if( !myMainView ) + return; + + OCCViewer_ViewWindow* aMainView = myMainView->getView( OCCViewer_ViewFrame::MAIN_VIEW ); + connect( aMainView, SIGNAL( vpTransformationFinished( OCCViewer_ViewWindow::OperationType ) ), + this, SLOT( OnTransformation() ) ); + connect( aMainView->getViewPort(), SIGNAL( vpResizeEvent( QResizeEvent* ) ), + this, SLOT( OnResizeEvent( QResizeEvent* ) ) ); + connect( aMainView->getViewPort(), SIGNAL( vpTransformed( OCCViewer_ViewPort* ) ), + this, SLOT( OnTransformation() ) ); + + 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* ) ) ); + +#if defined(TEST_MODE) || defined(_DEBUG) + //qApp->installEventFilter( this ); +#endif + + setWidget( myViewPort ); + setTopView(); + + qApp->processEvents(); + myBand = new HYDROGUI_OverviewBand( this ); + myBand->update( true ); +} + +void HYDROGUI_Overview::setTopView() +{ + Handle(V3d_View) aView3d = myViewPort->getView(); + if( !aView3d.IsNull() ) + aView3d->SetProj( V3d_Zpos ); + 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( myBand ) + myBand->update( true ); +} + +void HYDROGUI_Overview::OnTransformation() +{ + myBand->update( true ); +} + +QPoint HYDROGUI_Overview::fromMain( int xp, int yp ) const +{ + const double EPS = 1E-2; + + Handle(V3d_View) aMain = myMainView->getViewPort()->getView(); + Handle(V3d_View) aXY = myViewPort->getView(); + + // View coordinates to 3d (world) coordinates + double x, y, z; + aMain->Convert( xp, yp, x, y, z ); + + // Moving to the XY plane + gp_Vec aDir = aMain->Camera()->Direction(); + if( fabs( aDir.Z() )Convert( x, y, z, xp, yp ); + + return QPoint( xp, yp ); +} + +void HYDROGUI_Overview::OnMouseEvent( QMouseEvent* theEvent ) +{ + QPoint mp = theEvent->pos(); + if( !myBand ) + return; + + switch( theEvent->type() ) + { + case QEvent::MouseButtonPress: + myBand->drag( mp, true ); + break; + + case QEvent::MouseButtonRelease: + myBand->drag( mp, false ); + break; + + case QEvent::MouseMove: + if( myBand->isDrag() ) + myBand->dragging( mp ); + break; + } +} + +bool HYDROGUI_Overview::eventFilter( QObject* theObject, QEvent* theEvent ) +{ +#if defined(TEST_MODE) || defined(_DEBUG) + /*switch( theEvent->type() ) + { + case QEvent::MouseMove: + { + QPoint mp = ((QMouseEvent*)theEvent)->pos(); + //mp = getViewPort(false)->mapFromGlobal(mp); + QString coords = QString( "(%0, %1)" ).arg( mp.x() ).arg( mp.y() ); + std::string scoords = coords.toStdString(); + qDebug( scoords.c_str() ); + } + break; + }*/ +#endif + return QDockWidget::eventFilter( theObject, theEvent ); +} + +void HYDROGUI_Overview::OnResizeEvent( QResizeEvent* ) +{ + if( myBand ) + myBand->update( true ); +} diff --git a/src/HYDROGUI/HYDROGUI_Overview.h b/src/HYDROGUI/HYDROGUI_Overview.h new file mode 100644 index 00000000..11df12af --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_Overview.h @@ -0,0 +1,62 @@ +// Copyright (C) 2014-2015 EDF-R&D +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + + +#ifndef HYDROGUI_OVERVIEW_H +#define HYDROGUI_OVERVIEW_H + +#include + +class OCCViewer_ViewPort3d; +class OCCViewer_ViewFrame; +class HYDROGUI_OverviewBand; + +class HYDROGUI_Overview : public QDockWidget +{ + Q_OBJECT + +public: + HYDROGUI_Overview( const QString& theTitle, int theMargin = 5, QWidget* theParent = 0 ); + virtual ~HYDROGUI_Overview(); + + void setMainView( OCCViewer_ViewFrame* ); + void setTopView(); + + QPoint fromMain( int xp, int yp ) const; + OCCViewer_ViewPort3d* getViewPort( bool isMain ) const; + + QImage dump() const; + +protected: + virtual bool eventFilter( QObject*, QEvent* ); + +private slots: + void OnTransformation(); + void OnMouseEvent( QMouseEvent* ); + void OnResizeEvent( QResizeEvent* ); + +private: + int myMargin; + OCCViewer_ViewFrame* myMainView; + OCCViewer_ViewPort3d* myViewPort; + HYDROGUI_OverviewBand* myBand; +}; + +#endif + + diff --git a/src/HYDRO_tests/CMakeLists.txt b/src/HYDRO_tests/CMakeLists.txt index 20f22d15..35d87abf 100644 --- a/src/HYDRO_tests/CMakeLists.txt +++ b/src/HYDRO_tests/CMakeLists.txt @@ -25,6 +25,7 @@ set(PROJECT_HEADERS test_Dependencies.h test_HYDROData_DTM.h + test_Overview.h TestShape.h TestViewer.h @@ -54,6 +55,7 @@ set(PROJECT_SOURCES test_HYDROData_Stream.cxx test_Dependencies.cxx test_HYDROData_Tool.cxx + test_Overview.cxx TestShape.cxx TestViewer.cxx @@ -61,13 +63,13 @@ set(PROJECT_SOURCES TestLib_Runner.cxx ) -add_definitions( -DLIGHT_MODE -DHYDRODATA_STATIC -DHYDROGUI_STATIC ) +add_definitions( -DLIGHT_MODE -DHYDRODATA_STATIC -DHYDROGUI_STATIC -DTEST_MODE ) IF( ${WIN32} ) add_definitions( -DWNT -D__WIN32__ -D__x86__ -D_WIN64 -D_WIN32_WINNT=0x0400 -D__NT__ -D__OSVERSION__=4 ) ENDIF() -SET( CPPUNIT_INCLUDES $ENV{CPPUNIT_ROOT}/include ) +SET( CPPUNIT_INCLUDES $ENV{CPPUNIT_ROOT_DIR}/include ) SET( CAS_INCLUDES $ENV{CASROOT}/inc ) SET( QT_INCLUDES $ENV{QT_ROOT_DIR}/include $ENV{QT_ROOT_DIR}/include/QtCore $ENV{QT_ROOT_DIR}/include/QtGui $ENV{QT_ROOT_DIR}/include/QtTest ) SET( KERNEL_INCLUDES $ENV{KERNEL_ROOT_DIR}/include/salome ) diff --git a/src/HYDRO_tests/ExternalFiles.cmake b/src/HYDRO_tests/ExternalFiles.cmake index b093912a..947468e0 100644 --- a/src/HYDRO_tests/ExternalFiles.cmake +++ b/src/HYDRO_tests/ExternalFiles.cmake @@ -77,6 +77,7 @@ set( EXTERNAL_FILES ../HYDROGUI/HYDROGUI_StreamDlg.cxx ../HYDROGUI/HYDROGUI_ListSelector.cxx ../HYDROGUI/HYDROGUI_OrderedListWidget.cxx + ../HYDROGUI/HYDROGUI_Overview.cxx ) set( MOC_HEADERS @@ -85,6 +86,7 @@ set( MOC_HEADERS ../HYDROGUI/HYDROGUI_StreamDlg.h ../HYDROGUI/HYDROGUI_ListSelector.h ../HYDROGUI/HYDROGUI_OrderedListWidget.h + ../HYDROGUI/HYDROGUI_Overview.h ) QT_WRAP_MOC( PROJECT_MOC_HEADERS ${MOC_HEADERS} ) diff --git a/src/HYDRO_tests/TestViewer.cxx b/src/HYDRO_tests/TestViewer.cxx index 5ef6d2d9..038ba333 100644 --- a/src/HYDRO_tests/TestViewer.cxx +++ b/src/HYDRO_tests/TestViewer.cxx @@ -30,7 +30,7 @@ #ifdef WIN32 #pragma warning ( disable: 4251 ) #endif -#include +#include #ifdef WIN32 #pragma warning ( disable: 4251 ) #endif @@ -56,7 +56,7 @@ #include OCCViewer_ViewManager* TestViewer::myViewManager = 0; -OCCViewer_ViewWindow* TestViewer::myViewWindow = 0; +OCCViewer_ViewFrame* TestViewer::myViewWindow = 0; QString TestViewer::myKey = ""; OCCViewer_ViewManager* TestViewer::viewManager() @@ -72,7 +72,7 @@ OCCViewer_ViewManager* TestViewer::viewManager() aViewer->setZoomingStyle( 1 ); myViewManager->setViewModel( aViewer ); - myViewWindow = dynamic_cast( myViewManager->createViewWindow() ); + myViewWindow = dynamic_cast( myViewManager->createViewWindow() ); return myViewManager; } @@ -82,7 +82,7 @@ OCCViewer_Viewer* TestViewer::viewer() return dynamic_cast( viewManager()->getViewModel() ); } -OCCViewer_ViewWindow* TestViewer::viewWindow() +OCCViewer_ViewFrame* TestViewer::viewWindow() { viewManager(); //to create the view if it was not created earlier return myViewWindow; @@ -272,7 +272,7 @@ bool TestViewer::AssertImages( QString& theMessage, const QImage* theImage, cons if( theImage ) anActualImage = *theImage; else - anActualImage = viewWindow()->dumpView(); + anActualImage = viewWindow()->getView(OCCViewer_ViewFrame::MAIN_VIEW)->dumpView(); if( theCase ) myKey = theCase; diff --git a/src/HYDRO_tests/TestViewer.h b/src/HYDRO_tests/TestViewer.h index 90aac840..3584ef2d 100644 --- a/src/HYDRO_tests/TestViewer.h +++ b/src/HYDRO_tests/TestViewer.h @@ -22,7 +22,7 @@ class OCCViewer_ViewManager; class OCCViewer_Viewer; -class OCCViewer_ViewWindow; +class OCCViewer_ViewFrame; class TopoDS_Shape; class QString; class QColor; @@ -35,7 +35,7 @@ class TestViewer public: static OCCViewer_ViewManager* viewManager(); static OCCViewer_Viewer* viewer(); - static OCCViewer_ViewWindow* viewWindow(); + static OCCViewer_ViewFrame* viewWindow(); static Handle(AIS_InteractiveContext) context(); static void eraseAll( bool isUpdate ); @@ -62,7 +62,7 @@ public: private: static OCCViewer_ViewManager* myViewManager; - static OCCViewer_ViewWindow* myViewWindow; + static OCCViewer_ViewFrame* myViewWindow; static QString myKey; }; diff --git a/src/HYDRO_tests/reference_data/CMakeLists.txt b/src/HYDRO_tests/reference_data/CMakeLists.txt index 021ee7f6..36f0b5d1 100644 --- a/src/HYDRO_tests/reference_data/CMakeLists.txt +++ b/src/HYDRO_tests/reference_data/CMakeLists.txt @@ -120,6 +120,14 @@ SET(REFERENCE_DATA pb_1066.cbf f_cmp.brep rebuild_cmp_out.png + test_zone.brep + overview_empty.png + overview_prs.png + overview_selection.png + overview_zoomed_1.png + overview_zoomed_2.png + overview_panned_1.png + overview_rotated_1.png ) # Application tests diff --git a/src/HYDRO_tests/reference_data/overview_empty.png b/src/HYDRO_tests/reference_data/overview_empty.png new file mode 100644 index 00000000..fa9022f6 Binary files /dev/null and b/src/HYDRO_tests/reference_data/overview_empty.png differ diff --git a/src/HYDRO_tests/reference_data/overview_panned_1.png b/src/HYDRO_tests/reference_data/overview_panned_1.png new file mode 100644 index 00000000..cf482f44 Binary files /dev/null and b/src/HYDRO_tests/reference_data/overview_panned_1.png differ diff --git a/src/HYDRO_tests/reference_data/overview_prs.png b/src/HYDRO_tests/reference_data/overview_prs.png new file mode 100644 index 00000000..d0120ec9 Binary files /dev/null and b/src/HYDRO_tests/reference_data/overview_prs.png differ diff --git a/src/HYDRO_tests/reference_data/overview_rotated_1.png b/src/HYDRO_tests/reference_data/overview_rotated_1.png new file mode 100644 index 00000000..bc6b07ab Binary files /dev/null and b/src/HYDRO_tests/reference_data/overview_rotated_1.png differ diff --git a/src/HYDRO_tests/reference_data/overview_selection.png b/src/HYDRO_tests/reference_data/overview_selection.png new file mode 100644 index 00000000..18e18296 Binary files /dev/null and b/src/HYDRO_tests/reference_data/overview_selection.png differ diff --git a/src/HYDRO_tests/reference_data/overview_zoomed_1.png b/src/HYDRO_tests/reference_data/overview_zoomed_1.png new file mode 100644 index 00000000..e8a13399 Binary files /dev/null and b/src/HYDRO_tests/reference_data/overview_zoomed_1.png differ diff --git a/src/HYDRO_tests/reference_data/overview_zoomed_2.png b/src/HYDRO_tests/reference_data/overview_zoomed_2.png new file mode 100644 index 00000000..169f8a79 Binary files /dev/null and b/src/HYDRO_tests/reference_data/overview_zoomed_2.png differ diff --git a/src/HYDRO_tests/reference_data/test1.brep b/src/HYDRO_tests/reference_data/test1.brep new file mode 100644 index 00000000..8538356b --- /dev/null +++ b/src/HYDRO_tests/reference_data/test1.brep @@ -0,0 +1,40 @@ +DBRep_DrawableShape + +CASCADE Topology V1, (c) Matra-Datavision +Locations 0 +Curve2ds 0 +Curves 1 +7 0 1 3 70 36 40407.271980038946 34286.049813889753 0 41434.695364891566 34075.540478759103 0 41543.12570273161 33831.147955443885 0 41928.508752776201 33552.530669669075 0 42226.032860650426 33501.618691863972 0 42512.377282165187 33124.973722831535 0 42453.660703790389 32866.169491639623 0 42636.683232638294 32556.628928349546 0 42739.39438134151 32428.165853840786 0 43128.549115071481 32261.518244588729 0 43443.242731093269 32446.919465336847 0 44036.016109793818 32224.288873884427 0 44179.57722410289 31752.96667849454 0 44803.177266519742 31590.14386194132 0 45084.459863984281 31814.973824676825 0 45675.560064011988 31824.707181937414 0 45984.207150760994 31774.346493539811 0 46525.908372059785 31602.416570081987 0 46836.237065627618 31548.151248384765 0 47094.446316425885 31158.973712595835 0 46985.800617293673 30919.759745090963 0 47061.735829872901 30490.880508444068 0 47087.294586955686 30243.390071084152 0 47367.206218256455 29831.436491266431 0 47644.267070945622 29732.981437783019 0 48152.953739038458 29298.339926965706 0 48555.596554881646 29098.186461488429 0 48876.058650707077 28433.202778072668 0 48708.832731306546 28052.63880231194 0 48875.152078196683 27522.946396343301 0 48991.386126125355 27322.638678026422 0 49283.512757001568 27015.879527516525 0 49554.875124393504 27006.838610084858 0 49893.575552385431 26400.170107647227 0 49800.72715455712 25835.116327035401 0 49518.589779786307 24575.365902450871 0 49275.343115795353 23661.566879419035 0 48291.359705885057 22996.997512096725 0 47815.105167910348 22975.697128035215 0 47004.087052337156 23289.93243118906 0 46740.993451739683 23777.424526890667 0 46248.047551012423 24506.88867875783 0 46260.590886185521 24995.543673183489 0 45680.836210398062 25501.05877251576 0 45193.753985720774 25366.06132317154 0 44590.581148817015 25827.686595926763 0 44493.664062722637 26255.356606440237 0 43948.933050954409 27032.958768022665 0 43656.230461601815 27524.575979954498 0 43105.071660809372 28045.875215102329 0 42940.306990691439 28167.220544222648 0 42603.762295052293 28308.434975899007 0 42432.49586757076 28360.468562351842 0 42074.21364716997 28320.7478952366 0 41917.096381100302 28037.963429537689 0 41486.569214885603 28200.476344627772 0 41614.444853916815 28672.004731019108 0 41269.987018698317 28933.52538392763 0 41054.385996726916 28828.819484477142 0 40757.693528306168 29000.457579083766 0 40708.885980004889 29206.646048001887 0 40449.4164612846 29438.147603314061 0 40294.101335627864 29516.952126757198 0 39783.003996026935 29799.19113954125 0 39390.932908739604 29938.975500587658 0 38884.242234228928 30203.254562777289 0 38686.66320690907 30226.017924204774 0 38136.063842492869 31257.855058452078 0 38197.278854385338 32601.346506280064 0 39349.192858351256 34043.958558363622 0 + 0 2 641.48119551550326 2 1426.6496362974799 2 2060.8793228464447 2 2505.4514983140489 2 3330.8854220777839 2 4405.0572281218629 2 5264.4041166948127 2 6178.5982235452129 2 6969.3970802085223 2 7579.7336716889931 2 8276.0462317509246 2 9073.8911129778462 2 10283.302648601682 2 11288.409861290955 2 11948.87328079275 2 12559.217598125191 2 14033.311302405891 2 16432.091682619968 2 17595.457025794673 2 19041.391950091063 2 20236.673126216578 2 21348.977050960173 2 22515.32146956044 2 24197.234934635264 2 24791.230133437406 2 25292.148004649844 2 25872.662021104232 2 26672.682971892395 2 27170.120409365692 2 27700.970143377119 2 28213.315794378472 2 29452.516362567494 2 29927.72816050606 2 32961.166784790388 2 35465.987692899391 2 +Polygon3D 0 +PolygonOnTriangulations 0 +Surfaces 1 +1 44444.760874091022 28852.226106171107 0 -0 -0 -1 -1 0 0 0 1 -0 +Triangulations 0 + +TShapes 4 +Ve +1e-007 +41225.22 34118.46 0 +0 0 + +0101101 +* +Ed + 1e-007 1 1 0 +1 1 0 0 35465.9876928994 +0 + +0101000 ++4 0 -4 0 * +Wi + +0101100 ++3 0 * +Fa +0 1e-007 1 0 + +1111000 ++2 0 * + ++1 0 \ No newline at end of file diff --git a/src/HYDRO_tests/reference_data/test_zone.brep b/src/HYDRO_tests/reference_data/test_zone.brep new file mode 100644 index 00000000..8538356b --- /dev/null +++ b/src/HYDRO_tests/reference_data/test_zone.brep @@ -0,0 +1,40 @@ +DBRep_DrawableShape + +CASCADE Topology V1, (c) Matra-Datavision +Locations 0 +Curve2ds 0 +Curves 1 +7 0 1 3 70 36 40407.271980038946 34286.049813889753 0 41434.695364891566 34075.540478759103 0 41543.12570273161 33831.147955443885 0 41928.508752776201 33552.530669669075 0 42226.032860650426 33501.618691863972 0 42512.377282165187 33124.973722831535 0 42453.660703790389 32866.169491639623 0 42636.683232638294 32556.628928349546 0 42739.39438134151 32428.165853840786 0 43128.549115071481 32261.518244588729 0 43443.242731093269 32446.919465336847 0 44036.016109793818 32224.288873884427 0 44179.57722410289 31752.96667849454 0 44803.177266519742 31590.14386194132 0 45084.459863984281 31814.973824676825 0 45675.560064011988 31824.707181937414 0 45984.207150760994 31774.346493539811 0 46525.908372059785 31602.416570081987 0 46836.237065627618 31548.151248384765 0 47094.446316425885 31158.973712595835 0 46985.800617293673 30919.759745090963 0 47061.735829872901 30490.880508444068 0 47087.294586955686 30243.390071084152 0 47367.206218256455 29831.436491266431 0 47644.267070945622 29732.981437783019 0 48152.953739038458 29298.339926965706 0 48555.596554881646 29098.186461488429 0 48876.058650707077 28433.202778072668 0 48708.832731306546 28052.63880231194 0 48875.152078196683 27522.946396343301 0 48991.386126125355 27322.638678026422 0 49283.512757001568 27015.879527516525 0 49554.875124393504 27006.838610084858 0 49893.575552385431 26400.170107647227 0 49800.72715455712 25835.116327035401 0 49518.589779786307 24575.365902450871 0 49275.343115795353 23661.566879419035 0 48291.359705885057 22996.997512096725 0 47815.105167910348 22975.697128035215 0 47004.087052337156 23289.93243118906 0 46740.993451739683 23777.424526890667 0 46248.047551012423 24506.88867875783 0 46260.590886185521 24995.543673183489 0 45680.836210398062 25501.05877251576 0 45193.753985720774 25366.06132317154 0 44590.581148817015 25827.686595926763 0 44493.664062722637 26255.356606440237 0 43948.933050954409 27032.958768022665 0 43656.230461601815 27524.575979954498 0 43105.071660809372 28045.875215102329 0 42940.306990691439 28167.220544222648 0 42603.762295052293 28308.434975899007 0 42432.49586757076 28360.468562351842 0 42074.21364716997 28320.7478952366 0 41917.096381100302 28037.963429537689 0 41486.569214885603 28200.476344627772 0 41614.444853916815 28672.004731019108 0 41269.987018698317 28933.52538392763 0 41054.385996726916 28828.819484477142 0 40757.693528306168 29000.457579083766 0 40708.885980004889 29206.646048001887 0 40449.4164612846 29438.147603314061 0 40294.101335627864 29516.952126757198 0 39783.003996026935 29799.19113954125 0 39390.932908739604 29938.975500587658 0 38884.242234228928 30203.254562777289 0 38686.66320690907 30226.017924204774 0 38136.063842492869 31257.855058452078 0 38197.278854385338 32601.346506280064 0 39349.192858351256 34043.958558363622 0 + 0 2 641.48119551550326 2 1426.6496362974799 2 2060.8793228464447 2 2505.4514983140489 2 3330.8854220777839 2 4405.0572281218629 2 5264.4041166948127 2 6178.5982235452129 2 6969.3970802085223 2 7579.7336716889931 2 8276.0462317509246 2 9073.8911129778462 2 10283.302648601682 2 11288.409861290955 2 11948.87328079275 2 12559.217598125191 2 14033.311302405891 2 16432.091682619968 2 17595.457025794673 2 19041.391950091063 2 20236.673126216578 2 21348.977050960173 2 22515.32146956044 2 24197.234934635264 2 24791.230133437406 2 25292.148004649844 2 25872.662021104232 2 26672.682971892395 2 27170.120409365692 2 27700.970143377119 2 28213.315794378472 2 29452.516362567494 2 29927.72816050606 2 32961.166784790388 2 35465.987692899391 2 +Polygon3D 0 +PolygonOnTriangulations 0 +Surfaces 1 +1 44444.760874091022 28852.226106171107 0 -0 -0 -1 -1 0 0 0 1 -0 +Triangulations 0 + +TShapes 4 +Ve +1e-007 +41225.22 34118.46 0 +0 0 + +0101101 +* +Ed + 1e-007 1 1 0 +1 1 0 0 35465.9876928994 +0 + +0101000 ++4 0 -4 0 * +Wi + +0101100 ++3 0 * +Fa +0 1e-007 1 0 + +1111000 ++2 0 * + ++1 0 \ No newline at end of file diff --git a/src/HYDRO_tests/test_HYDROData_Main.cxx b/src/HYDRO_tests/test_HYDROData_Main.cxx index 05f6b9b8..9d2951d1 100644 --- a/src/HYDRO_tests/test_HYDROData_Main.cxx +++ b/src/HYDRO_tests/test_HYDROData_Main.cxx @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include #include @@ -39,7 +39,7 @@ int main( int argc, char* argv[] ) SUIT_Session aSession; aSession.startApplication("std"); - OCCViewer_ViewWindow* aWindow = TestViewer::viewWindow(); + OCCViewer_ViewFrame* aWindow = TestViewer::viewWindow(); int W = 800, H = 600; aWindow->setGeometry( 200, 200, W, H ); diff --git a/src/HYDRO_tests/test_Overview.cxx b/src/HYDRO_tests/test_Overview.cxx new file mode 100644 index 00000000..d52f7b76 --- /dev/null +++ b/src/HYDRO_tests/test_Overview.cxx @@ -0,0 +1,199 @@ +// Copyright (C) 2014-2015 EDF-R&D +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +extern QString REF_DATA_PATH; +HYDROGUI_Overview* test_Overview::myOverview = 0; + +#define CPPUNIT_ASSERT_OVERVIEW( theCase ) \ + { \ + QString aMessage; \ + QImage aDump = dumpViews(); \ + if( !TestViewer::AssertImages( aMessage, &aDump, theCase ) ) \ + { \ + TestViewer::showColorScale( false ); \ + std::string aMessageStl = aMessage.toStdString(); \ + CPPUNIT_FAIL( aMessageStl.c_str() ); \ + } \ + } + +const int m = 5; //margins +const QColor aColor = Qt::blue; +const QBrush SOLID( aColor ); +const int WIDTH = 2; +const QPen PSOLID( SOLID, WIDTH ); +const QColor BACK = Qt::white; + +QImage test_Overview::dumpViews() +{ + QImage aMain = TestViewer::viewWindow()->getView(OCCViewer_ViewFrame::MAIN_VIEW)->dumpView(); + QImage anOverview = myOverview->dump(); + + aMain = aMain.rgbSwapped(); //PATCH for image came from OCCT dump + //anOverview = anOverview.rgbSwapped(); //overview dump already normalizes the image, the line is not necessary!!! + + int w1 = aMain.width(); + int w2 = anOverview.width(); + int h1 = aMain.height(); + int h2 = anOverview.height(); + int w = w1 + w2 + 2*WIDTH; + int h = qMax( h1, h2 ) + 2*WIDTH; + + QPixmap pix( w, h ); + pix.fill( BACK ); + + QPainter painter( &pix ); + painter.setPen( PSOLID ); + + painter.drawRect( WIDTH, WIDTH, w2, h2 ); + painter.drawRect( w2+WIDTH, WIDTH, w1, h1 ); + + painter.drawImage( WIDTH, WIDTH, anOverview ); + painter.drawImage( w2+WIDTH, WIDTH, aMain ); + + return pix.toImage(); +} + +void test_Overview::create() +{ + static bool isPassed = false; + if( isPassed ) + return; + + // default mouse position + QTest::mouseMove( TestViewer::viewWindow(), QPoint( 0, 0 ) ); + + // Initialization of the empty viewer + myOverview = new HYDROGUI_Overview( "Test overview" ); + myOverview->show(); + myOverview->setMainView( TestViewer::viewWindow() ); + TestViewer::viewWindow()->setGeometry( 400, 100, 800, 800 ); + myOverview->setGeometry( 100, 100, 200, 200 ); + + isPassed = true; +} + +void test_Overview::showShape() +{ + static bool isPassed = false; + if( isPassed ) + return; + + // Show loaded shape in the viewer + BRep_Builder B; + TopoDS_Shape shape; + std::string fname = (REF_DATA_PATH + "/test_zone.brep").toStdString(); + BRepTools::Read( shape, fname.c_str(), B ); + TestViewer::show( shape, AIS_Shaded, true, 0x03399FF ); + + qApp->processEvents(); + myOverview->setTopView(); //TODO: automatic fit all on show???*/ + + isPassed = true; +} + +void fitAllWithRestore( OCCViewer_ViewPort3d* vp ) +{ + double s = vp->getView()->Scale(); + double x0, y0, z0; + vp->getView()->Convert( 0, 0, x0, y0, z0 ); + TestViewer::viewWindow()->onFitAll(); + vp->getView()->SetScale( s ); + int xp, yp; + vp->getView()->Convert( x0, y0, z0, xp, yp ); + vp->pan( -xp, -yp ); +} + + + + +void test_Overview::test_default() +{ + create(); + CPPUNIT_ASSERT_OVERVIEW( "overview_empty" ); +} + + +void test_Overview::test_presentation() +{ + create(); + showShape(); + + //QTest::qWait( 20000 ); + CPPUNIT_ASSERT_OVERVIEW( "overview_prs" ); +} + +void test_Overview::test_actions_in_main() +{ + create(); + showShape(); + + OCCViewer_ViewWindow* aMain = TestViewer::viewWindow()->getView( OCCViewer_ViewFrame::MAIN_VIEW ); + OCCViewer_ViewPort3d* vp = aMain->getViewPort(); + + // 1. selection in main view + QTest::mouseMove( TestViewer::viewWindow() ); + CPPUNIT_ASSERT_OVERVIEW( "overview_selection" ); + + // 2. mouse wheel zoom + QWheelEvent we( QPoint( 243, 416 ), 120*20, Qt::NoButton, Qt::NoModifier ); + qApp->sendEvent( vp, &we ); + qApp->processEvents(); + CPPUNIT_ASSERT_OVERVIEW( "overview_zoomed_1" ); + + // 3. zoom via mouse + const int d = 100; + vp->zoom( 243, 416, 243+d, 416+d ); + CPPUNIT_ASSERT_OVERVIEW( "overview_zoomed_2" ); + + // 4. panning via mouse + vp->pan( 300, -250 ); + CPPUNIT_ASSERT_OVERVIEW( "overview_panned_1" ); + + // 5. reverse zoom and rotation via mouse + vp->getView()->AutoZFit(); + vp->getView()->ZFitAll(); + vp->getView()->Camera()->SetZRange( -10, 10 ); + vp->zoom( 243+d, 416+d, 243, 416 ); + vp->startRotation( 400, 400, OCCViewer_ViewWindow::BBCENTER, gp_Pnt() ); + vp->rotate( 200, 300, OCCViewer_ViewWindow::BBCENTER, gp_Pnt() ); + + fitAllWithRestore( vp ); + // it is necessary to apply fit all to fit correct zmin/zmax + // and after that we restore the previous aspect + CPPUNIT_ASSERT_OVERVIEW( "overview_rotated_1" ); + + //QTest::qWait( 50000 ); +} + +void test_Overview::test_actions_in_overview() +{ +} diff --git a/src/HYDRO_tests/test_Overview.h b/src/HYDRO_tests/test_Overview.h new file mode 100644 index 00000000..140663ad --- /dev/null +++ b/src/HYDRO_tests/test_Overview.h @@ -0,0 +1,60 @@ +// Copyright (C) 2014-2015 EDF-R&D +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifdef WIN32 + #pragma warning( disable: 4251 ) +#endif + +#include + +class HYDROGUI_Overview; +class QImage; +class QColor; + +class test_Overview : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE( test_Overview ); + CPPUNIT_TEST( test_default ); + CPPUNIT_TEST( test_presentation ); + CPPUNIT_TEST( test_actions_in_main ); + CPPUNIT_TEST( test_actions_in_overview ); + CPPUNIT_TEST_SUITE_END(); + +public: + void test_default(); + void test_presentation(); + void test_actions_in_main(); + void test_actions_in_overview(); + +private: + static HYDROGUI_Overview* overView(); + static QImage dumpViews(); + + void create(); + void showShape(); + +private: + static HYDROGUI_Overview* myOverview; +}; + +CPPUNIT_TEST_SUITE_REGISTRATION( test_Overview ); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( test_Overview, "Overview" ); + +#ifdef WIN32 + #pragma warning( default: 4251 ) +#endif