Salome HOME
Preparation of 3.1.0a2: merge with BR_3_0_0_OCC
[samples/hello.git] / src / HELLOGUI / HELLOGUI.cxx
1 #include "HELLOGUI.h"
2
3 #include <SUIT_MessageBox.h>
4 #include <SUIT_ResourceMgr.h>
5 #include <SalomeApp_Application.h>
6
7 #include <SALOME_LifeCycleCORBA.hxx>
8
9 // QT Includes
10 #include <qinputdialog.h>
11
12 using namespace std;
13
14 // Constructor
15 HELLOGUI::HELLOGUI() :
16   SalomeApp_Module( "HELLO" ) // default name
17 {
18 }
19
20 // Gets an reference to the module's engine
21 HELLO_ORB::HELLO_Gen_ptr HELLOGUI::InitHELLOGen( SalomeApp_Application* app )
22 {
23   Engines::Component_var comp = app->lcc()->FindOrLoad_Component( "FactoryServer","HELLO" );
24   HELLO_ORB::HELLO_Gen_ptr clr = HELLO_ORB::HELLO_Gen::_narrow(comp);
25   ASSERT(!CORBA::is_nil(clr));
26   return clr;
27 }
28
29 // Module's initialization
30 void HELLOGUI::initialize( CAM_Application* app )
31 {
32
33   SalomeApp_Module::initialize( app );
34
35   InitHELLOGen( dynamic_cast<SalomeApp_Application*>( app ) );
36
37   QWidget* aParent = app->desktop();
38   SUIT_ResourceMgr* aResourceMgr = app->resourceMgr();
39
40   // create actions
41   createAction( 190, tr( "TLT_MY_NEW_ITEM" ), QIconSet(), tr( "MEN_MY_NEW_ITEM" ), tr( "STS_MY_NEW_ITEM" ), 0, aParent, false,
42                 this, SLOT( OnMyNewItem() ) );
43   QPixmap aPixmap = aResourceMgr->loadPixmap( "HELLO",tr( "ICON_GET_BANNER" ) );
44   createAction( 901, tr( "TLT_GET_BANNER" ), QIconSet( aPixmap ), tr( "MEN_GET_BANNER" ), tr( "STS_GET_BANNER" ), 0, aParent, false,
45                 this, SLOT( OnGetBanner() ) );
46
47   // create menus
48   int aMenuId;
49   aMenuId = createMenu( tr( "MEN_FILE" ), -1, -1 );
50   createMenu( separator(), aMenuId, -1, 10 );
51   aMenuId = createMenu( tr( "MEN_FILE_HELLO" ), aMenuId, -1, 10 );
52   createMenu( 190, aMenuId );
53
54   aMenuId = createMenu( tr( "MEN_HELLO" ), -1, -1, 30 );
55   createMenu( 901, aMenuId, 10 );
56
57   // create toolbars
58   int aToolId = createTool ( tr( "TOOL_HELLO" ) );
59   createTool( 901, aToolId );
60 }
61
62 // Module's engine IOR
63 QString HELLOGUI::engineIOR() const
64 {
65   CORBA::String_var anIOR = getApp()->orb()->object_to_string( InitHELLOGen( getApp() ) );
66   return QString( anIOR.in() );
67 }
68
69 // Module's activation
70 bool HELLOGUI::activateModule( SUIT_Study* theStudy )
71 {
72   bool bOk = SalomeApp_Module::activateModule( theStudy );
73
74   setMenuShown( true );
75   setToolShown( true );
76
77   return bOk;
78 }
79
80 // Module's deactivation
81 bool HELLOGUI::deactivateModule( SUIT_Study* theStudy )
82 {
83   setMenuShown( false );
84   setToolShown( false );
85
86   return SalomeApp_Module::deactivateModule( theStudy );
87 }
88
89 // Default windows
90 void HELLOGUI::windows( QMap<int, int>& theMap ) const
91 {
92   theMap.clear();
93   theMap.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::DockLeft );
94   theMap.insert( SalomeApp_Application::WT_PyConsole,     Qt::DockBottom );
95 }
96
97 // Action slot
98 void HELLOGUI::OnMyNewItem()
99 {
100   SUIT_MessageBox::warn1( getApp()->desktop(),tr( "INF_HELLO_BANNER" ), tr( "INF_HELLO_MENU" ), tr( "BUT_OK" ) );
101 }
102
103 // Action slot
104 void HELLOGUI::OnGetBanner()
105 {
106   // Dialog to get the Name
107   bool ok = FALSE;
108   QString myName = QInputDialog::getText( tr( "QUE_HELLO_LABEL" ), tr( "QUE_HELLO_NAME" ),
109                                           QLineEdit::Normal, QString::null, &ok );
110
111   if ( ok && !myName.isEmpty()) // if we got a name, get a HELLO component and ask for makeBanner
112   {
113     HELLO_ORB::HELLO_Gen_ptr hellogen = HELLOGUI::InitHELLOGen( getApp() );
114     QString banner = hellogen->makeBanner( myName );
115     SUIT_MessageBox::info1( getApp()->desktop(), tr( "INF_HELLO_BANNER" ), banner, tr( "BUT_OK" ) );
116   }
117 }
118
119 // Export the module
120 extern "C" {
121   CAM_Module* createModule()
122   {
123     return new HELLOGUI();
124   }
125 }