]> SALOME platform Git repositories - modules/geom.git/blob - src/DependencyTree/DependencyTree_ViewModel.cxx
Salome HOME
e6c853008bd140760a7284ef01928bbd197e482c
[modules/geom.git] / src / DependencyTree / DependencyTree_ViewModel.cxx
1 // Copyright (C) 2014  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, or (at your option) any later version.
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 // internal includes
21 #include "DependencyTree_ViewModel.h"
22 #include "DependencyTree_View.h"
23
24 // GUI includes
25 #include <SUIT_Session.h>
26 #include <SalomeApp_Study.h>
27 #include <LightApp_SelectionMgr.h>
28 #include <SALOME_ListIteratorOfListIO.hxx>
29 #include <SALOME_ListIO.hxx>
30 #include <OCCViewer_ViewManager.h>
31
32 // GEOM includes
33 #include <GEOM_Displayer.h>
34 #include <GeometryGUI_Operations.h>
35
36 // QT includes
37 #include <QMenu>
38
39 DependencyTree_ViewModel::DependencyTree_ViewModel( const QString& title )
40 : GraphicsView_Viewer( title )
41 {
42 }
43
44 DependencyTree_ViewModel::DependencyTree_ViewModel( const QString& title, QWidget* w )
45 : GraphicsView_Viewer( title,  w )
46 {
47 }
48
49 DependencyTree_ViewModel::~DependencyTree_ViewModel()
50 {
51 }
52
53 //=================================================================================
54 // function : onShowSelected()
55 // purpose  : slot for showing selected objects in OCC Viewer
56 //=================================================================================
57 void DependencyTree_ViewModel::onShowSelected()
58 {
59   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
60   if ( !app ) return;
61
62   app->getViewManager( OCCViewer_Viewer::Type(), /*create=*/ true );
63
64   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
65   if ( !aSelMgr ) return;
66
67   SALOME_ListIO aSelList;
68   aSelMgr->selectedObjects(aSelList);
69
70   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
71   GEOM_Displayer* disp = new GEOM_Displayer( appStudy );
72
73   OCCViewer_ViewManager* anOCCVM = ( OCCViewer_ViewManager* ) app->getViewManager( OCCViewer_Viewer::Type(), /*create=*/ true );
74
75   if ( SUIT_ViewModel* viewModel = anOCCVM->getViewModel() ) {
76     if ( SALOME_View* viewFrame = dynamic_cast<SALOME_View*>( viewModel ) ) {
77       SALOME_ListIteratorOfListIO Iter( aSelList );
78       for ( ; Iter.More(); Iter.Next() )
79         disp->Display( Iter.Value(), false, viewFrame );
80       viewFrame->Repaint();
81     }
82   }
83 }
84
85 //=================================================================================
86 // function : onShowOnlySelected()
87 // purpose  : slot for showing only selected objects in OCC Viewer
88 //=================================================================================
89 void DependencyTree_ViewModel::onShowOnlySelected()
90 {
91   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
92   if ( !app ) return;
93
94   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
95   if ( !aSelMgr ) return;
96
97   SALOME_ListIO aSelList;
98   aSelMgr->selectedObjects( aSelList );
99
100   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
101   GEOM_Displayer* disp = new GEOM_Displayer( appStudy );
102
103   OCCViewer_ViewManager* anOCCVM = (OCCViewer_ViewManager*) app->getViewManager( OCCViewer_Viewer::Type(), /*create=*/ true );
104
105   if ( SUIT_ViewModel* viewModel = anOCCVM->getViewModel() ) {
106     if ( SALOME_View* viewFrame = dynamic_cast<SALOME_View*>( viewModel ) ) {
107       disp->EraseAll( true, false, viewFrame );
108       SALOME_ListIteratorOfListIO Iter( aSelList );
109       for ( ; Iter.More(); Iter.Next() )
110         disp->Display( Iter.Value(), false, viewFrame );
111       viewFrame->Repaint();
112     }
113   }
114 }
115
116 //=================================================================================
117 // function : contextMenuPopup()
118 // purpose  : process calling of context menu popup
119 //=================================================================================
120 void DependencyTree_ViewModel::contextMenuPopup( QMenu* theMenu )
121 {
122   GraphicsView_Viewer::contextMenuPopup( theMenu );
123
124   if( DependencyTree_View* viewPort = dynamic_cast<DependencyTree_View*>( getActiveViewPort() ) )
125   {
126     int aNbSelected = viewPort->nbSelected();
127     if( aNbSelected > 0 ) {
128       SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
129       GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
130       theMenu->clear();
131       theMenu->addAction( tr( "MEN_DISPLAY" ), this, SLOT( onShowSelected() ) );
132       theMenu->addAction( tr( "MEN_DISPLAY_ONLY" ), this, SLOT( onShowOnlySelected() ) );
133       theMenu->addAction( tr( "MEN_REBUILD_THE_TREE"), viewPort, SLOT( onRebuildModel() ) );
134       theMenu->addSeparator();
135       theMenu->addAction( aGeomGUI->action( GEOMOp::OpReduceStudy ) );
136     }
137   }
138 }