1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "HYDROGUI_Operations.h"
25 #include "HYDROGUI_DataModel.h"
26 #include "HYDROGUI_ImportImageOp.h"
27 #include "HYDROGUI_Module.h"
28 #include "HYDROGUI_TwoImagesOp.h"
30 #include <HYDROData_Document.h>
31 #include <HYDROData_Image.h>
33 #include <CAM_Application.h>
35 #include <SUIT_Desktop.h>
36 #include <SUIT_ResourceMgr.h>
39 #include <QFileDialog>
41 QAction* HYDROGUI_Module::CreateAction( const int theId, const QString& theSuffix, const QString& theImg,
42 const int theKey, const bool isToggle, const QString& theSlot )
44 QString aSlot = theSlot;
46 aSlot = SLOT( onOperation() );
47 SUIT_ResourceMgr* aMgr = application()->resourceMgr();
48 std::string anImg = theImg.toStdString();
49 QPixmap aPixmap = theImg.isEmpty() ? QPixmap() : aMgr->loadPixmap( "HYDROGUI", tr( anImg.c_str() ) );
50 std::string aMenu = ( "MEN_" + theSuffix ).toStdString();
51 std::string aDesktop = ( "DSK_" + theSuffix ).toStdString();
52 std::string aToolbar = ( "STB_" + theSuffix ).toStdString();
53 std::string aSlotStr = aSlot.toStdString();
54 return LightApp_Module::createAction( theId, tr( aMenu.c_str() ), aPixmap,
55 tr( aDesktop.c_str() ), tr( aToolbar.c_str() ),
56 theKey, application()->desktop(), isToggle, this, aSlotStr.c_str() );
59 void HYDROGUI_Module::CreateActions()
61 CreateAction( ImportImageId, "IMPORT_IMAGE", "", Qt::CTRL + Qt::Key_I );
64 void HYDROGUI_Module::CreateMenus()
66 int aHydroMenuIndex = 6; // Edit menu id == 5, View menu id == 10
67 int aHydroId = createMenu( tr( "MEN_DESK_HYDRO" ), -1, -1, aHydroMenuIndex );
68 createMenu( ImportImageId, aHydroId, -1, -1 );
71 void HYDROGUI_Module::CreatePopups()
75 void HYDROGUI_Module::CreateToolbars()
79 void HYDROGUI_Module::onOperation()
81 const QAction* anAction = dynamic_cast<const QAction*>( sender() );
82 int anId = actionId( anAction );
84 startOperation( anId );
87 if( anId == ImportImageId )
89 QString aFileName = QFileDialog::getOpenFileName();
90 if( !aFileName.isEmpty() )
92 int aStudyId = getStudyId();
93 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( aStudyId );
94 if( !aDocument.IsNull() )
96 Handle(HYDROData_Image) anImageObj =
97 Handle(HYDROData_Image)::DownCast( aDocument->CreateObject( KIND_IMAGE ) );
98 if( !anImageObj.IsNull() )
100 static int ImageId = 0;
101 anImageObj->SetName( QString( "Image_%1" ).arg( QString::number( ++ImageId ) ) );
103 QImage anImage( aFileName );
104 QTransform aTransform;
105 anImageObj->SetImage( anImage );
106 anImageObj->SetTrsf( aTransform );
108 getModel()->updateModel();
115 LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const
117 LightApp_Operation* anOp = 0;
118 HYDROGUI_Module* aModule = const_cast<HYDROGUI_Module*>( this );
122 anOp = new HYDROGUI_ImportImageOp( aModule );
125 anOp = new HYDROGUI_TwoImagesOp( aModule, tr( "FUSE_OP" ) );
128 anOp = new HYDROGUI_TwoImagesOp( aModule, tr( "CUT_OP" ) );
133 anOp = LightApp_Module::createOperation( theId );