]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx
Salome HOME
1) Image name
[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                                          QString& theErrorMsg )
62 {
63   HYDROGUI_TwoImagesDlg* aPanel = dynamic_cast<HYDROGUI_TwoImagesDlg*>( inputPanel() );
64
65   QString aNewName = aPanel->GetName();
66
67   QString aName1, aName2;
68   aPanel->GetSelectedImages( aName1, aName2 );
69
70   if( aNewName.isEmpty() || aName1.isEmpty() || aName2.isEmpty() )
71     return false;
72
73   Handle(HYDROData_Image) anImage1 = Handle(HYDROData_Image)::DownCast(
74     findObjectByName( aName1, KIND_IMAGE ) );
75   Handle(HYDROData_Image) anImage2 = Handle(HYDROData_Image)::DownCast(
76     findObjectByName( aName2, KIND_IMAGE ) );
77   if( anImage1.IsNull() || anImage2.IsNull() )
78     return false;
79
80   HYDROOperations_Factory* aFactory = HYDROOperations_Factory::Factory();
81   ImageComposer_Operator* anOperator = 0;
82   switch( myType )
83   {
84     case Fuse: anOperator = new ImageComposer_FuseOperator(); break;
85     case Cut: anOperator = new ImageComposer_CutOperator(); break;
86     default: break;
87   }
88
89   if( !anOperator )
90     return false;
91
92   Handle(HYDROData_Image) aResult = aFactory->CreateImage( doc(), anOperator );
93   if( aResult.IsNull() )
94     return false;
95
96   aResult->SetName( aNewName );
97   aResult->AppendReference( anImage1 );
98   aResult->AppendReference( anImage2 );
99   aFactory->UpdateImage( doc(), aResult );
100
101   theUpdateFlags = UF_Model | UF_Viewer;
102   return true;
103 }