From b3976e6088a6f296cb8dba106806d4a05df1e683 Mon Sep 17 00:00:00 2001 From: asl Date: Mon, 26 Oct 2015 13:12:40 +0300 Subject: [PATCH] refs #651: dump python -- functionality and test --- src/HYDROData/HYDROData_StricklerTable.cxx | 15 +++- src/HYDROPy/HYDROData_StricklerTable.sip | 11 ++- src/HYDRO_tests/TestViewer.cxx | 34 ++++++++++ src/HYDRO_tests/TestViewer.h | 7 ++ src/HYDRO_tests/reference_data/st_dump.py | 68 +++++++++++++++++++ .../test_HYDROData_StricklerTable.cxx | 15 +++- 6 files changed, 146 insertions(+), 4 deletions(-) create mode 100644 src/HYDRO_tests/reference_data/st_dump.py diff --git a/src/HYDROData/HYDROData_StricklerTable.cxx b/src/HYDROData/HYDROData_StricklerTable.cxx index 9a583a94..b2901ef5 100644 --- a/src/HYDROData/HYDROData_StricklerTable.cxx +++ b/src/HYDROData/HYDROData_StricklerTable.cxx @@ -208,15 +208,26 @@ QStringList HYDROData_StricklerTable::DumpToPython( MapOfTreatedObjects& theTrea QStringList aResList = dumpObjectCreation( theTreatedObjects ); QString aPyName = GetObjPyName(); + QString anAttrName = GetAttrName(); + aResList << QString( "%1.SetAttrName( \"%2\" );" ).arg( aPyName ).arg( anAttrName ); + aResList << QString( "" ); Handle(TDataStd_NamedData) aMap = Map(); if( !aMap.IsNull() ) { for( TDataStd_DataMapIteratorOfDataMapOfStringReal it( aMap->GetRealsContainer() ); it.More(); it.Next() ) { - TCollection_ExtendedString aType = it.Key(); + QString aType = HYDROData_Tool::toQString( it.Key() ); Standard_Real aValue = it.Value(); - aResList << QString( "%1.Set( \"%2\", %3 );" ).arg( aPyName ).arg( QString( (QChar*)aType.ToExtString(), aType.Length() ) ).arg( aValue ); + aResList << QString( "%1.Set( u\"%2\", %3 );" ).arg( aPyName ).arg( aType ).arg( aValue ); + + QString anAttrValue = GetAttrValue( aType ); + aResList << QString( "%1.SetAttrValue( u\"%2\", \"%3\" );" ).arg( aPyName ).arg( aType ).arg( anAttrValue ); + + QColor aColor = GetColor( aType ); + aResList << QString( "%1.SetColor( u\"%2\", QColor( %3, %4, %5 ) );" ). + arg( aPyName ).arg( aType ).arg( aColor.red() ).arg( aColor.green() ).arg( aColor.blue() ); + aResList << QString(); } } aResList << QString( "" ); diff --git a/src/HYDROPy/HYDROData_StricklerTable.sip b/src/HYDROPy/HYDROData_StricklerTable.sip index a6493486..01fe3353 100644 --- a/src/HYDROPy/HYDROData_StricklerTable.sip +++ b/src/HYDROPy/HYDROData_StricklerTable.sip @@ -47,7 +47,16 @@ public: bool Export( const QString& theFileName ); double Get( const QString& theType, double theDefault ) const; - void Set( const QString& theType, double theCoefficient ); + void Set( const QString& theType, double theCoefficient ); + + QString GetAttrName() const; + bool SetAttrName( const QString& ) const; + + QString GetAttrValue( const QString& theType ) const; + void SetAttrValue( const QString& theType, const QString& theAttrValue ) const; + + QColor GetColor( const QString& theType ) const; + void SetColor( const QString& theType, const QColor& theColor ) const; QStringList GetTypes() const; diff --git a/src/HYDRO_tests/TestViewer.cxx b/src/HYDRO_tests/TestViewer.cxx index a7dd45d6..ca224f32 100644 --- a/src/HYDRO_tests/TestViewer.cxx +++ b/src/HYDRO_tests/TestViewer.cxx @@ -271,3 +271,37 @@ void TestViewer::select( int theViewX, int theViewY ) context()->MoveTo( theViewX, theViewY, aView ); context()->Select(); } + +bool TestViewer::areScriptsEqual( const QString& theBaseName ) +{ + QString anExpectedRefFilePath = qgetenv( "HYDRO_REFERENCE_DATA" ); + anExpectedRefFilePath += "/" + theBaseName; + + QString anActualFilePath = QDir::tempPath() + "/" + theBaseName; + + QFile anExpected( anExpectedRefFilePath ); + QFile anActual( anActualFilePath ); + if( !anExpected.open( QFile::ReadOnly | QFile::Text ) || + !anActual.open ( QFile::ReadOnly | QFile::Text ) ) + return false; + + const int aLinesToOmit = 20; + for( int i=0; i #include #include +#include #include #include #include @@ -200,5 +201,17 @@ void test_HYDROData_StricklerTable::test_duplication_refs_613() void test_HYDROData_StricklerTable::test_dump_python() { - //TODO + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + + Handle(HYDROData_StricklerTable) aTable = + Handle(HYDROData_StricklerTable)::DownCast( aDoc->CreateObject( KIND_STRICKLER_TABLE ) ); + aTable->SetName( "ST" ); + CPPUNIT_ASSERT_EQUAL( true, aTable->Import( DEF_STR_PATH ) ); + + QString aTmpPath = QDir::tempPath() + "/st_dump.py"; + CPPUNIT_ASSERT_EQUAL( true, aDoc->DumpToPython( aTmpPath, false ) ); + + CPPUNIT_ASSERT_SCRIPTS_EQUAL( "st_dump.py" ); + + aDoc->Close(); } -- 2.39.2