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