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