1 // Copyright (C) 2006-2008 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HXX2SALOME_GENERIC_CLASS_NAMEGUI.h"
21 #include <SUIT_MessageBox.h>
22 #include <SUIT_ResourceMgr.h>
23 #include <SUIT_Session.h>
24 #include <SalomeApp_Application.h>
25 #include <LightApp_Preferences.h>
27 #include <SALOME_LifeCycleCORBA.hxx>
29 #define COMPONENT_NAME "HXX2SALOME_GENERIC_CLASS_NAME"
34 HXX2SALOME_GENERIC_CLASS_NAMEGUI::HXX2SALOME_GENERIC_CLASS_NAMEGUI() :
35 SalomeApp_Module( COMPONENT_NAME ) // Module name
42 default_selection = QString("");
44 // List for the selector
45 selector_strings.clear();
46 selector_strings.append( tr( "PREF_LIST_TEXT_0" ) );
47 selector_strings.append( tr( "PREF_LIST_TEXT_1" ) );
48 selector_strings.append( tr( "PREF_LIST_TEXT_2" ) );
51 // Gets a reference to the module's engine
52 HXX2SALOME_GENERIC_CLASS_NAME_ORB::HXX2SALOME_GENERIC_CLASS_NAME_Gen_ptr HXX2SALOME_GENERIC_CLASS_NAMEGUI::InitHXX2SALOME_GENERIC_CLASS_NAMEGen( SalomeApp_Application* app )
54 Engines::Component_var comp = app->lcc()->FindOrLoad_Component( "FactoryServer",COMPONENT_NAME );
55 HXX2SALOME_GENERIC_CLASS_NAME_ORB::HXX2SALOME_GENERIC_CLASS_NAME_Gen_ptr clr = HXX2SALOME_GENERIC_CLASS_NAME_ORB::HXX2SALOME_GENERIC_CLASS_NAME_Gen::_narrow(comp);
56 ASSERT(!CORBA::is_nil(clr));
60 // Module's initialization
61 void HXX2SALOME_GENERIC_CLASS_NAMEGUI::initialize( CAM_Application* app )
63 // Get handle to Application, Desktop and Resource Manager
64 SalomeApp_Module::initialize( app );
66 InitHXX2SALOME_GENERIC_CLASS_NAMEGen( dynamic_cast<SalomeApp_Application*>( app ) );
68 QWidget* aParent = app->desktop();
70 SUIT_ResourceMgr* aResourceMgr = app->resourceMgr();
73 // --> Create actions: 190 is linked to item in "File" menu
74 // and 901 is linked to both specific menu and toolbar
75 createAction( 190, tr( "TLT_MY_NEW_ITEM" ), QIconSet(), tr( "MEN_MY_NEW_ITEM" ), tr( "STS_MY_NEW_ITEM" ), 0, aParent, false,
76 this, SLOT( OnMyNewItem() ) );
78 QPixmap aPixmap = aResourceMgr->loadPixmap( COMPONENT_NAME,tr( "ICON_HXX2SALOME_GENERIC_CLASS_NAME" ) );
79 createAction( 901, tr( "TLT_HXX2SALOME_GENERIC_CLASS_NAME_ACTION" ), QIconSet( aPixmap ), tr( "MEN_HXX2SALOME_GENERIC_CLASS_NAME_ACTION" ), tr( "STS_HXX2SALOME_GENERIC_CLASS_NAME_ACTION" ), 0, aParent, false,
80 this, SLOT( OnCallAction() ) );
82 // --> Create item in "File" menu
84 aMenuId = createMenu( tr( "MEN_FILE" ), -1, -1 );
85 createMenu( separator(), aMenuId, -1, 10 );
86 aMenuId = createMenu( tr( "MEN_FILE_HXX2SALOME_GENERIC_CLASS_NAME" ), aMenuId, -1, 10 );
87 createMenu( 190, aMenuId );
89 // --> Create specific menu
90 aMenuId = createMenu( tr( "MEN_HXX2SALOME_GENERIC_CLASS_NAME" ), -1, -1, 30 );
91 createMenu( 901, aMenuId, 10 );
93 // --> Create toolbar item
94 int aToolId = createTool ( tr( "TOOL_HXX2SALOME_GENERIC_CLASS_NAME" ) );
95 createTool( 901, aToolId );
98 // Module's engine IOR
99 QString HXX2SALOME_GENERIC_CLASS_NAMEGUI::engineIOR() const
101 CORBA::String_var anIOR = getApp()->orb()->object_to_string( InitHXX2SALOME_GENERIC_CLASS_NAMEGen( getApp() ) );
102 return QString( anIOR.in() );
105 // Module's activation
106 bool HXX2SALOME_GENERIC_CLASS_NAMEGUI::activateModule( SUIT_Study* theStudy )
108 bool bOk = SalomeApp_Module::activateModule( theStudy );
110 setMenuShown( true );
111 setToolShown( true );
116 // Module's deactivation
117 bool HXX2SALOME_GENERIC_CLASS_NAMEGUI::deactivateModule( SUIT_Study* theStudy )
119 setMenuShown( false );
120 setToolShown( false );
122 return SalomeApp_Module::deactivateModule( theStudy );
126 void HXX2SALOME_GENERIC_CLASS_NAMEGUI::windows( QMap<int, int>& theMap ) const
129 theMap.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::DockLeft );
130 theMap.insert( SalomeApp_Application::WT_PyConsole, Qt::DockBottom );
133 // Action slot: Launched with action 190
134 void HXX2SALOME_GENERIC_CLASS_NAMEGUI::OnMyNewItem()
136 SUIT_MessageBox::warn1( getApp()->desktop(),tr( "INF_HXX2SALOME_GENERIC_CLASS_NAME_TITLE" ), tr( "INF_HXX2SALOME_GENERIC_CLASS_NAME_TEXT" ), tr( "BUT_OK" ) );
139 // Action slot: Launched with action 901
140 void HXX2SALOME_GENERIC_CLASS_NAMEGUI::OnCallAction()
142 // Create a HXX2SALOME_GENERIC_CLASS_NAME component
143 HXX2SALOME_GENERIC_CLASS_NAME_ORB::HXX2SALOME_GENERIC_CLASS_NAME_Gen_ptr HXX2SALOME_GENERIC_CLASS_NAMEgen = HXX2SALOME_GENERIC_CLASS_NAMEGUI::InitHXX2SALOME_GENERIC_CLASS_NAMEGen( getApp() );
147 // HXX2SALOME_GENERIC_CLASS_NAMEgen->method( arg1, arg2, ... );
149 // Open a dialog showing Preferences values (just to display something)
151 // ****** Direct access to preferences: implementation at 12/12/05 ******
152 // Comment out this section when "preferencesChanged" called back
153 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
155 default_bool = mgr->booleanValue(COMPONENT_NAME, "default_bool", false);
157 default_int = mgr->integerValue(COMPONENT_NAME, "default_integer", 3);
159 default_spinInt = mgr->integerValue(COMPONENT_NAME, "default_spinint", 4);
161 default_spinDbl = mgr->doubleValue(COMPONENT_NAME, "default_spindbl", 4.5);
163 int selectorIndex = mgr->integerValue(COMPONENT_NAME, "default_selector");
164 default_selection = (0<=selectorIndex && selectorIndex<=selector_strings.count() ? selector_strings[selectorIndex]: QString("None"));
165 // ****** End of section to be commented out ******
167 QString SUC = ( default_bool ? QString( tr ("INF_HXX2SALOME_GENERIC_CLASS_NAME_CHECK") ) : QString( tr("INF_HXX2SALOME_GENERIC_CLASS_NAME_UNCHECK") ) ) ;
169 QString textResult = QString( tr( "RES_HXX2SALOME_GENERIC_CLASS_NAME_TEXT" ) ).arg(SUC).arg(default_int).arg(default_spinInt).arg(default_spinDbl).arg(default_selection);
170 SUIT_MessageBox::info1( getApp()->desktop(), tr( "RES_HXX2SALOME_GENERIC_CLASS_NAME_TITLE" ), textResult, tr( "BUT_OK" ) );
173 void HXX2SALOME_GENERIC_CLASS_NAMEGUI::createPreferences()
175 // A sample preference dialog
178 int genTab = addPreference( tr( "PREF_TAB_GENERAL" ) );
181 int defaultsGroup = addPreference( tr( "PREF_GROUP_DEFAULTS" ), genTab );
184 addPreference( tr( "PREF_DEFAULT_BOOL" ), defaultsGroup, LightApp_Preferences::Bool, COMPONENT_NAME, "default_bool" );
186 // An entry for integer
187 addPreference( tr( "PREF_DEFAULT_INTEGER" ), defaultsGroup, LightApp_Preferences::Integer, COMPONENT_NAME, "default_integer" );
189 // An integer changed by spinbox
190 int spinInt = addPreference( tr( "PREF_DEFAULT_SPININT" ), defaultsGroup, LightApp_Preferences::IntSpin, COMPONENT_NAME, "default_spinint" );
191 setPreferenceProperty( spinInt, "min", 0 );
192 setPreferenceProperty( spinInt, "max", 20 );
193 setPreferenceProperty( spinInt, "step", 2 );
195 // A Double changed by spinbox
196 int spinDbl = addPreference( tr( "PREF_DEFAULT_SPINDBL" ), defaultsGroup, LightApp_Preferences::DblSpin, COMPONENT_NAME, "default_spindbl" );
197 setPreferenceProperty( spinDbl, "min", 1 );
198 setPreferenceProperty( spinDbl, "max", 10 );
199 setPreferenceProperty( spinDbl, "step", 0.1 );
201 // A choice in a list
202 int options = addPreference( tr( "PREF_DEFAULT_SELECTOR" ), defaultsGroup, LightApp_Preferences::Selector, COMPONENT_NAME, "default_selector" );
203 QValueList<QVariant> indices;
207 setPreferenceProperty( options, "strings", selector_strings );
208 setPreferenceProperty( options, "indexes", indices );
211 void HXX2SALOME_GENERIC_CLASS_NAMEGUI::preferencesChanged( const QString& sect, const QString& name )
213 // ****** This is normal way: Not yet called back at 12/12/05 ******
214 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
215 if( sect==COMPONENT_NAME )
217 if( name=="default_bool" )
218 default_bool = mgr->booleanValue(COMPONENT_NAME, "default_bool", false);
219 if( name=="default_integer" )
220 default_int = mgr->integerValue(COMPONENT_NAME, "default_integer", 3);
221 if( name=="default_spinint" )
222 default_spinInt = mgr->integerValue(COMPONENT_NAME, "default_spinint", 4);
223 if( name=="default_spindbl" )
224 default_spinDbl = mgr->doubleValue(COMPONENT_NAME, "default_spindbl", 4.5);
225 if( name=="default_selector" )
227 int selectorIndex = mgr->integerValue(COMPONENT_NAME, "default_selector");
228 default_selection = (0<=selectorIndex && selectorIndex<=selector_strings.count() ? selector_strings[selectorIndex]: QString("None"));
235 CAM_Module* createModule()
237 return new HXX2SALOME_GENERIC_CLASS_NAMEGUI();