]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
refs #613: duplicated names
authorasl <asl@opencascade.com>
Mon, 26 Oct 2015 08:20:14 +0000 (11:20 +0300)
committerasl <asl@opencascade.com>
Mon, 26 Oct 2015 08:20:14 +0000 (11:20 +0300)
src/HYDROGUI/HYDROGUI_DataModel.h
src/HYDROGUI/HYDROGUI_DeleteOp.cxx
src/HYDRO_tests/test_HYDROData_StricklerTable.cxx
src/HYDRO_tests/test_HYDROData_StricklerTable.h

index 6d735d86fb522659a30562395f1484838be258ef..2b7d92176c7bd94a8f5b232b6fcd805d6d783f3f 100644 (file)
@@ -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
index 83dd008aca4a7b9efbeca9d4c1180072be28c747..78ab4dec9b51b93c0dbd251e066ccc37edaddfce 100644 (file)
@@ -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<HYDROGUI_DataModel*>( module()->dataModel() );
+    aModel->createDefaultStricklerTable( doc(), 0 );
+  }
+
   commitDocOperation();
 
   module()->update( UF_Model | UF_Viewer | UF_OCCViewer | UF_VTKViewer );
index 05b2dc4b1c2124508522407161606b75653daacd..acdc7a4bb34bce898ceac5c2d36aa2563077a6ed 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <test_HYDROData_StricklerTable.h>
 #include <HYDROData_Document.h>
+#include <HYDROData_Iterator.h>
 #include <HYDROData_StricklerTable.h>
 #include <HYDROData_Tool.h>
 #include <QStringList>
@@ -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
+}
index d12244ce276f38adb4197b59dc9d176bd70dd4c5..a24e2b82fc8474b46bcf18b1a3c5c9af4846b048 100644 (file)
@@ -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 );