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 #undef HYDROGUI_EXPORTS
21 #include <test_HYDROGUI_ProfilesDlg.h>
23 #define private public
24 #include <HYDROGUI_ProfileDlg.h>
25 #include <CurveCreator_Widget.h>
28 #include <HYDROGUI_CurveCreatorProfile.h>
29 #include <CurveCreator_TableView.h>
30 #include <CurveCreator_Displayer.hxx>
31 #include <CurveCreator_Utils.hxx>
33 #include <HYDROData_Document.h>
34 #include <HYDROData_Profile.h>
37 #include <TestViewer.h>
38 #include <QApplication>
43 #define CPPUNIT_ASSERT_WIDGET( theWidget, theCase ) \
45 QPixmap aPixmap = QPixmap::grabWindow( theWidget->winId() ); \
46 QImage anImage = aPixmap.toImage(); \
48 if( !TestViewer::AssertImages( aMessage, &anImage, theCase, false ) ) \
50 TestViewer::showColorScale( false ); \
51 std::string aMessageStl = aMessage.toStdString(); \
52 CPPUNIT_FAIL( aMessageStl.c_str() ); \
57 void test_HYDROGUI_ProfilesDlg::test_default_size()
59 HYDROGUI_ProfileDlg* dlg = new HYDROGUI_ProfileDlg( 0, "test" );
60 dlg->resize( 320, 640 );
62 QTest::qWaitForWindowExposed( dlg );
64 CPPUNIT_ASSERT_WIDGET( dlg, "profiles_dlg_presentation" );
67 qApp->processEvents();
70 HYDROGUI_CurveCreatorProfile* profile()
72 static HYDROGUI_CurveCreatorProfile* aProfile = 0;
76 aProfile = new HYDROGUI_CurveCreatorProfile();
77 CurveCreator::Coordinates coords;
78 coords.push_back( 0 );
79 coords.push_back( 20 );
80 coords.push_back( 30 );
81 coords.push_back( 0 );
82 coords.push_back( 60 );
83 coords.push_back( 0 );
84 coords.push_back( 90 );
85 coords.push_back( 20 );
86 aProfile->addPoints( coords, 0 );
90 void show_profile( HYDROGUI_ProfileDlg* dlg )
92 Handle(AIS_InteractiveContext) aCtx = dlg->getAISContext();
93 CurveCreator_Displayer* aDisplayer = new CurveCreator_Displayer( aCtx );
94 profile()->setDisplayer( aDisplayer );
95 aDisplayer->display( profile()->getAISObject( true ), true );
98 void select_points( HYDROGUI_ProfileDlg* dlg )
100 CurveCreator_ICurve::SectionToPointList sel;
101 sel.push_back( CurveCreator_ICurve::SectionToPoint( 0, 0 ) );
102 sel.push_back( CurveCreator_ICurve::SectionToPoint( 0, 1 ) );
103 sel.push_back( CurveCreator_ICurve::SectionToPoint( 0, 2 ) );
104 sel.push_back( CurveCreator_ICurve::SectionToPoint( 0, 3 ) );
105 dlg->myEditorWidget->getAction( CurveCreator_Widget::ModificationMode )->toggle();
106 dlg->myEditorWidget->onModificationMode( true );
107 dlg->myEditorWidget->setSelectedPoints( sel );
108 dlg->myEditorWidget->updateLocalPointView();
111 std::string coords( HYDROGUI_ProfileDlg* dlg, int col=2 )
113 int n = dlg->myEditorWidget->myLocalPointView->rowCount();
115 for( int r=0; r<n; r++ )
117 QString data = dlg->myEditorWidget->myLocalPointView->item(r, col)->data( Qt::DisplayRole ).toString();
118 datas.append( data );
120 return datas.join( ", " ).toStdString();
123 void setCoords( HYDROGUI_ProfileDlg* dlg, int theIndex, double theValue )
125 QAbstractItemModel* m = dlg->myEditorWidget->myLocalPointView->model();
126 QModelIndex index = m->index( theIndex, 2 );
128 m->setData( index, theValue, Qt::UserRole );
129 dlg->myEditorWidget->updateLocalPointView();
132 void test_HYDROGUI_ProfilesDlg::test_points_table()
134 HYDROGUI_ProfileDlg* dlg = new HYDROGUI_ProfileDlg( 0, "test" );
135 dlg->resize( 320, 800 );
136 dlg->setProfile( profile() );
138 QTest::qWaitForWindowExposed( dlg );
141 select_points( dlg );
149 dlg->splitter()->setSizes( sizes );
150 qApp->processEvents();
152 CPPUNIT_ASSERT_WIDGET( dlg, "profiles_selected_points" );
153 CPPUNIT_ASSERT_EQUAL( std::string( "0, 30, 60, 90" ), coords( dlg ) );
154 CPPUNIT_ASSERT_EQUAL( std::string( "20, 0, 0, 20" ), coords( dlg, 3 ) );
156 setCoords( dlg, 0, 130 );
157 CPPUNIT_ASSERT_EQUAL( std::string( "130, 30, 60, 90" ), coords( dlg ) );
158 CPPUNIT_ASSERT_EQUAL( std::string( "20, 0, 0, 20" ), coords( dlg, 3 ) );
160 setCoords( dlg, 0, 0 );
161 CPPUNIT_ASSERT_EQUAL( std::string( "0, 30, 60, 90" ), coords( dlg ) );
162 CPPUNIT_ASSERT_EQUAL( std::string( "20, 0, 0, 20" ), coords( dlg, 3 ) );
164 setCoords( dlg, 0, 80 );
165 dlg->myEditorWidget->myLocalPointView->OnHeaderClick( 2 );
166 CPPUNIT_ASSERT_EQUAL( std::string( "30, 60, 80, 90" ), coords( dlg ) );
167 CPPUNIT_ASSERT_EQUAL( std::string( "0, 0, 20, 20" ), coords( dlg, 3 ) );
169 setCoords( dlg, 2, 0 );
170 CPPUNIT_ASSERT_EQUAL( std::string( "30, 60, 0, 90" ), coords( dlg ) );
171 CPPUNIT_ASSERT_EQUAL( std::string( "0, 0, 20, 20" ), coords( dlg, 3 ) );
173 //qApp->processEvents();
174 //QTest::qWait( 50000 );
177 qApp->processEvents();