]> SALOME platform Git repositories - modules/gui.git/blob - src/Plot2d/Plot2d_ViewModel.cxx
Salome HOME
637351c9119d566fa550f6f70aac6f79a5f8d38b
[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 //////////////////////////////////////////////////////////////////////
22
23 #include "Plot2d_ViewModel.h"
24 #include "Plot2d_ViewWindow.h"
25 #include "Plot2d_ViewManager.h"
26 #include "Plot2d_ViewFrame.h"
27 #include "Plot2d_Prs.h"
28
29 #include <qpopupmenu.h>
30
31 Plot2d_Viewer::Plot2d_Viewer(bool theAutoDel)
32 :SUIT_ViewModel() 
33 {
34   myPrs = 0;
35   myAutoDel = theAutoDel;
36 }
37
38 Plot2d_Viewer::~Plot2d_Viewer()
39 {
40   if (myPrs)
41     clearPrs();
42 }
43
44 //*********************************************************************
45 SUIT_ViewWindow* Plot2d_Viewer::createView(SUIT_Desktop* theDesktop)
46 {
47   Plot2d_ViewWindow* aPlot2dView = new Plot2d_ViewWindow(theDesktop, this);
48   if (myPrs)
49     aPlot2dView->getViewFrame()->Display(myPrs);
50   return aPlot2dView;
51 }
52
53 //*********************************************************************
54 void Plot2d_Viewer::contextMenuPopup(QPopupMenu* thePopup)
55 {
56   Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)(myViewManager->getActiveView());
57   if ( aView )
58     aView->contextMenuPopup(thePopup);
59
60   if (thePopup->count() > 0) thePopup->insertSeparator();
61   thePopup->insertItem( tr( "MNU_DUMP_VIEW" ),                this, SLOT(onDumpView()));
62   thePopup->insertItem( tr( "MEN_PLOT2D_CHANGE_BACKGROUND" ), this, SLOT(onChangeBgColor()));
63
64   if ( aView ) {
65     if ( !aView->getToolBar()->isVisible() ) {
66       if (thePopup->count() > 0) thePopup->insertSeparator();
67         thePopup->insertItem("Show toolbar", this, SLOT(onShowToolbar()));
68     }
69   }
70 }
71
72
73 //*********************************************************************
74 void Plot2d_Viewer::setPrs(Plot2d_Prs* thePrs) 
75 {
76   if (myPrs)
77     clearPrs();
78   myPrs = thePrs;
79   myPrs->setAutoDel(myAutoDel);
80 }
81
82 //*********************************************************************
83 void Plot2d_Viewer::update()
84 {
85   SUIT_ViewManager* aMgr = getViewManager();
86   QPtrVector<SUIT_ViewWindow> aViews = aMgr->getViews();
87   unsigned int aSize = aViews.size();
88   for (uint i = 0; i < aSize; i++) {
89     Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)aViews[i];
90     if (myPrs && aView)
91       aView->getViewFrame()->Display(myPrs);
92   }
93 }
94
95 //*********************************************************************
96 void Plot2d_Viewer::clearPrs()
97 {
98   SUIT_ViewManager* aMgr = getViewManager();
99   QPtrVector<SUIT_ViewWindow> aViews = aMgr->getViews();
100   unsigned int aSize = aViews.size();
101   for (uint i = 0; i < aSize; i++) {
102     Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)aViews[i];
103     if (myPrs && aView)
104       aView->getViewFrame()->Erase(myPrs);
105   }
106   if (myAutoDel && myPrs) {
107     delete myPrs;
108   }
109   myPrs = 0;
110 }
111
112 //*********************************************************************
113 void Plot2d_Viewer::setAutoDel(bool theDel)
114 {
115   myAutoDel = theDel;
116   if (myPrs)
117     myPrs->setAutoDel(theDel);
118 }
119
120 //*********************************************************************
121 void Plot2d_Viewer::onChangeBgColor()
122 {
123   Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)(myViewManager->getActiveView());
124   if( !aView )
125     return;
126   Plot2d_ViewFrame* aViewFrame = aView->getViewFrame();
127   aViewFrame->onChangeBackground();
128 }
129
130 //*********************************************************************
131 void Plot2d_Viewer::onShowToolbar() {
132   Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)(myViewManager->getActiveView());
133   if ( aView )
134     aView->getToolBar()->show();    
135 }
136
137 //*********************************************************************
138 void Plot2d_Viewer::onDumpView()
139 {
140   Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)(myViewManager->getActiveView());
141   if ( aView )
142     aView->onDumpView();    
143 }
144
145 //*********************************************************************
146 void Plot2d_Viewer::onCloneView( Plot2d_ViewFrame*, Plot2d_ViewFrame* )
147 {
148 }
149 //*********************************************************************
150 void Plot2d_Viewer::setViewManager( SUIT_ViewManager* mgr )
151 {
152   SUIT_ViewModel::setViewManager( mgr );
153   if( mgr && mgr->inherits( "Plot2d_ViewManager" ) )
154   {
155     Plot2d_ViewManager* pmgr = ( Plot2d_ViewManager* )mgr;
156     connect( pmgr, SIGNAL( cloneView( Plot2d_ViewFrame*, Plot2d_ViewFrame* ) ),
157              this, SLOT( onCloneView( Plot2d_ViewFrame*, Plot2d_ViewFrame* ) ) );
158   }
159 }