Salome HOME
Copyright update 2022
[modules/gui.git] / src / LightApp / LightApp_Module.cxx
index 8bd88c4ea3f0a00d9836ec0a9ca3d85610d6ffd7..e5fef3efa9c1d5ac6bffc24d9b73433b0afa263a 100644 (file)
@@ -1,28 +1,29 @@
-//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2022  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
 //
+
 // File:      LightApp_Module.cxx
 // Created:   6/20/2005 16:30:56 AM
 // Author:    OCC team
-//
+
 #include "LightApp_Module.h"
 
 #include "CAM_Application.h"
 #include <SUIT_Operation.h>
 #include <SUIT_ViewManager.h>
 #include <SUIT_ResourceMgr.h>
+#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>
@@ -90,7 +96,9 @@
 #include <QVariant>
 #include <QString>
 #include <QStringList>
+#include <QAction>
 
+#include <iostream>
 
 /*!Constructor.*/
 LightApp_Module::LightApp_Module( const QString& name )
@@ -100,7 +108,8 @@ LightApp_Module::LightApp_Module( const QString& name )
   myDisplay( -1 ),
   myErase( -1 ),
   myDisplayOnly( -1 ),
-  myEraseAll( -1 )
+  myEraseAll( -1 ),
+  myIsFirstActivate( true )
 {
 }
 
@@ -136,29 +145,33 @@ void LightApp_Module::contextMenuPopup( const QString& client, QMenu* menu, QStr
 {
   LightApp_Selection* sel = createSelection();
   sel->init( client, getApp()->selectionMgr() );
+
   popupMgr()->setSelection( sel );
   popupMgr()->setMenu( menu );
   popupMgr()->updateMenu();
+  popupMgr()->setSelection( 0 );
 }
 
 /*!Update object browser.
  * For updating model or whole object browser use update() method can be used.
 */
 void LightApp_Module::updateObjBrowser( bool theIsUpdateDataModel, 
-                                       SUIT_DataObject* theDataObject )
+                                        SUIT_DataObject* theDataObject )
 {
+  if (!getApp()->objectBrowser())
+    return;
   bool upd = getApp()->objectBrowser()->autoUpdate();
   getApp()->objectBrowser()->setAutoUpdate( false );
 
   if( theIsUpdateDataModel ){
     if( CAM_DataModel* aDataModel = dataModel() ){
       if ( LightApp_DataModel* aModel = dynamic_cast<LightApp_DataModel*>( aDataModel ) ) {
-       SUIT_DataObject* aParent = NULL;
-       if(theDataObject && theDataObject != aDataModel->root())
-         aParent = theDataObject->parent();
+        //SUIT_DataObject* aParent = NULL;
+        //if(theDataObject && theDataObject != aDataModel->root())
+        //  aParent = theDataObject->parent();
 
-       LightApp_DataObject* anObject = dynamic_cast<LightApp_DataObject*>(theDataObject);
-       LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>(getApp()->activeStudy());
+        LightApp_DataObject* anObject = dynamic_cast<LightApp_DataObject*>(theDataObject);
+        LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>(getApp()->activeStudy());
         aModel->update( anObject, aStudy );
       }
     }
@@ -192,7 +205,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 );
     }
   }
@@ -219,6 +232,17 @@ bool LightApp_Module::activateModule( SUIT_Study* study )
   if ( mySwitchOp == 0 )
     mySwitchOp = new LightApp_SwitchOp( this );
 
+  // Enable Display and Erase actions
+  if ( action(myDisplay) )
+    action(myDisplay)->setEnabled(true);
+  if ( action(myErase) )
+    action(myErase)->setEnabled(true);
+
+  application()->shortcutMgr()->setSectionEnabled( moduleName() );
+
+  /*  BUG 0020498 : The Entry column is always shown at module activation
+      The registration of column is moved into LightApp_Application
+
   QString EntryCol = QObject::tr( "ENTRY_COLUMN" );
   LightApp_DataModel* m = dynamic_cast<LightApp_DataModel*>( dataModel() );
   if( m )
@@ -226,7 +250,8 @@ bool LightApp_Module::activateModule( SUIT_Study* study )
     SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( getApp()->objectBrowser()->model() );
     m->registerColumn( getApp()->objectBrowser(), EntryCol, LightApp_DataObject::EntryId );
     treeModel->setAppropriate( EntryCol, Qtx::Toggled );
-  }
+  }*/
+
   return res;
 }
 
