]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMBase/GEOMBase_Skeleton.cxx
Salome HOME
Merge from V4_1_0_maintainance branch (from tag mergeto_BR_QT4_Dev_08Jul08)
[modules/geom.git] / src / GEOMBase / GEOMBase_Skeleton.cxx
1 // GEOM GEOMGUI : GUI for Geometry component
2 //
3 // Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 // This library is free software; you can redistribute it and/or 
7 // modify it under the terms of the GNU Lesser General Public 
8 // License as published by the Free Software Foundation; either 
9 // version 2.1 of the License. 
10 // 
11 // This library is distributed in the hope that it will be useful, 
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 // Lesser General Public License for more details. 
15 // 
16 // You should have received a copy of the GNU Lesser General Public 
17 // License along with this library; if not, write to the Free Software 
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File   : GEOMBase_Skeleton.cxx
23 // Author : Damien COQUERET, Open CASCADE S.A.S.
24 //
25
26 #include "GEOMBase_Skeleton.h"
27 #include "GEOMBase.h"
28
29 #include <DlgRef.h>
30 #include <GeometryGUI.h>
31
32 #include <SalomeApp_Application.h>
33 #include <LightApp_Application.h>
34 #include <LightApp_SelectionMgr.h>
35 #include <SUIT_Desktop.h>
36 #include <SUIT_ResourceMgr.h>
37 #include <SUIT_Session.h>
38 #include <SUIT_MessageBox.h>
39
40 #include <QKeyEvent>
41 #include <QSpinBox>
42 #include <QDoubleSpinBox>
43
44 //=================================================================================
45 // class    : GEOMBase_Skeleton()
46 // purpose  : Constructs a GEOMBase_Skeleton which is a child of 'parent', with the 
47 //            name 'name' and widget flags set to 'f'.
48 //            The dialog will by default be modeless, unless you set 'modal' to
49 //            true to construct a modal dialog.
50 //=================================================================================
51 GEOMBase_Skeleton::GEOMBase_Skeleton( GeometryGUI* theGeometryGUI, QWidget* parent,
52                                       bool modal, Qt::WindowFlags fl )
53   : QDialog( parent, fl ), 
54     GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( parent ) ),
55     myGeomGUI( theGeometryGUI ),
56     myRBGroup( 0 )
57 {
58   setAttribute( Qt::WA_DeleteOnClose );
59
60   setModal( modal );
61
62   myMainFrame = new DlgRef_Skeleton( this );
63   QVBoxLayout* topLayout = new QVBoxLayout( this );
64   topLayout->setMargin( 0 ); topLayout->setSpacing( 0 );
65   topLayout->addWidget( myMainFrame );
66
67   myMainFrame->GroupBoxName->setTitle( tr( "GEOM_RESULT_NAME_GRP" ) );
68   myMainFrame->NameLabel->setText( tr( "GEOM_RESULT_NAME_LBL" ) );
69
70   myMainFrame->GroupBoxPublish->setTitle( tr( "GEOM_PUBLISH_RESULT_GRP" ) );
71   myMainFrame->CheckBoxRestoreSS->setText( tr( "GEOM_RESTORE_SUB_SHAPES" ) );
72
73   buttonCancel()->setText( tr( "GEOM_BUT_CLOSE" ) );
74   buttonOk()->setText( tr( "GEOM_BUT_APPLY_AND_CLOSE" ) );
75   buttonApply()->setText( tr( "GEOM_BUT_APPLY" ) );
76   buttonHelp()->setText( tr( "GEOM_BUT_HELP" ) );
77
78   myRBGroup = new QButtonGroup( this );
79   myRBGroup->addButton( myMainFrame->RadioButton1, 0 );
80   myRBGroup->addButton( myMainFrame->RadioButton2, 1 );
81   myRBGroup->addButton( myMainFrame->RadioButton3, 2 );
82   myRBGroup->addButton( myMainFrame->RadioButton4, 3 );
83   myRBGroup->addButton( myMainFrame->RadioButton5, 4 );
84
85   connect( myRBGroup, SIGNAL( buttonClicked( int ) ), this, SIGNAL( constructorsClicked( int ) ) );
86
87   Init();
88 }
89
90 //=================================================================================
91 // function : ~GEOMBase_Skeleton()
92 // purpose  : Destroys the object and frees any allocated resources
93 //=================================================================================
94 GEOMBase_Skeleton::~GEOMBase_Skeleton()
95 {
96   if ( myGeomGUI )
97     myGeomGUI->SetActiveDialogBox( 0 );
98 }
99
100 //=================================================================================
101 // function : Init()
102 // purpose  :
103 //=================================================================================
104 void GEOMBase_Skeleton::Init()
105 {
106   SalomeApp_Application* app = (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() );
107   if ( !myGeomGUI && app )
108     myGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
109
110   /* init variables */
111   if ( myGeomGUI )
112     myGeomGUI->SetActiveDialogBox( this );
113
114   /* signals and slots connections */
115   connect( buttonCancel(), SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) );
116   if ( myGeomGUI ) {
117     connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
118     connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ),        this, SLOT( ClickOnCancel() ) );
119   }
120
121   // connect help button on a private slot that displays help information
122   connect( buttonHelp(), SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) );
123
124   /* displays Dialog */
125   myMainFrame->RadioButton1->setChecked( true );
126   myMainFrame->RadioButton4->hide();
127   myMainFrame->RadioButton5->hide();
128
129   myMainFrame->CheckBoxRestoreSS->setChecked( false );
130   myMainFrame->GroupBoxPublish->hide();
131 }
132
133 void GEOMBase_Skeleton::initSpinBox( QSpinBox* spinBox, 
134                                      int min,  int max, int step )
135 {
136   spinBox->setRange( min, max );
137   spinBox->setSingleStep( step );
138 }
139
140 void GEOMBase_Skeleton::initSpinBox( QDoubleSpinBox* spinBox, 
141                                      double min,  double max, 
142                                      double step, int decimals )
143 {
144   spinBox->setDecimals( decimals ); // it's necessary to set decimals before the range setting,
145                                     // by default Qt rounds boundaries to 2 decimals at setRange
146   spinBox->setRange( min, max );
147   spinBox->setSingleStep( step );
148 }
149
150 //=================================================================================
151 // function : ClickOnCancel()
152 // purpose  :
153 //=================================================================================
154 void GEOMBase_Skeleton::ClickOnCancel()
155 {
156   close();
157 }
158
159 //=================================================================================
160 // function : LineEditReturnPressed()
161 // purpose  :
162 //=================================================================================
163 void GEOMBase_Skeleton::LineEditReturnPressed()
164 {
165   if ( !myEditCurrentArgument )
166     return;
167
168   /* User name of object input management                          */
169   /* If successfull the selection is changed and signal emitted... */
170   /* so SelectionIntoArgument() is automatically called.           */
171   const QString objectUserName = myEditCurrentArgument->text();
172   QWidget* thisWidget = (QWidget*)this;
173   
174   if ( GEOMBase::SelectionByNameInDialogs( thisWidget, objectUserName, selectedIO() ) )
175      myEditCurrentArgument->setText( objectUserName );
176 }
177
178 //=================================================================================
179 // function : DeactivateActiveDialog()
180 // purpose  :
181 //=================================================================================
182 void GEOMBase_Skeleton::DeactivateActiveDialog()
183 {
184   this->setEnabled( false );
185   globalSelection();
186   if ( myGeomGUI ) {
187     myGeomGUI->SetActiveDialogBox( 0 );
188     disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
189   }
190 }
191
192 //=================================================================================
193 // function : ActivateThisDialog()
194 // purpose  :
195 //=================================================================================
196 void GEOMBase_Skeleton::ActivateThisDialog()
197 {
198   /* Emit a signal to deactivate the active dialog */
199   if ( myGeomGUI ) myGeomGUI->EmitSignalDeactivateDialog();
200   this->setEnabled( true );
201   if ( myGeomGUI ) myGeomGUI->SetActiveDialogBox( (QDialog*)this );
202   return;
203 }
204
205 //=================================================================================
206 // function : closeEvent()
207 // purpose  : same than click on cancel button
208 //=================================================================================
209 void GEOMBase_Skeleton::closeEvent( QCloseEvent* e )
210 {
211   if ( myGeomGUI ) {
212     disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
213     myGeomGUI->getApp()->updateActions();
214   }
215   QDialog::closeEvent( e );
216 }
217
218 //=================================================================================
219 // function : initName()
220 // purpose  : initialize the Name field with a string "thePrefix_X" (Vertex_3)
221 //=================================================================================
222 void GEOMBase_Skeleton::initName( const QString& thePrefix )
223 {
224   if ( !thePrefix.isNull() )
225     setPrefix( thePrefix );
226   myMainFrame->ResultName->setText( GEOMBase::GetDefaultName( getPrefix() ) );
227 }
228
229 //=================================================================================
230 // function : getNewObjectName()
231 // purpose  : returns contents of Name field
232 //=================================================================================
233 QString GEOMBase_Skeleton::getNewObjectName() const
234 {
235   return myMainFrame->ResultName->text();
236 }
237
238 //=================================================================================
239 // function : getConstructorId()
240 // purpose  :
241 //=================================================================================
242 int GEOMBase_Skeleton::getConstructorId() const
243 {
244   if ( myRBGroup )
245     return myRBGroup->checkedId();
246   return -1;
247 }
248
249 void GEOMBase_Skeleton::setConstructorId( const int id )
250 {
251   if ( myRBGroup && myRBGroup->button( id ) )
252     myRBGroup->button( id )->setChecked( true );
253 }
254
255 //=================================================================================
256 // function : ClickOnHelp()
257 // purpose  :
258 //=================================================================================
259 void GEOMBase_Skeleton::ClickOnHelp()
260 {
261   LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
262   if ( app ) 
263     app->onHelpContextModule( myGeomGUI ? app->moduleName( myGeomGUI->moduleName() ) : QString(""), myHelpFileName );
264   else {
265     QString platform;
266 #ifdef WIN32
267     platform = "winapplication";
268 #else
269     platform = "application";
270 #endif
271     SUIT_MessageBox::warning( 0, QObject::tr( "WRN_WARNING" ),
272                               QObject::tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
273                               arg( app->resourceMgr()->stringValue( "ExternalBrowser", platform ) ).arg( myHelpFileName ),
274                               QObject::tr( "BUT_OK" ) );
275   }
276 }
277
278 //=================================================================================
279 //  function : setHelpFileName()
280 //  purpose  : set name for help file html
281 //=================================================================================
282 void GEOMBase_Skeleton::setHelpFileName( const QString& theName )
283 {
284   myHelpFileName = theName;
285 }
286
287 DlgRef_Skeleton* GEOMBase_Skeleton::mainFrame()
288 {
289   return myMainFrame;
290 }
291
292 QWidget* GEOMBase_Skeleton::centralWidget()
293 {
294   return myMainFrame->GroupMedium;
295 }
296
297 QPushButton* GEOMBase_Skeleton::buttonCancel() const
298 {
299   return myMainFrame->buttonCancel;
300 }
301
302 QPushButton* GEOMBase_Skeleton::buttonOk() const
303 {
304   return myMainFrame->buttonOk;
305 }
306
307 QPushButton* GEOMBase_Skeleton::buttonApply() const
308 {
309   return myMainFrame->buttonApply;
310 }
311
312 QPushButton* GEOMBase_Skeleton::buttonHelp() const
313 {
314   return myMainFrame->buttonHelp;
315 }
316
317 //=================================================================================
318 // function : keyPressEvent()
319 // purpose  :
320 //=================================================================================
321 void GEOMBase_Skeleton::keyPressEvent( QKeyEvent* e )
322 {
323   QDialog::keyPressEvent( e );
324   if ( e->isAccepted() )
325     return;
326
327   if ( e->key() == Qt::Key_F1 ) {
328     e->accept();
329     ClickOnHelp();
330   }
331 }