]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROGUI/HYDROGUI_Operations.cxx
Salome HOME
1) HYDRO: Import Image operation.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Operations.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_Operations.h"
24
25 #include "HYDROGUI_DataModel.h"
26 #include "HYDROGUI_ImportImageOp.h"
27 #include "HYDROGUI_Module.h"
28 #include "HYDROGUI_TwoImagesOp.h"
29
30 #include <CAM_Application.h>
31
32 #include <SUIT_Desktop.h>
33 #include <SUIT_ResourceMgr.h>
34
35 #include <QAction>
36
37 QAction* HYDROGUI_Module::CreateAction( const int theId, const QString& theSuffix, const QString& theImg,
38                                         const int theKey, const bool isToggle, const QString& theSlot )
39 {
40   QString aSlot = theSlot;
41   if( aSlot.isEmpty() )
42     aSlot = SLOT( onOperation() );
43   SUIT_ResourceMgr* aMgr = application()->resourceMgr();
44   std::string anImg = theImg.toStdString();
45   QPixmap aPixmap = theImg.isEmpty() ? QPixmap() : aMgr->loadPixmap( "HYDROGUI", tr( anImg.c_str() ) );
46   std::string aMenu    = ( "MEN_" + theSuffix ).toStdString();
47   std::string aDesktop = ( "DSK_" + theSuffix ).toStdString();
48   std::string aToolbar = ( "STB_" + theSuffix ).toStdString();
49   std::string aSlotStr = aSlot.toStdString();
50   return LightApp_Module::createAction( theId, tr( aMenu.c_str() ), aPixmap,
51     tr( aDesktop.c_str() ), tr( aToolbar.c_str() ),
52                 theKey, application()->desktop(), isToggle, this, aSlotStr.c_str() );
53 }
54
55 void HYDROGUI_Module::CreateActions()
56 {
57   CreateAction( ImportImageId, "IMPORT_IMAGE", "", Qt::CTRL + Qt::Key_I );
58   CreateAction( FuseId, "FUSE_IMAGES" );
59   CreateAction( CutId, "CUT_IMAGES" );
60 }
61
62 void HYDROGUI_Module::CreateMenus()
63 {
64   int aHydroMenuIndex = 6; // Edit menu id == 5, View menu id == 10
65   int aHydroId = createMenu( tr( "MEN_DESK_HYDRO" ), -1, -1, aHydroMenuIndex );
66   createMenu( ImportImageId, aHydroId, -1, -1 );
67   createMenu( FuseId, aHydroId, -1, -1 );
68   createMenu( CutId, aHydroId, -1, -1 );
69 }
70
71 void HYDROGUI_Module::CreatePopups()
72 {
73 }
74
75 void HYDROGUI_Module::CreateToolbars()
76 {
77 }
78
79 void HYDROGUI_Module::onOperation()
80 {
81   const QAction* anAction = dynamic_cast<const QAction*>( sender() );
82   int anId = actionId( anAction );
83   if( anId >= 0 )
84     startOperation( anId );
85 }
86
87 LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const
88 {
89   LightApp_Operation* anOp = 0;
90   HYDROGUI_Module* aModule = const_cast<HYDROGUI_Module*>( this );
91   switch( theId )
92   {
93   case ImportImageId:
94     anOp = new HYDROGUI_ImportImageOp( aModule );
95     break;
96   case FuseId:
97     anOp = new HYDROGUI_TwoImagesOp( aModule, tr( "FUSE_OP" ) );
98     break;
99   case CutId:
100     anOp = new HYDROGUI_TwoImagesOp( aModule, tr( "CUT_OP" ) );
101     break;
102   }
103
104   if( !anOp )
105     anOp = LightApp_Module::createOperation( theId );
106
107   return anOp;
108 }