Salome HOME
Copyright update: 2016
[modules/gui.git] / src / LightApp / LightApp_Module.cxx
index 41e803fabbc0aa2c230f761f19268a20ceb12ff6..8bf8e287f53d6f7e52619eae9e5e5cf8eda714f4 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016  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
 #include <SUIT_ShortcutMgr.h>
 #include <SUIT_Desktop.h>
 #include <SUIT_TreeModel.h>
+#include <SUIT_Session.h>
 
 #ifndef DISABLE_SALOMEOBJECT
 #include <SALOME_ListIO.hxx>
-#include <SALOME_ListIteratorOfListIO.hxx>
 #endif
 
 #ifndef DISABLE_VTKVIEWER
   #include <GLViewer_ViewFrame.h>
   #include <GLViewer_ViewPort.h>
 #endif
+#ifndef DISABLE_PVVIEWER
+  #include <PVViewer_ViewManager.h>
+  #include <PVViewer_ViewWindow.h>
+#endif
 #ifndef DISABLE_PLOT2DVIEWER
   #include <Plot2d_ViewWindow.h>
   #include <Plot2d_ViewFrame.h>
@@ -104,7 +108,8 @@ LightApp_Module::LightApp_Module( const QString& name )
   myDisplay( -1 ),
   myErase( -1 ),
   myDisplayOnly( -1 ),
-  myEraseAll( -1 )
+  myEraseAll( -1 ),
+  myIsFirstActivate( true )
 {
 }
 
@@ -197,7 +202,7 @@ bool LightApp_Module::isSelectionCompatible()
     // check data type of selection
     SALOME_ListIteratorOfListIO It( selected );
     for ( ; isCompatible && It.More(); It.Next()) {
-      Handle(SALOME_InteractiveObject)& io = It.Value();
+      Handle(SALOME_InteractiveObject) io = It.Value();
       isCompatible = ( aStudy->componentDataType( io->getEntry() ) == moduleDataType );
     }
   }
@@ -243,6 +248,7 @@ bool LightApp_Module::activateModule( SUIT_Study* study )
     m->registerColumn( getApp()->objectBrowser(), EntryCol, LightApp_DataObject::EntryId );
     treeModel->setAppropriate( EntryCol, Qtx::Toggled );
   }*/
+
   return res;
 }
 
@@ -285,6 +291,22 @@ bool LightApp_Module::deactivateModule( SUIT_Study* study )
   return CAM_Module::deactivateModule( study );
 }
 
+/*! Redefined to reset internal flags valid for study instance */
+void LightApp_Module::studyClosed( SUIT_Study* theStudy )
+{
+  CAM_Module::studyClosed( theStudy );
+  
+  myIsFirstActivate = true;
+  
+  LightApp_Application* app = dynamic_cast<LightApp_Application*>(application());
+  if ( app ) {
+    SUIT_DataBrowser* ob = app->objectBrowser();
+    if ( ob && ob->model() )
+      disconnect( ob->model(), SIGNAL( clicked( SUIT_DataObject*, int ) ),
+                 this, SLOT( onObjectClicked( SUIT_DataObject*, int ) ) );
+  }
+}
+
 /*!NOT IMPLEMENTED*/
 void LightApp_Module::MenuItem()
 {
@@ -358,6 +380,10 @@ void LightApp_Module::update( const int theFlags )
 #ifndef DISABLE_GLVIEWER
         if ( viewWnd->inherits( "GLViewer_ViewFrame" ) )
           ( (GLViewer_ViewFrame*)viewWnd )->getViewPort()->onUpdate();
+#endif
+#ifndef DISABLE_PVVIEWER
+//        if ( viewWnd->inherits( "PVViewer_ViewWindow" ) )
+//          ( (PVViewer_ViewWindow*)viewWnd )->getViewPort()->onUpdate();
 #endif
       }
   }
@@ -756,3 +782,74 @@ bool LightApp_Module::renameObject( const QString& /*entry*/, const QString& /*n
 {
   return false;
 }
+
+/*!
+  Update visibility state for data objects
+*/
+void LightApp_Module::updateModuleVisibilityState()
+{
+  // update visibility state of objects
+  LightApp_Application* app = dynamic_cast<LightApp_Application*>(SUIT_Session::session()->activeApplication());
+  if ( !app ) return;
+  
+  SUIT_DataBrowser* ob = app->objectBrowser();
+  if ( !ob || !ob->model() ) return;
+
+  if ( !myIsFirstActivate )
+    return;
+
+  myIsFirstActivate = false;
+
+  // connect to click on item
+  connect( ob->model(), SIGNAL( clicked( SUIT_DataObject*, int ) ),
+           this, SLOT( onObjectClicked( SUIT_DataObject*, int ) ), Qt::UniqueConnection );
+  // connect to click on item
+  connect( ob, SIGNAL( destroyed( QObject* ) ),
+           this, SLOT( onOBDestroyed() ), Qt::UniqueConnection );
+
+  SUIT_DataObject* rootObj = ob->root();
+  if ( !rootObj ) return;
+  
+  DataObjectList listObj = rootObj->children( true );
+  
+  SUIT_ViewModel* vmod = 0;
+  if ( SUIT_ViewManager* vman = app->activeViewManager() )
+    vmod = vman->getViewModel();
+  app->updateVisibilityState( listObj, vmod );
+}
+
+/*!
+ * \brief Virtual public slot
+ *
+ * This method is called after the object inserted into data view to update their visibility state
+ * This is default implementation
+ */
+void LightApp_Module::onObjectClicked( SUIT_DataObject* theObject, int theColumn )
+{
+  if ( !isActiveModule() ) return;
+
+  // change visibility of object
+  if ( !theObject || theColumn != SUIT_DataObject::VisibilityId ) return;
+
+  LightApp_Study* study = dynamic_cast<LightApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
+  if ( !study ) return;
+
+  LightApp_DataObject* lo = dynamic_cast<LightApp_DataObject*>( theObject );
+  if ( !lo ) return;
+  
+  // detect action index (from LightApp level)
+  int id = -1;
+  
+  if ( study->visibilityState( lo->entry() ) == Qtx::ShownState )
+    id = myErase;
+  else if ( study->visibilityState( lo->entry() ) == Qtx::HiddenState )
+    id = myDisplay;
+  
+  if ( id != -1 )
+    startOperation( id );
+}
+
+void LightApp_Module::onOBDestroyed()
+{
+  myIsFirstActivate = true;
+}