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