Salome HOME
*** empty log message ***
[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 <GeometryGUI.h>
30 #include <GEOM_DlgRef.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 <QDoubleSpinBox>
42
43 using namespace std;
44
45 //=================================================================================
46 // class    : GEOMBase_Skeleton()
47 // purpose  : Constructs a GEOMBase_Skeleton which is a child of 'parent', with the 
48 //            name 'name' and widget flags set to 'f'.
49 //            The dialog will by default be modeless, unless you set 'modal' to
50 //            true to construct a modal dialog.
51 //=================================================================================
52 GEOMBase_Skeleton::GEOMBase_Skeleton( GeometryGUI* theGeometryGUI, QWidget* parent,
53                                       bool modal, Qt::WindowFlags fl )
54   : QDialog( parent, fl ), 
55     GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( parent ) ),
56     myGeomGUI( theGeometryGUI ),
57     myRBGroup( 0 )
58 {
59   setAttribute( Qt::WA_DeleteOnClose );
60
61   setModal( modal );
62
63   myMainFrame = new DlgRef_Skeleton( this );
64   QVBoxLayout* topLayout = new QVBoxLayout( this );
65   topLayout->setMargin( 0 ); topLayout->setSpacing( 0 );
66   topLayout->addWidget( myMainFrame );
67
68   buttonCancel()->setText( tr( "GEOM_BUT_CLOSE" ) );
69   buttonOk()->setText( tr( "GEOM_BUT_OK" )) ;
70   buttonApply()->setText( tr( "GEOM_BUT_APPLY" ) );
71   buttonHelp()->setText( tr( "GEOM_BUT_HELP" ) );
72
73   myRBGroup = new QButtonGroup( this );
74   myRBGroup->addButton( myMainFrame->RadioButton1, 0 );
75   myRBGroup->addButton( myMainFrame->RadioButton2, 1 );
76   myRBGroup->addButton( myMainFrame->RadioButton3, 2 );
77   myRBGroup->addButton( myMainFrame->RadioButton4, 3 );
78
79   connect( myRBGroup, SIGNAL( buttonClicked( int ) ), this, SIGNAL( constructorsClicked( int ) ) );
80
81   Init();
82 }
83
84
85 //=================================================================================
86 // function : ~GEOMBase_Skeleton()
87 // purpose  : Destroys the object and frees any allocated resources
88 //=================================================================================
89 GEOMBase_Skeleton::~GEOMBase_Skeleton()
90 {
91   if ( myGeomGUI )
92     myGeomGUI->SetActiveDialogBox( 0 );
93 }
94
95
96 //=================================================================================
97 // function : Init()
98 // purpose  :
99 //=================================================================================
100 void GEOMBase_Skeleton::Init()
101 {
102   SalomeApp_Application* app = (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() );
103   if ( !myGeomGUI && app )
104     myGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
105
106   /* init variables */
107   myGeomGUI->SetActiveDialogBox( this );
108
109   /* signals and slots connections */
110   connect( buttonCancel(), SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) );
111   if ( myGeomGUI ) {
112     connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
113     connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ),        this, SLOT( ClickOnCancel() ) );
114   }
115
116   // connect help button on a private slot that displays help information
117   connect( buttonHelp(), SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) );
118
119   /* displays Dialog */
120   myMainFrame->RadioButton1->setChecked( true );
121   myMainFrame->RadioButton4->hide();
122 }
123
124 void GEOMBase_Skeleton::initSpinBox( QDoubleSpinBox* spinBox, 
125                                      double min,  double max, 
126                                      double step, int decimals )
127 {
128   spinBox->setRange( min, max );
129   spinBox->setSingleStep( step );
130   spinBox->setDecimals( decimals );
131 }
132
133 //=================================================================================
134 // function : ClickOnCancel()
135 // purpose  :
136 //=================================================================================
137 void GEOMBase_Skeleton::ClickOnCancel()
138 {
139   close();
140 }
141
142
143 //=================================================================================
144 // function : LineEditReturnPressed()
145 // purpose  :
146 //=================================================================================
147 void GEOMBase_Skeleton::LineEditReturnPressed()
148 {
149   if ( !myEditCurrentArgument )
150     return;
151
152   /* User name of object input management                          */
153   /* If successfull the selection is changed and signal emitted... */
154   /* so SelectionIntoArgument() is automatically called.           */
155   const QString objectUserName = myEditCurrentArgument->text();
156   QWidget* thisWidget = (QWidget*)this;
157   
158   if ( GEOMBase::SelectionByNameInDialogs( thisWidget, objectUserName, selectedIO() ) )
159      myEditCurrentArgument->setText( objectUserName );
160 }
161
162
163 //=================================================================================
164 // function : DeactivateActiveDialog()
165 // purpose  :
166 //=================================================================================
167 void GEOMBase_Skeleton::DeactivateActiveDialog()
168 {
169   this->setEnabled( false );
170   globalSelection();
171   disconnect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(), 0, this, 0 );
172   if ( myGeomGUI ) myGeomGUI->SetActiveDialogBox( 0 );
173 }
174
175
176 //=================================================================================
177 // function : ActivateThisDialog()
178 // purpose  :
179 //=================================================================================
180 void GEOMBase_Skeleton::ActivateThisDialog()
181 {
182   /* Emit a signal to deactivate the active dialog */
183   if ( myGeomGUI ) myGeomGUI->EmitSignalDeactivateDialog();
184   this->setEnabled( true );
185   if ( myGeomGUI ) myGeomGUI->SetActiveDialogBox( (QDialog*)this );
186   return;
187 }
188
189
190 //=================================================================================
191 // function : closeEvent()
192 // purpose  : same than click on cancel button
193 //=================================================================================
194 void GEOMBase_Skeleton::closeEvent( QCloseEvent* e )
195 {
196   SalomeApp_Application* app = (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() );
197   if( app ) {
198     disconnect( app->selectionMgr(), 0, this, 0 );
199     app->updateActions();
200   }
201   QDialog::closeEvent( e );
202 }
203
204 //=================================================================================
205 // function : initName()
206 // purpose  : initialize the Name field with a string "thePrefix_X" (Vertex_3)
207 //=================================================================================
208 void GEOMBase_Skeleton::initName( const QString& thePrefix )
209 {
210   if ( !thePrefix.isNull() )
211     setPrefix( thePrefix );
212   myMainFrame->ResultName->setText( GEOMBase::GetDefaultName( getPrefix() ) );
213 }
214
215 //=================================================================================
216 // function : getNewObjectName()
217 // purpose  : returns contents of Name field
218 //=================================================================================
219 const char* GEOMBase_Skeleton::getNewObjectName() const
220 {
221   return myMainFrame->ResultName->text().toLatin1().constData();
222 }
223
224 //=================================================================================
225 // function : getConstructorId()
226 // purpose  :
227 //=================================================================================
228 int GEOMBase_Skeleton::getConstructorId() const
229 {
230   if ( myRBGroup )
231     return myRBGroup->checkedId();
232   return -1;
233 }
234
235 void GEOMBase_Skeleton::setConstructorId( const int id )
236 {
237   if ( myRBGroup && myRBGroup->button( id ) )
238     myRBGroup->button( id )->setChecked( true );
239 }
240
241 //=================================================================================
242 // function : ClickOnHelp()
243 // purpose  :
244 //=================================================================================
245 void GEOMBase_Skeleton::ClickOnHelp()
246 {
247   LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
248   if ( app ) 
249     app->onHelpContextModule( myGeomGUI ? app->moduleName( myGeomGUI->moduleName() ) : QString(""), myHelpFileName );
250   else {
251     QString platform;
252 #ifdef WIN32
253     platform = "winapplication";
254 #else
255     platform = "application";
256 #endif
257     SUIT_MessageBox::warning( 0, QObject::tr( "WRN_WARNING" ),
258                               QObject::tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
259                               arg( app->resourceMgr()->stringValue( "ExternalBrowser", platform ) ).arg( myHelpFileName ),
260                               QObject::tr( "BUT_OK" ) );
261   }
262 }
263 //=================================================================================
264 //  function : setHelpFileName()
265 //  purpose  : set name for help file html
266 //=================================================================================
267
268 void GEOMBase_Skeleton::setHelpFileName( const QString& theName )
269 {
270   myHelpFileName = theName;
271 }
272
273 DlgRef_Skeleton* GEOMBase_Skeleton::mainFrame()
274 {
275   return myMainFrame;
276 }
277
278 QWidget* GEOMBase_Skeleton::centralWidget()
279 {
280   return myMainFrame->GroupMedium;
281 }
282
283 QPushButton* GEOMBase_Skeleton::buttonCancel() const
284 {
285   return myMainFrame->buttonCancel;
286 }
287
288 QPushButton* GEOMBase_Skeleton::buttonOk() const
289 {
290   return myMainFrame->buttonOk;
291 }
292
293 QPushButton* GEOMBase_Skeleton::buttonApply() const
294 {
295   return myMainFrame->buttonApply;
296 }
297
298 QPushButton* GEOMBase_Skeleton::buttonHelp() const
299 {
300   return myMainFrame->buttonHelp;
301 }
302
303 //=================================================================================
304 // function : keyPressEvent()
305 // purpose  :
306 //=================================================================================
307 void GEOMBase_Skeleton::keyPressEvent( QKeyEvent* e )
308 {
309   QDialog::keyPressEvent( e );
310   if ( e->isAccepted() )
311     return;
312
313   if ( e->key() == Qt::Key_F1 ) {
314     e->accept();
315     ClickOnHelp();
316   }
317 }