Salome HOME
Merge branch 'BR_H2018_2' of https://codev-tuleap.cea.fr/plugins/git/salome/hydro...
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ObserveImageOp.cxx
1 // Copyright (C) 2014-2015  EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
6 //
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10 // Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include "HYDROGUI_ObserveImageOp.h"
20
21 #include "HYDROGUI_Module.h"
22 #include "HYDROGUI_PrsImage.h"
23 #include "HYDROGUI_Tool2.h"
24 #include "HYDROGUI_UpdateFlags.h"
25
26 #include <HYDROData_Image.h>
27
28 #include <LightApp_Application.h>
29
30 #include <GraphicsView_ViewManager.h>
31 #include <GraphicsView_Viewer.h>
32
33 HYDROGUI_ObserveImageOp::HYDROGUI_ObserveImageOp( HYDROGUI_Module* theModule )
34 : HYDROGUI_Operation( theModule )
35 {
36   setName( tr( "OBSERVE_IMAGE" ) );
37 }
38
39 HYDROGUI_ObserveImageOp::~HYDROGUI_ObserveImageOp()
40 {
41 }
42
43 void HYDROGUI_ObserveImageOp::startOperation()
44 {
45   HYDROGUI_Operation::startOperation();
46
47   Handle(HYDROData_Image) anImageObj =
48     Handle(HYDROData_Image)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
49   if( !anImageObj.IsNull() )
50   {
51     QImage anImage = anImageObj->Image();
52     QTransform aTransform = anImageObj->Trsf();
53
54     HYDROGUI_PrsImage* aPrs = new HYDROGUI_PrsImage( anImageObj );
55     aPrs->setImage( anImage );
56     aPrs->setTransform( aTransform );
57     aPrs->compute();
58
59     LightApp_Application* anApp = module()->getApp();
60     GraphicsView_ViewManager* aViewManager =
61       dynamic_cast<GraphicsView_ViewManager*>( anApp->createViewManager( GraphicsView_Viewer::Type() ) );
62     if( aViewManager )
63     {
64       module()->setViewManagerRole( aViewManager, HYDROGUI_Module::VMR_ObserveImage );
65       aViewManager->setTitle( anImageObj->GetName() );
66       if( GraphicsView_Viewer* aViewer = aViewManager->getViewer() )
67         module()->setObjectVisible( (size_t)aViewer, anImageObj, true );
68     }
69   }
70
71   module()->update( UF_Viewer );
72   commit();
73 }