From 717022c15305dda37a3476f180e5deea10523d91 Mon Sep 17 00:00:00 2001 From: asl Date: Mon, 26 Oct 2015 11:20:14 +0300 Subject: [PATCH] refs #613: duplicated names --- src/HYDROGUI/HYDROGUI_DataModel.h | 15 +++--- src/HYDROGUI/HYDROGUI_DeleteOp.cxx | 17 ++++-- .../test_HYDROData_StricklerTable.cxx | 52 +++++++++++++++++++ .../test_HYDROData_StricklerTable.h | 4 ++ 4 files changed, 78 insertions(+), 10 deletions(-) diff --git a/src/HYDROGUI/HYDROGUI_DataModel.h b/src/HYDROGUI/HYDROGUI_DataModel.h index 6d735d86..2b7d9217 100644 --- a/src/HYDROGUI/HYDROGUI_DataModel.h +++ b/src/HYDROGUI/HYDROGUI_DataModel.h @@ -255,6 +255,14 @@ public: */ static QString partitionName( const ObjectKind theObjectKind ); + /** + * Creates the default Strickler table object: both GUI data object and corresponding model object + * \param theDocument a document into which created object will be added + * \param theParent a created object will be appended as a child of this GUI object + */ + void createDefaultStricklerTable( const Handle(HYDROData_Document)& theDocument, + LightApp_DataObject* theParent ); + protected: /** * Returns the document for the current study @@ -324,13 +332,6 @@ protected: const QString& theParentEntry, const bool theIsBuildTree , const bool theIsInOperation = false ); - /** - * Creates the default Strickler table object: both GUI data object and corresponding model object - * \param theDocument a document into which created object will be added - * \param theParent a created object will be appended as a child of this GUI object - */ - void createDefaultStricklerTable( const Handle(HYDROData_Document)& theDocument, - LightApp_DataObject* theParent ); /** * Build partition for object. * \param theObject gui object for which the partition will be build diff --git a/src/HYDROGUI/HYDROGUI_DeleteOp.cxx b/src/HYDROGUI/HYDROGUI_DeleteOp.cxx index 83dd008a..78ab4dec 100644 --- a/src/HYDROGUI/HYDROGUI_DeleteOp.cxx +++ b/src/HYDROGUI/HYDROGUI_DeleteOp.cxx @@ -17,7 +17,7 @@ // #include "HYDROGUI_DeleteOp.h" - +#include "HYDROGUI_DataModel.h" #include "HYDROGUI_DeleteDlg.h" #include "HYDROGUI_Module.h" #include "HYDROGUI_Tool.h" @@ -117,16 +117,21 @@ void HYDROGUI_DeleteOp::startOperation() HYDROGUI_DeleteDlg aDeleteDlg( module()->getApp()->desktop() ); aDeleteDlg.setObjectsToRemove( anObjNames ); + bool isLastStricklerRemoved = false; if ( aDeleteDlg.exec() != HYDROGUI_DeleteDlg::Accepted ) { abort(); return; - } else { + } + else + { QStringList aTableNames = HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_STRICKLER_TABLE, false ); aTableNames += anObjNames; - if ( aTableNames.toSet().size() == anObjNames.size() ) { + if ( aTableNames.toSet().size() == anObjNames.size() ) + { aWarningMsg = tr("DELETE_LAST_TABLE_WRN"); + isLastStricklerRemoved = true; } } @@ -153,6 +158,12 @@ void HYDROGUI_DeleteOp::startOperation() } } + if( isLastStricklerRemoved ) + { + HYDROGUI_DataModel* aModel = dynamic_cast( module()->dataModel() ); + aModel->createDefaultStricklerTable( doc(), 0 ); + } + commitDocOperation(); module()->update( UF_Model | UF_Viewer | UF_OCCViewer | UF_VTKViewer ); diff --git a/src/HYDRO_tests/test_HYDROData_StricklerTable.cxx b/src/HYDRO_tests/test_HYDROData_StricklerTable.cxx index 05b2dc4b..acdc7a4b 100644 --- a/src/HYDRO_tests/test_HYDROData_StricklerTable.cxx +++ b/src/HYDRO_tests/test_HYDROData_StricklerTable.cxx @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -150,3 +151,54 @@ void test_HYDROData_StricklerTable::test_colors_sync() aDoc->Close(); } + +void test_HYDROData_StricklerTable::test_duplication_refs_613() +{ + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + + Handle(HYDROData_StricklerTable) aTable1 = + Handle(HYDROData_StricklerTable)::DownCast( aDoc->CreateObject( KIND_STRICKLER_TABLE ) ); + aTable1->Set( "type1", 1.5 ); + aTable1->SetColor( "type1", QColor( 10, 20, 30 ) ); + aTable1->SetName( "DefStrickler_1" ); + + Handle(HYDROData_StricklerTable) aTable2 = + Handle(HYDROData_StricklerTable)::DownCast( aDoc->CreateObject( KIND_STRICKLER_TABLE ) ); + aTable1->CopyTo( aTable2, true ); + + CPPUNIT_ASSERT_EQUAL( QString( "DefStrickler_2" ), aTable2->GetName() ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.5, aTable2->Get( "type1", 0.0 ), 1E-5 ); + CPPUNIT_ASSERT_EQUAL( QColor( 10, 20, 30 ), aTable2->GetColor( "type1" ) ); + + aDoc->StartOperation(); + aTable1->Remove(); + aTable2->Remove(); + Handle(HYDROData_StricklerTable) aTable3 = + Handle(HYDROData_StricklerTable)::DownCast( aDoc->CreateObject( KIND_STRICKLER_TABLE ) ); + aTable3->SetName( "DefStrickler_1" ); + aDoc->CommitOperation(); + + HYDROData_Iterator anIt1( aDoc, KIND_STRICKLER_TABLE ); + CPPUNIT_ASSERT_EQUAL( true, anIt1.More() ); + CPPUNIT_ASSERT_EQUAL( QString( "DefStrickler_1" ), anIt1.Current()->GetName() ); + anIt1.Next(); + CPPUNIT_ASSERT_EQUAL( false, anIt1.More() ); + + aDoc->Undo(); + + HYDROData_Iterator anIt2( aDoc, KIND_STRICKLER_TABLE ); + CPPUNIT_ASSERT_EQUAL( true, anIt2.More() ); + CPPUNIT_ASSERT_EQUAL( QString( "DefStrickler_1" ), anIt2.Current()->GetName() ); + anIt2.Next(); + CPPUNIT_ASSERT_EQUAL( true, anIt2.More() ); + CPPUNIT_ASSERT_EQUAL( QString( "DefStrickler_2" ), anIt2.Current()->GetName() ); + anIt2.Next(); + CPPUNIT_ASSERT_EQUAL( false, anIt2.More() ); + + aDoc->Close(); +} + +void test_HYDROData_StricklerTable::test_dump_python() +{ + //TODO +} diff --git a/src/HYDRO_tests/test_HYDROData_StricklerTable.h b/src/HYDRO_tests/test_HYDROData_StricklerTable.h index d12244ce..a24e2b82 100644 --- a/src/HYDRO_tests/test_HYDROData_StricklerTable.h +++ b/src/HYDRO_tests/test_HYDROData_StricklerTable.h @@ -30,6 +30,8 @@ class test_HYDROData_StricklerTable : public CppUnit::TestFixture CPPUNIT_TEST( test_type_by_attr ); CPPUNIT_TEST( test_unique_attr_name ); CPPUNIT_TEST( test_colors_sync ); + CPPUNIT_TEST( test_duplication_refs_613 ); + CPPUNIT_TEST( test_dump_python ); CPPUNIT_TEST_SUITE_END(); public: @@ -38,6 +40,8 @@ public: void test_type_by_attr(); void test_unique_attr_name(); void test_colors_sync(); + void test_duplication_refs_613(); + void test_dump_python(); }; CPPUNIT_TEST_SUITE_REGISTRATION( test_HYDROData_StricklerTable ); -- 2.39.2