Salome HOME
Fix for Bug IPAL8945
[modules/visu.git] / src / VISUGUI / VisuGUI_PopupTools.cxx
index 74175dffb0c8d2ba83ab84cde7e5d6b161a9a476..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;
 
@@ -38,10 +44,12 @@ 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 ) );
@@ -49,6 +57,8 @@ QtxValue VisuGUI_Selection::param( const int ind, const QString& p ) const
     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 ) );
+    else if ( p == "isScalarMapAct" ) val = QtxValue( isScalarMapAct( ind ) );
   }
 
   return val;
@@ -64,35 +74,56 @@ QString VisuGUI_Selection::type( const int ind ) const
 {
   QString aResStr;
   VISU::Storable::TRestoringMap aMap;
-  CORBA::Object_var anObject = GetSelectedObj( study(), entry( ind ), &aMap );  
-  bool isExist;
-  const QString& aVal = VISU::Storable::FindValue(aMap,"myComment",&isExist);
-  if ( isExist )
-    aResStr = "VISU::T" + aVal;
-  else{
-    VISU::Base_var aVisuObj = VISU::Base::_narrow( anObject );
-    if ( !CORBA::is_nil( aVisuObj ) ){
-      VISU::VISUType aType = aVisuObj->GetType();
+  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 ) ){
+    VISU::VISUType aType = aVisuObj->GetType();
+    switch (aType) {
+      ENUM2STRING( aResStr, VISU::TVISUGEN );
+      ENUM2STRING( aResStr, VISU::TRESULT );
+      ENUM2STRING( aResStr, VISU::TTABLE );
+      ENUM2STRING( aResStr, VISU::TCURVE );
+      ENUM2STRING( aResStr, VISU::TCONTAINER );
+      ENUM2STRING( aResStr, VISU::TMESH );
+      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 );
+      ENUM2STRING( aResStr, VISU::TSTREAMLINES );
+      ENUM2STRING( aResStr, VISU::TPLOT3D );
+      ENUM2STRING( aResStr, VISU::TANIMATION );
+    }
+  }
+
+  if(aResStr.isNull()){
+    bool isExist;
+    VISU::VISUType aType = (VISU::VISUType)VISU::Storable::FindValue( aMap, "myType", &isExist).toInt();
+    if( isExist ){
       switch (aType) {
-       ENUM2STRING( aResStr, VISU::TVISUGEN );
-       ENUM2STRING( aResStr, VISU::TRESULT );
-       ENUM2STRING( aResStr, VISU::TTABLE );
-       ENUM2STRING( aResStr, VISU::TCURVE );
-       ENUM2STRING( aResStr, VISU::TCONTAINER );
-       ENUM2STRING( aResStr, VISU::TMESH );
-       ENUM2STRING( aResStr, VISU::TSCALARMAP );
-       ENUM2STRING( aResStr, VISU::TISOSURFACE );
-       ENUM2STRING( aResStr, VISU::TDEFORMEDSHAPE );
-       ENUM2STRING( aResStr, VISU::TCUTPLANES );
-       ENUM2STRING( aResStr, VISU::TCUTLINES );
-       ENUM2STRING( aResStr, VISU::TVECTORS );
-       ENUM2STRING( aResStr, VISU::TSTREAMLINES );
-       ENUM2STRING( aResStr, VISU::TPLOT3D );
-       ENUM2STRING( aResStr, VISU::TANIMATION );
+       ENUM2STRING( aResStr, VISU::TENTITY );
+       ENUM2STRING( aResStr, VISU::TFAMILY );
+       ENUM2STRING( aResStr, VISU::TGROUP );
+       ENUM2STRING( aResStr, VISU::TVIEW3D );
+       ENUM2STRING( aResStr, VISU::TFIELD );
+       ENUM2STRING( aResStr, VISU::TTIMESTAMP );
       }
     }
   }
 
+  if(aResStr.isNull()){
+    bool isExist;
+    QString aVal = VISU::Storable::FindValue(aMap,"myComment",&isExist);
+    if ( isExist && aVal!="MESH" )
+      aResStr = "VISU::T" + aVal;
+  }
+
   return aResStr;
 }
 
@@ -100,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 )
@@ -108,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 )
@@ -140,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 ){
@@ -171,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
@@ -198,3 +327,29 @@ QString VisuGUI_Selection::hasActor( const int ind ) const
 {
   return representation( ind ).isEmpty() ? "0" : "1";
 }
+
+QString VisuGUI_Selection::isShading( const int ind ) const
+{
+  QString aResStr;
+  
+  if ( SVTK_ViewWindow* aView = GetViewWindow( myModule ) )
+    if ( VISU_Actor* anVISUActor = FindActor( aView, entry( ind ).latin1() ) )
+      if ( VISU_ScalarMapAct* anActor = dynamic_cast<VISU_ScalarMapAct*>(anVISUActor) )
+       aResStr = anActor->IsShading() ? "1" : "0";
+  
+  return aResStr;      
+}
+
+QString VisuGUI_Selection::isScalarMapAct( const int ind ) const
+{
+  QString aResStr;
+
+  if ( SVTK_ViewWindow* aView = GetViewWindow( myModule ) )
+    if ( VISU_Actor* anVISUActor = FindActor( aView, entry( ind ).latin1() ) )
+      {
+       VISU_ScalarMapAct* anActor = dynamic_cast<VISU_ScalarMapAct*>(anVISUActor);
+       aResStr = anActor ? "1" : "0";
+      }
+  
+  return aResStr;
+}