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"
22 #include "DependencyTree_View.h"
23 #include "GEOM_Displayer.h"
25 #include <GraphicsView_Viewer.h>
26 #include <GraphicsView_ViewPort.h>
27 #include <SalomeApp_Application.h>
28 #include <SalomeApp_Study.h>
29 #include <LightApp_SelectionMgr.h>
30 #include <SALOME_ListIO.hxx>
31 #include <SALOME_ListIteratorOfListIO.hxx>
32 #include <SUIT_Session.h>
33 #include <OCCViewer_ViewModel.h>
34 #include <OCCViewer_ViewManager.h>
40 DependencyTree_ViewModel::DependencyTree_ViewModel( const QString& title )
41 : GraphicsView_Viewer( title )
45 DependencyTree_ViewModel::DependencyTree_ViewModel( const QString& title, QWidget* w )
46 : GraphicsView_Viewer( title, w )
51 DependencyTree_ViewModel::~DependencyTree_ViewModel()
55 void activateOCCViewer() {
58 void DependencyTree_ViewModel::onShowSelected()
60 std::cout<<"\n\n\n\n *****onShowSelected " << std::endl;
61 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
64 app->getViewManager(OCCViewer_Viewer::Type(), /*create=*/true);
66 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
67 if ( !aSelMgr ) return;
69 SALOME_ListIO aSelList;
70 aSelMgr->selectedObjects(aSelList);
72 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
73 GEOM_Displayer* disp = new GEOM_Displayer( appStudy );
75 OCCViewer_ViewManager* anOCCVM = (OCCViewer_ViewManager*) app->getViewManager( OCCViewer_Viewer::Type(), /*create=*/true );
77 if ( SUIT_ViewModel* vmod = anOCCVM->getViewModel() ) {
78 if ( SALOME_View* aViewFrame = dynamic_cast<SALOME_View*>( vmod ) ) {
79 SALOME_ListIteratorOfListIO Iter( aSelList );
80 for ( ; Iter.More(); Iter.Next() ) {
81 disp->Display( Iter.Value(), false, aViewFrame );
83 aViewFrame->Repaint();
88 void DependencyTree_ViewModel::onShowOnlySelected()
90 std::cout<<"\n\n\n\n *****onShowOnlySelected " << std::endl;
91 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
94 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
95 if ( !aSelMgr ) return;
97 SALOME_ListIO aSelList;
98 aSelMgr->selectedObjects(aSelList);
100 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
101 GEOM_Displayer* disp = new GEOM_Displayer( appStudy );
103 OCCViewer_ViewManager* anOCCVM = (OCCViewer_ViewManager*) app->getViewManager( OCCViewer_Viewer::Type(), /*create=*/true );
105 if ( SUIT_ViewModel* vmod = anOCCVM->getViewModel() ) {
106 if ( SALOME_View* aViewFrame = dynamic_cast<SALOME_View*>( vmod ) ) {
107 disp->EraseAll( true, false, aViewFrame );
108 SALOME_ListIteratorOfListIO Iter( aSelList );
109 for ( ; Iter.More(); Iter.Next() ) {
110 disp->Display( Iter.Value(), false, aViewFrame );
112 aViewFrame->Repaint();
117 void DependencyTree_ViewModel::contextMenuPopup( QMenu* theMenu )
119 GraphicsView_Viewer::contextMenuPopup( theMenu );
120 std::cout<<"\n\n\n\n *****contextMenuPopup " << std::endl;
123 if( DependencyTree_View* aViewPort = dynamic_cast<DependencyTree_View*>(getActiveViewPort()) )
125 int aNbSelected = aViewPort->nbSelected();
126 std::cout<<"\n aNbSelected " << aNbSelected << std::endl;
127 if( aNbSelected > 0 ) {
129 theMenu->addAction( tr( "MEN_DISPLAY" ), this, SLOT( onShowSelected() ) );
130 theMenu->addAction( tr( "MEN_DISPLAY_ONLY" ), this, SLOT( onShowOnlySelected() ) );
131 theMenu->addAction( tr( "REBUILD_THE_TREE"), aViewPort, SLOT( onUpdateModel() ) );
138 //SUIT_ViewWindow* DependencyTree_ViewModel::createView( SUIT_Desktop* theDesktop )
140 // DependencyTree_ViewWindow* aViewFrame;
142 // aViewFrame = new DependencyTree_ViewWindow( theDesktop, this, myWidget );
144 // aViewFrame = new DependencyTree_ViewWindow( theDesktop, this );
146 //connect( aViewFrame, SIGNAL( keyPressed( QKeyEvent* ) ),
147 // this, SLOT( onKeyEvent( QKeyEvent* ) ) );
149 //connect( aViewFrame, SIGNAL( keyReleased( QKeyEvent* ) ),
150 // this, SLOT( onKeyEvent( QKeyEvent* ) ) );
152 //connect( aViewFrame, SIGNAL( mousePressed( QGraphicsSceneMouseEvent* ) ),
153 // this, SLOT( onMouseEvent( QGraphicsSceneMouseEvent* ) ) );
155 //connect( aViewFrame, SIGNAL( mouseMoving( QGraphicsSceneMouseEvent* ) ),
156 // this, SLOT( onMouseEvent( QGraphicsSceneMouseEvent* ) ) );
158 //connect( aViewFrame, SIGNAL( mouseReleased( QGraphicsSceneMouseEvent* ) ),
159 // this, SLOT( onMouseEvent( QGraphicsSceneMouseEvent* ) ) );
161 //connect( aViewFrame, SIGNAL( wheeling( QGraphicsSceneWheelEvent* ) ),
162 // this, SLOT( onWheelEvent( QGraphicsSceneWheelEvent* ) ) );