1 // Copyright (C) 2007-2008 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
22 // Plot2d_ViewModel.cxx: implementation of the Plot2d_ViewModel class.
24 #include "Plot2d_ViewModel.h"
25 #include "Plot2d_ViewWindow.h"
26 #include "Plot2d_ViewManager.h"
27 #include "Plot2d_ViewFrame.h"
28 #include "Plot2d_Prs.h"
37 Plot2d_Viewer::Plot2d_Viewer(bool theAutoDel)
41 myAutoDel = theAutoDel;
47 Plot2d_Viewer::~Plot2d_Viewer()
54 Create new instance of view window on desktop \a theDesktop.
55 \retval SUIT_ViewWindow* - created view window pointer.
57 SUIT_ViewWindow* Plot2d_Viewer::createView(SUIT_Desktop* theDesktop)
59 Plot2d_ViewWindow* aPlot2dView = new Plot2d_ViewWindow(theDesktop, this);
61 aPlot2dView->getViewFrame()->Display(myPrs);
66 Adds custom items to popup menu
67 \param thePopup - popup menu
69 void Plot2d_Viewer::contextMenuPopup(QMenu* thePopup)
71 Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)(myViewManager->getActiveView());
73 aView->contextMenuPopup(thePopup);
75 if (!thePopup->isEmpty())
76 thePopup->addSeparator();
77 thePopup->addAction( tr( "MNU_DUMP_VIEW" ), this, SLOT(onDumpView()));
78 thePopup->addAction( tr( "MEN_PLOT2D_CHANGE_BACKGROUND" ), this, SLOT(onChangeBgColor()));
81 if ( !aView->getToolBar()->isVisible() ) {
82 if (!thePopup->isEmpty())
83 thePopup->addSeparator();
84 thePopup->addAction("Show toolbar", this, SLOT(onShowToolbar()));
86 aView->RefreshDumpImage();
91 Sets presentation of viewer
92 \param thePrs - new presentation
94 void Plot2d_Viewer::setPrs(Plot2d_Prs* thePrs)
99 myPrs->setAutoDel(myAutoDel);
103 Updates current viewer
105 void Plot2d_Viewer::update()
107 SUIT_ViewManager* aMgr = getViewManager();
108 QVector<SUIT_ViewWindow*> aViews = aMgr->getViews();
109 unsigned int aSize = aViews.size();
110 for (uint i = 0; i < aSize; i++) {
111 Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)aViews[i];
113 aView->getViewFrame()->Display(myPrs);
118 Clear viewer presentation
120 void Plot2d_Viewer::clearPrs()
122 SUIT_ViewManager* aMgr = getViewManager();
123 QVector<SUIT_ViewWindow*> aViews = aMgr->getViews();
124 unsigned int aSize = aViews.size();
125 for (uint i = 0; i < aSize; i++) {
126 Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)aViews[i];
128 aView->getViewFrame()->Erase(myPrs);
130 if (myAutoDel && myPrs) {
137 Sets "auto delete" state of of presentation
138 \param theDel - new state
140 void Plot2d_Viewer::setAutoDel(bool theDel)
144 myPrs->setAutoDel(theDel);
148 SLOT: called when action "Change background" is activated
150 void Plot2d_Viewer::onChangeBgColor()
152 Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)(myViewManager->getActiveView());
155 Plot2d_ViewFrame* aViewFrame = aView->getViewFrame();
156 aViewFrame->onChangeBackground();
160 SLOT: called when action "Show toolbar" is activated
162 void Plot2d_Viewer::onShowToolbar() {
163 Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)(myViewManager->getActiveView());
165 aView->getToolBar()->show();
169 SLOT: called when action "Dump view" is activated
171 void Plot2d_Viewer::onDumpView()
173 Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)(myViewManager->getActiveView());
179 SLOT: called when action "Clone view" is activated
181 void Plot2d_Viewer::onCloneView( Plot2d_ViewFrame* clonedVF, Plot2d_ViewFrame* newVF )
183 if( !clonedVF || !newVF )
186 // 1) Copy all properties of view
188 newVF->copyPreferences( clonedVF );
190 // 2) Display all curves displayed in cloned view
193 clonedVF->getCurves( aCurves );
194 curveList::const_iterator anIt = aCurves.begin(), aLast = aCurves.end();
196 for( ; anIt!=aLast; anIt++ )
197 if( clonedVF->isVisible( *anIt ) )
198 newVF->displayCurve( *anIt, false );
203 // find view window corresponding to the frame
204 QWidget* p = newVF->parentWidget();
205 while( p && !p->inherits( "SUIT_ViewWindow" ) )
206 p = p->parentWidget();
209 if ( p && p->inherits( "SUIT_ViewWindow" ) )
210 emit viewCloned( (SUIT_ViewWindow*)p );
215 SLOT: called when clicked item in the legend from Plot2d_ViewManager
217 void Plot2d_Viewer::onLegendClicked( QwtPlotItem* plotItem )
223 \param mgr - new view manager
225 void Plot2d_Viewer::setViewManager( SUIT_ViewManager* mgr )
227 SUIT_ViewModel::setViewManager( mgr );
228 if( mgr && mgr->inherits( "Plot2d_ViewManager" ) )
230 Plot2d_ViewManager* pmgr = ( Plot2d_ViewManager* )mgr;
231 connect( pmgr, SIGNAL( cloneView( Plot2d_ViewFrame*, Plot2d_ViewFrame* ) ),
232 this, SLOT( onCloneView( Plot2d_ViewFrame*, Plot2d_ViewFrame* ) ) );