]> SALOME platform Git repositories - modules/gui.git/blob - src/Plot2d/Plot2d_ViewModel.cxx
Salome HOME
30cd483b28212eaf1f9c8c48e4484b20eb24ce30
[modules/gui.git] / src / Plot2d / Plot2d_ViewModel.cxx
1 // Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
2 // 
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.
7 // 
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/
18 //
19 // Plot2d_ViewModel.cxx: implementation of the Plot2d_ViewModel class.
20
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"
26
27 #include <qpopupmenu.h>
28
29 /*!
30   Constructor
31 */
32 Plot2d_Viewer::Plot2d_Viewer(bool theAutoDel)
33 :SUIT_ViewModel() 
34 {
35   myPrs = 0;
36   myAutoDel = theAutoDel;
37 }
38
39 /*!
40   Destructor
41 */
42 Plot2d_Viewer::~Plot2d_Viewer()
43 {
44   if (myPrs)
45     clearPrs();
46 }
47
48 /*!
49   Create new instance of view window on desktop \a theDesktop.
50   \retval SUIT_ViewWindow* - created view window pointer.
51 */
52 SUIT_ViewWindow* Plot2d_Viewer::createView(SUIT_Desktop* theDesktop)
53 {
54   Plot2d_ViewWindow* aPlot2dView = new Plot2d_ViewWindow(theDesktop, this);
55   if (myPrs)
56     aPlot2dView->getViewFrame()->Display(myPrs);
57   return aPlot2dView;
58 }
59
60 /*!
61   Adds custom items to popup menu
62   \param thePopup - popup menu
63 */
64 void Plot2d_Viewer::contextMenuPopup(QPopupMenu* thePopup)
65 {
66   Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)(myViewManager->getActiveView());
67   if ( aView )
68     aView->contextMenuPopup(thePopup);
69
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()));
73
74   if ( aView ) {
75     if ( !aView->getToolBar()->isVisible() ) {
76       if (thePopup->count() > 0) thePopup->insertSeparator();
77         thePopup->insertItem("Show toolbar", this, SLOT(onShowToolbar()));
78     }
79   }
80 }
81
82 /*!
83   Sets presentation of viewer
84   \param thePrs - new presentation
85 */
86 void Plot2d_Viewer::setPrs(Plot2d_Prs* thePrs) 
87 {
88   if (myPrs)
89     clearPrs();
90   myPrs = thePrs;
91   myPrs->setAutoDel(myAutoDel);
92 }
93
94 /*!
95   Updates current viewer
96 */
97 void Plot2d_Viewer::update()
98 {
99   SUIT_ViewManager* aMgr = getViewManager();
100   QPtrVector<SUIT_ViewWindow> aViews = aMgr->getViews();
101   unsigned int aSize = aViews.size();
102   for (uint i = 0; i < aSize; i++) {
103     Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)aViews[i];
104     if (myPrs && aView)
105       aView->getViewFrame()->Display(myPrs);
106   }
107 }
108
109 /*!
110   Clear viewer presentation
111 */
112 void Plot2d_Viewer::clearPrs()
113 {
114   SUIT_ViewManager* aMgr = getViewManager();
115   QPtrVector<SUIT_ViewWindow> aViews = aMgr->getViews();
116   unsigned int aSize = aViews.size();
117   for (uint i = 0; i < aSize; i++) {
118     Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)aViews[i];
119     if (myPrs && aView)
120       aView->getViewFrame()->Erase(myPrs);
121   }
122   if (myAutoDel && myPrs) {
123     delete myPrs;
124   }
125   myPrs = 0;
126 }
127
128 /*!
129   Sets "auto delete" state of of presentation
130   \param theDel - new state
131 */
132 void Plot2d_Viewer::setAutoDel(bool theDel)
133 {
134   myAutoDel = theDel;
135   if (myPrs)
136     myPrs->setAutoDel(theDel);
137 }
138
139 /*!
140   SLOT: called when action "Change background" is activated
141 */
142 void Plot2d_Viewer::onChangeBgColor()
143 {
144   Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)(myViewManager->getActiveView());
145   if( !aView )
146     return;
147   Plot2d_ViewFrame* aViewFrame = aView->getViewFrame();
148   aViewFrame->onChangeBackground();
149 }
150
151 /*!
152   SLOT: called when action "Show toolbar" is activated
153 */
154 void Plot2d_Viewer::onShowToolbar() {
155   Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)(myViewManager->getActiveView());
156   if ( aView )
157     aView->getToolBar()->show();    
158 }
159
160 /*!
161   SLOT: called when action "Dump view" is activated
162 */
163 void Plot2d_Viewer::onDumpView()
164 {
165   Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)(myViewManager->getActiveView());
166   if ( aView )
167     aView->onDumpView();    
168 }
169
170 /*!
171   SLOT: called when action "Clone view" is activated
172 */
173 void Plot2d_Viewer::onCloneView( Plot2d_ViewFrame*, Plot2d_ViewFrame* )
174 {
175 }
176
177 /*!
178   Sets view manager
179   \param mgr - new view manager
180 */
181 void Plot2d_Viewer::setViewManager( SUIT_ViewManager* mgr )
182 {
183   SUIT_ViewModel::setViewManager( mgr );
184   if( mgr && mgr->inherits( "Plot2d_ViewManager" ) )
185   {
186     Plot2d_ViewManager* pmgr = ( Plot2d_ViewManager* )mgr;
187     connect( pmgr, SIGNAL( cloneView( Plot2d_ViewFrame*, Plot2d_ViewFrame* ) ),
188              this, SLOT( onCloneView( Plot2d_ViewFrame*, Plot2d_ViewFrame* ) ) );
189   }
190 }