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