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_ViewPort3d.h>
31 #include <V3d_View.hxx>
33 extern QString REF_DATA_PATH;
34 HYDROGUI_Overview* test_Overview::myOverview = 0;
36 #define CPPUNIT_ASSERT_OVERVIEW( theCase ) \
39 QImage aDump = dumpViews(); \
40 if( !TestViewer::AssertImages( aMessage, &aDump, theCase, false ) ) \
42 TestViewer::showColorScale( false ); \
43 std::string aMessageStl = aMessage.toStdString(); \
44 CPPUNIT_FAIL( aMessageStl.c_str() ); \
48 const int m = 5; //margins
49 const QColor aColor = Qt::blue;
50 const QBrush SOLID( aColor );
52 const QPen PSOLID( SOLID, WIDTH );
53 const QColor BACK = Qt::white;
55 QImage test_Overview::dumpViews()
57 QImage aMain = TestViewer::viewWindow()->getView(OCCViewer_ViewFrame::MAIN_VIEW)->dumpView();
58 QImage anOverview = myOverview->dump();
60 aMain = aMain.rgbSwapped(); //PATCH for image came from OCCT dump
61 //anOverview = anOverview.rgbSwapped(); //overview dump already normalizes the image, the line is not necessary!!!
63 int w1 = aMain.width();
64 int w2 = anOverview.width();
65 int h1 = aMain.height();
66 int h2 = anOverview.height();
67 int w = w1 + w2 + 2*WIDTH;
68 int h = qMax( h1, h2 ) + 2*WIDTH;
73 QPainter painter( &pix );
74 painter.setPen( PSOLID );
76 painter.drawRect( WIDTH, WIDTH, w2, h2 );
77 painter.drawRect( w2+WIDTH, WIDTH, w1, h1 );
79 painter.drawImage( WIDTH, WIDTH, anOverview );
80 painter.drawImage( w2+WIDTH, WIDTH, aMain );
85 void test_Overview::create()
87 static bool isPassed = false;
91 // default mouse position
92 QTest::mouseMove( TestViewer::viewWindow(), QPoint( 0, 0 ) );
94 // Initialization of the empty viewer
95 myOverview = new HYDROGUI_Overview( "Test overview" );
97 myOverview->setMainView( TestViewer::viewWindow() );
98 TestViewer::viewWindow()->setGeometry( 400, 100, 800, 800 );
99 TestViewer::viewWindow()->onTopView();
100 myOverview->setGeometry( 100, 100, 200, 200 );
105 void test_Overview::showShape()
107 static bool isPassed = false;
111 // Show loaded shape in the viewer
114 std::string fname = (REF_DATA_PATH + "/test_zone.brep").toStdString();
115 BRepTools::Read( shape, fname.c_str(), B );
116 TestViewer::show( shape, AIS_Shaded, true, 0x03399FF );
118 qApp->processEvents();
119 myOverview->setTopView(); //TODO: automatic fit all on show???*/
124 void fitAllWithRestore( OCCViewer_ViewPort3d* vp )
126 double s = vp->getView()->Scale();
128 vp->getView()->Convert( 0, 0, x0, y0, z0 );
129 TestViewer::viewWindow()->onFitAll();
130 vp->getView()->SetScale( s );
132 vp->getView()->Convert( x0, y0, z0, xp, yp );
139 void test_Overview::test_default()
142 //QTest::qWait( 50000 );
143 CPPUNIT_ASSERT_OVERVIEW( "overview_empty" );
147 void test_Overview::test_presentation()
152 //QTest::qWait( 20000 );
153 CPPUNIT_ASSERT_OVERVIEW( "overview_prs" );
156 void test_Overview::test_actions_in_main()
160 TestViewer::viewWindow()->onTopView();
162 OCCViewer_ViewWindow* aMain = TestViewer::viewWindow()->getView( OCCViewer_ViewFrame::MAIN_VIEW );
163 OCCViewer_ViewPort3d* vp = aMain->getViewPort();
165 // 1. selection in main view
166 QTest::mouseMove( TestViewer::viewWindow() );
167 CPPUNIT_ASSERT_OVERVIEW( "overview_selection" );
169 // 2. mouse wheel zoom
170 QWheelEvent we( QPoint( 243, 416 ), 120*20, Qt::NoButton, Qt::NoModifier );
171 qApp->sendEvent( vp, &we );
172 qApp->processEvents();
173 CPPUNIT_ASSERT_OVERVIEW( "overview_zoomed_1" );
177 vp->zoom( 243, 416, 243+d, 416+d );
178 CPPUNIT_ASSERT_OVERVIEW( "overview_zoomed_2" );
180 // 4. panning via mouse
181 vp->pan( 300, -250 );
182 CPPUNIT_ASSERT_OVERVIEW( "overview_panned_1" );
184 // 5. reverse zoom and rotation via mouse
185 vp->getView()->AutoZFit();
186 vp->getView()->ZFitAll();
187 vp->getView()->Camera()->SetZRange( -10, 10 );
188 vp->zoom( 243+d, 416+d, 243, 416 );
189 vp->startRotation( 400, 400, OCCViewer_ViewWindow::BBCENTER, gp_Pnt() );
190 vp->rotate( 200, 300, OCCViewer_ViewWindow::BBCENTER, gp_Pnt() );
192 fitAllWithRestore( vp );
193 // it is necessary to apply fit all to fit correct zmin/zmax
194 // and after that we restore the previous aspect
195 CPPUNIT_ASSERT_OVERVIEW( "overview_rotated_1" );
197 //QTest::qWait( 50000 );
200 void test_Overview::test_set_mainview_2_times()
204 TestViewer::viewWindow()->onTopView();
205 QTest::mouseMove( TestViewer::viewWindow() );
207 //QTest::qWait( 20000 );
208 CPPUNIT_ASSERT_OVERVIEW( "overview_selection" );
210 myOverview->setMainView( TestViewer::viewWindow() );
211 qApp->processEvents();
213 CPPUNIT_ASSERT_OVERVIEW( "overview_selection" );
216 void test_Overview::test_actions_in_overview()