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