Back to index

salome-gui  6.5.0
Plot2d_ViewModel.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 // Plot2d_ViewModel.cxx: implementation of the Plot2d_ViewModel class.
00024 //
00025 #include "Plot2d_ViewModel.h"
00026 #include "Plot2d_ViewWindow.h"
00027 #include "Plot2d_ViewManager.h"
00028 #include "Plot2d_ViewFrame.h"
00029 #include "Plot2d_Prs.h"
00030 
00031 #include <QMenu>
00032 #include <QToolBar>
00033 #include <QVector>
00034 
00038 Plot2d_Viewer::Plot2d_Viewer(bool theAutoDel)
00039 :SUIT_ViewModel() 
00040 {
00041   myPrs = 0;
00042   myAutoDel = theAutoDel;
00043   Plot2d_Object::initColors();
00044 }
00045 
00049 Plot2d_Viewer::~Plot2d_Viewer()
00050 {
00051   if (myPrs)
00052     clearPrs();
00053 }
00054 
00059 SUIT_ViewWindow* Plot2d_Viewer::createView(SUIT_Desktop* theDesktop)
00060 {
00061   Plot2d_ViewWindow* aView = new Plot2d_ViewWindow(theDesktop, this);
00062   aView->initLayout();
00063   if (myPrs)
00064     aView->getViewFrame()->Display(myPrs);
00065   return aView;
00066 }
00067 
00072 void Plot2d_Viewer::contextMenuPopup(QMenu* thePopup)
00073 {
00074   Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)(myViewManager->getActiveView());
00075   if ( aView )
00076     aView->contextMenuPopup(thePopup);
00077 
00078   if (!thePopup->isEmpty())
00079     thePopup->addSeparator();
00080   thePopup->addAction( tr( "MNU_DUMP_VIEW" ),                this, SLOT(onDumpView()));
00081   thePopup->addAction( tr( "MEN_PLOT2D_CHANGE_BACKGROUND" ), this, SLOT(onChangeBgColor()));
00082 
00083   if ( aView ) {
00084     if ( !aView->getToolBar()->isVisible() ) {
00085       if (!thePopup->isEmpty())
00086         thePopup->addSeparator();
00087       thePopup->addAction("Show toolbar", this, SLOT(onShowToolbar()));
00088     }
00089     aView->RefreshDumpImage();
00090   }
00091 }
00092 
00097 void Plot2d_Viewer::setPrs(Plot2d_Prs* thePrs) 
00098 {
00099   if (myPrs)
00100     clearPrs();
00101   myPrs = thePrs;
00102   myPrs->setAutoDel(myAutoDel);
00103 }
00104 
00108 void Plot2d_Viewer::update()
00109 {
00110   SUIT_ViewManager* aMgr = getViewManager();
00111   QVector<SUIT_ViewWindow*> aViews = aMgr->getViews();
00112   unsigned int aSize = aViews.size();
00113   for (uint i = 0; i < aSize; i++) {
00114     Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)aViews[i];
00115     if (myPrs && aView)
00116       aView->getViewFrame()->Display(myPrs);
00117   }
00118 }
00119 
00123 void Plot2d_Viewer::clearPrs()
00124 {
00125   SUIT_ViewManager* aMgr = getViewManager();
00126   QVector<SUIT_ViewWindow*> aViews;
00127   if ( aMgr )
00128     aViews = aMgr->getViews();
00129   unsigned int aSize = aViews.size();
00130   for (uint i = 0; i < aSize; i++) {
00131     Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)aViews[i];
00132     if (myPrs && aView)
00133       aView->getViewFrame()->Erase(myPrs);
00134   }
00135   if (myAutoDel && myPrs) {
00136     delete myPrs;
00137   }
00138   myPrs = 0;
00139 }
00140 
00145 void Plot2d_Viewer::setAutoDel(bool theDel)
00146 {
00147   myAutoDel = theDel;
00148   if (myPrs)
00149     myPrs->setAutoDel(theDel);
00150 }
00151 
00155 void Plot2d_Viewer::onChangeBgColor()
00156 {
00157   Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)(myViewManager->getActiveView());
00158   if( !aView )
00159     return;
00160   Plot2d_ViewFrame* aViewFrame = aView->getViewFrame();
00161   aViewFrame->onChangeBackground();
00162 }
00163 
00167 void Plot2d_Viewer::onShowToolbar() {
00168   Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)(myViewManager->getActiveView());
00169   if ( aView )
00170     aView->getToolBar()->show();    
00171 }
00172 
00176 void Plot2d_Viewer::onDumpView()
00177 {
00178   Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)(myViewManager->getActiveView());
00179   if ( aView )
00180     aView->onDumpView();    
00181 }
00182 
00186 void Plot2d_Viewer::onCloneView( Plot2d_ViewFrame* clonedVF, Plot2d_ViewFrame* newVF )
00187 {
00188   if( !clonedVF || !newVF )
00189     return;
00190 
00191   // 1) Copy all properties of view
00192 
00193   newVF->copyPreferences( clonedVF );
00194 
00195   // 2) Display all curves displayed in cloned view
00196 
00197   curveList aCurves;
00198   clonedVF->getCurves( aCurves );
00199   curveList::const_iterator anIt = aCurves.begin(), aLast = aCurves.end();
00200 
00201   for( ; anIt!=aLast; anIt++ )
00202     if( clonedVF->isVisible( *anIt ) )
00203       newVF->displayCurve( *anIt, false );
00204   newVF->Repaint();
00205   
00206   if ( newVF )
00207   {
00208     // find view window corresponding to the frame 
00209     QWidget* p = newVF->parentWidget();
00210     while( p && !p->inherits( "SUIT_ViewWindow" ) )
00211       p = p->parentWidget();
00212     
00213     // emits signal
00214     if ( p && p->inherits( "SUIT_ViewWindow" ) )
00215       emit viewCloned( (SUIT_ViewWindow*)p );
00216   }
00217 }
00218 
00219 /*
00220   SLOT: called when clicked item in the legend from Plot2d_ViewManager
00221  */
00222 void Plot2d_Viewer::onLegendClicked( QwtPlotItem* plotItem )
00223 {
00224 }
00225 
00230 void Plot2d_Viewer::setViewManager( SUIT_ViewManager* mgr )
00231 {
00232   SUIT_ViewModel::setViewManager( mgr );
00233   if( mgr && mgr->inherits( "Plot2d_ViewManager" ) )
00234   {
00235     Plot2d_ViewManager* pmgr = ( Plot2d_ViewManager* )mgr;
00236     connect( pmgr, SIGNAL( cloneView( Plot2d_ViewFrame*, Plot2d_ViewFrame* ) ),
00237              this, SLOT( onCloneView( Plot2d_ViewFrame*, Plot2d_ViewFrame* ) ) );
00238   }
00239 }