Salome HOME
Merge branch 'BR_PY3'
[modules/hydro.git] / src / HYDRO_tests / TestViewer.h
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 #pragma once
20
21 #include <AIS_InteractiveContext.hxx>
22 #include <Standard_Version.hxx>
23
24 class OCCViewer_ViewManager;
25 class OCCViewer_Viewer;
26 class OCCViewer_ViewFrame;
27 class TopoDS_Shape;
28 class QString;
29 class QColor;
30 class QImage;
31 class AIS_InteractiveObject;
32 class AIS_ColorScale;
33
34 #define OCC_VERSION_LARGE (OCC_VERSION_MAJOR << 24 | OCC_VERSION_MINOR << 16 | OCC_VERSION_MAINTENANCE << 8)
35 #if OCC_VERSION_LARGE >= 0x07020000
36 const bool SWAP_RGB = false;
37 #else
38 const bool SWAP_RGB = true;
39 #endif
40
41 class TestViewer
42 {
43 public:
44   static OCCViewer_ViewManager* viewManager();
45   static OCCViewer_Viewer* viewer();
46   static OCCViewer_ViewFrame* viewWindow();
47   static Handle(AIS_InteractiveContext) context();
48
49   static void eraseAll( bool isUpdate, bool eraseStructures = false );
50   static void show( const Handle(AIS_InteractiveObject)& theObject,
51                     int theMode, int theSelectionMode, bool isFitAll, const char* theKey );
52   static void show( const TopoDS_Shape& theShape, int theMode, bool isFitAll, const QColor& theColor,
53                     int theUIANb = 10, int theVIANb = 10);
54   static void show( const TopoDS_Shape& theShape, int theMode, bool isFitAll, const char* theKey,
55                     int theUIANb = 10, int theVIANb = 10);
56   static bool AssertImages( QString& theMessage, const QImage* = 0, const char* theCase = 0, bool swapRGB = SWAP_RGB );
57   static QColor GetColor(int i);
58
59   static Handle(AIS_ColorScale) colorScale();
60   static void showColorScale( bool );
61   static bool ColorScaleIsDisplayed();
62
63   static void select( int theViewX, int theViewY );
64
65   static bool areScriptsEqual( const QString& theBaseName,
66                                bool isExpectedUtf8,
67                                bool isActualUtf8,
68                                int theLinesToOmit,
69                                QString& theMsg );
70
71   static void setKey( const QString& );
72   static void fitAll();
73   static QImage diff( const QImage& im1, const QImage& im2 );
74
75 private:
76   static OCCViewer_ViewManager* myViewManager;
77   static OCCViewer_ViewFrame* myViewWindow;
78   static QString myKey;
79 };
80
81 #define CPPUNIT_ASSERT_IMAGES                              \
82   {                                                        \
83     QString aMessage;                                      \
84     if( !TestViewer::AssertImages( aMessage ) )            \
85     {                                                      \
86       TestViewer::showColorScale( false );                 \
87       std::string aMessageStl = aMessage.toStdString();    \
88       CPPUNIT_FAIL( aMessageStl.c_str() );                 \
89     }                                                      \
90   }                                                        \
91
92 #define CPPUNIT_ASSERT_IMAGES2( theImage, theCase )        \
93   {                                                        \
94     QString aMessage;                                      \
95     if( !TestViewer::AssertImages( aMessage, theImage, theCase ) ) \
96     {                                                      \
97       TestViewer::showColorScale( false );                 \
98       std::string aMessageStl = aMessage.toStdString();    \
99       CPPUNIT_FAIL( aMessageStl.c_str() );                 \
100     }                                                      \
101   }                                                        \
102
103 #define CPPUNIT_ASSERT_IMAGES3( theImage, theCase, theSwapRGB )        \
104   {                                                        \
105     QString aMessage;                                      \
106     if( !TestViewer::AssertImages( aMessage, theImage, theCase, theSwapRGB ) ) \
107     {                                                      \
108       TestViewer::showColorScale( false );                 \
109       std::string aMessageStl = aMessage.toStdString();    \
110       CPPUNIT_FAIL( aMessageStl.c_str() );                 \
111     }                                                      \
112   }   
113
114 #define CPPUNIT_ASSERT_SCRIPTS_EQUAL( theBaseName,         \
115                                       isExpectedUtf8,      \
116                                       isActualUtf8,        \
117                                       theLinesToOmit )     \
118   {                                                        \
119     QString aMsg;                                          \
120     if( !TestViewer::areScriptsEqual(                      \
121           theBaseName, isExpectedUtf8,                     \
122           isActualUtf8, theLinesToOmit, aMsg ) )           \
123     {                                                      \
124       std::string aStlMsg = "Scripts are not equal: " +    \
125         aMsg.toStdString();                                \
126       CPPUNIT_FAIL( aStlMsg );                             \
127     }                                                      \
128   }                                                        \
129                                                            \
130