Salome HOME
refs #1807
authorisn <isn@opencascade.com>
Wed, 1 Aug 2018 16:32:35 +0000 (19:32 +0300)
committerisn <isn@opencascade.com>
Thu, 6 Sep 2018 14:36:32 +0000 (17:36 +0300)
lot 9 reorder level > 1

src/HYDROGUI/HYDROGUI_DataModel.cxx
src/HYDROGUI/HYDROGUI_Module.cxx
src/HYDROGUI/HYDROGUI_Module.h

index 95862a4d423727f9ff39bd971250d6c0b08002c3..63d4252c76e48e41ec8561d70e867760007440ba 100644 (file)
@@ -59,6 +59,7 @@
 #include <SUIT_Study.h>
 #include <SUIT_Tools.h>
 #include <SUIT_TreeSync.h>
+#include <SUIT_DataObjectIterator.h>
 
 #include <HYDROData_Document.h>
 
@@ -305,11 +306,19 @@ void HYDROGUI_DataModel::update( const int theStudyId )
   // VISUAL STATES
   LightApp_DataObject* aVisualStateRootObj = createObject( aNewRootObj, tr( partitionName( KIND_VISUAL_STATE ).toLatin1() ) );
 
+
   int aNoStricklerTableObj = 0;
+
   HYDROData_Iterator anIterator( aDocument, KIND_UNKNOWN );
