1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include <test_Overview.h>
20 #include <BRep_Builder.hxx>
21 #include <BRepTools.hxx>
22 #include <AIS_Shape.hxx>
23 #include <TestViewer.h>
28 #include <HYDROGUI_Overview.h>
29 #include <OCCViewer_ViewFrame.h>
30 #include <OCCViewer_ViewModel.h>
31 #include <OCCViewer_ViewPort3d.h>
32 #include <V3d_View.hxx>
34 extern QString REF_DATA_PATH;
35 HYDROGUI_Overview* test_Overview::myOverview = 0;
37 #define CPPUNIT_ASSERT_OVERVIEW( theCase ) \
40 QImage aDump = dumpViews(); \
41 if( !TestViewer::AssertImages( aMessage, &aDump, theCase, false ) ) \
43 TestViewer::showColorScale( false ); \
44 std::string aMessageStl = aMessage.toStdString(); \
45 CPPUNIT_FAIL( aMessageStl.c_str() ); \
49 const int m = 5; //margins
50 const QColor aColor = Qt::blue;
51 const QBrush SOLID( aColor );
53 const QPen PSOLID( SOLID, WIDTH );
54 const QColor BACK = Qt::white;
56 QImage test_Overview::dumpViews()
58 QImage aMain = TestViewer::viewWindow()->getView(OCCViewer_ViewFrame::MAIN_VIEW)->dumpView();
59 QImage anOverview = myOverview->dump();
61 aMain = aMain.rgbSwapped(); //PATCH for image came from OCCT dump
62 //anOverview = anOverview.rgbSwapped(); //overview dump already normalizes the image, the line is not necessary!!!
64 int w1 = aMain.width();
65 int w2 = anOverview.width();
66 int h1 = aMain.height();
67 int h2 = anOverview.height();
68 int w = w1 + w2 + 2*WIDTH;
69 int h = qMax( h1, h2 ) + 2*WIDTH;
74 QPainter painter( &pix );
75 painter.setPen( PSOLID );
77 painter.drawRect( WIDTH, WIDTH, w2, h2 );
78 painter.drawRect( w2+WIDTH, WIDTH, w1, h1 );
82 //anOverview.save( QString( "/tmp/hydro/overview_" ) + QString::number( q ) + ".png" );
83 //aMain.save( QString( "/tmp/hydro/main_" ) + QString::number( q ) + ".png" );
85 painter.drawImage( WIDTH, WIDTH, anOverview );
86 painter.drawImage( w2+WIDTH, WIDTH, aMain );
88 QImage res = pix.toImage();
89 //res.save( QString( "/tmp/hydro/result_" ) + QString::number( q ) + ".png" );
94 extern int MAIN_W, MAIN_H;
96 void test_Overview::create()
98 TestViewer::eraseAll( true, true );
100 // Initialization of the empty viewer
102 static bool isCreated = false;
105 myOverview = new HYDROGUI_Overview( "Test overview" );
108 // default mouse position
109 QTest::mouseMove( TestViewer::viewWindow(), QPoint( 0, 0 ) );
113 myOverview->setMainView( TestViewer::viewWindow() );
114 //TestViewer::viewWindow()->setGeometry( 400, 100, MAIN_W, MAIN_H );
115 TestViewer::viewWindow()->onTopView();
116 myOverview->setGeometry( 100, 100, 200, 200 );
119 void test_Overview::showShape()
121 // Show loaded shape in the viewer
124 std::string fname = (REF_DATA_PATH + "/test_zone.brep").toStdString();
125 //std::cout << "Loading shape: " << fname << std::endl;
126 BRepTools::Read( shape, fname.c_str(), B );
127 TestViewer::show( shape, AIS_Shaded, true, 0x03399FF );
129 qApp->processEvents();
130 myOverview->setTopView(); //TODO: automatic fit all on show???*/
133 void fitAllWithRestore( OCCViewer_ViewPort3d* vp )
135 double s = vp->getView()->Scale();
137 vp->getView()->Convert( 0, 0, x0, y0, z0 );
138 TestViewer::viewWindow()->onFitAll();
139 vp->getView()->SetScale( s );
141 vp->getView()->Convert( x0, y0, z0, xp, yp );
148 void test_Overview::test_default()
151 //QTest::qWait( 50000 );
152 CPPUNIT_ASSERT_OVERVIEW( "overview_empty" );
156 void test_Overview::test_presentation()
161 //QTest::qWait( 20000 );
162 CPPUNIT_ASSERT_OVERVIEW( "overview_prs" );
165 void test_Overview::test_actions_in_main()
169 TestViewer::viewWindow()->onTopView();
170 qApp->processEvents();
172 OCCViewer_ViewWindow* aMain = TestViewer::viewWindow()->getView( OCCViewer_ViewFrame::MAIN_VIEW );
173 OCCViewer_ViewPort3d* vp = aMain->getViewPort();
175 // 1. selection in main view
176 QTest::mouseMove( vp, QPoint(150,150) );
177 TestViewer::context()->MoveTo(150, 150, vp->getView(), Standard_True );
178 TestViewer::context()->Select( Standard_True );
179 qApp->processEvents();
180 //QTest::qWait( 50000 );
181 //aMain->dumpView().save("/tmp/hydro/dump.png");
182 //aMain->dumpView().rgbSwapped().save("/tmp/hydro/dump2.png");
183 CPPUNIT_ASSERT_OVERVIEW( "overview_selection" );
185 // 2. mouse wheel zoom
186 QWheelEvent we( QPoint( 243, 316 ), 120*20, Qt::NoButton, Qt::NoModifier );
187 qApp->sendEvent( vp, &we );
188 qApp->processEvents();
189 CPPUNIT_ASSERT_OVERVIEW( "overview_zoomed_1" );
193 vp->zoom( 243, 316, 243+d, 316+d );
194 CPPUNIT_ASSERT_OVERVIEW( "overview_zoomed_2" );
196 // 4. panning via mouse
197 vp->pan( 300, -250 );
198 CPPUNIT_ASSERT_OVERVIEW( "overview_panned_1" );
200 // 5. reverse zoom and rotation via mouse
201 vp->getView()->AutoZFit();
202 vp->getView()->ZFitAll();
203 vp->getView()->Camera()->SetZRange( -10, 10 );
204 vp->zoom( 243+d, 416+d, 243, 416 );
205 vp->startRotation( 400, 400, OCCViewer_ViewWindow::BBCENTER, gp_Pnt() );
206 vp->rotate( 200, 300, OCCViewer_ViewWindow::BBCENTER, gp_Pnt() );
208 fitAllWithRestore( vp );
209 // it is necessary to apply fit all to fit correct zmin/zmax
210 // and after that we restore the previous aspect
211 CPPUNIT_ASSERT_OVERVIEW( "overview_rotated_1" );
213 //QTest::qWait( 50000 );
216 void test_Overview::test_set_mainview_2_times()
220 TestViewer::viewWindow()->onTopView();
222 OCCViewer_ViewWindow* aMain = TestViewer::viewWindow()->getView( OCCViewer_ViewFrame::MAIN_VIEW );
223 OCCViewer_ViewPort3d* vp = aMain->getViewPort();
225 QTest::mouseMove( vp, QPoint(150,150) );
226 TestViewer::context()->MoveTo(150, 150, vp->getView(), Standard_True );
227 TestViewer::context()->Select( Standard_True );
228 qApp->processEvents();
230 //QTest::qWait( 20000 );
231 CPPUNIT_ASSERT_OVERVIEW( "overview_selection" );
233 myOverview->setMainView( TestViewer::viewWindow() );
234 qApp->processEvents();
236 CPPUNIT_ASSERT_OVERVIEW( "overview_selection_a" );
239 void test_Overview::test_actions_in_overview()
243 TestViewer::viewWindow()->onTopView();
245 OCCViewer_ViewWindow* aMain = TestViewer::viewWindow()->getView( OCCViewer_ViewFrame::MAIN_VIEW );
246 OCCViewer_ViewPort3d* vp = aMain->getViewPort();
248 QTest::mouseMove( vp, QPoint(150,150) );
249 TestViewer::context()->MoveTo(150, 150, vp->getView(), Standard_True );
250 TestViewer::context()->Select( Standard_True );
251 qApp->processEvents();
253 QWheelEvent we( QPoint( 243, 316 ), 120*20, Qt::NoButton, Qt::NoModifier );
254 qApp->sendEvent( vp, &we );
255 qApp->processEvents();
256 CPPUNIT_ASSERT_OVERVIEW( "overview_zoomed_1" );
258 QTest::mouseMove( myOverview->getViewPort(false), QPoint( 150, 50 ) );
259 QTest::mouseClick( myOverview->getViewPort(false), Qt::LeftButton, Qt::KeyboardModifiers(), QPoint( 150, 50 ) );
260 qApp->processEvents();
262 CPPUNIT_ASSERT_OVERVIEW( "overview_drag" );
264 //QTest::qWait( 50000 );