Salome HOME
Merge branch 'BR_2018_V8_5' of https://git.forge.pleiade.edf.fr/git/modules-salome...
[modules/hydro.git] / src / HYDRO_tests / test_HYDROGUI_ProfilesDlg.cxx
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.
6 //
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.
11 //
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
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #undef HYDROGUI_EXPORTS
20
21 #include <test_HYDROGUI_ProfilesDlg.h>
22
23 #define private public
24 #include <HYDROGUI_ProfileDlg.h>
25 #include <CurveCreator_Widget.h>
26 #undef private 
27
28 #include <HYDROGUI_CurveCreatorProfile.h>
29 #include <CurveCreator_TableView.h>
30 #include <CurveCreator_Displayer.hxx>
31 #include <CurveCreator_Utils.hxx>
32
33 #include <HYDROData_Document.h>
34 #include <HYDROData_Profile.h>
35
36
37 #include <TestViewer.h>
38 #include <QApplication>
39 #include <QAction>
40 #include <QSplitter>
41 #include <QTest>
42
43 #define CPPUNIT_ASSERT_WIDGET( theWidget, theCase )                           \
44   {                                                                           \
45     QPixmap aPixmap = QPixmap::grabWindow( theWidget->winId() );              \
46     QImage anImage = aPixmap.toImage();                                       \
47     QString aMessage;                                                         \
48     if( !TestViewer::AssertImages( aMessage, &anImage, theCase, false ) )     \
49     {                                                                         \
50       TestViewer::showColorScale( false );                                    \
51       std::string aMessageStl = aMessage.toStdString();                       \
52       CPPUNIT_FAIL( aMessageStl.c_str() );                                    \
53     }                                                                         \
54   }                                                                           \
55
56
57 void test_HYDROGUI_ProfilesDlg::test_default_size()
58 {
59   return;
60   HYDROGUI_ProfileDlg* dlg = new HYDROGUI_ProfileDlg( 0, "test", true );
61   dlg->resize( 320, 640 );
62   dlg->show();
63   QTest::qWaitForWindowExposed( dlg );
64
65   CPPUNIT_ASSERT_WIDGET( dlg, "profiles_dlg_presentation" );
66
67   dlg->deleteLater();
68   qApp->processEvents();
69 }
70
71 HYDROGUI_CurveCreatorProfile* profile()
72 {
73   static HYDROGUI_CurveCreatorProfile* aProfile = 0;
74   if( aProfile )
75     return aProfile;
76
77   aProfile = new HYDROGUI_CurveCreatorProfile();
78   CurveCreator::Coordinates coords;
79   coords.push_back( 0 );
80   coords.push_back( 20 );
81   coords.push_back( 30 );
82   coords.push_back( 0 );
83   coords.push_back( 60 );
84   coords.push_back( 0 );
85   coords.push_back( 90 );
86   coords.push_back( 20 );
87   aProfile->addPoints( coords, 0 );
88   return aProfile;
89 }
90
91 void show_profile( HYDROGUI_ProfileDlg* dlg )
92 {
93   Handle(AIS_InteractiveContext) aCtx = dlg->getAISContext();
94   CurveCreator_Displayer* aDisplayer = new CurveCreator_Displayer( aCtx );
95   profile()->setDisplayer( aDisplayer );
96   aDisplayer->display( profile()->getAISObject( true ), true );
97 }
98
99 void select_points( HYDROGUI_ProfileDlg* dlg )
100 {
101   CurveCreator_ICurve::SectionToPointList sel;
102   sel.push_back( CurveCreator_ICurve::SectionToPoint( 0, 0 ) );
103   sel.push_back( CurveCreator_ICurve::SectionToPoint( 0, 1 ) );
104   sel.push_back( CurveCreator_ICurve::SectionToPoint( 0, 2 ) );
105   sel.push_back( CurveCreator_ICurve::SectionToPoint( 0, 3 ) );
106   dlg->myEditorWidget->getAction( CurveCreator_Widget::ModificationMode )->toggle();
107   dlg->myEditorWidget->onModificationMode( true );
108   dlg->myEditorWidget->setSelectedPoints( sel );
109   dlg->myEditorWidget->updateLocalPointView();
110 }
111
112 std::string coords( HYDROGUI_ProfileDlg* dlg, int col=2 )
113 {
114   int n = dlg->myEditorWidget->myLocalPointView->rowCount();
115   QStringList datas;
116   for( int r=0; r<n; r++ )
117   {
118     QString data = dlg->myEditorWidget->myLocalPointView->item(r, col)->data( Qt::DisplayRole ).toString();
119     datas.append( data );
120   }
121   return datas.join( ", " ).toStdString();
122 }
123
124 void setCoords( HYDROGUI_ProfileDlg* dlg, int theIndex, double theValue )
125 {
126   QAbstractItemModel* m = dlg->myEditorWidget->myLocalPointView->model();
127   QModelIndex index = m->index( theIndex, 2 );
128
129   m->setData( index, theValue, Qt::UserRole );
130   dlg->myEditorWidget->updateLocalPointView();
131 }
132
133 void test_HYDROGUI_ProfilesDlg::test_points_table()
134 {
135   return;
136   HYDROGUI_ProfileDlg* dlg = new HYDROGUI_ProfileDlg( 0, "test", false ); 
137   dlg->resize( 320, 800 );
138   dlg->setProfile( profile() );
139   dlg->show();
140   QTest::qWaitForWindowExposed( dlg );
141
142   show_profile( dlg );  
143   select_points( dlg );
144
145   QList<int> sizes;
146   sizes.append( 25 );
147   sizes.append( 100 );
148   sizes.append( 200 );
149   sizes.append( 25 );
150   sizes.append( 25 );
151   dlg->splitter()->setSizes( sizes );
152   qApp->processEvents();
153
154   CPPUNIT_ASSERT_WIDGET( dlg, "profiles_selected_points" );
155   CPPUNIT_ASSERT_EQUAL( std::string( "0, 30, 60, 90" ), coords( dlg ) );
156   CPPUNIT_ASSERT_EQUAL( std::string( "20, 0, 0, 20" ), coords( dlg, 3 ) );
157   
158   setCoords( dlg, 0, 130 );
159   CPPUNIT_ASSERT_EQUAL( std::string( "130, 30, 60, 90" ), coords( dlg ) );
160   CPPUNIT_ASSERT_EQUAL( std::string( "20, 0, 0, 20" ), coords( dlg, 3 ) );
161
162   setCoords( dlg, 0, 0 );
163   CPPUNIT_ASSERT_EQUAL( std::string( "0, 30, 60, 90" ), coords( dlg ) );
164   CPPUNIT_ASSERT_EQUAL( std::string( "20, 0, 0, 20" ), coords( dlg, 3 ) );
165
166   setCoords( dlg, 0, 80 );
167   dlg->myEditorWidget->myLocalPointView->OnHeaderClick( 2 );
168   CPPUNIT_ASSERT_EQUAL( std::string( "30, 60, 80, 90" ), coords( dlg ) );
169   CPPUNIT_ASSERT_EQUAL( std::string( "0, 0, 20, 20" ), coords( dlg, 3 ) );
170
171   setCoords( dlg, 2, 0 );
172   CPPUNIT_ASSERT_EQUAL( std::string( "30, 60, 0, 90" ), coords( dlg ) );
173   CPPUNIT_ASSERT_EQUAL( std::string( "0, 0, 20, 20" ), coords( dlg, 3 ) );
174
175   //qApp->processEvents();
176   //QTest::qWait( 50000 );
177
178   dlg->deleteLater();
179   qApp->processEvents();
180 }