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