Salome HOME
PAL10427
[samples/sierpinsky.git] / src / SierpinskyGUI / SierpinskyGUI.cxx
1 ///////////////////////////////////////////////////////////
2 // File    : SierpinskyGUI.cxx
3 // Author  : Vadim SANDLER (OCN)
4 // Created : 13/07/05
5 // Copyright (C) 2005 Open CASCADE
6 ///////////////////////////////////////////////////////////
7
8 #include "SierpinskyGUI.h"
9
10 #include <SUIT_MessageBox.h>
11 #include <SUIT_ResourceMgr.h>
12 #include <SUIT_Desktop.h>
13 #include <SalomeApp_Application.h>
14 #include <SVTK_ViewModel.h>
15 #include <SALOME_LifeCycleCORBA.hxx>
16 #include <SierpinskyGUI_RunDlg.h>
17
18 /*!
19  * Constructor
20  */
21 SierpinskyGUI::SierpinskyGUI() : 
22   SalomeApp_Module("Sierpinsky")
23 {
24 }
25
26 /*! 
27  * Gets an reference to the module's engine
28  */
29 SIERPINSKY_ORB::SIERPINSKY_ptr SierpinskyGUI::InitSIERPINSKYGen( SalomeApp_Application* app )
30 {
31   SIERPINSKY_ORB::SIERPINSKY_ptr clr;
32   try{
33     Engines::Component_var comp = app->lcc()->FindOrLoad_Component( "FactoryServer","SIERPINSKY" );
34     clr = SIERPINSKY_ORB::SIERPINSKY::_narrow(comp);
35   }
36   catch (CORBA::Exception&){
37     MESSAGE("Caught CORBA::Exception.");
38   }
39   catch (...){
40     MESSAGE("Caught unknown exception.");
41   }
42   return clr;
43 }
44
45 /*!
46  * Module's initialization
47  */
48 void SierpinskyGUI::initialize( CAM_Application* app )
49 {
50   SalomeApp_Module::initialize( app );
51
52   InitSIERPINSKYGen( dynamic_cast<SalomeApp_Application*>( app ) );
53
54   QWidget* aParent = app->desktop();
55   SUIT_ResourceMgr* aResourceMgr = app->resourceMgr();
56
57   // create actions
58   QPixmap aPixmap = aResourceMgr->loadPixmap( "SIERPINSKY",tr( "ICON_RUN_DLG" ) );
59   createAction( 901, tr( "Run Dialog" ), QIconSet(aPixmap), tr( "RUN" ), tr( "CAPTION" ), 0, aParent, false,
60                 this, SLOT( OnRun() ) );
61
62   // create menus
63   int aMenuId;
64   aMenuId = createMenu( tr( "MENU_Sierpinsky" ), -1, -1, 30 );
65   createMenu( 901, aMenuId, 10 );
66
67   // create toolbars
68   int aToolId = createTool ( tr( "TOOL_Sierpinsky" ) );
69   createTool( 901, aToolId );
70 }
71
72 /*!
73  * Module's engine IOR
74  */
75 QString SierpinskyGUI::engineIOR() const
76 {
77   CORBA::String_var anIOR = getApp()->orb()->object_to_string( InitSIERPINSKYGen( getApp() ) );
78   return QString( anIOR.in() );
79 }
80
81 /*!
82  * Required dockable windows
83  */
84 void SierpinskyGUI::windows( QMap<int, int>& wmap ) const
85 {
86   wmap.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::DockLeft );
87 }
88
89 /*!
90  * Required viewers list
91  */
92 void SierpinskyGUI::viewManagers( QStringList& vmlist ) const
93 {
94   vmlist.append( SVTK_Viewer::Type() );
95 }
96
97 /*!
98  * Module's activation
99  */
100 bool SierpinskyGUI::activateModule( SUIT_Study* theStudy )
101 {
102   bool bOk = SalomeApp_Module::activateModule( theStudy );
103
104   setMenuShown(true);
105   setToolShown(true);
106
107   return bOk;
108 }
109
110 /*!
111  * Module's deactivation
112  */
113 bool SierpinskyGUI::deactivateModule( SUIT_Study* theStudy )
114 {
115   setMenuShown(false);
116   setToolShown(false);
117
118   return SalomeApp_Module::deactivateModule( theStudy );
119 }
120
121 /*!
122  * Destructor
123  */
124 SierpinskyGUI::~SierpinskyGUI()
125 {
126 }
127
128
129 // Action slot
130 void SierpinskyGUI::OnRun()
131 {
132   QWidget* aParent = getApp()->desktop();
133   SierpinskyGUI_RunDlg* aDlg = new SierpinskyGUI_RunDlg( aParent, this );
134   aDlg->exec();
135 }
136
137 extern "C" {
138   CAM_Module* createModule()
139   {
140     return new SierpinskyGUI();
141   }
142 }