1 // Copyright (C) 2014-2016 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
21 #include "DependencyTree_ViewModel.h"
22 #include "DependencyTree_View.h"
25 #include <SUIT_Session.h>
26 #include <SalomeApp_Study.h>
27 #include <LightApp_SelectionMgr.h>
28 #include <SALOME_ListIO.hxx>
29 #include <OCCViewer_ViewManager.h>
32 #include <GEOM_Displayer.h>
33 #include <GeometryGUI_Operations.h>
38 DependencyTree_ViewModel::DependencyTree_ViewModel( const QString& title )
39 : GraphicsView_Viewer( title )
43 DependencyTree_ViewModel::DependencyTree_ViewModel( const QString& title, QWidget* w )
44 : GraphicsView_Viewer( title, w )
48 DependencyTree_ViewModel::~DependencyTree_ViewModel()
52 //=================================================================================
53 // function : onShowSelected()
54 // purpose : slot for showing selected objects in OCC Viewer
55 //=================================================================================
56 void DependencyTree_ViewModel::onShowSelected()
58 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
61 app->getViewManager( OCCViewer_Viewer::Type(), /*create=*/ true );
63 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
64 if ( !aSelMgr ) return;
66 SALOME_ListIO aSelList;
67 aSelMgr->selectedObjects(aSelList);
69 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
70 GEOM_Displayer disp( appStudy );
72 OCCViewer_ViewManager* anOCCVM = ( OCCViewer_ViewManager* ) app->getViewManager( OCCViewer_Viewer::Type(), /*create=*/ true );
74 if ( SUIT_ViewModel* viewModel = anOCCVM->getViewModel() ) {
75 if ( SALOME_View* viewFrame = dynamic_cast<SALOME_View*>( viewModel ) ) {
76 SALOME_ListIteratorOfListIO Iter( aSelList );
77 for ( ; Iter.More(); Iter.Next() )
78 disp.Display( Iter.Value(), false, viewFrame );
84 //=================================================================================
85 // function : onShowOnlySelected()
86 // purpose : slot for showing only selected objects in OCC Viewer
87 //=================================================================================
88 void DependencyTree_ViewModel::onShowOnlySelected()
90 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
93 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
94 if ( !aSelMgr ) return;
96 SALOME_ListIO aSelList;
97 aSelMgr->selectedObjects( aSelList );
99 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
100 GEOM_Displayer disp( appStudy );
102 OCCViewer_ViewManager* anOCCVM = (OCCViewer_ViewManager*) app->getViewManager( OCCViewer_Viewer::Type(), /*create=*/ true );
104 if ( SUIT_ViewModel* viewModel = anOCCVM->getViewModel() ) {
105 if ( SALOME_View* viewFrame = dynamic_cast<SALOME_View*>( viewModel ) ) {
106 disp.EraseAll( true, false, viewFrame );
107 SALOME_ListIteratorOfListIO Iter( aSelList );
108 for ( ; Iter.More(); Iter.Next() )
109 disp.Display( Iter.Value(), false, viewFrame );
110 viewFrame->Repaint();
115 //=================================================================================
116 // function : contextMenuPopup()
117 // purpose : process calling of context menu popup
118 //=================================================================================
119 void DependencyTree_ViewModel::contextMenuPopup( QMenu* theMenu )
121 GraphicsView_Viewer::contextMenuPopup( theMenu );
123 if( DependencyTree_View* viewPort = dynamic_cast<DependencyTree_View*>( getActiveViewPort() ) )
125 int aNbSelected = viewPort->nbSelected();
126 if( aNbSelected > 0 ) {
127 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
128 GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
130 theMenu->addAction( tr( "MEN_DISPLAY" ), this, SLOT( onShowSelected() ) );
131 theMenu->addAction( tr( "MEN_DISPLAY_ONLY" ), this, SLOT( onShowOnlySelected() ) );
132 theMenu->addAction( tr( "MEN_REBUILD_THE_TREE"), viewPort, SLOT( onRebuildModel() ) );
133 theMenu->addSeparator();
134 theMenu->addAction( aGeomGUI->action( GEOMOp::OpReduceStudy ) );