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 ), false );
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 ), false );
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()->getViewModel() );
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()->getViewModel() );
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() );
709 void SALOMEGUI_Swig::FitSelection()
711 class TEvent: public SALOME_Event
715 virtual void Execute()
717 if ( LightApp_Application* anApp = getApplication() ) {
718 SUIT_ViewManager* viewMgr = anApp->activeViewManager();
719 if (!viewMgr) return;
720 SUIT_ViewWindow* window = viewMgr->getActiveView();
722 #if !defined(DISABLE_SALOMEOBJECT) && !defined(DISABLE_VTKVIEWER)
723 if ( dynamic_cast<SVTK_ViewWindow*>( window ) )
724 (dynamic_cast<SVTK_ViewWindow*>( window ))->onFitSelection();
726 #if !defined(DISABLE_OCCVIEWER)
727 if ( dynamic_cast<OCCViewer_ViewWindow*>( window ) )
728 (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onFitSelection();
734 ProcessVoidEvent( new TEvent() );
737 void SALOMEGUI_Swig::FitIObjects(const std::list<std::string>& entries)
739 class TEvent: public SALOME_Event
741 const std::list<std::string>& myEntries;
743 TEvent( const std::list<std::string>& objs ) : myEntries( objs ) {}
744 virtual void Execute()
746 if ( LightApp_Application* anApp = getApplication() ) {
747 SUIT_ViewManager* viewMgr = anApp->activeViewManager();
748 if (!viewMgr) return;
749 SUIT_ViewWindow* window = viewMgr->getActiveView();
751 SALOME_ListIO objects;
752 std::list<std::string>::const_iterator it;
753 for ( it = myEntries.begin(); it != myEntries.end(); ++it )
754 objects.Append( new SALOME_InteractiveObject( (*it).c_str(), "" ) );
755 #if !defined(DISABLE_SALOMEOBJECT) && !defined(DISABLE_VTKVIEWER)
756 if ( dynamic_cast<SVTK_ViewWindow*>( window ) )
757 (dynamic_cast<SVTK_ViewWindow*>( window ))->onFitIObjects( objects );
763 ProcessVoidEvent( new TEvent( entries ) );
767 \brief Reset current view window to the default state.
769 void SALOMEGUI_Swig::ResetView()
771 class TEvent: public SALOME_Event
775 virtual void Execute()
777 if ( LightApp_Application* anApp = getApplication() ) {
778 SUIT_ViewManager* viewMgr = anApp->activeViewManager();
779 if (!viewMgr) return;
780 SUIT_ViewWindow* window = viewMgr->getActiveView();
782 #ifndef DISABLE_SALOMEOBJECT
783 #ifndef DISABLE_VTKVIEWER
784 if ( dynamic_cast<SVTK_ViewWindow*>( window ) )
785 (dynamic_cast<SVTK_ViewWindow*>( window ))->onResetView();
787 #ifndef DISABLE_PLOT2DVIEWER
788 if ( dynamic_cast<SPlot2d_ViewWindow*>( window ) )
789 (dynamic_cast<SPlot2d_ViewWindow*>( window ))->onFitAll();
790 // VSR: there is no 'ResetView' functionality for Plot2d viewer,
791 // so we use 'FitAll' instead.
794 #ifndef DISABLE_OCCVIEWER
795 if ( dynamic_cast<OCCViewer_ViewWindow*>( window ) )
796 (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onResetView();
802 ProcessVoidEvent( new TEvent() );
806 \brief View operation type.
810 __ViewTop, //!< view top side
811 __ViewBottom, //!< view bottom side
812 __ViewLeft, //!< view left side
813 __ViewRight, //!< view right side
814 __ViewFront, //!< view front side
815 __ViewBack //!< view back side
819 \brief Change the view of the current view window.
821 \param view view operation type
823 static void setView( int view )
825 class TEvent: public SALOME_Event
830 TEvent( int view ) : myView( view ) {}
831 virtual void Execute()
833 if ( LightApp_Application* anApp = getApplication() ) {
834 SUIT_ViewManager* viewMgr = anApp->activeViewManager();
835 if (!viewMgr) return;
836 SUIT_ViewWindow* window = viewMgr->getActiveView();
838 #ifndef DISABLE_SALOMEOBJECT
839 #ifndef DISABLE_VTKVIEWER
840 if ( dynamic_cast<SVTK_ViewWindow*>( window ) ) {
843 (dynamic_cast<SVTK_ViewWindow*>( window ))->onTopView(); break;
845 (dynamic_cast<SVTK_ViewWindow*>( window ))->onBottomView(); break;
847 (dynamic_cast<SVTK_ViewWindow*>( window ))->onLeftView(); break;
849 (dynamic_cast<SVTK_ViewWindow*>( window ))->onRightView(); break;
851 (dynamic_cast<SVTK_ViewWindow*>( window ))->onFrontView(); break;
853 (dynamic_cast<SVTK_ViewWindow*>( window ))->onBackView(); break;
860 #ifndef DISABLE_OCCVIEWER
861 if ( dynamic_cast<OCCViewer_ViewWindow*>( window ) ) {
864 (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onTopView(); break;
866 (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onBottomView(); break;
868 (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onLeftView(); break;
870 (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onRightView(); break;
872 (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onFrontView(); break;
874 (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onBackView(); break;
884 ProcessVoidEvent( new TEvent( view ) );
888 \brief Switch current view window to show the top view.
890 void SALOMEGUI_Swig::ViewTop()
892 setView( __ViewTop );
896 \brief Switch current view window to show the bottom view
898 void SALOMEGUI_Swig::ViewBottom()
900 setView( __ViewBottom );
904 \brief Switch current view window to show the left view
906 void SALOMEGUI_Swig::ViewLeft()
908 setView( __ViewLeft );
912 \brief Switch current view window to show the right view
914 void SALOMEGUI_Swig::ViewRight()
916 setView( __ViewRight );
920 \brief Switch current view window to show the front view
922 void SALOMEGUI_Swig::ViewFront()
924 setView( __ViewFront );
928 \brief Switch current view window to show the back view
930 void SALOMEGUI_Swig::ViewBack()
932 setView( __ViewBack );
936 \fn bool SALOMEGUI_Swig::getViewParameters()
937 \brief Get camera parameters of the active view.
939 NOTE: For the current moment implemented for VTK viewer only.
941 \return \c string with the view parameters
944 class TGetViewParameters: public SALOME_Event
947 typedef QString TResult;
949 TGetViewParameters() : myResult( "" ) {}
950 virtual void Execute() {
951 if ( LightApp_Application* anApp = getApplication() ) {
952 SUIT_ViewManager* viewMgr = anApp->activeViewManager();
953 if (!viewMgr) return;
954 if ( SUIT_ViewWindow* window = viewMgr->getActiveView() ) {
955 #ifndef DISABLE_VTKVIEWER
956 if ( SVTK_ViewWindow* svtk = dynamic_cast<SVTK_ViewWindow*>( window ) ) {
957 if ( vtkRenderer* ren = svtk->getRenderer()) {
958 if ( vtkCamera* camera = ren->GetActiveCamera() ) {
959 double pos[3], focalPnt[3], viewUp[3], scale[3], parScale;
961 // save position, focal point, viewUp, scale
962 camera->GetPosition( pos );
963 camera->GetFocalPoint( focalPnt );
964 camera->GetViewUp( viewUp );
965 parScale = camera->GetParallelScale();
966 svtk->GetRenderer()->GetScale( scale );
968 myResult += QString("sg.setCameraPosition( %1, %2, %3 )\n").arg(pos[0]).arg(pos[1]).arg(pos[2]);
969 myResult += QString("sg.setCameraFocalPoint( %1, %2, %3 )\n").arg(focalPnt[0]).arg(focalPnt[1]).arg(focalPnt[2]);
970 myResult += QString("sg.setCameraViewUp( %1, %2, %3 )\n").arg(viewUp[0]).arg(viewUp[1]).arg(viewUp[2]);
971 myResult += QString("sg.setViewScale(%1, %2, %3, %4 )\n").arg(parScale).arg(scale[0]).arg(scale[1]).arg(scale[2]);
981 const char* SALOMEGUI_Swig::getViewParameters() {
982 QString result = ProcessEvent( new TGetViewParameters() );
983 return result.isEmpty() ? 0 : strdup( result.toLatin1().constData() );
988 \brief View parameter type.
992 __CameraPosition, //!< position of the active camera
993 __CameraFocalPoint, //!< focal point of the active camera
994 __CameraViewUp, //!< view up of the active camera
995 __ViewScale //!< scale of the view
1000 \brief Change the camera parameters of the current view window.
1003 NOTE: For the current moment implemented for VTK viewer only.
1005 \param parameter type of the parameter
1006 \param values value of the parameter
1008 static void setViewParameter( int parameter, QList<double>& values ) {
1009 class TEvent: public SALOME_Event {
1012 QList<double> myValues;
1014 TEvent( int parameter , QList<double>& values ) : myParameter(parameter), myValues( values ) {}
1016 virtual void Execute() {
1017 if ( LightApp_Application* anApp = getApplication() ) {
1018 SUIT_ViewManager* viewMgr = anApp->activeViewManager();
1019 if (!viewMgr) return;
1020 if ( SUIT_ViewWindow* window = viewMgr->getActiveView() ) {
1021 #ifndef DISABLE_VTKVIEWER
1022 if ( SVTK_ViewWindow* svtk = dynamic_cast<SVTK_ViewWindow*>( window ) ) {
1023 if ( vtkRenderer* ren = svtk->getRenderer()) {
1024 if ( vtkCamera* camera = ren->GetActiveCamera() ) {
1025 switch(myParameter) {
1026 case __CameraPosition : {
1027 if ( myValues.size() == 3 ) {
1028 camera->SetPosition( myValues[0], myValues[1], myValues[2] );
1032 case __CameraFocalPoint : {
1033 if ( myValues.size() == 3 ) {
1034 camera->SetFocalPoint( myValues[0], myValues[1], myValues[2] );
1038 case __CameraViewUp : {
1039 if ( myValues.size() == 3 ) {
1040 camera->SetViewUp( myValues[0], myValues[1], myValues[2] );
1044 case __ViewScale : {
1045 if ( myValues.size() == 4 ) {
1046 camera->SetParallelScale( myValues[0] );
1047 double scale[] = { myValues[1], myValues[2], myValues[3] };
1048 svtk->GetRenderer()->SetScale( scale );
1063 ProcessVoidEvent( new TEvent( parameter, values ) );
1067 \brief Set camera position of the active view .
1068 \param x - X coordinate of the camera
1069 \param y - Y coordinate of the camera
1070 \param z - Z coordinate of the camera
1072 void SALOMEGUI_Swig::setCameraPosition( double x, double y, double z ) {
1077 setViewParameter( __CameraPosition, lst );
1081 \brief Set camera focal point of the active view.
1082 \param x - X coordinate of the focal point
1083 \param y - Y coordinate of the focal point
1084 \param z - Z coordinate of the focal point
1086 void SALOMEGUI_Swig::setCameraFocalPoint( double x, double y, double z ) {
1091 setViewParameter( __CameraFocalPoint, lst );
1095 \brief Set the view up direction for the camera.
1096 \param x - X component of the direction vector
1097 \param y - Y component of the direction vector
1098 \param z - Z component of the direction vector
1100 void SALOMEGUI_Swig::setCameraViewUp( double x, double y, double z ) {
1105 setViewParameter( __CameraViewUp, lst );
1109 \brief Set view scale.
1110 \param parallelScale - scaling used for a parallel projection.
1115 void SALOMEGUI_Swig::setViewScale( double parallelScale, double x, double y, double z ) {
1117 lst.push_back( parallelScale );
1121 setViewParameter( __ViewScale, lst );