X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDRO_tests%2FTestViewer.cxx;h=96eaec9030fb8af7154b31e822d530c164c64bc6;hb=f709724a7a412254db7ee6ca094b01b6dc75e82b;hp=4fc29d343263750c2d268e89d4594fd7ae39d505;hpb=6e821f3c2b6ef1e29bd597c90a70c2b47472775d;p=modules%2Fhydro.git diff --git a/src/HYDRO_tests/TestViewer.cxx b/src/HYDRO_tests/TestViewer.cxx index 4fc29d34..96eaec90 100644 --- a/src/HYDRO_tests/TestViewer.cxx +++ b/src/HYDRO_tests/TestViewer.cxx @@ -5,7 +5,9 @@ #include #include #include +#include #include +#include OCCViewer_ViewManager* TestViewer::myViewManager = 0; OCCViewer_ViewWindow* TestViewer::myViewWindow = 0; @@ -44,21 +46,76 @@ Handle(AIS_InteractiveContext) context() return TestViewer::viewer()->getAISContext(); } -void TestViewer::show( const TopoDS_Shape& theShape, bool isFitAll ) +void TestViewer::show( const TopoDS_Shape& theShape, const QColor& theColor, int theMode ) { - context()->EraseAll(); + QColor aColor = theColor; + if( !aColor.isValid() ) + { + // random color + int aHue = rand()%255; + aColor = QColor::fromHsl( aHue, 255, 128 ); + } + + double r = aColor.red() / 255.0; + double g = aColor.green() / 255.0; + double b = aColor.blue() / 255.0; + Handle(AIS_Shape) aShape = new AIS_Shape( theShape ); - context()->Display( aShape, AIS_Shaded, 0, Standard_False ); + aShape->SetMaterial( Graphic3d_NOM_PLASTIC ); + aShape->SetColor( Quantity_Color( r, g, b, Quantity_TOC_RGB ) ); + context()->Display( aShape, theMode, 0, Standard_False ); +} + +void TestViewer::show( const TopoDS_Shape& theShape, int theMode, bool isFitAll ) +{ + context()->EraseAll(); + + if( theShape.ShapeType()==TopAbs_COMPOUND ) + { + TopoDS_Iterator anIt( theShape ); + for( ; anIt.More(); anIt.Next() ) + show( anIt.Value(), QColor(), theMode ); + } + else + show( theShape, QColor(), theMode ); viewWindow()->onTopView(); viewWindow()->onFitAll(); } -void TestViewer::dump( const TopoDS_Shape& theShape, const QString& theName ) +bool AreImagesEqual( const QImage& theImage1, const QImage& theImage2, double theTolerance = 0.0 ) { - show( theShape ); - QImage anImage = viewWindow()->dumpView(); + if( theImage1.isNull() || theImage2.isNull() ) + return theImage1.isNull() == theImage2.isNull(); + + if( theImage1.size() != theImage2.size() ) + return false; + + int aBytesCount = theImage1.byteCount(); + const uchar *aBytes1 = theImage1.constBits(); + const uchar *aBytes2 = theImage2.constBits(); + for( int i=0; idumpView(); + + QString anExpectedRefFilePath = qgetenv( "HYDRO_REFERENCE_DATA" ); + anExpectedRefFilePath += "/" + theUseCaseName + ".png"; + QImage anExpectedRefImage; + anExpectedRefImage.load( anExpectedRefFilePath ); + + if( AreImagesEqual( anActualImage, anExpectedRefImage ) ) + return true; - QString aPath = QDir::tempPath() + "/" + theName + ".png"; - anImage.save( aPath ); + QString aPath = QDir::tempPath() + "/" + theUseCaseName + ".png"; + anActualImage.save( aPath ); + std::string aMessage = "The viewer contents does not correspond to the reference image: " + theUseCaseName.toStdString(); + CPPUNIT_FAIL( aMessage.c_str() ); + return false; }