Salome HOME
a91d4734465c3ef0f172cd95caa465e6901741d7
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_TwoImagesOp.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "HYDROGUI_TwoImagesOp.h"
24
25 #include "HYDROGUI_Module.h"
26 #include "HYDROGUI_TwoImagesDlg.h"
27 #include "HYDROGUI_UpdateFlags.h"
28
29 #include <HYDROData_Document.h>
30 #include <HYDROData_Image.h>
31
32 #include <HYDROOperations_Factory.h>
33
34 #include <ImageComposer_CutOperator.h>
35 #include <ImageComposer_FuseOperator.h>
36
37 HYDROGUI_TwoImagesOp::HYDROGUI_TwoImagesOp( HYDROGUI_Module* theModule, const int theType )
38 : HYDROGUI_Operation( theModule ),
39   myType( theType )
40 {
41   QString aName;
42   switch( myType )
43   {
44     case Fuse: aName = tr( "FUSE" ); break;
45     case Cut: aName = tr( "CUT" ); break;
46     default: break;
47   }
48   setName( aName );
49 }
50
51 HYDROGUI_TwoImagesOp::~HYDROGUI_TwoImagesOp()
52 {
53 }
54
55 HYDROGUI_InputPanel* HYDROGUI_TwoImagesOp::createInputPanel() const
56 {
57   return new HYDROGUI_TwoImagesDlg( module(), getName() );
58 }
59
60 bool HYDROGUI_TwoImagesOp::processApply( int& theUpdateFlags )
61 {
62   HYDROGUI_TwoImagesDlg* aPanel = dynamic_cast<HYDROGUI_TwoImagesDlg*>( inputPanel() );
63
64   QString aNewName = aPanel->GetName();
65
66   QString aName1, aName2;
67   aPanel->GetSelectedImages( aName1, aName2 );
68
69   if( aNewName.isEmpty() || aName1.isEmpty() || aName2.isEmpty() )
70     return false;
71
72   Handle(HYDROData_Image) anImage1 = Handle(HYDROData_Image)::DownCast(
73     findObjectByName( aName1, KIND_IMAGE ) );
74   Handle(HYDROData_Image) anImage2 = Handle(HYDROData_Image)::DownCast(
75     findObjectByName( aName2, KIND_IMAGE ) );
76   if( anImage1.IsNull() || anImage2.IsNull() )
77     return false;
78
79   HYDROOperations_Factory* aFactory = HYDROOperations_Factory::Factory();
80   ImageComposer_Operator* anOperator = 0;
81   switch( myType )
82   {
83     case Fuse: anOperator = new ImageComposer_FuseOperator(); break;
84     case Cut: anOperator = new ImageComposer_CutOperator(); break;
85     default: break;
86   }
87
88   if( !anOperator )
89     return false;
90
91   Handle(HYDROData_Image) aResult = aFactory->CreateImage( doc(), anOperator );
92   if( aResult.IsNull() )
93     return false;
94
95   aResult->SetName( aNewName );
96   aResult->AppendReference( anImage1 );
97   aResult->AppendReference( anImage2 );
98   aFactory->UpdateImage( doc(), aResult );
99
100   theUpdateFlags = UF_Model | UF_Viewer;
101   return true;
102 }