1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Plot2d_ViewModel.cxx: implementation of the Plot2d_ViewModel class.
21 #include "Plot2d_ViewModel.h"
22 #include "Plot2d_ViewWindow.h"
23 #include "Plot2d_ViewManager.h"
24 #include "Plot2d_ViewFrame.h"
25 #include "Plot2d_Prs.h"
27 #include <qpopupmenu.h>
32 Plot2d_Viewer::Plot2d_Viewer(bool theAutoDel)
36 myAutoDel = theAutoDel;
42 Plot2d_Viewer::~Plot2d_Viewer()
49 Create new instance of view window on desktop \a theDesktop.
50 \retval SUIT_ViewWindow* - created view window pointer.
52 SUIT_ViewWindow* Plot2d_Viewer::createView(SUIT_Desktop* theDesktop)
54 Plot2d_ViewWindow* aPlot2dView = new Plot2d_ViewWindow(theDesktop, this);
56 aPlot2dView->getViewFrame()->Display(myPrs);
61 Adds custom items to popup menu
62 \param thePopup - popup menu
64 void Plot2d_Viewer::contextMenuPopup(QPopupMenu* thePopup)
66 Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)(myViewManager->getActiveView());
68 aView->contextMenuPopup(thePopup);
70 if (thePopup->count() > 0) thePopup->insertSeparator();
71 thePopup->insertItem( tr( "MNU_DUMP_VIEW" ), this, SLOT(onDumpView()));
72 thePopup->insertItem( tr( "MEN_PLOT2D_CHANGE_BACKGROUND" ), this, SLOT(onChangeBgColor()));
75 if ( !aView->getToolBar()->isVisible() ) {
76 if (thePopup->count() > 0) thePopup->insertSeparator();
77 thePopup->insertItem("Show toolbar", this, SLOT(onShowToolbar()));
79 aView->RefreshDumpImage();
84 Sets presentation of viewer
85 \param thePrs - new presentation
87 void Plot2d_Viewer::setPrs(Plot2d_Prs* thePrs)
92 myPrs->setAutoDel(myAutoDel);
96 Updates current viewer
98 void Plot2d_Viewer::update()
100 SUIT_ViewManager* aMgr = getViewManager();
101 QPtrVector<SUIT_ViewWindow> aViews = aMgr->getViews();
102 unsigned int aSize = aViews.size();
103 for (uint i = 0; i < aSize; i++) {
104 Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)aViews[i];
106 aView->getViewFrame()->Display(myPrs);
111 Clear viewer presentation
113 void Plot2d_Viewer::clearPrs()
115 SUIT_ViewManager* aMgr = getViewManager();
116 QPtrVector<SUIT_ViewWindow> aViews = aMgr->getViews();
117 unsigned int aSize = aViews.size();
118 for (uint i = 0; i < aSize; i++) {
119 Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)aViews[i];
121 aView->getViewFrame()->Erase(myPrs);
123 if (myAutoDel && myPrs) {
130 Sets "auto delete" state of of presentation
131 \param theDel - new state
133 void Plot2d_Viewer::setAutoDel(bool theDel)
137 myPrs->setAutoDel(theDel);
141 SLOT: called when action "Change background" is activated
143 void Plot2d_Viewer::onChangeBgColor()
145 Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)(myViewManager->getActiveView());
148 Plot2d_ViewFrame* aViewFrame = aView->getViewFrame();
149 aViewFrame->onChangeBackground();
153 SLOT: called when action "Show toolbar" is activated
155 void Plot2d_Viewer::onShowToolbar() {
156 Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)(myViewManager->getActiveView());
158 aView->getToolBar()->show();
162 SLOT: called when action "Dump view" is activated
164 void Plot2d_Viewer::onDumpView()
166 Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)(myViewManager->getActiveView());
172 SLOT: called when action "Clone view" is activated
174 void Plot2d_Viewer::onCloneView( Plot2d_ViewFrame*, Plot2d_ViewFrame* )
180 \param mgr - new view manager
182 void Plot2d_Viewer::setViewManager( SUIT_ViewManager* mgr )
184 SUIT_ViewModel::setViewManager( mgr );
185 if( mgr && mgr->inherits( "Plot2d_ViewManager" ) )
187 Plot2d_ViewManager* pmgr = ( Plot2d_ViewManager* )mgr;
188 connect( pmgr, SIGNAL( cloneView( Plot2d_ViewFrame*, Plot2d_ViewFrame* ) ),
189 this, SLOT( onCloneView( Plot2d_ViewFrame*, Plot2d_ViewFrame* ) ) );