]> SALOME platform Git repositories - modules/visu.git/blob - src/VISUGUI/VisuGUI_ViewExtender.cxx
Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/visu.git] / src / VISUGUI / VisuGUI_ViewExtender.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 //  VISU VISUGUI : GUI of VISU component
23 //  File   : VisuGUI_ViewExtender.cxx
24 //  Author : Vitaly Smetannikov
25 //  Module : VISU
26 //
27 #include "VisuGUI_ViewExtender.h"
28
29 #include "VisuGUI.h"
30 #include "VisuGUI_SegmentationMgr.h"
31 #include "VisuGUI_ViewTools.h"
32 #include "VisuGUI_Tools.h"
33 #include <VTKViewer_Actor.h>
34
35 #include <LightApp_SelectionMgr.h>
36 #include <SalomeApp_Application.h>
37
38 #include <VISU_PipeLine.hxx>
39 #include <SUIT_ViewManager.h>
40 #include <SUIT_ViewWindow.h>
41
42 #include <SVTK_ViewModel.h>
43 #include <SVTK_ViewWindow.h>
44
45
46
47 //using namespace std;
48
49 VisuGUI_ViewExtender::VisuGUI_ViewExtender(VisuGUI* theModule):
50   myModule(theModule)
51 {
52 }
53
54 //****************************************************************
55 VisuGUI_ViewExtender::~VisuGUI_ViewExtender()
56 {
57   QMapIterator<SVTK_ViewWindow*, VisuGUI_SegmentationMgr*> aIt(myViewMgrMap);
58   while (aIt.hasNext()) {
59     aIt.next();
60     delete aIt.value();
61   }
62 }
63
64 //****************************************************************
65 int VisuGUI_ViewExtender::createToolbar(SUIT_ViewWindow* theView)
66 {
67   SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>(theView);
68   if (!aViewWindow) return -1;
69
70   VisuGUI_SegmentationMgr* aMgr = getSegmentationMgr(aViewWindow);
71   return aMgr->createToolbar(theView->toolMgr());
72 }
73
74 //****************************************************************
75 void VisuGUI_ViewExtender::contextMenuPopup(QMenu* theMenu)
76 {
77 //   SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow<SVTK_ViewWindow>(myModule);
78 //   if (!aViewWindow) return;
79
80 //   SalomeApp_Application* anApp = myModule->getApp();
81 //   LightApp_SelectionMgr* aSelectionMgr = VISU::GetSelectionMgr(myModule);
82 //   myListIO.Clear();
83 //   aSelectionMgr->selectedObjects(myListIO);
84 //   if (myListIO.IsEmpty()) return;
85
86 //   theMenu->addSeparator();
87 //   theMenu->addAction(tr("VISU_SETPLANES_MNU"), this, SLOT(onSetPlanes()));
88 }
89
90
91 //****************************************************************
92 void VisuGUI_ViewExtender::activate(SUIT_ViewModel* theViewer)
93 {
94   // Connect to signal on destroy ViewWindow
95   SVTK_Viewer* aViewer = dynamic_cast<SVTK_Viewer*>(theViewer);
96   if (aViewer) {
97     if (!myViewers.contains(aViewer)) {
98       SUIT_ViewManager* aMgr = aViewer->getViewManager();
99       connect(aMgr, SIGNAL(deleteView(SUIT_ViewWindow*)), 
100               this, SLOT(onViewDeleted(SUIT_ViewWindow*)));
101       connect(aViewer, SIGNAL(actorAdded(SVTK_ViewWindow*, VTKViewer_Actor*)), 
102               this, SLOT(onAddActor(SVTK_ViewWindow*, VTKViewer_Actor*)));
103       myViewers.append(aViewer);
104     }
105   }
106 }
107
108 //****************************************************************
109 void VisuGUI_ViewExtender::deactivate(SUIT_ViewModel*)
110 {
111   QMapIterator<SVTK_ViewWindow*, VisuGUI_SegmentationMgr*> aIt(myViewMgrMap);
112   while (aIt.hasNext()) {
113     aIt.next();
114     aIt.value()->deactivate();
115   }
116 }
117
118
119 //****************************************************************
120 VisuGUI_SegmentationMgr* VisuGUI_ViewExtender::getSegmentationMgr(SVTK_ViewWindow* theWindow)
121 {
122   if (myViewMgrMap.contains(theWindow)) 
123     return myViewMgrMap[theWindow];
124   
125   VisuGUI_SegmentationMgr* aMgr = new VisuGUI_SegmentationMgr(myModule, theWindow);
126   myViewMgrMap[theWindow] = aMgr;
127   return aMgr;
128 }
129
130 //****************************************************************
131 void VisuGUI_ViewExtender::onViewDeleted(SUIT_ViewWindow* theWindow)
132 {
133   SVTK_ViewWindow* aWindow = dynamic_cast<SVTK_ViewWindow*>(theWindow);
134   if (!aWindow) return;
135
136   if (!myViewMgrMap.contains(aWindow)) return;
137   delete myViewMgrMap[aWindow];
138   myViewMgrMap.remove(aWindow);
139 }
140
141 //****************************************************************
142 void VisuGUI_ViewExtender::onAddActor(SVTK_ViewWindow* theWindow, VTKViewer_Actor* theActor)
143 {
144   if (!myViewMgrMap.contains(theWindow)) return;
145   myViewMgrMap[theWindow]->onAddActor(theActor);
146 }