Salome HOME
refs #568: use ordered list view with selection synchronized with object browser...
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ZLevelsOp.cxx
index 085b8e98a280907be7747f6135e044cdf145529b..64d3c157a503e3d6bb09e47a5054e029d506f7e6 100644 (file)
@@ -1,12 +1,8 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
-//
-// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
+// Copyright (C) 2014-2015  EDF-R&D
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -27,6 +23,7 @@
 #include "HYDROGUI_Module.h"
 #include "HYDROGUI_Tool.h"
 #include "HYDROGUI_UpdateFlags.h"
+#include "HYDROGUI_ListSelector.h"
 
 #include <HYDROData_Entity.h>
 
@@ -41,7 +38,7 @@
 */
 HYDROGUI_ZLevelsOp::HYDROGUI_ZLevelsOp( HYDROGUI_Module* theModule )
 : HYDROGUI_Operation( theModule ),
-  myZLevelsDlg( NULL )
+  myDlg( NULL )
 {
   setName( tr( "SET_Z_LEVELS" ) );
 }
@@ -60,7 +57,7 @@ void HYDROGUI_ZLevelsOp::startOperation()
   HYDROGUI_Operation::startOperation();
 
   // Prepare the list of objects
-  HYDROGUI_ZLevelsModel::Object2VisibleList anObject2VisibleList;
+  HYDROGUI_ListModel::Object2VisibleList anObject2VisibleList;
 
   // get the document
   Handle(HYDROData_Document) aDoc = doc();
@@ -75,34 +72,35 @@ void HYDROGUI_ZLevelsOp::startOperation()
       Handle(HYDROData_Entity) anObject = anIter.Value();
       if ( !anObject.IsNull() ) {
         bool isVisible = module()->isObjectVisible( anActiveOCCViewId, anObject );
-        anObject2VisibleList << HYDROGUI_ZLevelsModel::Object2Visible( anObject, isVisible );
+        anObject2VisibleList << HYDROGUI_ListModel::Object2Visible( anObject, isVisible );
       }
     }
   }
 
   // Show the dialog
-  myZLevelsDlg = new HYDROGUI_ZLevelsDlg( module()->getApp()->desktop() );
-  myZLevelsDlg->setModal( true );
-  myZLevelsDlg->setObjects( anObject2VisibleList );
-
-  //TODO: check
-  connect( myZLevelsDlg, SIGNAL( applyOrder() ), this, SLOT( onApply() ) );
-  connect( myZLevelsDlg, SIGNAL( rejected() ), this, SLOT( onCancel() ) );
+  if ( !myDlg ) {
+    myDlg = new HYDROGUI_ZLevelsDlg( module()->getApp()->desktop(), module() );
+       connect( myDlg, SIGNAL( applyOrderAndClose() ), this, SLOT( onApplyAndClose() ) );
+    connect( myDlg, SIGNAL( applyOrder() ), this, SLOT( onApply() ) );
+    connect( myDlg, SIGNAL( rejected() ), this, SLOT( onCancel() ) );
+  }
+  myDlg->setObjects( anObject2VisibleList );
 
-  myZLevelsDlg->exec();
+  myDlg->exec();
 }
 
 /**
 */
 bool HYDROGUI_ZLevelsOp::processApply( int& theUpdateFlags,
-                                       QString& theErrorMsg )
+                                       QString& theErrorMsg,
+                                       QStringList& theBrowseObjectsEntries )
 {
   bool aRes = false;
 
-  if ( myZLevelsDlg ) {
+  if ( myDlg ) {
     Handle(HYDROData_Document) aDoc = doc();
     if( !aDoc.IsNull() ) {
-      HYDROGUI_ZLevelsModel::ObjectList anObjects = myZLevelsDlg->getObjects();
+      HYDROGUI_ListModel::ObjectList anObjects = myDlg->getObjects();
       HYDROData_SequenceOfObjects anOrderedObjects;
       foreach ( const Handle(HYDROData_Entity) anObject, anObjects ) {
         anOrderedObjects.Append( anObject );
@@ -110,7 +108,7 @@ bool HYDROGUI_ZLevelsOp::processApply( int& theUpdateFlags,
 
       aDoc->SetObjectsLayerOrder( anOrderedObjects );
 
-      theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced;
+      theUpdateFlags = UF_Model | UF_OCCViewer;
       aRes = true;
     }
   }
@@ -118,3 +116,27 @@ bool HYDROGUI_ZLevelsOp::processApply( int& theUpdateFlags,
   return aRes;
 }
 
+/**
+*/
+bool HYDROGUI_ZLevelsOp::isGranted() const
+{
+  return true;
+}
+
+/**
+*/
+void HYDROGUI_ZLevelsOp::processCancel()
+{
+  // Delete the dialog
+  if ( myDlg ) {
+    delete myDlg;
+    myDlg = 0;
+  }
+}
+
+void HYDROGUI_ZLevelsOp::onApplyAndClose()
+{
+  HYDROGUI_Operation::onApplyAndClose();
+  if ( myDlg )
+    myDlg->reject();
+}