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 - getActiveStudyId(), getActiveStudyName() : get active study identifier and 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.
176 \param updateSelection this parameter is obsolete
178 void SALOMEGUI_Swig::updateObjBrowser( bool /*updateSelection*/ )
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 int SALOMEGUI_Swig::getActiveStudyId()
197 \brief Get active study identifier
198 \return active study's ID or 0 if there is no active study
201 class TGetActiveStudyIdEvent: public SALOME_Event
206 TGetActiveStudyIdEvent() : myResult( 0 ) {}
207 virtual void Execute()
209 if ( LightApp_Study* aStudy = getActiveStudy() ) {
210 myResult = aStudy->id();
214 int SALOMEGUI_Swig::getActiveStudyId()
216 return ProcessEvent( new TGetActiveStudyIdEvent() );
220 \fn const char* SALOMEGUI_Swig::getActiveStudyName()
221 \brief Get active study name
222 \return active study's name or null string if there is no active study
225 class TGetActiveStudyNameEvent: public SALOME_Event
228 typedef std::string TResult;
230 TGetActiveStudyNameEvent() {}
231 virtual void Execute()
233 if ( LightApp_Study* aStudy = getActiveStudy() ) {
234 myResult = aStudy->studyName().toUtf8().constData();
238 const char* SALOMEGUI_Swig::getActiveStudyName()
240 std::string result = ProcessEvent( new TGetActiveStudyNameEvent() );
241 return result.empty() ? 0 : result.c_str();
245 \fn const char* SALOMEGUI_Swig::getComponentName( const char* componentUserName )
246 \brief Get name of the component by its title (user name)
247 \param componentUserName component title (user name)
248 \return component name or null string if component title is invalid
252 \fn const char* SALOMEGUI_Swig::getComponentUserName( const char* componentName )
253 \brief Get title (user name) of the component by its name
254 \param componentName component name
255 \return component title or null string if component name is invalid
258 class TGetComponentNameEvent: public SALOME_Event
261 typedef QString TResult;
265 TGetComponentNameEvent( const QString& name, bool isUserName )
266 : myName( name ), myIsUserName( isUserName ) {}
267 virtual void Execute()
269 if ( LightApp_Application* app = getApplication() ) {
270 myResult = myIsUserName ? app->moduleTitle( myName ) : app->moduleName( myName );
274 const char* SALOMEGUI_Swig::getComponentName( const char* componentUserName )
276 QString result = ProcessEvent( new TGetComponentNameEvent( componentUserName, false ) );
277 return result.isEmpty() ? 0 : strdup( result.toLatin1().constData() );
279 const char* SALOMEGUI_Swig::getComponentUserName( const char* componentName )
281 QString result = ProcessEvent( new TGetComponentNameEvent( componentName, true ) );
282 return result.isEmpty() ? 0 : strdup( result.toLatin1().constData() );
286 \fn int SALOMEGUI_Swig::SelectedCount()
287 \brief Get number of selected items
288 \return number of selected items in the active study
292 \fn const char* SALOMEGUI_Swig::getSelected( int index )
293 \brief Get entry of the specified selected item
294 \param index selected object index
295 \return selected object entry (null string if index is invalid)
298 class TGetSelectedEvent: public SALOME_Event
301 typedef QStringList TResult;
303 TGetSelectedEvent() {}
304 virtual void Execute()
306 if ( LightApp_Application* anApp = getApplication() ) {
307 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( anApp->activeStudy() ); // for sure!
308 LightApp_SelectionMgr* aSelMgr = anApp->selectionMgr();
309 if ( aStudy && aSelMgr ) {
310 SUIT_DataOwnerPtrList aList;
311 aSelMgr->selected( aList );
313 for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin();
314 itr != aList.end(); ++itr ) {
315 const LightApp_DataOwner* owner =
316 dynamic_cast<const LightApp_DataOwner*>( (*itr).operator->() );
319 QString entry = owner->entry();
320 if( !myResult.contains( entry ) )
321 myResult.append( entry );
327 int SALOMEGUI_Swig::SelectedCount()
329 QStringList selected = ProcessEvent( new TGetSelectedEvent() );
330 return selected.count();
332 const char* SALOMEGUI_Swig::getSelected( int index )
334 QStringList selected = ProcessEvent( new TGetSelectedEvent() );
335 return index >= 0 && index < selected.count() ?
336 strdup( selected[ index ].toLatin1().constData() ) : 0;
340 \brief Add an object to the current selection.
341 \param theEntry object entry
343 void SALOMEGUI_Swig::AddIObject( const char* theEntry )
345 class TEvent: public SALOME_Event
349 TEvent( const char* theEntry ) : myEntry( theEntry ) {}
350 virtual void Execute()
352 if ( LightApp_Application* anApp = getApplication() ) {
353 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( anApp->activeStudy() ); // for sure!
354 LightApp_SelectionMgr* aSelMgr = anApp->selectionMgr();
355 if ( aStudy && aSelMgr ) {
356 SALOME_ListIO anIOList;
357 anIOList.Append( new SALOME_InteractiveObject( myEntry.toLatin1(), "", "" ) );
358 aSelMgr->setSelectedObjects( anIOList, true );
363 ProcessVoidEvent( new TEvent( theEntry ) );
367 \brief Remove the object from the selection.
368 \param theEntry object entry
370 void SALOMEGUI_Swig::RemoveIObject( const char* theEntry )
372 class TEvent: public SALOME_Event
376 TEvent( const char* theEntry ) : myEntry( theEntry ) {}
377 virtual void Execute()
379 if ( LightApp_Application* anApp = getApplication() ) {
380 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( anApp->activeStudy() ); // for sure!
381 LightApp_SelectionMgr* aSelMgr = anApp->selectionMgr();
382 if ( aStudy && aSelMgr ) {
383 SALOME_ListIO anIOList;
384 // VSR: temporary solution, until LightApp_SelectionMgr::unsetSelectedObjects() method appears
385 // Lately this should be replaced by the following:
386 // anIOList.Append( new SALOME_InteractiveObject( myEntry, "", "" ) );
387 // aSelMgr->unsetSelectedObjects( anIOList );
388 ///////////////////////////////////////////////
389 aSelMgr->selectedObjects( anIOList );
390 SALOME_ListIteratorOfListIO anIter( anIOList );
391 for( ; anIter.More(); anIter.Next() ) {
392 if ( anIter.Value()->isSame( new SALOME_InteractiveObject( myEntry.toLatin1(), "", "" ) ) ) {
393 anIOList.Remove( anIter );
394 aSelMgr->setSelectedObjects( anIOList, true );
402 ProcessVoidEvent( new TEvent( theEntry ) );
406 \brief Clear selection (unselect all objects).
408 void SALOMEGUI_Swig::ClearIObjects()
410 class TEvent: public SALOME_Event
414 virtual void Execute()
416 if ( LightApp_Application* anApp = getApplication() ) {
417 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( anApp->activeStudy() ); // for sure!
418 LightApp_SelectionMgr* aSelMgr = anApp->selectionMgr();
419 if ( aStudy && aSelMgr )
420 aSelMgr->clearSelected();
424 ProcessVoidEvent( new TEvent() );
428 \brief Display an object in the current view window.
430 The presentable object should be previously created and
431 displayed in this viewer.
433 \param theEntry object entry
435 void SALOMEGUI_Swig::Display( const char* theEntry )
437 class TEvent: public SALOME_Event
441 TEvent( const char* theEntry ) : myEntry( theEntry ) {}
442 virtual void Execute() {
443 LightApp_Application* anApp = getApplication();
444 LightApp_Study* aStudy = getActiveStudy();
445 if ( anApp && aStudy ) {
446 QString mname = anApp->moduleTitle( aStudy->componentDataType( myEntry ) );
447 LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mname, true );
450 if( aStudy->isComponent( myEntry ) )
451 aStudy->children( myEntry, entries );
453 entries.append( myEntry );
454 foreach( QString entry, entries )
455 d->Display( aStudy->referencedToEntry( entry ), false, 0 );
460 ProcessVoidEvent( new TEvent( theEntry ) );
464 \brief Displays an object in the current view window and
465 erases all other ones.
467 The presentable object should be previously created and
468 displayed in this viewer.
470 \param theEntry object entry
472 void SALOMEGUI_Swig::DisplayOnly( const char* theEntry )
474 class TEvent: public SALOME_Event
478 TEvent( const char* theEntry ) : myEntry( theEntry ) {}
479 virtual void Execute()
481 LightApp_Application* anApp = getApplication();
482 LightApp_Study* aStudy = getActiveStudy();
483 if ( anApp && aStudy ) {
485 aStudy->components( comps );
486 foreach( QString comp, comps ) {
487 LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( anApp->moduleTitle( comp ), true );
488 if ( d ) d->EraseAll( false, false, 0 );
491 QString mname = anApp->moduleTitle( aStudy->componentDataType( myEntry ) );
492 LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mname, true );
495 if( aStudy->isComponent( myEntry ) )
496 aStudy->children( myEntry, entries );
498 entries.append( myEntry );
499 foreach( QString entry, entries )
500 d->Display( aStudy->referencedToEntry( entry ), false, 0 );
505 ProcessVoidEvent( new TEvent( theEntry ) );
509 \brief Erase an object in the current view window.
511 The presentable object should be previously created and
512 displayed in this viewer.
514 \param theEntry object entry
516 void SALOMEGUI_Swig::Erase( const char* theEntry )
518 class TEvent: public SALOME_Event
522 TEvent( const char* theEntry ) : myEntry( theEntry ) {}
523 virtual void Execute()
525 LightApp_Application* anApp = getApplication();
526 LightApp_Study* aStudy = getActiveStudy();
527 if ( anApp && aStudy ) {
528 QString mname = anApp->moduleTitle( aStudy->componentDataType( myEntry ) );
529 LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mname, true );
532 if( aStudy->isComponent( myEntry ) )
533 aStudy->children( myEntry, entries );
535 entries.append( myEntry );
536 foreach( QString entry, entries )
537 d->Erase( aStudy->referencedToEntry( entry ), false, false, 0 );
542 ProcessVoidEvent( new TEvent( theEntry ) );
546 \brief Display all active module's presentable
547 child objects in the current view window.
549 The presentable objects should be previously created and
550 displayed in this viewer.
552 void SALOMEGUI_Swig::DisplayAll()
554 class TEvent: public SALOME_Event
558 virtual void Execute()
560 LightApp_Application* anApp = getApplication();
561 LightApp_Study* aStudy = getActiveStudy();
562 if ( anApp && aStudy ) {
564 aStudy->components( comps );
565 foreach( QString comp, comps ) {
566 LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( anApp->moduleTitle( comp ), true );
569 aStudy->children( aStudy->centry( comp ), entries );
570 foreach( QString entry, entries )
571 d->Display( aStudy->referencedToEntry( entry ), false, 0 );
577 ProcessVoidEvent( new TEvent() );
581 \brief Erase all objects from the current view window.
583 void SALOMEGUI_Swig::EraseAll()
585 class TEvent: public SALOME_Event
589 virtual void Execute()
591 LightApp_Application* anApp = getApplication();
592 LightApp_Study* aStudy = getActiveStudy();
593 if ( anApp && aStudy ) {
595 aStudy->components( comps );
596 foreach( QString comp, comps ) {
597 LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( anApp->moduleTitle( comp ), true );
598 if ( d ) d->EraseAll( false, false, 0 );
603 ProcessVoidEvent( new TEvent() );
607 \fn bool SALOMEGUI_Swig::IsInCurrentView( const char* theEntry )
608 \brief Check it the object is displayed in the current view window.
610 VSR: For the current moment implemented for OCC and VTK viewers only.
612 \param theEntry object entry
613 \return \c true if the object with given entry is displayed
614 in the current viewer
617 class TIsInViewerEvent: public SALOME_Event
621 typedef bool TResult;
623 TIsInViewerEvent( const char* theEntry ) : myEntry( theEntry ), myResult( false ) {}
624 virtual void Execute()
626 if ( LightApp_Application* anApp = getApplication() ) {
627 SUIT_ViewManager* viewMgr = anApp->activeViewManager();
628 if (!viewMgr) return;
629 SUIT_ViewWindow* window = viewMgr->getActiveView();
631 SALOME_View* view = dynamic_cast<SALOME_View*>( window->getViewManager()->getActiveView() );
633 SALOME_Prs* aPrs = view->CreatePrs( myEntry.toLatin1() );
634 myResult = !aPrs->IsNull();
640 bool SALOMEGUI_Swig::IsInCurrentView( const char* theEntry )
642 return ProcessEvent( new TIsInViewerEvent( theEntry ) );
646 \brief Update (repaint) current view window.
648 void SALOMEGUI_Swig::UpdateView()
650 class TEvent: public SALOME_Event
654 virtual void Execute()
656 if ( LightApp_Application* anApp = getApplication() ) {
657 SUIT_ViewManager* viewMgr = anApp->activeViewManager();
658 if (!viewMgr) return;
659 SUIT_ViewWindow* window = viewMgr->getActiveView();
661 SALOME_View* view = dynamic_cast<SALOME_View*>( window->getViewManager()->getActiveView() );
668 ProcessVoidEvent( new TEvent() );
672 \brief Fit current view window to display all its contents.
674 void SALOMEGUI_Swig::FitAll()
677 class TEvent: public SALOME_Event
681 virtual void Execute()
683 if ( LightApp_Application* anApp = getApplication() ) {
684 SUIT_ViewManager* viewMgr = anApp->activeViewManager();
685 if (!viewMgr) return;
686 SUIT_ViewWindow* window = viewMgr->getActiveView();
688 #ifndef DISABLE_SALOMEOBJECT
689 #ifndef DISABLE_VTKVIEWER
690 if ( dynamic_cast<SVTK_ViewWindow*>( window ) )
691 ( dynamic_cast<SVTK_ViewWindow*>( window ) )->onFitAll();
693 #ifndef DISABLE_PLOT2DVIEWER
694 if ( dynamic_cast<SPlot2d_ViewWindow*>( window ) )
695 ( dynamic_cast<SPlot2d_ViewWindow*>( window ) )->onFitAll();
698 #ifndef DISABLE_OCCVIEWER
699 if ( dynamic_cast<OCCViewer_ViewWindow*>( window ) )
700 ( dynamic_cast<OCCViewer_ViewWindow*>( window ) )->onFitAll();
706 ProcessVoidEvent( new TEvent() );
710 \brief Reset current view window to the default state.
712 void SALOMEGUI_Swig::ResetView()
714 class TEvent: public SALOME_Event
718 virtual void Execute()
720 if ( LightApp_Application* anApp = getApplication() ) {
721 SUIT_ViewManager* viewMgr = anApp->activeViewManager();
722 if (!viewMgr) return;
723 SUIT_ViewWindow* window = viewMgr->getActiveView();
725 #ifndef DISABLE_SALOMEOBJECT
726 #ifndef DISABLE_VTKVIEWER
727 if ( dynamic_cast<SVTK_ViewWindow*>( window ) )
728 (dynamic_cast<SVTK_ViewWindow*>( window ))->onResetView();
730 #ifndef DISABLE_PLOT2DVIEWER
731 if ( dynamic_cast<SPlot2d_ViewWindow*>( window ) )
732 (dynamic_cast<SPlot2d_ViewWindow*>( window ))->onFitAll();
733 // VSR: there is no 'ResetView' functionality for Plot2d viewer,
734 // so we use 'FitAll' instead.
737 #ifndef DISABLE_OCCVIEWER
738 if ( dynamic_cast<OCCViewer_ViewWindow*>( window ) )
739 (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onResetView();
745 ProcessVoidEvent( new TEvent() );
749 \brief View operation type.
753 __ViewTop, //!< view top side
754 __ViewBottom, //!< view bottom side
755 __ViewLeft, //!< view left side
756 __ViewRight, //!< view right side
757 __ViewFront, //!< view front side
758 __ViewBack //!< view back side
762 \brief Change the view of the current view window.
764 \param view view operation type
766 static void setView( int view )
768 class TEvent: public SALOME_Event
773 TEvent( int view ) : myView( view ) {}
774 virtual void Execute()
776 if ( LightApp_Application* anApp = getApplication() ) {
777 SUIT_ViewManager* viewMgr = anApp->activeViewManager();
778 if (!viewMgr) return;
779 SUIT_ViewWindow* window = viewMgr->getActiveView();
781 #ifndef DISABLE_SALOMEOBJECT
782 #ifndef DISABLE_VTKVIEWER
783 if ( dynamic_cast<SVTK_ViewWindow*>( window ) ) {
786 (dynamic_cast<SVTK_ViewWindow*>( window ))->onTopView(); break;
788 (dynamic_cast<SVTK_ViewWindow*>( window ))->onBottomView(); break;
790 (dynamic_cast<SVTK_ViewWindow*>( window ))->onLeftView(); break;
792 (dynamic_cast<SVTK_ViewWindow*>( window ))->onRightView(); break;
794 (dynamic_cast<SVTK_ViewWindow*>( window ))->onFrontView(); break;
796 (dynamic_cast<SVTK_ViewWindow*>( window ))->onBackView(); break;
803 #ifndef DISABLE_OCCVIEWER
804 if ( dynamic_cast<OCCViewer_ViewWindow*>( window ) ) {
807 (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onTopView(); break;
809 (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onBottomView(); break;
811 (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onLeftView(); break;
813 (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onRightView(); break;
815 (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onFrontView(); break;
817 (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onBackView(); break;
827 ProcessVoidEvent( new TEvent( view ) );
831 \brief Switch current view window to show the top view.
833 void SALOMEGUI_Swig::ViewTop()
835 setView( __ViewTop );
839 \brief Switch current view window to show the bottom view
841 void SALOMEGUI_Swig::ViewBottom()
843 setView( __ViewBottom );
847 \brief Switch current view window to show the left view
849 void SALOMEGUI_Swig::ViewLeft()
851 setView( __ViewLeft );
855 \brief Switch current view window to show the right view
857 void SALOMEGUI_Swig::ViewRight()
859 setView( __ViewRight );
863 \brief Switch current view window to show the front view
865 void SALOMEGUI_Swig::ViewFront()
867 setView( __ViewFront );
871 \brief Switch current view window to show the back view
873 void SALOMEGUI_Swig::ViewBack()
875 setView( __ViewBack );
879 \fn bool SALOMEGUI_Swig::getViewParameters()
880 \brief Get camera parameters of the active view.
882 NOTE: For the current moment implemented for VTK viewer only.
884 \return \c string with the view parameters
887 class TGetViewParameters: public SALOME_Event
890 typedef QString TResult;
892 TGetViewParameters() : myResult( "" ) {}
893 virtual void Execute() {
894 if ( LightApp_Application* anApp = getApplication() ) {
895 SUIT_ViewManager* viewMgr = anApp->activeViewManager();
896 if (!viewMgr) return;
897 if ( SUIT_ViewWindow* window = viewMgr->getActiveView() ) {
898 #ifndef DISABLE_VTKVIEWER
899 if ( SVTK_ViewWindow* svtk = dynamic_cast<SVTK_ViewWindow*>( window ) ) {
900 if ( vtkRenderer* ren = svtk->getRenderer()) {
901 if ( vtkCamera* camera = ren->GetActiveCamera() ) {
902 double pos[3], focalPnt[3], viewUp[3], scale[3], parScale;
904 // save position, focal point, viewUp, scale
905 camera->GetPosition( pos );
906 camera->GetFocalPoint( focalPnt );
907 camera->GetViewUp( viewUp );
908 parScale = camera->GetParallelScale();
909 svtk->GetRenderer()->GetScale( scale );
911 myResult += QString("sg.setCameraPosition( %1, %2, %3 )\n").arg(pos[0]).arg(pos[1]).arg(pos[2]);
912 myResult += QString("sg.setCameraFocalPoint( %1, %2, %3 )\n").arg(focalPnt[0]).arg(focalPnt[1]).arg(focalPnt[2]);
913 myResult += QString("sg.setCameraViewUp( %1, %2, %3 )\n").arg(viewUp[0]).arg(viewUp[1]).arg(viewUp[2]);
914 myResult += QString("sg.setViewScale(%1, %2, %3, %4 )\n").arg(parScale).arg(scale[0]).arg(scale[1]).arg(scale[2]);
924 const char* SALOMEGUI_Swig::getViewParameters() {
925 QString result = ProcessEvent( new TGetViewParameters() );
926 return result.isEmpty() ? 0 : strdup( result.toLatin1().constData() );
931 \brief View parameter type.
935 __CameraPosition, //!< position of the active camera
936 __CameraFocalPoint, //!< focal point of the active camera
937 __CameraViewUp, //!< view up of the active camera
938 __ViewScale //!< scale of the view
943 \brief Change the camera parameters of the current view window.
946 NOTE: For the current moment implemented for VTK viewer only.
948 \param parameter type of the parameter
949 \param values value of the parameter
951 static void setViewParameter( int parameter, QList<double>& values ) {
952 class TEvent: public SALOME_Event {
955 QList<double> myValues;
957 TEvent( int parameter , QList<double>& values ) : myParameter(parameter), myValues( values ) {}
959 virtual void Execute() {
960 if ( LightApp_Application* anApp = getApplication() ) {
961 SUIT_ViewManager* viewMgr = anApp->activeViewManager();
962 if (!viewMgr) return;
963 if ( SUIT_ViewWindow* window = viewMgr->getActiveView() ) {
964 #ifndef DISABLE_VTKVIEWER
965 if ( SVTK_ViewWindow* svtk = dynamic_cast<SVTK_ViewWindow*>( window ) ) {
966 if ( vtkRenderer* ren = svtk->getRenderer()) {
967 if ( vtkCamera* camera = ren->GetActiveCamera() ) {
968 switch(myParameter) {
969 case __CameraPosition : {
970 if ( myValues.size() == 3 ) {
971 camera->SetPosition( myValues[0], myValues[1], myValues[2] );
975 case __CameraFocalPoint : {
976 if ( myValues.size() == 3 ) {
977 camera->SetFocalPoint( myValues[0], myValues[1], myValues[2] );
981 case __CameraViewUp : {
982 if ( myValues.size() == 3 ) {
983 camera->SetViewUp( myValues[0], myValues[1], myValues[2] );
988 if ( myValues.size() == 4 ) {
989 camera->SetParallelScale( myValues[0] );
990 double scale[] = { myValues[1], myValues[2], myValues[3] };
991 svtk->GetRenderer()->SetScale( scale );
1006 ProcessVoidEvent( new TEvent( parameter, values ) );
1010 \brief Set camera position of the active view .
1011 \param x - X coordinate of the camera
1012 \param y - Y coordinate of the camera
1013 \param z - Z coordinate of the camera
1015 void SALOMEGUI_Swig::setCameraPosition( double x, double y, double z ) {
1020 setViewParameter( __CameraPosition, lst );
1024 \brief Set camera focal point of the active view.
1025 \param x - X coordinate of the focal point
1026 \param y - Y coordinate of the focal point
1027 \param z - Z coordinate of the focal point
1029 void SALOMEGUI_Swig::setCameraFocalPoint( double x, double y, double z ) {
1034 setViewParameter( __CameraFocalPoint, lst );
1038 \brief Set the view up direction for the camera.
1039 \param x - X component of the direction vector
1040 \param y - Y component of the direction vector
1041 \param z - Z component of the direction vector
1043 void SALOMEGUI_Swig::setCameraViewUp( double x, double y, double z ) {
1048 setViewParameter( __CameraViewUp, lst );
1052 \brief Set view scale.
1053 \param parallelScale - scaling used for a parallel projection.
1058 void SALOMEGUI_Swig::setViewScale( double parallelScale, double x, double y, double z ) {
1060 lst.push_back( parallelScale );
1064 setViewParameter( __ViewScale, lst );