Salome HOME
Fix for Bug IPAL8945
[modules/visu.git] / src / VISUGUI / VisuGUI_PopupTools.cxx
index 73826c9682b25aa172326d9f8add8c8d906190b9..b4ca7c2079eda64b23b1b2c1fd0852084e1bacec 100644 (file)
 //  Module : VISU
 
 #include "VisuGUI_PopupTools.h"
+#include "VisuGUI_ViewTools.h"
 #include "VisuGUI_Tools.h"
+#include "SalomeApp_Study.h"
+#include "LightApp_Study.h"
 
 #include "VISU_Actor.h"
 #include "VISU_ScalarMapAct.h"
+#include "VISU_Result_i.hh"
+#include "SalomeApp_Study.h"
 
 using namespace VISU;
 
@@ -39,15 +44,17 @@ using namespace VISU;
 
 QtxValue VisuGUI_Selection::param( const int ind, const QString& p ) const
 {
-  QtxValue val( SalomeApp_Selection::param( ind, p ) );
+  QtxValue val( LightApp_Selection::param( ind, p ) );
   if ( !val.isValid() ) {
     if      ( p == "type"           ) val = QtxValue( type( ind ) );
     else if ( p == "nbComponents"   ) val = QtxValue( nbComponents( ind ) );
+    else if ( p == "medEntity"   ) val = QtxValue( medEntity( ind ) );
+    else if ( p == "medSource"   ) val = QtxValue( medSource( ind ) );
     else if ( p == "representation" ) val = QtxValue( representation( ind ) );
     else if ( p == "nbTimeStamps"   ) val = QtxValue( nbTimeStamps( ind ) );
     else if ( p == "nbChildren"     ) val = QtxValue( nbChildren( ind ) );
     else if ( p == "nbNamedChildren") val = QtxValue( nbNamedChildren( ind ) );
-//    else if ( p == "isVisible"      ) val = QtxValue( isVisible( ind ) );
+    else if ( p == "isVisible"      ) val = QtxValue( isVisible( ind ) );
     else if ( p == "isShrunk"       ) val = QtxValue( isShrunk( ind ) );
     else if ( p == "hasActor"       ) val = QtxValue( hasActor( ind ) );
     else if ( p == "isShading"      ) val = QtxValue( isShading( ind ) );
@@ -67,7 +74,10 @@ QString VisuGUI_Selection::type( const int ind ) const
 {
   QString aResStr;
   VISU::Storable::TRestoringMap aMap;
-  CORBA::Object_var anObject = GetSelectedObj( study(), entry( ind ), &aMap );  
+  SalomeApp_Study* aStudy = GetStudy();
+  if ( !aStudy )
+    return aResStr;
+  CORBA::Object_var anObject = GetSelectedObj( aStudy, entry( ind ), &aMap );  
 
   VISU::Base_var aVisuObj = VISU::Base::_narrow( anObject );
   if ( !CORBA::is_nil( aVisuObj ) ){
@@ -82,6 +92,7 @@ QString VisuGUI_Selection::type( const int ind ) const
       ENUM2STRING( aResStr, VISU::TSCALARMAP );
       ENUM2STRING( aResStr, VISU::TISOSURFACE );
       ENUM2STRING( aResStr, VISU::TDEFORMEDSHAPE );
+      ENUM2STRING( aResStr, VISU::TSCALARMAPONDEFORMEDSHAPE );
       ENUM2STRING( aResStr, VISU::TCUTPLANES );
       ENUM2STRING( aResStr, VISU::TCUTLINES );
       ENUM2STRING( aResStr, VISU::TVECTORS );
@@ -120,7 +131,10 @@ QString VisuGUI_Selection::nbComponents( const int ind ) const
 {
   QString aResStr;
   VISU::Storable::TRestoringMap aMap;
-  GetSelectedObj( study(), entry( ind ), &aMap );  
+  SalomeApp_Study* aStudy = GetStudy();
+  if ( !aStudy )
+    return aResStr;
+  GetSelectedObj( aStudy, entry( ind ), &aMap );  
   bool isExist;
   const QString& aVal = VISU::Storable::FindValue(aMap,"myNumComponent",&isExist);
   if ( isExist )
@@ -128,11 +142,64 @@ QString VisuGUI_Selection::nbComponents( const int ind ) const
   return aResStr;
 }
 
+QString VisuGUI_Selection::medEntity( const int ind ) const
+{
+  bool isExist;
+  VISU::Storable::TRestoringMap aMap;
+  GetSelectedObj( GetStudy(), entry( ind ), &aMap );  
+  const QString& aVal = VISU::Storable::FindValue(aMap,"myEntityId",&isExist);
+  if ( isExist ) {
+    using namespace VISU;
+    TEntity anEntityId = TEntity(aVal.toInt());
+    switch(anEntityId){
+    case NODE_ENTITY :
+      return "NODE_ENTITY";
+    case EDGE_ENTITY :
+      return "EDGE_ENTITY";
+    case FACE_ENTITY :
+      return "FACE_ENTITY";
+    case CELL_ENTITY :
+      return "CELL_ENTITY";
+    default:
+      return QString();
+    }
+  }
+  return QString();
+}
+
+QString VisuGUI_Selection::medSource( const int ind ) const
+{
+  _PTR(Study) aStudyDS = GetStudy()->studyDS();
+  if(_PTR(SObject) aSObject = aStudyDS->FindObjectID(entry(ind))){
+    VISU::Result_var aRes;
+    if(VISU::Result_i* aResult = CheckResult(myModule,aSObject,aRes)){
+      using namespace VISU;
+      Result_i::ECreationId aCreationId = aResult->GetCreationId();
+      switch(aCreationId){
+      case Result_i::eImportFile :
+       return "eImportFile";
+      case Result_i::eCopyAndImportFile :
+       return "eCopyAndImportFile";
+      case Result_i::eImportMed :
+       return "eImportMed";
+      case Result_i::eImportMedField :
+       return "eImportMedField";
+      default:
+       return QString();
+      }      
+    }
+  }
+  return QString();
+}
+
 QString VisuGUI_Selection::nbTimeStamps( const int ind ) const
 {
   QString aResStr;
   VISU::Storable::TRestoringMap aMap;
-  GetSelectedObj( study(), entry( ind ), &aMap );  
+  SalomeApp_Study* aStudy = GetStudy();
+  if ( !aStudy )
+    return aResStr;
+  GetSelectedObj( aStudy, entry( ind ), &aMap );  
   bool isExist;
   const QString& aVal = VISU::Storable::FindValue(aMap,"myNbTimeStamps",&isExist);
   if ( isExist )
@@ -160,10 +227,20 @@ QString VisuGUI_Selection::representation( const int ind ) const
   return aResStr;
 }
 
+SalomeApp_Study* VisuGUI_Selection::GetStudy() const
+  
+{
+  LightApp_Study* aLightStudy = const_cast<LightApp_Study*>( study() );
+  return dynamic_cast<SalomeApp_Study*>( aLightStudy );
+}
+
 int VisuGUI_Selection::nbChild( const int ind, const bool named ) const
 {
   int cnt = 0;
-  _PTR(Study) aStudy =  GetCStudy( study() );
+  SalomeApp_Study* aSStudy = GetStudy();
+  if ( !aSStudy )
+    return cnt;
+  _PTR(Study) aStudy =  GetCStudy( aSStudy );
   if ( aStudy ){
     _PTR(SObject) SO = aStudy->FindObjectID( entry( ind ).latin1() );
     if ( SO ){
@@ -191,15 +268,47 @@ QString VisuGUI_Selection::nbNamedChildren( const int ind ) const
   return aResStr;
 }
 
-QString VisuGUI_Selection::isVisible( const int ind ) const
+namespace
 {
-  QString aResStr;
+  struct TIsVisibleFunctor
+  {
+    template<class TViewer>
+    QString
+    Get(VisuGUI* theModule, 
+       const QString& theEntry)
+    {
+      typedef typename TViewer::TViewWindow TViewWindow;
+      if(TViewWindow* aViewWindow = GetViewWindow<TViewer>(theModule))
+       if(VISU_Actor* anActor = FindActor(aViewWindow,theEntry.latin1()))
+         return anActor->GetVisibility() ? "true" : "false";
 
-  if ( SVTK_ViewWindow* aView = GetViewWindow( myModule ) )
-    if ( VISU_Actor* anVISUActor = FindActor( aView, entry( ind ).latin1() ) )
-      aResStr = anVISUActor->GetVisibility() ? "1" : "0";
+      return QString();
+    }
+  };
 
-  return aResStr;
+  template<class TPopupFunctor>
+  struct TPopupDispatcher
+  {
+    QString
+    operator()(VisuGUI* theModule, 
+              const QString& theEntry)
+    {
+      if(SUIT_ViewManager* aViewManager = theModule->getApp()->activeViewManager()){
+       QString aType = aViewManager->getType();
+       TPopupFunctor aFunctor;
+       if(aType == SVTK_Viewer::Type())
+         return aFunctor.template Get<SVTK_Viewer>(theModule,theEntry);
+       else if(aType == VVTK_Viewer::Type())
+         return aFunctor.template Get<VVTK_Viewer>(theModule,theEntry);
+      }
+      return QString();
+    }    
+  };
+}
+
+QString VisuGUI_Selection::isVisible( const int ind ) const
+{
+  return TPopupDispatcher<TIsVisibleFunctor>()((VisuGUI*)myModule,entry(ind));
 }
 
 QString VisuGUI_Selection::isShrunk( const int ind ) const