@@ -237,9 +262,9 @@ bool LightApp_Module::deactivateModule( SUIT_Study* study )
   mySwitchOp = 0;
 
   disconnect( application(), SIGNAL( viewManagerAdded( SUIT_ViewManager* ) ),
-             this, SLOT( onViewManagerAdded( SUIT_ViewManager* ) ) );
+              this, SLOT( onViewManagerAdded( SUIT_ViewManager* ) ) );
   disconnect( application(), SIGNAL( viewManagerRemoved( SUIT_ViewManager* ) ),
-             this, SLOT( onViewManagerRemoved( SUIT_ViewManager* ) ) );
+              this, SLOT( onViewManagerRemoved( SUIT_ViewManager* ) ) );
 
   // abort all operations
   MapOfOperation::const_iterator anIt;
@@ -247,6 +272,15 @@ bool LightApp_Module::deactivateModule( SUIT_Study* study )
     anIt.value()->abort();
   }
 
+  // Disable Display and Erase action
+  if ( action(myDisplay) )
+    action(myDisplay)->setEnabled(false);
+  if ( action(myErase) )
+    action(myErase)->setEnabled(false);
+
+  application()->shortcutMgr()->setSectionEnabled( moduleName(), false );
+  
+  /*  BUG 0020498 : The Entry column is always shown at module activation
   QString EntryCol = QObject::tr( "ENTRY_COLUMN" );
   LightApp_DataModel* m = dynamic_cast<LightApp_DataModel*>( dataModel() );
   if( m )
@@ -256,14 +290,36 @@ bool LightApp_Module::deactivateModule( SUIT_Study* study )
     treeModel->setAppropriate( EntryCol, Qtx::Shown );
     m->unregisterColumn( getApp()->objectBrowser(), EntryCol );
   }
+  */
   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()
 {
 }
 
+/*!NOT IMPLEMENTED*/
+void LightApp_Module::updateInfoPanel()
+{
+}
+
 /*!NOT IMPLEMENTED*/
 void LightApp_Module::createPreferences()
 {
@@ -274,6 +330,11 @@ void LightApp_Module::preferencesChanged( const QString&, const QString& )
 {
 }
 
+/*!NOT IMPLEMENTED*/
+void LightApp_Module::message( const QString& )
+{
+}
+
 /*!Gets application.*/
 LightApp_Application* LightApp_Module::getApp() const
 {
@@ -327,6 +388,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
       }
   }
@@ -380,13 +445,13 @@ QtxPopupMgr* LightApp_Module::popupMgr()
     
     QAction 
       *disp = createAction( -1, tr( "TOP_SHOW" ), p, tr( "MEN_SHOW" ), tr( "STB_SHOW" ),
-                           0, d, false, this, SLOT( onShowHide() ) ),
+                            0, d, false, this, SLOT( onShowHide() ), QString("General:Show object(s)") ),
       *erase = createAction( -1, tr( "TOP_HIDE" ), p, tr( "MEN_HIDE" ), tr( "STB_HIDE" ),
-                            0, d, false, this, SLOT( onShowHide() ) ),
+                             0, d, false, this, SLOT( onShowHide() ) , QString("General:Hide object(s)") ),
       *dispOnly = createAction( -1, tr( "TOP_DISPLAY_ONLY" ), p, tr( "MEN_DISPLAY_ONLY" ), tr( "STB_DISPLAY_ONLY" ),
-                               0, d, false, this, SLOT( onShowHide() ) ),
+                                0, d, false, this, SLOT( onShowHide() ) ),
       *eraseAll = createAction( -1, tr( "TOP_ERASE_ALL" ), p, tr( "MEN_ERASE_ALL" ), tr( "STB_ERASE_ALL" ),
-                               0, d, false, this, SLOT( onShowHide() ) );
+                                0, d, false, this, SLOT( onShowHide() ) );
     myDisplay     = actionId( disp );
     myErase       = actionId( erase );
     myDisplayOnly = actionId( dispOnly );
