1 // Copyright (C) 2007-2016 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>
65 #include <utilities.h>
69 \brief Python interface module for SALOME GUI.
71 This module provides an access to the SALOME GUI implementing set of functions
72 which can be used from Python. This module is implemented using SWIG wrappings
73 for some GUI functionality:
74 - getActiveStudyName() : get active study name
75 - updateObjBrowser() : update contents of the Object Browser
76 - SelectedCount() : get number of currently selected items
77 - getSelected() : get entry of the speicified selected item
78 - ClearIObjects() : clear selection
79 - Display(), DisplayOnly(), Erase() : display/erase objects
82 Instance of this class is created every time "import salome" line is typed
83 - in IAPP embedded Python interpretor (SALOME_Session_Server executable)
84 - in inline Python nodes in Supervisor (in SALOME_Container executable)
85 - in stand-alone Python console outside any executable
87 SALOME GUI (desktop and other objects) is only available in SALOME_Session_Server.
88 It means that it can not be accessed from the external Python console.
93 sg = libSALOME_Swig.SALOMEGUI_Swig()
95 selcount = sg.SelectedCount()
97 sg.Erase( sg.getSelected( 0 ) )
103 --- INTERNAL COMMENTS SECTION ---
105 ASV : 03.12.04 : added checking for NULL GUI objects in almost all methods.
106 In the scope of fixing bug PAL6869.
108 VSR : 19.04.05 : Reimplemented for new SALOME GUI (SUIT-based)
109 All methods are implemeted using Event mechanism.
110 Display/Erase methods use SALOME_Prs/SALOME_View mechanism. It is currently
111 implemented only for OCC and VTK viewers.
115 \brief Get active application object
117 \return active application or 0 if there is no any
119 static LightApp_Application* getApplication()
121 if ( SUIT_Session::session() )
122 return dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() );
127 \brief Get active study object
129 \return active study or 0 if there is no study opened
131 static LightApp_Study* getActiveStudy()
133 if ( getApplication() )
134 return dynamic_cast<LightApp_Study*>( getApplication()->activeStudy() );
141 SALOMEGUI_Swig::SALOMEGUI_Swig()
148 SALOMEGUI_Swig::~SALOMEGUI_Swig()
153 \fn bool SALOMEGUI_Swig::hasDesktop()
154 \brief Check GUI availability.
155 \return \c true if GUI is available
158 class THasDesktopEvent: public SALOME_Event
161 typedef bool TResult;
163 THasDesktopEvent() : myResult( false ) {}
164 virtual void Execute()
166 myResult = (bool)( getApplication() && getApplication()->desktop() );
169 bool SALOMEGUI_Swig::hasDesktop()
171 return ProcessEvent( new THasDesktopEvent() );
175 \brief Update active study's Object Browser.
177 void SALOMEGUI_Swig::updateObjBrowser()
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 const char* SALOMEGUI_Swig::getActiveStudyName()
196 \brief Get active study name
197 \return active study's name or null string if there is no active study
200 class TGetActiveStudyNameEvent: public SALOME_Event
203 typedef std::string TResult;
205 TGetActiveStudyNameEvent() {}
206 virtual void Execute()
208 if ( LightApp_Study* aStudy = getActiveStudy() ) {
209 myResult = aStudy->studyName().toUtf8().constData();
213 const char* SALOMEGUI_Swig::getActiveStudyName()
215 std::string result = ProcessEvent( new TGetActiveStudyNameEvent() );
216 return result.empty() ? 0 : result.c_str();
220 \fn const char* SALOMEGUI_Swig::getComponentName( const char* componentUserName )
221 \brief Get name of the component by its title (user name)
222 \param componentUserName component title (user name)
223 \return component name or null string if component title is invalid
227 \fn const char* SALOMEGUI_Swig::getComponentUserName( const char* componentName )
228 \brief Get title (user name) of the component by its name
229 \param componentName component name
230 \return component title or null string if component name is invalid
233 class TGetComponentNameEvent: public SALOME_Event
236 typedef QString TResult;
240 TGetComponentNameEvent( const QString& name, bool isUserName )
241 : myName( name ), myIsUserName( isUserName ) {}
242 virtual void Execute()
244 if ( LightApp_Application* app = getApplication() ) {
245 myResult = myIsUserName ? app->moduleTitle( myName ) : app->moduleName( myName );
249 const char* SALOMEGUI_Swig::getComponentName( const char* componentUserName )
251 QString result = ProcessEvent( new TGetComponentNameEvent( componentUserName, false ) );
252 return result.isEmpty() ? 0 : strdup( result.toLatin1().constData() );
254 const char* SALOMEGUI_Swig::getComponentUserName( const char* componentName )
256 QString result = ProcessEvent( new TGetComponentNameEvent( componentName, true ) );
257 return result.isEmpty() ? 0 : strdup( result.toLatin1().constData() );
261 \fn int SALOMEGUI_Swig::SelectedCount()
262 \brief Get number of selected items
263 \return number of selected items in the active study
267 \fn const char* SALOMEGUI_Swig::getSelected( int index )
268 \brief Get entry of the specified selected item
269 \param index selected object index
270 \return selected object entry (null string if index is invalid)
273 class TGetSelectedEvent: public SALOME_Event
276 typedef QStringList TResult;
278 TGetSelectedEvent() {}
279 virtual void Execute()
281 if ( LightApp_Application* anApp = getApplication() ) {
282 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( anApp->activeStudy() ); // for sure!
283 LightApp_SelectionMgr* aSelMgr = anApp->selectionMgr();
284 if ( aStudy && aSelMgr ) {
285 SUIT_DataOwnerPtrList aList;
286 aSelMgr->selected( aList );
288 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin();
289 itr != aList.end(); ++itr ) {
290 const LightApp_DataOwner* owner =
291 dynamic_cast<const LightApp_DataOwner*>( (*itr).operator->() );
294 QString entry = owner->entry();
295 if( !myResult.contains( entry ) )
296 myResult.append( entry );
302 int SALOMEGUI_Swig::SelectedCount()
304 QStringList selected = ProcessEvent( new TGetSelectedEvent() );
305 return selected.count();
307 const char* SALOMEGUI_Swig::getSelected( int index )
309 QStringList selected = ProcessEvent( new TGetSelectedEvent() );
310 return index >= 0 && index < selected.count() ?
311 strdup( selected[ index ].toLatin1().constData() ) : 0;
315 \brief Add an object to the current selection.
316 \param theEntry object entry
318 void SALOMEGUI_Swig::AddIObject( const char* theEntry )
320 class TEvent: public SALOME_Event
324 TEvent( const char* theEntry ) : myEntry( theEntry ) {}
325 virtual void Execute()
327 if ( LightApp_Application* anApp = getApplication() ) {
328 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( anApp->activeStudy() ); // for sure!
329 LightApp_SelectionMgr* aSelMgr = anApp->selectionMgr();
330 if ( aStudy && aSelMgr ) {
331 SALOME_ListIO anIOList;
332 anIOList.Append( new SALOME_InteractiveObject( myEntry.toLatin1(), "", "" ) );
333 aSelMgr->setSelectedObjects( anIOList, true );
338 ProcessVoidEvent( new TEvent( theEntry ) );
342 \brief Remove the object from the selection.
343 \param theEntry object entry
345 void SALOMEGUI_Swig::RemoveIObject( const char* theEntry )
347 class TEvent: public SALOME_Event
351 TEvent( const char* theEntry ) : myEntry( theEntry ) {}
352 virtual void Execute()
354 if ( LightApp_Application* anApp = getApplication() ) {
355 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( anApp->activeStudy() ); // for sure!
356 LightApp_SelectionMgr* aSelMgr = anApp->selectionMgr();
357 if ( aStudy && aSelMgr ) {
358 SALOME_ListIO anIOList;
359 // VSR: temporary solution, until LightApp_SelectionMgr::unsetSelectedObjects() method appears
360 // Lately this should be replaced by the following:
361 // anIOList.Append( new SALOME_InteractiveObject( myEntry, "", "" ) );
362 // aSelMgr->unsetSelectedObjects( anIOList );
363 ///////////////////////////////////////////////
364 aSelMgr->selectedObjects( anIOList );
365 SALOME_ListIteratorOfListIO anIter( anIOList );
366 for( ; anIter.More(); anIter.Next() ) {
367 if ( anIter.Value()->isSame( new SALOME_InteractiveObject( myEntry.toLatin1(), "", "" ) ) ) {
368 anIOList.Remove( anIter );
369 aSelMgr->setSelectedObjects( anIOList, true );
377 ProcessVoidEvent( new TEvent( theEntry ) );
381 \brief Clear selection (unselect all objects).
383 void SALOMEGUI_Swig::ClearIObjects()
385 class TEvent: public SALOME_Event
389 virtual void Execute()
391 if ( LightApp_Application* anApp = getApplication() ) {
392 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( anApp->activeStudy() ); // for sure!
393 LightApp_SelectionMgr* aSelMgr = anApp->selectionMgr();
394 if ( aStudy && aSelMgr )
395 aSelMgr->clearSelected();
399 ProcessVoidEvent( new TEvent() );
403 \brief Display an object in the current view window.
405 The presentable object should be previously created and
406 displayed in this viewer.
408 \param theEntry object entry
410 void SALOMEGUI_Swig::Display( const char* theEntry )
412 class TEvent: public SALOME_Event
416 TEvent( const char* theEntry ) : myEntry( theEntry ) {}
417 virtual void Execute() {
418 LightApp_Application* anApp = getApplication();
419 LightApp_Study* aStudy = getActiveStudy();
420 if ( anApp && aStudy ) {
421 QString mname = anApp->moduleTitle( aStudy->componentDataType( myEntry ) );
422 LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mname, true );
425 if( aStudy->isComponent( myEntry ) )
426 aStudy->children( myEntry, entries );
428 entries.append( myEntry );
429 foreach( QString entry, entries )
430 d->Display( aStudy->referencedToEntry( entry ), false, 0 );
435 ProcessVoidEvent( new TEvent( theEntry ) );
439 \brief Displays an object in the current view window and
440 erases all other ones.
442 The presentable object should be previously created and
443 displayed in this viewer.
445 \param theEntry object entry
447 void SALOMEGUI_Swig::DisplayOnly( const char* theEntry )
449 class TEvent: public SALOME_Event
453 TEvent( const char* theEntry ) : myEntry( theEntry ) {}
454 virtual void Execute()
456 LightApp_Application* anApp = getApplication();
457 LightApp_Study* aStudy = getActiveStudy();
458 if ( anApp && aStudy ) {
460 aStudy->components( comps );
461 foreach( QString comp, comps ) {
462 LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( anApp->moduleTitle( comp ), false );
463 if ( d ) d->EraseAll( false, false, 0 );
466 QString mname = anApp->moduleTitle( aStudy->componentDataType( myEntry ) );
467 LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mname, true );
470 if( aStudy->isComponent( myEntry ) )
471 aStudy->children( myEntry, entries );
473 entries.append( myEntry );
474 foreach( QString entry, entries )
475 d->Display( aStudy->referencedToEntry( entry ), false, 0 );
480 ProcessVoidEvent( new TEvent( theEntry ) );
484 \brief Erase an object in the current view window.
486 The presentable object should be previously created and
487 displayed in this viewer.
489 \param theEntry object entry
491 void SALOMEGUI_Swig::Erase( const char* theEntry )
493 class TEvent: public SALOME_Event
497 TEvent( const char* theEntry ) : myEntry( theEntry ) {}
498 virtual void Execute()
500 LightApp_Application* anApp = getApplication();
501 LightApp_Study* aStudy = getActiveStudy();
502 if ( anApp && aStudy ) {
503 QString mname = anApp->moduleTitle( aStudy->componentDataType( myEntry ) );
504 LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mname, true );
507 if( aStudy->isComponent( myEntry ) )
508 aStudy->children( myEntry, entries );
510 entries.append( myEntry );
511 foreach( QString entry, entries )
512 d->Erase( aStudy->referencedToEntry( entry ), false, false, 0 );
517 ProcessVoidEvent( new TEvent( theEntry ) );
521 \brief Display all active module's presentable
522 child objects in the current view window.
524 The presentable objects should be previously created and
525 displayed in this viewer.
527 void SALOMEGUI_Swig::DisplayAll()
529 class TEvent: public SALOME_Event
533 virtual void Execute()
535 LightApp_Application* anApp = getApplication();
536 LightApp_Study* aStudy = getActiveStudy();
537 if ( anApp && aStudy ) {
539 aStudy->components( comps );
540 foreach( QString comp, comps ) {
541 LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( anApp->moduleTitle( comp ), true );
544 aStudy->children( aStudy->centry( comp ), entries );
545 foreach( QString entry, entries )
546 d->Display( aStudy->referencedToEntry( entry ), false, 0 );
552 ProcessVoidEvent( new TEvent() );
556 \brief Erase all objects from the current view window.
558 void SALOMEGUI_Swig::EraseAll()
560 class TEvent: public SALOME_Event
564 virtual void Execute()
566 LightApp_Application* anApp = getApplication();
567 LightApp_Study* aStudy = getActiveStudy();
568 if ( anApp && aStudy ) {
570 aStudy->components( comps );
571 foreach( QString comp, comps ) {
572 LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( anApp->moduleTitle( comp ), false );
573 if ( d ) d->EraseAll( false, false, 0 );
578 ProcessVoidEvent( new TEvent() );
582 \fn bool SALOMEGUI_Swig::IsInCurrentView( const char* theEntry )
583 \brief Check it the object is displayed in the current view window.
585 VSR: For the current moment implemented for OCC and VTK viewers only.
587 \param theEntry object entry
588 \return \c true if the object with given entry is displayed
589 in the current viewer
592 class TIsInViewerEvent: public SALOME_Event
596 typedef bool TResult;
598 TIsInViewerEvent( const char* theEntry ) : myEntry( theEntry ), myResult( false ) {}
599 virtual void Execute()
601 if ( LightApp_Application* anApp = getApplication() ) {
602 SUIT_ViewManager* viewMgr = anApp->activeViewManager();
603 if (!viewMgr) return;
604 SUIT_ViewWindow* window = viewMgr->getActiveView();
606 SALOME_View* view = dynamic_cast<SALOME_View*>( window->getViewManager()->getViewModel() );
608 SALOME_Prs* aPrs = view->CreatePrs( myEntry.toLatin1() );
609 myResult = !aPrs->IsNull();
615 bool SALOMEGUI_Swig::IsInCurrentView( const char* theEntry )
617 return ProcessEvent( new TIsInViewerEvent( theEntry ) );
621 \brief Update (repaint) current view window.
623 void SALOMEGUI_Swig::UpdateView()
625 class TEvent: public SALOME_Event
629 virtual void Execute()
631 if ( LightApp_Application* anApp = getApplication() ) {
632 SUIT_ViewManager* viewMgr = anApp->activeViewManager();
633 if (!viewMgr) return;
634 SUIT_ViewWindow* window = viewMgr->getActiveView();
636 SALOME_View* view = dynamic_cast<SALOME_View*>( window->getViewManager()->getViewModel() );
643 ProcessVoidEvent( new TEvent() );
647 \brief Fit current view window to display all its contents.
649 void SALOMEGUI_Swig::FitAll()
652 class TEvent: public SALOME_Event
656 virtual void Execute()
658 if ( LightApp_Application* anApp = getApplication() ) {
659 SUIT_ViewManager* viewMgr = anApp->activeViewManager();
660 if (!viewMgr) return;
661 SUIT_ViewWindow* window = viewMgr->getActiveView();
663 #ifndef DISABLE_SALOMEOBJECT
664 #ifndef DISABLE_VTKVIEWER
665 if ( dynamic_cast<SVTK_ViewWindow*>( window ) )
666 ( dynamic_cast<SVTK_ViewWindow*>( window ) )->onFitAll();
668 #ifndef DISABLE_PLOT2DVIEWER
669 if ( dynamic_cast<SPlot2d_ViewWindow*>( window ) )
670 ( dynamic_cast<SPlot2d_ViewWindow*>( window ) )->onFitAll();
673 #ifndef DISABLE_OCCVIEWER
674 if ( dynamic_cast<OCCViewer_ViewWindow*>( window ) )
675 ( dynamic_cast<OCCViewer_ViewWindow*>( window ) )->onFitAll();
681 ProcessVoidEvent( new TEvent() );
685 \brief Reset current view window to the default state.
687 void SALOMEGUI_Swig::ResetView()
689 class TEvent: public SALOME_Event
693 virtual void Execute()
695 if ( LightApp_Application* anApp = getApplication() ) {
696 SUIT_ViewManager* viewMgr = anApp->activeViewManager();
697 if (!viewMgr) return;
698 SUIT_ViewWindow* window = viewMgr->getActiveView();
700 #ifndef DISABLE_SALOMEOBJECT
701 #ifndef DISABLE_VTKVIEWER
702 if ( dynamic_cast<SVTK_ViewWindow*>( window ) )
703 (dynamic_cast<SVTK_ViewWindow*>( window ))->onResetView();
705 #ifndef DISABLE_PLOT2DVIEWER
706 if ( dynamic_cast<SPlot2d_ViewWindow*>( window ) )
707 (dynamic_cast<SPlot2d_ViewWindow*>( window ))->onFitAll();
708 // VSR: there is no 'ResetView' functionality for Plot2d viewer,
709 // so we use 'FitAll' instead.
712 #ifndef DISABLE_OCCVIEWER
713 if ( dynamic_cast<OCCViewer_ViewWindow*>( window ) )
714 (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onResetView();
720 ProcessVoidEvent( new TEvent() );
724 \brief View operation type.
728 __ViewTop, //!< view top side
729 __ViewBottom, //!< view bottom side
730 __ViewLeft, //!< view left side
731 __ViewRight, //!< view right side
732 __ViewFront, //!< view front side
733 __ViewBack //!< view back side
737 \brief Change the view of the current view window.
739 \param view view operation type
741 static void setView( int view )
743 class TEvent: public SALOME_Event
748 TEvent( int view ) : myView( view ) {}
749 virtual void Execute()
751 if ( LightApp_Application* anApp = getApplication() ) {
752 SUIT_ViewManager* viewMgr = anApp->activeViewManager();
753 if (!viewMgr) return;
754 SUIT_ViewWindow* window = viewMgr->getActiveView();
756 #ifndef DISABLE_SALOMEOBJECT
757 #ifndef DISABLE_VTKVIEWER
758 if ( dynamic_cast<SVTK_ViewWindow*>( window ) ) {
761 (dynamic_cast<SVTK_ViewWindow*>( window ))->onTopView(); break;
763 (dynamic_cast<SVTK_ViewWindow*>( window ))->onBottomView(); break;
765 (dynamic_cast<SVTK_ViewWindow*>( window ))->onLeftView(); break;
767 (dynamic_cast<SVTK_ViewWindow*>( window ))->onRightView(); break;
769 (dynamic_cast<SVTK_ViewWindow*>( window ))->onFrontView(); break;
771 (dynamic_cast<SVTK_ViewWindow*>( window ))->onBackView(); break;
778 #ifndef DISABLE_OCCVIEWER
779 if ( dynamic_cast<OCCViewer_ViewWindow*>( window ) ) {
782 (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onTopView(); break;
784 (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onBottomView(); break;
786 (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onLeftView(); break;
788 (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onRightView(); break;
790 (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onFrontView(); break;
792 (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onBackView(); break;
802 ProcessVoidEvent( new TEvent( view ) );
806 \brief Switch current view window to show the top view.
808 void SALOMEGUI_Swig::ViewTop()
810 setView( __ViewTop );
814 \brief Switch current view window to show the bottom view
816 void SALOMEGUI_Swig::ViewBottom()
818 setView( __ViewBottom );
822 \brief Switch current view window to show the left view
824 void SALOMEGUI_Swig::ViewLeft()
826 setView( __ViewLeft );
830 \brief Switch current view window to show the right view
832 void SALOMEGUI_Swig::ViewRight()
834 setView( __ViewRight );
838 \brief Switch current view window to show the front view
840 void SALOMEGUI_Swig::ViewFront()
842 setView( __ViewFront );
846 \brief Switch current view window to show the back view
848 void SALOMEGUI_Swig::ViewBack()
850 setView( __ViewBack );
854 \fn bool SALOMEGUI_Swig::getViewParameters()
855 \brief Get camera parameters of the active view.
857 NOTE: For the current moment implemented for VTK viewer only.
859 \return \c string with the view parameters
862 class TGetViewParameters: public SALOME_Event
865 typedef QString TResult;
867 TGetViewParameters() : myResult( "" ) {}
868 virtual void Execute() {
869 if ( LightApp_Application* anApp = getApplication() ) {
870 SUIT_ViewManager* viewMgr = anApp->activeViewManager();
871 if (!viewMgr) return;
872 if ( SUIT_ViewWindow* window = viewMgr->getActiveView() ) {
873 #ifndef DISABLE_VTKVIEWER
874 if ( SVTK_ViewWindow* svtk = dynamic_cast<SVTK_ViewWindow*>( window ) ) {
875 if ( vtkRenderer* ren = svtk->getRenderer()) {
876 if ( vtkCamera* camera = ren->GetActiveCamera() ) {
877 double pos[3], focalPnt[3], viewUp[3], scale[3], parScale;
879 // save position, focal point, viewUp, scale
880 camera->GetPosition( pos );
881 camera->GetFocalPoint( focalPnt );
882 camera->GetViewUp( viewUp );
883 parScale = camera->GetParallelScale();
884 svtk->GetRenderer()->GetScale( scale );
886 myResult += QString("sg.setCameraPosition( %1, %2, %3 )\n").arg(pos[0]).arg(pos[1]).arg(pos[2]);
887 myResult += QString("sg.setCameraFocalPoint( %1, %2, %3 )\n").arg(focalPnt[0]).arg(focalPnt[1]).arg(focalPnt[2]);
888 myResult += QString("sg.setCameraViewUp( %1, %2, %3 )\n").arg(viewUp[0]).arg(viewUp[1]).arg(viewUp[2]);
889 myResult += QString("sg.setViewScale(%1, %2, %3, %4 )\n").arg(parScale).arg(scale[0]).arg(scale[1]).arg(scale[2]);
899 const char* SALOMEGUI_Swig::getViewParameters() {
900 QString result = ProcessEvent( new TGetViewParameters() );
901 return result.isEmpty() ? 0 : strdup( result.toLatin1().constData() );
906 \brief View parameter type.
910 __CameraPosition, //!< position of the active camera
911 __CameraFocalPoint, //!< focal point of the active camera
912 __CameraViewUp, //!< view up of the active camera
913 __ViewScale //!< scale of the view
918 \brief Change the camera parameters of the current view window.
921 NOTE: For the current moment implemented for VTK viewer only.
923 \param parameter type of the parameter
924 \param values value of the parameter
926 static void setViewParameter( int parameter, QList<double>& values ) {
927 class TEvent: public SALOME_Event {
930 QList<double> myValues;
932 TEvent( int parameter , QList<double>& values ) : myParameter(parameter), myValues( values ) {}
934 virtual void Execute() {
935 if ( LightApp_Application* anApp = getApplication() ) {
936 SUIT_ViewManager* viewMgr = anApp->activeViewManager();
937 if (!viewMgr) return;
938 if ( SUIT_ViewWindow* window = viewMgr->getActiveView() ) {
939 #ifndef DISABLE_VTKVIEWER
940 if ( SVTK_ViewWindow* svtk = dynamic_cast<SVTK_ViewWindow*>( window ) ) {
941 if ( vtkRenderer* ren = svtk->getRenderer()) {
942 if ( vtkCamera* camera = ren->GetActiveCamera() ) {
943 switch(myParameter) {
944 case __CameraPosition : {
945 if ( myValues.size() == 3 ) {
946 camera->SetPosition( myValues[0], myValues[1], myValues[2] );
950 case __CameraFocalPoint : {
951 if ( myValues.size() == 3 ) {
952 camera->SetFocalPoint( myValues[0], myValues[1], myValues[2] );
956 case __CameraViewUp : {
957 if ( myValues.size() == 3 ) {
958 camera->SetViewUp( myValues[0], myValues[1], myValues[2] );
963 if ( myValues.size() == 4 ) {
964 camera->SetParallelScale( myValues[0] );
965 double scale[] = { myValues[1], myValues[2], myValues[3] };
966 svtk->GetRenderer()->SetScale( scale );
981 ProcessVoidEvent( new TEvent( parameter, values ) );
985 \brief Set camera position of the active view .
986 \param x - X coordinate of the camera
987 \param y - Y coordinate of the camera
988 \param z - Z coordinate of the camera
990 void SALOMEGUI_Swig::setCameraPosition( double x, double y, double z ) {
995 setViewParameter( __CameraPosition, lst );
999 \brief Set camera focal point of the active view.
1000 \param x - X coordinate of the focal point
1001 \param y - Y coordinate of the focal point
1002 \param z - Z coordinate of the focal point
1004 void SALOMEGUI_Swig::setCameraFocalPoint( double x, double y, double z ) {
1009 setViewParameter( __CameraFocalPoint, lst );
1013 \brief Set the view up direction for the camera.
1014 \param x - X component of the direction vector
1015 \param y - Y component of the direction vector
1016 \param z - Z component of the direction vector
1018 void SALOMEGUI_Swig::setCameraViewUp( double x, double y, double z ) {
1023 setViewParameter( __CameraViewUp, lst );
1027 \brief Set view scale.
1028 \param parallelScale - scaling used for a parallel projection.
1033 void SALOMEGUI_Swig::setViewScale( double parallelScale, double x, double y, double z ) {
1035 lst.push_back( parallelScale );
1039 setViewParameter( __ViewScale, lst );