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();
62 aMain = aMain.rgbSwapped(); //PATCH for image came from OCCT dump
63 //anOverview = anOverview.rgbSwapped(); //overview dump already normalizes the image, the line is not necessary!!!
65 int w1 = aMain.width();
66 int w2 = anOverview.width();
67 int h1 = aMain.height();
68 int h2 = anOverview.height();
69 int w = w1 + w2 + 2*WIDTH;
70 int h = qMax( h1, h2 ) + 2*WIDTH;
75 QPainter painter( &pix );
76 painter.setPen( PSOLID );
80 //anOverview.save( QString( "/tmp/hydro/overview_" ) + QString::number( q ) + ".png" );
81 //aMain.save( QString( "/tmp/hydro/main_" ) + QString::number( q ) + ".png" );
83 painter.drawImage( WIDTH, WIDTH, anOverview );
84 painter.drawImage( w2+WIDTH, WIDTH, aMain );
86 painter.drawRect( WIDTH, WIDTH, w2, h2 );
87 painter.drawRect( w2+WIDTH, WIDTH, w1, h1 );
89 QImage res = pix.toImage();
90 //res.save( QString( "/tmp/hydro/result_" ) + QString::number( q ) + ".png" );
95 extern int MAIN_W, MAIN_H;
97 void test_Overview::create()
99 TestViewer::eraseAll( true, true );
101 // Initialization of the empty viewer
103 static bool isCreated = false;
106 myOverview = new HYDROGUI_Overview( "Test overview" );
109 // default mouse position
110 QTest::mouseMove( TestViewer::viewWindow(), QPoint( 0, 0 ) );
114 myOverview->setMainView( TestViewer::viewWindow() );
115 //TestViewer::viewWindow()->setGeometry( 400, 100, MAIN_W, MAIN_H );
116 TestViewer::viewWindow()->onTopView();
117 myOverview->setGeometry( 100, 100, 200, 200 );
120 void test_Overview::showShape()
122 // Show loaded shape in the viewer
125 std::string fname = (REF_DATA_PATH + "/test_zone.brep").toStdString();
126 //std::cout << "Loading shape: " << fname << std::endl;
127 BRepTools::Read( shape, fname.c_str(), B );
128 TestViewer::show( shape, AIS_Shaded, true, 0x03399FF );
130 qApp->processEvents();
131 myOverview->setTopView(); //TODO: automatic fit all on show???*/
134 void fitAllWithRestore( OCCViewer_ViewPort3d* vp )
136 double s = vp->getView()->Scale();
138 vp->getView()->Convert( 0, 0, x0, y0, z0 );
139 TestViewer::viewWindow()->onFitAll();
140 vp->getView()->SetScale( s );
142 vp->getView()->Convert( x0, y0, z0, xp, yp );
149 void test_Overview::test_default()
152 //QTest::qWait( 50000 );
153 CPPUNIT_ASSERT_OVERVIEW( "overview_empty" );
157 void test_Overview::test_presentation()
162 //QTest::qWait( 20000 );
163 CPPUNIT_ASSERT_OVERVIEW( "overview_prs" );
166 void test_Overview::test_actions_in_main()
170 TestViewer::viewWindow()->onTopView();
171 qApp->processEvents();
173 OCCViewer_ViewWindow* aMain = TestViewer::viewWindow()->getView( OCCViewer_ViewFrame::MAIN_VIEW );
174 OCCViewer_ViewPort3d* vp = aMain->getViewPort();
176 // 1. selection in main view
177 QTest::mouseMove( vp, QPoint(150,150) );
178 TestViewer::context()->MoveTo(150, 150, vp->getView(), Standard_True );
179 TestViewer::context()->Select( Standard_True );
180 qApp->processEvents();
181 //QTest::qWait( 50000 );
182 //aMain->dumpView().save("/tmp/hydro/dump.png");
183 //aMain->dumpView().rgbSwapped().save("/tmp/hydro/dump2.png");
184 CPPUNIT_ASSERT_OVERVIEW( "overview_selection" );
186 // 2. mouse wheel zoom
187 QWheelEvent we( QPoint( 243, 316 ), 120*20, Qt::NoButton, Qt::NoModifier );
188 qApp->sendEvent( vp, &we );
189 qApp->processEvents();
190 CPPUNIT_ASSERT_OVERVIEW( "overview_zoomed_1" );
194 vp->zoom( 243, 316, 243+d, 316+d );
195 CPPUNIT_ASSERT_OVERVIEW( "overview_zoomed_2" );
197 // 4. panning via mouse
198 vp->pan( 300, -250 );
199 CPPUNIT_ASSERT_OVERVIEW( "overview_panned_1" );
201 // 5. reverse zoom and rotation via mouse
202 vp->getView()->AutoZFit();
203 vp->getView()->ZFitAll();
204 vp->getView()->Camera()->SetZRange( -10, 10 );
205 vp->zoom( 243+d, 416+d, 243, 416 );
206 vp->startRotation( 400, 400, OCCViewer_ViewWindow::BBCENTER, gp_Pnt() );
207 vp->rotate( 200, 300, OCCViewer_ViewWindow::BBCENTER, gp_Pnt() );
209 fitAllWithRestore( vp );
210 // it is necessary to apply fit all to fit correct zmin/zmax
211 // and after that we restore the previous aspect
212 CPPUNIT_ASSERT_OVERVIEW( "overview_rotated_1" );
214 //QTest::qWait( 50000 );
217 void test_Overview::test_set_mainview_2_times()
221 TestViewer::viewWindow()->onTopView();
223 OCCViewer_ViewWindow* aMain = TestViewer::viewWindow()->getView( OCCViewer_ViewFrame::MAIN_VIEW );
224 OCCViewer_ViewPort3d* vp = aMain->getViewPort();
226 QTest::mouseMove( vp, QPoint(150,150) );
227 TestViewer::context()->MoveTo(150, 150, vp->getView(), Standard_True );
228 TestViewer::context()->Select( Standard_True );
229 qApp->processEvents();
231 //QTest::qWait( 20000 );
232 CPPUNIT_ASSERT_OVERVIEW( "overview_selection" );
234 myOverview->setMainView( TestViewer::viewWindow() );
235 qApp->processEvents();
237 CPPUNIT_ASSERT_OVERVIEW( "overview_selection_a" );
240 void test_Overview::test_actions_in_overview()
244 TestViewer::viewWindow()->onTopView();
246 OCCViewer_ViewWindow* aMain = TestViewer::viewWindow()->getView( OCCViewer_ViewFrame::MAIN_VIEW );
247 OCCViewer_ViewPort3d* vp = aMain->getViewPort();
249 QTest::mouseMove( vp, QPoint(150,150) );
250 TestViewer::context()->MoveTo(150, 150, vp->getView(), Standard_True );
251 TestViewer::context()->Select( Standard_True );
252 qApp->processEvents();
254 QWheelEvent we( QPoint( 243, 316 ), 120*20, Qt::NoButton, Qt::NoModifier );
255 qApp->sendEvent( vp, &we );
256 qApp->processEvents();
257 CPPUNIT_ASSERT_OVERVIEW( "overview_zoomed_1" );
259 QTest::mouseMove( myOverview->getViewPort(false), QPoint( 150, 50 ) );
260 QTest::mouseClick( myOverview->getViewPort(false), Qt::LeftButton, Qt::KeyboardModifiers(), QPoint( 150, 50 ) );
261 qApp->processEvents();
263 CPPUNIT_ASSERT_OVERVIEW( "overview_drag" );
265 //QTest::qWait( 50000 );