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