]> SALOME platform Git repositories - modules/geom.git/blob - src/DependencyTree/DependencyTree_ViewModel.cxx
Salome HOME
- add new translation
[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 #include "DependencyTree_ViewModel.h"
21 #include "DependencyTree_View.h"
22
23 // GUI includes
24 #include <SUIT_Session.h>
25 #include <SalomeApp_Study.h>
26 #include <LightApp_SelectionMgr.h>
27 #include <SALOME_ListIteratorOfListIO.hxx>
28 #include <OCCViewer_ViewManager.h>
29
30 // GEOM includes
31 #include <GEOM_Displayer.h>
32
33 // QT includes
34 #include <QMenu>
35
36
37 DependencyTree_ViewModel::DependencyTree_ViewModel( const QString& title )
38 : GraphicsView_Viewer( title )
39 {
40 }
41
42 DependencyTree_ViewModel::DependencyTree_ViewModel( const QString& title, QWidget* w )
43 : GraphicsView_Viewer( title,  w )
44 {
45 }
46
47 DependencyTree_ViewModel::~DependencyTree_ViewModel()
48 {
49 }
50
51 void DependencyTree_ViewModel::onShowSelected()
52 {
53   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
54   if ( !app ) return;
55
56   app->getViewManager( OCCViewer_Viewer::Type(), /*create=*/ true );
57
58   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
59   if ( !aSelMgr ) return;
60
61   SALOME_ListIO aSelList;
62   aSelMgr->selectedObjects(aSelList);
63
64   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
65   GEOM_Displayer* disp = new GEOM_Displayer( appStudy );
66
67   OCCViewer_ViewManager* anOCCVM = ( OCCViewer_ViewManager* ) app->getViewManager( OCCViewer_Viewer::Type(), /*create=*/ true );
68
69   if ( SUIT_ViewModel* viewModel = anOCCVM->getViewModel() ) {
70     if ( SALOME_View* viewFrame = dynamic_cast<SALOME_View*>( viewModel ) ) {
71       SALOME_ListIteratorOfListIO Iter( aSelList );
72       for ( ; Iter.More(); Iter.Next() )
73         disp->Display( Iter.Value(), false, viewFrame );
74       viewFrame->Repaint();
75     }
76   }
77 }
78
79 void DependencyTree_ViewModel::onShowOnlySelected()
80 {
81   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
82   if ( !app ) return;
83
84   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
85   if ( !aSelMgr ) return;
86
87   SALOME_ListIO aSelList;
88   aSelMgr->selectedObjects( aSelList );
89
90   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
91   GEOM_Displayer* disp = new GEOM_Displayer( appStudy );
92
93   OCCViewer_ViewManager* anOCCVM = (OCCViewer_ViewManager*) app->getViewManager( OCCViewer_Viewer::Type(), /*create=*/ true );
94
95   if ( SUIT_ViewModel* viewModel = anOCCVM->getViewModel() ) {
96     if ( SALOME_View* viewFrame = dynamic_cast<SALOME_View*>( viewModel ) ) {
97       disp->EraseAll( true, false, viewFrame );
98       SALOME_ListIteratorOfListIO Iter( aSelList );
99       for ( ; Iter.More(); Iter.Next() )
100         disp->Display( Iter.Value(), false, viewFrame );
101       viewFrame->Repaint();
102     }
103   }
104 }
105
106 void DependencyTree_ViewModel::contextMenuPopup( QMenu* theMenu )
107 {
108   GraphicsView_Viewer::contextMenuPopup( theMenu );
109
110   if( DependencyTree_View* viewPort = dynamic_cast<DependencyTree_View*>( getActiveViewPort() ) )
111   {
112     int aNbSelected = viewPort->nbSelected();
113     if( aNbSelected > 0 ) {
114       theMenu->clear();
115       theMenu->addAction( tr( "MEN_DISPLAY" ), this, SLOT( onShowSelected() ) );
116       theMenu->addAction( tr( "MEN_DISPLAY_ONLY" ), this, SLOT( onShowOnlySelected() ) );
117       theMenu->addAction( tr( "REBUILD_THE_TREE"), viewPort, SLOT( onRebuildModel() ) );
118     }
119   }
120 }