1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, 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_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>
45 #ifndef DISABLE_SALOMEOBJECT
46 #include <SALOME_ListIO.hxx>
47 #include <SALOME_InteractiveObject.hxx>
48 #ifndef DISABLE_OCCVIEWER
49 #include <SOCC_ViewModel.h>
50 #include <SOCC_ViewWindow.h>
52 #ifndef DISABLE_VTKVIEWER
53 #include <SVTK_ViewModel.h>
54 #include <SVTK_ViewWindow.h>
55 #include <SVTK_Renderer.h>
57 #include <vtkCamera.h>
58 #include <vtkRenderer.h>
60 #ifndef DISABLE_PLOT2DVIEWER
61 #include <SPlot2d_ViewWindow.h>
68 \brief Python interface module for SALOME GUI.
70 This module provides an access to the SALOME GUI implementing set of functions
71 which can be used from Python. This module is implemented using SWIG wrappings
72 for some GUI functionality:
73 - getActiveStudyId(), getActiveStudyName() : get active study identifier and name
74 - updateObjBrowser() : update contents of the Object Browser
75 - SelectedCount() : get number of currently selected items
76 - getSelected() : get entry of the speicified selected item
77 - ClearIObjects() : clear selection
78 - Display(), DisplayOnly(), Erase() : display/erase objects
81 Instance of this class is created every time "import salome" line is typed
82 - in IAPP embedded Python interpretor (SALOME_Session_Server executable)
83 - in inline Python nodes in Supervisor (in SALOME_Container executable)
84 - in stand-alone Python console outside any executable
86 SALOME GUI (desktop and other objects) is only available in SALOME_Session_Server.
87 It means that it can not be accessed from the external Python console.
92 sg = libSALOME_Swig.SALOMEGUI_Swig()
94 selcount = sg.SelectedCount()
96 sg.Erase( sg.getSelected( 0 ) )
102 --- INTERNAL COMMENTS SECTION ---
104 ASV : 03.12.04 : added checking for NULL GUI objects in almost all methods.
105 In the scope of fixing bug PAL6869.
107 VSR : 19.04.05 : Reimplemented for new SALOME GUI (SUIT-based)
108 All methods are implemeted using Event mechanism.
109 Display/Erase methods use SALOME_Prs/SALOME_View mechanism. It is currently
110 implemented only for OCC and VTK viewers.
114 \brief Get active application object
116 \return active application or 0 if there is no any
118 static LightApp_Application* getApplication()
120 if ( SUIT_Session::session() )
121 return dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() );
126 \brief Get active study object
128 \return active study or 0 if there is no study opened
130 static LightApp_Study* getActiveStudy()
132 if ( getApplication() )
133 return dynamic_cast<LightApp_Study*>( getApplication()->activeStudy() );
140 SALOMEGUI_Swig::SALOMEGUI_Swig()
147 SALOMEGUI_Swig::~SALOMEGUI_Swig()
152 \fn bool SALOMEGUI_Swig::hasDesktop()
153 \brief Check GUI availability.
154 \return \c true if GUI is available
157 class THasDesktopEvent: public SALOME_Event
160 typedef bool TResult;
162 THasDesktopEvent() : myResult( false ) {}
163 virtual void Execute()
165 myResult = (bool)( getApplication() && getApplication()->desktop() );
168 bool SALOMEGUI_Swig::hasDesktop()
170 return ProcessEvent( new THasDesktopEvent() );
174 \brief Update active study's Object Browser.
175 \param updateSelection this parameter is obsolete
177 void SALOMEGUI_Swig::updateObjBrowser( bool /*updateSelection*/ )
179 class TEvent: public SALOME_Event
183 virtual void Execute()
185 if ( LightApp_Application* anApp = getApplication() ) {
186 anApp->updateObjectBrowser();
187 anApp->updateActions(); //SRN: added in order to update the toolbar
191 ProcessVoidEvent( new TEvent() );
195 \fn int SALOMEGUI_Swig::getActiveStudyId()
196 \brief Get active study identifier
197 \return active study's ID or 0 if there is no active study
200 class TGetActiveStudyIdEvent: public SALOME_Event
205 TGetActiveStudyIdEvent() : myResult( 0 ) {}
206 virtual void Execute()
208 if ( LightApp_Study* aStudy = getActiveStudy() ) {
209 myResult = aStudy->id();
213 int SALOMEGUI_Swig::getActiveStudyId()
215 return ProcessEvent( new TGetActiveStudyIdEvent() );
219 \fn const char* SALOMEGUI_Swig::getActiveStudyName()
220 \brief Get active study name
221 \return active study's name or null string if there is no active study
224 class TGetActiveStudyNameEvent: public SALOME_Event
227 typedef std::string TResult;
229 TGetActiveStudyNameEvent() {}
230 virtual void Execute()
232 if ( LightApp_Study* aStudy = getActiveStudy() ) {
233 myResult = aStudy->studyName().toUtf8().constData();
237 const char* SALOMEGUI_Swig::getActiveStudyName()
239 std::string result = ProcessEvent( new TGetActiveStudyNameEvent() );
240 return result.empty() ? 0 : result.c_str();
244 \fn const char* SALOMEGUI_Swig::getComponentName( const char* componentUserName )
245 \brief Get name of the component by its title (user name)
246 \param componentUserName component title (user name)
247 \return component name or null string if component title is invalid
251 \fn const char* SALOMEGUI_Swig::getComponentUserName( const char* componentName )
252 \brief Get title (user name) of the component by its name
253 \param componentName component name
254 \return component title or null string if component name is invalid
257 class TGetComponentNameEvent: public SALOME_Event
260 typedef QString TResult;
264 TGetComponentNameEvent( const QString& name, bool isUserName )
265 : myName( name ), myIsUserName( isUserName ) {}
266 virtual void Execute()
268 if ( LightApp_Application* app = getApplication() ) {
269 myResult = myIsUserName ? app->moduleTitle( myName ) : app->moduleName( myName );
273 const char* SALOMEGUI_Swig::getComponentName( const char* componentUserName )
275 QString result = ProcessEvent( new TGetComponentNameEvent( componentUserName, false ) );
276 return result.isEmpty() ? 0 : strdup( result.toLatin1().constData() );
278 const char* SALOMEGUI_Swig::getComponentUserName( const char* componentName )
280 QString result = ProcessEvent( new TGetComponentNameEvent( componentName, true ) );
281 return result.isEmpty() ? 0 : strdup( result.toLatin1().constData() );
285 \fn int SALOMEGUI_Swig::SelectedCount()
286 \brief Get number of selected items
287 \return number of selected items in the active study
291 \fn const char* SALOMEGUI_Swig::getSelected( int index )
292 \brief Get entry of the specified selected item
293 \param index selected object index
294 \return selected object entry (null string if index is invalid)
297 class TGetSelectedEvent: public SALOME_Event
300 typedef QStringList TResult;
302 TGetSelectedEvent() {}
303 virtual void Execute()
305 if ( LightApp_Application* anApp = getApplication() ) {
306 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( anApp->activeStudy() ); // for sure!
307 LightApp_SelectionMgr* aSelMgr = anApp->selectionMgr();
308 if ( aStudy && aSelMgr ) {
309 SUIT_DataOwnerPtrList aList;
310 aSelMgr->selected( aList );
312 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin();
313 itr != aList.end(); ++itr ) {
314 const LightApp_DataOwner* owner =
315 dynamic_cast<const LightApp_DataOwner*>( (*itr).operator->() );
318 QString entry = owner->entry();
319 if( !myResult.contains( entry ) )
320 myResult.append( entry );
326 int SALOMEGUI_Swig::SelectedCount()
328 QStringList selected = ProcessEvent( new TGetSelectedEvent() );
329 return selected.count();
331 const char* SALOMEGUI_Swig::getSelected( int index )
333 QStringList selected = ProcessEvent( new TGetSelectedEvent() );
334 return index >= 0 && index < selected.count() ?
335 strdup( selected[ index ].toLatin1().constData() ) : 0;
339 \brief Add an object to the current selection.
340 \param theEntry object entry
342 void SALOMEGUI_Swig::AddIObject( const char* theEntry )
344 class TEvent: public SALOME_Event
348 TEvent( const char* theEntry ) : myEntry( theEntry ) {}
349 virtual void Execute()
351 if ( LightApp_Application* anApp = getApplication() ) {
352 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( anApp->activeStudy() ); // for sure!
353 LightApp_SelectionMgr* aSelMgr = anApp->selectionMgr();
354 if ( aStudy && aSelMgr ) {
355 SALOME_ListIO anIOList;
356 anIOList.Append( new SALOME_InteractiveObject( myEntry.toLatin1(), "", "" ) );
357 aSelMgr->setSelectedObjects( anIOList, true );
362 ProcessVoidEvent( new TEvent( theEntry ) );
366 \brief Remove the object from the selection.
367 \param theEntry object entry
369 void SALOMEGUI_Swig::RemoveIObject( const char* theEntry )
371 class TEvent: public SALOME_Event
375 TEvent( const char* theEntry ) : myEntry( theEntry ) {}
376 virtual void Execute()
378 if ( LightApp_Application* anApp = getApplication() ) {
379 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( anApp->activeStudy() ); // for sure!
380 LightApp_SelectionMgr* aSelMgr = anApp->selectionMgr();
381 if ( aStudy && aSelMgr ) {
382 SALOME_ListIO anIOList;
383 // VSR: temporary solution, until LightApp_SelectionMgr::unsetSelectedObjects() method appears
384 // Lately this should be replaced by the following:
385 // anIOList.Append( new SALOME_InteractiveObject( myEntry, "", "" ) );
386 // aSelMgr->unsetSelectedObjects( anIOList );
387 ///////////////////////////////////////////////
388 aSelMgr->selectedObjects( anIOList );
389 SALOME_ListIteratorOfListIO anIter( anIOList );
390 for( ; anIter.More(); anIter.Next() ) {
391 if ( anIter.Value()->isSame( new SALOME_InteractiveObject( myEntry.toLatin1(), "", "" ) ) ) {
392 anIOList.Remove( anIter );
393 aSelMgr->setSelectedObjects( anIOList, true );
401 ProcessVoidEvent( new TEvent( theEntry ) );
405 \brief Clear selection (unselect all objects).
407 void SALOMEGUI_Swig::ClearIObjects()
409 class TEvent: public SALOME_Event
413 virtual void Execute()
415 if ( LightApp_Application* anApp = getApplication() ) {
416 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( anApp->activeStudy() ); // for sure!
417 LightApp_SelectionMgr* aSelMgr = anApp->selectionMgr();
418 if ( aStudy && aSelMgr )
419 aSelMgr->clearSelected();
423 ProcessVoidEvent( new TEvent() );
427 \brief Display an object in the current view window.
429 The presentable object should be previously created and
430 displayed in this viewer.
432 \param theEntry object entry
434 void SALOMEGUI_Swig::Display( const char* theEntry )
436 class TEvent: public SALOME_Event
440 TEvent( const char* theEntry ) : myEntry( theEntry ) {}
441 virtual void Execute() {
442 LightApp_Application* anApp = getApplication();
443 LightApp_Study* aStudy = getActiveStudy();
444 if ( anApp && aStudy ) {
445 QString mname = anApp->moduleTitle( aStudy->componentDataType( myEntry ) );
446 LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mname, true );
449 if( aStudy->isComponent( myEntry ) )
450 aStudy->children( myEntry, entries );
452 entries.append( myEntry );
453 foreach( QString entry, entries )
454 d->Display( aStudy->referencedToEntry( entry ), false, 0 );
459 ProcessVoidEvent( new TEvent( theEntry ) );
463 \brief Displays an object in the current view window and
464 erases all other ones.
466 The presentable object should be previously created and
467 displayed in this viewer.
469 \param theEntry object entry
471 void SALOMEGUI_Swig::DisplayOnly( const char* theEntry )
473 class TEvent: public SALOME_Event
477 TEvent( const char* theEntry ) : myEntry( theEntry ) {}
478 virtual void Execute()
480 LightApp_Application* anApp = getApplication();
481 LightApp_Study* aStudy = getActiveStudy();
482 if ( anApp && aStudy ) {
484 aStudy->components( comps );
485 foreach( QString comp, comps ) {
486 LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( anApp->moduleTitle( comp ), true );
487 if ( d ) d->EraseAll( false, false, 0 );
490 QString mname = anApp->moduleTitle( aStudy->componentDataType( myEntry ) );
491 LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mname, true );
494 if( aStudy->isComponent( myEntry ) )
495 aStudy->children( myEntry, entries );
497 entries.append( myEntry );
498 foreach( QString entry, entries )
499 d->Display( aStudy->referencedToEntry( entry ), false, 0 );
504 ProcessVoidEvent( new TEvent( theEntry ) );
508 \brief Erase an object in the current view window.
510 The presentable object should be previously created and
511 displayed in this viewer.
513 \param theEntry object entry
515 void SALOMEGUI_Swig::Erase( const char* theEntry )
517 class TEvent: public SALOME_Event
521 TEvent( const char* theEntry ) : myEntry( theEntry ) {}
522 virtual void Execute()
524 LightApp_Application* anApp = getApplication();
525 LightApp_Study* aStudy = getActiveStudy();
526 if ( anApp && aStudy ) {
527 QString mname = anApp->moduleTitle( aStudy->componentDataType( myEntry ) );
528 LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mname, true );
531 if( aStudy->isComponent( myEntry ) )
532 aStudy->children( myEntry, entries );
534 entries.append( myEntry );
535 foreach( QString entry, entries )
536 d->Erase( aStudy->referencedToEntry( entry ), false, false, 0 );
541 ProcessVoidEvent( new TEvent( theEntry ) );
545 \brief Display all active module's presentable
546 child objects in the current view window.
548 The presentable objects should be previously created and
549 displayed in this viewer.
551 void SALOMEGUI_Swig::DisplayAll()
553 class TEvent: public SALOME_Event
557 virtual void Execute()
559 LightApp_Application* anApp = getApplication();
560 LightApp_Study* aStudy = getActiveStudy();
561 if ( anApp && aStudy ) {
563 aStudy->components( comps );
564 foreach( QString comp, comps ) {
565 LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( anApp->moduleTitle( comp ), true );
568 aStudy->children( aStudy->centry( comp ), entries );
569 foreach( QString entry, entries )
570 d->Display( aStudy->referencedToEntry( entry ), false, 0 );
576 ProcessVoidEvent( new TEvent() );
580 \brief Erase all objects from the current view window.
582 void SALOMEGUI_Swig::EraseAll()
584 class TEvent: public SALOME_Event
588 virtual void Execute()
590 LightApp_Application* anApp = getApplication();
591 LightApp_Study* aStudy = getActiveStudy();
592 if ( anApp && aStudy ) {
594 aStudy->components( comps );
595 foreach( QString comp, comps ) {
596 LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( anApp->moduleTitle( comp ), true );
597 if ( d ) d->EraseAll( false, false, 0 );
602 ProcessVoidEvent( new TEvent() );
606 \fn bool SALOMEGUI_Swig::IsInCurrentView( const char* theEntry )
607 \brief Check it the object is displayed in the current view window.
609 VSR: For the current moment implemented for OCC and VTK viewers only.
611 \param theEntry object entry
612 \return \c true if the object with given entry is displayed
613 in the current viewer
616 class TIsInViewerEvent: public SALOME_Event
620 typedef bool TResult;
622 TIsInViewerEvent( const char* theEntry ) : myEntry( theEntry ), myResult( false ) {}
623 virtual void Execute()
625 if ( LightApp_Application* anApp = getApplication() ) {
626 SUIT_ViewWindow* window = anApp->desktop()->activeWindow();
628 SALOME_View* view = dynamic_cast<SALOME_View*>( window->getViewManager()->getActiveView() );
630 SALOME_Prs* aPrs = view->CreatePrs( myEntry.toLatin1() );
631 myResult = !aPrs->IsNull();
637 bool SALOMEGUI_Swig::IsInCurrentView( const char* theEntry )
639 return ProcessEvent( new TIsInViewerEvent( theEntry ) );
643 \brief Update (repaint) current view window.
645 void SALOMEGUI_Swig::UpdateView()
647 class TEvent: public SALOME_Event
651 virtual void Execute()
653 if ( LightApp_Application* anApp = getApplication() ) {
654 SUIT_ViewWindow* window = anApp->desktop()->activeWindow();
656 SALOME_View* view = dynamic_cast<SALOME_View*>( window->getViewManager()->getActiveView() );
663 ProcessVoidEvent( new TEvent() );
667 \brief Fit current view window to display all its contents.
669 void SALOMEGUI_Swig::FitAll()
671 class TEvent: public SALOME_Event
675 virtual void Execute()
677 if ( LightApp_Application* anApp = getApplication() ) {
678 SUIT_ViewWindow* window = anApp->desktop()->activeWindow();
680 #ifndef DISABLE_SALOMEOBJECT
681 #ifndef DISABLE_VTKVIEWER
682 if ( dynamic_cast<SVTK_ViewWindow*>( window ) )
683 ( dynamic_cast<SVTK_ViewWindow*>( window ) )->onFitAll();
685 #ifndef DISABLE_PLOT2DVIEWER
686 if ( dynamic_cast<SPlot2d_ViewWindow*>( window ) )
687 ( dynamic_cast<SPlot2d_ViewWindow*>( window ) )->onFitAll();
690 #ifndef DISABLE_OCCVIEWER
691 if ( dynamic_cast<OCCViewer_ViewWindow*>( window ) )
692 ( dynamic_cast<OCCViewer_ViewWindow*>( window ) )->onFitAll();
698 ProcessVoidEvent( new TEvent() );
702 \brief Reset current view window to the default state.
704 void SALOMEGUI_Swig::ResetView()
706 class TEvent: public SALOME_Event
710 virtual void Execute()
712 if ( LightApp_Application* anApp = getApplication() ) {
713 SUIT_ViewWindow* window = anApp->desktop()->activeWindow();
715 #ifndef DISABLE_SALOMEOBJECT
716 #ifndef DISABLE_VTKVIEWER
717 if ( dynamic_cast<SVTK_ViewWindow*>( window ) )
718 (dynamic_cast<SVTK_ViewWindow*>( window ))->onResetView();
720 #ifndef DISABLE_PLOT2DVIEWER
721 if ( dynamic_cast<SPlot2d_ViewWindow*>( window ) )
722 (dynamic_cast<SPlot2d_ViewWindow*>( window ))->onFitAll();
723 // VSR: there is no 'ResetView' functionality for Plot2d viewer,
724 // so we use 'FitAll' instead.
727 #ifndef DISABLE_OCCVIEWER
728 if ( dynamic_cast<OCCViewer_ViewWindow*>( window ) )
729 (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onResetView();
735 ProcessVoidEvent( new TEvent() );
739 \brief View operation type.
743 __ViewTop, //!< view top side
744 __ViewBottom, //!< view bottom side
745 __ViewLeft, //!< view left side
746 __ViewRight, //!< view right side
747 __ViewFront, //!< view front side
748 __ViewBack //!< view back side
752 \brief Change the view of the current view window.
754 \param view view operation type
756 static void setView( int view )
758 class TEvent: public SALOME_Event
763 TEvent( int view ) : myView( view ) {}
764 virtual void Execute()
766 if ( LightApp_Application* anApp = getApplication() ) {
767 SUIT_ViewWindow* window = anApp->desktop()->activeWindow();
769 #ifndef DISABLE_SALOMEOBJECT
770 #ifndef DISABLE_VTKVIEWER
771 if ( dynamic_cast<SVTK_ViewWindow*>( window ) ) {
774 (dynamic_cast<SVTK_ViewWindow*>( window ))->onTopView(); break;
776 (dynamic_cast<SVTK_ViewWindow*>( window ))->onBottomView(); break;
778 (dynamic_cast<SVTK_ViewWindow*>( window ))->onLeftView(); break;
780 (dynamic_cast<SVTK_ViewWindow*>( window ))->onRightView(); break;
782 (dynamic_cast<SVTK_ViewWindow*>( window ))->onFrontView(); break;
784 (dynamic_cast<SVTK_ViewWindow*>( window ))->onBackView(); break;
791 #ifndef DISABLE_OCCVIEWER
792 if ( dynamic_cast<OCCViewer_ViewWindow*>( window ) ) {
795 (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onTopView(); break;
797 (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onBottomView(); break;
799 (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onLeftView(); break;
801 (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onRightView(); break;
803 (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onFrontView(); break;
805 (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onBackView(); break;
815 ProcessVoidEvent( new TEvent( view ) );
819 \brief Switch current view window to show the top view.
821 void SALOMEGUI_Swig::ViewTop()
823 setView( __ViewTop );
827 \brief Switch current view window to show the bottom view
829 void SALOMEGUI_Swig::ViewBottom()
831 setView( __ViewBottom );
835 \brief Switch current view window to show the left view
837 void SALOMEGUI_Swig::ViewLeft()
839 setView( __ViewLeft );
843 \brief Switch current view window to show the right view
845 void SALOMEGUI_Swig::ViewRight()
847 setView( __ViewRight );
851 \brief Switch current view window to show the front view
853 void SALOMEGUI_Swig::ViewFront()
855 setView( __ViewFront );
859 \brief Switch current view window to show the back view
861 void SALOMEGUI_Swig::ViewBack()
863 setView( __ViewBack );
867 \fn bool SALOMEGUI_Swig::getViewParameters()
868 \brief Get camera parameters of the active view.
870 NOTE: For the current moment implemented for VTK viewer only.
872 \return \c string with the view parameters
875 class TGetViewParameters: public SALOME_Event
878 typedef QString TResult;
880 TGetViewParameters() : myResult( "" ) {}
881 virtual void Execute() {
882 if ( LightApp_Application* anApp = getApplication() ) {
883 if ( SUIT_ViewWindow* window = anApp->desktop()->activeWindow() ) {
884 #ifndef DISABLE_VTKVIEWER
885 if ( SVTK_ViewWindow* svtk = dynamic_cast<SVTK_ViewWindow*>( window ) ) {
886 if ( vtkRenderer* ren = svtk->getRenderer()) {
887 if ( vtkCamera* camera = ren->GetActiveCamera() ) {
888 double pos[3], focalPnt[3], viewUp[3], scale[3], parScale;
890 // save position, focal point, viewUp, scale
891 camera->GetPosition( pos );
892 camera->GetFocalPoint( focalPnt );
893 camera->GetViewUp( viewUp );
894 parScale = camera->GetParallelScale();
895 svtk->GetRenderer()->GetScale( scale );
897 myResult += QString("sg.setCameraPosition( %1, %2, %3 )\n").arg(pos[0]).arg(pos[1]).arg(pos[2]);
898 myResult += QString("sg.setCameraFocalPoint( %1, %2, %3 )\n").arg(focalPnt[0]).arg(focalPnt[1]).arg(focalPnt[2]);
899 myResult += QString("sg.setCameraViewUp( %1, %2, %3 )\n").arg(viewUp[0]).arg(viewUp[1]).arg(viewUp[2]);
900 myResult += QString("sg.setViewScale(%1, %2, %3, %4 )\n").arg(parScale).arg(scale[0]).arg(scale[1]).arg(scale[2]);
910 const char* SALOMEGUI_Swig::getViewParameters() {
911 QString result = ProcessEvent( new TGetViewParameters() );
912 return result.isEmpty() ? 0 : strdup( result.toLatin1().constData() );
917 \brief View parameter type.
921 __CameraPosition, //!< position of the active camera
922 __CameraFocalPoint, //!< focal point of the active camera
923 __CameraViewUp, //!< view up of the active camera
924 __ViewScale //!< scale of the view
929 \brief Change the camera parameters of the current view window.
932 NOTE: For the current moment implemented for VTK viewer only.
934 \param parameter type of the parameter
935 \param values value of the parameter
937 static void setViewParameter( int parameter, QList<double>& values ) {
938 class TEvent: public SALOME_Event {
941 QList<double> myValues;
943 TEvent( int parameter , QList<double>& values ) : myParameter(parameter), myValues( values ) {}
945 virtual void Execute() {
946 if ( LightApp_Application* anApp = getApplication() ) {
947 if ( SUIT_ViewWindow* window = anApp->desktop()->activeWindow() ) {
948 #ifndef DISABLE_VTKVIEWER
949 if ( SVTK_ViewWindow* svtk = dynamic_cast<SVTK_ViewWindow*>( window ) ) {
950 if ( vtkRenderer* ren = svtk->getRenderer()) {
951 if ( vtkCamera* camera = ren->GetActiveCamera() ) {
952 switch(myParameter) {
953 case __CameraPosition : {
954 if ( myValues.size() == 3 ) {
955 camera->SetPosition( myValues[0], myValues[1], myValues[2] );
959 case __CameraFocalPoint : {
960 if ( myValues.size() == 3 ) {
961 camera->SetFocalPoint( myValues[0], myValues[1], myValues[2] );
965 case __CameraViewUp : {
966 if ( myValues.size() == 3 ) {
967 camera->SetViewUp( myValues[0], myValues[1], myValues[2] );
972 if ( myValues.size() == 4 ) {
973 camera->SetParallelScale( myValues[0] );
974 double scale[] = { myValues[1], myValues[2], myValues[3] };
975 svtk->GetRenderer()->SetScale( scale );
990 ProcessVoidEvent( new TEvent( parameter, values ) );
994 \brief Set camera position of the active view .
995 \param x - X coordinate of the camera
996 \param y - Y coordinate of the camera
997 \param z - Z coordinate of the camera
999 void SALOMEGUI_Swig::setCameraPosition( double x, double y, double z ) {
1004 setViewParameter( __CameraPosition, lst );
1008 \brief Set camera focal point of the active view.
1009 \param x - X coordinate of the focal point
1010 \param y - Y coordinate of the focal point
1011 \param z - Z coordinate of the focal point
1013 void SALOMEGUI_Swig::setCameraFocalPoint( double x, double y, double z ) {
1018 setViewParameter( __CameraFocalPoint, lst );
1022 \brief Set the view up direction for the camera.
1023 \param x - X component of the direction vector
1024 \param y - Y component of the direction vector
1025 \param z - Z component of the direction vector
1027 void SALOMEGUI_Swig::setCameraViewUp( double x, double y, double z ) {
1032 setViewParameter( __CameraViewUp, lst );
1036 \brief Set view scale.
1037 \param parallelScale - scaling used for a parallel projection.
1042 void SALOMEGUI_Swig::setViewScale( double parallelScale, double x, double y, double z ) {
1044 lst.push_back( parallelScale );
1048 setViewParameter( __ViewScale, lst );