Salome HOME
Join modifications from branch OCC_debug_for_3_2_0b1
[samples/hello.git] / src / HELLOGUI / HELLOGUI.cxx
1 // Copyright (C) 2005  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/
18 //
19 #include "HELLOGUI.h"
20
21 #include <SUIT_MessageBox.h>
22 #include <SUIT_ResourceMgr.h>
23 #include <SalomeApp_Application.h>
24
25 #include <SALOME_LifeCycleCORBA.hxx>
26
27 // QT Includes
28 #include <qinputdialog.h>
29
30 using namespace std;
31
32 // Constructor
33 HELLOGUI::HELLOGUI() :
34   SalomeApp_Module( "HELLO" ) // default name
35 {
36 }
37
38 // Gets an reference to the module's engine
39 HELLO_ORB::HELLO_Gen_ptr HELLOGUI::InitHELLOGen( SalomeApp_Application* app )
40 {
41   Engines::Component_var comp = app->lcc()->FindOrLoad_Component( "FactoryServer","HELLO" );
42   HELLO_ORB::HELLO_Gen_ptr clr = HELLO_ORB::HELLO_Gen::_narrow(comp);
43   ASSERT(!CORBA::is_nil(clr));
44   return clr;
45 }
46
47 // Module's initialization
48 void HELLOGUI::initialize( CAM_Application* app )
49 {
50
51   SalomeApp_Module::initialize( app );
52
53   InitHELLOGen( dynamic_cast<SalomeApp_Application*>( app ) );
54
55   QWidget* aParent = app->desktop();
56   SUIT_ResourceMgr* aResourceMgr = app->resourceMgr();
57
58   // create actions
59   createAction( 190, tr( "TLT_MY_NEW_ITEM" ), QIconSet(), tr( "MEN_MY_NEW_ITEM" ), tr( "STS_MY_NEW_ITEM" ), 0, aParent, false,
60                 this, SLOT( OnMyNewItem() ) );
61   QPixmap aPixmap = aResourceMgr->loadPixmap( "HELLO",tr( "ICON_GET_BANNER" ) );
62   createAction( 901, tr( "TLT_GET_BANNER" ), QIconSet( aPixmap ), tr( "MEN_GET_BANNER" ), tr( "STS_GET_BANNER" ), 0, aParent, false,
63                 this, SLOT( OnGetBanner() ) );
64
65   // create menus
66   int aMenuId;
67   aMenuId = createMenu( tr( "MEN_FILE" ), -1, -1 );
68   createMenu( separator(), aMenuId, -1, 10 );
69   aMenuId = createMenu( tr( "MEN_FILE_HELLO" ), aMenuId, -1, 10 );
70   createMenu( 190, aMenuId );
71
72   aMenuId = createMenu( tr( "MEN_HELLO" ), -1, -1, 30 );
73   createMenu( 901, aMenuId, 10 );
74
75   // create toolbars
76   int aToolId = createTool ( tr( "TOOL_HELLO" ) );
77   createTool( 901, aToolId );
78 }
79
80 // Module's engine IOR
81 QString HELLOGUI::engineIOR() const
82 {
83   CORBA::String_var anIOR = getApp()->orb()->object_to_string( InitHELLOGen( getApp() ) );
84   return QString( anIOR.in() );
85 }
86
87 // Module's activation
88 bool HELLOGUI::activateModule( SUIT_Study* theStudy )
89 {
90   bool bOk = SalomeApp_Module::activateModule( theStudy );
91
92   setMenuShown( true );
93   setToolShown( true );
94
95   return bOk;
96 }
97
98 // Module's deactivation
99 bool HELLOGUI::deactivateModule( SUIT_Study* theStudy )
100 {
101   setMenuShown( false );
102   setToolShown( false );
103
104   return SalomeApp_Module::deactivateModule( theStudy );
105 }
106
107 // Default windows
108 void HELLOGUI::windows( QMap<int, int>& theMap ) const
109 {
110   theMap.clear();
111   theMap.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::DockLeft );
112   theMap.insert( SalomeApp_Application::WT_PyConsole,     Qt::DockBottom );
113 }
114
115 // Action slot
116 void HELLOGUI::OnMyNewItem()
117 {
118   SUIT_MessageBox::warn1( getApp()->desktop(),tr( "INF_HELLO_BANNER" ), tr( "INF_HELLO_MENU" ), tr( "BUT_OK" ) );
119 }
120
121 // Action slot
122 void HELLOGUI::OnGetBanner()
123 {
124   // Dialog to get the Name
125   bool ok = FALSE;
126   QString myName = QInputDialog::getText( tr( "QUE_HELLO_LABEL" ), tr( "QUE_HELLO_NAME" ),
127                                           QLineEdit::Normal, QString::null, &ok );
128
129   if ( ok && !myName.isEmpty()) // if we got a name, get a HELLO component and ask for makeBanner
130   {
131     HELLO_ORB::HELLO_Gen_ptr hellogen = HELLOGUI::InitHELLOGen( getApp() );
132     QString banner = hellogen->makeBanner( myName );
133     SUIT_MessageBox::info1( getApp()->desktop(), tr( "INF_HELLO_BANNER" ), banner, tr( "BUT_OK" ) );
134   }
135 }
136
137 // Export the module
138 extern "C" {
139   CAM_Module* createModule()
140   {
141     return new HELLOGUI();
142   }
143 }