Salome HOME
Modify creation of curves: 1) using QDockWidget instead of QDialog; 2) selection...
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Module.cxx
index 6ce7fa531a283235f384068c464a8ef5f0a16bc3..509fc2e357c31af76299d8ea46cf3b6f89fe1794 100644 (file)
@@ -47,6 +47,7 @@
 #include <ImageComposer_FuseOperator.h>
 
 #include <LightApp_Application.h>
+#include <LightApp_DataOwner.h>
 #include <LightApp_GVSelector.h>
 #include <LightApp_SelectionMgr.h>
 #include <LightApp_UpdateFlags.h>
@@ -193,6 +194,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
   bool anIsMustBeUpdatedImage = false;
   bool anIsPolyline = false;
   bool anIsCalculation = false;
+  bool anIsZone = false;
   bool anIsVisualState = false;
 
   // check the selected data model objects
@@ -236,6 +238,8 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
         anIsPolyline = true;
       else if( anObject->GetKind() == KIND_CALCULATION )
         anIsCalculation = true;
+      else if( anObject->GetKind() == KIND_ZONE )
+        anIsZone = true;
       else if( anObject->GetKind() == KIND_VISUAL_STATE )
         anIsVisualState = true;
     }
@@ -264,6 +268,9 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
         case KIND_CALCULATION:
           theMenu->addAction( action( CreateCalculationId ) );
           break;
+        case KIND_ZONE:
+          theMenu->addAction( action( CreateZoneId ) );
+          break;
       }
       theMenu->addSeparator();
     }
@@ -310,6 +317,11 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
       theMenu->addAction( action( EditCalculationId ) );
       theMenu->addSeparator();
     }
+    else if( anIsZone )
+    {
+      theMenu->addAction( action( EditZoneId ) );
+      theMenu->addSeparator();
+    }
     else if( anIsVisualState && anIsObjectBrowser )
     {
       theMenu->addAction( action( SaveVisualStateId ) );
@@ -324,7 +336,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
     theMenu->addSeparator();
   }
 
-  if( anIsSelectedDataObjects && ( anIsImage || anIsPolyline ) )
+  if( anIsSelectedDataObjects && ( anIsImage || anIsPolyline || anIsZone ) )
   {
     if( anIsHiddenInSelection )
       theMenu->addAction( action( ShowId ) );
@@ -353,6 +365,9 @@ void HYDROGUI_Module::update( const int flags )
   // from one of the methods called below
   setUpdateEnabled( false );
 
+  // store selected objects
+  QStringList aSelectedEntries = storeSelection();
+
   if( ( flags & UF_Viewer ) )
     updateGV( flags & UF_GV_Init,
               flags & UF_GV_Forced );
@@ -376,6 +391,9 @@ void HYDROGUI_Module::update( const int flags )
   if( ( flags & UF_Controls ) && getApp() )
     getApp()->updateActions();
 
+  // restore selected objects
+  restoreSelection( aSelectedEntries );
+
   setUpdateEnabled( true );
 
   QApplication::restoreOverrideCursor();
@@ -693,3 +711,34 @@ bool HYDROGUI_Module::isUpdateEnabled() const
 {
   return myIsUpdateEnabled;
 }
+
+QStringList HYDROGUI_Module::storeSelection() const
+{
+  QStringList anEntryList;
+  if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
+  {
+    SUIT_DataOwnerPtrList aList( true );
+    aSelectionMgr->selected( aList );
+
+    SUIT_DataOwnerPtrList::iterator anIter;
+    for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
+    {
+      const LightApp_DataOwner* anOwner = 
+        dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
+      if( anOwner )
+        anEntryList.append( anOwner->entry() );
+    }
+  }
+  return anEntryList;
+}
+
+void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
+{
+  if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
+  {
+    SUIT_DataOwnerPtrList aList( true );
+    for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
+      aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
+    aSelectionMgr->setSelected( aList );
+  }
+}