Salome HOME
Fix a bug of SALOME_PYQT package - to work properly with Sip and PyQt libraries addit...
[modules/gui.git] / src / SalomeApp / SalomeApp_Module.cxx
1 // File:      SalomeApp_Module.cxx
2 // Created:   10/25/2004 11:39:56 AM
3 // Author:    Sergey LITONIN
4 // Copyright (C) CEA 2004
5
6 #include "SalomeApp_Module.h"
7
8 #include "SalomeApp_Study.h"
9 #include "SalomeApp_DataModel.h"
10 #include "SalomeApp_Application.h"
11 #include "SalomeApp_Preferences.h"
12
13 #include <OB_Browser.h>
14
15 #include <CAM_Study.h>
16
17 #include <SUIT_MessageBox.h>
18 #include <SUIT_ResourceMgr.h>
19
20 #include <QtxPopupMgr.h>
21
22 /*!Constructor.*/
23 SalomeApp_Module::SalomeApp_Module( const QString& name )
24 : CAM_Module( name ),
25 myPopupMgr( 0 )
26 {
27 }
28
29 /*!Destructor.*/
30 SalomeApp_Module::~SalomeApp_Module()
31 {
32 }
33
34 /*!Initialize module.*/
35 void SalomeApp_Module::initialize( CAM_Application* app )
36 {
37   CAM_Module::initialize( app );
38
39   SUIT_ResourceMgr* resMgr = app ? app->resourceMgr() : 0;
40   if ( resMgr )
41     resMgr->raiseTranslators( name() );
42 }
43
44 /*!Activate module.*/
45 bool SalomeApp_Module::activateModule( SUIT_Study* study )
46 {
47   bool res = CAM_Module::activateModule( study );
48
49   if ( res && application() && application()->resourceMgr() )
50     application()->resourceMgr()->raiseTranslators( name() );
51     
52   return res;
53 }
54
55 /*!Deactivate module.*/
56 bool SalomeApp_Module::deactivateModule( SUIT_Study* )
57 {
58   return true;
59 }
60
61 /*!NOT IMPLEMENTED*/
62 void SalomeApp_Module::selectionChanged()
63 {
64 }
65
66 /*!NOT IMPLEMENTED*/
67 void SalomeApp_Module::MenuItem()
68 {
69 }
70
71 /*!NOT IMPLEMENTED*/
72 void SalomeApp_Module::windows( QMap<int, int>& ) const
73 {
74 }
75
76 /*!NOT IMPLEMENTED*/
77 void SalomeApp_Module::viewManagers( QStringList& ) const
78 {
79 }
80
81 /*!NOT IMPLEMENTED*/
82 void SalomeApp_Module::createPreferences()
83 {
84 }
85
86 /*!NOT IMPLEMENTED*/
87 void SalomeApp_Module::preferencesChanged( const QString&, const QString& )
88 {
89 }
90
91 /*!Gets application.*/
92 SalomeApp_Application* SalomeApp_Module::getApp() const
93 {
94   return (SalomeApp_Application*)application();
95 }
96
97 /*!NOT IMPLEMENTED*/
98 void SalomeApp_Module::onModelOpened()
99 {
100 }
101
102 /*!NOT IMPLEMENTED*/
103 void SalomeApp_Module::onModelSaved()
104 {
105 }
106
107 /*!NOT IMPLEMENTED*/
108 void SalomeApp_Module::onModelClosed()
109 {
110 }
111
112 /*!Gets popup manager.(create if not exist)*/
113 QtxPopupMgr* SalomeApp_Module::popupMgr()
114 {
115   if ( !myPopupMgr )
116     myPopupMgr = new QtxPopupMgr( 0, this );
117   return myPopupMgr;
118 }
119
120 /*!Gets preferences.*/
121 SalomeApp_Preferences* SalomeApp_Module::preferences() const
122 {
123   SalomeApp_Preferences* pref = 0;
124   if ( getApp() )
125     pref = getApp()->preferences();
126   return pref;
127 }
128
129 /*!Create new instance of data model and return it.*/
130 CAM_DataModel* SalomeApp_Module::createDataModel()
131 {
132   return new SalomeApp_DataModel(this);
133 }
134
135 /*!Update object browser.*/
136 void SalomeApp_Module::updateObjBrowser( bool updateDataModel, SUIT_DataObject* root )
137 {
138   if( updateDataModel )
139     if( CAM_DataModel* aDataModel = dataModel() )
140       if( SalomeApp_DataModel* aModel = dynamic_cast<SalomeApp_DataModel*>( aDataModel ) )
141         aModel->update( 0, dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() ) );
142   getApp()->objectBrowser()->updateTree( root );
143 }
144
145 /*!Context menu popup.*/
146 void SalomeApp_Module::contextMenuPopup( const QString& client, QPopupMenu* menu, QString& /*title*/ )
147 {
148   SalomeApp_Selection* sel = createSelection();
149   sel->init( client, getApp()->selectionMgr() );
150   popupMgr()->updatePopup( menu, sel );
151   delete sel;
152 }
153
154 /*!Create and return instance of SalomeApp_Selection.*/
155 SalomeApp_Selection* SalomeApp_Module::createSelection() const
156 {
157   return new SalomeApp_Selection();
158 }
159
160 /*!Add preference to preferences.*/
161 int SalomeApp_Module::addPreference( const QString& label )
162 {
163   SalomeApp_Preferences* pref = preferences();
164   if ( !pref )
165     return -1;
166
167   int catId = pref->addPreference( moduleName(), -1 );
168   if ( catId == -1 )
169     return -1;
170
171   return pref->addPreference( label, catId );
172 }
173
174 /*!Add preference to preferences.*/
175 int SalomeApp_Module::addPreference( const QString& label, const int pId, const int type,
176                                      const QString& section, const QString& param )
177 {
178   SalomeApp_Preferences* pref = preferences();
179   if ( !pref )
180     return -1;
181
182   return pref->addPreference( moduleName(), label, pId, type, section, param );
183 }
184
185 /*!Gets property of preferences.*/
186 QVariant SalomeApp_Module::preferenceProperty( const int id, const QString& prop ) const
187 {
188   QVariant var;
189   SalomeApp_Preferences* pref = preferences();
190   if ( pref )
191     var = pref->itemProperty( id, prop );
192   return var;
193 }
194
195
196 /*!Set property of preferences.*/
197 void SalomeApp_Module::setPreferenceProperty( const int id, const QString& prop, const QVariant& var )
198 {
199   SalomeApp_Preferences* pref = preferences();
200   if ( pref )
201     pref->setItemProperty( id, prop, var );
202 }