]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
0021206: CEA] example script fails V6_main_20110311 V6_main_20110314 V6_main_20110315
authorvsr <vsr@opencascade.com>
Thu, 10 Mar 2011 13:06:42 +0000 (13:06 +0000)
committervsr <vsr@opencascade.com>
Thu, 10 Mar 2011 13:06:42 +0000 (13:06 +0000)
src/VISU_I/VISU_Tools.cxx

index d17a33ec2603d06f610da029403b23513fc7ce0e..fb66089e3ded20ff441fbf3ea5d47fe404b444f7 100644 (file)
@@ -347,93 +347,79 @@ namespace VISU
                              bool updateContainers) {
     
     SUIT_Session* aSession = SUIT_Session::session();
-    if(!aSession)
-      return;
+    if (!aSession) return;
     
     SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(aSession->activeApplication());
-    if( !anApp )
-      return;
+    if ( !anApp ) return;
 
-    SUIT_ViewManager* aManager = anApp->activeViewManager();
+    SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
+    if ( !aStudy ) return;
 
-    if( !aManager)
-      return;
-    
-    bool is2dViewActive = aManager->getType() == SPlot2d_Viewer::Type();
+    SalomeApp_Module* aModule = dynamic_cast<SalomeApp_Module*>( anApp->module( anApp->moduleTitle( "VISU" ) ) );
+    if ( !aModule ) return;
+
+    LightApp_Displayer* aDisplayer = aModule->displayer();
+
+    SUIT_ViewManager* aManager = anApp->activeViewManager();
 
-    Qtx::VisibilityState state = is2dViewActive ? GetStateByDisplaying(theDisplaying) : Qtx::UnpresentableState;
+    Qtx::VisibilityState state = ( aManager && aManager->getType() == SPlot2d_Viewer::Type() ) ?
+      GetStateByDisplaying(theDisplaying) : Qtx::UnpresentableState;
     
-    if(updateCurve)
-      SetVisibilityState(theCurve->GetEntry(), state);
+    if ( updateCurve )
+      SetVisibilityState( theCurve->GetEntry(), state );
     
-    if(updateTable) {
+    if ( updateTable ) {
       Table_i* aTable = theCurve->getTable();
-      if(aTable) {
-       if( SalomeApp_Study* aStudy =  dynamic_cast<SalomeApp_Study*>(anApp->activeStudy()) ) {
-         _PTR(SObject) TableSO = aStudy->studyDS()->FindObjectID( aTable->GetEntry() );
-         if ( TableSO ) {
+      if ( aTable ) {
+       _PTR(SObject) TableSO = aStudy->studyDS()->FindObjectID( aTable->GetEntry() );
+       if ( TableSO ) {
+         bool isTableVisible = false;
+         if ( aDisplayer && state != Qtx::UnpresentableState ) {
            _PTR(ChildIterator) Iter = aStudy->studyDS()->NewChildIterator( TableSO );
-           bool isTableVisible = false;
-           LightApp_Displayer* aDisplayer = (dynamic_cast<SalomeApp_Module*>(anApp->activeModule()))->displayer();
-           if(aDisplayer && state != Qtx::UnpresentableState ) {
-             for ( ; Iter->More(); Iter->Next() ) {
-               CORBA::Object_var childObject = VISU::ClientSObjectToObject( Iter->Value() );
-               if( !CORBA::is_nil( childObject ) ) {
-                 CORBA::Object_ptr aCurve_ptr = VISU::Curve::_narrow( childObject );
-                 if( !CORBA::is_nil( aCurve_ptr ) ) {
-                   VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aCurve_ptr).in());
-                   if(aDisplayer->IsDisplayed(aCurve->GetEntry().c_str())) {
-                     isTableVisible = true;
-                     break;
-                   }
-                 } //!CORBA::is_nil( aCurve )
-               } // !CORBA::is_nil( childObject )
-             } //for
-             if(state != Qtx::UnpresentableState)
-               SetVisibilityState(aTable->GetEntry(), (isTableVisible ? Qtx::ShownState : Qtx::HiddenState));
-             else 
-               SetVisibilityState(aTable->GetEntry(), state);
-           } //aDisplayer
-         } //TableSO
-       } //aStudy
-      } //aTable
-    } //updateTable
-
-    if(updateContainers) {
-      if( SalomeApp_Study* aStudy =  dynamic_cast<SalomeApp_Study*>(anApp->activeStudy()) ) {
-       if(LightApp_Displayer* aDisplayer =  (dynamic_cast<SalomeApp_Module*>(anApp->activeModule()))->displayer()) { 
-         ContainerSet aContainers = theCurve->getContainers();
-         ContainerSet::ConstIterator it = aContainers.begin();
-         for(;it != aContainers.end();it++ ) {
-           if(state != Qtx::UnpresentableState) {
-             bool isContainerDisplayed = false;
-             _PTR(SObject) aSObject = aStudy->studyDS()->FindObjectID( (*it).toLatin1().data());
-             CORBA::Object_var anObj = VISU::ClientSObjectToObject( aSObject );
-             if( !CORBA::is_nil( anObj ) ) {
-               if(VISU::Container_i* aContainer = dynamic_cast<VISU::Container_i*>( VISU::GetServant( anObj ).in())) {
-                 int nbCurves = aContainer->GetNbCurves();
-                 for( int k=1; k<=nbCurves; k++ ) {
-                   VISU::Curve_i* aCurve = aContainer->GetCurve( k );
-                   if(aCurve && aDisplayer->IsDisplayed(aCurve->GetEntry().c_str())) {
-                     isContainerDisplayed = true;
-                     break;
-                   } // aCurve && aDisplater->IsDisplayed
-                 } //for k=1 ...
-                 SetVisibilityState(aContainer->GetEntry(), (isContainerDisplayed ? Qtx::ShownState : Qtx::HiddenState));
-               } //aContainer
-             } //!CORBA::is_nil( anObj )
-           } //state != Qtx::UnpresentableState
-           else {
-             SetVisibilityState((*it).toLatin1().data(), state);
+           for ( ; Iter->More() && !isTableVisible ; Iter->Next() ) {
+             CORBA::Object_var childObject = VISU::ClientSObjectToObject( Iter->Value() );
+             if ( CORBA::is_nil( childObject ) ) continue;
+             VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>( VISU::GetServant( childObject.in() ).in() );
+             isTableVisible = aCurve && aDisplayer->IsDisplayed( aCurve->GetEntry().c_str() );
            }
-         } // for Containers           
-       } //aDisplayer
-      } //aStudy
+         } // if ( aDisplayer ... )
+         if ( state != Qtx::UnpresentableState )
+           SetVisibilityState( aTable->GetEntry(), ( isTableVisible ? Qtx::ShownState : Qtx::HiddenState ) );
+         else 
+           SetVisibilityState( aTable->GetEntry(), state );
+       } // if ( TableSO )
+      } // if ( aTable )
+    } // if ( updateTable )
+
+    if ( updateContainers ) {
+      ContainerSet aContainers = theCurve->getContainers();
+      ContainerSet::ConstIterator it = aContainers.begin();
+      for ( ; it != aContainers.end(); it++ ) {
+       _PTR(SObject) aSObject = aStudy->studyDS()->FindObjectID( (*it).toLatin1().data() );
+       if ( !aSObject ) continue;
+       bool isContainerDisplayed = false;
+       if ( aDisplayer && state != Qtx::UnpresentableState ) {
+         CORBA::Object_var anObj = VISU::ClientSObjectToObject( aSObject );
+         if ( CORBA::is_nil( anObj ) ) continue;
+         VISU::Container_i* aContainer = dynamic_cast<VISU::Container_i*>( VISU::GetServant( anObj.in() ).in() );
+         if ( !aContainer ) continue;
+         int nbCurves = aContainer->GetNbCurves();
+         for ( int k = 1; k <= nbCurves && !isContainerDisplayed; k++ ) {
+           VISU::Curve_i* aCurve = aContainer->GetCurve( k );
+           isContainerDisplayed = aCurve && aDisplayer->IsDisplayed( aCurve->GetEntry().c_str() );
+         }
+       } // if ( aDisplayer ... )
+       if ( state != Qtx::UnpresentableState )
+         SetVisibilityState( (*it).toLatin1().constData(), ( isContainerDisplayed ? Qtx::ShownState : Qtx::HiddenState ) );
+       else {
+         SetVisibilityState( (*it).toLatin1().constData(), state );
+       }
+      } // for ( ; it != aContainers.end(); it++ )
     } //updateContainers    
-  } 
-
-  Qtx::VisibilityState GetStateByDisplaying(int theDisplaying) {
-    
+  }
+  
+  Qtx::VisibilityState GetStateByDisplaying(int theDisplaying)
+  {
     Qtx::VisibilityState state = Qtx::UnpresentableState;
     if(theDisplaying == eDisplayAll || 
        theDisplaying == eDisplay    || 
@@ -446,40 +432,38 @@ namespace VISU
     return state;
   }
 
-  void updateContainerVisibility(VISU::Container_i* theContainer) {
-    if(!theContainer)
-      return;
+  void updateContainerVisibility(VISU::Container_i* theContainer)
+  {
+    if ( !theContainer ) return;
     
-    if( SUIT_Session* aSession = SUIT_Session::session() ) {
-      if( SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(aSession->activeApplication()) ) {
-       if( SalomeApp_Study* aStudy =  dynamic_cast<SalomeApp_Study*>(anApp->activeStudy()) ) {
-         Qtx::VisibilityState state = Qtx::UnpresentableState;
-         int nbCurves = theContainer->GetNbCurves();
-         if( nbCurves > 0 ) {
-           if(LightApp_Displayer* aDisplayer =  (dynamic_cast<SalomeApp_Module*>(anApp->activeModule()))->displayer()) {
-             for( int k=1; k<=nbCurves; k++ ) {
-               VISU::Curve_i* aCurve = theContainer->GetCurve( k );
-               if(aCurve && aDisplayer->IsDisplayed(aCurve->GetEntry().c_str())) {
-                 state = Qtx::ShownState;
-                 break;
-               }             
-             }
-             if ( state  == Qtx::UnpresentableState) {
-               if( SUIT_ViewManager * vm = anApp->activeViewManager()){
-                 if(vm->getType() == SPlot2d_Viewer::Type()) {
-                   state = Qtx::HiddenState;
-                 }
-               }
-             }
-           }
-         } else if(SUIT_ViewManager * vm = anApp->activeViewManager()){
-           if(vm->getType() == SPlot2d_Viewer::Type()) {
-             state = Qtx::HiddenState;
-           }
-         }
-         aStudy->setVisibilityState(theContainer->GetEntry().c_str(),state);
-       }
+    SUIT_Session* aSession = SUIT_Session::session();
+    if (!aSession) return;
+    
+    SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(aSession->activeApplication());
+    if ( !anApp ) return;
+
+    SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
+    if ( !aStudy ) return;
+
+    SalomeApp_Module* aModule = dynamic_cast<SalomeApp_Module*>( anApp->module( "VISU" ) );
+    if ( !aModule ) return;
+
+    SUIT_ViewManager* aManager = anApp->activeViewManager();
+    Qtx::VisibilityState state = ( aManager && aManager->getType() == SPlot2d_Viewer::Type() ) ?
+      Qtx::HiddenState : Qtx::UnpresentableState;
+    
+    LightApp_Displayer* aDisplayer = aModule->displayer();
+
+    int nbCurves = theContainer->GetNbCurves();
+    if ( nbCurves > 0 && aDisplayer ) {
+      for ( int k = 1; k <= nbCurves; k++ ) {
+       VISU::Curve_i* aCurve = theContainer->GetCurve( k );
+       if ( aCurve && aDisplayer->IsDisplayed( aCurve->GetEntry().c_str() ) ) {
+         state = Qtx::ShownState;
+         break;
+       }             
       }
     }
+    aStudy->setVisibilityState( theContainer->GetEntry().c_str(), state );
   }
 }