]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
#415: tree synchronization
authorasl <asl@opencascade.com>
Thu, 7 Aug 2014 08:04:14 +0000 (08:04 +0000)
committerasl <asl@opencascade.com>
Thu, 7 Aug 2014 08:04:14 +0000 (08:04 +0000)
src/HYDROGUI/CMakeLists.txt
src/HYDROGUI/HYDROGUI_DataModel.cxx
src/HYDROGUI/HYDROGUI_DataModelSync.cxx [new file with mode: 0644]
src/HYDROGUI/HYDROGUI_DataModelSync.h [new file with mode: 0644]
src/HYDROGUI/HYDROGUI_DataObject.cxx
src/HYDROGUI/HYDROGUI_DataObject.h

index 79549b29ce725798faf55ed8e3b491466c87e091..212a5153eb76f2e3bf9595bc5da4966291dd575e 100644 (file)
@@ -14,6 +14,7 @@ set(PROJECT_HEADERS
     HYDROGUI_CopyPastePositionOp.h
     HYDROGUI_DataBrowser.h
     HYDROGUI_DataModel.h
+    HYDROGUI_DataModelSync.h
     HYDROGUI_DataObject.h
     HYDROGUI_DeleteDlg.h
     HYDROGUI_DeleteOp.h
@@ -108,6 +109,7 @@ set(PROJECT_SOURCES
     HYDROGUI_CopyPastePositionOp.cxx
     HYDROGUI_DataBrowser.cxx
     HYDROGUI_DataModel.cxx
+    HYDROGUI_DataModelSync.cxx
     HYDROGUI_DataObject.cxx
     HYDROGUI_DeleteDlg.cxx
     HYDROGUI_DeleteOp.cxx
index 654451d863bd0a2dfcf77abd94e807c45f692f24..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 )
diff --git a/src/HYDROGUI/HYDROGUI_DataModelSync.cxx b/src/HYDROGUI/HYDROGUI_DataModelSync.cxx
new file mode 100644 (file)
index 0000000..58808f1
--- /dev/null
@@ -0,0 +1,96 @@
+
+#include <HYDROGUI_DataModelSync.h>
+#include <HYDROGUI_DataObject.h>
+
+HYDROGUI_DataModelSync::HYDROGUI_DataModelSync( SUIT_DataObject* theRoot )
+  : myRoot( theRoot )
+{
+}
+
+HYDROGUI_DataModelSync::~HYDROGUI_DataModelSync()
+{
+}
+
+void HYDROGUI_DataModelSync::deleteItemWithChildren( const suitPtr& theSuitPtr ) const
+{
+  if( !theSuitPtr )
+    return;
+
+  DataObjectList aChildren;
+  theSuitPtr->children( aChildren );
+  foreach( SUIT_DataObject* anObj, aChildren )
+    deleteItemWithChildren( anObj );
+
+  delete theSuitPtr;
+}
+
+suitPtr HYDROGUI_DataModelSync::nullSrc() const
+{
+  return 0;
+}
+
+suitPtr HYDROGUI_DataModelSync::nullTrg() const
+{
+  return 0;
+}
+
+QList<suitPtr> HYDROGUI_DataModelSync::children( const suitPtr& theSuitPtr ) const
+{
+  QList<suitPtr> aChildren;
+  if( theSuitPtr )
+  {
+    DataObjectList anObjList;
+    theSuitPtr->children( anObjList );
+    foreach( SUIT_DataObject* anObj, anObjList )
+      aChildren.append( anObj );
+  }
+  return aChildren;
+}
+
+suitPtr HYDROGUI_DataModelSync::parent( const suitPtr& theSuitPtr ) const
+{
+  return theSuitPtr ? theSuitPtr->parent() : 0;
+}
+
+void HYDROGUI_DataModelSync::updateItem( const suitPtr& theSrcPtr, const suitPtr& theTrgPtr ) const
+{
+  HYDROGUI_DataObject* aDataObj = dynamic_cast<HYDROGUI_DataObject*>( theTrgPtr );
+  if( aDataObj )
+    aDataObj->updateBy( theSrcPtr );
+
+  HYDROGUI_NamedObject* aNamedObj = dynamic_cast<HYDROGUI_NamedObject*>( theTrgPtr );
+  if( aNamedObj )
+    aNamedObj->updateBy( theSrcPtr );
+}
+
+bool HYDROGUI_DataModelSync::isEqual( const suitPtr& theSrcPtr, const suitPtr& theTrgPtr ) const
+{
+  if( theSrcPtr==myRoot )
+    return true;
+
+  if( theSrcPtr==0 )
+    return theTrgPtr==0;
+
+  if( theTrgPtr==0 )
+    return theSrcPtr==0;
+
+  QString aSrcClass = typeid( *theSrcPtr ).name();
+  QString aTrgClass = typeid( *theTrgPtr ).name();
+  return aSrcClass==aTrgClass;
+}
+
+suitPtr HYDROGUI_DataModelSync::createItem( const suitPtr& theSrcPtr,
+                                            const suitPtr& theParent,
+                                            const suitPtr& theAfter ) const
+{
+  if( theParent )
+  {
+    int aPos = theParent->childPos( theAfter );
+    if( aPos>=0 )
+      theParent->insertChild( theSrcPtr, aPos+1 );
+    else
+      theParent->appendChild( theSrcPtr );
+  }
+  return theSrcPtr;
+}
+
diff --git a/src/HYDROGUI/HYDROGUI_DataModelSync.h b/src/HYDROGUI/HYDROGUI_DataModelSync.h
new file mode 100644 (file)
index 0000000..9192068
--- /dev/null
@@ -0,0 +1,30 @@
+
+#ifndef HYDROGUI_DATA_MODEL_SYNC_HEADER
+#define HYDROGUI_DATA_MODEL_SYNC_HEADER
+
+#include <QList>
+
+class SUIT_DataObject;
+
+typedef SUIT_DataObject* suitPtr;
+
+class HYDROGUI_DataModelSync
+{
+public:
+  HYDROGUI_DataModelSync( SUIT_DataObject* theRoot );
+  ~HYDROGUI_DataModelSync();
+
+  void     deleteItemWithChildren( const suitPtr& ) const;
+  suitPtr  nullSrc() const;
+  suitPtr  nullTrg() const;
+  QList<suitPtr> children( const suitPtr& ) const;
+  suitPtr  parent( const suitPtr& ) const;
+  void     updateItem( const suitPtr&, const suitPtr& ) const;
+  bool     isEqual( const suitPtr&, const suitPtr& ) const;
+  suitPtr  createItem( const suitPtr&, const suitPtr&, const suitPtr& ) const;
+
+private:
+  SUIT_DataObject* myRoot;
+};
+
+#endif
index a259a866e83a88b6078527673b852c0e1d089a07..cde78b0d08e9e8627c87de4228f172a147298d01 100644 (file)
@@ -220,6 +220,22 @@ bool HYDROGUI_DataObject::renameAllowed( const int theColumnId ) const
   return aRes;
 }
 
