Salome HOME
Improvement: now in rules you can use "canBeDisplayed" parameter. It is true, if...
authorasl <asl@opencascade.com>
Thu, 1 Dec 2005 10:04:49 +0000 (10:04 +0000)
committerasl <asl@opencascade.com>
Thu, 1 Dec 2005 10:04:49 +0000 (10:04 +0000)
src/LightApp/LightApp_Displayer.cxx
src/LightApp/LightApp_Displayer.h
src/LightApp/LightApp_Module.cxx
src/LightApp/LightApp_Selection.cxx
src/LightApp/LightApp_ShowHideOp.cxx
src/LightApp/LightApp_ShowHideOp.h

index f2952de04d4d2a2f842eb4ad94aad61c37f9599e..17475e574e830a7cba7375fb8f8105f7ec3a67c9 100644 (file)
@@ -1,6 +1,9 @@
 
 #include "LightApp_Displayer.h"
 #include "LightApp_Application.h"
+#include "LightApp_Module.h"
+
+#include <CAM_Study.h>
 
 #include <SALOME_InteractiveObject.hxx>
 
@@ -143,3 +146,48 @@ SALOME_View* LightApp_Displayer::GetActiveView()
   }
   return 0;
 }
+
+bool LightApp_Displayer::canBeDisplayed( const QString&, const QString& ) const
+{
+  return true;
+}
+
+bool LightApp_Displayer::canBeDisplayed( const QString& entry ) const
+{
+  QString viewerType;
+  SUIT_Session* session = SUIT_Session::session();
+  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();
+  return !viewerType.isNull() && canBeDisplayed( entry, viewerType );
+}
+
+LightApp_Displayer* LightApp_Displayer::FindDisplayer( const QString& mod_name, const bool load )
+{
+  SUIT_Session* session = SUIT_Session::session();
+  SUIT_Application* sapp = session ? session->activeApplication() : 0;
+  LightApp_Application* app = dynamic_cast<LightApp_Application*>( sapp );
+  if( !app )
+    return 0;
+
+  LightApp_Module* m = dynamic_cast<LightApp_Module*>( app ? app->module( mod_name ) : 0 );
+  if( !m && load )
+  {
+    m = dynamic_cast<LightApp_Module*>( app->loadModule( mod_name ) );
+    if( m )
+      app->addModule( m );
+  }
+
+  if( m )
+  {
+    m->connectToStudy( dynamic_cast<CAM_Study*>( app->activeStudy() ) );
+    if( m!=app->activeModule() && load )
+    {
+      m->setMenuShown( false );
+      m->setToolShown( false );
+    }
+  }
+  return m ? m->displayer() : 0;
+}
index 94ccd4f90d173f0e17d0837e25a99163d7fce834..cafb3cd7facb436db53dac0e10b1498e95d15b83 100644 (file)
@@ -19,7 +19,11 @@ public:
   bool IsDisplayed( const QString&, SALOME_View* = 0 ) const;
   void UpdateViewer() const;
 
-  static SALOME_View*  GetActiveView();
+  static SALOME_View*        GetActiveView();
+  static LightApp_Displayer* FindDisplayer( const QString&, const bool );
+
+  virtual bool canBeDisplayed( const QString& /*entry*/, const QString& /*viewer_type*/ ) const;
+          bool canBeDisplayed( const QString& /*entry*/ ) const;
 
 protected:
   virtual SALOME_Prs* buildPresentation( const QString&, SALOME_View* = 0 );
index b3f1428cba03eac23f44f624b71e732dec3f617b..46d3f82afbba36a87b47afa7317d9a1e08445b21 100644 (file)
@@ -253,8 +253,9 @@ QtxPopupMgr* LightApp_Module::popupMgr()
     myPopupMgr->insert( eraseAll, -1, 0 );
     myPopupMgr->insert( separator(), -1, 0 );
 
-    QString uniform = "( count( $component ) = 1 ) and ( component != activeModule ) and ( activeModule = '%1' )";
-    uniform = uniform.arg( name() );
+    QString oneAndNotActive = "( count( $component ) = 1 ) and ( component != activeModule )";
+    QString uniform = "true in $canBeDisplayed and %1 and ( activeModule = '%2' )";
+    uniform = uniform.arg( oneAndNotActive ).arg( name() );
     myPopupMgr->setRule( disp, /*QString( "( not isVisible ) and " ) + */ uniform, true );
     myPopupMgr->setRule( erase, /*QString( "( isVisible ) and " ) + */ uniform, true );
     myPopupMgr->setRule( dispOnly, uniform, true );
