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