Salome HOME
mergefrom branch BR_V511_PR tag mergeto_trunk_03feb09
[modules/yacs.git] / src / wrappergen / bin / HXX2SALOME_GENERIC_CLASS_NAME_SRC / src / HXX2SALOME_GENERIC_CLASS_NAMEGUI / HXX2SALOME_GENERIC_CLASS_NAMEGUI.cxx
1 //  Copyright (C) 2006-2008  CEA/DEN, EDF R&D
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.
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 #include "HXX2SALOME_GENERIC_CLASS_NAMEGUI.h"
20
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>
26
27 #include <SALOME_LifeCycleCORBA.hxx>
28
29 #define COMPONENT_NAME "HXX2SALOME_GENERIC_CLASS_NAME"
30
31 using namespace std;
32
33 // Constructor
34 HXX2SALOME_GENERIC_CLASS_NAMEGUI::HXX2SALOME_GENERIC_CLASS_NAMEGUI() :
35   SalomeApp_Module( COMPONENT_NAME ) // Module name
36 {
37   // Initializations
38   default_bool = false;
39   default_int = 0;
40   default_spinInt = 0;
41   default_spinDbl = 0.;
42   default_selection = QString("");
43   
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" ) );
49 }
50
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 )
53 {
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));
57   return clr;
58 }
59
60 // Module's initialization
61 void HXX2SALOME_GENERIC_CLASS_NAMEGUI::initialize( CAM_Application* app )
62 {
63   // Get handle to Application, Desktop and Resource Manager
64   SalomeApp_Module::initialize( app );
65
66   InitHXX2SALOME_GENERIC_CLASS_NAMEGen( dynamic_cast<SalomeApp_Application*>( app ) );
67
68   QWidget* aParent = app->desktop();
69   
70   SUIT_ResourceMgr* aResourceMgr = app->resourceMgr();
71   
72   // GUI items
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() ) );
77
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() ) );
81
82   // --> Create item in "File" menu
83   int aMenuId;
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 );
88
89   // --> Create specific menu
90   aMenuId = createMenu( tr( "MEN_HXX2SALOME_GENERIC_CLASS_NAME" ), -1, -1, 30 );
91   createMenu( 901, aMenuId, 10 );
92
93   // --> Create toolbar item
94   int aToolId = createTool ( tr( "TOOL_HXX2SALOME_GENERIC_CLASS_NAME" ) );
95   createTool( 901, aToolId );
96 }
97
98 // Module's engine IOR
99 QString HXX2SALOME_GENERIC_CLASS_NAMEGUI::engineIOR() const
100 {
101   CORBA::String_var anIOR = getApp()->orb()->object_to_string( InitHXX2SALOME_GENERIC_CLASS_NAMEGen( getApp() ) );
102   return QString( anIOR.in() );
103 }
104
105 // Module's activation
106 bool HXX2SALOME_GENERIC_CLASS_NAMEGUI::activateModule( SUIT_Study* theStudy )
107 {
108   bool bOk = SalomeApp_Module::activateModule( theStudy );
109
110   setMenuShown( true );
111   setToolShown( true );
112
113   return bOk;
114 }
115
116 // Module's deactivation
117 bool HXX2SALOME_GENERIC_CLASS_NAMEGUI::deactivateModule( SUIT_Study* theStudy )
118 {
119   setMenuShown( false );
120   setToolShown( false );
121
122   return SalomeApp_Module::deactivateModule( theStudy );
123 }
124
125 // Default windows
126 void HXX2SALOME_GENERIC_CLASS_NAMEGUI::windows( QMap<int, int>& theMap ) const
127 {
128   theMap.clear();
129   theMap.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::DockLeft );
130   theMap.insert( SalomeApp_Application::WT_PyConsole,     Qt::DockBottom );
131 }
132
133 // Action slot: Launched with action 190
134 void HXX2SALOME_GENERIC_CLASS_NAMEGUI::OnMyNewItem()
135 {
136   SUIT_MessageBox::warn1( getApp()->desktop(),tr( "INF_HXX2SALOME_GENERIC_CLASS_NAME_TITLE" ), tr( "INF_HXX2SALOME_GENERIC_CLASS_NAME_TEXT" ), tr( "BUT_OK" ) );
137 }
138
139 // Action slot: Launched with action 901
140 void HXX2SALOME_GENERIC_CLASS_NAMEGUI::OnCallAction()
141 {
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() );
144   
145   // Do the job...
146   //
147   // HXX2SALOME_GENERIC_CLASS_NAMEgen->method( arg1, arg2, ... );
148   
149   // Open a dialog showing Preferences values (just to display something)
150   
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();
154   
155   default_bool = mgr->booleanValue(COMPONENT_NAME, "default_bool", false);
156
157   default_int = mgr->integerValue(COMPONENT_NAME, "default_integer", 3);
158
159   default_spinInt = mgr->integerValue(COMPONENT_NAME, "default_spinint", 4);
160
161   default_spinDbl = mgr->doubleValue(COMPONENT_NAME, "default_spindbl", 4.5);
162
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 ******
166   
167   QString SUC = ( default_bool ? QString( tr ("INF_HXX2SALOME_GENERIC_CLASS_NAME_CHECK") ) : QString( tr("INF_HXX2SALOME_GENERIC_CLASS_NAME_UNCHECK") ) ) ;
168     
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" ) );
171 }
172
173 void HXX2SALOME_GENERIC_CLASS_NAMEGUI::createPreferences()
174 {
175   // A sample preference dialog
176   
177   // One only tab
178   int genTab = addPreference( tr( "PREF_TAB_GENERAL" ) );
179
180   // One only group
181   int defaultsGroup = addPreference( tr( "PREF_GROUP_DEFAULTS" ), genTab );
182   
183   // A checkbox
184   addPreference( tr( "PREF_DEFAULT_BOOL" ), defaultsGroup, LightApp_Preferences::Bool, COMPONENT_NAME, "default_bool" );
185   
186   // An entry for integer
187   addPreference( tr( "PREF_DEFAULT_INTEGER" ), defaultsGroup, LightApp_Preferences::Integer, COMPONENT_NAME, "default_integer" );
188
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 );
194
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 );
200
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;
204   indices.append( 0 );
205   indices.append( 1 );
206   indices.append( 2 );
207   setPreferenceProperty( options, "strings", selector_strings );
208   setPreferenceProperty( options, "indexes", indices );
209 }
210
211 void HXX2SALOME_GENERIC_CLASS_NAMEGUI::preferencesChanged( const QString& sect, const QString& name )
212 {
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 )
216   {
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" )
226     {
227         int selectorIndex = mgr->integerValue(COMPONENT_NAME, "default_selector");
228         default_selection = (0<=selectorIndex && selectorIndex<=selector_strings.count() ? selector_strings[selectorIndex]: QString("None"));
229     }
230   }
231 }
232
233 // Export the module
234 extern "C" {
235   CAM_Module* createModule()
236   {
237     return new HXX2SALOME_GENERIC_CLASS_NAMEGUI();
238   }
239 }