index 4c43e644d2f6ae2fdc1534488e15e3e45d81069c..0e3458f8fb7fc8093e85510c45739f97ca1a5ccd 100644 (file)
@@ -85,21 +85,46 @@ int LightApp_Selection::count() const
 */
 QtxValue LightApp_Selection::param( const int ind, const QString& p ) const
 {
-  if( !( ind>=0 && ind<count() ) )
+  LightApp_Application* app = dynamic_cast<LightApp_Application*>( myStudy ? myStudy->application() : 0 );
+  if( !( ind>=0 && ind<count() ) || !app )
     return QtxValue();
 
   if( p=="isVisible" )
   {
-    LightApp_Displayer d;
-    bool vis = d.IsDisplayed( myEntries[ ind ] );
+    QString mod_name = app->moduleTitle( param( ind, "component" ).toString() );
+    LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mod_name, false );
+    // false in last parameter means that now we doesn't load module, if it isn't loaded
+
+    bool vis = false;
+    if( d )
+      vis = d->IsDisplayed( myEntries[ ind ] );
+    else
+    {
+      LightApp_Displayer local_d;
+      vis = local_d.IsDisplayed( myEntries[ ind ] );
+    }
     return QtxValue( vis, 0 );
   }
-  else if( p=="component" ) {
+
+  else if( p=="component" )
+  {
     return myStudy->componentDataType( myEntries[ ind ] );
   }
+
   else if( p=="isReference" )
     return QtxValue( isReference( ind ), false );
 
+  else if( p=="canBeDisplayed" )
+  {
+    QString mod_name = app->moduleTitle( param( ind, "component" ).toString() );
+    LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mod_name, false );
+    // false in last parameter means that now we doesn't load module, if it isn't loaded
+
+    return QtxValue( d ? d->canBeDisplayed( myEntries[ ind ] ) : true, 0 );
+    //now if displayer is null, it means, that according module isn't loaded, so that we allow to all display/erase
+    //operations under object
+  }
+
   return QtxValue();
 }
 
index c1a365b8e8439de6511471c579f11ea180a2a245..525d9f8428845feff9be0447264b704071a6170b 100644 (file)
@@ -23,29 +23,6 @@ LightApp_ShowHideOp::~LightApp_ShowHideOp()
 {
 }
 
-LightApp_Displayer* LightApp_ShowHideOp::displayer( const QString& mod_name ) const
-{
-  LightApp_Application* app = dynamic_cast<LightApp_Application*>( application() );
-  LightApp_Module* m = dynamic_cast<LightApp_Module*>( app ? app->module( mod_name ) : 0 );
-  if( !m )
-  {
-    m = dynamic_cast<LightApp_Module*>( app->loadModule( mod_name ) );
-    if( m )
-      app->addModule( m );
-  }
-
-  if( m )
-  {
-    m->connectToStudy( dynamic_cast<CAM_Study*>( app->activeStudy() ) );
-    if( m!=app->activeModule() )
-    {
-      m->setMenuShown( false );
-      m->setToolShown( false );
-    }
-  }
-  return m ? m->displayer() : 0;
-}
-
 void LightApp_ShowHideOp::startOperation()
 {
   LightApp_Application* app = dynamic_cast<LightApp_Application*>( application() );
@@ -65,7 +42,7 @@ void LightApp_ShowHideOp::startOperation()
   }
   QString aStr =  sel.param( 0, "component" ).toString();
   QString mod_name = app->moduleTitle( aStr );//sel.param( 0, "component" ).toString() );
-  LightApp_Displayer* d = displayer( mod_name );
+  LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mod_name, true );
   if( !d )
   {
     abort();
@@ -80,7 +57,7 @@ void LightApp_ShowHideOp::startOperation()
     QStringList::const_iterator anIt = comps.begin(), aLast = comps.end();
     for( ; anIt!=aLast; anIt++ )
     {
-      LightApp_Displayer* disp = displayer( app->moduleTitle( *anIt ) );
+      LightApp_Displayer* disp = LightApp_Displayer::FindDisplayer( app->moduleTitle( *anIt ), true );
       if( disp )
        disp->EraseAll( false, false, 0 );
     }
index 7c322240ca99376e585f1ea87dd9e6aa78e98237..fd234b58a5fa48c4eb4d286151f624bc3066a315 100644 (file)
@@ -18,7 +18,6 @@ public:
   
 protected:
   virtual void startOperation();
-  virtual LightApp_Displayer* displayer( const QString& ) const;
 
 private:
   ActionType   myActionType;