Salome HOME
cc3b24520200d4028d3f67a820512f3224eb5bb1
[modules/hexablock.git] / src / HEXABLOCKGUI / HEXABLOCKGUI.cxx
1 //  Copyright (C) 2007-2008  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 #include "HEXABLOCKGUI.h"
23
24 #include <SUIT_MessageBox.h>
25 #include <SUIT_ResourceMgr.h>
26 #include <SUIT_Desktop.h>
27 #include <SalomeApp_Application.h>
28
29 #include <SALOME_LifeCycleCORBA.hxx>
30
31 // QT Includes
32 #include <QInputDialog>
33 #include <QIcon>
34
35 using namespace std;
36
37 // Constructor
38 HEXABLOCKGUI::HEXABLOCKGUI() :
39   SalomeApp_Module( "HEXABLOCK" ), // default name
40   LightApp_Module( "HEXABLOCK" )
41 {
42 }
43
44 // Gets an reference to the module's engine
45 HEXABLOCK_ORB::HEXABLOCK_Gen_ptr HEXABLOCKGUI::InitHEXABLOCKGen( SalomeApp_Application* app )
46 {
47   Engines::Component_var comp = app->lcc()->FindOrLoad_Component( "FactoryServer","HEXABLOCK" );
48   HEXABLOCK_ORB::HEXABLOCK_Gen_ptr clr = HEXABLOCK_ORB::HEXABLOCK_Gen::_narrow(comp);
49   ASSERT(!CORBA::is_nil(clr));
50   return clr;
51 }
52
53 // Module's initialization
54 void HEXABLOCKGUI::initialize( CAM_Application* app )
55 {
56
57   SalomeApp_Module::initialize( app );
58
59   InitHEXABLOCKGen( dynamic_cast<SalomeApp_Application*>( app ) );
60
61   QWidget* aParent = application()->desktop();
62   SUIT_ResourceMgr* aResourceMgr = app->resourceMgr();
63
64   // create actions
65   createAction( 190, tr( "TLT_MY_NEW_ITEM" ), QIcon(), tr( "MEN_MY_NEW_ITEM" ), tr( "STS_MY_NEW_ITEM" ), 0, aParent, false,
66                 this, SLOT( OnMyNewItem() ) );
67   QPixmap aPixmap = aResourceMgr->loadPixmap( "HEXABLOCK",tr( "ICON_GET_BANNER" ) );
68   createAction( 901, tr( "TLT_GET_BANNER" ), QIcon( aPixmap ), tr( "MEN_GET_BANNER" ), tr( "STS_GET_BANNER" ), 0, aParent, false,
69                 this, SLOT( OnGetBanner() ) );
70
71   // create menus
72   int aMenuId;
73   aMenuId = createMenu( tr( "MEN_FILE" ), -1, -1 );
74   createMenu( separator(), aMenuId, -1, 10 );
75   aMenuId = createMenu( tr( "MEN_FILE_HEXABLOCK" ), aMenuId, -1, 10 );
76   createMenu( 190, aMenuId );
77
78   aMenuId = createMenu( tr( "MEN_HEXABLOCK" ), -1, -1, 30 );
79   createMenu( 901, aMenuId, 10 );
80
81   // create toolbars
82   int aToolId = createTool ( tr( "TOOL_HEXABLOCK" ) );
83   createTool( 901, aToolId );
84 }
85
86 // Module's engine IOR
87 QString HEXABLOCKGUI::engineIOR() const
88 {
89   CORBA::String_var anIOR = getApp()->orb()->object_to_string( InitHEXABLOCKGen( getApp() ) );
90   return QString( anIOR.in() );
91 }
92
93 // Module's activation
94 bool HEXABLOCKGUI::activateModule( SUIT_Study* theStudy )
95 {
96   bool bOk = SalomeApp_Module::activateModule( theStudy );
97
98   setMenuShown( true );
99   setToolShown( true );
100
101   return bOk;
102 }
103
104 // Module's deactivation
105 bool HEXABLOCKGUI::deactivateModule( SUIT_Study* theStudy )
106 {
107   setMenuShown( false );
108   setToolShown( false );
109
110   return SalomeApp_Module::deactivateModule( theStudy );
111 }
112
113 // Default windows
114 void HEXABLOCKGUI::windows( QMap<int, int>& theMap ) const
115 {
116   theMap.clear();
117   theMap.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
118   theMap.insert( SalomeApp_Application::WT_PyConsole,     Qt::BottomDockWidgetArea );
119 }
120
121 // Action slot
122 void HEXABLOCKGUI::OnMyNewItem()
123 {
124   SUIT_MessageBox::warning( getApp()->desktop(),tr( "INF_HEXABLOCK_BANNER" ), tr( "INF_HEXABLOCK_MENU" ) );
125 }
126
127 // Action slot
128 void HEXABLOCKGUI::OnGetBanner()
129 {
130   // Dialog to get the Name
131   bool ok = FALSE;
132   QString myName = QInputDialog::getText( getApp()->desktop(), tr( "QUE_HEXABLOCK_LABEL" ), tr( "QUE_HEXABLOCK_NAME" ),
133                                           QLineEdit::Normal, QString::null, &ok );
134
135   if ( ok && !myName.isEmpty()) // if we got a name, get a HEXABLOCK component and ask for makeBanner
136   {
137 //     HEXABLOCK_ORB::HEXABLOCK_Gen_ptr hexablockgen = HEXABLOCKGUI::InitHEXABLOCKGen( getApp() );
138 //     QString banner = hexablockgen->makeBanner( (const char*)myName.toLatin1() );
139 //     SUIT_MessageBox::information( getApp()->desktop(), tr( "INF_HEXABLOCK_BANNER" ), banner, tr( "BUT_OK" ) );
140   }
141 }
142
143 // Export the module
144 extern "C" {
145   CAM_Module* createModule()
146   {
147     return new HEXABLOCKGUI();
148   }
149 }