1 // File: SalomeApp_Module.cxx
2 // Created: 10/25/2004 11:39:56 AM
3 // Author: Sergey LITONIN
4 // Copyright (C) CEA 2004
6 #include "SalomeApp_Module.h"
8 #include "SalomeApp_Study.h"
9 #include "SalomeApp_DataModel.h"
10 #include "SalomeApp_Application.h"
11 #include "SalomeApp_Preferences.h"
13 #include <OB_Browser.h>
15 #include <CAM_Study.h>
17 #include <SUIT_MessageBox.h>
18 #include <SUIT_ResourceMgr.h>
20 #include <QtxPopupMgr.h>
23 SalomeApp_Module::SalomeApp_Module( const QString& name )
30 SalomeApp_Module::~SalomeApp_Module()
34 /*!Initialize module.*/
35 void SalomeApp_Module::initialize( CAM_Application* app )
37 CAM_Module::initialize( app );
39 SUIT_ResourceMgr* resMgr = app ? app->resourceMgr() : 0;
41 resMgr->raiseTranslators( name() );
45 bool SalomeApp_Module::activateModule( SUIT_Study* study )
47 bool res = CAM_Module::activateModule( study );
49 if ( res && application() && application()->resourceMgr() )
50 application()->resourceMgr()->raiseTranslators( name() );
55 /*!Deactivate module.*/
56 bool SalomeApp_Module::deactivateModule( SUIT_Study* )
62 void SalomeApp_Module::selectionChanged()
67 void SalomeApp_Module::MenuItem()
72 void SalomeApp_Module::windows( QMap<int, int>& ) const
77 void SalomeApp_Module::viewManagers( QStringList& ) const
82 void SalomeApp_Module::createPreferences()
87 void SalomeApp_Module::preferencesChanged( const QString&, const QString& )
91 /*!Gets application.*/
92 SalomeApp_Application* SalomeApp_Module::getApp() const
94 return (SalomeApp_Application*)application();
98 void SalomeApp_Module::onModelOpened()
103 void SalomeApp_Module::onModelSaved()
108 void SalomeApp_Module::onModelClosed()
112 /*!Gets popup manager.(create if not exist)*/
113 QtxPopupMgr* SalomeApp_Module::popupMgr()
116 myPopupMgr = new QtxPopupMgr( 0, this );
120 /*!Gets preferences.*/
121 SalomeApp_Preferences* SalomeApp_Module::preferences() const
123 SalomeApp_Preferences* pref = 0;
125 pref = getApp()->preferences();
129 /*!Create new instance of data model and return it.*/
130 CAM_DataModel* SalomeApp_Module::createDataModel()
132 return new SalomeApp_DataModel(this);
135 /*!Update object browser.*/
136 void SalomeApp_Module::updateObjBrowser( bool updateDataModel, SUIT_DataObject* root )
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 );
145 /*!Context menu popup.*/
146 void SalomeApp_Module::contextMenuPopup( const QString& client, QPopupMenu* menu, QString& /*title*/ )
148 SalomeApp_Selection* sel = createSelection();
149 sel->init( client, getApp()->selectionMgr() );
150 popupMgr()->updatePopup( menu, sel );
154 /*!Create and return instance of SalomeApp_Selection.*/
155 SalomeApp_Selection* SalomeApp_Module::createSelection() const
157 return new SalomeApp_Selection();
160 /*!Add preference to preferences.*/
161 int SalomeApp_Module::addPreference( const QString& label )
163 SalomeApp_Preferences* pref = preferences();
167 int catId = pref->addPreference( moduleName(), -1 );
171 return pref->addPreference( label, catId );
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 )
178 SalomeApp_Preferences* pref = preferences();
182 return pref->addPreference( moduleName(), label, pId, type, section, param );
185 /*!Gets property of preferences.*/
186 QVariant SalomeApp_Module::preferenceProperty( const int id, const QString& prop ) const
189 SalomeApp_Preferences* pref = preferences();
191 var = pref->itemProperty( id, prop );
196 /*!Set property of preferences.*/
197 void SalomeApp_Module::setPreferenceProperty( const int id, const QString& prop, const QVariant& var )
199 SalomeApp_Preferences* pref = preferences();
201 pref->setItemProperty( id, prop, var );