Salome HOME
refs #369: local CS for profiles
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_DataModel.cxx
index 0476f169f858ccd0fa007606415710c4e8c19888..cb445127bd4694ca6f75093699e15852d3b2b8a3 100644 (file)
@@ -30,6 +30,7 @@
 
 #include <HYDROData_Bathymetry.h>
 #include <HYDROData_CalculationCase.h>
+#include <HYDROGUI_DataModelSync.h>
 #include <HYDROData_Document.h>
 #include <HYDROData_DummyObject3D.h>
 #include <HYDROData_Image.h>
@@ -61,6 +62,7 @@
 #include <SUIT_ResourceMgr.h>
 #include <SUIT_Study.h>
 #include <SUIT_Tools.h>
+#include <SUIT_TreeSync.h>
 
 #include <HYDROData_Document.h>
 
@@ -219,19 +221,8 @@ void HYDROGUI_DataModel::update( const int theStudyId )
   if( !aStudyRoot )
     return;
 
-  // create root object if not exist
-  CAM_DataObject* aRootObj = root();
-  if( !aRootObj )
-    aRootObj = createRootModuleObject( aStudyRoot );
-
-  if( !aRootObj )
-    return;
-
-  DataObjectList aList;
-  aRootObj->children( aList );
-  QListIterator<SUIT_DataObject*> anIter( aList );
-  while( anIter.hasNext() )
-    removeChild( aRootObj, anIter.next() );
+  // create a new root object
+  CAM_DataObject* aNewRootObj = new CAM_DataObject();
 
   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theStudyId );
   if( aDocument.IsNull() )
@@ -240,34 +231,34 @@ void HYDROGUI_DataModel::update( const int theStudyId )
   // Create root objects:
 
   // IMAGES
-  LightApp_DataObject* anImageRootObj = createObject( aRootObj, tr( partitionName( KIND_IMAGE ).toAscii() ) );
+  LightApp_DataObject* anImageRootObj = createObject( aNewRootObj, tr( partitionName( KIND_IMAGE ).toAscii() ) );
 
   // BATHYMETRY
-  LightApp_DataObject* aBathymetryRootObj = createObject( aRootObj, tr( partitionName( KIND_BATHYMETRY ).toAscii() ) );
+  LightApp_DataObject* aBathymetryRootObj = createObject( aNewRootObj, tr( partitionName( KIND_BATHYMETRY ).toAscii() ) );
 
   // ARTIFICIAL OBJECTS
-  LightApp_DataObject* anArtificialObjectsRootObj = createObject( aRootObj, tr( partitionName( KIND_ARTIFICIAL_OBJECT ).toAscii() ) );
+  LightApp_DataObject* anArtificialObjectsRootObj = createObject( aNewRootObj, tr( partitionName( KIND_ARTIFICIAL_OBJECT ).toAscii() ) );
 
   // NATURAL OBJECTS
-  LightApp_DataObject* aNaturalObjectsRootObj = createObject( aRootObj, tr( partitionName( KIND_NATURAL_OBJECT ).toAscii() ) );
+  LightApp_DataObject* aNaturalObjectsRootObj = createObject( aNewRootObj, tr( partitionName( KIND_NATURAL_OBJECT ).toAscii() ) );
 
   // OBSTACLES
-  LightApp_DataObject* anObstaclesRootObj = createObject( aRootObj, tr( partitionName( KIND_OBSTACLE ).toAscii() ) );
+  LightApp_DataObject* anObstaclesRootObj = createObject( aNewRootObj, tr( partitionName( KIND_OBSTACLE ).toAscii() ) );
 
   // CALCULATION CASES
-  LightApp_DataObject* aCalculRootObj = createObject( aRootObj, tr( partitionName( KIND_CALCULATION ).toAscii() ) );
+  LightApp_DataObject* aCalculRootObj = createObject( aNewRootObj, tr( partitionName( KIND_CALCULATION ).toAscii() ) );
 
   // POLYLINES
-  LightApp_DataObject* aPolylineRootObj = createObject( aRootObj, tr( partitionName( KIND_POLYLINEXY ).toAscii() ) );
+  LightApp_DataObject* aPolylineRootObj = createObject( aNewRootObj, tr( partitionName( KIND_POLYLINEXY ).toAscii() ) );
 
   // POLYLINES
-  LightApp_DataObject* aPolyline3DRootObj = createObject( aRootObj, tr( partitionName( KIND_POLYLINE ).toAscii() ) );
+  LightApp_DataObject* aPolyline3DRootObj = createObject( aNewRootObj, tr( partitionName( KIND_POLYLINE ).toAscii() ) );
 
   // PROFILES
-  LightApp_DataObject* aProfileRootObj = createObject( aRootObj, tr( partitionName( KIND_PROFILE ).toAscii() ) );
+  LightApp_DataObject* aProfileRootObj = createObject( aNewRootObj, tr( partitionName( KIND_PROFILE ).toAscii() ) );
 
   // VISUAL STATES
-  LightApp_DataObject* aVisualStateRootObj = createObject( aRootObj, tr( partitionName( KIND_VISUAL_STATE ).toAscii() ) );
+  LightApp_DataObject* aVisualStateRootObj = createObject( aNewRootObj, tr( partitionName( KIND_VISUAL_STATE ).toAscii() ) );
 
   HYDROData_Iterator anIterator( aDocument, KIND_UNKNOWN );
   for( ; anIterator.More(); anIterator.Next() ) {
@@ -410,11 +401,18 @@ void HYDROGUI_DataModel::update( const int theStudyId )
     }
   }
 
-  if( SUIT_DataBrowser* anObjectBrowser = anApp->objectBrowser() )
-  {
-    anObjectBrowser->setAutoOpenLevel( 3 );
-    anObjectBrowser->openLevels();
-  }
+  //if( SUIT_DataBrowser* anObjectBrowser = anApp->objectBrowser() )
+  //{
+  //  anObjectBrowser->setAutoOpenLevel( 3 );
+  //  anObjectBrowser->openLevels();
+  //}
+
+  HYDROGUI_DataModelSync aSync( aNewRootObj );
+  SUIT_DataObject* aRoot = root();
+  if( !aRoot )
+    aRoot = createRootModuleObject( aStudyRoot );
+  ::synchronize < suitPtr, suitPtr, HYDROGUI_DataModelSync >
+    ( aNewRootObj, aRoot, aSync );
 }
 
 HYDROGUI_DataObject* HYDROGUI_DataModel::getDataObject( const Handle(HYDROData_Entity)& theModelObject )
@@ -601,6 +599,9 @@ bool HYDROGUI_DataModel::paste()
         anObject->CopyTo( aClone );
         anIsChanged = true;
 
+        // remove Z layer
+        aClone->RemoveZLevel();
+        
         // generate a new unique name for the clone object:
         // case 1: Image_1 -> Image_2
         // case 2: ImageObj -> ImageObj_1