1 // Copyright (C) 2007-2012 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 view0->setParent( centralFrame );
41 myViews.append( view0 ); // MAIN_VIEW
43 myLayout = new QGridLayout( centralFrame );
44 myLayout->setMargin( 0 );
45 myLayout->setSpacing( 1 );
47 myLayout->addWidget( view0, 1, 1 );
48 connectViewSignals(view0);
51 OCCViewer_ViewFrame::~OCCViewer_ViewFrame()
55 //**************************************************************************************
56 OCCViewer_ViewWindow* OCCViewer_ViewFrame::getView( const int i ) const
58 return ( i >= 0 && i < myViews.count() ) ? myViews.at( i ) : 0 ;
61 //**************************************************************************************
62 void OCCViewer_ViewFrame::setViewManager( SUIT_ViewManager* theMgr )
64 OCCViewer_ViewWindow::setViewManager(theMgr);
65 foreach (OCCViewer_ViewWindow* aView, myViews) {
66 aView->setViewManager(theMgr);
71 //**************************************************************************************
72 void OCCViewer_ViewFrame::onMaximizedView( OCCViewer_ViewWindow* theView, bool isMaximized)
75 if (myViews.count() <= 1)
78 myLayout->setColumnStretch(0, 0);
79 myLayout->setColumnStretch(1, 0);
81 OCCViewer_ViewWindow* view = 0;
82 for ( i = BOTTOM_RIGHT; i <= TOP_RIGHT; i++) {
84 view->setVisible( view == theView );
85 view->setMaximized( view == theView, false );
89 OCCViewer_Viewer* aModel = dynamic_cast<OCCViewer_Viewer*>(myManager->getViewModel());
92 myLayout->setColumnStretch(0, 10);
93 myLayout->setColumnStretch(1, 10);
96 if (myViews.count() == 1) {
97 //QColor aColor = myViews.at( MAIN_VIEW )->backgroundColor();
98 OCCViewer_ViewWindow* view = 0;
99 for ( i = BOTTOM_LEFT; i <= TOP_RIGHT; i++) {
100 view = aModel->createSubWindow();
101 view->set2dMode( (Mode2dType) i );
102 view->setParent( centralWidget() );
103 view->setViewManager(myManager);
104 myViews.append( view );
105 aModel->initView(view);
106 view->setMaximized(false, false);
107 view->setDropDownButtons( dropDownButtons() );
108 connectViewSignals(view);
109 view->setBackground(aModel->background(i));
111 myLayout->addWidget( myViews.at(BOTTOM_LEFT), 1, 0 );
112 myLayout->addWidget( myViews.at(TOP_LEFT), 0, 0 );
113 myLayout->addWidget( myViews.at(TOP_RIGHT), 0, 1 );
115 OCCViewer_ViewWindow* view = 0;
116 for ( i = BOTTOM_RIGHT; i <= TOP_RIGHT; i++) {
117 view = myViews.at(i);
119 view->setMaximized( false, false );
120 ///////////////QApplication::processEvents(); // VSR: hangs up ?
122 view->onViewFitAll();
125 myLayout->invalidate();
128 OCCViewer_ViewPort3d* OCCViewer_ViewFrame::getViewPort(int theView)
130 return getView(theView)? getView(theView)->getViewPort() : 0;
133 void OCCViewer_ViewFrame::updateEnabledDrawMode()
135 foreach (OCCViewer_ViewWindow* aView, myViews) {
136 aView->updateEnabledDrawMode();
140 void OCCViewer_ViewFrame::setCuttingPlane( bool on, const double x , const double y , const double z,
141 const double dx, const double dy, const double dz)
143 foreach (OCCViewer_ViewWindow* aView, myViews) {
144 aView->setCuttingPlane(on, x, y, z, dx, dy, dz);
149 //**************************************************************************************
150 void OCCViewer_ViewFrame::setCuttingPlane( bool on, const gp_Pln thePln )
152 foreach (OCCViewer_ViewWindow* aView, myViews) {
153 aView->setCuttingPlane(on, thePln);
158 //**************************************************************************************
159 void OCCViewer_ViewFrame::setInteractionStyle( const int i )
161 foreach (OCCViewer_ViewWindow* aView, myViews) {
162 aView->setInteractionStyle(i);
166 //**************************************************************************************
167 void OCCViewer_ViewFrame::setZoomingStyle( const int i )
169 foreach (OCCViewer_ViewWindow* aView, myViews) {
170 aView->setZoomingStyle(i);
174 //**************************************************************************************
175 void OCCViewer_ViewFrame::connectViewSignals(OCCViewer_ViewWindow* theView)
177 connect( theView, SIGNAL( maximized( OCCViewer_ViewWindow*, bool ) ),
178 this, SLOT( onMaximizedView( OCCViewer_ViewWindow*, bool ) ) );
180 connect( theView, SIGNAL( wheeling(SUIT_ViewWindow*, QWheelEvent*) ),
181 this, SIGNAL( wheeling(SUIT_ViewWindow*, QWheelEvent*) ) );
183 connect( theView, SIGNAL( keyReleased(SUIT_ViewWindow*, QKeyEvent*) ),
184 this, SIGNAL( keyReleased(SUIT_ViewWindow*, QKeyEvent*) ) );
185 connect( theView, SIGNAL( keyPressed(SUIT_ViewWindow*, QKeyEvent*) ),
186 this, SIGNAL( keyPressed(SUIT_ViewWindow*, QKeyEvent*) ) );
188 connect( theView, SIGNAL( mouseDoubleClicked(SUIT_ViewWindow*, QMouseEvent*) ),
189 this, SIGNAL( mouseDoubleClicked(SUIT_ViewWindow*, QMouseEvent*) ) );
190 connect( theView, SIGNAL( mousePressed(SUIT_ViewWindow*, QMouseEvent*) ),
191 this, SIGNAL( mousePressed(SUIT_ViewWindow*, QMouseEvent*) ) );
192 connect( theView, SIGNAL( mouseReleased(SUIT_ViewWindow*, QMouseEvent*) ),
193 this, SIGNAL( mouseReleased(SUIT_ViewWindow*, QMouseEvent*) ) );
194 connect( theView, SIGNAL( mouseMoving(SUIT_ViewWindow*, QMouseEvent*) ),
195 this, SIGNAL( mouseMoving(SUIT_ViewWindow*, QMouseEvent*) ) );
197 // The signal is used to process get/set background color from popup
198 connect( theView, SIGNAL( contextMenuRequested(QContextMenuEvent*) ),
199 this, SLOT( onContextMenuRequested(QContextMenuEvent*) ) );
201 connect( theView, SIGNAL( contextMenuRequested(QContextMenuEvent*) ),
202 this, SIGNAL( contextMenuRequested(QContextMenuEvent*) ) );
206 void OCCViewer_ViewFrame::setBackgroundColor( const QColor& theColor )
208 if (myPopupRequestedView)
209 myPopupRequestedView->setBackgroundColor(theColor);
211 foreach (OCCViewer_ViewWindow* aView, myViews) {
212 if (aView->isVisible())
213 aView->setBackgroundColor(theColor);
217 void OCCViewer_ViewFrame::setBackground( const Qtx::BackgroundData& theBackground )
219 if (myPopupRequestedView)
220 myPopupRequestedView->setBackground(theBackground);
222 foreach (OCCViewer_ViewWindow* aView, myViews) {
223 if (aView->isVisible())
224 aView->setBackground(theBackground);
229 void OCCViewer_ViewFrame::onViewFitAll()
231 foreach (OCCViewer_ViewWindow* aView, myViews) {
232 aView->onViewFitAll();
236 void OCCViewer_ViewFrame::onFitAll()
238 foreach (OCCViewer_ViewWindow* aView, myViews) {
244 QColor OCCViewer_ViewFrame::backgroundColor() const
246 if (myPopupRequestedView)
247 return myPopupRequestedView->backgroundColor();
249 foreach (OCCViewer_ViewWindow* aView, myViews) {
250 if (aView->isVisible())
251 return aView->backgroundColor();
253 return getView(MAIN_VIEW)->backgroundColor();
256 Qtx::BackgroundData OCCViewer_ViewFrame::background() const
258 if (myPopupRequestedView)
259 return myPopupRequestedView->background();
261 foreach (OCCViewer_ViewWindow* aView, myViews) {
262 if (aView->isVisible())
263 return aView->background();
265 return getView(MAIN_VIEW)->background();
268 QImage OCCViewer_ViewFrame::dumpView()
270 foreach (OCCViewer_ViewWindow* aView, myViews) {
271 if (aView->isVisible())
272 return aView->dumpView();
277 bool OCCViewer_ViewFrame::dumpViewToFormat( const QImage& image, const QString& fileName, const QString& format )
279 foreach (OCCViewer_ViewWindow* aView, myViews) {
280 if (aView->isVisible())
281 return aView->dumpViewToFormat( image, fileName, format );
286 void OCCViewer_ViewFrame::onContextMenuRequested(QContextMenuEvent*)
288 myPopupRequestedView = dynamic_cast<OCCViewer_ViewWindow*>(sender());
291 void OCCViewer_ViewFrame::onDumpView()
293 if (myPopupRequestedView) {
294 myPopupRequestedView->onDumpView();
297 getView(MAIN_VIEW)->onDumpView();
301 void OCCViewer_ViewFrame::setDropDownButtons( bool on )
303 foreach( OCCViewer_ViewWindow* aView, myViews ) {
304 aView->setDropDownButtons( on );
306 OCCViewer_ViewWindow::setDropDownButtons( on );
309 QString OCCViewer_ViewFrame::getVisualParameters()
312 int maximizedView = 999;
313 for ( int i = BOTTOM_RIGHT; i <= TOP_RIGHT && i < myViews.count(); i++) {
314 if ( getView(i)->isVisible() )
315 maximizedView = ( maximizedView != -1 ) ? ( maximizedView == 999 ? i : -1 ) : ( maximizedView );
316 params << getView(i)->getVisualParameters();
318 params.prepend( QString::number( maximizedView ) );
319 return params.join( "|" );
322 void OCCViewer_ViewFrame::setVisualParameters( const QString& parameters )
324 QStringList params = parameters.split( "|" );
325 if ( params.count() > 1 ) {
326 int maximizedView = params[0].toInt();
327 if ( myViews.count() < params.count()-1 )
328 onMaximizedView( getView(MAIN_VIEW), false ); // secondary views are not created yet, but should be
329 for ( int i = 1; i < params.count(); i++ ) {
331 getView( idx )->setVisualParameters( params[i] );
333 onMaximizedView( getView( maximizedView ), maximizedView != -1 ); // set proper sib-window maximized
336 // handle obsolete versions - no parameters for xy, yz, xz views
337 getView(MAIN_VIEW)->setVisualParameters( parameters );