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 void test_Overview::create()
96 TestViewer::eraseAll( true, true );
98 // Initialization of the empty viewer
100 static bool isCreated = false;
103 myOverview = new HYDROGUI_Overview( "Test overview" );
106 // default mouse position
107 QTest::mouseMove( TestViewer::viewWindow(), QPoint( 0, 0 ) );
111 myOverview->setMainView( TestViewer::viewWindow() );
112 TestViewer::viewWindow()->setGeometry( 400, 100, 800, 800 );
113 TestViewer::viewWindow()->onTopView();
114 myOverview->setGeometry( 100, 100, 200, 200 );
117 void test_Overview::showShape()
119 // Show loaded shape in the viewer
122 std::string fname = (REF_DATA_PATH + "/test_zone.brep").toStdString();
123 //std::cout << "Loading shape: " << fname << std::endl;
124 BRepTools::Read( shape, fname.c_str(), B );
125 TestViewer::show( shape, AIS_Shaded, true, 0x03399FF );
127 qApp->processEvents();
128 myOverview->setTopView(); //TODO: automatic fit all on show???*/
131 void fitAllWithRestore( OCCViewer_ViewPort3d* vp )
133 double s = vp->getView()->Scale();
135 vp->getView()->Convert( 0, 0, x0, y0, z0 );
136 TestViewer::viewWindow()->onFitAll();
137 vp->getView()->SetScale( s );
139 vp->getView()->Convert( x0, y0, z0, xp, yp );
146 void test_Overview::test_default()
149 //QTest::qWait( 50000 );
150 CPPUNIT_ASSERT_OVERVIEW( "overview_empty" );
154 void test_Overview::test_presentation()
159 //QTest::qWait( 20000 );
160 CPPUNIT_ASSERT_OVERVIEW( "overview_prs" );
163 void test_Overview::test_actions_in_main()
167 TestViewer::viewWindow()->onTopView();
168 qApp->processEvents();
170 OCCViewer_ViewWindow* aMain = TestViewer::viewWindow()->getView( OCCViewer_ViewFrame::MAIN_VIEW );
171 OCCViewer_ViewPort3d* vp = aMain->getViewPort();
173 // 1. selection in main view
174 QTest::mouseMove( vp, QPoint(150,150) );
175 TestViewer::context()->MoveTo(150, 150, vp->getView(), Standard_True );
176 TestViewer::context()->Select( Standard_True );
177 qApp->processEvents();
178 //QTest::qWait( 50000 );
179 //aMain->dumpView().save("/tmp/hydro/dump.png");
180 //aMain->dumpView().rgbSwapped().save("/tmp/hydro/dump2.png");
181 CPPUNIT_ASSERT_OVERVIEW( "overview_selection" );
183 // 2. mouse wheel zoom
184 QWheelEvent we( QPoint( 243, 416 ), 120*20, Qt::NoButton, Qt::NoModifier );
185 qApp->sendEvent( vp, &we );
186 qApp->processEvents();
187 CPPUNIT_ASSERT_OVERVIEW( "overview_zoomed_1" );
191 vp->zoom( 243, 416, 243+d, 416+d );
192 CPPUNIT_ASSERT_OVERVIEW( "overview_zoomed_2" );
194 // 4. panning via mouse
195 vp->pan( 300, -250 );
196 CPPUNIT_ASSERT_OVERVIEW( "overview_panned_1" );
198 // 5. reverse zoom and rotation via mouse
199 vp->getView()->AutoZFit();
200 vp->getView()->ZFitAll();
201 vp->getView()->Camera()->SetZRange( -10, 10 );
202 vp->zoom( 243+d, 416+d, 243, 416 );
203 vp->startRotation( 400, 400, OCCViewer_ViewWindow::BBCENTER, gp_Pnt() );
204 vp->rotate( 200, 300, OCCViewer_ViewWindow::BBCENTER, gp_Pnt() );
206 fitAllWithRestore( vp );
207 // it is necessary to apply fit all to fit correct zmin/zmax
208 // and after that we restore the previous aspect
209 CPPUNIT_ASSERT_OVERVIEW( "overview_rotated_1" );
211 //QTest::qWait( 50000 );
214 void test_Overview::test_set_mainview_2_times()
218 TestViewer::viewWindow()->onTopView();
220 OCCViewer_ViewWindow* aMain = TestViewer::viewWindow()->getView( OCCViewer_ViewFrame::MAIN_VIEW );
221 OCCViewer_ViewPort3d* vp = aMain->getViewPort();
223 QTest::mouseMove( vp, QPoint(150,150) );
224 TestViewer::context()->MoveTo(150, 150, vp->getView(), Standard_True );
225 TestViewer::context()->Select( Standard_True );
226 qApp->processEvents();
228 //QTest::qWait( 20000 );
229 CPPUNIT_ASSERT_OVERVIEW( "overview_selection" );
231 myOverview->setMainView( TestViewer::viewWindow() );
232 qApp->processEvents();
234 CPPUNIT_ASSERT_OVERVIEW( "overview_selection_a" );
237 void test_Overview::test_actions_in_overview()
241 TestViewer::viewWindow()->onTopView();
243 OCCViewer_ViewWindow* aMain = TestViewer::viewWindow()->getView( OCCViewer_ViewFrame::MAIN_VIEW );
244 OCCViewer_ViewPort3d* vp = aMain->getViewPort();
246 QTest::mouseMove( vp, QPoint(150,150) );
247 TestViewer::context()->MoveTo(150, 150, vp->getView(), Standard_True );
248 TestViewer::context()->Select( Standard_True );
249 qApp->processEvents();
251 QWheelEvent we( QPoint( 243, 416 ), 120*20, Qt::NoButton, Qt::NoModifier );
252 qApp->sendEvent( vp, &we );
253 qApp->processEvents();
254 CPPUNIT_ASSERT_OVERVIEW( "overview_zoomed_1" );
256 QTest::mouseMove( myOverview->getViewPort(false), QPoint( 150, 50 ) );
257 QTest::mouseClick( myOverview->getViewPort(false), Qt::LeftButton, Qt::KeyboardModifiers(), QPoint( 150, 50 ) );
258 qApp->processEvents();
260 CPPUNIT_ASSERT_OVERVIEW( "overview_drag" );
262 //QTest::qWait( 50000 );