+void HYDROGUI_DataObject::updateBy( SUIT_DataObject* theObj )
+{
+  HYDROGUI_DataObject* aDataObj = dynamic_cast<HYDROGUI_DataObject*>( theObj );
+  if( !aDataObj )
+    return;
+
+  myData = aDataObj->myData;
+  myParentEntry = aDataObj->myParentEntry;
+  myIsValid = aDataObj->myIsValid;
+  myIsInOperation = aDataObj->myIsInOperation;
+  myIcon = aDataObj->myIcon;
+}
+
+
+
+
 
 
 HYDROGUI_NamedObject::HYDROGUI_NamedObject( SUIT_DataObject* theParent,
@@ -270,6 +286,23 @@ QFont HYDROGUI_NamedObject::font( const int theId ) const
   return aFont;
 }
 
+void HYDROGUI_NamedObject::updateBy( SUIT_DataObject* theObj )
+{
+  HYDROGUI_NamedObject* aNamedObj = dynamic_cast<HYDROGUI_NamedObject*>( theObj );
+  if( !aNamedObj )
+    return;
+
+  myName = aNamedObj->myName;
+  myParentEntry = aNamedObj->myParentEntry;
+  myIcon = aNamedObj->myIcon;
+  myIsInOperation = aNamedObj->myIsInOperation;
+}
+
+
+
+
+
+
 HYDROGUI_DropTargetObject::HYDROGUI_DropTargetObject( SUIT_DataObject* theParent,
                                             const QString&   theName,
                                             const QString&   theParentEntry,
index 6ffeaa1eed17ecf1a0e33710bbba4258d8174289..b35d60c01860e7aa79bb882a5b5e3fb339559d4e 100644 (file)
@@ -141,6 +141,8 @@ public:
    */
   bool isInOperation() const { return myIsInOperation; }
 
+  void updateBy( SUIT_DataObject* );
+
 protected:
   Handle(HYDROData_Entity) myData; ///< object from data model
   QString myParentEntry;
@@ -199,6 +201,8 @@ public:
    */
   bool isInOperation() const { return myIsInOperation; }
 
+  void updateBy( SUIT_DataObject* );
+
 private:
   QString myName; ///< name in the OB
   QString myParentEntry;