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