1 // Copyright (C) 2006-2014 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, or (at your option) any later version.
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
20 #include "HXX2SALOME_GENERIC_CLASS_NAMEGUI.h"
22 #include <SUIT_MessageBox.h>
23 #include <SUIT_ResourceMgr.h>
24 #include <SUIT_Session.h>
25 #include <SalomeApp_Application.h>
26 #include <LightApp_Preferences.h>
28 #include <SALOME_LifeCycleCORBA.hxx>
30 #define COMPONENT_NAME "HXX2SALOME_GENERIC_CLASS_NAME"
35 HXX2SALOME_GENERIC_CLASS_NAMEGUI::HXX2SALOME_GENERIC_CLASS_NAMEGUI() :
36 SalomeApp_Module( COMPONENT_NAME ) // Module name
43 default_selection = QString("");
45 // List for the selector
46 selector_strings.clear();
47 selector_strings.append( tr( "PREF_LIST_TEXT_0" ) );
48 selector_strings.append( tr( "PREF_LIST_TEXT_1" ) );
49 selector_strings.append( tr( "PREF_LIST_TEXT_2" ) );
52 // Gets a reference to the module's engine
53 HXX2SALOME_GENERIC_CLASS_NAME_ORB::HXX2SALOME_GENERIC_CLASS_NAME_Gen_ptr HXX2SALOME_GENERIC_CLASS_NAMEGUI::InitHXX2SALOME_GENERIC_CLASS_NAMEGen( SalomeApp_Application* app )
55 Engines::EngineComponent_var comp = app->lcc()->FindOrLoad_Component( "FactoryServer",COMPONENT_NAME );
56 HXX2SALOME_GENERIC_CLASS_NAME_ORB::HXX2SALOME_GENERIC_CLASS_NAME_Gen_ptr clr = HXX2SALOME_GENERIC_CLASS_NAME_ORB::HXX2SALOME_GENERIC_CLASS_NAME_Gen::_narrow(comp);
57 ASSERT(!CORBA::is_nil(clr));
61 // Module's initialization
62 void HXX2SALOME_GENERIC_CLASS_NAMEGUI::initialize( CAM_Application* app )
64 // Get handle to Application, Desktop and Resource Manager
65 SalomeApp_Module::initialize( app );
67 InitHXX2SALOME_GENERIC_CLASS_NAMEGen( dynamic_cast<SalomeApp_Application*>( app ) );
69 QWidget* aParent = app->desktop();
71 SUIT_ResourceMgr* aResourceMgr = app->resourceMgr();
74 // --> Create actions: 190 is linked to item in "File" menu
75 // and 901 is linked to both specific menu and toolbar
76 createAction( 190, tr( "TLT_MY_NEW_ITEM" ), QIconSet(), tr( "MEN_MY_NEW_ITEM" ), tr( "STS_MY_NEW_ITEM" ), 0, aParent, false,
77 this, SLOT( OnMyNewItem() ) );
79 QPixmap aPixmap = aResourceMgr->loadPixmap( COMPONENT_NAME,tr( "ICON_HXX2SALOME_GENERIC_CLASS_NAME" ) );
80 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,
81 this, SLOT( OnCallAction() ) );
83 // --> Create item in "File" menu
85 aMenuId = createMenu( tr( "MEN_FILE" ), -1, -1 );
86 createMenu( separator(), aMenuId, -1, 10 );
87 aMenuId = createMenu( tr( "MEN_FILE_HXX2SALOME_GENERIC_CLASS_NAME" ), aMenuId, -1, 10 );
88 createMenu( 190, aMenuId );
90 // --> Create specific menu
91 aMenuId = createMenu( tr( "MEN_HXX2SALOME_GENERIC_CLASS_NAME" ), -1, -1, 30 );
92 createMenu( 901, aMenuId, 10 );
94 // --> Create toolbar item
95 int aToolId = createTool ( tr( "TOOL_HXX2SALOME_GENERIC_CLASS_NAME" ) );
96 createTool( 901, aToolId );
99 // Module's engine IOR
100 QString HXX2SALOME_GENERIC_CLASS_NAMEGUI::engineIOR() const
102 CORBA::String_var anIOR = getApp()->orb()->object_to_string( InitHXX2SALOME_GENERIC_CLASS_NAMEGen( getApp() ) );
103 return QString( anIOR.in() );
106 // Module's activation
107 bool HXX2SALOME_GENERIC_CLASS_NAMEGUI::activateModule( SUIT_Study* theStudy )
109 bool bOk = SalomeApp_Module::activateModule( theStudy );
111 setMenuShown( true );
112 setToolShown( true );
117 // Module's deactivation
118 bool HXX2SALOME_GENERIC_CLASS_NAMEGUI::deactivateModule( SUIT_Study* theStudy )
120 setMenuShown( false );
121 setToolShown( false );
123 return SalomeApp_Module::deactivateModule( theStudy );
127 void HXX2SALOME_GENERIC_CLASS_NAMEGUI::windows( QMap<int, int>& theMap ) const
130 theMap.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::DockLeft );
131 theMap.insert( SalomeApp_Application::WT_PyConsole, Qt::DockBottom );
134 // Action slot: Launched with action 190
135 void HXX2SALOME_GENERIC_CLASS_NAMEGUI::OnMyNewItem()
137 SUIT_MessageBox::warn1( getApp()->desktop(),tr( "INF_HXX2SALOME_GENERIC_CLASS_NAME_TITLE" ), tr( "INF_HXX2SALOME_GENERIC_CLASS_NAME_TEXT" ), tr( "BUT_OK" ) );
140 // Action slot: Launched with action 901
141 void HXX2SALOME_GENERIC_CLASS_NAMEGUI::OnCallAction()
143 // Create a HXX2SALOME_GENERIC_CLASS_NAME component
144 HXX2SALOME_GENERIC_CLASS_NAME_ORB::HXX2SALOME_GENERIC_CLASS_NAME_Gen_ptr HXX2SALOME_GENERIC_CLASS_NAMEgen = HXX2SALOME_GENERIC_CLASS_NAMEGUI::InitHXX2SALOME_GENERIC_CLASS_NAMEGen( getApp() );
148 // HXX2SALOME_GENERIC_CLASS_NAMEgen->method( arg1, arg2, ... );
150 // Open a dialog showing Preferences values (just to display something)
152 // ****** Direct access to preferences: implementation at 12/12/05 ******
153 // Comment out this section when "preferencesChanged" called back
154 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
156 default_bool = mgr->booleanValue(COMPONENT_NAME, "default_bool", false);
158 default_int = mgr->integerValue(COMPONENT_NAME, "default_integer", 3);
160 default_spinInt = mgr->integerValue(COMPONENT_NAME, "default_spinint", 4);
162 default_spinDbl = mgr->doubleValue(COMPONENT_NAME, "default_spindbl", 4.5);
164 int selectorIndex = mgr->integerValue(COMPONENT_NAME, "default_selector");
165 default_selection = (0<=selectorIndex && selectorIndex<=selector_strings.count() ? selector_strings[selectorIndex]: QString("None"));
166 // ****** End of section to be commented out ******
168 QString SUC = ( default_bool ? QString( tr ("INF_HXX2SALOME_GENERIC_CLASS_NAME_CHECK") ) : QString( tr("INF_HXX2SALOME_GENERIC_CLASS_NAME_UNCHECK") ) ) ;
170 QString textResult = QString( tr( "RES_HXX2SALOME_GENERIC_CLASS_NAME_TEXT" ) ).arg(SUC).arg(default_int).arg(default_spinInt).arg(default_spinDbl).arg(default_selection);
171 SUIT_MessageBox::info1( getApp()->desktop(), tr( "RES_HXX2SALOME_GENERIC_CLASS_NAME_TITLE" ), textResult, tr( "BUT_OK" ) );
174 void HXX2SALOME_GENERIC_CLASS_NAMEGUI::createPreferences()
176 // A sample preference dialog
179 int genTab = addPreference( tr( "PREF_TAB_GENERAL" ) );
182 int defaultsGroup = addPreference( tr( "PREF_GROUP_DEFAULTS" ), genTab );
185 addPreference( tr( "PREF_DEFAULT_BOOL" ), defaultsGroup, LightApp_Preferences::Bool, COMPONENT_NAME, "default_bool" );
187 // An entry for integer
188 addPreference( tr( "PREF_DEFAULT_INTEGER" ), defaultsGroup, LightApp_Preferences::Integer, COMPONENT_NAME, "default_integer" );
190 // An integer changed by spinbox
191 int spinInt = addPreference( tr( "PREF_DEFAULT_SPININT" ), defaultsGroup, LightApp_Preferences::IntSpin, COMPONENT_NAME, "default_spinint" );
192 setPreferenceProperty( spinInt, "min", 0 );
193 setPreferenceProperty( spinInt, "max", 20 );
194 setPreferenceProperty( spinInt, "step", 2 );
196 // A Double changed by spinbox
197 int spinDbl = addPreference( tr( "PREF_DEFAULT_SPINDBL" ), defaultsGroup, LightApp_Preferences::DblSpin, COMPONENT_NAME, "default_spindbl" );
198 setPreferenceProperty( spinDbl, "min", 1 );
199 setPreferenceProperty( spinDbl, "max", 10 );
200 setPreferenceProperty( spinDbl, "step", 0.1 );
202 // A choice in a list
203 int options = addPreference( tr( "PREF_DEFAULT_SELECTOR" ), defaultsGroup, LightApp_Preferences::Selector, COMPONENT_NAME, "default_selector" );
204 QValueList<QVariant> indices;
208 setPreferenceProperty( options, "strings", selector_strings );
209 setPreferenceProperty( options, "indexes", indices );
212 void HXX2SALOME_GENERIC_CLASS_NAMEGUI::preferencesChanged( const QString& sect, const QString& name )
214 // ****** This is normal way: Not yet called back at 12/12/05 ******
215 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
216 if( sect==COMPONENT_NAME )
218 if( name=="default_bool" )
219 default_bool = mgr->booleanValue(COMPONENT_NAME, "default_bool", false);
220 if( name=="default_integer" )
221 default_int = mgr->integerValue(COMPONENT_NAME, "default_integer", 3);
222 if( name=="default_spinint" )
223 default_spinInt = mgr->integerValue(COMPONENT_NAME, "default_spinint", 4);
224 if( name=="default_spindbl" )
225 default_spinDbl = mgr->doubleValue(COMPONENT_NAME, "default_spindbl", 4.5);
226 if( name=="default_selector" )
228 int selectorIndex = mgr->integerValue(COMPONENT_NAME, "default_selector");
229 default_selection = (0<=selectorIndex && selectorIndex<=selector_strings.count() ? selector_strings[selectorIndex]: QString("None"));
236 CAM_Module* createModule()
238 return new HXX2SALOME_GENERIC_CLASS_NAMEGUI();