1 // Copyright (C) 2007-2023 CEA, EDF, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
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)
27 #include "SALOMEGUI_Swig.hxx"
29 #include <SUIT_Session.h>
30 #include <SUIT_Desktop.h>
31 #include <SUIT_ViewWindow.h>
32 #include <SUIT_ViewManager.h>
33 #include <SUIT_ViewModel.h>
34 #include <SUIT_DataObjectIterator.h>
35 #include <CAM_DataModel.h>
36 #include <LightApp_Application.h>
37 #include <LightApp_Displayer.h>
38 #include <LightApp_Study.h>
39 #include <LightApp_Module.h>
40 #include <LightApp_DataObject.h>
41 #include <LightApp_SelectionMgr.h>
42 #include <LightApp_DataOwner.h>
43 #include <SALOME_Prs.h>
44 #include <SALOME_Event.h>
46 #ifndef DISABLE_SALOMEOBJECT
47 #include <SALOME_ListIO.hxx>
48 #include <SALOME_InteractiveObject.hxx>
49 #ifndef DISABLE_OCCVIEWER
50 #include <SOCC_ViewModel.h>
51 #include <SOCC_ViewWindow.h>
53 #ifndef DISABLE_VTKVIEWER
54 #include <SVTK_ViewModel.h>
55 #include <SVTK_ViewWindow.h>
56 #include <SVTK_Renderer.h>
58 #include <vtkCamera.h>
59 #include <vtkRenderer.h>
61 #ifndef DISABLE_PLOT2DVIEWER
62 #include <SPlot2d_ViewWindow.h>
66 #include <utilities.h>
70 \brief Python interface module for SALOME GUI.
72 This module provides an access to the SALOME GUI implementing set of functions
73 which can be used from Python. This module is implemented using SWIG wrappings
74 for some GUI functionality:
75 - getActiveStudyName() : get active study name
76 - updateObjBrowser() : update contents of the Object Browser
77 - SelectedCount() : get number of currently selected items
78 - getSelected() : get entry of the speicified selected item
79 - ClearIObjects() : clear selection
80 - Display(), DisplayOnly(), Erase() : display/erase objects
83 Instance of this class is created every time "import salome" line is typed
84 - in IAPP embedded Python interpretor (SALOME_Session_Server executable)
85 - in inline Python nodes in Supervisor (in SALOME_Container executable)
86 - in stand-alone Python console outside any executable
88 SALOME GUI (desktop and other objects) is only available in SALOME_Session_Server.
89 It means that it can not be accessed from the external Python console.
94 sg = libSALOME_Swig.SALOMEGUI_Swig()
96 selcount = sg.SelectedCount()
98 sg.Erase( sg.getSelected( 0 ) )
104 --- INTERNAL COMMENTS SECTION ---
106 ASV : 03.12.04 : added checking for NULL GUI objects in almost all methods.
107 In the scope of fixing bug PAL6869.
109 VSR : 19.04.05 : Reimplemented for new SALOME GUI (SUIT-based)
110 All methods are implemeted using Event mechanism.
111 Display/Erase methods use SALOME_Prs/SALOME_View mechanism. It is currently
112 implemented only for OCC and VTK viewers.
116 \brief Get active application object
118 \return active application or 0 if there is no any
120 static LightApp_Application* getApplication()
122 if ( SUIT_Session::session() )
123 return dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() );
128 \brief Get active study object
130 \return active study or 0 if there is no study opened
132 static LightApp_Study* getActiveStudy()
134 if ( getApplication() )
135 return dynamic_cast<LightApp_Study*>( getApplication()->activeStudy() );
142 SALOMEGUI_Swig::SALOMEGUI_Swig()
149 SALOMEGUI_Swig::~SALOMEGUI_Swig()
154 \fn bool SALOMEGUI_Swig::hasDesktop()
155 \brief Check GUI availability.
156 \return \c true if GUI is available
159 class THasDesktopEvent: public SALOME_Event
162 typedef bool TResult;
164 THasDesktopEvent() : myResult( false ) {}
165 virtual void Execute()
167 myResult = (bool)( getApplication() && getApplication()->desktop() );
170 bool SALOMEGUI_Swig::hasDesktop()
172 return ProcessEvent( new THasDesktopEvent() );
176 \brief Update active study's Object Browser.
178 void SALOMEGUI_Swig::updateObjBrowser()
180 class TEvent: public SALOME_Event
184 virtual void Execute()
186 if ( LightApp_Application* anApp = getApplication() ) {
187 anApp->updateObjectBrowser();
188 anApp->updateActions(); //SRN: added in order to update the toolbar
192 ProcessVoidEvent( new TEvent() );
196 \fn const char* SALOMEGUI_Swig::getActiveStudyName()
197 \brief Get active study name
198 \return active study's name or null string if there is no active study
201 class TGetActiveStudyNameEvent: public SALOME_Event
204 typedef std::string TResult;
206 TGetActiveStudyNameEvent() {}
207 virtual void Execute()
209 if ( LightApp_Study* aStudy = getActiveStudy() ) {
210 myResult = aStudy->studyName().toUtf8().constData();
214 const char* SALOMEGUI_Swig::getActiveStudyName()
216 std::string result = ProcessEvent( new TGetActiveStudyNameEvent() );
217 return result.empty() ? 0 : result.c_str();
221 \fn const char* SALOMEGUI_Swig::getComponentName( const char* componentUserName )
222 \brief Get name of the component by its title (user name)
223 \param componentUserName component title (user name)
224 \return component name or null string if component title is invalid
228 \fn const char* SALOMEGUI_Swig::getComponentUserName( const char* componentName )
229 \brief Get title (user name) of the component by its name
230 \param componentName component name
231 \return component title or null string if component name is invalid
234 class TGetComponentNameEvent: public SALOME_Event
237 typedef QString TResult;
241 TGetComponentNameEvent( const QString& name, bool isUserName )
242 : myName( name ), myIsUserName( isUserName ) {}
243 virtual void Execute()
245 if ( LightApp_Application* app = getApplication() ) {
246 myResult = myIsUserName ? app->moduleTitle( myName ) : app->moduleName( myName );
250 const char* SALOMEGUI_Swig::getComponentName( const char* componentUserName )
252 QString result = ProcessEvent( new TGetComponentNameEvent( componentUserName, false ) );
253 return result.isEmpty() ? 0 : strdup( result.toLatin1().constData() );
255 const char* SALOMEGUI_Swig::getComponentUserName( const char* componentName )
257 QString result = ProcessEvent( new TGetComponentNameEvent( componentName, true ) );
258 return result.isEmpty() ? 0 : strdup( result.toLatin1().constData() );
262 \fn int SALOMEGUI_Swig::SelectedCount()
263 \brief Get number of selected items
264 \return number of selected items in the active study
268 \fn const char* SALOMEGUI_Swig::getSelected( int index )
269 \brief Get entry of the specified selected item
270 \param index selected object index
271 \return selected object entry (null string if index is invalid)
274 class TGetSelectedEvent: public SALOME_Event
277 typedef QStringList TResult;
279 TGetSelectedEvent() {}
280 virtual void Execute()
282 if ( LightApp_Application* anApp = getApplication() ) {
283 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( anApp->activeStudy() ); // for sure!
284 LightApp_SelectionMgr* aSelMgr = anApp->selectionMgr();
285 if ( aStudy && aSelMgr ) {
286 SUIT_DataOwnerPtrList aList;
287 aSelMgr->selected( aList );
289 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin();
290 itr != aList.end(); ++itr ) {
291 const LightApp_DataOwner* owner =
292 dynamic_cast<const LightApp_DataOwner*>( (*itr).operator->() );
295 QString entry = owner->entry();
296 if( !myResult.contains( entry ) )
297 myResult.append( entry );
303 int SALOMEGUI_Swig::SelectedCount()
305 QStringList selected = ProcessEvent( new TGetSelectedEvent() );
306 return selected.count();
308 const char* SALOMEGUI_Swig::getSelected( int index )
310 QStringList selected = ProcessEvent( new TGetSelectedEvent() );
311 return index >= 0 && index < selected.count() ?
312 strdup( selected[ index ].toUtf8().constData() ) : 0;
316 \brief Add an object to the current selection.
317 \param theEntry object entry
319 void SALOMEGUI_Swig::AddIObject( const char* theEntry )
321 class TEvent: public SALOME_Event
325 TEvent( const char* theEntry ) : myEntry( theEntry ) {}
326 virtual void Execute()
328 if ( LightApp_Application* anApp = getApplication() ) {
329 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( anApp->activeStudy() ); // for sure!
330 LightApp_SelectionMgr* aSelMgr = anApp->selectionMgr();
331 if ( aStudy && aSelMgr ) {
332 SALOME_ListIO anIOList;
333 anIOList.Append( new SALOME_InteractiveObject( myEntry.toUtf8(), "", "" ) );
334 aSelMgr->setSelectedObjects( anIOList, true );
339 ProcessVoidEvent( new TEvent( theEntry ) );
343 \brief Remove the object from the selection.
344 \param theEntry object entry
346 void SALOMEGUI_Swig::RemoveIObject( const char* theEntry )
348 class TEvent: public SALOME_Event
352 TEvent( const char* theEntry ) : myEntry( theEntry ) {}
353 virtual void Execute()
355 if ( LightApp_Application* anApp = getApplication() ) {
356 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( anApp->activeStudy() ); // for sure!
357 LightApp_SelectionMgr* aSelMgr = anApp->selectionMgr();
358 if ( aStudy && aSelMgr ) {
359 SALOME_ListIO anIOList;
360 // VSR: temporary solution, until LightApp_SelectionMgr::unsetSelectedObjects() method appears
361 // Lately this should be replaced by the following:
362 // anIOList.Append( new SALOME_InteractiveObject( myEntry, "", "" ) );
363 // aSelMgr->unsetSelectedObjects( anIOList );
364 ///////////////////////////////////////////////
365 aSelMgr->selectedObjects( anIOList );
366 SALOME_ListIteratorOfListIO anIter( anIOList );
367 for( ; anIter.More(); anIter.Next() ) {
368 if ( anIter.Value()->isSame( new SALOME_InteractiveObject( myEntry.toUtf8(), "", "" ) ) ) {
369 anIOList.Remove( anIter );
370 aSelMgr->setSelectedObjects( anIOList, true );
378 ProcessVoidEvent( new TEvent( theEntry ) );
382 \brief Clear selection (unselect all objects).
384 void SALOMEGUI_Swig::ClearIObjects()
386 class TEvent: public SALOME_Event
390 virtual void Execute()
392 if ( LightApp_Application* anApp = getApplication() ) {
393 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( anApp->activeStudy() ); // for sure!
394 LightApp_SelectionMgr* aSelMgr = anApp->selectionMgr();
395 if ( aStudy && aSelMgr )
396 aSelMgr->clearSelected();
400 ProcessVoidEvent( new TEvent() );
404 \brief Display an object in the current view window.
406 The presentable object should be previously created and
407 displayed in this viewer.
409 \param theEntry object entry
411 void SALOMEGUI_Swig::Display( const char* theEntry )
413 class TEvent: public SALOME_Event
417 TEvent( const char* theEntry ) : myEntry( theEntry ) {}
418 virtual void Execute() {
419 LightApp_Application* anApp = getApplication();
420 LightApp_Study* aStudy = getActiveStudy();
421 if ( anApp && aStudy ) {
422 QString mname = aStudy->componentDataType( myEntry );
423 LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mname, true );
426 if( aStudy->isComponent( myEntry ) )
427 aStudy->children( myEntry, entries );
429 entries.append( myEntry );
430 foreach( QString entry, entries )
431 d->Display( aStudy->referencedToEntry( entry ), false, 0 );
436 ProcessVoidEvent( new TEvent( theEntry ) );
440 \brief Displays an object in the current view window and
441 erases all other ones.
443 The presentable object should be previously created and
444 displayed in this viewer.
446 \param theEntry object entry
448 void SALOMEGUI_Swig::DisplayOnly( const char* theEntry )
450 class TEvent: public SALOME_Event
454 TEvent( const char* theEntry ) : myEntry( theEntry ) {}
455 virtual void Execute()
457 LightApp_Application* anApp = getApplication();
458 LightApp_Study* aStudy = getActiveStudy();
459 if ( anApp && aStudy ) {
461 aStudy->components( comps );
462 foreach( QString comp, comps ) {
463 LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( comp, false );
464 if ( d ) d->EraseAll( false, false, 0 );
467 QString mname = aStudy->componentDataType( myEntry );
468 LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mname, true );
471 if( aStudy->isComponent( myEntry ) )
472 aStudy->children( myEntry, entries );
474 entries.append( myEntry );
475 foreach( QString entry, entries )
476 d->Display( aStudy->referencedToEntry( entry ), false, 0 );
481 ProcessVoidEvent( new TEvent( theEntry ) );
485 \brief Erase an object in the current view window.
487 The presentable object should be previously created and
488 displayed in this viewer.
490 \param theEntry object entry
492 void SALOMEGUI_Swig::Erase( const char* theEntry )
494 class TEvent: public SALOME_Event
498 TEvent( const char* theEntry ) : myEntry( theEntry ) {}
499 virtual void Execute()
501 LightApp_Application* anApp = getApplication();
502 LightApp_Study* aStudy = getActiveStudy();
503 if ( anApp && aStudy ) {
504 QString mname = aStudy->componentDataType( myEntry );
505 LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mname, true );
508 if( aStudy->isComponent( myEntry ) )
509 aStudy->children( myEntry, entries );
511 entries.append( myEntry );
512 foreach( QString entry, entries )
513 d->Erase( aStudy->referencedToEntry( entry ), false, false, 0 );
518 ProcessVoidEvent( new TEvent( theEntry ) );
522 \brief Display all active module's presentable
523 child objects in the current view window.
525 The presentable objects should be previously created and
526 displayed in this viewer.
528 void SALOMEGUI_Swig::DisplayAll()
530 class TEvent: public SALOME_Event
534 virtual void Execute()
536 LightApp_Application* anApp = getApplication();
537 LightApp_Study* aStudy = getActiveStudy();
538 if ( anApp && aStudy ) {
540 aStudy->components( comps );
541 foreach( QString comp, comps ) {
542 LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( comp, true );
545 aStudy->children( aStudy->centry( comp ), entries );
546 foreach( QString entry, entries )
547 d->Display( aStudy->referencedToEntry( entry ), false, 0 );
553 ProcessVoidEvent( new TEvent() );
557 \brief Erase all objects from the current view window.
559 void SALOMEGUI_Swig::EraseAll()
561 class TEvent: public SALOME_Event
565 virtual void Execute()
567 LightApp_Application* anApp = getApplication();
568 LightApp_Study* aStudy = getActiveStudy();
569 if ( anApp && aStudy ) {
571 aStudy->components( comps );
572 foreach( QString comp, comps ) {
573 LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( comp, false );
574 if ( d ) d->EraseAll( false, false, 0 );
579 ProcessVoidEvent( new TEvent() );
583 \fn bool SALOMEGUI_Swig::IsInCurrentView( const char* theEntry )
584 \brief Check it the object is displayed in the current view window.
586 VSR: For the current moment implemented for OCC and VTK viewers only.
588 \param theEntry object entry
589 \return \c true if the object with given entry is displayed
590 in the current viewer
593 class TIsInViewerEvent: public SALOME_Event
597 typedef bool TResult;
599 TIsInViewerEvent( const char* theEntry ) : myEntry( theEntry ), myResult( false ) {}
600 virtual void Execute()
602 if ( LightApp_Application* anApp = getApplication() ) {
603 SUIT_ViewManager* viewMgr = anApp->activeViewManager();
604 if (!viewMgr) return;
605 SUIT_ViewWindow* window = viewMgr->getActiveView();
607 SALOME_View* view = dynamic_cast<SALOME_View*>( window->getViewManager()->getViewModel() );
609 SALOME_Prs* aPrs = view->CreatePrs( myEntry.toUtf8() );
610 myResult = !aPrs->IsNull();
616 bool SALOMEGUI_Swig::IsInCurrentView( const char* theEntry )
618 return ProcessEvent( new TIsInViewerEvent( theEntry ) );
622 \brief Update (repaint) current view window.
624 void SALOMEGUI_Swig::UpdateView()
626 class TEvent: public SALOME_Event
630 virtual void Execute()
632 if ( LightApp_Application* anApp = getApplication() ) {
633 SUIT_ViewManager* viewMgr = anApp->activeViewManager();
634 if (!viewMgr) return;
635 SUIT_ViewWindow* window = viewMgr->getActiveView();
637 SALOME_View* view = dynamic_cast<SALOME_View*>( window->getViewManager()->getViewModel() );
644 ProcessVoidEvent( new TEvent() );
648 \brief Fit current view window to display all its contents.
650 void SALOMEGUI_Swig::FitAll()
653 class TEvent: public SALOME_Event
657 virtual void Execute()
659 if ( LightApp_Application* anApp = getApplication() ) {
660 SUIT_ViewManager* viewMgr = anApp->activeViewManager();
661 if (!viewMgr) return;
662 SUIT_ViewWindow* window = viewMgr->getActiveView();
664 #ifndef DISABLE_SALOMEOBJECT
665 #ifndef DISABLE_VTKVIEWER
666 if ( dynamic_cast<SVTK_ViewWindow*>( window ) )
667 ( dynamic_cast<SVTK_ViewWindow*>( window ) )->onFitAll();
669 #ifndef DISABLE_PLOT2DVIEWER
670 if ( dynamic_cast<SPlot2d_ViewWindow*>( window ) )
671 ( dynamic_cast<SPlot2d_ViewWindow*>( window ) )->onFitAll();
674 #ifndef DISABLE_OCCVIEWER
675 if ( dynamic_cast<OCCViewer_ViewWindow*>( window ) )
676 ( dynamic_cast<OCCViewer_ViewWindow*>( window ) )->onFitAll();
682 ProcessVoidEvent( new TEvent() );
685 void SALOMEGUI_Swig::FitSelection()
687 class TEvent: public SALOME_Event
691 virtual void Execute()
693 if ( LightApp_Application* anApp = getApplication() ) {
694 SUIT_ViewManager* viewMgr = anApp->activeViewManager();
695 if (!viewMgr) return;
696 SUIT_ViewWindow* window = viewMgr->getActiveView();
698 #if !defined(DISABLE_SALOMEOBJECT) && !defined(DISABLE_VTKVIEWER)
699 if ( dynamic_cast<SVTK_ViewWindow*>( window ) )
700 (dynamic_cast<SVTK_ViewWindow*>( window ))->onFitSelection();
702 #if !defined(DISABLE_OCCVIEWER)
703 if ( dynamic_cast<OCCViewer_ViewWindow*>( window ) )
704 (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onFitSelection();
710 ProcessVoidEvent( new TEvent() );
713 void SALOMEGUI_Swig::FitIObjects(const std::list<std::string>& entries)
715 class TEvent: public SALOME_Event
717 const std::list<std::string>& myEntries;
719 TEvent( const std::list<std::string>& objs ) : myEntries( objs ) {}
720 virtual void Execute()
722 if ( LightApp_Application* anApp = getApplication() ) {
723 SUIT_ViewManager* viewMgr = anApp->activeViewManager();
724 if (!viewMgr) return;
725 SUIT_ViewWindow* window = viewMgr->getActiveView();
727 SALOME_ListIO objects;
728 std::list<std::string>::const_iterator it;
729 for ( it = myEntries.begin(); it != myEntries.end(); ++it )
730 objects.Append( new SALOME_InteractiveObject( (*it).c_str(), "" ) );
731 #if !defined(DISABLE_SALOMEOBJECT) && !defined(DISABLE_VTKVIEWER)
732 if ( dynamic_cast<SVTK_ViewWindow*>( window ) )
733 (dynamic_cast<SVTK_ViewWindow*>( window ))->onFitIObjects( objects );
739 ProcessVoidEvent( new TEvent( entries ) );
743 \brief Reset current view window to the default state.
745 void SALOMEGUI_Swig::ResetView()
747 class TEvent: public SALOME_Event
751 virtual void Execute()
753 if ( LightApp_Application* anApp = getApplication() ) {
754 SUIT_ViewManager* viewMgr = anApp->activeViewManager();
755 if (!viewMgr) return;
756 SUIT_ViewWindow* window = viewMgr->getActiveView();
758 #ifndef DISABLE_SALOMEOBJECT
759 #ifndef DISABLE_VTKVIEWER
760 if ( dynamic_cast<SVTK_ViewWindow*>( window ) )
761 (dynamic_cast<SVTK_ViewWindow*>( window ))->onResetView();
763 #ifndef DISABLE_PLOT2DVIEWER
764 if ( dynamic_cast<SPlot2d_ViewWindow*>( window ) )
765 (dynamic_cast<SPlot2d_ViewWindow*>( window ))->onFitAll();
766 // VSR: there is no 'ResetView' functionality for Plot2d viewer,
767 // so we use 'FitAll' instead.
770 #ifndef DISABLE_OCCVIEWER
771 if ( dynamic_cast<OCCViewer_ViewWindow*>( window ) )
772 (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onResetView();
778 ProcessVoidEvent( new TEvent() );
782 \brief View operation type.
786 __ViewTop, //!< view top side
787 __ViewBottom, //!< view bottom side
788 __ViewLeft, //!< view left side
789 __ViewRight, //!< view right side
790 __ViewFront, //!< view front side
791 __ViewBack //!< view back side
795 \brief Change the view of the current view window.
797 \param view view operation type
799 static void setView( int view )
801 class TEvent: public SALOME_Event
806 TEvent( int view ) : myView( view ) {}
807 virtual void Execute()
809 if ( LightApp_Application* anApp = getApplication() ) {
810 SUIT_ViewManager* viewMgr = anApp->activeViewManager();
811 if (!viewMgr) return;
812 SUIT_ViewWindow* window = viewMgr->getActiveView();
814 #ifndef DISABLE_SALOMEOBJECT
815 #ifndef DISABLE_VTKVIEWER
816 if ( dynamic_cast<SVTK_ViewWindow*>( window ) ) {
819 (dynamic_cast<SVTK_ViewWindow*>( window ))->onTopView(); break;
821 (dynamic_cast<SVTK_ViewWindow*>( window ))->onBottomView(); break;
823 (dynamic_cast<SVTK_ViewWindow*>( window ))->onLeftView(); break;
825 (dynamic_cast<SVTK_ViewWindow*>( window ))->onRightView(); break;
827 (dynamic_cast<SVTK_ViewWindow*>( window ))->onFrontView(); break;
829 (dynamic_cast<SVTK_ViewWindow*>( window ))->onBackView(); break;
836 #ifndef DISABLE_OCCVIEWER
837 if ( dynamic_cast<OCCViewer_ViewWindow*>( window ) ) {
840 (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onTopView(); break;
842 (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onBottomView(); break;
844 (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onLeftView(); break;
846 (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onRightView(); break;
848 (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onFrontView(); break;
850 (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onBackView(); break;
860 ProcessVoidEvent( new TEvent( view ) );
864 \brief Switch current view window to show the top view.
866 void SALOMEGUI_Swig::ViewTop()
868 setView( __ViewTop );
872 \brief Switch current view window to show the bottom view
874 void SALOMEGUI_Swig::ViewBottom()
876 setView( __ViewBottom );
880 \brief Switch current view window to show the left view
882 void SALOMEGUI_Swig::ViewLeft()
884 setView( __ViewLeft );
888 \brief Switch current view window to show the right view
890 void SALOMEGUI_Swig::ViewRight()
892 setView( __ViewRight );
896 \brief Switch current view window to show the front view
898 void SALOMEGUI_Swig::ViewFront()
900 setView( __ViewFront );
904 \brief Switch current view window to show the back view
906 void SALOMEGUI_Swig::ViewBack()
908 setView( __ViewBack );
912 \fn bool SALOMEGUI_Swig::getViewParameters()
913 \brief Get camera parameters of the active view.
915 NOTE: For the current moment implemented for VTK viewer only.
917 \return \c string with the view parameters
920 class TGetViewParameters: public SALOME_Event
923 typedef QString TResult;
925 TGetViewParameters() : myResult( "" ) {}
926 virtual void Execute() {
927 if ( LightApp_Application* anApp = getApplication() ) {
928 SUIT_ViewManager* viewMgr = anApp->activeViewManager();
929 if (!viewMgr) return;
930 if ( SUIT_ViewWindow* window = viewMgr->getActiveView() ) {
931 #ifndef DISABLE_VTKVIEWER
932 if ( SVTK_ViewWindow* svtk = dynamic_cast<SVTK_ViewWindow*>( window ) ) {
933 if ( vtkRenderer* ren = svtk->getRenderer()) {
934 if ( vtkCamera* camera = ren->GetActiveCamera() ) {
935 double pos[3], focalPnt[3], viewUp[3], scale[3], parScale;
937 // save position, focal point, viewUp, scale
938 camera->GetPosition( pos );
939 camera->GetFocalPoint( focalPnt );
940 camera->GetViewUp( viewUp );
941 parScale = camera->GetParallelScale();
942 svtk->GetRenderer()->GetScale( scale );
944 myResult += QString("sg.setCameraPosition( %1, %2, %3 )\n").arg(pos[0]).arg(pos[1]).arg(pos[2]);
945 myResult += QString("sg.setCameraFocalPoint( %1, %2, %3 )\n").arg(focalPnt[0]).arg(focalPnt[1]).arg(focalPnt[2]);
946 myResult += QString("sg.setCameraViewUp( %1, %2, %3 )\n").arg(viewUp[0]).arg(viewUp[1]).arg(viewUp[2]);
947 myResult += QString("sg.setViewScale(%1, %2, %3, %4 )\n").arg(parScale).arg(scale[0]).arg(scale[1]).arg(scale[2]);
957 const char* SALOMEGUI_Swig::getViewParameters() {
958 QString result = ProcessEvent( new TGetViewParameters() );
959 return result.isEmpty() ? 0 : strdup( result.toUtf8().constData() );
964 \brief View parameter type.
968 __CameraPosition, //!< position of the active camera
969 __CameraFocalPoint, //!< focal point of the active camera
970 __CameraViewUp, //!< view up of the active camera
971 __ViewScale //!< scale of the view
976 \brief Change the camera parameters of the current view window.
979 NOTE: For the current moment implemented for VTK viewer only.
981 \param parameter type of the parameter
982 \param values value of the parameter
984 static void setViewParameter( int parameter, QList<double>& values ) {
985 class TEvent: public SALOME_Event {
988 QList<double> myValues;
990 TEvent( int parameter , QList<double>& values ) : myParameter(parameter), myValues( values ) {}
992 virtual void Execute() {
993 if ( LightApp_Application* anApp = getApplication() ) {
994 SUIT_ViewManager* viewMgr = anApp->activeViewManager();
995 if (!viewMgr) return;
996 if ( SUIT_ViewWindow* window = viewMgr->getActiveView() ) {
997 #ifndef DISABLE_VTKVIEWER
998 if ( SVTK_ViewWindow* svtk = dynamic_cast<SVTK_ViewWindow*>( window ) ) {
999 if ( vtkRenderer* ren = svtk->getRenderer()) {
1000 if ( vtkCamera* camera = ren->GetActiveCamera() ) {
1001 switch(myParameter) {
1002 case __CameraPosition : {
1003 if ( myValues.size() == 3 ) {
1004 camera->SetPosition( myValues[0], myValues[1], myValues[2] );
1008 case __CameraFocalPoint : {
1009 if ( myValues.size() == 3 ) {
1010 camera->SetFocalPoint( myValues[0], myValues[1], myValues[2] );
1014 case __CameraViewUp : {
1015 if ( myValues.size() == 3 ) {
1016 camera->SetViewUp( myValues[0], myValues[1], myValues[2] );
1020 case __ViewScale : {
1021 if ( myValues.size() == 4 ) {
1022 camera->SetParallelScale( myValues[0] );
1023 double scale[] = { myValues[1], myValues[2], myValues[3] };
1024 svtk->GetRenderer()->SetScale( scale );
1039 ProcessVoidEvent( new TEvent( parameter, values ) );
1043 \brief Set camera position of the active view .
1044 \param x - X coordinate of the camera
1045 \param y - Y coordinate of the camera
1046 \param z - Z coordinate of the camera
1048 void SALOMEGUI_Swig::setCameraPosition( double x, double y, double z ) {
1053 setViewParameter( __CameraPosition, lst );
1057 \brief Set camera focal point of the active view.
1058 \param x - X coordinate of the focal point
1059 \param y - Y coordinate of the focal point
1060 \param z - Z coordinate of the focal point
1062 void SALOMEGUI_Swig::setCameraFocalPoint( double x, double y, double z ) {
1067 setViewParameter( __CameraFocalPoint, lst );
1071 \brief Set the view up direction for the camera.
1072 \param x - X component of the direction vector
1073 \param y - Y component of the direction vector
1074 \param z - Z component of the direction vector
1076 void SALOMEGUI_Swig::setCameraViewUp( double x, double y, double z ) {
1081 setViewParameter( __CameraViewUp, lst );
1085 \brief Set view scale.
1086 \param parallelScale - scaling used for a parallel projection.
1091 void SALOMEGUI_Swig::setViewScale( double parallelScale, double x, double y, double z ) {
1093 lst.push_back( parallelScale );
1097 setViewParameter( __ViewScale, lst );