Salome HOME
introduction of penta18 in VTK viewer
[modules/gui.git] / src / LightApp / LightApp_Displayer.cxx
index c050811d1ebf4b85e96cf79d881bb30f6fe81f08..a490d9c88aea278dca564de494ef5eaa5e16e9b7 100644 (file)
@@ -1,27 +1,29 @@
-//  Copyright (C) 2007-2008  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
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
-//  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.
+// 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, 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
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-//  Lesser General Public License for more details.
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
 //
-//  You should have received a copy of the GNU Lesser General Public
-//  License along with this library; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 #include "LightApp_Displayer.h"
 #include "LightApp_Application.h"
 #include "LightApp_Module.h"
+#include "LightApp_Study.h"
 
 #include <CAM_Study.h>
 
@@ -31,6 +33,7 @@
 #include <SUIT_ViewModel.h>
 #include <SUIT_ViewWindow.h>
 
+#include <QStringList>
 #include <QString>
 #ifndef DISABLE_SALOMEOBJECT
   #include "SALOME_InteractiveObject.hxx"
@@ -56,22 +59,43 @@ LightApp_Displayer::~LightApp_Displayer()
   \param updateViewer - is it necessary to update viewer
   \param theViewFrame - view
 */
-void LightApp_Displayer::Display( const QString& entry, const bool updateViewer, SALOME_View* theViewFrame )
+void LightApp_Displayer::Display( const QString& entry, const bool updateViewer,
+                                  SALOME_View* theViewFrame )
+{
+  QStringList aList;
+  aList.append( entry );
+  Display( aList, updateViewer, theViewFrame );
+}
+
+/*!
+  Displays object in view
+  \param list - object entries
+  \param updateViewer - is it necessary to update viewer
+  \param theViewFrame - view
+*/
+void LightApp_Displayer::Display( const QStringList& list, const bool updateViewer,
+                                  SALOME_View* theViewFrame )
 {
-  SALOME_Prs* prs = buildPresentation( entry, theViewFrame );
-  if ( prs )
+  SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
+  QStringList::const_iterator it = list.constBegin();
+  for ( ; it != list.constEnd(); ++it)
   {
-    SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
-    if ( vf )
+    SALOME_Prs* prs = buildPresentation( *it, vf );
+    if ( prs )
     {
-      vf->BeforeDisplay( this );
-      vf->Display( prs );
-      vf->AfterDisplay( this );
 
-      if ( updateViewer )
-        vf->Repaint();
+      if ( vf )
+      {
+       myLastEntry = *it;
+        vf->BeforeDisplay( this, prs );
+        vf->Display( this, prs );
+        vf->AfterDisplay( this, prs );
 
+        if ( updateViewer )
+          vf->Repaint();
+      }
       delete prs;  // delete presentation because displayer is its owner
+      setVisibilityState(*it, Qtx::ShownState);
     }
   }
 }
@@ -98,13 +122,13 @@ void LightApp_Displayer::Redisplay( const QString& entry, const bool updateViewe
 
       SUIT_ViewModel* vmodel = vman->getViewModel();
       if( !vmodel )
-       continue;
-       
+        continue;
+        
       SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
       if( view && ( IsDisplayed( entry, view ) || view == GetActiveView() ) )
       {
-       Erase( entry, true, false, view );
-       Display( entry, updateViewer, view );
+        Erase( entry, true, false, view );
+        Display( entry, updateViewer, view );
       }
     }
   }
