1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // VISU VISUGUI : GUI of VISU component
21 // File : VisuGUI_ViewExtender.cxx
22 // Author : Vitaly Smetannikov
25 #include "VisuGUI_ViewExtender.h"
28 #include "VisuGUI_SegmentationMgr.h"
29 #include "VisuGUI_ViewTools.h"
30 #include "VisuGUI_Tools.h"
31 #include <VTKViewer_Actor.h>
33 #include <LightApp_SelectionMgr.h>
34 #include <SalomeApp_Application.h>
36 #include <VISU_PipeLine.hxx>
37 #include <SUIT_ViewManager.h>
38 #include <SUIT_ViewWindow.h>
40 #include <SVTK_ViewModel.h>
41 #include <SVTK_ViewWindow.h>
45 //using namespace std;
47 VisuGUI_ViewExtender::VisuGUI_ViewExtender(VisuGUI* theModule):
52 //****************************************************************
53 VisuGUI_ViewExtender::~VisuGUI_ViewExtender()
55 QMapIterator<SVTK_ViewWindow*, VisuGUI_SegmentationMgr*> aIt(myViewMgrMap);
56 while (aIt.hasNext()) {
62 //****************************************************************
63 int VisuGUI_ViewExtender::createToolbar(SUIT_ViewWindow* theView)
65 SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>(theView);
66 if (!aViewWindow) return -1;
68 VisuGUI_SegmentationMgr* aMgr = getSegmentationMgr(aViewWindow);
69 return aMgr->createToolbar(theView->toolMgr());
72 //****************************************************************
73 void VisuGUI_ViewExtender::contextMenuPopup(QMenu* theMenu)
75 // SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow<SVTK_ViewWindow>(myModule);
76 // if (!aViewWindow) return;
78 // SalomeApp_Application* anApp = myModule->getApp();
79 // LightApp_SelectionMgr* aSelectionMgr = VISU::GetSelectionMgr(myModule);
81 // aSelectionMgr->selectedObjects(myListIO);
82 // if (myListIO.IsEmpty()) return;
84 // theMenu->addSeparator();
85 // theMenu->addAction(tr("VISU_SETPLANES_MNU"), this, SLOT(onSetPlanes()));
89 //****************************************************************
90 void VisuGUI_ViewExtender::activate(SUIT_ViewModel* theViewer)
92 // Connect to signal on destroy ViewWindow
93 SVTK_Viewer* aViewer = dynamic_cast<SVTK_Viewer*>(theViewer);
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);
106 //****************************************************************
107 void VisuGUI_ViewExtender::deactivate(SUIT_ViewModel*)
109 QMapIterator<SVTK_ViewWindow*, VisuGUI_SegmentationMgr*> aIt(myViewMgrMap);
110 while (aIt.hasNext()) {
112 aIt.value()->deactivate();
117 //****************************************************************
118 VisuGUI_SegmentationMgr* VisuGUI_ViewExtender::getSegmentationMgr(SVTK_ViewWindow* theWindow)
120 if (myViewMgrMap.contains(theWindow))
121 return myViewMgrMap[theWindow];
123 VisuGUI_SegmentationMgr* aMgr = new VisuGUI_SegmentationMgr(myModule, theWindow);
124 myViewMgrMap[theWindow] = aMgr;
128 //****************************************************************
129 void VisuGUI_ViewExtender::onViewDeleted(SUIT_ViewWindow* theWindow)
131 SVTK_ViewWindow* aWindow = dynamic_cast<SVTK_ViewWindow*>(theWindow);
132 if (!aWindow) return;
134 if (!myViewMgrMap.contains(aWindow)) return;
135 delete myViewMgrMap[aWindow];
136 myViewMgrMap.remove(aWindow);
139 //****************************************************************
140 void VisuGUI_ViewExtender::onAddActor(SVTK_ViewWindow* theWindow, VTKViewer_Actor* theActor)
142 if (!myViewMgrMap.contains(theWindow)) return;
143 myViewMgrMap[theWindow]->onAddActor(theActor);