Salome HOME
704e33095f2acdae5223e3fe275fec72d2c55acc
[modules/gui.git] / src / Plot2d / Plot2d_ViewManager.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 #include "Plot2d_ViewManager.h"
20 #include "Plot2d_ViewModel.h"
21 #include "Plot2d_ViewWindow.h"
22
23 int Plot2d_ViewManager::myMaxId = 0;
24
25 Plot2d_ViewManager::Plot2d_ViewManager( SUIT_Study* study, SUIT_Desktop* desk ) 
26 : SUIT_ViewManager( study, desk )
27 {
28   myId = ++myMaxId;
29   Plot2d_Viewer* v = new Plot2d_Viewer();
30   setViewModel( v );
31 }
32
33 Plot2d_ViewManager::~Plot2d_ViewManager()
34 {
35 }
36
37 Plot2d_Viewer* Plot2d_ViewManager::getPlot2dModel() const
38 {
39   return (Plot2d_Viewer*)myViewModel;
40 }
41
42 void Plot2d_ViewManager::setViewName( SUIT_ViewWindow* theView )
43 {
44   int aPos = myViews.find(theView);
45   theView->setCaption( QString( "Plot2d scene:%1 - viewer:%2" ).arg(myId).arg(aPos+1));
46 }
47
48 bool Plot2d_ViewManager::insertView( SUIT_ViewWindow* theView )
49 {
50   bool res = SUIT_ViewManager::insertView( theView );
51   if ( res )
52   {
53     Plot2d_ViewWindow* view = (Plot2d_ViewWindow*)theView;
54     connect( view, SIGNAL( cloneView() ), this, SLOT( onCloneView() ) );
55   }
56   return res;
57 }
58
59 void Plot2d_ViewManager::createView()
60 {
61   createViewWindow();
62 }
63
64 void Plot2d_ViewManager::onCloneView()
65 {
66   SUIT_ViewWindow* vw = createViewWindow();
67
68   Plot2d_ViewWindow  *newWnd = 0, *clonedWnd = 0;
69   if( vw && vw->inherits( "Plot2d_ViewWindow" ) )
70     newWnd = ( Plot2d_ViewWindow* )vw;
71   if( sender() && sender()->inherits( "Plot2d_ViewWindow" ) )
72     clonedWnd = ( Plot2d_ViewWindow* )sender();
73   
74   if( newWnd && clonedWnd )
75     emit cloneView( clonedWnd->getViewFrame(), newWnd->getViewFrame() );
76 }