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::setSelectionColor( QColor(80,80,80) );
44 Plot2d_Object::setHighlightedLegendTextColor( QColor(255,255,255) );
50 Plot2d_Viewer::~Plot2d_Viewer()
57 Create new instance of view window on desktop \a theDesktop.
58 \retval SUIT_ViewWindow* - created view window pointer.
60 SUIT_ViewWindow* Plot2d_Viewer::createView(SUIT_Desktop* theDesktop)
62 Plot2d_ViewWindow* aView = new Plot2d_ViewWindow(theDesktop, this);
65 aView->getViewFrame()->Display(myPrs);
70 Adds custom items to popup menu
71 \param thePopup - popup menu
73 void Plot2d_Viewer::contextMenuPopup(QMenu* thePopup)
75 Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)(myViewManager->getActiveView());
77 aView->contextMenuPopup(thePopup);
79 if (!thePopup->isEmpty())
80 thePopup->addSeparator();
81 thePopup->addAction( tr( "MNU_DUMP_VIEW" ), this, SLOT(onDumpView()));
82 thePopup->addAction( tr( "MEN_PLOT2D_CHANGE_BACKGROUND" ), this, SLOT(onChangeBgColor()));
85 if ( !aView->getToolBar()->isVisible() ) {
86 if (!thePopup->isEmpty())
87 thePopup->addSeparator();
88 thePopup->addAction("Show toolbar", this, SLOT(onShowToolbar()));
90 aView->RefreshDumpImage();
95 Sets presentation of viewer
96 \param thePrs - new presentation
98 void Plot2d_Viewer::setPrs(Plot2d_Prs* thePrs)
103 myPrs->setAutoDel(myAutoDel);
107 Updates current viewer
109 void Plot2d_Viewer::update()
111 SUIT_ViewManager* aMgr = getViewManager();
112 QVector<SUIT_ViewWindow*> aViews = aMgr->getViews();
113 unsigned int aSize = aViews.size();
114 for (uint i = 0; i < aSize; i++) {
115 Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)aViews[i];
117 aView->getViewFrame()->Display(myPrs);
122 Clear viewer presentation
124 void Plot2d_Viewer::clearPrs()
126 SUIT_ViewManager* aMgr = getViewManager();
127 QVector<SUIT_ViewWindow*> aViews;
129 aViews = aMgr->getViews();
130 unsigned int aSize = aViews.size();
131 for (uint i = 0; i < aSize; i++) {
132 Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)aViews[i];
134 aView->getViewFrame()->Erase(myPrs);
136 if (myAutoDel && myPrs) {
143 Sets "auto delete" state of of presentation
144 \param theDel - new state
146 void Plot2d_Viewer::setAutoDel(bool theDel)
150 myPrs->setAutoDel(theDel);
154 SLOT: called when action "Change background" is activated
156 void Plot2d_Viewer::onChangeBgColor()
158 Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)(myViewManager->getActiveView());
161 Plot2d_ViewFrame* aViewFrame = aView->getViewFrame();
162 aViewFrame->onChangeBackground();
166 SLOT: called when action "Show toolbar" is activated
168 void Plot2d_Viewer::onShowToolbar() {
169 Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)(myViewManager->getActiveView());
171 aView->getToolBar()->show();
175 SLOT: called when action "Dump view" is activated
177 void Plot2d_Viewer::onDumpView()
179 Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)(myViewManager->getActiveView());
185 SLOT: called when action "Clone view" is activated
187 void Plot2d_Viewer::onCloneView( Plot2d_ViewFrame* clonedVF, Plot2d_ViewFrame* newVF )
189 if( !clonedVF || !newVF )
192 // 1) Copy all properties of view
194 newVF->copyPreferences( clonedVF );
196 // 2) Display all curves displayed in cloned view
199 clonedVF->getCurves( aCurves );
200 curveList::const_iterator anIt = aCurves.begin(), aLast = aCurves.end();
202 for( ; anIt!=aLast; anIt++ )
203 if( clonedVF->isVisible( *anIt ) )
204 newVF->displayCurve( *anIt, false );
209 // find view window corresponding to the frame
210 QWidget* p = newVF->parentWidget();
211 while( p && !p->inherits( "SUIT_ViewWindow" ) )
212 p = p->parentWidget();
215 if ( p && p->inherits( "SUIT_ViewWindow" ) )
216 emit viewCloned( (SUIT_ViewWindow*)p );
221 SLOT: called when clicked item in the legend from Plot2d_ViewManager
223 void Plot2d_Viewer::onClicked(const QVariant& itemInfo, int index)
229 \param mgr - new view manager
231 void Plot2d_Viewer::setViewManager( SUIT_ViewManager* mgr )
233 SUIT_ViewModel::setViewManager( mgr );
234 if( mgr && mgr->inherits( "Plot2d_ViewManager" ) )
236 Plot2d_ViewManager* pmgr = ( Plot2d_ViewManager* )mgr;
237 connect( pmgr, SIGNAL( cloneView( Plot2d_ViewFrame*, Plot2d_ViewFrame* ) ),
238 this, SLOT( onCloneView( Plot2d_ViewFrame*, Plot2d_ViewFrame* ) ) );