1 // Copyright (C) 2014 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, or (at your option) any later version.
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 #include "DependencyTree_ViewModel.h"
21 #include "DependencyTree_View.h"
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>
31 #include <GEOM_Displayer.h>
37 DependencyTree_ViewModel::DependencyTree_ViewModel( const QString& title )
38 : GraphicsView_Viewer( title )
42 DependencyTree_ViewModel::DependencyTree_ViewModel( const QString& title, QWidget* w )
43 : GraphicsView_Viewer( title, w )
47 DependencyTree_ViewModel::~DependencyTree_ViewModel()
51 void DependencyTree_ViewModel::onShowSelected()
53 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
56 app->getViewManager( OCCViewer_Viewer::Type(), /*create=*/ true );
58 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
59 if ( !aSelMgr ) return;
61 SALOME_ListIO aSelList;
62 aSelMgr->selectedObjects(aSelList);
64 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
65 GEOM_Displayer* disp = new GEOM_Displayer( appStudy );
67 OCCViewer_ViewManager* anOCCVM = ( OCCViewer_ViewManager* ) app->getViewManager( OCCViewer_Viewer::Type(), /*create=*/ true );
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 );
79 void DependencyTree_ViewModel::onShowOnlySelected()
81 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
84 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
85 if ( !aSelMgr ) return;
87 SALOME_ListIO aSelList;
88 aSelMgr->selectedObjects( aSelList );
90 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
91 GEOM_Displayer* disp = new GEOM_Displayer( appStudy );
93 OCCViewer_ViewManager* anOCCVM = (OCCViewer_ViewManager*) app->getViewManager( OCCViewer_Viewer::Type(), /*create=*/ true );
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();
106 void DependencyTree_ViewModel::contextMenuPopup( QMenu* theMenu )
108 GraphicsView_Viewer::contextMenuPopup( theMenu );
110 if( DependencyTree_View* viewPort = dynamic_cast<DependencyTree_View*>( getActiveViewPort() ) )
112 int aNbSelected = viewPort->nbSelected();
113 if( aNbSelected > 0 ) {
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() ) );