@@ -118,17 +142,43 @@ void LightApp_Displayer::Redisplay( const QString& entry, const bool updateViewe
   \param theViewFrame - view
 */
 void LightApp_Displayer::Erase( const QString& entry, const bool forced,
-                                const bool updateViewer, SALOME_View* theViewFrame )
+                                const bool updateViewer,
+                                SALOME_View* theViewFrame )
+{
+  QStringList aList;
+  aList.append( entry );
+  Erase( aList, forced, updateViewer, theViewFrame );
+}
+
+/*!
+  Erases object in view
+  \param list - object entries
+  \param forced - deletes object from viewer (otherwise it will be erased, but cached)
+  \param updateViewer - is it necessary to update viewer
+  \param theViewFrame - view
+*/
+void LightApp_Displayer::Erase( const QStringList& list, const bool forced,
+                                const bool updateViewer,
+                                SALOME_View* theViewFrame )
 {
   SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
 
-  if ( vf ) {
-    SALOME_Prs* prs = vf->CreatePrs( entry.toLatin1() );
+  if ( !vf )
+    return;
+
+  QStringList::const_iterator it = list.constBegin();
+  for ( ; it != list.constEnd(); ++it)
+  {
+    SALOME_Prs* prs = vf->CreatePrs( (*it).toLatin1().data() );
     if ( prs ) {
-      vf->Erase( prs, forced );
+      myLastEntry = *it;
+      vf->BeforeErase( this, prs );
+      vf->Erase( this, prs, forced );
+      vf->AfterErase( this, prs );
       if ( updateViewer )
-       vf->Repaint();
+        vf->Repaint();
       delete prs;  // delete presentation because displayer is its owner
+      setVisibilityState(*it,Qtx::HiddenState);
     }
   }
 }
@@ -139,15 +189,20 @@ void LightApp_Displayer::Erase( const QString& entry, const bool forced,
   \param updateViewer - is it necessary to update viewer
   \param theViewFrame - view
 */
-void LightApp_Displayer::EraseAll( const bool forced, const bool updateViewer, SALOME_View* theViewFrame ) const
+void LightApp_Displayer::EraseAll( const bool forced, const bool updateViewer, SALOME_View* theViewFrame )
 {
   SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
 
   if ( vf ) {
-    vf->EraseAll( forced );
+    vf->EraseAll( this, forced );
     if ( updateViewer )
       vf->Repaint();
   }
+
+  LightApp_Application* app = dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() );
+  LightApp_Study* study = app ? dynamic_cast<LightApp_Study*>( app->activeStudy() ) : 0;  
+  if(study)
+    study->setVisibilityStateForAll(Qtx::HiddenState);
 }
 
 /*!
@@ -207,8 +262,8 @@ SALOME_View* LightApp_Displayer::GetActiveView()
   if (  SUIT_Application* app = session->activeApplication() ) {
     if ( LightApp_Application* sApp = dynamic_cast<LightApp_Application*>( app ) ) {
       if( SUIT_ViewManager* vman = sApp->activeViewManager() ) {
-       if ( SUIT_ViewModel* vmod = vman->getViewModel() )
-         return dynamic_cast<SALOME_View*>( vmod );
+        if ( SUIT_ViewModel* vmod = vman->getViewModel() )
+          return dynamic_cast<SALOME_View*>( vmod );
       }
     }
   }
@@ -236,8 +291,8 @@ bool LightApp_Displayer::canBeDisplayed( const QString& entry ) const
   if(  SUIT_Application* app = session->activeApplication() )
     if( LightApp_Application* sApp = dynamic_cast<LightApp_Application*>( app ) )
       if( SUIT_ViewManager* vman = sApp->activeViewManager() )
-       if( SUIT_ViewModel* vmod = vman->getViewModel() )
-         viewerType = vmod->getType();
+        if( SUIT_ViewModel* vmod = vman->getViewModel() )
+          viewerType = vmod->getType();
   return canBeDisplayed( entry, viewerType );
 }
 
@@ -255,21 +310,34 @@ LightApp_Displayer* LightApp_Displayer::FindDisplayer( const QString& mod_name,
     return 0;
 
   LightApp_Module* m = dynamic_cast<LightApp_Module*>( app ? app->module( mod_name ) : 0 );
+  bool wasLoaded = false;
   if( !m && load )
   {
     m = dynamic_cast<LightApp_Module*>( app->loadModule( mod_name, false ) );
-    if( m )
+       if( m ) {
       app->addModule( m );
+         wasLoaded = true;
+       }
   }
 
   if( m )
   {
     m->connectToStudy( dynamic_cast<CAM_Study*>( app->activeStudy() ) );
-    if( m!=app->activeModule() && load )
-    {
-      m->setMenuShown( false );
-      m->setToolShown( false );
-    }
+       if( wasLoaded ) 
+               m->updateModuleVisibilityState();
   }
   return m ? m->displayer() : 0;
 }
+
+/*!
+  Find the active study and set the 'visibility state' property of the object
+  \param mod_name - name of module
+  \param load - is module has to be forced loaded
+*/
+void LightApp_Displayer::setVisibilityState( const QString& theEntry, Qtx::VisibilityState theState) const {
+  LightApp_Application* app = dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() );
+  LightApp_Study* study = app ? dynamic_cast<LightApp_Study*>( app->activeStudy() ) : 0;
+  
+  if(study)
+    study->setVisibilityState( theEntry, theState);
+}