Salome HOME
Remove obsolete staff; redesign Handle-based and CDL-generated classes
[modules/gui.git] / src / SALOME_SWIG / SALOMEGUI_Swig.cxx
1 // Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  SALOME SALOMEGUI : implementation of desktop and GUI kernel
24 // File   : SALOMEGUI_Swig.cxx
25 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
26 //
27 #include "SALOMEGUI_Swig.hxx"
28
29 #include <SUIT_Session.h>
30 #include <SUIT_Desktop.h>
31 #include <SUIT_ViewWindow.h>
32 #include <SUIT_ViewManager.h>
33 #include <SUIT_DataObjectIterator.h>
34 #include <CAM_DataModel.h>
35 #include <LightApp_Application.h>
36 #include <LightApp_Displayer.h>
37 #include <LightApp_Study.h>
38 #include <LightApp_Module.h>
39 #include <LightApp_DataObject.h>
40 #include <LightApp_SelectionMgr.h>
41 #include <LightApp_DataOwner.h>
42 #include <SALOME_Prs.h>
43 #include <SALOME_Event.h>
44
45 #ifndef DISABLE_SALOMEOBJECT
46   #include <SALOME_ListIO.hxx>
47   #include <SALOME_InteractiveObject.hxx>
48 #ifndef DISABLE_OCCVIEWER
49     #include <SOCC_ViewModel.h>
50     #include <SOCC_ViewWindow.h>
51 #endif
52 #ifndef DISABLE_VTKVIEWER
53     #include <SVTK_ViewModel.h>
54     #include <SVTK_ViewWindow.h>
55 #endif
56 #ifndef DISABLE_PLOT2DVIEWER
57     #include <SPlot2d_ViewWindow.h>
58 #endif
59 #endif
60
61
62 /*!
63   \class SALOMEGUI_Swig
64   \brief Python interface module for SALOME GUI.
65
66   This module provides an access to the SALOME GUI implementing set of functions
67   which can be used from Python. This module is implemented using SWIG wrappings
68   for some GUI functionality:
69   - getActiveStudyId(), getActiveStudyName() : get active study identifier and name
70   - updateObjBrowser() : update contents of the Object Browser
71   - SelectedCount() : get number of currently selected items
72   - getSelected() : get entry of the speicified selected item
73   - ClearIObjects() : clear selection
74   - Display(), DisplayOnly(), Erase() : display/erase objects
75   - etc.
76
77   Instance of this class is created every time "import salome" line is typed 
78   - in IAPP embedded Python interpretor  (SALOME_Session_Server executable)
79   - in inline Python nodes in Supervisor (in SALOME_Container executable)
80   - in stand-alone Python console outside any executable
81
82   SALOME GUI (desktop and other objects) is only available in SALOME_Session_Server.
83   It means that it can not be accessed from the external Python console.
84
85   The usage in Python:
86   \code
87   import libSALOME_Swig
88   sg = libSALOME_Swig.SALOMEGUI_Swig()
89   if sg.hasDesktop():
90       selcount = sg.SelectedCount()
91       if selcount > 0:
92           sg.Erase( sg.getSelected( 0 ) )
93       pass
94   \endcode
95 */
96
97 /*
98   --- INTERNAL COMMENTS SECTION ---
99
100   ASV : 03.12.04 : added checking for NULL GUI objects in almost all methods.
101   In the scope of fixing bug PAL6869.
102
103   VSR : 19.04.05 : Reimplemented for new SALOME GUI (SUIT-based)
104   All methods are implemeted using Event mechanism.
105   Display/Erase methods use SALOME_Prs/SALOME_View mechanism. It is currently
106   implemented only for OCC and VTK viewers.
107 */
108
109 /*!
110   \brief Get active application object
111   \internal
112   \return active application or 0 if there is no any
113 */
114 static LightApp_Application* getApplication()
115 {
116   if ( SUIT_Session::session() )
117     return dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() );
118   return 0;
119 }
120
121 /*!
122   \brief Get active study object
123   \internal
124   \return active study or 0 if there is no study opened
125 */
126 static LightApp_Study* getActiveStudy()
127 {
128   if ( getApplication() )
129     return dynamic_cast<LightApp_Study*>( getApplication()->activeStudy() );
130   return 0;
131 }
132
133 /*!
134   \brief Constructor.
135 */
136 SALOMEGUI_Swig::SALOMEGUI_Swig()
137 {
138 }
139
140 /*!
141   \brief Destructor
142 */
143 SALOMEGUI_Swig::~SALOMEGUI_Swig()
144 {
145 }
146
147 /*!
148   \fn bool SALOMEGUI_Swig::hasDesktop()
149   \brief Check GUI availability.
150   \return \c true if GUI is available
151 */
152
153 class THasDesktopEvent: public SALOME_Event
154 {
155 public:
156   typedef bool TResult;
157   TResult myResult;
158   THasDesktopEvent() : myResult( false ) {}
159   virtual void Execute()
160   {
161     myResult = (bool)( getApplication() && getApplication()->desktop() );
162   }
163 };
164 bool SALOMEGUI_Swig::hasDesktop()
165 {
166   return ProcessEvent( new THasDesktopEvent() );
167 }
168
169 /*!
170   \brief Update active study's Object Browser.
171   \param updateSelection this parameter is obsolete
172 */
173 void SALOMEGUI_Swig::updateObjBrowser( bool /*updateSelection*/ )
174 {
175   class TEvent: public SALOME_Event
176   {
177   public:
178     TEvent() {}
179     virtual void Execute()
180     {
181       if ( LightApp_Application* anApp = getApplication() ) {
182         anApp->updateObjectBrowser();
183         anApp->updateActions(); //SRN: added in order to update the toolbar
184       }
185     }
186   };
187   ProcessVoidEvent( new TEvent() );
188 }
189
190 /*!
191   \fn int SALOMEGUI_Swig::getActiveStudyId()
192   \brief Get active study identifier
193   \return active study's ID or 0 if there is no active study
194 */
195
196 class TGetActiveStudyIdEvent: public SALOME_Event
197 {
198 public:
199   typedef int TResult;
200   TResult myResult;
201   TGetActiveStudyIdEvent() : myResult( 0 ) {}
202   virtual void Execute()
203   {
204     if ( LightApp_Study* aStudy = getActiveStudy() ) {
205       myResult = aStudy->id();
206     }
207   }
208 };
209 int SALOMEGUI_Swig::getActiveStudyId()
210 {
211   return ProcessEvent( new TGetActiveStudyIdEvent() );
212 }
213
214 /*!
215   \fn const char* SALOMEGUI_Swig::getActiveStudyName()
216   \brief Get active study name
217   \return active study's name or null string if there is no active study
218 */
219
220 class TGetActiveStudyNameEvent: public SALOME_Event
221 {
222 public:
223   typedef std::string TResult;
224   TResult myResult;
225   TGetActiveStudyNameEvent() {}
226   virtual void Execute()
227   {
228     if ( LightApp_Study* aStudy = getActiveStudy() ) {
229       myResult = aStudy->studyName().toUtf8().constData();
230     }
231   }
232 };
233 const char* SALOMEGUI_Swig::getActiveStudyName()
234 {
235   std::string result = ProcessEvent( new TGetActiveStudyNameEvent() );
236   return result.empty() ? 0 : result.c_str();
237 }
238
239 /*!
240   \fn const char* SALOMEGUI_Swig::getComponentName( const char* componentUserName )
241   \brief Get name of the component by its title (user name)
242   \param componentUserName component title (user name)
243   \return component name or null string if component title is invalid
244 */
245
246 /*!
247   \fn const char* SALOMEGUI_Swig::getComponentUserName( const char* componentName )
248   \brief Get title (user name) of the component by its name
249   \param componentName component name
250   \return component title or null string if component name is invalid
251 */
252
253 class TGetComponentNameEvent: public SALOME_Event
254 {
255 public:
256   typedef QString TResult;
257   TResult myResult;
258   QString myName;
259   bool    myIsUserName;
260   TGetComponentNameEvent( const QString& name, bool isUserName )
261     : myName( name ), myIsUserName( isUserName ) {}
262   virtual void Execute()
263   {
264     if ( LightApp_Application* app = getApplication() ) {
265       myResult = myIsUserName ? app->moduleTitle( myName ) : app->moduleName( myName );
266     }
267   }
268 };
269 const char* SALOMEGUI_Swig::getComponentName( const char* componentUserName )
270 {
271   QString result = ProcessEvent( new TGetComponentNameEvent( componentUserName, false ) );
272   return result.isEmpty() ? 0 : strdup( result.toLatin1().constData() );
273 }
274 const char* SALOMEGUI_Swig::getComponentUserName( const char* componentName )
275 {
276   QString result = ProcessEvent( new TGetComponentNameEvent( componentName, true ) );
277   return result.isEmpty() ? 0 : strdup( result.toLatin1().constData() );
278 }
279
280 /*!
281   \fn int SALOMEGUI_Swig::SelectedCount()
282   \brief Get number of selected items
283   \return number of selected items in the active study
284 */
285
286 /*!
287   \fn const char* SALOMEGUI_Swig::getSelected( int index )
288   \brief Get entry of the specified selected item
289   \param index selected object index
290   \return selected object entry (null string if index is invalid)
291 */
292
293 class TGetSelectedEvent: public SALOME_Event
294 {
295 public:
296   typedef QStringList TResult;
297   TResult myResult;
298   TGetSelectedEvent() {}
299   virtual void Execute()
300   {
301     if ( LightApp_Application* anApp = getApplication() ) {
302       LightApp_Study* aStudy  = dynamic_cast<LightApp_Study*>( anApp->activeStudy() ); // for sure!
303       LightApp_SelectionMgr* aSelMgr = anApp->selectionMgr(); 
304       if ( aStudy && aSelMgr ) {
305         SUIT_DataOwnerPtrList aList;
306         aSelMgr->selected( aList );
307
308         for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); 
309               itr != aList.end(); ++itr ) {
310           const LightApp_DataOwner* owner = 
311             dynamic_cast<const LightApp_DataOwner*>( (*itr).operator->() );
312           if( !owner )
313             continue;
314           QString entry = owner->entry();
315           if( !myResult.contains( entry ) )
316             myResult.append( entry );
317         }
318       }
319     }
320   }
321 };
322 int SALOMEGUI_Swig::SelectedCount()
323 {
324   QStringList selected = ProcessEvent( new TGetSelectedEvent() );
325   return selected.count();
326 }
327 const char* SALOMEGUI_Swig::getSelected( int index )
328 {
329   QStringList selected = ProcessEvent( new TGetSelectedEvent() );
330   return index >= 0 && index < selected.count() ? 
331     strdup( selected[ index ].toLatin1().constData() ) : 0;
332 }
333
334 /*!
335   \brief Add an object to the current selection.
336   \param theEntry object entry
337 */
338 void SALOMEGUI_Swig::AddIObject( const char* theEntry )
339 {
340   class TEvent: public SALOME_Event
341   {
342   public:
343     QString myEntry;
344     TEvent( const char* theEntry ) : myEntry( theEntry ) {}
345     virtual void Execute()
346     {
347       if ( LightApp_Application* anApp = getApplication() ) {
348         LightApp_Study*       aStudy  = dynamic_cast<LightApp_Study*>( anApp->activeStudy() ); // for sure!
349         LightApp_SelectionMgr* aSelMgr = anApp->selectionMgr(); 
350         if ( aStudy && aSelMgr ) {
351           SALOME_ListIO anIOList;
352           anIOList.Append( new SALOME_InteractiveObject( myEntry.toLatin1(), "", "" ) );
353           aSelMgr->setSelectedObjects( anIOList, true );
354         }
355       }
356     }
357   };
358   ProcessVoidEvent( new TEvent( theEntry ) );
359 }
360
361 /*!
362   \brief Remove the object from the selection.
363   \param theEntry object entry
364 */
365 void SALOMEGUI_Swig::RemoveIObject( const char* theEntry )
366 {
367   class TEvent: public SALOME_Event
368   {
369   public:
370     QString myEntry;
371     TEvent( const char* theEntry ) : myEntry( theEntry ) {}
372     virtual void Execute()
373     {
374       if ( LightApp_Application* anApp = getApplication() ) {
375         LightApp_Study* aStudy  = dynamic_cast<LightApp_Study*>( anApp->activeStudy() ); // for sure!
376         LightApp_SelectionMgr* aSelMgr = anApp->selectionMgr(); 
377         if ( aStudy && aSelMgr ) {
378           SALOME_ListIO anIOList;
379           // VSR: temporary solution, until LightApp_SelectionMgr::unsetSelectedObjects() method appears
380           // Lately this should be replaced by the following:
381           // anIOList.Append( new SALOME_InteractiveObject( myEntry, "", "" ) );
382           // aSelMgr->unsetSelectedObjects( anIOList );
383           ///////////////////////////////////////////////
384           aSelMgr->selectedObjects( anIOList );
385           SALOME_ListIteratorOfListIO anIter( anIOList );
386           for( ; anIter.More(); anIter.Next() ) {
387             if ( anIter.Value()->isSame( new SALOME_InteractiveObject( myEntry.toLatin1(), "", "" ) ) ) { 
388               anIOList.Remove( anIter );
389               aSelMgr->setSelectedObjects( anIOList, true );
390               return;
391             }
392           }
393         }
394       }
395     }
396   };
397   ProcessVoidEvent( new TEvent( theEntry ) );
398 }
399
400 /*!
401   \brief Clear selection (unselect all objects).
402 */
403 void SALOMEGUI_Swig::ClearIObjects()
404 {
405   class TEvent: public SALOME_Event
406   {
407   public:
408     TEvent() {}
409     virtual void Execute()
410     {
411       if ( LightApp_Application* anApp = getApplication() ) {
412         LightApp_Study* aStudy  = dynamic_cast<LightApp_Study*>( anApp->activeStudy() ); // for sure!
413         LightApp_SelectionMgr* aSelMgr = anApp->selectionMgr(); 
414         if ( aStudy && aSelMgr )
415           aSelMgr->clearSelected();
416       }
417     }
418   };
419   ProcessVoidEvent( new TEvent() );
420 }
421
422 /*!
423   \brief Display an object in the current view window.
424
425   The presentable object should be previously created and
426   displayed in this viewer.
427
428   \param theEntry object entry
429 */              
430 void SALOMEGUI_Swig::Display( const char* theEntry )
431 {
432   class TEvent: public SALOME_Event
433   {
434     QString myEntry;
435   public:
436     TEvent( const char* theEntry ) : myEntry( theEntry ) {}
437     virtual void Execute() {
438       LightApp_Application* anApp  = getApplication();
439       LightApp_Study*       aStudy = getActiveStudy();
440       if ( anApp && aStudy ) {
441         QString mname = anApp->moduleTitle( aStudy->componentDataType( myEntry ) );
442         LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mname, true );
443         if ( d ) {
444           QStringList entries;
445           if( aStudy->isComponent( myEntry ) )
446             aStudy->children( myEntry, entries );
447           else
448             entries.append( myEntry );
449           foreach( QString entry, entries )
450             d->Display( aStudy->referencedToEntry( entry ), false, 0 );
451         }
452       }
453     }
454   };
455   ProcessVoidEvent( new TEvent( theEntry ) );
456 }
457
458 /*!
459   \brief Displays an object in the current view window and 
460   erases all other ones.
461
462   The presentable object should be previously created and 
463   displayed in this viewer.
464
465   \param theEntry object entry
466 */
467 void SALOMEGUI_Swig::DisplayOnly( const char* theEntry )
468 {
469   class TEvent: public SALOME_Event
470   {
471     QString myEntry;
472   public:
473     TEvent( const char* theEntry ) : myEntry( theEntry ) {}
474     virtual void Execute()
475     {
476       LightApp_Application* anApp  = getApplication();
477       LightApp_Study*       aStudy = getActiveStudy();
478       if ( anApp && aStudy ) {
479         QStringList comps;
480         aStudy->components( comps );
481         foreach( QString comp, comps ) {
482           LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( anApp->moduleTitle( comp ), true );
483           if ( d ) d->EraseAll( false, false, 0 );
484         }
485
486         QString mname = anApp->moduleTitle( aStudy->componentDataType( myEntry ) );
487         LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mname, true );
488         if ( d ) {
489           QStringList entries;
490           if( aStudy->isComponent( myEntry ) )
491             aStudy->children( myEntry, entries );
492           else
493             entries.append( myEntry );
494           foreach( QString entry, entries )
495             d->Display( aStudy->referencedToEntry( entry ), false, 0 );
496         }
497       }
498     }
499   };
500   ProcessVoidEvent( new TEvent( theEntry ) );
501 }
502
503 /*!
504   \brief Erase an object in the current view window.
505
506   The presentable object should be previously created and 
507   displayed in this viewer.
508
509   \param theEntry object entry
510 */              
511 void SALOMEGUI_Swig::Erase( const char* theEntry )
512 {
513   class TEvent: public SALOME_Event
514   {
515     QString myEntry;
516   public:
517     TEvent( const char* theEntry ) : myEntry( theEntry ) {}
518     virtual void Execute()
519     {
520       LightApp_Application* anApp  = getApplication();
521       LightApp_Study*       aStudy = getActiveStudy();
522       if ( anApp && aStudy ) {
523         QString mname = anApp->moduleTitle( aStudy->componentDataType( myEntry ) );
524         LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mname, true );
525         if ( d ) {
526           QStringList entries;
527           if( aStudy->isComponent( myEntry ) )
528             aStudy->children( myEntry, entries );
529           else
530             entries.append( myEntry );
531           foreach( QString entry, entries )
532             d->Erase( aStudy->referencedToEntry( entry ), false, false, 0 );
533         }
534       }
535     }
536   };
537   ProcessVoidEvent( new TEvent( theEntry ) );
538 }
539
540 /*!
541   \brief Display all active module's presentable 
542   child objects in the current view window.
543   
544   The presentable objects should be previously created and
545   displayed in this viewer.
546 */
547 void SALOMEGUI_Swig::DisplayAll()
548 {
549   class TEvent: public SALOME_Event
550   {
551   public:
552     TEvent() {}
553     virtual void Execute()
554     {
555       LightApp_Application* anApp  = getApplication();
556       LightApp_Study*       aStudy = getActiveStudy();
557       if ( anApp && aStudy ) {
558         QStringList comps;
559         aStudy->components( comps );
560         foreach( QString comp, comps ) {
561           LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( anApp->moduleTitle( comp ), true );
562           if ( d ) {
563             QStringList entries;
564             aStudy->children( aStudy->centry( comp ), entries );
565             foreach( QString entry, entries )
566               d->Display( aStudy->referencedToEntry( entry ), false, 0 );
567           }
568         }
569       }
570     }
571   };
572   ProcessVoidEvent( new TEvent() );
573 }
574
575 /*!
576   \brief Erase all objects from the current view window.
577 */
578 void SALOMEGUI_Swig::EraseAll()
579 {
580   class TEvent: public SALOME_Event
581   {
582   public:
583     TEvent() {}
584     virtual void Execute()
585     {
586       LightApp_Application* anApp  = getApplication();
587       LightApp_Study*       aStudy = getActiveStudy();
588       if ( anApp && aStudy ) {
589         QStringList comps;
590         aStudy->components( comps );
591         foreach( QString comp, comps ) {
592           LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( anApp->moduleTitle( comp ), true );
593           if ( d ) d->EraseAll( false, false, 0 );
594         }
595       }
596     }
597   };
598   ProcessVoidEvent( new TEvent() );
599 }
600
601 /*!
602   \fn bool SALOMEGUI_Swig::IsInCurrentView( const char* theEntry )
603   \brief Check it the object is displayed in the current view window.
604
605   VSR: For the current moment implemented for OCC and VTK viewers only.
606
607   \param theEntry object entry
608   \return \c true if the object with given entry is displayed 
609           in the current viewer
610 */
611
612 class TIsInViewerEvent: public SALOME_Event
613 {
614   QString myEntry;
615 public:
616   typedef bool TResult;
617   TResult myResult;
618   TIsInViewerEvent( const char* theEntry ) : myEntry( theEntry ), myResult( false ) {}
619   virtual void Execute()
620   {
621     if ( LightApp_Application* anApp = getApplication() ) {
622       SUIT_ViewWindow* window = anApp->desktop()->activeWindow();
623       if ( window ) {
624         SALOME_View* view = dynamic_cast<SALOME_View*>( window->getViewManager()->getActiveView() );
625         if ( view ) {
626           SALOME_Prs* aPrs = view->CreatePrs( myEntry.toLatin1() );
627           myResult = !aPrs->IsNull();
628         }
629       }
630     }
631   }
632 };
633 bool SALOMEGUI_Swig::IsInCurrentView( const char* theEntry )
634 {
635   return ProcessEvent( new TIsInViewerEvent( theEntry ) );
636 }
637
638 /*!
639   \brief Update (repaint) current view window.
640 */
641 void SALOMEGUI_Swig::UpdateView()
642 {
643   class TEvent: public SALOME_Event
644   {
645   public:
646     TEvent() {}
647     virtual void Execute()
648     {
649       if ( LightApp_Application* anApp = getApplication() ) {
650         SUIT_ViewWindow* window = anApp->desktop()->activeWindow();
651         if ( window ) {
652           SALOME_View* view = dynamic_cast<SALOME_View*>( window->getViewManager()->getActiveView() );
653           if ( view )
654             view->Repaint();
655         }
656       }
657     }
658   };
659   ProcessVoidEvent( new TEvent() );
660 }
661
662 /*!
663   \brief Fit current view window to display all its contents.
664 */
665 void SALOMEGUI_Swig::FitAll()
666 {
667   class TEvent: public SALOME_Event
668   {
669   public:
670     TEvent() {}
671     virtual void Execute()
672     {
673       if ( LightApp_Application* anApp = getApplication() ) {
674         SUIT_ViewWindow* window = anApp->desktop()->activeWindow();
675         if ( window ) {
676 #ifndef DISABLE_SALOMEOBJECT
677 #ifndef DISABLE_VTKVIEWER
678           if ( dynamic_cast<SVTK_ViewWindow*>( window ) )
679             ( dynamic_cast<SVTK_ViewWindow*>( window ) )->onFitAll();
680 #endif
681 #ifndef DISABLE_PLOT2DVIEWER
682           if ( dynamic_cast<SPlot2d_ViewWindow*>( window ) )
683             ( dynamic_cast<SPlot2d_ViewWindow*>( window ) )->onFitAll();
684 #endif
685 #endif
686 #ifndef DISABLE_OCCVIEWER
687           if ( dynamic_cast<OCCViewer_ViewWindow*>( window ) )
688             ( dynamic_cast<OCCViewer_ViewWindow*>( window ) )->onFitAll();
689 #endif
690         }
691       }
692     }
693   };
694   ProcessVoidEvent( new TEvent() );
695 }
696
697 /*!
698   \brief Reset current view window to the default state.
699 */
700 void SALOMEGUI_Swig::ResetView()
701 {
702   class TEvent: public SALOME_Event
703   {
704   public:
705     TEvent() {}
706     virtual void Execute()
707     {
708       if ( LightApp_Application* anApp = getApplication() ) {
709         SUIT_ViewWindow* window = anApp->desktop()->activeWindow();
710         if ( window ) {
711 #ifndef DISABLE_SALOMEOBJECT
712 #ifndef DISABLE_VTKVIEWER
713           if ( dynamic_cast<SVTK_ViewWindow*>( window ) )
714             (dynamic_cast<SVTK_ViewWindow*>( window ))->onResetView();
715 #endif
716 #ifndef DISABLE_PLOT2DVIEWER
717           if ( dynamic_cast<SPlot2d_ViewWindow*>( window ) )
718             (dynamic_cast<SPlot2d_ViewWindow*>( window ))->onFitAll();
719           // VSR: there is no 'ResetView' functionality for Plot2d viewer,
720           // so we use 'FitAll' instead.
721 #endif
722 #endif
723 #ifndef DISABLE_OCCVIEWER
724           if ( dynamic_cast<OCCViewer_ViewWindow*>( window ) )
725             (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onResetView();
726 #endif
727         }
728       }
729     }
730   };
731   ProcessVoidEvent( new TEvent() );
732 }
733
734 /*!
735   \brief View operation type.
736   \internal
737 */
738 enum {
739   __ViewTop,          //!< view top side
740   __ViewBottom,       //!< view bottom side
741   __ViewLeft,         //!< view left side
742   __ViewRight,        //!< view right side
743   __ViewFront,        //!< view front side
744   __ViewBack          //!< view back side
745 };
746
747 /*!
748   \brief Change the view of the current view window.
749   \internal
750   \param view view operation type
751 */
752 static void setView( int view )
753 {
754   class TEvent: public SALOME_Event
755   {
756   private:
757     int myView;
758   public:
759     TEvent( int view ) : myView( view ) {}
760     virtual void Execute()
761     {
762       if ( LightApp_Application* anApp = getApplication() ) {
763         SUIT_ViewWindow* window = anApp->desktop()->activeWindow();
764         if ( window ) {
765 #ifndef DISABLE_SALOMEOBJECT
766 #ifndef DISABLE_VTKVIEWER
767           if ( dynamic_cast<SVTK_ViewWindow*>( window ) ) {
768             switch( myView ) {
769             case __ViewTop:
770               (dynamic_cast<SVTK_ViewWindow*>( window ))->onTopView(); break;
771             case __ViewBottom:
772               (dynamic_cast<SVTK_ViewWindow*>( window ))->onBottomView(); break;
773             case __ViewLeft:
774               (dynamic_cast<SVTK_ViewWindow*>( window ))->onLeftView(); break;
775             case __ViewRight:
776               (dynamic_cast<SVTK_ViewWindow*>( window ))->onRightView(); break;
777             case __ViewFront:
778               (dynamic_cast<SVTK_ViewWindow*>( window ))->onFrontView(); break;
779             case __ViewBack:
780               (dynamic_cast<SVTK_ViewWindow*>( window ))->onBackView(); break;
781             default:
782               break;
783             }
784           }
785 #endif
786 #endif
787 #ifndef DISABLE_OCCVIEWER
788           if ( dynamic_cast<OCCViewer_ViewWindow*>( window ) ) {
789             switch( myView ) {
790             case __ViewTop:
791               (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onTopView(); break;
792             case __ViewBottom:
793               (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onBottomView(); break;
794             case __ViewLeft:
795               (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onLeftView(); break;
796             case __ViewRight:
797               (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onRightView(); break;
798             case __ViewFront:
799               (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onFrontView(); break;
800             case __ViewBack:
801               (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onBackView(); break;
802             default:
803               break;
804             }
805           }
806 #endif
807         }
808       }
809     }
810   };
811   ProcessVoidEvent( new TEvent( view ) );
812 }
813
814 /*!
815   \brief Switch current view window to show the top view.
816 */
817 void SALOMEGUI_Swig::ViewTop()
818 {
819   setView( __ViewTop );
820 }
821
822 /*!
823   \brief Switch current view window to show the bottom view
824 */
825 void SALOMEGUI_Swig::ViewBottom()
826 {
827   setView( __ViewBottom );
828 }
829
830 /*!
831   \brief Switch current view window to show the left view
832 */
833 void SALOMEGUI_Swig::ViewLeft()
834 {
835   setView( __ViewLeft );
836 }
837
838 /*!
839   \brief Switch current view window to show the right view
840 */
841 void SALOMEGUI_Swig::ViewRight()
842 {
843   setView( __ViewRight );
844 }
845
846 /*!
847   \brief Switch current view window to show the front view
848 */
849 void SALOMEGUI_Swig::ViewFront()
850 {
851   setView( __ViewFront );
852 }
853
854 /*!
855   \brief Switch current view window to show the back view
856 */
857 void SALOMEGUI_Swig::ViewBack()
858 {
859   setView( __ViewBack );
860 }