1 // Copyright (C) 2007-2013 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.
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 #include "OCCViewer_ViewFrame.h"
24 #include "OCCViewer_ViewWindow.h"
25 #include "OCCViewer_ViewModel.h"
27 #include <SUIT_ViewManager.h>
31 #include <QApplication>
33 OCCViewer_ViewFrame::OCCViewer_ViewFrame(SUIT_Desktop* theDesktop, OCCViewer_Viewer* theModel)
34 : OCCViewer_ViewWindow( theDesktop, theModel ), myPopupRequestedView(0)
36 QFrame* centralFrame = new QFrame( this );
37 setCentralWidget( centralFrame );
39 OCCViewer_ViewWindow* view0 = theModel->createSubWindow();
40 updateWindowTitle( view0 );
41 view0->setParent( centralFrame );
42 myViews.append( view0 ); // MAIN_VIEW
44 myLayout = new QGridLayout( centralFrame );
45 myLayout->setMargin( 0 );
46 myLayout->setSpacing( 1 );
48 myLayout->addWidget( view0, 1, 1 );
49 connectViewSignals(view0);
52 OCCViewer_ViewFrame::~OCCViewer_ViewFrame()
56 bool OCCViewer_ViewFrame::event( QEvent* e )
58 if ( e->type() == QEvent::WindowTitleChange ) {
59 updateWindowTitle( getView( MAIN_VIEW ) );
60 updateWindowTitle( getView( BOTTOM_LEFT ) );
61 updateWindowTitle( getView( TOP_LEFT ) );
62 updateWindowTitle( getView( TOP_RIGHT ) );
64 return OCCViewer_ViewWindow::event( e );
67 //**************************************************************************************
68 OCCViewer_ViewWindow* OCCViewer_ViewFrame::getView( const int i ) const
70 return ( i >= 0 && i < myViews.count() ) ? myViews.at( i ) : 0 ;
73 //**************************************************************************************
74 void OCCViewer_ViewFrame::setViewManager( SUIT_ViewManager* theMgr )
76 OCCViewer_ViewWindow::setViewManager(theMgr);
77 foreach (OCCViewer_ViewWindow* aView, myViews) {
78 aView->setViewManager(theMgr);
83 //**************************************************************************************
84 void OCCViewer_ViewFrame::onMaximizedView( OCCViewer_ViewWindow* theView, bool isMaximized)
87 if (myViews.count() <= 1)
90 myLayout->setColumnStretch(0, 0);
91 myLayout->setColumnStretch(1, 0);
93 OCCViewer_ViewWindow* view = 0;
94 for ( i = BOTTOM_RIGHT; i <= TOP_RIGHT; i++) {
96 view->setVisible( view == theView );
97 view->setMaximized( view == theView, false );
101 OCCViewer_Viewer* aModel = dynamic_cast<OCCViewer_Viewer*>(myManager->getViewModel());
104 myLayout->setColumnStretch(0, 10);
105 myLayout->setColumnStretch(1, 10);
108 if (myViews.count() == 1) {
109 //QColor aColor = myViews.at( MAIN_VIEW )->backgroundColor();
110 OCCViewer_ViewWindow* view = 0;
111 for ( i = BOTTOM_LEFT; i <= TOP_RIGHT; i++) {
112 view = aModel->createSubWindow();
113 view->set2dMode( (Mode2dType) i );
114 view->setParent( centralWidget() );
115 view->setViewManager(myManager);
116 updateWindowTitle( view );
117 myViews.append( view );
118 aModel->initView(view);
119 view->setMaximized(false, false);
120 view->setDropDownButtons( dropDownButtons() );
121 connectViewSignals(view);
122 view->setBackground(aModel->background(i));
124 myLayout->addWidget( myViews.at(BOTTOM_LEFT), 1, 0 );
125 myLayout->addWidget( myViews.at(TOP_LEFT), 0, 0 );
126 myLayout->addWidget( myViews.at(TOP_RIGHT), 0, 1 );
128 OCCViewer_ViewWindow* view = 0;
129 for ( i = BOTTOM_RIGHT; i <= TOP_RIGHT; i++) {
130 view = myViews.at(i);
132 view->setMaximized( false, false );
133 ///////////////QApplication::processEvents(); // VSR: hangs up ?
135 view->onViewFitAll();
138 myLayout->invalidate();
141 OCCViewer_ViewPort3d* OCCViewer_ViewFrame::getViewPort(int theView)
143 return getView(theView)? getView(theView)->getViewPort() : 0;
146 void OCCViewer_ViewFrame::updateEnabledDrawMode()
148 foreach (OCCViewer_ViewWindow* aView, myViews) {
149 aView->updateEnabledDrawMode();
153 void OCCViewer_ViewFrame::setCuttingPlane( bool on, const double x , const double y , const double z,
154 const double dx, const double dy, const double dz)
156 foreach (OCCViewer_ViewWindow* aView, myViews) {
157 aView->setCuttingPlane(on, x, y, z, dx, dy, dz);
162 //**************************************************************************************
163 void OCCViewer_ViewFrame::setCuttingPlane( bool on, const gp_Pln thePln )
165 foreach (OCCViewer_ViewWindow* aView, myViews) {
166 aView->setCuttingPlane(on, thePln);
171 //**************************************************************************************
172 void OCCViewer_ViewFrame::setInteractionStyle( const int i )
174 foreach (OCCViewer_ViewWindow* aView, myViews) {
175 aView->setInteractionStyle(i);
179 //**************************************************************************************
180 void OCCViewer_ViewFrame::setZoomingStyle( const int i )
182 foreach (OCCViewer_ViewWindow* aView, myViews) {
183 aView->setZoomingStyle(i);
187 //**************************************************************************************
188 void OCCViewer_ViewFrame::connectViewSignals(OCCViewer_ViewWindow* theView)
190 connect( theView, SIGNAL( maximized( OCCViewer_ViewWindow*, bool ) ),
191 this, SLOT( onMaximizedView( OCCViewer_ViewWindow*, bool ) ) );
193 connect( theView, SIGNAL( wheeling(SUIT_ViewWindow*, QWheelEvent*) ),
194 this, SIGNAL( wheeling(SUIT_ViewWindow*, QWheelEvent*) ) );
196 connect( theView, SIGNAL( keyReleased(SUIT_ViewWindow*, QKeyEvent*) ),
197 this, SIGNAL( keyReleased(SUIT_ViewWindow*, QKeyEvent*) ) );
198 connect( theView, SIGNAL( keyPressed(SUIT_ViewWindow*, QKeyEvent*) ),
199 this, SIGNAL( keyPressed(SUIT_ViewWindow*, QKeyEvent*) ) );
201 connect( theView, SIGNAL( mouseDoubleClicked(SUIT_ViewWindow*, QMouseEvent*) ),
202 this, SIGNAL( mouseDoubleClicked(SUIT_ViewWindow*, QMouseEvent*) ) );
203 connect( theView, SIGNAL( mousePressed(SUIT_ViewWindow*, QMouseEvent*) ),
204 this, SIGNAL( mousePressed(SUIT_ViewWindow*, QMouseEvent*) ) );
205 connect( theView, SIGNAL( mouseReleased(SUIT_ViewWindow*, QMouseEvent*) ),
206 this, SIGNAL( mouseReleased(SUIT_ViewWindow*, QMouseEvent*) ) );
207 connect( theView, SIGNAL( mouseMoving(SUIT_ViewWindow*, QMouseEvent*) ),
208 this, SIGNAL( mouseMoving(SUIT_ViewWindow*, QMouseEvent*) ) );
210 // The signal is used to process get/set background color from popup
211 connect( theView, SIGNAL( contextMenuRequested(QContextMenuEvent*) ),
212 this, SLOT( onContextMenuRequested(QContextMenuEvent*) ) );
214 connect( theView, SIGNAL( contextMenuRequested(QContextMenuEvent*) ),
215 this, SIGNAL( contextMenuRequested(QContextMenuEvent*) ) );
217 connect( theView, SIGNAL( viewCloned( SUIT_ViewWindow* ) ),
218 this, SIGNAL( viewCloned( SUIT_ViewWindow* ) ) );
222 void OCCViewer_ViewFrame::setBackgroundColor( const QColor& theColor )
224 if (myPopupRequestedView)
225 myPopupRequestedView->setBackgroundColor(theColor);
227 foreach (OCCViewer_ViewWindow* aView, myViews) {
228 if (aView->isVisible())
229 aView->setBackgroundColor(theColor);
233 void OCCViewer_ViewFrame::setBackground( const Qtx::BackgroundData& theBackground )
235 if (myPopupRequestedView)
236 myPopupRequestedView->setBackground(theBackground);
238 foreach (OCCViewer_ViewWindow* aView, myViews) {
239 if (aView->isVisible())
240 aView->setBackground(theBackground);
245 void OCCViewer_ViewFrame::onViewFitAll()
247 foreach (OCCViewer_ViewWindow* aView, myViews) {
248 aView->onViewFitAll();
252 void OCCViewer_ViewFrame::onFitAll()
254 foreach (OCCViewer_ViewWindow* aView, myViews) {
260 QColor OCCViewer_ViewFrame::backgroundColor() const
262 if (myPopupRequestedView)
263 return myPopupRequestedView->backgroundColor();
265 foreach (OCCViewer_ViewWindow* aView, myViews) {
266 if (aView->isVisible())
267 return aView->backgroundColor();
269 return getView(MAIN_VIEW)->backgroundColor();
272 Qtx::BackgroundData OCCViewer_ViewFrame::background() const
274 if (myPopupRequestedView)
275 return myPopupRequestedView->background();
277 foreach (OCCViewer_ViewWindow* aView, myViews) {
278 if (aView->isVisible())
279 return aView->background();
281 return getView(MAIN_VIEW)->background();
284 QImage OCCViewer_ViewFrame::dumpView()
286 foreach (OCCViewer_ViewWindow* aView, myViews) {
287 if (aView->isVisible())
288 return aView->dumpView();
293 bool OCCViewer_ViewFrame::dumpViewToFormat( const QImage& image, const QString& fileName, const QString& format )
295 foreach (OCCViewer_ViewWindow* aView, myViews) {
296 if (aView->isVisible())
297 return aView->dumpViewToFormat( image, fileName, format );
302 void OCCViewer_ViewFrame::onContextMenuRequested(QContextMenuEvent*)
304 myPopupRequestedView = dynamic_cast<OCCViewer_ViewWindow*>(sender());
307 void OCCViewer_ViewFrame::onDumpView()
309 if (myPopupRequestedView) {
310 myPopupRequestedView->onDumpView();
313 getView(MAIN_VIEW)->onDumpView();
317 void OCCViewer_ViewFrame::setDropDownButtons( bool on )
319 foreach( OCCViewer_ViewWindow* aView, myViews ) {
320 aView->setDropDownButtons( on );
322 OCCViewer_ViewWindow::setDropDownButtons( on );
325 QString OCCViewer_ViewFrame::getVisualParameters()
328 int maximizedView = 999;
329 for ( int i = BOTTOM_RIGHT; i <= TOP_RIGHT && i < myViews.count(); i++) {
330 if ( getView(i)->isVisible() )
331 maximizedView = ( maximizedView != -1 ) ? ( maximizedView == 999 ? i : -1 ) : ( maximizedView );
332 params << getView(i)->getVisualParameters();
334 params.prepend( QString::number( maximizedView ) );
335 return params.join( "|" );
338 void OCCViewer_ViewFrame::setVisualParameters( const QString& parameters )
340 QStringList params = parameters.split( "|" );
341 if ( params.count() > 1 ) {
342 int maximizedView = params[0].toInt();
343 if ( myViews.count() < params.count()-1 )
344 onMaximizedView( getView(MAIN_VIEW), false ); // secondary views are not created yet, but should be
345 for ( int i = 1; i < params.count(); i++ ) {
347 getView( idx )->setVisualParameters( params[i] );
349 onMaximizedView( getView( maximizedView ), maximizedView != -1 ); // set proper sib-window maximized
352 // handle obsolete versions - no parameters for xy, yz, xz views
353 getView(MAIN_VIEW)->setVisualParameters( parameters );
357 SUIT_CameraProperties OCCViewer_ViewFrame::cameraProperties()
359 // view frame does not have camera properties
360 return SUIT_CameraProperties();
363 void OCCViewer_ViewFrame::updateWindowTitle(OCCViewer_ViewWindow* theView)
368 switch ( theView->get2dMode() ) {
380 if ( !title.isEmpty() )
381 theView->setWindowTitle( windowTitle() + " - " + title );