1 // Copyright (C) 2007-2014 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, or (at your option) any later version.
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 // Plot2d_ViewModel.cxx: implementation of the Plot2d_ViewModel class.
25 #include "Plot2d_ViewModel.h"
26 #include "Plot2d_ViewWindow.h"
27 #include "Plot2d_ViewManager.h"
28 #include "Plot2d_ViewFrame.h"
29 #include "Plot2d_Prs.h"
38 Plot2d_Viewer::Plot2d_Viewer(bool theAutoDel)
42 myAutoDel = theAutoDel;
43 Plot2d_Object::initColors();
49 Plot2d_Viewer::~Plot2d_Viewer()
56 Create new instance of view window on desktop \a theDesktop.
57 \retval SUIT_ViewWindow* - created view window pointer.
59 SUIT_ViewWindow* Plot2d_Viewer::createView(SUIT_Desktop* theDesktop)
61 Plot2d_ViewWindow* aView = new Plot2d_ViewWindow(theDesktop, this);
64 aView->getViewFrame()->Display(myPrs);
69 Adds custom items to popup menu
70 \param thePopup - popup menu
72 void Plot2d_Viewer::contextMenuPopup(QMenu* thePopup)
74 Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)(myViewManager->getActiveView());
76 aView->contextMenuPopup(thePopup);
78 if (!thePopup->isEmpty())
79 thePopup->addSeparator();
80 thePopup->addAction( tr( "MNU_DUMP_VIEW" ), this, SLOT(onDumpView()));
81 thePopup->addAction( tr( "MEN_PLOT2D_CHANGE_BACKGROUND" ), this, SLOT(onChangeBgColor()));
84 if ( !aView->getToolBar()->isVisible() ) {
85 if (!thePopup->isEmpty())
86 thePopup->addSeparator();
87 thePopup->addAction("Show toolbar", this, SLOT(onShowToolbar()));
89 aView->RefreshDumpImage();
94 Sets presentation of viewer
95 \param thePrs - new presentation
97 void Plot2d_Viewer::setPrs(Plot2d_Prs* thePrs)
102 myPrs->setAutoDel(myAutoDel);
106 Updates current viewer
108 void Plot2d_Viewer::update()
110 SUIT_ViewManager* aMgr = getViewManager();
111 QVector<SUIT_ViewWindow*> aViews = aMgr->getViews();
112 unsigned int aSize = aViews.size();
113 for (uint i = 0; i < aSize; i++) {
114 Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)aViews[i];
116 aView->getViewFrame()->Display(myPrs);
121 Clear viewer presentation
123 void Plot2d_Viewer::clearPrs()
125 SUIT_ViewManager* aMgr = getViewManager();
126 QVector<SUIT_ViewWindow*> aViews;
128 aViews = aMgr->getViews();
129 unsigned int aSize = aViews.size();
130 for (uint i = 0; i < aSize; i++) {
131 Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)aViews[i];
133 aView->getViewFrame()->Erase(myPrs);
135 if (myAutoDel && myPrs) {
142 Sets "auto delete" state of of presentation
143 \param theDel - new state
145 void Plot2d_Viewer::setAutoDel(bool theDel)
149 myPrs->setAutoDel(theDel);
153 SLOT: called when action "Change background" is activated
155 void Plot2d_Viewer::onChangeBgColor()
157 Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)(myViewManager->getActiveView());
160 Plot2d_ViewFrame* aViewFrame = aView->getViewFrame();
161 aViewFrame->onChangeBackground();
165 SLOT: called when action "Show toolbar" is activated
167 void Plot2d_Viewer::onShowToolbar() {
168 Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)(myViewManager->getActiveView());
170 aView->getToolBar()->show();
174 SLOT: called when action "Dump view" is activated
176 void Plot2d_Viewer::onDumpView()
178 Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)(myViewManager->getActiveView());
184 SLOT: called when action "Clone view" is activated
186 void Plot2d_Viewer::onCloneView( Plot2d_ViewFrame* clonedVF, Plot2d_ViewFrame* newVF )
188 if( !clonedVF || !newVF )
191 // 1) Copy all properties of view
193 newVF->copyPreferences( clonedVF );
195 // 2) Display all curves displayed in cloned view
198 clonedVF->getCurves( aCurves );
199 curveList::const_iterator anIt = aCurves.begin(), aLast = aCurves.end();
201 for( ; anIt!=aLast; anIt++ )
202 if( clonedVF->isVisible( *anIt ) )
203 newVF->displayCurve( *anIt, false );
208 // find view window corresponding to the frame
209 QWidget* p = newVF->parentWidget();
210 while( p && !p->inherits( "SUIT_ViewWindow" ) )
211 p = p->parentWidget();
214 if ( p && p->inherits( "SUIT_ViewWindow" ) )
215 emit viewCloned( (SUIT_ViewWindow*)p );
220 SLOT: called when clicked item in the legend from Plot2d_ViewManager
222 void Plot2d_Viewer::onLegendClicked( QwtPlotItem* plotItem )
228 \param mgr - new view manager
230 void Plot2d_Viewer::setViewManager( SUIT_ViewManager* mgr )
232 SUIT_ViewModel::setViewManager( mgr );
233 if( mgr && mgr->inherits( "Plot2d_ViewManager" ) )
235 Plot2d_ViewManager* pmgr = ( Plot2d_ViewManager* )mgr;
236 connect( pmgr, SIGNAL( cloneView( Plot2d_ViewFrame*, Plot2d_ViewFrame* ) ),
237 this, SLOT( onCloneView( Plot2d_ViewFrame*, Plot2d_ViewFrame* ) ) );