Salome HOME
Update from BR_V5_DEV 13Feb2009
[modules/gui.git] / src / Plot2d / Plot2d_ViewManager.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #include "Plot2d_ViewManager.h"
23 #include "Plot2d_ViewModel.h"
24 #include "Plot2d_ViewWindow.h"
25 #include "Plot2d_ViewFrame.h"
26
27 /*!
28   Constructor
29 */
30 Plot2d_ViewManager::Plot2d_ViewManager( SUIT_Study* study, SUIT_Desktop* desk ) 
31 : SUIT_ViewManager( study, desk, new Plot2d_Viewer() )
32 {
33   setTitle( tr( "PLOT2D_VIEW_TITLE" ) );
34 }
35
36 /*!
37   Destructor
38 */
39 Plot2d_ViewManager::~Plot2d_ViewManager()
40 {
41 }
42
43 /*!
44   \return corresponding viewer
45 */
46 Plot2d_Viewer* Plot2d_ViewManager::getPlot2dModel() const
47 {
48   return (Plot2d_Viewer*)myViewModel;
49 }
50
51 /*!
52   Adds new view
53   \param theView - view to be added
54 */
55 bool Plot2d_ViewManager::insertView( SUIT_ViewWindow* theView )
56 {
57   bool res = SUIT_ViewManager::insertView( theView );
58   if ( res )
59   {
60     Plot2d_ViewWindow* view = (Plot2d_ViewWindow*)theView;
61     connect( view, SIGNAL( cloneView() ), this, SLOT( onCloneView() ) );
62
63     Plot2d_ViewFrame* aViewFrame = view->getViewFrame();
64     Plot2d_Viewer* aViewer = getPlot2dModel();
65     connect( aViewFrame, SIGNAL( legendClicked( QwtPlotItem* ) ), 
66              aViewer, SLOT( onLegendClicked( QwtPlotItem* ) ) );
67   }
68   return res;
69 }
70
71 /*!
72   Creates new view
73 */
74 void Plot2d_ViewManager::createView()
75 {
76   createViewWindow();
77 }
78
79 /*!
80   SLOT: called if action "Clone view" is activated, emits signal cloneView()
81 */
82 void Plot2d_ViewManager::onCloneView()
83 {
84   if( sender() && sender()->inherits( "Plot2d_ViewWindow" ) )
85   {
86     Plot2d_ViewWindow* srcWnd = ( Plot2d_ViewWindow* )sender();
87     cloneView( srcWnd );
88   }
89 }
90
91 /*!
92   \brief Creates clone of source window
93   \param srcWnd source window
94   \return Pointer on the new window
95   \sa onCloneView()
96 */
97 Plot2d_ViewWindow* Plot2d_ViewManager::cloneView( Plot2d_ViewWindow* srcWnd )
98 {
99   SUIT_ViewWindow* vw = createViewWindow();
100
101   Plot2d_ViewWindow* newWnd = 0;
102   if( vw && vw->inherits( "Plot2d_ViewWindow" ) )
103     newWnd = ( Plot2d_ViewWindow* )vw;
104   
105   if( newWnd && srcWnd )
106     emit cloneView( srcWnd->getViewFrame(), newWnd->getViewFrame() );
107
108   return newWnd;
109 }