Salome HOME
[EDF] AsterStudy: fit 3D view to given presentations
[modules/gui.git] / src / SALOME_SWIG / SALOMEGUI_Swig.cxx
index d1ee880c200091ac3a2f669aca882d4c39d36cee..ff1eaf98bbbec700bfcbf2a40a0aaf50707df4e1 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -62,6 +62,7 @@
 #endif
 #endif
 
+#include <utilities.h>
 
 /*!
   \class SALOMEGUI_Swig
@@ -483,7 +484,7 @@ void SALOMEGUI_Swig::DisplayOnly( const char* theEntry )
        QStringList comps;
        aStudy->components( comps );
        foreach( QString comp, comps ) {
-         LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( anApp->moduleTitle( comp ), true );
+         LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( anApp->moduleTitle( comp ), false );
          if ( d ) d->EraseAll( false, false, 0 );
        }
 
@@ -593,7 +594,7 @@ void SALOMEGUI_Swig::EraseAll()
        QStringList comps;
        aStudy->components( comps );
        foreach( QString comp, comps ) {
-         LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( anApp->moduleTitle( comp ), true );
+         LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( anApp->moduleTitle( comp ), false );
          if ( d ) d->EraseAll( false, false, 0 );
        }
       }
@@ -623,9 +624,11 @@ public:
   virtual void Execute()
   {
     if ( LightApp_Application* anApp = getApplication() ) {
-      SUIT_ViewWindow* window = anApp->desktop()->activeWindow();
+      SUIT_ViewManager* viewMgr = anApp->activeViewManager();
+      if (!viewMgr) return;
+      SUIT_ViewWindow* window = viewMgr->getActiveView();
       if ( window ) {
-        SALOME_View* view = dynamic_cast<SALOME_View*>( window->getViewManager()->getActiveView() );
+        SALOME_View* view = dynamic_cast<SALOME_View*>( window->getViewManager()->getViewModel() );
         if ( view ) {
           SALOME_Prs* aPrs = view->CreatePrs( myEntry.toLatin1() );
           myResult = !aPrs->IsNull();
@@ -651,9 +654,11 @@ void SALOMEGUI_Swig::UpdateView()
     virtual void Execute()
     {
       if ( LightApp_Application* anApp = getApplication() ) {
-        SUIT_ViewWindow* window = anApp->desktop()->activeWindow();
+        SUIT_ViewManager* viewMgr = anApp->activeViewManager();
+        if (!viewMgr) return;
+        SUIT_ViewWindow* window = viewMgr->getActiveView();
         if ( window ) {
-          SALOME_View* view = dynamic_cast<SALOME_View*>( window->getViewManager()->getActiveView() );
+          SALOME_View* view = dynamic_cast<SALOME_View*>( window->getViewManager()->getViewModel() );
           if ( view )
             view->Repaint();
         }
@@ -668,6 +673,7 @@ void SALOMEGUI_Swig::UpdateView()
 */
 void SALOMEGUI_Swig::FitAll()
 {
+  MESSAGE("FitAll");
   class TEvent: public SALOME_Event
   {
   public:
@@ -675,7 +681,9 @@ void SALOMEGUI_Swig::FitAll()
     virtual void Execute()
     {
       if ( LightApp_Application* anApp = getApplication() ) {
-        SUIT_ViewWindow* window = anApp->desktop()->activeWindow();
+        SUIT_ViewManager* viewMgr = anApp->activeViewManager();
+        if (!viewMgr) return;
+        SUIT_ViewWindow* window = viewMgr->getActiveView();
         if ( window ) {
 #ifndef DISABLE_SALOMEOBJECT
 #ifndef DISABLE_VTKVIEWER
@@ -698,6 +706,63 @@ void SALOMEGUI_Swig::FitAll()
   ProcessVoidEvent( new TEvent() );
 }
 
+void SALOMEGUI_Swig::FitSelection()
+{
+  class TEvent: public SALOME_Event
+  {
+  public:
+    TEvent() {}
+    virtual void Execute()
+    {
+      if ( LightApp_Application* anApp = getApplication() ) {
+        SUIT_ViewManager* viewMgr = anApp->activeViewManager();
+        if (!viewMgr) return;
+        SUIT_ViewWindow* window = viewMgr->getActiveView();
+        if ( window ) {
+#if !defined(DISABLE_SALOMEOBJECT) && !defined(DISABLE_VTKVIEWER)
+          if ( dynamic_cast<SVTK_ViewWindow*>( window ) )
+            (dynamic_cast<SVTK_ViewWindow*>( window ))->onFitSelection();
+#endif
+#if !defined(DISABLE_OCCVIEWER)
+          if ( dynamic_cast<OCCViewer_ViewWindow*>( window ) )
+            (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onFitSelection();
+#endif
+        }
+      }
+    }
+  };
+  ProcessVoidEvent( new TEvent() );
+}
+
+void SALOMEGUI_Swig::FitIObjects(const std::list<std::string>& entries)
+{
+  class TEvent: public SALOME_Event
+  {
+    const std::list<std::string>& myEntries;
+  public:
+    TEvent( const std::list<std::string>& objs ) : myEntries( objs ) {}
+    virtual void Execute()
+    {
+      if ( LightApp_Application* anApp = getApplication() ) {
+        SUIT_ViewManager* viewMgr = anApp->activeViewManager();
+        if (!viewMgr) return;
+        SUIT_ViewWindow* window = viewMgr->getActiveView();
+        if ( window ) {
+         SALOME_ListIO objects;
+         std::list<std::string>::const_iterator it;
+         for ( it = myEntries.begin(); it != myEntries.end(); ++it )
+           objects.Append( new SALOME_InteractiveObject( (*it).c_str(), "" ) );
+#if !defined(DISABLE_SALOMEOBJECT) && !defined(DISABLE_VTKVIEWER)
+          if ( dynamic_cast<SVTK_ViewWindow*>( window ) )
+            (dynamic_cast<SVTK_ViewWindow*>( window ))->onFitIObjects( objects );
+#endif
+        }
+      }
+    }
+  };
+  ProcessVoidEvent( new TEvent( entries ) );
+}
+
 /*!
   \brief Reset current view window to the default state.
 */
@@ -710,7 +775,9 @@ void SALOMEGUI_Swig::ResetView()
     virtual void Execute()
     {
       if ( LightApp_Application* anApp = getApplication() ) {
-        SUIT_ViewWindow* window = anApp->desktop()->activeWindow();
+        SUIT_ViewManager* viewMgr = anApp->activeViewManager();
+        if (!viewMgr) return;
+        SUIT_ViewWindow* window = viewMgr->getActiveView();
         if ( window ) {
 #ifndef DISABLE_SALOMEOBJECT
 #ifndef DISABLE_VTKVIEWER
@@ -764,7 +831,9 @@ static void setView( int view )
     virtual void Execute()
     {
       if ( LightApp_Application* anApp = getApplication() ) {
-        SUIT_ViewWindow* window = anApp->desktop()->activeWindow();
+           SUIT_ViewManager* viewMgr = anApp->activeViewManager();
+           if (!viewMgr) return;
+           SUIT_ViewWindow* window = viewMgr->getActiveView();
         if ( window ) {
 #ifndef DISABLE_SALOMEOBJECT
 #ifndef DISABLE_VTKVIEWER
@@ -880,7 +949,9 @@ public:
   TGetViewParameters() : myResult( "" ) {}
   virtual void Execute() {  
     if ( LightApp_Application* anApp = getApplication() ) {
-      if ( SUIT_ViewWindow* window = anApp->desktop()->activeWindow() ) {
+         SUIT_ViewManager* viewMgr = anApp->activeViewManager();
+         if (!viewMgr) return;
+         if ( SUIT_ViewWindow* window = viewMgr->getActiveView() ) {
 #ifndef DISABLE_VTKVIEWER
        if ( SVTK_ViewWindow* svtk = dynamic_cast<SVTK_ViewWindow*>( window ) ) {         
          if ( vtkRenderer* ren = svtk->getRenderer()) {                    
@@ -944,7 +1015,9 @@ static void setViewParameter( int parameter, QList<double>& values ) {
 
     virtual void Execute() {
       if ( LightApp_Application* anApp = getApplication() ) {
-       if ( SUIT_ViewWindow* window = anApp->desktop()->activeWindow() ) {
+         SUIT_ViewManager* viewMgr = anApp->activeViewManager();
+         if (!viewMgr) return;
+         if ( SUIT_ViewWindow* window = viewMgr->getActiveView() ) {
 #ifndef DISABLE_VTKVIEWER
          if ( SVTK_ViewWindow* svtk = dynamic_cast<SVTK_ViewWindow*>( window ) ) {       
            if ( vtkRenderer* ren = svtk->getRenderer()) {