-  for( ; anIterator.More(); anIterator.Next() ) {
+  std::vector<Handle(HYDROData_Entity)> ents;
+
+  for( ; anIterator.More(); anIterator.Next() )
+    ents.push_back(anIterator.Current());
+
+  for (int i = 0; i< ents.size();i++)
+  {
     LightApp_DataObject* obj = 0;
-    Handle(HYDROData_Entity) anObj = anIterator.Current();
+    Handle(HYDROData_Entity) anObj = ents[i];
 
     if ( !anObj.IsNull() )
     {
@@ -479,8 +488,79 @@ void HYDROGUI_DataModel::update( const int theStudyId )
   //  anObjectBrowser->openLevels();
   //}
 
-  HYDROGUI_DataModelSync aSync( aNewRootObj );
   SUIT_DataObject* aRoot = root();
+
+  if (aRoot)
+  {
+    std::map<std::string, SUIT_DataObject*> entry2ObjNewRoot;
+    SUIT_DataObjectIterator::DetourType dt = SUIT_DataObjectIterator::DepthLeft;
+    for ( SUIT_DataObjectIterator it( aNewRootObj, dt ); it.current(); ++it )
+    {
+      LightApp_DataObject* aCurObjN = dynamic_cast<LightApp_DataObject*>(it.current());
+      if (aCurObjN)
+        entry2ObjNewRoot[aCurObjN->entry().toStdString()] = it.current();
+    }
+
+    for ( SUIT_DataObjectIterator it( aRoot, dt ); it.current(); ++it )
+    {
+      LightApp_DataObject* aCurObjO = dynamic_cast<LightApp_DataObject*>(it.current());
+      if (aCurObjO && aCurObjO->childCount() > 0)
+      {
+        std::string entry = aCurObjO->entry().toStdString();
+        SUIT_DataObject* newNode = entry2ObjNewRoot[entry];
+        if (newNode && aCurObjO->childCount() > 0)
+        {
+          DataObjectList newchildren;
+          newNode->children(newchildren);
+          //new root - remove children 
+          std::map<std::string, SUIT_DataObject*> newNode2Entries;
+          for ( DataObjectList::const_iterator it = newchildren.begin(); it != newchildren.end(); ++it )
+          {
+            SUIT_DataObject* cc = *it;
+            LightApp_DataObject* obj = dynamic_cast<LightApp_DataObject*>(cc);
+            newNode2Entries[obj->entry().toStdString()] = cc;
+            newNode->removeChild(cc);
+          }
+          //
+          std::set<SUIT_DataObject*> objtemp;
+
+          DataObjectList oldchildren;
+          aCurObjO->children(oldchildren);  
+          for ( DataObjectList::const_iterator it = oldchildren.begin(); it != oldchildren.end(); ++it )
+          {
+            SUIT_DataObject* old_ch = *it;
+            std::string entr = dynamic_cast<LightApp_DataObject*>(old_ch)->entry().toStdString();
+            if (newNode2Entries.count(entr) > 0)
+            {
+              SUIT_DataObject* obj = newNode2Entries[entr]; 
+              newNode->appendChild(obj);
+              objtemp.insert(obj);
+            }
+          }
+          //
+          for ( DataObjectList::const_iterator it = newchildren.begin(); it != newchildren.end(); ++it )
+          {
+            SUIT_DataObject* ch = *it;
+            if (objtemp.count(ch) == 0)
+              newNode->appendChild(ch);
+          }
+          { //IF DEBUG
+            //add. check
+            DataObjectList newchildren2;
+            newNode->children(newchildren2);
+            std::set<std::string> entries2, entries1;
+            for ( DataObjectList::const_iterator it = newchildren2.begin(); it != newchildren2.end(); ++it )
+              entries2.insert((dynamic_cast<LightApp_DataObject*>(*it))->entry().toStdString());
+            for ( DataObjectList::const_iterator it = newchildren.begin(); it != newchildren.end(); ++it )
+              entries1.insert((dynamic_cast<LightApp_DataObject*>(*it))->entry().toStdString());
+            assert(entries1 == entries2);
+          }
+        }
+      }
+    }
+  }
+
+  HYDROGUI_DataModelSync aSync( aNewRootObj );
   bool isNewDoc = aRoot==0;
   if( isNewDoc )
     aRoot = createRootModuleObject( aStudyRoot );
index 54d2a851049d52a4fdabb436b279281abcaf460e..d51503a4a97b38ad4068bf45e9a46748a9fc46e6 100644 (file)
@@ -1992,6 +1992,67 @@ void HYDROGUI_Module::onObjectClicked( SUIT_DataObject* theObject, int theColumn
   update( UF_OCCViewer | UF_VTKViewer | ( visState == Qtx::ShownState ? UF_FitAll : 0 ) );
 }
 
+bool HYDROGUI_Module::isDraggable( const SUIT_DataObject* what ) const
+{
+  return true;
+}
+
+bool HYDROGUI_Module::isDropAccepted( const SUIT_DataObject* where ) const
+{
+
+  return true;
+}
+
+void HYDROGUI_Module::dropObjects( const DataObjectList& what, SUIT_DataObject* where,
+                                   const int row, Qt::DropAction action )
+{
+  if ( action != Qt::CopyAction && action != Qt::MoveAction )
+    return; 
+
+  if (row == -1)
+    return;
+
+  if (where->level() < 2 )
+    return;  
+
+  DataObjectList::ConstIterator it = what.constBegin();
+  for (;it != what.constEnd();++it) 
+  {
+    if ((*it)->parent() != where)
+      return;
+  }
+
+  it = what.constBegin();
+
+  int i=0;
+  for (;it != what.constEnd();++it) 
+  {
+    SUIT_DataObject* objWhat = *it;
+
+    DataObjectList objInSect = where->children();
+
+    //std::list<SUIT_DataObject*> t1 = where->children().toStdList(); //debug
+    int ind = objInSect.indexOf(objWhat);
+    if (ind != -1)
+    {
+      HYDROGUI_DataModel* aModel = getDataModel();
+      int pos = -1;
+      if (ind >= row)
+      {
+        pos = row + i;
+        i++;
+      }
+      else
+        pos = row - 1;
+      where->moveChildPos(objWhat, pos);
+      //std::list<SUIT_DataObject*> t2 = where->children().toStdList(); //debug
+    }  
+  }
+
+  getApp()->updateObjectBrowser(true);
+  
+}
+
 Handle(HYDROData_StricklerTable) HYDROGUI_Module::getLandCoverColoringTable( const int theViewId ) const
 {
   Handle(HYDROData_StricklerTable) aTable;
index 00c87819cb5da34642811bc1494b8f7b0c87a420..116a351dab38b4b56e2dbec65c6f569f81f37128 100644 (file)
@@ -29,6 +29,7 @@
 #include <LightApp_Application.h>
 #include <QEvent>
 #include <QStack>
+#include <HYDROGUI_DataObject.h>
 
 #ifdef WIN32
   #pragma warning ( default: 4251 )
@@ -224,6 +225,13 @@ public:
 
   void                            clearCache();
 
+  bool isDraggable( const SUIT_DataObject* what ) const;
+
+  bool isDropAccepted( const SUIT_DataObject* where ) const;
+
+  void dropObjects( const DataObjectList& what, SUIT_DataObject* where,
+                    const int row, Qt::DropAction action );
+
   /**
    * Returns Strickler table used for Land Cover scalar map coloring in the given view.
    * @param theViewId the view id