Salome HOME
Initial version
[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("Change background...", this, SLOT(onChangeBgColor()));
40
41   if ( aView ) {
42     if ( !aView->getToolBar()->isVisible() ) {
43       if (thePopup->count() > 0) thePopup->insertSeparator();
44         thePopup->insertItem("Show toolbar", this, SLOT(onShowToolbar()));
45     }
46   }
47 }
48
49
50 //*********************************************************************
51 void Plot2d_Viewer::setPrs(Plot2d_Prs* thePrs) 
52 {
53   if (myPrs)
54     clearPrs();
55   myPrs = thePrs;
56   myPrs->setAutoDel(myAutoDel);
57 }
58
59 //*********************************************************************
60 void Plot2d_Viewer::update()
61 {
62   SUIT_ViewManager* aMgr = getViewManager();
63   QPtrVector<SUIT_ViewWindow> aViews = aMgr->getViews();
64   unsigned int aSize = aViews.size();
65   for (uint i = 0; i < aSize; i++) {
66     Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)aViews[i];
67     if (myPrs && aView)
68       aView->getViewFrame()->Display(myPrs);
69   }
70 }
71
72 //*********************************************************************
73 void Plot2d_Viewer::clearPrs()
74 {
75   SUIT_ViewManager* aMgr = getViewManager();
76   QPtrVector<SUIT_ViewWindow> aViews = aMgr->getViews();
77   unsigned int aSize = aViews.size();
78   for (uint i = 0; i < aSize; i++) {
79     Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)aViews[i];
80     if (myPrs && aView)
81       aView->getViewFrame()->Erase(myPrs);
82   }
83   if (myAutoDel && myPrs) {
84     delete myPrs;
85   }
86   myPrs = 0;
87 }
88
89 //*********************************************************************
90 void Plot2d_Viewer::setAutoDel(bool theDel)
91 {
92   myAutoDel = theDel;
93   if (myPrs)
94     myPrs->setAutoDel(theDel);
95 }
96
97 //*********************************************************************
98 void Plot2d_Viewer::onChangeBgColor()
99 {
100   Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)(myViewManager->getActiveView());
101   if( !aView )
102     return;
103   Plot2d_ViewFrame* aViewFrame = aView->getViewFrame();
104   aViewFrame->onChangeBackground();
105 }
106
107 //*********************************************************************
108 void Plot2d_Viewer::onShowToolbar() {
109   Plot2d_ViewWindow* aView = (Plot2d_ViewWindow*)(myViewManager->getActiveView());
110   if ( aView )
111     aView->getToolBar()->show();    
112 }