Salome HOME
Fix for Bug IPAL8945
[modules/visu.git] / src / VISUGUI / VisuGUI_PopupTools.cxx
index 39f904b0ee0038628ff637af89b78db8fd157100..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;
 
@@ -45,6 +48,8 @@ QtxValue VisuGUI_Selection::param( const int ind, const QString& p ) const
   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 ) );
@@ -69,7 +74,7 @@ QString VisuGUI_Selection::type( const int ind ) const
 {
   QString aResStr;
   VISU::Storable::TRestoringMap aMap;
-  SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( ( LightApp_Study* )study() );
+  SalomeApp_Study* aStudy = GetStudy();
   if ( !aStudy )
     return aResStr;
   CORBA::Object_var anObject = GetSelectedObj( aStudy, entry( ind ), &aMap );  
@@ -87,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 );
@@ -125,7 +131,7 @@ QString VisuGUI_Selection::nbComponents( const int ind ) const
 {
   QString aResStr;
   VISU::Storable::TRestoringMap aMap;
-  SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( ( LightApp_Study* )study() );
+  SalomeApp_Study* aStudy = GetStudy();
   if ( !aStudy )
     return aResStr;
   GetSelectedObj( aStudy, entry( ind ), &aMap );  
@@ -136,11 +142,61 @@ 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;
-  SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( ( LightApp_Study* )study() );
+  SalomeApp_Study* aStudy = GetStudy();
   if ( !aStudy )
     return aResStr;
   GetSelectedObj( aStudy, entry( ind ), &aMap );  
@@ -171,10 +227,17 @@ 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;
-  SalomeApp_Study* aSStudy = dynamic_cast<SalomeApp_Study*>( ( LightApp_Study* )study() );
+  SalomeApp_Study* aSStudy = GetStudy();
   if ( !aSStudy )
     return cnt;
   _PTR(Study) aStudy =  GetCStudy( aSStudy );
@@ -205,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