Salome HOME
*** empty log message ***
[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
8
9 Plot2d_Viewer::Plot2d_Viewer(bool theAutoDel)
10 :SUIT_ViewModel() 
11 {
12   myPrs = 0;
13   myAutoDel = theAutoDel;
14 }
15
16 Plot2d_Viewer::~Plot2d_Viewer()
17 {
18   if (myPrs)
19     clearPrs();
20 }
21
22 //*********************************************************************
23 SUIT_ViewWindow* Plot2d_Viewer::createView(SUIT_Desktop* theDesktop)
24 {
25   Plot2d_ViewWindow* aPlot2dView = new Plot2d_ViewWindow(theDesktop, this);
26   if (myPrs)
27     aPlot2dView->getViewFrame()->Display(myPrs);
28   return aPlot2dView;
29 }
30
31 //*********************************************************************
32 void Plot2d_Viewer::contextMenuPopup(QPopupMenu* thePopup)
33 {
34   Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)(myViewManager->getActiveView());
35   if ( aView )
36     aView->contextMenuPopup(thePopup);
37
38   if (thePopup->count() > 0) thePopup->insertSeparator();
39   thePopup->insertItem( tr( "MNU_DUMP_VIEW" ),                this, SLOT(onDumpView()));
40   thePopup->insertItem( tr( "MEN_PLOT2D_CHANGE_BACKGROUND" ), this, SLOT(onChangeBgColor()));
41
42   if ( aView ) {
43     if ( !aView->getToolBar()->isVisible() ) {
44       if (thePopup->count() > 0) thePopup->insertSeparator();
45         thePopup->insertItem("Show toolbar", this, SLOT(onShowToolbar()));
46     }
47   }
48 }
49
50
51 //*********************************************************************
52 void Plot2d_Viewer::setPrs(Plot2d_Prs* thePrs) 
53 {
54   if (myPrs)
55     clearPrs();
56   myPrs = thePrs;
57   myPrs->setAutoDel(myAutoDel);
58 }
59
60 //*********************************************************************
61 void Plot2d_Viewer::update()
62 {
63   SUIT_ViewManager* aMgr = getViewManager();
64   QPtrVector<SUIT_ViewWindow> aViews = aMgr->getViews();
65   unsigned int aSize = aViews.size();
66   for (uint i = 0; i < aSize; i++) {
67     Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)aViews[i];
68     if (myPrs && aView)
69       aView->getViewFrame()->Display(myPrs);
70   }
71 }
72
73 //*********************************************************************
74 void Plot2d_Viewer::clearPrs()
75 {
76   SUIT_ViewManager* aMgr = getViewManager();
77   QPtrVector<SUIT_ViewWindow> aViews = aMgr->getViews();
78   unsigned int aSize = aViews.size();
79   for (uint i = 0; i < aSize; i++) {
80     Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)aViews[i];
81     if (myPrs && aView)
82       aView->getViewFrame()->Erase(myPrs);
83   }
84   if (myAutoDel && myPrs) {
85     delete myPrs;
86   }
87   myPrs = 0;
88 }
89
90 //*********************************************************************
91 void Plot2d_Viewer::setAutoDel(bool theDel)
92 {
93   myAutoDel = theDel;
94   if (myPrs)
95     myPrs->setAutoDel(theDel);
96 }
97
98 //*********************************************************************
99 void Plot2d_Viewer::onChangeBgColor()
100 {
101   Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)(myViewManager->getActiveView());
102   if( !aView )
103     return;
104   Plot2d_ViewFrame* aViewFrame = aView->getViewFrame();
105   aViewFrame->onChangeBackground();
106 }
107
108 //*********************************************************************
109 void Plot2d_Viewer::onShowToolbar() {
110   Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)(myViewManager->getActiveView());
111   if ( aView )
112     aView->getToolBar()->show();    
113 }
114
115 //*********************************************************************
116 void Plot2d_Viewer::onDumpView()
117 {
118   Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)(myViewManager->getActiveView());
119   if ( aView )
120     aView->onDumpView();    
121 }