Back to index

salome-gui  6.5.0
OCCViewer_ViewFrame.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #include "OCCViewer_ViewFrame.h"
00024 #include "OCCViewer_ViewWindow.h"
00025 #include "OCCViewer_ViewModel.h"
00026 
00027 #include <SUIT_ViewManager.h>
00028 
00029 #include <QFrame>
00030 #include <QLayout>
00031 #include <QApplication>
00032 
00033 OCCViewer_ViewFrame::OCCViewer_ViewFrame(SUIT_Desktop* theDesktop, OCCViewer_Viewer* theModel)
00034   : OCCViewer_ViewWindow( theDesktop, theModel ), myPopupRequestedView(0)
00035 {
00036   QFrame* centralFrame = new QFrame( this );
00037   setCentralWidget( centralFrame );
00038 
00039   OCCViewer_ViewWindow* view0 = theModel->createSubWindow();
00040   view0->setParent( centralFrame );
00041   myViews.append( view0 ); // MAIN_VIEW
00042 
00043   myLayout = new QGridLayout( centralFrame );
00044   myLayout->setMargin( 0 );
00045   myLayout->setSpacing( 1 );
00046 
00047   myLayout->addWidget( view0, 1, 1 );
00048   connectViewSignals(view0);
00049 }
00050 
00051 OCCViewer_ViewFrame::~OCCViewer_ViewFrame()
00052 {
00053 }
00054 
00055 //**************************************************************************************
00056 OCCViewer_ViewWindow* OCCViewer_ViewFrame::getView( const int i ) const
00057 {
00058   return ( i >= 0 && i < myViews.count() ) ? myViews.at( i ) : 0 ;
00059 }
00060 
00061 //**************************************************************************************
00062 void OCCViewer_ViewFrame::setViewManager( SUIT_ViewManager* theMgr )
00063 {
00064   OCCViewer_ViewWindow::setViewManager(theMgr);
00065   foreach (OCCViewer_ViewWindow* aView, myViews) {
00066     aView->setViewManager(theMgr); 
00067   }
00068 }
00069 
00070 
00071 //**************************************************************************************
00072 void OCCViewer_ViewFrame::onMaximizedView( OCCViewer_ViewWindow* theView, bool isMaximized)
00073 {
00074   if (isMaximized) {
00075     if (myViews.count() <= 1)
00076       return;
00077 
00078     myLayout->setColumnStretch(0, 0);
00079     myLayout->setColumnStretch(1, 0);
00080     int i = 0;
00081     OCCViewer_ViewWindow* view = 0;
00082     for ( i = BOTTOM_RIGHT; i <= TOP_RIGHT; i++) {
00083       view = myViews.at(i);
00084       view->setVisible( view == theView );
00085       view->setMaximized( view == theView, false );
00086     }
00087   }
00088   else {
00089     OCCViewer_Viewer* aModel = dynamic_cast<OCCViewer_Viewer*>(myManager->getViewModel());
00090     if (!aModel) return;
00091 
00092     myLayout->setColumnStretch(0, 10);
00093     myLayout->setColumnStretch(1, 10);
00094 
00095     int i = 0;
00096     if (myViews.count() == 1) {
00097       //QColor aColor = myViews.at( MAIN_VIEW )->backgroundColor();
00098       OCCViewer_ViewWindow* view = 0;
00099       for ( i = BOTTOM_LEFT; i <= TOP_RIGHT; i++) {
00100         view = aModel->createSubWindow();
00101         view->set2dMode( (Mode2dType) i );
00102         view->setParent( centralWidget() );
00103         view->setViewManager(myManager); 
00104         myViews.append( view ); 
00105         aModel->initView(view);
00106         view->setMaximized(false, false);
00107        view->setDropDownButtons( dropDownButtons() );
00108         connectViewSignals(view);
00109        view->setBackground(aModel->background(i));
00110       }
00111       myLayout->addWidget( myViews.at(BOTTOM_LEFT), 1, 0 );
00112       myLayout->addWidget( myViews.at(TOP_LEFT), 0, 0 );
00113       myLayout->addWidget( myViews.at(TOP_RIGHT), 0, 1 );
00114     }
00115     OCCViewer_ViewWindow* view = 0;
00116     for ( i = BOTTOM_RIGHT; i <= TOP_RIGHT; i++) {
00117       view = myViews.at(i);
00118       view->show();
00119       view->setMaximized( false, false );
00121       if (view != theView)
00122         view->onViewFitAll();
00123     }
00124   }
00125   myLayout->invalidate();
00126 }
00127 
00128 OCCViewer_ViewPort3d* OCCViewer_ViewFrame::getViewPort(int theView) 
00129 { 
00130   return getView(theView)? getView(theView)->getViewPort() : 0;
00131 }
00132   
00133 void OCCViewer_ViewFrame::updateEnabledDrawMode() 
00134 { 
00135   foreach (OCCViewer_ViewWindow* aView, myViews) {
00136     aView->updateEnabledDrawMode(); 
00137   }
00138 }
00139 
00140 void OCCViewer_ViewFrame::setCuttingPlane( bool on, const double x , const double y , const double z,
00141                                            const double dx, const double dy, const double dz)  
00142 { 
00143   foreach (OCCViewer_ViewWindow* aView, myViews) {
00144     aView->setCuttingPlane(on, x, y, z, dx, dy, dz); 
00145     aView->update();
00146   }
00147 }
00148 
00149 //**************************************************************************************
00150 void OCCViewer_ViewFrame::setCuttingPlane( bool on, const gp_Pln thePln ) 
00151 { 
00152   foreach (OCCViewer_ViewWindow* aView, myViews) {
00153     aView->setCuttingPlane(on, thePln); 
00154     aView->update();
00155   }
00156 }
00157   
00158 //**************************************************************************************
00159 void OCCViewer_ViewFrame::setInteractionStyle( const int i ) 
00160 { 
00161   foreach (OCCViewer_ViewWindow* aView, myViews) {
00162     aView->setInteractionStyle(i); 
00163   }
00164 }
00165 
00166 //**************************************************************************************
00167 void OCCViewer_ViewFrame::setZoomingStyle( const int i ) 
00168 { 
00169   foreach (OCCViewer_ViewWindow* aView, myViews) {
00170     aView->setZoomingStyle(i); 
00171   }
00172 }
00173   
00174 //**************************************************************************************
00175 void OCCViewer_ViewFrame::connectViewSignals(OCCViewer_ViewWindow* theView)
00176 {
00177   connect( theView, SIGNAL( maximized( OCCViewer_ViewWindow*, bool ) ), 
00178            this, SLOT( onMaximizedView( OCCViewer_ViewWindow*, bool ) ) );
00179 
00180   connect( theView, SIGNAL( wheeling(SUIT_ViewWindow*, QWheelEvent*) ), 
00181            this, SIGNAL( wheeling(SUIT_ViewWindow*, QWheelEvent*) ) );
00182 
00183   connect( theView, SIGNAL( keyReleased(SUIT_ViewWindow*, QKeyEvent*) ), 
00184            this, SIGNAL( keyReleased(SUIT_ViewWindow*, QKeyEvent*) ) );
00185   connect( theView, SIGNAL( keyPressed(SUIT_ViewWindow*, QKeyEvent*) ), 
00186            this, SIGNAL( keyPressed(SUIT_ViewWindow*, QKeyEvent*) ) );
00187 
00188   connect( theView, SIGNAL( mouseDoubleClicked(SUIT_ViewWindow*, QMouseEvent*) ), 
00189            this, SIGNAL( mouseDoubleClicked(SUIT_ViewWindow*, QMouseEvent*) ) );
00190   connect( theView, SIGNAL( mousePressed(SUIT_ViewWindow*, QMouseEvent*) ), 
00191            this, SIGNAL( mousePressed(SUIT_ViewWindow*, QMouseEvent*) ) );
00192   connect( theView, SIGNAL( mouseReleased(SUIT_ViewWindow*, QMouseEvent*) ), 
00193            this, SIGNAL( mouseReleased(SUIT_ViewWindow*, QMouseEvent*) ) );
00194   connect( theView, SIGNAL( mouseMoving(SUIT_ViewWindow*, QMouseEvent*) ), 
00195            this, SIGNAL( mouseMoving(SUIT_ViewWindow*, QMouseEvent*) ) );
00196 
00197   // The signal is used to process get/set background color from popup
00198   connect( theView, SIGNAL( contextMenuRequested(QContextMenuEvent*) ), 
00199            this, SLOT( onContextMenuRequested(QContextMenuEvent*) ) );
00200 
00201   connect( theView, SIGNAL( contextMenuRequested(QContextMenuEvent*) ), 
00202            this, SIGNAL( contextMenuRequested(QContextMenuEvent*) ) );
00203 }
00204 
00205 // obsolete
00206 void OCCViewer_ViewFrame::setBackgroundColor( const QColor& theColor )
00207 {
00208   if (myPopupRequestedView)
00209     myPopupRequestedView->setBackgroundColor(theColor); 
00210   else {
00211     foreach (OCCViewer_ViewWindow* aView, myViews) {
00212       if (aView->isVisible())
00213         aView->setBackgroundColor(theColor); 
00214     }
00215   }
00216 }
00217 void OCCViewer_ViewFrame::setBackground( const Qtx::BackgroundData& theBackground )
00218 {
00219   if (myPopupRequestedView)
00220     myPopupRequestedView->setBackground(theBackground); 
00221   else {
00222     foreach (OCCViewer_ViewWindow* aView, myViews) {
00223       if (aView->isVisible())
00224         aView->setBackground(theBackground); 
00225     }
00226   }
00227 }
00228 
00229 void OCCViewer_ViewFrame::onViewFitAll()
00230 {
00231   foreach (OCCViewer_ViewWindow* aView, myViews) {
00232     aView->onViewFitAll(); 
00233   }
00234 }
00235 
00236 void OCCViewer_ViewFrame::onFitAll()
00237 {
00238   foreach (OCCViewer_ViewWindow* aView, myViews) {
00239     aView->onFitAll(); 
00240   }
00241 }
00242 
00243 // obsolete  
00244 QColor OCCViewer_ViewFrame::backgroundColor() const 
00245 { 
00246   if (myPopupRequestedView)
00247     return myPopupRequestedView->backgroundColor(); 
00248 
00249   foreach (OCCViewer_ViewWindow* aView, myViews) {
00250     if (aView->isVisible())
00251       return aView->backgroundColor(); 
00252   }
00253   return getView(MAIN_VIEW)->backgroundColor(); 
00254 }
00255 
00256 Qtx::BackgroundData OCCViewer_ViewFrame::background() const 
00257 { 
00258   if (myPopupRequestedView)
00259     return myPopupRequestedView->background(); 
00260 
00261   foreach (OCCViewer_ViewWindow* aView, myViews) {
00262     if (aView->isVisible())
00263       return aView->background(); 
00264   }
00265   return getView(MAIN_VIEW)->background(); 
00266 }
00267 
00268 QImage OCCViewer_ViewFrame::dumpView()
00269 {
00270   foreach (OCCViewer_ViewWindow* aView, myViews) {
00271     if (aView->isVisible())
00272       return aView->dumpView();
00273   }
00274   return QImage();
00275 }
00276 
00277 bool OCCViewer_ViewFrame::dumpViewToFormat( const QImage& image, const QString& fileName, const QString& format )
00278 {
00279   foreach (OCCViewer_ViewWindow* aView, myViews) {
00280     if (aView->isVisible())
00281       return aView->dumpViewToFormat( image, fileName, format );
00282   }
00283   return false;
00284 }
00285 
00286 void OCCViewer_ViewFrame::onContextMenuRequested(QContextMenuEvent*)
00287 {
00288   myPopupRequestedView = dynamic_cast<OCCViewer_ViewWindow*>(sender());
00289 }
00290 
00291 void OCCViewer_ViewFrame::onDumpView()
00292 {
00293   if (myPopupRequestedView) {
00294     myPopupRequestedView->onDumpView(); 
00295   }
00296   else {
00297     getView(MAIN_VIEW)->onDumpView(); 
00298   }
00299 }
00300 
00301 void OCCViewer_ViewFrame::setDropDownButtons( bool on )
00302 {
00303   foreach( OCCViewer_ViewWindow* aView, myViews ) {
00304     aView->setDropDownButtons( on );
00305   }
00306   OCCViewer_ViewWindow::setDropDownButtons( on );
00307 }
00308 
00309 QString OCCViewer_ViewFrame::getVisualParameters()
00310 {
00311   QStringList params;
00312   int maximizedView = 999;
00313   for ( int i = BOTTOM_RIGHT; i <= TOP_RIGHT && i < myViews.count(); i++) {
00314     if ( getView(i)->isVisible() )
00315       maximizedView = ( maximizedView != -1 ) ? ( maximizedView == 999 ? i : -1 ) : ( maximizedView );
00316     params << getView(i)->getVisualParameters();
00317   }
00318   params.prepend( QString::number( maximizedView ) );
00319   return params.join( "|" );
00320 }
00321 
00322 void OCCViewer_ViewFrame::setVisualParameters( const QString& parameters ) 
00323 {
00324   QStringList params = parameters.split( "|" );
00325   if ( params.count() > 1 ) {
00326     int maximizedView = params[0].toInt();
00327     if ( myViews.count() < params.count()-1 )
00328       onMaximizedView( getView(MAIN_VIEW), false ); // secondary views are not created yet, but should be
00329     for ( int i = 1; i < params.count(); i++ ) {
00330       int idx = i-1;
00331       getView( idx )->setVisualParameters( params[i] );
00332     }
00333     onMaximizedView( getView( maximizedView ), maximizedView != -1 ); // set proper sib-window maximized 
00334   }
00335   else {
00336     // handle obsolete versions - no parameters for xy, yz, xz views
00337     getView(MAIN_VIEW)->setVisualParameters( parameters );
00338   }
00339 }