1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "VTKViewer_ViewModel.h"
20 #include "VTKViewer_ViewWindow.h"
21 #include "VTKViewer_ViewManager.h"
22 #include "VTKViewer_RenderWindowInteractor.h"
24 #include "SUIT_ViewWindow.h"
25 #include "SUIT_Desktop.h"
26 #include "SUIT_Session.h"
29 #include <qapplication.h>
30 #include <qcolordialog.h>
32 #include <qpopupmenu.h>
34 /*!Constructor.Sets background color to black.*/
35 VTKViewer_Viewer::VTKViewer_Viewer()
37 myBgColor( Qt::black )
42 VTKViewer_Viewer::~VTKViewer_Viewer()
46 /*!Gets background color.*/
47 QColor VTKViewer_Viewer::backgroundColor() const
52 /*!Sets background color.*/
53 void VTKViewer_Viewer::setBackgroundColor( const QColor& c )
59 /*!Create new instance of VTKViewer_ViewWindow, sets background color and return pointer to it.*/
60 SUIT_ViewWindow* VTKViewer_Viewer::createView( SUIT_Desktop* theDesktop )
62 VTKViewer_ViewWindow* vw = new VTKViewer_ViewWindow( theDesktop, this );
63 vw->setBackgroundColor( myBgColor );
67 /*!Sets view manager and connect slots.*/
68 void VTKViewer_Viewer::setViewManager(SUIT_ViewManager* theViewManager)
70 SUIT_ViewModel::setViewManager(theViewManager);
71 connect(theViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)),
72 this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
74 connect(theViewManager, SIGNAL(mouseMove(SUIT_ViewWindow*, QMouseEvent*)),
75 this, SLOT(onMouseMove(SUIT_ViewWindow*, QMouseEvent*)));
77 connect(theViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)),
78 this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
81 /*!Insert context into popup menu.*/
82 void VTKViewer_Viewer::contextMenuPopup(QPopupMenu* thePopup)
84 thePopup->insertItem( tr( "MEN_DUMP_VIEW" ), this, SLOT( onDumpView() ) );
85 thePopup->insertItem( tr( "MEN_CHANGE_BACKGROUD" ), this, SLOT( onChangeBgColor() ) );
87 thePopup->insertSeparator();
89 VTKViewer_ViewWindow* aView = (VTKViewer_ViewWindow*)(myViewManager->getActiveView());
90 if ( aView && !aView->getToolBar()->isVisible() )
91 thePopup->insertItem( tr( "MEN_SHOW_TOOLBAR" ), this, SLOT( onShowToolbar() ) );
94 /*!On mouse press event.*/
95 void VTKViewer_Viewer::onMousePress(SUIT_ViewWindow* vw, QMouseEvent* event)
97 VTKViewer_RenderWindowInteractor* rwi = 0;
98 if ( vw && vw->inherits( "VTKViewer_ViewWindow" ) )
99 rwi = ((VTKViewer_ViewWindow*)vw)->getRWInteractor();
103 switch(event->button()) {
105 rwi->LeftButtonPressed(event) ;
108 rwi->MiddleButtonPressed(event) ;
111 rwi->RightButtonPressed(event) ;
118 /*!On mouse move event.*/
119 void VTKViewer_Viewer::onMouseMove(SUIT_ViewWindow* vw, QMouseEvent* event)
121 VTKViewer_RenderWindowInteractor* rwi = 0;
122 if ( vw && vw->inherits( "VTKViewer_ViewWindow" ) )
123 rwi = ((VTKViewer_ViewWindow*)vw)->getRWInteractor();
125 rwi->MouseMove( event );
128 /*!On mouse release event.*/
129 void VTKViewer_Viewer::onMouseRelease(SUIT_ViewWindow* vw, QMouseEvent* event)
131 VTKViewer_RenderWindowInteractor* rwi = 0;
132 if ( vw && vw->inherits( "VTKViewer_ViewWindow" ) )
133 rwi = ((VTKViewer_ViewWindow*)vw)->getRWInteractor();
137 switch(event->button()) {
139 rwi->LeftButtonReleased(event) ;
142 rwi->MiddleButtonReleased(event) ;
145 rwi->RightButtonReleased(event) ;
152 /*!Sets flag to enable selection \a isEnable.*/
153 void VTKViewer_Viewer::enableSelection(bool isEnabled)
155 mySelectionEnabled = isEnabled;
156 //!! To be done for view windows
159 /*!Sets flag to multi selection enable \a isEnable.*/
160 void VTKViewer_Viewer::enableMultiselection(bool isEnable)
162 myMultiSelectionEnabled = isEnable;
163 //!! To be done for view windows
166 /*!On dump view event.*/
167 void VTKViewer_Viewer::onDumpView()
169 VTKViewer_ViewWindow* aView = (VTKViewer_ViewWindow*)(myViewManager->getActiveView());
174 /*!On change back ground color event.*/
175 void VTKViewer_Viewer::onChangeBgColor()
177 VTKViewer_ViewWindow* aView = (VTKViewer_ViewWindow*)(myViewManager->getActiveView());
181 QColor aColor = QColorDialog::getColor( aView->backgroundColor(), aView);
182 if ( aColor.isValid() )
183 aView->setBackgroundColor(aColor);
186 /*!On show tool bar event.*/
187 void VTKViewer_Viewer::onShowToolbar() {
188 VTKViewer_ViewWindow* aView = (VTKViewer_ViewWindow*)(myViewManager->getActiveView());
190 aView->getToolBar()->show();