@@ -398,9 +463,9 @@ QtxPopupMgr* LightApp_Module::popupMgr()
     myPopupMgr->insert( eraseAll, -1, 0 );
     myPopupMgr->insert( separator(), -1, 0 );
 
-    QString oneAndNotActive = "( count( $component ) = 1 ) and ( not( activeModule in $component ) )";
+    QString oneAndNotActive = "( count( $component ) = 1 ) and ( not( activeModule in $component ) ) and ( not($displayer={'%3'}) )";
     QString uniform = "true in $canBeDisplayed and %1 and ( activeModule = '%2' )";
-    uniform = uniform.arg( oneAndNotActive ).arg( name() );
+    uniform = uniform.arg( oneAndNotActive ).arg( name() ).arg( LightApp_Application::moduleDisplayer( name() ) );
     myPopupMgr->setRule( disp, /*QString( "( not isVisible ) and " ) + */ uniform, QtxPopupMgr::VisibleRule );
     myPopupMgr->setRule( erase, /*QString( "( isVisible ) and " ) + */ uniform, QtxPopupMgr::VisibleRule );
     myPopupMgr->setRule( dispOnly, uniform, QtxPopupMgr::VisibleRule );
@@ -505,7 +570,7 @@ void LightApp_Module::setPreferenceProperty( const int id, const QString& prop,
 void LightApp_Module::startOperation( const int id )
 {
   LightApp_Operation* op = 0;
-  if( myOperations.contains( id ) )
+  if( myOperations.contains( id ) && reusableOperation( id ) )
     op = myOperations[ id ];
   else
   {
@@ -636,3 +701,163 @@ LightApp_Operation* LightApp_Module::operation( const int id ) const
 {
   return myOperations.contains( id ) ? myOperations[id] : 0;
 }
+
+/*!
+  virtual method called to manage the same operations
+*/
+bool LightApp_Module::reusableOperation( const int /*id*/ )
+{
+ return true;
+} 
+
+/*!
+  virtual method
+  \return true if module can copy the current selection
+*/
+bool LightApp_Module::canCopy() const
+{
+  return false;
+}
+
+/*!
+  virtual method
+  \return true if module can paste previously copied data
+*/
+bool LightApp_Module::canPaste() const
+{
+  return false;
+}
+
+/*!
+  virtual method
+  \brief Copies the current selection into clipboard
+*/
+void LightApp_Module::copy()
+{
+}
+
+/*!
+  virtual method
+  \brief Pastes the current data in the clipboard
+*/
+void LightApp_Module::paste()
+{
+}
+
+/*!
+  virtual method
+  \return true if module allows dragging the given object
+*/
+bool LightApp_Module::isDraggable( const SUIT_DataObject* /*what*/ ) const
+{
+  return false;
+}
+
+/*!
+  virtual method
+  \return true if module allows dropping one or more objects (currently selected) on the object \c where
+*/
+bool LightApp_Module::isDropAccepted( const SUIT_DataObject* /*where*/ ) const
+{
+  return false;
+}
+
+/*!
+  virtual method
+  Complete drag-n-drop operation by processing objects \a what being dragged, dropped to the line \a row
+  within the object \a where. The drop action being performed is specified by \a action.
+*/
+void LightApp_Module::dropObjects( const DataObjectList& /*what*/, SUIT_DataObject* /*where*/,
+                                   const int /*row*/, Qt::DropAction /*action*/ )
+{
+}
+
+/*!
+  \brief Return \c true if object can be renamed
+*/
+bool LightApp_Module::renameAllowed( const QString& /*entry*/ ) const
+{
+  return false;
+}
+
+/*!
+  Rename object by entry.
+  \param entry entry of the object
+  \param name new name of the object
+  \brief Return \c true if rename operation finished successfully, \c false otherwise.
+*/
+bool LightApp_Module::renameObject( const QString& /*entry*/, const QString& /*name*/ )
+{
+  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;
+}